diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/migrations/v3/v3_4_0/storage/EnsureSampleIndexConfigurationIsAlwaysDefined.java b/opencga-app/src/main/java/org/opencb/opencga/app/migrations/v3/v3_4_0/storage/EnsureSampleIndexConfigurationIsAlwaysDefined.java index dceb209fd9..2f336ed889 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/migrations/v3/v3_4_0/storage/EnsureSampleIndexConfigurationIsAlwaysDefined.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/migrations/v3/v3_4_0/storage/EnsureSampleIndexConfigurationIsAlwaysDefined.java @@ -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; @@ -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 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 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); + } + }); } } } diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/migration/MigrationManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/migration/MigrationManager.java index fa8fd7b9ee..d0893232b6 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/migration/MigrationManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/migration/MigrationManager.java @@ -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()