Skip to content

Commit

Permalink
Pivotal ID # 188131969: Archive submission request (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan-EBI authored Aug 28, 2024
1 parent 4dad399 commit 808931e
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ import ac.uk.ebi.biostd.persistence.doc.db.converters.shared.DocSubmissionReques
import ac.uk.ebi.biostd.persistence.doc.db.converters.shared.DocSubmissionRequestFileFields.RQT_PREVIOUS_SUB_FILE
import ac.uk.ebi.biostd.persistence.doc.db.reactive.repositories.SubmissionRequestRepository
import ac.uk.ebi.biostd.persistence.doc.model.CollectionsNames.RQT_ARCH_COL
import ac.uk.ebi.biostd.persistence.doc.model.CollectionsNames.RQT_COL
import ac.uk.ebi.biostd.persistence.doc.model.CollectionsNames.RQT_FILE_ARCH_COL
import ac.uk.ebi.biostd.persistence.doc.model.CollectionsNames.RQT_FILE_COL
import ac.uk.ebi.biostd.persistence.doc.model.DocRequestStatusChanges
import ac.uk.ebi.biostd.persistence.doc.model.DocSubmissionRequest
import ac.uk.ebi.biostd.persistence.doc.model.DocSubmissionRequestFile
import com.google.common.collect.ImmutableList
import com.mongodb.BasicDBObject
import ebi.ac.uk.coroutines.every
import ebi.ac.uk.model.RequestStatus
import ebi.ac.uk.model.RequestStatus.Companion.PROCESSING
import ebi.ac.uk.model.RequestStatus.PROCESSED
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.count
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.reactive.asFlow
import kotlinx.coroutines.reactive.awaitSingle
import kotlinx.coroutines.reactive.awaitFirstOrNull
import kotlinx.coroutines.reactor.awaitSingle
import kotlinx.coroutines.reactor.awaitSingleOrNull
import org.bson.Document
import org.bson.types.ObjectId
import org.springframework.data.mongodb.core.FindAndModifyOptions
import org.springframework.data.mongodb.core.ReactiveMongoTemplate
Expand Down Expand Up @@ -92,18 +92,20 @@ class SubmissionRequestDocDataRepository(
return submissionRequestRepository.getByAccNoAndStatusIn(request.accNo, PROCESSING) to created
}

/**
* Archive the given request. Note that {@see Document} is used rathet than specific entity type to avoid schema
* changes to affect operation.
*/
suspend fun archiveRequest(
accNo: String,
version: Int,
): Int {
val matchOperation =
match(
where(RQT_FILE_SUB_ACC_NO)
.`is`(accNo)
.andOperator(where(RQT_FILE_SUB_VERSION).`is`(version)),
)
): Long {
var criteria =
where(RQT_FILE_SUB_ACC_NO)
.`is`(accNo)
.andOperator(where(RQT_FILE_SUB_VERSION).`is`(version))

fun archiveRequestFiles(): Flow<DocSubmissionRequestFile> {
suspend fun archiveRequestFiles(): Long {
var mergeOperation =
Aggregation
.merge()
Expand All @@ -115,16 +117,23 @@ class SubmissionRequestDocDataRepository(
val aggregation =
Aggregation
.newAggregation(
DocSubmissionRequestFile::class.java,
matchOperation,
Document::class.java,
match(criteria),
mergeOperation,
).withOptions(AggregationOptions.builder().allowDiskUse(true).build())
return mongoTemplate
.aggregate(aggregation, DocSubmissionRequestFile::class.java)
.asFlow()
).withOptions(
AggregationOptions
.builder()
.allowDiskUse(true)
.skipOutput()
.build(),
)
mongoTemplate
.aggregate(aggregation, RQT_FILE_COL, Document::class.java)
.awaitFirstOrNull()
return mongoTemplate.count(Query().addCriteria(criteria), RQT_FILE_ARCH_COL).awaitSingle()
}

suspend fun archiveRequest(): DocSubmissionRequest {
suspend fun archiveRequest() {
var mergeOperation =
Aggregation
.merge()
Expand All @@ -136,19 +145,22 @@ class SubmissionRequestDocDataRepository(
val aggregation =
Aggregation
.newAggregation(
DocSubmissionRequest::class.java,
matchOperation,
Document::class.java,
match(criteria),
mergeOperation,
).withOptions(AggregationOptions.builder().allowDiskUse(true).build())
return mongoTemplate
.aggregate(aggregation, DocSubmissionRequest::class.java)
.awaitSingle()
).withOptions(
AggregationOptions
.builder()
.allowDiskUse(true)
.skipOutput()
.build(),
)
mongoTemplate
.aggregate(aggregation, RQT_COL, Document::class.java)
.awaitFirstOrNull()
}

val archivedFiles =
archiveRequestFiles()
.every(REPORT_RATE) { "$accNo, $version archived file ${it.index}, path='${it.value.path}'" }
.count()
val archivedFiles = archiveRequestFiles()
archiveRequest()
return archivedFiles
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ interface SubmissionRequestFilesRepository : CoroutineCrudRepository<DocSubmissi
suspend fun countByAccNoAndVersion(
accNo: String,
version: Int,
): Int
): Long

@Query("{ 'accNo': ?0, 'version': ?1, 'status': ?2 }")
@Meta(flags = [CursorOption.NO_TIMEOUT])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class SecurityProperties(
val tokenHash: String,
val environment: String,
val requireActivation: Boolean = false,
val preventFileDelition: Boolean,
val preventFileDeletion: Boolean,
@NestedConfigurationProperty
val instanceKeys: InstanceKeys = InstanceKeys(),
val filesProperties: FilesProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SubmissionRequestValidator(
) {
val (request) =
requestService.onRequest(accNo, version, RequestStatus.INDEXED_CLEANED, processId) {
val requestStatus = if (properties.preventFileDelition) validateRequest(it) else VALIDATED
val requestStatus = if (properties.preventFileDeletion) validateRequest(it) else VALIDATED
RqtUpdate(it.withNewStatus(requestStatus))
}

Expand Down
2 changes: 1 addition & 1 deletion submission/submission-webapp/src/itest/itestsInventory.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Contains test related to submission file deletion.
| DeleteFilesPermissionTest | 1-14 | Regular user deletes their own public submission files |
| DeleteFilesPermissionTest | 1-15 | Regular user with UPDATE_PUBLIC permission delete their own public submission files |
| DeleteFilesPermissionTest | 1-16 | Regular user deletes their own public submission filelist files |
| DeleteFilesPermissionTest | 1-16 | Regular user deletes their own public submission files when preventFileDelition is disable |
| DeleteFilesPermissionTest | 1-16 | Regular user deletes their own public submission files when preventFileDeletion is disable |

### Submit Permission Test Suite

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ class DeleteFilesPermissionTest(
}

@Nested
@SpringBootTest(webEnvironment = RANDOM_PORT, properties = ["app.security.preventFileDelition=false"])
inner class PreventFileDelitionFlag(
@SpringBootTest(webEnvironment = RANDOM_PORT, properties = ["app.security.preventFileDeletion=false"])
inner class PreventFileDeletionFlag(
@Autowired val securityTestService: SecurityTestService,
@LocalServerPort val serverPort: Int,
) {
Expand All @@ -198,7 +198,7 @@ class DeleteFilesPermissionTest(
}

@Test
fun `1-17 Regular user deletes their own public submission files when preventFileDelition is disable`() =
fun `1-17 Regular user deletes their own public submission files when preventFileDeletion is disable`() =
runTest {
val version1 =
tsv {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ app:
tokenHash: biostd-test
environment: TEST
requireActivation: false
preventFileDelition: true
preventFileDeletion: true
filesProperties:
defaultMode: NFS
filesDirPath:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ app:
tokenHash: # Token used for hash authentication
environment: # Current application execution environment
requireActivation: # Indicates whether a new user need activation before being used
preventFileDelition: # Indicates wheter or not to prevent public submission non pagetab file delitions
preventFileDeletion: # Indicates wheter or not to prevent public submission non pagetab file delitions
instanceKeys:
dev: # Instance key for the submission tool DEV environment
beta: # Instance key for the submission tool BETA environment
Expand Down

0 comments on commit 808931e

Please sign in to comment.