Skip to content

Commit

Permalink
feat(backend): add URLs to the data use terms to SILO (#1515)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoran-chen authored Mar 29, 2024
1 parent 256d177 commit 75242d1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
6 changes: 6 additions & 0 deletions backend/src/main/kotlin/org/loculus/backend/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ import org.loculus.backend.api.Organism
data class BackendConfig(
val organisms: Map<String, InstanceConfig>,
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<ProcessedData<GeneticSequence>> {
log.info { "fetching released submissions" }
Expand All @@ -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)) +
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class EmptyProcessedDataProviderTest {
),
),
),
dataUseTermsUrls = null,
),
)

Expand Down
7 changes: 7 additions & 0 deletions kubernetes/loculus/templates/_common-metadata.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 */}}
Expand Down Expand Up @@ -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 }}:
Expand Down
3 changes: 3 additions & 0 deletions kubernetes/loculus/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 75242d1

Please sign in to comment.