Skip to content

Commit

Permalink
app: Fix migration EnsureSampleIndexConfigurationIsAlwaysDefined. #TA…
Browse files Browse the repository at this point in the history
…SK-6765
  • Loading branch information
j-coll committed Sep 11, 2024
1 parent a4b75fa commit b663722
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opencb.opencga.app.migrations.v3.v3_4_0.storage;

import org.apache.commons.collections4.CollectionUtils;
import org.opencb.opencga.app.migrations.StorageMigrationTool;
import org.opencb.opencga.catalog.migration.Migration;
import org.opencb.opencga.core.config.storage.SampleIndexConfiguration;
Expand Down Expand Up @@ -27,15 +28,19 @@ protected void run() throws Exception {
if (engine.getMetadataManager().exists()) {
for (Integer studyId : engine.getMetadataManager().getStudyIds()) {
StudyMetadata studyMetadata = engine.getMetadataManager().getStudyMetadata(studyId);
List<StudyMetadata.SampleIndexConfigurationVersioned> configurations = studyMetadata.getSampleIndexConfigurations();
if (configurations == null || configurations.isEmpty()) {
configurations = new ArrayList<>(1);
logger.info("Creating default SampleIndexConfiguration for study '" + studyMetadata.getName() + "' (" + studyId + ")");
configurations.add(new StudyMetadata.SampleIndexConfigurationVersioned(
preFileDataConfiguration(),
StudyMetadata.DEFAULT_SAMPLE_INDEX_VERSION,
Date.from(Instant.now()), StudyMetadata.SampleIndexConfigurationVersioned.Status.ACTIVE));
studyMetadata.setSampleIndexConfigurations(configurations);
if (CollectionUtils.isEmpty(studyMetadata.getSampleIndexConfigurations())) {
engine.getMetadataManager().updateStudyMetadata(studyId, sm -> {
if (CollectionUtils.isEmpty(sm.getSampleIndexConfigurations())) {
List<StudyMetadata.SampleIndexConfigurationVersioned> configurations = new ArrayList<>(1);
logger.info("Creating default SampleIndexConfiguration for study '" + studyMetadata.getName() + "'"
+ " (" + studyId + ")");
configurations.add(new StudyMetadata.SampleIndexConfigurationVersioned(
preFileDataConfiguration(),
StudyMetadata.DEFAULT_SAMPLE_INDEX_VERSION,
Date.from(Instant.now()), StudyMetadata.SampleIndexConfigurationVersioned.Status.ACTIVE));
sm.setSampleIndexConfigurations(configurations);
}
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ private MigrationSummary getMigrationSummary(String organizationId) throws Catal
p -> p.getValue().getStatus(),
() -> new EnumMap<>(MigrationRun.MigrationStatus.class),
Collectors.counting())))
.setVersionCount(runs.stream().collect(Collectors.groupingBy(p -> p.getKey().version(), Collectors.counting())));
.setVersionCount(runs.stream().collect(Collectors.groupingBy(p -> p.getKey().version(),
TreeMap::new, Collectors.counting())));

long toBeApplied = migrationSummary
.getStatusCount()
Expand Down

0 comments on commit b663722

Please sign in to comment.