-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sketch: do not hide metadata processing in sequence compression function
- Loading branch information
1 parent
b8090dc
commit 448b0eb
Showing
4 changed files
with
72 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
backend/src/main/kotlin/org/loculus/backend/service/submission/ProcessedDataPostprocessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.loculus.backend.service.submission | ||
|
||
import org.loculus.backend.api.Organism | ||
import org.loculus.backend.api.ProcessedData | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ProcessedDataPostprocessor( | ||
private val compressionService: CompressionService, | ||
private val processedMetadataPostprocessor: ProcessedMetadataPostprocessor, | ||
) { | ||
fun prepareForStorage(processedData: ProcessedData<String>, organism: Organism) = processedData | ||
.let { compressionService.compressSequencesInProcessedData(it, organism) } | ||
.let { processedMetadataPostprocessor.stripNullValuesFromMetadata(it) } | ||
|
||
fun retrieveFromStoredValue(storedValue: ProcessedData<CompressedSequence>, organism: Organism) = storedValue | ||
.let { processedMetadataPostprocessor.addMissingMetadataAsNull(it, organism) } | ||
.let { compressionService.decompressSequencesInProcessedData(it, organism) } | ||
} |
27 changes: 27 additions & 0 deletions
27
.../src/main/kotlin/org/loculus/backend/service/submission/ProcessedMetadataPostprocessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.loculus.backend.service.submission | ||
|
||
import com.fasterxml.jackson.databind.node.NullNode | ||
import org.loculus.backend.api.Organism | ||
import org.loculus.backend.api.ProcessedData | ||
import org.loculus.backend.config.BackendConfig | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ProcessedMetadataPostprocessor( | ||
private val backendConfig: BackendConfig, | ||
) { | ||
fun <SequenceType> stripNullValuesFromMetadata(processedData: ProcessedData<SequenceType>) = | ||
processedData.copy(metadata = processedData.metadata.filterNot { (_, value) -> value.isNull }) | ||
|
||
fun <SequenceType> addMissingMetadataAsNull(processedData: ProcessedData<SequenceType>, organism: Organism) = | ||
processedData.copy( | ||
metadata = backendConfig | ||
.getInstanceConfig(organism) | ||
.schema | ||
.metadata | ||
.map { it.name } | ||
.associateWith { fieldName -> | ||
processedData.metadata[fieldName] ?: NullNode.instance | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters