Skip to content

Commit

Permalink
refactor(backend): rename class #704
Browse files Browse the repository at this point in the history
  • Loading branch information
fengelniederhammer committed Jan 24, 2024
1 parent 53b4f92 commit 4e7c662
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import org.loculus.backend.api.Status.IN_PROCESSING
import org.loculus.backend.api.Status.RECEIVED
import org.loculus.backend.api.SubmittedProcessedData
import org.loculus.backend.api.UnprocessedData
import org.loculus.backend.config.BackendConfig
import org.loculus.backend.controller.BadRequestException
import org.loculus.backend.controller.ProcessingValidationException
import org.loculus.backend.controller.UnprocessableEntityException
Expand All @@ -54,7 +53,7 @@ private val log = KotlinLogging.logger { }
@Service
@Transactional
class DatabaseService(
private val sequenceValidatorFactory: SequenceValidatorFactory,
private val processedSequenceEntryValidatorFactory: ProcessedSequenceEntryValidatorFactory,
private val submissionPreconditionValidator: SubmissionPreconditionValidator,
private val groupManagementPreconditionValidator: GroupManagementPreconditionValidator,
private val objectMapper: ObjectMapper,
Expand Down Expand Up @@ -156,7 +155,7 @@ class DatabaseService(
}

private fun validateProcessedData(submittedProcessedData: SubmittedProcessedData, organism: Organism) = try {
sequenceValidatorFactory.create(organism).validateSequence(submittedProcessedData.data)
processedSequenceEntryValidatorFactory.create(organism).validate(submittedProcessedData.data)
} catch (validationException: ProcessingValidationException) {
throwIfIsSubmissionForWrongOrganism(submittedProcessedData, organism)
throw validationException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ enum class NucleotideSymbols(override val symbol: Char) : Symbol {
}

@Component
class SequenceValidatorFactory(private val backendConfig: BackendConfig) {
fun create(organism: Organism): SequenceValidator {
class ProcessedSequenceEntryValidatorFactory(private val backendConfig: BackendConfig) {
fun create(organism: Organism): ProcessedSequenceEntryValidator {
val instanceConfig = backendConfig.instances[organism.name]!!
return SequenceValidator(instanceConfig.schema, instanceConfig.referenceGenomes)
return ProcessedSequenceEntryValidator(instanceConfig.schema, instanceConfig.referenceGenomes)
}
}

class SequenceValidator(
class ProcessedSequenceEntryValidator(
private val schema: Schema,
private val referenceGenome: ReferenceGenome,
) {
fun validateSequence(processedData: ProcessedData): ProcessedData {
fun validate(processedData: ProcessedData): ProcessedData {
val processedDataWithAllMetadataFields = validateMetadata(processedData)
validateNucleotideSequences(processedDataWithAllMetadataFields)
validateAminoAcidSequences(processedDataWithAllMetadataFields)
Expand Down

0 comments on commit 4e7c662

Please sign in to comment.