From bfe19252a8356dc0a220c0f2152ce5c3aa098e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacobo=20Coll=20Morag=C3=B3n?= Date: Thu, 24 Oct 2024 16:07:17 +0100 Subject: [PATCH] app: Fix NPE. Add appHome to OrganizationMigration. #TASK-7118 --- .../admin/executors/MigrationCommandExecutor.java | 2 +- .../migrations/v3/v3_0_0/OrganizationMigration.java | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/MigrationCommandExecutor.java b/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/MigrationCommandExecutor.java index 1a52874866..5fdada19a9 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/MigrationCommandExecutor.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/MigrationCommandExecutor.java @@ -70,7 +70,7 @@ private void runMigrationToV3() throws Exception { setCatalogDatabaseCredentials(options, options.commonOptions); OrganizationMigration organizationMigration = new OrganizationMigration(configuration, options.commonOptions.adminPassword, - options.user, options.organizationId); + options.user, options.organizationId, Paths.get(appHome)); organizationMigration.execute(); } diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/migrations/v3/v3_0_0/OrganizationMigration.java b/opencga-app/src/main/java/org/opencb/opencga/app/migrations/v3/v3_0_0/OrganizationMigration.java index 25215778dd..26780bc506 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/migrations/v3/v3_0_0/OrganizationMigration.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/migrations/v3/v3_0_0/OrganizationMigration.java @@ -9,6 +9,7 @@ import org.bson.conversions.Bson; import org.opencb.commons.datastore.mongodb.MongoDataStore; import org.opencb.commons.utils.CryptoUtils; +import org.opencb.commons.utils.FileUtils; import org.opencb.opencga.analysis.variant.manager.VariantStorageManager; import org.opencb.opencga.catalog.auth.authentication.CatalogAuthenticationManager; import org.opencb.opencga.catalog.db.api.StudyDBAdaptor; @@ -45,6 +46,7 @@ import java.lang.reflect.Modifier; import java.net.URL; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.security.NoSuchAlgorithmException; import java.util.*; @@ -70,21 +72,25 @@ private enum MigrationStatus { ERROR } - public OrganizationMigration(Configuration configuration, String adminPassword, String userId, String organizationId) - throws CatalogException { + public OrganizationMigration(Configuration configuration, String adminPassword, String userId, String organizationId, Path appHome) + throws CatalogException, IOException { this.configuration = configuration; this.adminPassword = adminPassword; this.userId = userId; this.organizationId = organizationId; + this.appHome = appHome; this.status = checkAndInit(); } - private MigrationStatus checkAndInit() throws CatalogException { + private MigrationStatus checkAndInit() throws CatalogException, IOException { this.oldDatabase = configuration.getDatabasePrefix() + "_catalog"; this.mongoDBAdaptorFactory = new MongoDBAdaptorFactory(configuration); this.oldDatastore = mongoDBAdaptorFactory.getMongoManager().get(oldDatabase, mongoDBAdaptorFactory.getMongoDbConfiguration()); + FileUtils.checkDirectory(appHome); + readStorageConfiguration(); + MongoCollection userCol = oldDatastore.getDb().getCollection(OrganizationMongoDBAdaptorFactory.USER_COLLECTION); FindIterable iterable = userCol.find(Filters.eq("id", ParamConstants.OPENCGA_USER_ID)); try (MongoCursor cursor = iterable.cursor()) {