Skip to content

Commit

Permalink
app: store old fqn in attributes before migration, #TASK-7118
Browse files Browse the repository at this point in the history
  • Loading branch information
pfurio committed Oct 22, 2024
1 parent 4a0618f commit acac916
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.opencb.opencga.catalog.utils.FqnUtils;
import org.opencb.opencga.catalog.utils.ParamUtils;
import org.opencb.opencga.core.api.ParamConstants;
import org.opencb.opencga.core.common.TimeUtils;
import org.opencb.opencga.core.config.AuthenticationOrigin;
import org.opencb.opencga.core.config.Configuration;
import org.opencb.opencga.core.models.migration.MigrationRun;
Expand Down Expand Up @@ -461,16 +462,23 @@ protected void run() throws Exception {

private void changeFqns() throws CatalogDBException {
this.dbAdaptorFactory = this.mongoDBAdaptorFactory;
String date = TimeUtils.getTime();

// Change project fqn's
for (String projectCol : Arrays.asList(OrganizationMongoDBAdaptorFactory.PROJECT_COLLECTION,
OrganizationMongoDBAdaptorFactory.DELETED_PROJECT_COLLECTION)) {
migrateCollection(projectCol, new Document(), Projections.include("_id", "id"), (document, bulk) -> {
migrateCollection(projectCol, new Document(), Projections.include("_id", "id", "fqn"), (document, bulk) -> {
String currentFqn = document.getString("fqn");
String projectId = document.getString("id");
String projectFqn = FqnUtils.buildFqn(this.organizationId, projectId);
bulk.add(new UpdateOneModel<>(
Filters.eq("_id", document.get("_id")),
new Document("$set", new Document("fqn", projectFqn)))
new Document("$set", new Document()
.append("fqn", projectFqn)
.append("attributes.OPENCGA.3_0_0", new Document()
.append("date", date)
.append("oldFqn", currentFqn)
)))
);
});
}
Expand All @@ -490,12 +498,24 @@ private void changeFqns() throws CatalogDBException {
String newFqn = FqnUtils.buildFqn(this.organizationId, oldFqnInstance.getProject(), oldFqnInstance.getStudy());
bulk.add(new UpdateOneModel<>(
Filters.eq("_id", document.get("_id")),
new Document("$set", new Document("fqn", newFqn)))
new Document("$set", new Document()
.append("fqn", newFqn)
.append("attributes.OPENCGA.3_0_0", new Document()
.append("date", date)
.append("oldFqn", oldStudyFqn)
)
))
);

// Change fqn in all jobs that were pointing to this study
Bson jobQuery = Filters.eq("studyUid", studyUid);
Bson update = Updates.set("study.id", newFqn);
Bson update = new Document("$set", new Document()
.append("study.id", newFqn)
.append("attributes.OPENCGA.3_0_0", new Document()
.append("date", date)
.append("oldStudyFqn", oldStudyFqn)
)
);
jobCollection.updateMany(jobQuery, update);
jobDeletedCollection.updateMany(jobQuery, update);
});
Expand Down

0 comments on commit acac916

Please sign in to comment.