Skip to content

Commit

Permalink
refactor(backend): rename enum SiloVersionStatus to VersionStatus
Browse files Browse the repository at this point in the history
… and document the enum (#2817)

---------

Co-authored-by: Theo Sanderson <theo@sndrsn.co.uk>
  • Loading branch information
corneliusroemer and theosanderson committed Sep 17, 2024
1 parent 096b1d2 commit 442e100
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ enum class PreprocessingStatus {
FINISHED,
}

enum class SiloVersionStatus {
REVOKED,
REVISED,
LATEST_VERSION,
enum class VersionStatus {
REVOKED, // This is not the highest version of the sequence entry, and a higher version is a revocation
REVISED, // This is not the highest version of the sequence entry, and no higher version is a revocation
LATEST_VERSION, // This is the highest version of the sequence entry
}

enum class CompressionFormat(val compressionName: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.loculus.backend.api.DataUseTerms
import org.loculus.backend.api.GeneticSequence
import org.loculus.backend.api.Organism
import org.loculus.backend.api.ProcessedData
import org.loculus.backend.api.SiloVersionStatus
import org.loculus.backend.api.VersionStatus
import org.loculus.backend.config.BackendConfig
import org.loculus.backend.service.submission.RawProcessedData
import org.loculus.backend.service.submission.SubmissionDatabaseService
Expand Down Expand Up @@ -47,7 +47,7 @@ class ReleasedDataModel(
latestVersions: Map<Accession, Version>,
latestRevocationVersions: Map<Accession, Version>,
): ProcessedData<GeneticSequence> {
val siloVersionStatus = computeSiloVersionStatus(rawProcessedData, latestVersions, latestRevocationVersions)
val versionStatus = computeVersionStatus(rawProcessedData, latestVersions, latestRevocationVersions)

val currentDataUseTerms = computeDataUseTerm(rawProcessedData)
val restrictedDataUseTermsUntil = if (currentDataUseTerms is DataUseTerms.Restricted) {
Expand All @@ -69,7 +69,7 @@ class ReleasedDataModel(
("submittedAtTimestamp" to LongNode(rawProcessedData.submittedAtTimestamp.toTimestamp())) +
("releasedAtTimestamp" to LongNode(rawProcessedData.releasedAtTimestamp.toTimestamp())) +
("releasedDate" to TextNode(rawProcessedData.releasedAtTimestamp.toUtcDateString())) +
("versionStatus" to TextNode(siloVersionStatus.name)) +
("versionStatus" to TextNode(versionStatus.name)) +
("dataUseTerms" to TextNode(currentDataUseTerms.type.name)) +
("dataUseTermsRestrictedUntil" to restrictedDataUseTermsUntil) +
("versionComment" to TextNode(rawProcessedData.versionComment))
Expand Down Expand Up @@ -102,22 +102,26 @@ class ReleasedDataModel(
DataUseTerms.Open
}

private fun computeSiloVersionStatus(
// LATEST_VERSION: This is the highest version of the sequence entry
// REVOKED: This is not the highest version of the sequence entry, and a higher version is a revocation
// REVISED: This is not the highest version of the sequence entry, and no higher version is a revocation
// Note: a revocation entry is only REVOKED when there's a higher version that is a revocation
private fun computeVersionStatus(
rawProcessedData: RawProcessedData,
latestVersions: Map<Accession, Version>,
latestRevocationVersions: Map<Accession, Version>,
): SiloVersionStatus {
): VersionStatus {
val isLatestVersion = (latestVersions[rawProcessedData.accession] == rawProcessedData.version)
if (isLatestVersion) {
return SiloVersionStatus.LATEST_VERSION
return VersionStatus.LATEST_VERSION
}

latestRevocationVersions[rawProcessedData.accession]?.let {
if (it > rawProcessedData.version) {
return SiloVersionStatus.REVOKED
return VersionStatus.REVOKED
}
}

return SiloVersionStatus.REVISED
return VersionStatus.REVISED
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import org.hamcrest.Matchers.not
import org.junit.jupiter.api.Test
import org.loculus.backend.api.GeneticSequence
import org.loculus.backend.api.ProcessedData
import org.loculus.backend.api.SiloVersionStatus
import org.loculus.backend.api.Status
import org.loculus.backend.api.VersionStatus
import org.loculus.backend.controller.DEFAULT_GROUP_NAME
import org.loculus.backend.controller.DEFAULT_USER_NAME
import org.loculus.backend.controller.EndpointTest
Expand Down Expand Up @@ -134,23 +134,23 @@ class GetReleasedDataEndpointTest(

assertThat(
response.findAccessionVersionStatus(accession, revokedVersion1),
`is`(SiloVersionStatus.REVOKED.name),
`is`(VersionStatus.REVOKED.name),
)
assertThat(
response.findAccessionVersionStatus(accession, revokedVersion2),
`is`(SiloVersionStatus.REVOKED.name),
`is`(VersionStatus.REVOKED.name),
)
assertThat(
response.findAccessionVersionStatus(accession, revocationVersion3),
`is`(SiloVersionStatus.REVISED.name),
`is`(VersionStatus.REVISED.name),
)
assertThat(
response.findAccessionVersionStatus(accession, revisedVersion4),
`is`(SiloVersionStatus.REVISED.name),
`is`(VersionStatus.REVISED.name),
)
assertThat(
response.findAccessionVersionStatus(accession, latestVersion5),
`is`(SiloVersionStatus.LATEST_VERSION.name),
`is`(VersionStatus.LATEST_VERSION.name),
)
}

Expand Down

0 comments on commit 442e100

Please sign in to comment.