Skip to content

Commit

Permalink
app: Fix rename storage studyFqn #TASK-7118
Browse files Browse the repository at this point in the history
  • Loading branch information
j-coll committed Oct 28, 2024
1 parent 85671b9 commit f73fbc1
Showing 1 changed file with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,16 +493,16 @@ private void changeFqns() throws CatalogDBException, MigrationException {
for (String projectCol : Arrays.asList(OrganizationMongoDBAdaptorFactory.PROJECT_COLLECTION,
OrganizationMongoDBAdaptorFactory.DELETED_PROJECT_COLLECTION)) {
migrateCollection(projectCol, new Document(), Projections.include("_id", "id", "fqn", "internal.datastores.variant"), (document, bulk) -> {
String oldFqn = document.getString("fqn");
String projectId = document.getString("id");
String newFqn = FqnUtils.buildFqn(this.organizationId, projectId);
logger.info("Changing project fqn from '{}' to '{}'", oldFqn, newFqn);
String oldProjectFqn = document.getString("fqn");
String newProjectFqn = FqnUtils.buildFqn(this.organizationId, projectId);
logger.info("Changing project fqn from '{}' to '{}'", oldProjectFqn, newProjectFqn);

Document set = new Document()
.append("fqn", newFqn)
.append("fqn", newProjectFqn)
.append("attributes.OPENCGA.3_0_0", new Document()
.append("date", date)
.append("oldFqn", oldFqn)
.append("oldFqn", oldProjectFqn)
);

Document internal = document.get("internal", Document.class);
Expand All @@ -511,8 +511,8 @@ private void changeFqns() throws CatalogDBException, MigrationException {
if (datastores != null) {
Document variant = datastores.get("variant", Document.class);
if (variant == null) {
DataStore dataStore = VariantStorageManager.defaultDataStore(configuration.getDatabasePrefix(), oldFqn);
logger.info("Undefined variant \"internal.datastores.variant\" at project '{}'.", oldFqn);
DataStore dataStore = VariantStorageManager.defaultDataStore(configuration.getDatabasePrefix(), oldProjectFqn);
logger.info("Undefined variant \"internal.datastores.variant\" at project '{}'.", oldProjectFqn);

// Update only if the project exists in the variant storage
try (VariantStorageEngine variantStorageEngine = storageEngineFactory
Expand All @@ -523,13 +523,18 @@ private void changeFqns() throws CatalogDBException, MigrationException {
.append("storageEngine", dataStore.getStorageEngine())
.append("dbName", dataStore.getDbName())
.append("options", new Document()));
variantStorageEngine.getMetadataManager().updateStudyMetadata(oldFqn, studyMetadata -> {
studyMetadata.setName(newFqn);
studyMetadata.getAttributes().put("OPENCGA.3_0_0", new Document()
.append("date", date)
.append("oldFqn", oldFqn)
);
});

for (String oldStudyFqn : variantStorageEngine.getMetadataManager().getStudies().keySet()) {
String newStudyFqn = FqnUtils.buildFqn(this.organizationId, projectId, FqnUtils.parse(oldStudyFqn).getStudy());
logger.info("Changing study fqn from '{}' to '{}'", oldStudyFqn, newStudyFqn);
variantStorageEngine.getMetadataManager().updateStudyMetadata(oldStudyFqn, studyMetadata -> {
studyMetadata.setName(newStudyFqn);
studyMetadata.getAttributes().put("OPENCGA.3_0_0", new Document()
.append("date", date)
.append("oldFqn", oldStudyFqn)
);
});
}
} else {
logger.info("Project does not exist in the variant storage. Skipping");
}
Expand Down

0 comments on commit f73fbc1

Please sign in to comment.