Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(backend): rename enum SiloVersionStatus to VersionStatus and document the enum #2817

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
corneliusroemer marked this conversation as resolved.
Show resolved Hide resolved
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
corneliusroemer marked this conversation as resolved.
Show resolved Hide resolved
REVISED, // Not the highest, and there is no higher revocation
corneliusroemer marked this conversation as resolved.
Show resolved Hide resolved
LATEST_VERSION, // Highest version
corneliusroemer marked this conversation as resolved.
Show resolved Hide resolved
}

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: Highest version
theosanderson marked this conversation as resolved.
Show resolved Hide resolved
corneliusroemer marked this conversation as resolved.
Show resolved Hide resolved
// REVOKED: Not highest version, higher version is a revocation
corneliusroemer marked this conversation as resolved.
Show resolved Hide resolved
// REVISED: Not the highest version, and there's no higher version that is a revocation
corneliusroemer marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading