From 75242d11c067997b418261df2c32de33d0a2cdb0 Mon Sep 17 00:00:00 2001 From: Chaoran Chen Date: Fri, 29 Mar 2024 18:03:38 +0100 Subject: [PATCH] feat(backend): add URLs to the data use terms to SILO (#1515) --- .../kotlin/org/loculus/backend/config/Config.kt | 6 ++++++ .../loculus/backend/model/ReleasedDataModel.kt | 17 +++++++++++++++-- .../GenerateAccessionFromNumberServiceTest.kt | 2 +- .../EmptyProcessedDataProviderTest.kt | 1 + .../loculus/templates/_common-metadata.tpl | 7 +++++++ kubernetes/loculus/values.yaml | 3 +++ 6 files changed, 33 insertions(+), 3 deletions(-) diff --git a/backend/src/main/kotlin/org/loculus/backend/config/Config.kt b/backend/src/main/kotlin/org/loculus/backend/config/Config.kt index 0c7aca74eb..04e4c72571 100644 --- a/backend/src/main/kotlin/org/loculus/backend/config/Config.kt +++ b/backend/src/main/kotlin/org/loculus/backend/config/Config.kt @@ -7,12 +7,18 @@ import org.loculus.backend.api.Organism data class BackendConfig( val organisms: Map, val accessionPrefix: String, + val dataUseTermsUrls: DataUseTermsUrls?, ) { fun getInstanceConfig(organism: Organism) = organisms[organism.name] ?: throw IllegalArgumentException( "Organism: ${organism.name} not found in backend config. Available organisms: ${organisms.keys}", ) } +data class DataUseTermsUrls( + val open: String, + val restricted: String, +) + data class InstanceConfig( val schema: Schema, val referenceGenomes: ReferenceGenome, diff --git a/backend/src/main/kotlin/org/loculus/backend/model/ReleasedDataModel.kt b/backend/src/main/kotlin/org/loculus/backend/model/ReleasedDataModel.kt index df05913508..89fa1f38a5 100644 --- a/backend/src/main/kotlin/org/loculus/backend/model/ReleasedDataModel.kt +++ b/backend/src/main/kotlin/org/loculus/backend/model/ReleasedDataModel.kt @@ -14,6 +14,7 @@ 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.config.BackendConfig import org.loculus.backend.service.submission.RawProcessedData import org.loculus.backend.service.submission.SubmissionDatabaseService import org.loculus.backend.utils.Accession @@ -24,7 +25,10 @@ import org.springframework.transaction.annotation.Transactional private val log = KotlinLogging.logger { } @Service -class ReleasedDataModel(private val submissionDatabaseService: SubmissionDatabaseService) { +class ReleasedDataModel( + private val submissionDatabaseService: SubmissionDatabaseService, + private val backendConfig: BackendConfig, +) { @Transactional(readOnly = true) fun getReleasedData(organism: Organism): Sequence> { log.info { "fetching released submissions" } @@ -45,7 +49,7 @@ class ReleasedDataModel(private val submissionDatabaseService: SubmissionDatabas val currentDataUseTermsType = computeDataUseTerm(rawProcessedData) - val metadata = rawProcessedData.processedData.metadata + + var metadata = rawProcessedData.processedData.metadata + ("accession" to TextNode(rawProcessedData.accession)) + ("version" to LongNode(rawProcessedData.version)) + (HEADER_TO_CONNECT_METADATA_AND_SEQUENCES to TextNode(rawProcessedData.submissionId)) + @@ -58,6 +62,15 @@ class ReleasedDataModel(private val submissionDatabaseService: SubmissionDatabas ("versionStatus" to TextNode(siloVersionStatus.name)) + ("dataUseTerms" to TextNode(currentDataUseTermsType.name)) + if (backendConfig.dataUseTermsUrls != null) { + val url = if (rawProcessedData.dataUseTerms == DataUseTerms.Open) { + backendConfig.dataUseTermsUrls.open + } else { + backendConfig.dataUseTermsUrls.restricted + } + metadata += ("dataUseTermsUrl" to TextNode(url)) + } + return ProcessedData( metadata = metadata, unalignedNucleotideSequences = rawProcessedData.processedData.unalignedNucleotideSequences, diff --git a/backend/src/test/kotlin/org/loculus/backend/service/GenerateAccessionFromNumberServiceTest.kt b/backend/src/test/kotlin/org/loculus/backend/service/GenerateAccessionFromNumberServiceTest.kt index 865895ea5b..ad3b53fa80 100644 --- a/backend/src/test/kotlin/org/loculus/backend/service/GenerateAccessionFromNumberServiceTest.kt +++ b/backend/src/test/kotlin/org/loculus/backend/service/GenerateAccessionFromNumberServiceTest.kt @@ -11,7 +11,7 @@ const val PREFIX = "LOC_" class GenerateAccessionFromNumberServiceTest { private val accessionFromNumberService = GenerateAccessionFromNumberService( - BackendConfig(accessionPrefix = PREFIX, organisms = emptyMap()), + BackendConfig(accessionPrefix = PREFIX, organisms = emptyMap(), dataUseTermsUrls = null), ) @Test diff --git a/backend/src/test/kotlin/org/loculus/backend/service/submission/EmptyProcessedDataProviderTest.kt b/backend/src/test/kotlin/org/loculus/backend/service/submission/EmptyProcessedDataProviderTest.kt index f462af8dba..96a0dea239 100644 --- a/backend/src/test/kotlin/org/loculus/backend/service/submission/EmptyProcessedDataProviderTest.kt +++ b/backend/src/test/kotlin/org/loculus/backend/service/submission/EmptyProcessedDataProviderTest.kt @@ -46,6 +46,7 @@ class EmptyProcessedDataProviderTest { ), ), ), + dataUseTermsUrls = null, ), ) diff --git a/kubernetes/loculus/templates/_common-metadata.tpl b/kubernetes/loculus/templates/_common-metadata.tpl index b47367a29e..bd51d8ec95 100644 --- a/kubernetes/loculus/templates/_common-metadata.tpl +++ b/kubernetes/loculus/templates/_common-metadata.tpl @@ -32,6 +32,11 @@ fields: - name: versionStatus type: string notSearchable: true + {{- if $.Values.dataUseTermsUrls }} + - name: dataUseTermsUrl + type: string + notSearchable: true + {{- end}} {{- end}} {{/* Generate website config from passed config object */}} @@ -97,6 +102,8 @@ fields: {{- define "loculus.generateBackendConfig" }} accessionPrefix: {{$.Values.accessionPrefix}} name: {{ $.Values.name }} +dataUseTermsUrls: + {{$.Values.dataUseTermsUrls | toYaml | nindent 2}} organisms: {{- range $key, $instance := (.Values.organisms | default .Values.defaultOrganisms) }} {{ $key }}: diff --git a/kubernetes/loculus/values.yaml b/kubernetes/loculus/values.yaml index 1eda8cb649..6a57f61e0f 100644 --- a/kubernetes/loculus/values.yaml +++ b/kubernetes/loculus/values.yaml @@ -15,6 +15,9 @@ disablePreprocessing: false disableIngest: false siloImportLimitSeconds: 3600 accessionPrefix: "LOC_" +dataUseTermsUrls: + open: https://#TODO-MVP/open + restricted: https://#TODO-MVP/restricted name: "Loculus" logo: url: "/favicon.svg"