Skip to content

Commit

Permalink
app: Rename StudyMetadata.name to match the new fqn. #TASK-7118
Browse files Browse the repository at this point in the history
  • Loading branch information
j-coll committed Oct 25, 2024
1 parent bfe1925 commit 85671b9
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import java.util.*;
import java.util.stream.Collectors;

import static org.opencb.opencga.core.config.storage.StorageConfiguration.Mode.READ_ONLY;

@Migration(id = "add_organizations", description = "Add new Organization layer #TASK-4389", version = "3.0.0",
language = Migration.MigrationLanguage.JAVA, domain = Migration.MigrationDomain.CATALOG, date = 20231212)
public class OrganizationMigration extends MigrationTool {
Expand All @@ -65,6 +67,7 @@ public class OrganizationMigration extends MigrationTool {
private Set<String> userIdsToDiscardData;

private MigrationStatus status;
private boolean changeOrganizationId;

private enum MigrationStatus {
MIGRATED,
Expand Down Expand Up @@ -212,6 +215,11 @@ private MigrationStatus checkAndInit() throws CatalogException, IOException {
if (StringUtils.isEmpty(this.organizationId)) {
this.organizationId = this.userId;
}
changeOrganizationId = !this.organizationId.equals(this.userId);
if (changeOrganizationId && readStorageConfiguration().getMode() == READ_ONLY) {
throw new CatalogException("Cannot change organization id when storage is in read-only mode");
}

ParamUtils.checkIdentifier(this.organizationId, "Organization id");
this.catalogManager = new CatalogManager(configuration);
return MigrationStatus.PENDING_MIGRATION;
Expand Down Expand Up @@ -464,7 +472,7 @@ protected void run() throws Exception {
}

// If the user didn't want to use the userId as the new organization id, we then need to change all the fqn's
if (!this.organizationId.equals(this.userId)) {
if (changeOrganizationId) {
logger.info("New organization id '{}' is different from original userId '{}'. Changing FQN's from projects and studies"
, this.organizationId, this.userId);
changeFqns();
Expand Down Expand Up @@ -515,6 +523,13 @@ 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)
);
});
} else {
logger.info("Project does not exist in the variant storage. Skipping");
}
Expand Down

0 comments on commit 85671b9

Please sign in to comment.