Skip to content

Commit

Permalink
refactor(backend): rename enum SiloVersionStatus to VersionStatus and…
Browse files Browse the repository at this point in the history
… document the enum
  • Loading branch information
corneliusroemer committed Sep 17, 2024
1 parent 096b1d2 commit fdcd349
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 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, // Not the highest version, and a higher version is a revocation
REVISED, // Not the highest, and there is no higher revocation
LATEST_VERSION, // Highest version
}

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 siloVersionStatus = computeVersionStatus(rawProcessedData, latestVersions, latestRevocationVersions)

val currentDataUseTerms = computeDataUseTerm(rawProcessedData)
val restrictedDataUseTermsUntil = if (currentDataUseTerms is DataUseTerms.Restricted) {
Expand Down Expand Up @@ -102,22 +102,26 @@ class ReleasedDataModel(
DataUseTerms.Open
}

private fun computeSiloVersionStatus(
// LATEST_VERSION: Highest version
// REVOKED: Not highest version, higher version is a revocation
// REVISED: Not the highest version, and there's no higher version that 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 fdcd349

Please sign in to comment.