package org.opencb.opencga.app.migrations.v2_1_0.storage;


import org.opencb.commons.datastore.core.Query;
import org.opencb.commons.datastore.core.QueryOptions;
import org.opencb.opencga.catalog.migration.Migration;
import org.opencb.opencga.catalog.migration.MigrationTool;
import org.opencb.opencga.core.config.storage.StorageConfiguration;
import org.opencb.opencga.core.models.project.Project;

@Migration(id="add_cellbase_configuration_to_project", description = "Add cellbase configuration from storage-configuration.yml to project.internal.cellbase", version = "2.1.0",
        language = Migration.MigrationLanguage.JAVA,
        domain = Migration.MigrationDomain.STORAGE,
        patch = 2,
        rank = 11)
public class AddCellbaseConfigurationToProject extends MigrationTool {

    @Override
    protected void run() throws Exception {
        StorageConfiguration storageConfiguration = readStorageConfiguration();
//        StorageEngineFactory engineFactory = StorageEngineFactory.get(storageConfiguration);
//        VariantStorageManager variantStorageManager = new VariantStorageManager(catalogManager, engineFactory);

        for (Project project : catalogManager.getProjectManager().get(new Query(), new QueryOptions(), token).getResults()) {
            if (project.getInternal() == null || project.getInternal().getCellbase() == null) {
                catalogManager.getProjectManager()
                        .setInternalCellbaseConfiguration(project.getFqn(), storageConfiguration.getCellbase(), token);
            }
        }
    }
}

@@ -394,16 +394,98 @@
 oject;%0A%0A
+import static org.opencb.opencga.core.api.ParamConstants.USER_PROJECT_SEPARATOR;%0A%0A
 @Migrati
@@ -775,17 +775,17 @@
 patch = 
-2
+3
 ,%0A      
@@ -1435,24 +1435,195 @@
  == null) %7B%0A
+                String userToken = catalogManager.getUserManager()%0A                        .getNonExpiringToken(project.getFqn().split(USER_PROJECT_SEPARATOR)%5B0%5D, token);%0A
             
@@ -1769,25 +1769,29 @@
 Cellbase(), 
-t
+userT
 oken);%0A     

Use userToken to update project.internal.cellbase