From e680f468ac4166eb39c9b6fba3e194ef9262800b Mon Sep 17 00:00:00 2001 From: Tobias Kampmann Date: Tue, 5 Dec 2023 19:33:55 +0100 Subject: [PATCH] chore(deps): code style official renamed to intellij_idea; run ktlintFormat --- backend/.editorconfig | 2 +- .../org/pathoplexus/backend/config/Config.kt | 7 +- .../pathoplexus/backend/model/SubmitModel.kt | 17 +- .../backend/service/CompressionService.kt | 71 +++--- .../backend/service/DatabaseService.kt | 4 +- .../backend/service/SequenceValidator.kt | 54 +---- .../backend/utils/IteratorStreamer.kt | 5 +- .../controller/GetReleasedDataEndpointTest.kt | 4 +- .../controller/PreparedProcessedData.kt | 208 ++++++++---------- .../controller/SubmissionControllerClient.kt | 135 ++++++------ .../controller/SubmissionConvenienceClient.kt | 42 ++-- .../controller/SubmissionJourneyTest.kt | 7 +- .../SubmitProcessedDataEndpointTest.kt | 7 +- .../backend/controller/TestHelpers.kt | 3 +- 14 files changed, 236 insertions(+), 330 deletions(-) diff --git a/backend/.editorconfig b/backend/.editorconfig index 2aec51827..b3b52f846 100644 --- a/backend/.editorconfig +++ b/backend/.editorconfig @@ -6,7 +6,7 @@ insert_final_newline = true end_of_line = crlf [*.{kt,kts}] -ktlint_code_style = official +ktlint_code_style = intellij_idea trailing-comma-on-call-site = true trailing-comma-on-declaration-site = true ij_kotlin_allow_trailing_comma_on_call_site = true diff --git a/backend/src/main/kotlin/org/pathoplexus/backend/config/Config.kt b/backend/src/main/kotlin/org/pathoplexus/backend/config/Config.kt index aa38199e6..5596607db 100644 --- a/backend/src/main/kotlin/org/pathoplexus/backend/config/Config.kt +++ b/backend/src/main/kotlin/org/pathoplexus/backend/config/Config.kt @@ -5,10 +5,9 @@ import org.pathoplexus.backend.api.Organism data class BackendConfig( val instances: Map, ) { - fun getInstanceConfig(organism: Organism) = - instances[organism.name] ?: throw IllegalArgumentException( - "Organism: ${organism.name} not found in backend config. Available organisms: ${instances.keys}", - ) + fun getInstanceConfig(organism: Organism) = instances[organism.name] ?: throw IllegalArgumentException( + "Organism: ${organism.name} not found in backend config. Available organisms: ${instances.keys}", + ) } data class InstanceConfig( diff --git a/backend/src/main/kotlin/org/pathoplexus/backend/model/SubmitModel.kt b/backend/src/main/kotlin/org/pathoplexus/backend/model/SubmitModel.kt index e7906d703..b8dc5e050 100644 --- a/backend/src/main/kotlin/org/pathoplexus/backend/model/SubmitModel.kt +++ b/backend/src/main/kotlin/org/pathoplexus/backend/model/SubmitModel.kt @@ -182,12 +182,7 @@ class SubmitModel( } } - private fun uploadSequences( - uploadId: String, - sequenceStream: InputStream, - batchSize: Int, - organism: Organism, - ) { + private fun uploadSequences(uploadId: String, sequenceStream: InputStream, batchSize: Int, organism: Organism) { log.info { "intermediate storing uploaded sequence data with UploadId $uploadId" } @@ -238,10 +233,7 @@ class SubmitModel( } // TODO(#604): adapt revisions to the new flow - private fun processRevisedData( - metadataFile: MultipartFile, - sequenceFile: MultipartFile, - ): List { + private fun processRevisedData(metadataFile: MultipartFile, sequenceFile: MultipartFile): List { if (metadataFile.originalFilename == null || !metadataFile.originalFilename?.endsWith(".tsv")!!) { throw BadRequestException("Metadata file must have extension .tsv") } @@ -263,10 +255,7 @@ class SubmitModel( } } - private fun validateHeaders( - metadataMap: Map, - sequenceMap: Map, - ) { + private fun validateHeaders(metadataMap: Map, sequenceMap: Map) { val metadataKeysSet = metadataMap.keys.toSet() val sequenceKeysSet = sequenceMap.keys.toSet() validateSubmissionIdSets(metadataKeysSet, sequenceKeysSet) diff --git a/backend/src/main/kotlin/org/pathoplexus/backend/service/CompressionService.kt b/backend/src/main/kotlin/org/pathoplexus/backend/service/CompressionService.kt index 313997ca8..a448dc673 100644 --- a/backend/src/main/kotlin/org/pathoplexus/backend/service/CompressionService.kt +++ b/backend/src/main/kotlin/org/pathoplexus/backend/service/CompressionService.kt @@ -25,11 +25,10 @@ class CompressionService(private val backendConfig: BackendConfig) { uncompressedSequence: String, segmentName: String, organism: Organism, - ): String = - compress( - uncompressedSequence, - getDictionaryForNucleotideSequenceSegments(segmentName, organism), - ) + ): String = compress( + uncompressedSequence, + getDictionaryForNucleotideSequenceSegments(segmentName, organism), + ) private fun decompressUnalignedNucleotideSequence( compressedSequence: String, @@ -40,31 +39,29 @@ class CompressionService(private val backendConfig: BackendConfig) { getDictionaryForNucleotideSequenceSegments(segmentName, organism), ) - fun decompressSequencesInOriginalData(originalData: OriginalData, organism: Organism) = - OriginalData( - originalData.metadata, - originalData - .unalignedNucleotideSequences.mapValues { - decompressUnalignedNucleotideSequence( - it.value, - it.key, - organism, - ) - }, - ) + fun decompressSequencesInOriginalData(originalData: OriginalData, organism: Organism) = OriginalData( + originalData.metadata, + originalData + .unalignedNucleotideSequences.mapValues { + decompressUnalignedNucleotideSequence( + it.value, + it.key, + organism, + ) + }, + ) - fun compressSequencesInOriginalData(originalData: OriginalData, organism: Organism) = - OriginalData( - originalData.metadata, - originalData - .unalignedNucleotideSequences.mapValues { (segmentName, sequenceData) -> - compressUnalignedNucleotideSequence( - sequenceData, - segmentName, - organism, - ) - }, - ) + fun compressSequencesInOriginalData(originalData: OriginalData, organism: Organism) = OriginalData( + originalData.metadata, + originalData + .unalignedNucleotideSequences.mapValues { (segmentName, sequenceData) -> + compressUnalignedNucleotideSequence( + sequenceData, + segmentName, + organism, + ) + }, + ) private fun compress(seq: String, dictionary: ByteArray?): String { val input = seq.toByteArray(StandardCharsets.UTF_8) @@ -99,13 +96,11 @@ class CompressionService(private val backendConfig: BackendConfig) { return String(decompressedBuffer, 0, decompressionReturnCode.toInt(), StandardCharsets.UTF_8) } - private fun getDictionaryForNucleotideSequenceSegments( - segmentName: String, - organism: Organism, - ): ByteArray? = backendConfig - .getInstanceConfig(organism) - .referenceGenomes - .getNucleotideSegmentReference( - segmentName, - )?.toByteArray() + private fun getDictionaryForNucleotideSequenceSegments(segmentName: String, organism: Organism): ByteArray? = + backendConfig + .getInstanceConfig(organism) + .referenceGenomes + .getNucleotideSegmentReference( + segmentName, + )?.toByteArray() } diff --git a/backend/src/main/kotlin/org/pathoplexus/backend/service/DatabaseService.kt b/backend/src/main/kotlin/org/pathoplexus/backend/service/DatabaseService.kt index fc0af57e7..6bef0cbb4 100644 --- a/backend/src/main/kotlin/org/pathoplexus/backend/service/DatabaseService.kt +++ b/backend/src/main/kotlin/org/pathoplexus/backend/service/DatabaseService.kt @@ -189,9 +189,7 @@ class DatabaseService( } } - private fun addMissingKeysForInsertions( - submittedProcessedData: SubmittedProcessedData, - ): SubmittedProcessedData { + private fun addMissingKeysForInsertions(submittedProcessedData: SubmittedProcessedData): SubmittedProcessedData { val nucleotideInsertions = referenceGenome.nucleotideSequences.associate { if (it.name in submittedProcessedData.data.nucleotideInsertions.keys) { it.name to submittedProcessedData.data.nucleotideInsertions[it.name]!! diff --git a/backend/src/main/kotlin/org/pathoplexus/backend/service/SequenceValidator.kt b/backend/src/main/kotlin/org/pathoplexus/backend/service/SequenceValidator.kt index f631050a7..0a10db7dd 100644 --- a/backend/src/main/kotlin/org/pathoplexus/backend/service/SequenceValidator.kt +++ b/backend/src/main/kotlin/org/pathoplexus/backend/service/SequenceValidator.kt @@ -89,9 +89,7 @@ class SequenceValidator( validateAminoAcidSequences(submittedProcessedData) } - private fun validateMetadata( - submittedProcessedData: SubmittedProcessedData, - ) { + private fun validateMetadata(submittedProcessedData: SubmittedProcessedData) { val metadataFields = schema.metadata validateNoUnknownInMetaData(submittedProcessedData.data.metadata, metadataFields.map { it.name }) @@ -100,10 +98,7 @@ class SequenceValidator( } } - private fun validateNoUnknownInMetaData( - data: Map, - known: List, - ) { + private fun validateNoUnknownInMetaData(data: Map, known: List) { val unknownMetadataKeys = data.keys.subtract(known.toSet()) if (unknownMetadataKeys.isNotEmpty()) { val unknownMetadataKeysString = unknownMetadataKeys.sorted().joinToString(", ") @@ -111,10 +106,7 @@ class SequenceValidator( } } - private fun validateKnownMetadataField( - metadata: Metadata, - submittedProcessedData: SubmittedProcessedData, - ) { + private fun validateKnownMetadataField(metadata: Metadata, submittedProcessedData: SubmittedProcessedData) { val fieldName = metadata.name val fieldValue = submittedProcessedData.data.metadata[fieldName] @@ -192,9 +184,7 @@ class SequenceValidator( return pangoLineageCandidate.matches(pangoLineageRegex) } - private fun validateNucleotideSequences( - submittedProcessedData: SubmittedProcessedData, - ) { + private fun validateNucleotideSequences(submittedProcessedData: SubmittedProcessedData) { for (segment in referenceGenome.nucleotideSequences) { validateNoMissingSegment( segment, @@ -268,10 +258,7 @@ class SequenceValidator( } } - private fun validateNoUnknownSegment( - dataToValidate: Map, - sequenceGrouping: String, - ) { + private fun validateNoUnknownSegment(dataToValidate: Map, sequenceGrouping: String) { val unknownSegments = dataToValidate.keys.subtract(referenceGenome.nucleotideSequences.map { it.name }.toSet()) if (unknownSegments.isNotEmpty()) { val unknownSegmentsString = unknownSegments.sorted().joinToString(", ") @@ -281,10 +268,7 @@ class SequenceValidator( } } - private fun validateNoUnknownNucleotideSymbol( - dataToValidate: Map, - sequenceGrouping: String, - ) { + private fun validateNoUnknownNucleotideSymbol(dataToValidate: Map, sequenceGrouping: String) { for (sequence in dataToValidate) { val invalidSymbols = sequence.value.getInvalidSymbols() if (invalidSymbols.isNotEmpty()) { @@ -296,9 +280,7 @@ class SequenceValidator( } } - private fun validateNoUnknownNucleotideSymbolInInsertion( - dataToValidate: Map>, - ) { + private fun validateNoUnknownNucleotideSymbolInInsertion(dataToValidate: Map>) { for (sequence in dataToValidate) { for (insertion in sequence.value) { val invalidSymbols = insertion.sequence.getInvalidSymbols() @@ -320,9 +302,7 @@ class SequenceValidator( where ValidSymbols : Enum, ValidSymbols : Symbol = enumValues().any { it.symbol == this } - private fun validateAminoAcidSequences( - submittedProcessedData: SubmittedProcessedData, - ) { + private fun validateAminoAcidSequences(submittedProcessedData: SubmittedProcessedData) { for (gene in referenceGenome.genes) { validateNoMissingGene(gene, submittedProcessedData) validateLengthOfSequence( @@ -346,19 +326,13 @@ class SequenceValidator( validateNoUnknownAminoAcidSymbolInInsertion(submittedProcessedData.data.aminoAcidInsertions) } - private fun validateNoMissingGene( - gene: ReferenceSequence, - submittedProcessedData: SubmittedProcessedData, - ) { + private fun validateNoMissingGene(gene: ReferenceSequence, submittedProcessedData: SubmittedProcessedData) { if (!submittedProcessedData.data.alignedAminoAcidSequences.containsKey(gene.name)) { throw ProcessingValidationException("Missing the required gene '${gene.name}'.") } } - private fun validateNoUnknownGeneInData( - data: Map, - geneGrouping: String, - ) { + private fun validateNoUnknownGeneInData(data: Map, geneGrouping: String) { val unknownGenes = data.keys.subtract(referenceGenome.genes.map { it.name }.toSet()) if (unknownGenes.isNotEmpty()) { val unknownGenesString = unknownGenes.sorted().joinToString(", ") @@ -366,9 +340,7 @@ class SequenceValidator( } } - private fun validateNoUnknownAminoAcidSymbol( - dataToValidate: Map, - ) { + private fun validateNoUnknownAminoAcidSymbol(dataToValidate: Map) { for (sequence in dataToValidate) { val invalidSymbols = sequence.value.getInvalidSymbols() if (invalidSymbols.isNotEmpty()) { @@ -380,9 +352,7 @@ class SequenceValidator( } } - private fun validateNoUnknownAminoAcidSymbolInInsertion( - dataToValidate: Map>, - ) { + private fun validateNoUnknownAminoAcidSymbolInInsertion(dataToValidate: Map>) { for (sequence in dataToValidate) { for (insertion in sequence.value) { val invalidSymbols = insertion.sequence.getInvalidSymbols() diff --git a/backend/src/main/kotlin/org/pathoplexus/backend/utils/IteratorStreamer.kt b/backend/src/main/kotlin/org/pathoplexus/backend/utils/IteratorStreamer.kt index 8df0836f9..43ed1c992 100644 --- a/backend/src/main/kotlin/org/pathoplexus/backend/utils/IteratorStreamer.kt +++ b/backend/src/main/kotlin/org/pathoplexus/backend/utils/IteratorStreamer.kt @@ -12,10 +12,7 @@ class IteratorStreamer(private val objectMapper: ObjectMapper) { fun streamAsNdjson(iterable: Iterable, outputStream: OutputStream) = streamAsNdjson(iterable.iterator(), outputStream) - fun streamAsNdjson( - iterator: Iterator, - outputStream: OutputStream, - ) { + fun streamAsNdjson(iterator: Iterator, outputStream: OutputStream) { iterator.forEach { val json = objectMapper.writeValueAsString(it) outputStream.write(json.toByteArray()) diff --git a/backend/src/test/kotlin/org/pathoplexus/backend/controller/GetReleasedDataEndpointTest.kt b/backend/src/test/kotlin/org/pathoplexus/backend/controller/GetReleasedDataEndpointTest.kt index d891c7b0e..b8d8808cf 100644 --- a/backend/src/test/kotlin/org/pathoplexus/backend/controller/GetReleasedDataEndpointTest.kt +++ b/backend/src/test/kotlin/org/pathoplexus/backend/controller/GetReleasedDataEndpointTest.kt @@ -22,7 +22,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status import java.time.LocalDateTime import java.time.format.DateTimeFormatter -private const val numberOfFieldsWithUnknownValue = 2 +private const val NUMBER_OF_FIELDS_WITH_UNKNOWN_VALUE = 2 @EndpointTest class GetReleasedDataEndpointTest( @@ -77,7 +77,7 @@ class GetReleasedDataEndpointTest( "versionStatus" to TextNode("LATEST_VERSION"), ) - assertThat(it.metadata.size, `is`(expectedMetadata.size + numberOfFieldsWithUnknownValue)) + assertThat(it.metadata.size, `is`(expectedMetadata.size + NUMBER_OF_FIELDS_WITH_UNKNOWN_VALUE)) for ((key, value) in it.metadata) { when (key) { "submittedAt" -> { diff --git a/backend/src/test/kotlin/org/pathoplexus/backend/controller/PreparedProcessedData.kt b/backend/src/test/kotlin/org/pathoplexus/backend/controller/PreparedProcessedData.kt index e2a39b921..ece77173a 100644 --- a/backend/src/test/kotlin/org/pathoplexus/backend/controller/PreparedProcessedData.kt +++ b/backend/src/test/kotlin/org/pathoplexus/backend/controller/PreparedProcessedData.kt @@ -70,32 +70,30 @@ object PreparedProcessedData { fun successfullyProcessed( accession: Accession = DefaultFiles.firstAccession, version: Long = defaultSuccessfulSubmittedData.version, - ) = - defaultSuccessfulSubmittedData.withValues( - accession = accession, - version = version, - ) + ) = defaultSuccessfulSubmittedData.withValues( + accession = accession, + version = version, + ) fun successfullyProcessedOtherOrganismData( accession: Accession = DefaultFiles.firstAccession, version: Long = defaultSuccessfulSubmittedData.version, - ) = - defaultSuccessfulSubmittedData.withValues( - accession = accession, - version = version, - data = ProcessedData( - metadata = mapOf( - "date" to TextNode("2022-12-24"), - "specialOtherField" to TextNode("some value"), - "pangoLineage" to TextNode("B.1.1.7"), - ), - alignedNucleotideSequences = mapOf("main" to "ATCG"), - alignedAminoAcidSequences = mapOf("gene" to "MADS"), - unalignedNucleotideSequences = mapOf("main" to "ATCG"), - nucleotideInsertions = mapOf("main" to listOf(Insertion(123, "ACTG"))), - aminoAcidInsertions = mapOf("gene" to listOf(Insertion(123, "MADS"))), + ) = defaultSuccessfulSubmittedData.withValues( + accession = accession, + version = version, + data = ProcessedData( + metadata = mapOf( + "date" to TextNode("2022-12-24"), + "specialOtherField" to TextNode("some value"), + "pangoLineage" to TextNode("B.1.1.7"), ), - ) + alignedNucleotideSequences = mapOf("main" to "ATCG"), + alignedAminoAcidSequences = mapOf("gene" to "MADS"), + unalignedNucleotideSequences = mapOf("main" to "ATCG"), + nucleotideInsertions = mapOf("main" to listOf(Insertion(123, "ACTG"))), + aminoAcidInsertions = mapOf("gene" to listOf(Insertion(123, "MADS"))), + ), + ) fun withNullForFields(accession: Accession = DefaultFiles.firstAccession, fields: List) = defaultSuccessfulSubmittedData.withValues( @@ -155,64 +153,59 @@ object PreparedProcessedData { fun withMissingSegmentInUnalignedNucleotideSequences( accession: Accession = DefaultFiles.firstAccession, segment: SegmentName, - ) = - defaultSuccessfulSubmittedData.withValues( - accession = accession, - data = defaultProcessedData.withValues( - unalignedNucleotideSequences = defaultProcessedData.unalignedNucleotideSequences - segment, - ), - ) + ) = defaultSuccessfulSubmittedData.withValues( + accession = accession, + data = defaultProcessedData.withValues( + unalignedNucleotideSequences = defaultProcessedData.unalignedNucleotideSequences - segment, + ), + ) fun withMissingSegmentInAlignedNucleotideSequences( accession: Accession = DefaultFiles.firstAccession, segment: SegmentName, - ) = - defaultSuccessfulSubmittedData.withValues( - accession = accession, - data = defaultProcessedData.withValues( - alignedNucleotideSequences = defaultProcessedData.alignedNucleotideSequences - segment, - ), - ) + ) = defaultSuccessfulSubmittedData.withValues( + accession = accession, + data = defaultProcessedData.withValues( + alignedNucleotideSequences = defaultProcessedData.alignedNucleotideSequences - segment, + ), + ) fun withUnknownSegmentInAlignedNucleotideSequences( accession: Accession = DefaultFiles.firstAccession, segment: SegmentName, - ) = - defaultSuccessfulSubmittedData.withValues( - accession = accession, - data = defaultProcessedData.withValues( - alignedNucleotideSequences = defaultProcessedData.alignedNucleotideSequences + (segment to "NNNN"), - ), - ) + ) = defaultSuccessfulSubmittedData.withValues( + accession = accession, + data = defaultProcessedData.withValues( + alignedNucleotideSequences = defaultProcessedData.alignedNucleotideSequences + (segment to "NNNN"), + ), + ) fun withUnknownSegmentInUnalignedNucleotideSequences( accession: Accession = DefaultFiles.firstAccession, segment: SegmentName, - ) = - defaultSuccessfulSubmittedData.withValues( - accession = accession, - data = defaultProcessedData.withValues( - unalignedNucleotideSequences = defaultProcessedData.unalignedNucleotideSequences + (segment to "NNNN"), - ), - ) + ) = defaultSuccessfulSubmittedData.withValues( + accession = accession, + data = defaultProcessedData.withValues( + unalignedNucleotideSequences = defaultProcessedData.unalignedNucleotideSequences + (segment to "NNNN"), + ), + ) fun withUnknownSegmentInNucleotideInsertions( accession: Accession = DefaultFiles.firstAccession, segment: SegmentName, - ) = - defaultSuccessfulSubmittedData.withValues( - accession = accession, - data = defaultProcessedData.withValues( - nucleotideInsertions = defaultProcessedData.nucleotideInsertions + ( - segment to listOf( - Insertion( - 123, - "ACTG", - ), - ) + ) = defaultSuccessfulSubmittedData.withValues( + accession = accession, + data = defaultProcessedData.withValues( + nucleotideInsertions = defaultProcessedData.nucleotideInsertions + ( + segment to listOf( + Insertion( + 123, + "ACTG", ), - ), - ) + ) + ), + ), + ) fun withAlignedNucleotideSequenceOfWrongLength( accession: Accession = DefaultFiles.firstAccession, @@ -267,10 +260,7 @@ object PreparedProcessedData { ) } - fun withMissingGeneInAminoAcidSequences( - accession: Accession = DefaultFiles.firstAccession, - gene: GeneName, - ) = + fun withMissingGeneInAminoAcidSequences(accession: Accession = DefaultFiles.firstAccession, gene: GeneName) = defaultSuccessfulSubmittedData.withValues( accession = accession, data = defaultProcessedData.withValues( @@ -278,10 +268,7 @@ object PreparedProcessedData { ), ) - fun withUnknownGeneInAminoAcidSequences( - accession: Accession = DefaultFiles.firstAccession, - gene: GeneName, - ) = + fun withUnknownGeneInAminoAcidSequences(accession: Accession = DefaultFiles.firstAccession, gene: GeneName) = defaultSuccessfulSubmittedData.withValues( accession = accession, data = defaultProcessedData.withValues( @@ -289,10 +276,7 @@ object PreparedProcessedData { ), ) - fun withUnknownGeneInAminoAcidInsertions( - accession: Accession = DefaultFiles.firstAccession, - gene: GeneName, - ) = + fun withUnknownGeneInAminoAcidInsertions(accession: Accession = DefaultFiles.firstAccession, gene: GeneName) = defaultSuccessfulSubmittedData.withValues( accession = accession, data = defaultProcessedData.withValues( @@ -347,55 +331,53 @@ object PreparedProcessedData { ) } - fun withErrors(accession: Accession = DefaultFiles.firstAccession) = - defaultSuccessfulSubmittedData.withValues( - accession = accession, - errors = listOf( - PreprocessingAnnotation( - source = listOf( - PreprocessingAnnotationSource( - PreprocessingAnnotationSourceType.Metadata, - "host", - ), + fun withErrors(accession: Accession = DefaultFiles.firstAccession) = defaultSuccessfulSubmittedData.withValues( + accession = accession, + errors = listOf( + PreprocessingAnnotation( + source = listOf( + PreprocessingAnnotationSource( + PreprocessingAnnotationSourceType.Metadata, + "host", ), - "Not this kind of host", ), - PreprocessingAnnotation( - source = listOf( - PreprocessingAnnotationSource( - PreprocessingAnnotationSourceType.NucleotideSequence, - "main", - ), + "Not this kind of host", + ), + PreprocessingAnnotation( + source = listOf( + PreprocessingAnnotationSource( + PreprocessingAnnotationSourceType.NucleotideSequence, + "main", ), - "dummy nucleotide sequence error", ), + "dummy nucleotide sequence error", ), - ) - - fun withWarnings(accession: Accession = DefaultFiles.firstAccession) = - defaultSuccessfulSubmittedData.withValues( - accession = accession, - warnings = listOf( - PreprocessingAnnotation( - source = listOf( - PreprocessingAnnotationSource( - PreprocessingAnnotationSourceType.Metadata, - "host", - ), + ), + ) + + fun withWarnings(accession: Accession = DefaultFiles.firstAccession) = defaultSuccessfulSubmittedData.withValues( + accession = accession, + warnings = listOf( + PreprocessingAnnotation( + source = listOf( + PreprocessingAnnotationSource( + PreprocessingAnnotationSourceType.Metadata, + "host", ), - "Not this kind of host", ), - PreprocessingAnnotation( - source = listOf( - PreprocessingAnnotationSource( - PreprocessingAnnotationSourceType.NucleotideSequence, - "main", - ), + "Not this kind of host", + ), + PreprocessingAnnotation( + source = listOf( + PreprocessingAnnotationSource( + PreprocessingAnnotationSourceType.NucleotideSequence, + "main", ), - "dummy nucleotide sequence error", ), + "dummy nucleotide sequence error", ), - ) + ), + ) } fun SubmittedProcessedData.withValues( diff --git a/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmissionControllerClient.kt b/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmissionControllerClient.kt index 1792f0bab..b4167eaf7 100644 --- a/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmissionControllerClient.kt +++ b/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmissionControllerClient.kt @@ -22,24 +22,22 @@ class SubmissionControllerClient(private val mockMvc: MockMvc, private val objec sequencesFile: MockMultipartFile, organism: String = DEFAULT_ORGANISM, jwt: String? = jwtForDefaultUser, - ): ResultActions = - mockMvc.perform( - multipart(addOrganismToPath("/submit", organism = organism)) - .file(sequencesFile) - .file(metadataFile) - .withAuth(jwt), - ) + ): ResultActions = mockMvc.perform( + multipart(addOrganismToPath("/submit", organism = organism)) + .file(sequencesFile) + .file(metadataFile) + .withAuth(jwt), + ) fun extractUnprocessedData( numberOfSequenceEntries: Int, organism: String = DEFAULT_ORGANISM, jwt: String? = jwtForDefaultUser, - ): ResultActions = - mockMvc.perform( - post(addOrganismToPath("/extract-unprocessed-data", organism = organism)) - .withAuth(jwt) - .param("numberOfSequenceEntries", numberOfSequenceEntries.toString()), - ) + ): ResultActions = mockMvc.perform( + post(addOrganismToPath("/extract-unprocessed-data", organism = organism)) + .withAuth(jwt) + .param("numberOfSequenceEntries", numberOfSequenceEntries.toString()), + ) fun submitProcessedData( vararg submittedProcessedData: SubmittedProcessedData, @@ -55,44 +53,40 @@ class SubmissionControllerClient(private val mockMvc: MockMvc, private val objec submittedProcessedData: String, organism: String = DEFAULT_ORGANISM, jwt: String? = jwtForDefaultUser, - ): ResultActions = - mockMvc.perform( - post(addOrganismToPath("/submit-processed-data", organism = organism)) - .contentType(MediaType.APPLICATION_NDJSON_VALUE) - .withAuth(jwt) - .content(submittedProcessedData), - ) + ): ResultActions = mockMvc.perform( + post(addOrganismToPath("/submit-processed-data", organism = organism)) + .contentType(MediaType.APPLICATION_NDJSON_VALUE) + .withAuth(jwt) + .content(submittedProcessedData), + ) fun getSequenceEntriesOfUser( organism: String = DEFAULT_ORGANISM, jwt: String? = jwtForDefaultUser, - ): ResultActions = - mockMvc.perform( - get(addOrganismToPath("/get-sequences-of-user", organism = organism)) - .withAuth(jwt), - ) + ): ResultActions = mockMvc.perform( + get(addOrganismToPath("/get-sequences-of-user", organism = organism)) + .withAuth(jwt), + ) fun getSequenceEntryThatHasErrors( accession: Accession, version: Long, organism: String = DEFAULT_ORGANISM, jwt: String? = jwtForDefaultUser, - ): ResultActions = - mockMvc.perform( - get(addOrganismToPath("/get-data-to-edit/$accession/$version", organism = organism)) - .withAuth(jwt), - ) + ): ResultActions = mockMvc.perform( + get(addOrganismToPath("/get-data-to-edit/$accession/$version", organism = organism)) + .withAuth(jwt), + ) fun getNumberOfSequenceEntriesThatHaveErrors( numberOfSequenceEntries: Int, organism: String = DEFAULT_ORGANISM, jwt: String? = jwtForDefaultUser, - ): ResultActions = - mockMvc.perform( - get(addOrganismToPath("/get-data-to-edit", organism = organism)) - .withAuth(jwt) - .param("numberOfSequenceEntries", numberOfSequenceEntries.toString()), - ) + ): ResultActions = mockMvc.perform( + get(addOrganismToPath("/get-data-to-edit", organism = organism)) + .withAuth(jwt) + .param("numberOfSequenceEntries", numberOfSequenceEntries.toString()), + ) fun submitEditedSequenceEntryVersion( editedData: UnprocessedData, @@ -111,37 +105,34 @@ class SubmissionControllerClient(private val mockMvc: MockMvc, private val objec listOfSequencesToApprove: List, organism: String = DEFAULT_ORGANISM, jwt: String? = jwtForDefaultUser, - ): ResultActions = - mockMvc.perform( - post(addOrganismToPath("/approve-processed-data", organism = organism)) - .contentType(MediaType.APPLICATION_JSON) - .content("""{"accessionVersions":${objectMapper.writeValueAsString(listOfSequencesToApprove)}}""") - .withAuth(jwt), - ) + ): ResultActions = mockMvc.perform( + post(addOrganismToPath("/approve-processed-data", organism = organism)) + .contentType(MediaType.APPLICATION_JSON) + .content("""{"accessionVersions":${objectMapper.writeValueAsString(listOfSequencesToApprove)}}""") + .withAuth(jwt), + ) fun revokeSequenceEntries( listOfSequenceEntriesToRevoke: List, organism: String = DEFAULT_ORGANISM, jwt: String? = jwtForDefaultUser, - ): ResultActions = - mockMvc.perform( - post(addOrganismToPath("/revoke", organism = organism)) - .contentType(MediaType.APPLICATION_JSON) - .content("""{"accessions":$listOfSequenceEntriesToRevoke}""") - .withAuth(jwt), - ) + ): ResultActions = mockMvc.perform( + post(addOrganismToPath("/revoke", organism = organism)) + .contentType(MediaType.APPLICATION_JSON) + .content("""{"accessions":$listOfSequenceEntriesToRevoke}""") + .withAuth(jwt), + ) fun confirmRevocation( listOfSequencesToConfirm: List, organism: String = DEFAULT_ORGANISM, jwt: String? = jwtForDefaultUser, - ): ResultActions = - mockMvc.perform( - post(addOrganismToPath("/confirm-revocation", organism = organism)) - .contentType(MediaType.APPLICATION_JSON) - .content("""{"accessionVersions":${objectMapper.writeValueAsString(listOfSequencesToConfirm)}}""") - .withAuth(jwt), - ) + ): ResultActions = mockMvc.perform( + post(addOrganismToPath("/confirm-revocation", organism = organism)) + .contentType(MediaType.APPLICATION_JSON) + .content("""{"accessionVersions":${objectMapper.writeValueAsString(listOfSequencesToConfirm)}}""") + .withAuth(jwt), + ) fun getReleasedData(organism: String = DEFAULT_ORGANISM, jwt: String? = jwtForDefaultUser): ResultActions = mockMvc.perform( @@ -153,26 +144,24 @@ class SubmissionControllerClient(private val mockMvc: MockMvc, private val objec listOfAccessionVersionsToDelete: List, organism: String = DEFAULT_ORGANISM, jwt: String? = jwtForDefaultUser, - ): ResultActions = - mockMvc.perform( - delete(addOrganismToPath("/delete-sequence-entry-versions", organism = organism)) - .withAuth(jwt) - .contentType(MediaType.APPLICATION_JSON) - .content( - """{"accessionVersions":${objectMapper.writeValueAsString(listOfAccessionVersionsToDelete)}}""", - ), - ) + ): ResultActions = mockMvc.perform( + delete(addOrganismToPath("/delete-sequence-entry-versions", organism = organism)) + .withAuth(jwt) + .contentType(MediaType.APPLICATION_JSON) + .content( + """{"accessionVersions":${objectMapper.writeValueAsString(listOfAccessionVersionsToDelete)}}""", + ), + ) fun reviseSequenceEntries( metadataFile: MockMultipartFile, sequencesFile: MockMultipartFile, organism: String = DEFAULT_ORGANISM, jwt: String? = jwtForDefaultUser, - ): ResultActions = - mockMvc.perform( - multipart(addOrganismToPath("/revise", organism = organism)) - .file(sequencesFile) - .file(metadataFile) - .withAuth(jwt), - ) + ): ResultActions = mockMvc.perform( + multipart(addOrganismToPath("/revise", organism = organism)) + .file(sequencesFile) + .file(metadataFile) + .withAuth(jwt), + ) } diff --git a/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmissionConvenienceClient.kt b/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmissionConvenienceClient.kt index 473a8a108..8baba01b4 100644 --- a/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmissionConvenienceClient.kt +++ b/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmissionConvenienceClient.kt @@ -115,13 +115,10 @@ class SubmissionConvenienceClient( fun extractUnprocessedData( numberOfSequenceEntries: Int = DefaultFiles.NUMBER_OF_SEQUENCES, organism: String = DEFAULT_ORGANISM, - ) = - client.extractUnprocessedData(numberOfSequenceEntries, organism) - .expectNdjsonAndGetContent() + ) = client.extractUnprocessedData(numberOfSequenceEntries, organism) + .expectNdjsonAndGetContent() - fun prepareDatabaseWith( - vararg processedData: SubmittedProcessedData, - ) { + fun prepareDatabaseWith(vararg processedData: SubmittedProcessedData) { submitDefaultFiles() extractUnprocessedData() client.submitProcessedData(*processedData) @@ -139,15 +136,11 @@ class SubmissionConvenienceClient( ) } - fun getSequenceEntriesOfUserInState( - userName: String = USER_NAME, - status: Status, - ): List = getSequenceEntriesOfUser(userName).filter { it.status == status } + fun getSequenceEntriesOfUserInState(userName: String = USER_NAME, status: Status): List = + getSequenceEntriesOfUser(userName).filter { it.status == status } - fun getSequenceEntryOfUser( - accessionVersion: AccessionVersion, - userName: String = USER_NAME, - ) = getSequenceEntryOfUser(accessionVersion.accession, accessionVersion.version, userName) + fun getSequenceEntryOfUser(accessionVersion: AccessionVersion, userName: String = USER_NAME) = + getSequenceEntryOfUser(accessionVersion.accession, accessionVersion.version, userName) fun getSequenceEntryOfUser( accession: Accession, @@ -165,18 +158,15 @@ class SubmissionConvenienceClient( accession: Accession, version: Long, userName: String = USER_NAME, - ): SequenceEntryVersionToEdit = - deserializeJsonResponse( - client.getSequenceEntryThatHasErrors( - accession = accession, - version = version, - jwt = generateJwtForUser(userName), - ), - ) - - fun submitDefaultEditedData( - userName: String = USER_NAME, - ) { + ): SequenceEntryVersionToEdit = deserializeJsonResponse( + client.getSequenceEntryThatHasErrors( + accession = accession, + version = version, + jwt = generateJwtForUser(userName), + ), + ) + + fun submitDefaultEditedData(userName: String = USER_NAME) { DefaultFiles.allAccessions.forEach { accession -> client.submitEditedSequenceEntryVersion( UnprocessedData(accession, 1L, defaultOriginalData), diff --git a/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmissionJourneyTest.kt b/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmissionJourneyTest.kt index 11352bab7..2e2fecb2e 100644 --- a/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmissionJourneyTest.kt +++ b/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmissionJourneyTest.kt @@ -154,10 +154,9 @@ class SubmissionJourneyTest( ) } - private fun getAccessionVersionsOfProcessedData(processedData: List) = - processedData - .map { it.metadata } - .map { it["accessionVersion"]!!.asText() } + private fun getAccessionVersionsOfProcessedData(processedData: List) = processedData + .map { it.metadata } + .map { it["accessionVersion"]!!.asText() } private fun getAccessionVersions(sequenceEntryVersions: List) = sequenceEntryVersions.map { it.displayAccessionVersion() } diff --git a/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmitProcessedDataEndpointTest.kt b/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmitProcessedDataEndpointTest.kt index 370a243b1..1890ab992 100644 --- a/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmitProcessedDataEndpointTest.kt +++ b/backend/src/test/kotlin/org/pathoplexus/backend/controller/SubmitProcessedDataEndpointTest.kt @@ -334,10 +334,9 @@ class SubmitProcessedDataEndpointTest( companion object { @JvmStatic - fun provideInvalidDataScenarios() = - provideInvalidMetadataScenarios() + - provideInvalidNucleotideSequenceDataScenarios() + - provideInvalidAminoAcidSequenceDataScenarios() + fun provideInvalidDataScenarios() = provideInvalidMetadataScenarios() + + provideInvalidNucleotideSequenceDataScenarios() + + provideInvalidAminoAcidSequenceDataScenarios() @JvmStatic fun provideInvalidMetadataScenarios() = listOf( diff --git a/backend/src/test/kotlin/org/pathoplexus/backend/controller/TestHelpers.kt b/backend/src/test/kotlin/org/pathoplexus/backend/controller/TestHelpers.kt index 34295a3b0..d4703feec 100644 --- a/backend/src/test/kotlin/org/pathoplexus/backend/controller/TestHelpers.kt +++ b/backend/src/test/kotlin/org/pathoplexus/backend/controller/TestHelpers.kt @@ -24,8 +24,7 @@ fun AccessionVersionInterface.toAccessionVersion() = AccessionVersion(this.acces fun List.getAccessionVersions() = map { it.toAccessionVersion() } -fun addOrganismToPath(path: String, organism: String = DEFAULT_ORGANISM) = - "/$organism/${path.trimStart('/')}" +fun addOrganismToPath(path: String, organism: String = DEFAULT_ORGANISM) = "/$organism/${path.trimStart('/')}" val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper().findAndRegisterModules()