Skip to content

Commit

Permalink
Backend changes WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fhennig committed Jan 29, 2025
1 parent 0e6da1b commit 9ffea30
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.loculus.backend.api.Organism
data class BackendConfig(
val organisms: Map<String, InstanceConfig>,
val accessionPrefix: String,
// TODO changes to be made here: add the flag here. we can put the Urls in a "date use terms" section in the config
val dataUseTermsEnabled: Boolean,
val dataUseTermsUrls: DataUseTermsUrls?,
) {
fun getInstanceConfig(organism: Organism) = organisms[organism.name] ?: throw IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.loculus.backend.api.SubmittedProcessedData
import org.loculus.backend.api.UnprocessedData
import org.loculus.backend.auth.AuthenticatedUser
import org.loculus.backend.auth.HiddenParam
import org.loculus.backend.config.BackendConfig
import org.loculus.backend.controller.LoculusCustomHeaders.X_TOTAL_RECORDS
import org.loculus.backend.log.REQUEST_ID_MDC_KEY
import org.loculus.backend.log.RequestIdContext
Expand Down Expand Up @@ -76,36 +77,45 @@ open class SubmissionController(
private val submissionDatabaseService: SubmissionDatabaseService,
private val iteratorStreamer: IteratorStreamer,
private val requestIdContext: RequestIdContext,
private val backendConfig: BackendConfig,
) {

/* TODO change to be made here - similar to restrictedUntil the parameter will conditionally be mandatory */
@Operation(description = SUBMIT_DESCRIPTION)
@ApiResponse(responseCode = "200", description = SUBMIT_RESPONSE_DESCRIPTION)
@ApiResponse(responseCode = "400", description = SUBMIT_ERROR_RESPONSE)
@PostMapping("/submit", consumes = ["multipart/form-data"])
fun submit(
@PathVariable @Valid organism: Organism,
@HiddenParam authenticatedUser: AuthenticatedUser,
@Parameter(description = GROUP_ID_DESCRIPTION) @RequestParam groupId: Int,
@Parameter(description = METADATA_FILE_DESCRIPTION) @RequestParam metadataFile: MultipartFile,
@Parameter(description = SEQUENCE_FILE_DESCRIPTION) @RequestParam sequenceFile: MultipartFile?,
@Parameter(description = "Data Use terms under which data is released.") @RequestParam dataUseTermsType:
DataUseTermsType,
@Parameter(
description =
"Data Use terms under which data is released. Mandatory when data use terms are enabled for this Instance.",
) @RequestParam dataUseTermsType: DataUseTermsType?,
@Parameter(
description =
"Mandatory when data use terms are set to 'RESTRICTED'." +
" It is the date when the sequence entries will become 'OPEN'." +
" Format: YYYY-MM-DD",
) @RequestParam restrictedUntil: String?,
): List<SubmissionIdMapping> {
// in here, just default to open DataUseTerms and then don't worry anymore
// throw an error if the parameter is given
var dataUseTermsKind = DataUseTermsType.OPEN
if (backendConfig.dataUseTermsEnabled) {
if (dataUseTermsType == null) {
throw BadRequestException("the 'dataUseTermsType' needs to be provided.")
} else {
dataUseTermsKind = dataUseTermsType
}
}

val params = SubmissionParams.OriginalSubmissionParams(
organism,
authenticatedUser,
metadataFile,
sequenceFile,
groupId,
DataUseTerms.fromParameters(dataUseTermsType, restrictedUntil),
DataUseTerms.fromParameters(dataUseTermsKind, restrictedUntil),
)
return submitModel.processSubmissions(UUID.randomUUID().toString(), params)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The accession is the (globally unique) id that the system assigned to the sequen
You can use this response to associate the user provided submissionId with the system assigned accession.
"""

const val SUBMIT_ERROR_RESPONSE = """
The data use terms type have not been provided, even though they are enabled for this Loculus instance.
"""

const val METADATA_FILE_DESCRIPTION = """
A TSV (tab separated values) file containing the metadata of the submitted sequence entries.
The file may be compressed with zstd, xz, zip, gzip, lzma, bzip2 (with common extensions).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ fun backendConfig(metadataList: List<Metadata>, earliestReleaseDate: EarliestRel
),
),
accessionPrefix = "FOO_",
dataUseTermsEnabled = true,
dataUseTermsUrls = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ const val PREFIX = "LOC_"

class GenerateAccessionFromNumberServiceTest {
private val accessionFromNumberService = GenerateAccessionFromNumberService(
BackendConfig(accessionPrefix = PREFIX, organisms = emptyMap(), dataUseTermsUrls = null),
BackendConfig(
accessionPrefix = PREFIX,
organisms = emptyMap(),
dataUseTermsEnabled = true,
dataUseTermsUrls = null,
),
)

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class EmptyProcessedDataProviderTest {
),
),
),
dataUseTermsEnabled = true,
dataUseTermsUrls = null,
),
)
Expand Down
1 change: 1 addition & 0 deletions kubernetes/loculus/templates/_common-metadata.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ fields:
{{- define "loculus.generateBackendConfig" }}
accessionPrefix: {{ quote $.Values.accessionPrefix }}
name: {{ quote $.Values.name }}
dataUseTermsEnabled: {{$.Values.dataUseTermsEnabled }}
dataUseTermsUrls:
{{$.Values.dataUseTermsUrls | toYaml | nindent 2}}
organisms:
Expand Down

0 comments on commit 9ffea30

Please sign in to comment.