From 1de04f2a6b2c8facb0bc6f00633d044aee60d0e9 Mon Sep 17 00:00:00 2001 From: pfurio Date: Mon, 28 Aug 2023 10:17:46 +0200 Subject: [PATCH] catalog: add organizationId to some managers, #TASK-4389 --- .../opencga/analysis/AnalysisUtils.java | 15 +- .../opencga/analysis/ResourceUtils.java | 2 +- .../opencga/analysis/StorageManager.java | 8 +- .../alignment/AlignmentCoverageAnalysis.java | 4 +- .../alignment/AlignmentIndexOperation.java | 4 +- .../alignment/AlignmentStorageManager.java | 8 +- .../qc/AlignmentFastQcMetricsAnalysis.java | 5 +- .../qc/AlignmentFlagStatsAnalysis.java | 4 +- .../alignment/qc/AlignmentQcAnalysis.java | 7 +- .../alignment/qc/AlignmentStatsAnalysis.java | 6 +- .../annotations/TsvAnnotationLoader.java | 4 +- .../ClinicalInterpretationManager.java | 22 +- .../ExomiserInterpretationAnalysis.java | 2 +- .../team/TeamInterpretationAnalysis.java | 4 +- .../CancerTieringInterpretationAnalysis.java | 2 +- ...TieringInterpretationAnalysisExecutor.java | 2 +- .../TieringInterpretationAnalysis.java | 2 +- .../zetta/ZettaInterpretationAnalysis.java | 2 +- .../analysis/cohort/CohortIndexTask.java | 4 +- .../cohort/CohortTsvAnnotationLoader.java | 2 +- .../analysis/family/FamilyIndexTask.java | 4 +- .../family/FamilyTsvAnnotationLoader.java | 2 +- .../family/PedigreeGraphAnalysis.java | 4 +- .../family/PedigreeGraphInitAnalysis.java | 2 +- .../analysis/family/qc/FamilyQcAnalysis.java | 6 +- .../qc/FamilyQcLocalAnalysisExecutor.java | 2 +- .../analysis/file/FetchAndRegisterTask.java | 2 +- .../opencga/analysis/file/FileDeleteTask.java | 8 +- .../opencga/analysis/file/FileIndexTask.java | 4 +- .../file/FileTsvAnnotationLoader.java | 2 +- .../opencga/analysis/file/FileUnlinkTask.java | 4 +- .../file/PostLinkSampleAssociation.java | 10 +- .../individual/IndividualIndexTask.java | 4 +- .../IndividualTsvAnnotationLoader.java | 2 +- .../individual/qc/IndividualQcAnalysis.java | 2 +- .../individual/qc/IndividualQcUtils.java | 22 +- .../opencga/analysis/job/JobIndexTask.java | 4 +- .../opencga/analysis/rga/RgaManager.java | 44 +- .../analysis/sample/SampleIndexTask.java | 4 +- .../sample/SampleTsvAnnotationLoader.java | 2 +- .../analysis/sample/qc/SampleQcAnalysis.java | 15 +- .../analysis/templates/TemplateRunner.java | 2 +- .../analysis/tools/OpenCgaToolScopeStudy.java | 2 +- .../opencga/analysis/tools/ToolRunner.java | 2 +- .../genomePlot/GenomePlotAnalysis.java | 2 +- .../analysis/variant/gwas/GwasAnalysis.java | 8 +- .../variant/hrdetect/HRDetectAnalysis.java | 4 +- .../inferredSex/InferredSexAnalysis.java | 2 +- .../analysis/variant/julie/JulieTool.java | 4 +- .../variant/knockout/KnockoutAnalysis.java | 10 +- .../KnockoutAnalysisResultReader.java | 2 +- .../variant/manager/CatalogUtils.java | 10 +- .../manager/VariantCatalogQueryUtils.java | 56 +- .../manager/VariantStorageManager.java | 48 +- .../manager/operations/OperationManager.java | 4 +- .../VariantAnnotationOperationManager.java | 4 +- .../VariantDeleteOperationManager.java | 2 +- .../VariantFileIndexerOperationManager.java | 26 +- .../VariantStatsOperationManager.java | 6 +- .../MendelianErrorAnalysis.java | 2 +- .../CatalogStorageMetadataSynchronizer.java | 28 +- .../CatalogVariantMetadataFactory.java | 6 +- .../MutationalSignatureAnalysis.java | 11 +- ...ationalSignatureLocalAnalysisExecutor.java | 4 +- .../variant/operations/OperationTool.java | 4 +- .../VariantFileIndexJobLauncherTool.java | 4 +- .../operations/VariantIndexOperationTool.java | 2 +- .../VariantStatsIndexOperationTool.java | 3 +- .../VariantStorageMetadataRepairTool.java | 2 +- .../relatedness/RelatednessAnalysis.java | 8 +- .../samples/SampleEligibilityAnalysis.java | 12 +- .../samples/SampleVariantFilterAnalysis.java | 2 +- .../stats/CohortVariantStatsAnalysis.java | 14 +- .../stats/SampleVariantStatsAnalysis.java | 10 +- .../variant/stats/VariantStatsAnalysis.java | 10 +- .../ClinicalInterpretationAnalysisTest.java | 6 +- .../ExomiserInterpretationAnalysisTest.java | 11 +- .../analysis/family/FamilyAnalysisTest.java | 16 +- .../file/PostLinkSampleAssociationTest.java | 48 +- .../opencga/analysis/rga/RgaManagerTest.java | 2 +- .../variant/OpenCGATestExternalResource.java | 2 +- .../analysis/variant/VariantAnalysisTest.java | 20 +- .../manager/VariantCatalogQueryUtilsTest.java | 32 +- .../manager/VariantManagerFetchTest.java | 34 +- .../manager/VariantOperationsTest.java | 28 +- .../manager/VariantStorageManagerTest.java | 4 +- .../AbstractVariantOperationManagerTest.java | 20 +- .../operations/PlatinumFileIndexerTest.java | 6 +- .../operations/RemoveVariantsTest.java | 10 +- .../operations/StatsVariantStorageTest.java | 68 +- .../VariantFileIndexSameNameTest.java | 24 +- ...ariantFileIndexerOperationManagerTest.java | 20 +- .../manager/operations/VariantImportTest.java | 4 +- .../VariantVirtualFileIndexTest.java | 4 +- ...atalogStorageMetadataSynchronizerTest.java | 44 +- .../executors/CatalogCommandExecutor.java | 6 +- .../executors/StorageCommandExecutor.java | 6 +- .../storage/AbstractStorageMigrator.java | 2 +- ...FilePathToStudyConfigurationMigration.java | 2 +- .../executors/InternalCommandExecutor.java | 2 +- .../app/migrations/StorageMigrationTool.java | 2 +- .../app/cli/analysis/InternalMainTest.java | 32 +- .../opencga/catalog/db/DBAdaptorFactory.java | 6 + .../db/mongodb/MongoDBAdaptorFactory.java | 16 +- .../ProjectCatalogMongoDBIterator.java | 4 +- .../catalog/managers/AbstractManager.java | 2 +- .../catalog/managers/AdminManager.java | 2 +- .../managers/AnnotationSetManager.java | 4 +- .../catalog/managers/AuditManager.java | 2 +- .../catalog/managers/CatalogManager.java | 9 +- .../managers/ClinicalAnalysisManager.java | 272 +++---- .../catalog/managers/CohortManager.java | 82 +-- .../catalog/managers/FamilyManager.java | 72 +- .../opencga/catalog/managers/FileManager.java | 148 ++-- .../opencga/catalog/managers/FileUtils.java | 4 +- .../catalog/managers/IndividualManager.java | 84 +-- .../managers/InterpretationManager.java | 66 +- .../opencga/catalog/managers/JobManager.java | 106 +-- .../catalog/managers/PanelManager.java | 60 +- .../catalog/managers/ProjectManager.java | 267 +++---- .../catalog/managers/ResourceManager.java | 200 +++--- .../catalog/managers/SampleManager.java | 82 +-- .../catalog/managers/StudyManager.java | 490 +++++++------ .../opencga/catalog/managers/UserManager.java | 16 +- .../catalog/migration/MigrationManager.java | 4 +- .../catalog/templates/TemplateManager.java | 40 +- .../opencga/catalog/utils/CatalogDemo.java | 8 +- .../utils/CatalogSampleAnnotationsLoader.java | 10 +- .../catalog/utils/FileMetadataReader.java | 6 +- .../opencga/catalog/utils/FileScanner.java | 12 +- .../CatalogAuthorizationManagerTest.java | 236 +++--- .../managers/AbstractClinicalManagerTest.java | 12 +- .../catalog/managers/AbstractManagerTest.java | 26 +- .../catalog/managers/CatalogManagerTest.java | 424 +++++------ .../managers/ClinicalAnalysisManagerTest.java | 552 +++++++------- .../catalog/managers/DummyModelUtils.java | 2 +- .../catalog/managers/FamilyManagerTest.java | 178 ++--- .../catalog/managers/FileManagerTest.java | 304 ++++---- .../managers/IndividualManagerTest.java | 252 +++---- .../managers/InterpretationManagerTest.java | 36 +- .../catalog/managers/PanelManagerTest.java | 72 +- .../catalog/managers/ProjectManagerTest.java | 50 +- .../catalog/managers/SampleManagerTest.java | 676 +++++++++--------- .../catalog/managers/StudyManagerTest.java | 66 +- .../migration/MigrationManagerTest.java | 6 +- .../stats/solr/AbstractSolrManagerTest.java | 22 +- .../catalog/utils/CatalogFileUtilsTest.java | 2 +- .../CatalogSampleAnnotationsLoaderTest.java | 8 +- .../catalog/utils/FileMetadataReaderTest.java | 18 +- .../catalog/utils/FileScannerTest.java | 6 +- .../templates/TemplateManagerTest.java | 4 +- .../monitor/daemons/ExecutionDaemon.java | 12 +- .../monitor/daemons/ExecutionDaemonTest.java | 54 +- .../models/PrivateJobUpdateParamsTest.java | 4 +- .../opencga/server/rest/CohortWSServer.java | 8 +- .../opencga/server/rest/FamilyWSServer.java | 20 +- .../opencga/server/rest/FileWSServer.java | 8 +- .../server/rest/IndividualWSServer.java | 6 +- .../opencga/server/rest/JobWSServer.java | 8 +- .../opencga/server/rest/OpenCGAWSServer.java | 2 +- .../opencga/server/rest/PanelWSServer.java | 8 +- .../opencga/server/rest/ProjectWSServer.java | 14 +- .../opencga/server/rest/SampleWSServer.java | 10 +- .../opencga/server/rest/StudyWSServer.java | 44 +- .../opencga/server/rest/UserWSServer.java | 2 +- .../rest/analysis/ClinicalWebService.java | 26 +- .../rest/analysis/VariantWebService.java | 7 +- .../rest/fileupload/FileUploadServlet.java | 2 +- .../server/rest/ga4gh/Ga4ghWSServer.java | 6 +- .../server/rest/utils/FileRangesWSServer.java | 2 +- .../opencga/server/rest/FileWSServerTest.java | 2 +- .../server/rest/IndividualWSServerTest.java | 14 +- .../server/rest/SampleWSServerTest.java | 12 +- .../server/rest/VariableSetWSServerTest.java | 2 +- 174 files changed, 3185 insertions(+), 3143 deletions(-) diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/AnalysisUtils.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/AnalysisUtils.java index 628bc63b2ff..1f9b4b375db 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/AnalysisUtils.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/AnalysisUtils.java @@ -1,6 +1,5 @@ package org.opencb.opencga.analysis; -import org.opencb.biodata.models.clinical.qc.RelatednessScore; import org.opencb.commons.datastore.core.Query; import org.opencb.commons.datastore.core.QueryOptions; import org.opencb.opencga.catalog.db.api.FileDBAdaptor; @@ -17,8 +16,6 @@ import java.nio.file.Path; import java.util.*; -import static org.opencb.opencga.core.api.ParamConstants.SAMTOOLS_COMMANDS_SUPPORTED; - public class AnalysisUtils { public static boolean isSupportedCommand(String commands) { @@ -36,7 +33,7 @@ public static File getBamFileBySampleId(String sampleId, String studyId, FileMan Query query = new Query(FileDBAdaptor.QueryParams.FORMAT.key(), File.Format.BAM) .append(FileDBAdaptor.QueryParams.SAMPLE_IDS.key(), sampleId); try { - fileQueryResult = fileManager.search(studyId, query, QueryOptions.empty(), token); + fileQueryResult = fileManager.search(organizationId, studyId, query, QueryOptions.empty(), token); } catch (CatalogException e) { throw new ToolException(e); } @@ -58,7 +55,7 @@ public static File getBamFile(String filename, String sampleId, String studyId, query.put(FileDBAdaptor.QueryParams.SAMPLE_IDS.key(), sampleId); try { - fileQueryResult = fileManager.search(studyId, query, queryOptions, token); + fileQueryResult = fileManager.search(organizationId, studyId, query, queryOptions, token); } catch (CatalogException e) { throw new ToolException(e); } @@ -84,7 +81,7 @@ public static File getCatalogFile(String file, String studyId, FileManager fileM Query query = new Query(FileDBAdaptor.QueryParams.ID.key(), file); - fileQueryResult = fileManager.search(studyId, query, QueryOptions.empty(), token); + fileQueryResult = fileManager.search(organizationId, studyId, query, QueryOptions.empty(), token); // Sanity check if (fileQueryResult.getNumResults() == 0) { @@ -127,7 +124,7 @@ public static Map> parseRelatednessThresholds(Path th public static boolean waitFor(String jobId, String study, JobManager jobManager, String token) throws ToolException, CatalogException { Query query = new Query("id", jobId); - OpenCGAResult result = jobManager.search(study, query, QueryOptions.empty(), token); + OpenCGAResult result = jobManager.search(organizationId, study, query, QueryOptions.empty(), token); Job job = result.first(); String status = job.getInternal().getStatus().getId(); @@ -137,7 +134,7 @@ public static boolean waitFor(String jobId, String study, JobManager jobManager, try { // Sleep for 30 seconds Thread.sleep(30000); - result = jobManager.search(study, query, QueryOptions.empty(), token); + result = jobManager.search(organizationId, study, query, QueryOptions.empty(), token); job = result.first(); } catch (CatalogException | InterruptedException e) { new ToolException("Error waiting for job '" + jobId + "': " + e.getMessage()); @@ -149,7 +146,7 @@ public static boolean waitFor(String jobId, String study, JobManager jobManager, public static Job getJob(String jobId, String study, JobManager jobManager, String token) throws ToolException, CatalogException { Query query = new Query("id", jobId); - OpenCGAResult result = jobManager.search(study, query, QueryOptions.empty(), token); + OpenCGAResult result = jobManager.search(organizationId, study, query, QueryOptions.empty(), token); Job job = result.first(); if (job == null) { new ToolException("Error getting job '" + jobId + "' from study '" + study + "'."); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/ResourceUtils.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/ResourceUtils.java index 11c9741cde2..21bfb6030ba 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/ResourceUtils.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/ResourceUtils.java @@ -116,7 +116,7 @@ public static DownloadedRefGenome downloadRefGenome(String assembly, Path outDir public static String getAssembly(CatalogManager catalogManager, String studyId, String sessionId) throws CatalogException { String assembly = ""; OpenCGAResult projectQueryResult; - projectQueryResult = catalogManager.getProjectManager().search(new Query(ProjectDBAdaptor.QueryParams.STUDY.key(), studyId), + projectQueryResult = catalogManager.getProjectManager().search(organizationId, new Query(ProjectDBAdaptor.QueryParams.STUDY.key(), studyId), new QueryOptions(QueryOptions.INCLUDE, ProjectDBAdaptor.QueryParams.ORGANISM.key()), sessionId); if (CollectionUtils.isNotEmpty(projectQueryResult.getResults()) && projectQueryResult.first().getOrganism() != null diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/StorageManager.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/StorageManager.java index 6fd2ab85719..c2c9ef0f092 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/StorageManager.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/StorageManager.java @@ -100,13 +100,13 @@ protected StudyInfo getStudyInfo(@Nullable String studyIdStr, List fileI StudyInfo studyInfo = new StudyInfo().setSessionId(sessionId); String userId = catalogManager.getUserManager().getUserId(sessionId); - Study study = catalogManager.getStudyManager().get(studyIdStr, QueryOptions.empty(), sessionId).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyIdStr, QueryOptions.empty(), sessionId).first(); List files; if (fileIdStrs.isEmpty()) { files = Collections.emptyList(); } else { - DataResult queryResult = catalogManager.getFileManager().get(studyIdStr, fileIdStrs, null, sessionId); + DataResult queryResult = catalogManager.getFileManager().get(organizationId, studyIdStr, fileIdStrs, null, sessionId); files = queryResult.getResults(); } List fileInfos = new ArrayList<>(fileIdStrs.size()); @@ -130,12 +130,12 @@ protected StudyInfo getStudyInfo(@Nullable String studyIdStr, List fileI studyInfo.setStudy(study); String projectFqn = catalogManager.getStudyManager().getProjectFqn(study.getFqn()); - Project project = catalogManager.getProjectManager().search(new Query(ProjectDBAdaptor.QueryParams.FQN.key(), projectFqn), + Project project = catalogManager.getProjectManager().search(organizationId, new Query(ProjectDBAdaptor.QueryParams.FQN.key(), projectFqn), new QueryOptions(), sessionId).first(); studyInfo.setProjectUid(project.getUid()); studyInfo.setProjectId(project.getId()); studyInfo.setOrganism(project.getOrganism()); - String user = catalogManager.getProjectManager().getOwner(project.getUid()); + String user = catalogManager.getProjectManager().getOwner(organizationId, project.getUid()); studyInfo.setUserId(user); Map dataStores = new HashMap<>(); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/AlignmentCoverageAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/AlignmentCoverageAnalysis.java index fca5b6a8b16..2c206856df4 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/AlignmentCoverageAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/AlignmentCoverageAnalysis.java @@ -65,7 +65,7 @@ protected void check() throws Exception { OpenCGAResult fileResult; try { logger.info("{}: checking file {}", ID, coverageParams.getFile()); - fileResult = catalogManager.getFileManager().get(getStudy(), coverageParams.getFile(), QueryOptions.empty(), getToken()); + fileResult = catalogManager.getFileManager().get(organizationId, getStudy(), coverageParams.getFile(), QueryOptions.empty(), getToken()); } catch (CatalogException e) { throw new ToolException("Error accessing file '" + coverageParams.getFile() + "' of the study " + getStudy() + "'", e); } @@ -143,7 +143,7 @@ protected void run() throws Exception { Path outputCatalogPath = Paths.get(bamCatalogFile.getPath()).getParent().resolve(outputPath.getFileName()); OpenCGAResult fileResult; try { - fileResult = catalogManager.getFileManager().get(getStudy(), outputCatalogPath.toString(), QueryOptions.empty(), + fileResult = catalogManager.getFileManager().get(organizationId, getStudy(), outputCatalogPath.toString(), QueryOptions.empty(), getToken()); if (fileResult.getNumResults() <= 0) { isLinked = false; diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/AlignmentIndexOperation.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/AlignmentIndexOperation.java index 723ca02e16e..c5420f3d827 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/AlignmentIndexOperation.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/AlignmentIndexOperation.java @@ -50,7 +50,7 @@ protected void check() throws Exception { OpenCGAResult fileResult; try { - fileResult = catalogManager.getFileManager().get(getStudy(), inputFile, QueryOptions.empty(), token); + fileResult = catalogManager.getFileManager().get(organizationId, getStudy(), inputFile, QueryOptions.empty(), token); } catch (CatalogException e) { throw new ToolException("Error accessing file '" + inputFile + "' of the study " + study + "'", e); } @@ -96,7 +96,7 @@ protected void run() throws Exception { Path outputCatalogPath = Paths.get(inputCatalogFile.getPath()).getParent().resolve(outputPath.getFileName()); OpenCGAResult fileResult; try { - fileResult = catalogManager.getFileManager().get(getStudy(), outputCatalogPath.toString(), QueryOptions.empty(), token); + fileResult = catalogManager.getFileManager().get(organizationId, getStudy(), outputCatalogPath.toString(), QueryOptions.empty(), token); if (fileResult.getNumResults() <= 0) { isLinked = false; } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/AlignmentStorageManager.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/AlignmentStorageManager.java index 38953f5ff7f..90e51cb4d0e 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/AlignmentStorageManager.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/AlignmentStorageManager.java @@ -221,7 +221,7 @@ public OpenCGAResult coverageStats(String studyIdStr, String // Get species and assembly from catalog OpenCGAResult projectQueryResult = catalogManager.getProjectManager().search( - new Query(ProjectDBAdaptor.QueryParams.STUDY.key(), studyIdStr), + organizationId, new Query(ProjectDBAdaptor.QueryParams.STUDY.key(), studyIdStr), new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(ProjectDBAdaptor.QueryParams.ORGANISM.key(), ProjectDBAdaptor.QueryParams.CELLBASE.key())), token); if (projectQueryResult.getNumResults() != 1) { @@ -439,7 +439,7 @@ public List mergeRegions(List regions, List genes, boole // Get species and assembly from catalog OpenCGAResult projectQueryResult = catalogManager.getProjectManager().search( - new Query(ProjectDBAdaptor.QueryParams.STUDY.key(), study), + organizationId, new Query(ProjectDBAdaptor.QueryParams.STUDY.key(), study), new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( ProjectDBAdaptor.QueryParams.ORGANISM.key(), ProjectDBAdaptor.QueryParams.CELLBASE.key())), token); @@ -537,7 +537,7 @@ public Map> getExonRegionsPerTranscript(String geneName, Ce } private File extractAlignmentOrCoverageFile(String studyIdStr, String fileIdStr, String sessionId) throws CatalogException { - OpenCGAResult fileResult = catalogManager.getFileManager().get(studyIdStr, fileIdStr, QueryOptions.empty(), sessionId); + OpenCGAResult fileResult = catalogManager.getFileManager().get(organizationId, studyIdStr, fileIdStr, QueryOptions.empty(), sessionId); if (fileResult.getNumResults() == 0) { throw new CatalogException("File " + fileIdStr + " not found"); } @@ -583,7 +583,7 @@ private Path getFilePath(long fileId, String sessionId) throws CatalogException, private Path getWorkspace(long studyId, String sessionId) throws CatalogException, IOException { // Obtain the study uri QueryOptions studyOptions = new QueryOptions(QueryOptions.INCLUDE, FileDBAdaptor.QueryParams.URI.key()); - OpenCGAResult studyResult = catalogManager.getStudyManager().get(String.valueOf((Long) studyId), studyOptions, sessionId); + OpenCGAResult studyResult = catalogManager.getStudyManager().get(organizationId, String.valueOf((Long) studyId), studyOptions, sessionId); if (studyResult .getNumResults() != 1) { logger.error("Critical error: Study {} not found in catalog.", studyId); throw new CatalogException("Critical error: Study " + studyId + " not found in catalog"); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentFastQcMetricsAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentFastQcMetricsAnalysis.java index c2541d1560d..cc5dde58f44 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentFastQcMetricsAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentFastQcMetricsAnalysis.java @@ -17,7 +17,6 @@ package org.opencb.opencga.analysis.alignment.qc; import org.apache.commons.lang3.StringUtils; -import org.opencb.biodata.formats.alignment.samtools.SamtoolsFlagstats; import org.opencb.biodata.formats.sequence.fastqc.FastQcMetrics; import org.opencb.biodata.formats.sequence.fastqc.io.FastQcParser; import org.opencb.commons.datastore.core.Query; @@ -29,8 +28,6 @@ import org.opencb.opencga.core.models.alignment.AlignmentFastQcMetricsParams; import org.opencb.opencga.core.models.common.Enums; import org.opencb.opencga.core.models.file.File; -import org.opencb.opencga.core.models.file.FileQualityControl; -import org.opencb.opencga.core.models.file.FileUpdateParams; import org.opencb.opencga.core.response.OpenCGAResult; import org.opencb.opencga.core.tools.annotations.Tool; import org.opencb.opencga.core.tools.annotations.ToolParams; @@ -70,7 +67,7 @@ protected void check() throws Exception { Query query = new Query(FileDBAdaptor.QueryParams.ID.key(), analysisParams.getFile()); query.put(FileDBAdaptor.QueryParams.FORMAT.key(), File.Format.BAM); - OpenCGAResult fileResult = catalogManager.getFileManager().search(getStudy(), query, QueryOptions.empty(), token); + OpenCGAResult fileResult = catalogManager.getFileManager().search(organizationId, getStudy(), query, QueryOptions.empty(), token); if (fileResult.getNumResults() != 1) { throw new ToolException("File " + analysisParams.getFile() + " must be a BAM file in study " + getStudy()); } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentFlagStatsAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentFlagStatsAnalysis.java index e78cab5a9d9..0849771ec33 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentFlagStatsAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentFlagStatsAnalysis.java @@ -30,8 +30,6 @@ import org.opencb.opencga.core.models.alignment.AlignmentFlagStatsParams; import org.opencb.opencga.core.models.common.Enums; import org.opencb.opencga.core.models.file.File; -import org.opencb.opencga.core.models.file.FileQualityControl; -import org.opencb.opencga.core.models.file.FileUpdateParams; import org.opencb.opencga.core.response.OpenCGAResult; import org.opencb.opencga.core.tools.annotations.Tool; import org.opencb.opencga.core.tools.annotations.ToolParams; @@ -74,7 +72,7 @@ protected void check() throws Exception { Query query = new Query(FileDBAdaptor.QueryParams.ID.key(), analysisParams.getFile()); query.put(FileDBAdaptor.QueryParams.FORMAT.key(), File.Format.BAM); - OpenCGAResult fileResult = catalogManager.getFileManager().search(getStudy(), query, QueryOptions.empty(), token); + OpenCGAResult fileResult = catalogManager.getFileManager().search(organizationId, getStudy(), query, QueryOptions.empty(), token); if (fileResult.getNumResults() != 1) { throw new ToolException("File " + analysisParams.getFile() + " must be a BAM file in study " + getStudy()); } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentQcAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentQcAnalysis.java index d4d08bba37f..24edb3b3e11 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentQcAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentQcAnalysis.java @@ -17,7 +17,6 @@ package org.opencb.opencga.analysis.alignment.qc; import org.apache.commons.lang3.StringUtils; -import org.opencb.biodata.formats.alignment.picard.HsMetrics; import org.opencb.biodata.formats.alignment.samtools.SamtoolsFlagstats; import org.opencb.biodata.formats.alignment.samtools.SamtoolsStats; import org.opencb.biodata.formats.sequence.fastqc.FastQcMetrics; @@ -241,7 +240,7 @@ private boolean waitFor(String jobId) throws ToolException { Query query = new Query("id", jobId); OpenCGAResult result = null; try { - result = catalogManager.getJobManager().search(study, query, QueryOptions.empty(), token); + result = catalogManager.getJobManager().search(organizationId, study, query, QueryOptions.empty(), token); } catch (CatalogException e) { new ToolException("Error waiting for job '" + jobId + "': " + e.getMessage()); } @@ -254,7 +253,7 @@ private boolean waitFor(String jobId) throws ToolException { // Sleep for 1 minute try { Thread.sleep(60000); - result = catalogManager.getJobManager().search(study, query, QueryOptions.empty(), token); + result = catalogManager.getJobManager().search(organizationId, study, query, QueryOptions.empty(), token); job = result.first(); } catch (CatalogException | InterruptedException e) { new ToolException("Error waiting for job '" + jobId + "': " + e.getMessage()); @@ -269,7 +268,7 @@ private Job getJob(String jobId) { Job job = null; try { Query query = new Query("id", jobId); - OpenCGAResult result = catalogManager.getJobManager().search(study, query, QueryOptions.empty(), token); + OpenCGAResult result = catalogManager.getJobManager().search(organizationId, study, query, QueryOptions.empty(), token); job = result.first(); } catch (CatalogException e) { new ToolException("Error getting job '" + jobId + "' from catalog: " + e.getMessage()); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentStatsAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentStatsAnalysis.java index d53da2f5299..64e0d2c6853 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentStatsAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/alignment/qc/AlignmentStatsAnalysis.java @@ -18,9 +18,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; -import org.opencb.biodata.formats.alignment.samtools.SamtoolsFlagstats; import org.opencb.biodata.formats.alignment.samtools.SamtoolsStats; -import org.opencb.biodata.formats.alignment.samtools.io.SamtoolsFlagstatsParser; import org.opencb.commons.datastore.core.Query; import org.opencb.commons.datastore.core.QueryOptions; import org.opencb.opencga.analysis.tools.OpenCgaToolScopeStudy; @@ -32,8 +30,6 @@ import org.opencb.opencga.core.models.alignment.AlignmentStatsParams; import org.opencb.opencga.core.models.common.Enums; import org.opencb.opencga.core.models.file.File; -import org.opencb.opencga.core.models.file.FileQualityControl; -import org.opencb.opencga.core.models.file.FileUpdateParams; import org.opencb.opencga.core.response.OpenCGAResult; import org.opencb.opencga.core.tools.annotations.Tool; import org.opencb.opencga.core.tools.annotations.ToolParams; @@ -77,7 +73,7 @@ protected void check() throws Exception { Query query = new Query(FileDBAdaptor.QueryParams.ID.key(), analysisParams.getFile()); query.put(FileDBAdaptor.QueryParams.FORMAT.key(), File.Format.BAM); - OpenCGAResult fileResult = catalogManager.getFileManager().search(getStudy(), query, QueryOptions.empty(), token); + OpenCGAResult fileResult = catalogManager.getFileManager().search(organizationId, getStudy(), query, QueryOptions.empty(), token); if (fileResult.getNumResults() != 1) { throw new ToolException("File " + analysisParams.getFile() + " must be a BAM file in study " + getStudy()); } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/annotations/TsvAnnotationLoader.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/annotations/TsvAnnotationLoader.java index 8fba9b92654..7bdf356b66d 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/annotations/TsvAnnotationLoader.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/annotations/TsvAnnotationLoader.java @@ -73,13 +73,13 @@ public void setStudy(String study) { protected void check() throws Exception { String userId = catalogManager.getUserManager().getUserId(token); - OpenCGAResult fileResult = catalogManager.getFileManager().get(study, path, FileManager.INCLUDE_FILE_URI_PATH, token); + OpenCGAResult fileResult = catalogManager.getFileManager().get(organizationId, study, path, FileManager.INCLUDE_FILE_URI_PATH, token); if (fileResult.getNumResults() == 0) { throw new ToolException("File '" + path + "' not found"); } filePath = Paths.get(fileResult.first().getUri()); - OpenCGAResult variableSetResult = catalogManager.getStudyManager().getVariableSet(study, variableSetId, + OpenCGAResult variableSetResult = catalogManager.getStudyManager().getVariableSet(organizationId, study, variableSetId, QueryOptions.empty(), token); if (variableSetResult.getNumResults() == 0) { throw new ToolException("Variable set '" + variableSetId + "' not found"); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/ClinicalInterpretationManager.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/ClinicalInterpretationManager.java index 50e6d32da75..4856a65803f 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/ClinicalInterpretationManager.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/ClinicalInterpretationManager.java @@ -165,7 +165,7 @@ public DataResult index(String token) { public DataResult index(String study, String token) throws IOException, ClinicalVariantException, CatalogException { DBIterator clinicalAnalysisDBIterator = - clinicalAnalysisManager.iterator(study, new Query(), QueryOptions.empty(), token); + clinicalAnalysisManager.iterator(organizationId, study, new Query(), QueryOptions.empty(), token); while (clinicalAnalysisDBIterator.hasNext()) { ClinicalAnalysis clinicalAnalysis = clinicalAnalysisDBIterator.next(); @@ -297,7 +297,7 @@ public OpenCGAResult get(Query query, QueryOptions queryOptions logger.info("Checking the parameter {} with value = {} in query {}", ParamConstants.INCLUDE_INTERPRETATION, includeInterpretation, query.toJson()); if (StringUtils.isNotEmpty(includeInterpretation)) { - OpenCGAResult interpretationResult = catalogManager.getInterpretationManager().get(studyId, + OpenCGAResult interpretationResult = catalogManager.getInterpretationManager().get(organizationId, studyId, includeInterpretation, QueryOptions.empty(), token); int numResults = interpretationResult.getNumResults(); logger.info("Checking number of results ({}) found for the interpretation ID {}, it should be 1, otherwise something wrong" @@ -545,7 +545,7 @@ public List getDeNovoVariants(String clinicalAnalysisId, String studyId ClinicalAnalysis clinicalAnalysis = getClinicalAnalysis(studyId, clinicalAnalysisId, sessionId); Individual proband = ClinicalUtils.getProband(clinicalAnalysis); - OpenCGAResult studyQueryResult = catalogManager.getStudyManager().get(studyId, + OpenCGAResult studyQueryResult = catalogManager.getStudyManager().get(organizationId, studyId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.FQN.key()), sessionId); if (studyQueryResult.getNumResults() == 0) { throw new ToolException("Study " + studyId + " not found"); @@ -714,7 +714,7 @@ public DefaultClinicalVariantCreator createClinicalVariantCreator(Query query, S public ClinicalAnalysis getClinicalAnalysis(String studyId, String clinicalAnalysisId, String sessionId) throws ToolException, CatalogException { OpenCGAResult clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager() - .get(studyId, clinicalAnalysisId, QueryOptions.empty(), sessionId); + .get(organizationId, studyId, clinicalAnalysisId, QueryOptions.empty(), sessionId); if (clinicalAnalysisQueryResult.getNumResults() == 0) { throw new ToolException("Clinical analysis " + clinicalAnalysisId + " not found in study " + studyId); @@ -746,7 +746,7 @@ public List getDiseasePanels(String studyId, List diseaseP if (CollectionUtils.isNotEmpty(diseasePanelIds)) { OpenCGAResult queryResults; try { - queryResults = catalogManager.getPanelManager().get(studyId, diseasePanelIds, QueryOptions.empty(), + queryResults = catalogManager.getPanelManager().get(organizationId, studyId, diseasePanelIds, QueryOptions.empty(), sessionId); } catch (CatalogException e) { throw new ToolException("Error accessing panel manager", e); @@ -833,7 +833,7 @@ public ClinicalAnalyst getAnalyst(String token) throws ToolException { public String getAssembly(String studyId, String sessionId) throws CatalogException { String assembly = ""; OpenCGAResult projectQueryResult; - projectQueryResult = catalogManager.getProjectManager().search(new Query(ProjectDBAdaptor.QueryParams.STUDY.key(), studyId), + projectQueryResult = catalogManager.getProjectManager().search(organizationId, new Query(ProjectDBAdaptor.QueryParams.STUDY.key(), studyId), new QueryOptions(QueryOptions.INCLUDE, ProjectDBAdaptor.QueryParams.ORGANISM.key()), sessionId); if (CollectionUtils.isNotEmpty(projectQueryResult.getResults())) { assembly = projectQueryResult.first().getOrganism().getAssembly(); @@ -885,7 +885,7 @@ private Query checkQueryPermissions(Query query, String token) throws ClinicalVa if (studyIds.size() == 1) { // This checks that the user has permission to the clinical analysis, family, sample or individual DataResult clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager() - .search(studyIds.get(0), query, QueryOptions.empty(), token); + .search(organizationId, studyIds.get(0), query, QueryOptions.empty(), token); if (clinicalAnalysisQueryResult.getResults().isEmpty()) { throw new ClinicalVariantException("Either the ID does not exist or the user does not have permissions to view it"); @@ -914,7 +914,7 @@ private Query checkQueryPermissions(Query query, String token) throws ClinicalVa // There must be one single owner for all the studies, we do nt allow to query multiple databases if (users.size() == 1) { Query studyQuery = new Query(StudyDBAdaptor.QueryParams.ID.key(), StringUtils.join(studyIds, ",")); - DataResult studyQueryResult = catalogManager.getStudyManager().search(studyQuery, QueryOptions.empty(), token); + DataResult studyQueryResult = catalogManager.getStudyManager().search(organizationId, studyQuery, QueryOptions.empty(), token); // If the user is the owner we do not have to check anything else List studyAliases = new ArrayList<>(studyIds.size()); @@ -948,12 +948,12 @@ private Query checkQueryPermissions(Query query, String token) throws ClinicalVa private void checkInterpretationPermissions(String study, long interpretationId, String token) throws CatalogException, ClinicalVariantException { // Get user ID from token and study numeric ID - String studyId = catalogManager.getStudyManager().get(study, StudyManager.INCLUDE_STUDY_IDS, token).first().getFqn(); + String studyId = catalogManager.getStudyManager().get(organizationId, study, StudyManager.INCLUDE_STUDY_IDS, token).first().getFqn(); // This checks that the user has permission to this interpretation Query query = new Query(ClinicalAnalysisDBAdaptor.QueryParams.INTERPRETATION_ID.key(), interpretationId); DataResult clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager() - .search(studyId, query, QueryOptions.empty(), token); + .search(organizationId, studyId, query, QueryOptions.empty(), token); if (clinicalAnalysisQueryResult.getResults().isEmpty()) { throw new ClinicalVariantException("Either the interpretation ID (" + interpretationId + ") does not exist or the user does" @@ -967,7 +967,7 @@ private List getStudyIds(String userId, Query query) throws CatalogExcep if (query != null && query.containsKey(ClinicalVariantEngine.QueryParams.STUDY.key())) { String study = query.getString(ClinicalVariantEngine.QueryParams.STUDY.key()); List studies = Arrays.asList(study.split(",")); - studyIds = catalogManager.getStudyManager().get(studies, StudyManager.INCLUDE_STUDY_IDS, false, userId) + studyIds = catalogManager.getStudyManager().get(organizationId, studies, StudyManager.INCLUDE_STUDY_IDS, false, userId) .getResults() .stream() .map(Study::getFqn) diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/exomiser/ExomiserInterpretationAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/exomiser/ExomiserInterpretationAnalysis.java index 39fa4fd581c..f7bfd6e7f2a 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/exomiser/ExomiserInterpretationAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/exomiser/ExomiserInterpretationAnalysis.java @@ -94,7 +94,7 @@ protected void check() throws Exception { // Get clinical analysis to ckeck proband sample ID, family ID OpenCGAResult clinicalAnalysisQueryResult; try { - clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager().get(studyId, clinicalAnalysisId, QueryOptions.empty(), + clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyId, clinicalAnalysisId, QueryOptions.empty(), token); } catch ( CatalogException e) { diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/team/TeamInterpretationAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/team/TeamInterpretationAnalysis.java index 29c71be5744..1d5c4d34f33 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/team/TeamInterpretationAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/team/TeamInterpretationAnalysis.java @@ -61,7 +61,7 @@ protected void check() throws Exception { throw new ToolException("Missing study"); } try { - catalogManager.getStudyManager().get(studyId, null, token).first().getFqn(); + catalogManager.getStudyManager().get(organizationId, studyId, null, token).first().getFqn(); } catch (CatalogException e) { throw new ToolException(e); } @@ -74,7 +74,7 @@ protected void check() throws Exception { // Get clinical analysis to ckeck proband sample ID, family ID OpenCGAResult clinicalAnalysisQueryResult; try { - clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager().get(studyId, clinicalAnalysisId, QueryOptions.empty(), + clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyId, clinicalAnalysisId, QueryOptions.empty(), token); } catch (CatalogException e) { throw new ToolException(e); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/tiering/CancerTieringInterpretationAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/tiering/CancerTieringInterpretationAnalysis.java index 94d9344b238..730a8e2c0ef 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/tiering/CancerTieringInterpretationAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/tiering/CancerTieringInterpretationAnalysis.java @@ -64,7 +64,7 @@ protected void check() throws Exception { // Get clinical analysis to ckeck proband sample ID, family ID OpenCGAResult clinicalAnalysisQueryResult; try { - clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager().get(studyId, clinicalAnalysisId, QueryOptions.empty(), + clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyId, clinicalAnalysisId, QueryOptions.empty(), token); } catch (CatalogException e) { throw new ToolException(e); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/tiering/CancerTieringInterpretationAnalysisExecutor.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/tiering/CancerTieringInterpretationAnalysisExecutor.java index ce89757143a..00cbd90a816 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/tiering/CancerTieringInterpretationAnalysisExecutor.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/tiering/CancerTieringInterpretationAnalysisExecutor.java @@ -597,7 +597,7 @@ private List getTier3GenePanels(Individual proband, List p private void addPanels(Query query, List panels) throws CatalogException { if (query.containsKey(PANEL.key())) { List panelsIds = query.getAsStringList(PANEL.key()); - OpenCGAResult panelQueryResult = clinicalInterpretationManager.getCatalogManager().getPanelManager().get(studyId, + OpenCGAResult panelQueryResult = clinicalInterpretationManager.getCatalogManager().getPanelManager().get(organizationId, studyId, panelsIds, QueryOptions.empty(), sessionId); for (org.opencb.opencga.core.models.panel.Panel panel : panelQueryResult.getResults()) { panels.add(panel); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/tiering/TieringInterpretationAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/tiering/TieringInterpretationAnalysis.java index 7a7fbe7ca15..5501df7a600 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/tiering/TieringInterpretationAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/tiering/TieringInterpretationAnalysis.java @@ -69,7 +69,7 @@ protected void check() throws Exception { // Get clinical analysis to ckeck proband sample ID, family ID OpenCGAResult clinicalAnalysisQueryResult; try { - clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager().get(studyId, clinicalAnalysisId, QueryOptions.empty(), + clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyId, clinicalAnalysisId, QueryOptions.empty(), token); } catch ( CatalogException e) { diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/zetta/ZettaInterpretationAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/zetta/ZettaInterpretationAnalysis.java index 91d2304e2c7..1ceb05bc86f 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/zetta/ZettaInterpretationAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/clinical/zetta/ZettaInterpretationAnalysis.java @@ -93,7 +93,7 @@ protected void check() throws Exception { // Get clinical analysis to ckeck proband sample ID, family ID OpenCGAResult clinicalAnalysisQueryResult; try { - clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager().get(studyId, clinicalAnalysisId, QueryOptions.empty(), + clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyId, clinicalAnalysisId, QueryOptions.empty(), token); } catch (CatalogException e) { throw new ToolException(e); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/cohort/CohortIndexTask.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/cohort/CohortIndexTask.java index c5b16bf144b..02e62400d4e 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/cohort/CohortIndexTask.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/cohort/CohortIndexTask.java @@ -58,7 +58,7 @@ protected void run() throws Exception { StudyDBAdaptor.QueryParams.ID.key(), StudyDBAdaptor.QueryParams.FQN.key(), StudyDBAdaptor.QueryParams.VARIABLE_SET.key())) .append(DBAdaptor.INCLUDE_ACLS, true); - OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(query, options, token); + OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(organizationId, query, options, token); if (studyDataResult.getNumResults() == 0) { throw new CatalogException("Could not index catalog into solr. No studies found"); } @@ -90,7 +90,7 @@ private void indexCohort(CatalogSolrManager catalogSolrManager, Study study) thr .append(DBAdaptor.INCLUDE_ACLS, true) .append(ParamConstants.FLATTEN_ANNOTATIONS, true); - catalogSolrManager.insertCatalogCollection(catalogManager.getCohortManager().iterator(study.getFqn(), query, + catalogSolrManager.insertCatalogCollection(catalogManager.getCohortManager().iterator(organizationId, study.getFqn(), query, cohortQueryOptions, token), new CatalogCohortToSolrCohortConverter(study), CatalogSolrManager.COHORT_SOLR_COLLECTION); } } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/cohort/CohortTsvAnnotationLoader.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/cohort/CohortTsvAnnotationLoader.java index 82b8c9e1bb4..1ade09d1516 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/cohort/CohortTsvAnnotationLoader.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/cohort/CohortTsvAnnotationLoader.java @@ -31,7 +31,7 @@ public class CohortTsvAnnotationLoader extends TsvAnnotationLoader { @Override public int count(Query query) throws CatalogException { - return catalogManager.getCohortManager().count(study, query, token).getNumResults(); + return catalogManager.getCohortManager().count(organizationId, study, query, token).getNumResults(); } @Override diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/FamilyIndexTask.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/FamilyIndexTask.java index 7f4d76b1fa4..4f922639925 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/FamilyIndexTask.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/FamilyIndexTask.java @@ -58,7 +58,7 @@ protected void run() throws Exception { StudyDBAdaptor.QueryParams.ID.key(), StudyDBAdaptor.QueryParams.FQN.key(), StudyDBAdaptor.QueryParams.VARIABLE_SET.key())) .append(DBAdaptor.INCLUDE_ACLS, true); - OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(query, options, token); + OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(organizationId, query, options, token); if (studyDataResult.getNumResults() == 0) { throw new CatalogException("Could not index catalog into solr. No studies found"); } @@ -89,7 +89,7 @@ private void indexFamily(CatalogSolrManager catalogSolrManager, Study study) thr .append(DBAdaptor.INCLUDE_ACLS, true) .append(ParamConstants.FLATTEN_ANNOTATIONS, true); - catalogSolrManager.insertCatalogCollection(catalogManager.getFamilyManager().iterator(study.getFqn(), query, + catalogSolrManager.insertCatalogCollection(catalogManager.getFamilyManager().iterator(organizationId, study.getFqn(), query, familyQueryOptions, token), new CatalogFamilyToSolrFamilyConverter(study), CatalogSolrManager.FAMILY_SOLR_COLLECTION); } } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/FamilyTsvAnnotationLoader.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/FamilyTsvAnnotationLoader.java index 6d4091fdce3..50666a075e6 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/FamilyTsvAnnotationLoader.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/FamilyTsvAnnotationLoader.java @@ -31,7 +31,7 @@ public class FamilyTsvAnnotationLoader extends TsvAnnotationLoader { @Override public int count(Query query) throws CatalogException { - return catalogManager.getFamilyManager().count(study, query, token).getNumResults(); + return catalogManager.getFamilyManager().count(organizationId, study, query, token).getNumResults(); } @Override diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/PedigreeGraphAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/PedigreeGraphAnalysis.java index 3d49b12c7fb..dc45eeb4c05 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/PedigreeGraphAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/PedigreeGraphAnalysis.java @@ -53,8 +53,8 @@ protected void check() throws Exception { } // Check family - study = catalogManager.getStudyManager().get(study, QueryOptions.empty(), token).first().getFqn(); - OpenCGAResult familyResult = catalogManager.getFamilyManager().get(study, pedigreeParams.getFamilyId(), + study = catalogManager.getStudyManager().get(organizationId, study, QueryOptions.empty(), token).first().getFqn(); + OpenCGAResult familyResult = catalogManager.getFamilyManager().get(organizationId, study, pedigreeParams.getFamilyId(), QueryOptions.empty(), token); if (familyResult.getNumResults() != 1) { throw new ToolException("Unable to compute the pedigree graph imae. Family '" + pedigreeParams.getFamilyId() + "' not found"); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/PedigreeGraphInitAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/PedigreeGraphInitAnalysis.java index 619c7f3490e..34897c8b57b 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/PedigreeGraphInitAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/PedigreeGraphInitAnalysis.java @@ -69,7 +69,7 @@ protected void run() throws ToolException { step(getId(), () -> { // Get all families from that study QueryOptions queryOptions = new QueryOptions(QueryOptions.INCLUDE, Arrays.asList("id", "members", "pedigreeGraph")); - OpenCGAResult results = catalogManager.getFamilyManager().search(study, new Query(), queryOptions, token); + OpenCGAResult results = catalogManager.getFamilyManager().search(organizationId, study, new Query(), queryOptions, token); // Get families to update by filtering List familiesToUpdate = results.getResults().stream().filter(family -> PedigreeGraphUtils.hasMinTwoGenerations(family) diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/qc/FamilyQcAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/qc/FamilyQcAnalysis.java index 3c624aec0c2..b6821a980e5 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/qc/FamilyQcAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/qc/FamilyQcAnalysis.java @@ -16,16 +16,13 @@ package org.opencb.opencga.analysis.family.qc; -import com.fasterxml.jackson.core.JsonProcessingException; import org.apache.commons.lang3.StringUtils; import org.opencb.commons.datastore.core.QueryOptions; import org.opencb.opencga.analysis.AnalysisUtils; -import org.opencb.opencga.analysis.individual.qc.IndividualQcAnalysis; import org.opencb.opencga.analysis.individual.qc.IndividualQcUtils; import org.opencb.opencga.analysis.tools.OpenCgaTool; import org.opencb.opencga.analysis.variant.relatedness.RelatednessAnalysis; import org.opencb.opencga.catalog.exceptions.CatalogException; -import org.opencb.opencga.core.common.JacksonUtils; import org.opencb.opencga.core.exceptions.ToolException; import org.opencb.opencga.core.models.common.Enums; import org.opencb.opencga.core.models.family.Family; @@ -36,7 +33,6 @@ import org.opencb.opencga.core.tools.variant.FamilyQcAnalysisExecutor; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -71,7 +67,7 @@ protected void check() throws Exception { // Check permissions try { - Study study = catalogManager.getStudyManager().get(studyId, QueryOptions.empty(), token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyId, QueryOptions.empty(), token).first(); String userId = catalogManager.getUserManager().getUserId(token); catalogManager.getAuthorizationManager().checkStudyPermission(study.getUid(), userId, WRITE_FAMILIES); } catch (CatalogException e) { diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/qc/FamilyQcLocalAnalysisExecutor.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/qc/FamilyQcLocalAnalysisExecutor.java index ff0316f42de..54bce2b3be5 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/qc/FamilyQcLocalAnalysisExecutor.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/family/qc/FamilyQcLocalAnalysisExecutor.java @@ -85,7 +85,7 @@ private void runRelatedness() throws ToolException { List sampleIds = new ArrayList<>(); try { - OpenCGAResult individualResult = catalogManager.getIndividualManager().search(getStudyId(), query, queryOptions, + OpenCGAResult individualResult = catalogManager.getIndividualManager().search(organizationId, getStudyId(), query, queryOptions, getToken()); for (Individual individual : individualResult.getResults()) { if (CollectionUtils.isNotEmpty(individual.getSamples())) { diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FetchAndRegisterTask.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FetchAndRegisterTask.java index e400585f536..c95bf18450a 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FetchAndRegisterTask.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FetchAndRegisterTask.java @@ -73,7 +73,7 @@ protected void check() throws Exception { } try { - Study study = catalogManager.getStudyManager().get(studyFqn, StudyManager.INCLUDE_STUDY_IDS, token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyFqn, StudyManager.INCLUDE_STUDY_IDS, token).first(); OpenCGAResult parents = catalogManager.getFileManager().getParents(studyFqn, toolParams.getPath(), false, QueryOptions.empty(), token); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileDeleteTask.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileDeleteTask.java index 89edaa6e683..ed0fd76b75e 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileDeleteTask.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileDeleteTask.java @@ -101,7 +101,7 @@ protected void run() throws Exception { File catalogFile; try { - catalogFile = fileManager.get(studyFqn, file, FileManager.INCLUDE_FILE_URI_PATH, token).first(); + catalogFile = fileManager.get(organizationId, studyFqn, file, FileManager.INCLUDE_FILE_URI_PATH, token).first(); fileManager.checkCanDeleteFile(studyFqn, catalogFile.getUuid(), false, token); } catch (CatalogException e) { logger.error("Error checking file '{}': {}", file, e.getMessage(), e); @@ -132,13 +132,13 @@ protected void run() throws Exception { Query query = new Query() .append(FileDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), FileStatus.PENDING_DELETE) .append(FileDBAdaptor.QueryParams.TAGS.key(), randomMark); - try (DBIterator iterator = fileManager.iterator(studyFqn, query, FileManager.EXCLUDE_FILE_ATTRIBUTES, token)) { + try (DBIterator iterator = fileManager.iterator(organizationId, studyFqn, query, FileManager.EXCLUDE_FILE_ATTRIBUTES, token)) { while (iterator.hasNext()) { File file = iterator.next(); try { logger.info("Deleting file '{}'...", file.getPath()); QueryOptions params = new QueryOptions(Constants.SKIP_TRASH, skipTrash); - fileManager.delete(studyFqn, Collections.singletonList(file.getUuid()), params, token); + fileManager.delete(organizationId, studyFqn, Collections.singletonList(file.getUuid()), params, token); } catch (Exception e) { logger.error("Error deleting file '{}': {}", file.getPath(), e.getMessage(), e); logger.info("Restoring status of file '{}'", file.getPath()); @@ -172,7 +172,7 @@ private void recoverFromFatalCrash() { query.put(FileDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), FileStatus.DELETING); OpenCGAResult fileResult = null; try { - fileResult = catalogManager.getFileManager().search(studyFqn, query, FileManager.EXCLUDE_FILE_ATTRIBUTES, + fileResult = catalogManager.getFileManager().search(organizationId, studyFqn, query, FileManager.EXCLUDE_FILE_ATTRIBUTES, token); } catch (CatalogException e) { logger.error("Critical: Could not check if there are any inconsistent files", e); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileIndexTask.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileIndexTask.java index 50728337279..29f7eb1a246 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileIndexTask.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileIndexTask.java @@ -62,7 +62,7 @@ protected void run() throws Exception { StudyDBAdaptor.QueryParams.ID.key(), StudyDBAdaptor.QueryParams.FQN.key(), StudyDBAdaptor.QueryParams.VARIABLE_SET.key())) .append(DBAdaptor.INCLUDE_ACLS, true); - OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(query, options, token); + OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(organizationId, query, options, token); if (studyDataResult.getNumResults() == 0) { throw new CatalogException("Could not index catalog into solr. No studies found"); } @@ -98,7 +98,7 @@ private void indexFile(CatalogSolrManager catalogSolrManager, Study study) throw .append(DBAdaptor.INCLUDE_ACLS, true) .append(ParamConstants.FLATTEN_ANNOTATIONS, true); - catalogSolrManager.insertCatalogCollection(catalogManager.getFileManager().iterator(study.getFqn(), query, + catalogSolrManager.insertCatalogCollection(catalogManager.getFileManager().iterator(organizationId, study.getFqn(), query, fileQueryOptions, token), new CatalogFileToSolrFileConverter(study), CatalogSolrManager.FILE_SOLR_COLLECTION); } } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileTsvAnnotationLoader.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileTsvAnnotationLoader.java index ddd77ca22af..9ea521accf9 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileTsvAnnotationLoader.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileTsvAnnotationLoader.java @@ -38,7 +38,7 @@ public class FileTsvAnnotationLoader extends TsvAnnotationLoader { @Override public int count(Query query) throws CatalogException { - return catalogManager.getFileManager().count(study, query, token).getNumResults(); + return catalogManager.getFileManager().count(organizationId, study, query, token).getNumResults(); } @Override diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileUnlinkTask.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileUnlinkTask.java index 4340046ff50..acbbbf23811 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileUnlinkTask.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/FileUnlinkTask.java @@ -90,7 +90,7 @@ protected void run() throws Exception { File catalogFile; try { - catalogFile = fileManager.get(studyFqn, file, FileManager.INCLUDE_FILE_URI_PATH, token).first(); + catalogFile = fileManager.get(organizationId, studyFqn, file, FileManager.INCLUDE_FILE_URI_PATH, token).first(); fileManager.checkCanDeleteFile(studyFqn, catalogFile.getUuid(), true, token); } catch (CatalogException e) { logger.error("Error checking file '{}': {}", file, e.getMessage(), e); @@ -121,7 +121,7 @@ protected void run() throws Exception { Query query = new Query() .append(FileDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), FileStatus.PENDING_DELETE) .append(FileDBAdaptor.QueryParams.TAGS.key(), randomMark); - try (DBIterator iterator = fileManager.iterator(studyFqn, query, FileManager.EXCLUDE_FILE_ATTRIBUTES, token)) { + try (DBIterator iterator = fileManager.iterator(organizationId, studyFqn, query, FileManager.EXCLUDE_FILE_ATTRIBUTES, token)) { while (iterator.hasNext()) { File file = iterator.next(); try { diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/PostLinkSampleAssociation.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/PostLinkSampleAssociation.java index 60d67f05996..c0b580204f7 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/PostLinkSampleAssociation.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/file/PostLinkSampleAssociation.java @@ -71,7 +71,7 @@ protected void run() throws Exception { OpenCGAResult fileResult; if (files == null) { // We need to associate all non-associated files - fileResult = catalogManager.getFileManager().search(study, fileQuery, options, token); + fileResult = catalogManager.getFileManager().search(organizationId, study, fileQuery, options, token); if (fileResult.getNumResults() == 0) { break; } @@ -80,7 +80,7 @@ protected void run() throws Exception { if (files.isEmpty()) { break; } - fileResult = catalogManager.getFileManager().get(study, files.remove(0), options, token); + fileResult = catalogManager.getFileManager().get(organizationId, study, files.remove(0), options, token); } if (numPendingFiles < 0) { numPendingFiles = ((int) fileResult.getNumMatches()); @@ -103,7 +103,7 @@ protected void run() throws Exception { } } if (!virtualFiles.isEmpty()) { - fileResult = catalogManager.getFileManager().get(study, new ArrayList<>(virtualFiles), options, token); + fileResult = catalogManager.getFileManager().get(organizationId, study, new ArrayList<>(virtualFiles), options, token); fileList.addAll(fileResult.getResults()); } @@ -126,7 +126,7 @@ protected void run() throws Exception { if (!sampleExists(sampleId)) { try { // Sample still doesn't exist, so we create it - OpenCGAResult sampleResult = catalogManager.getSampleManager().create(study, new Sample().setId(sampleId), + OpenCGAResult sampleResult = catalogManager.getSampleManager().create(organizationId, study, new Sample().setId(sampleId), QueryOptions.empty(), token); if (sampleResult.getNumResults() != 1) { throw new CatalogException("Could not create sample '" + sampleId + "'"); @@ -218,7 +218,7 @@ protected void run() throws Exception { private boolean sampleExists(String sampleId) throws CatalogException { Query sampleQuery = new Query(SampleDBAdaptor.QueryParams.ID.key(), sampleId); - OpenCGAResult sampleResult = catalogManager.getSampleManager().search(study, sampleQuery, + OpenCGAResult sampleResult = catalogManager.getSampleManager().search(organizationId, study, sampleQuery, SampleManager.INCLUDE_SAMPLE_IDS, token); return sampleResult.getNumResults() == 1; diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/IndividualIndexTask.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/IndividualIndexTask.java index 48ddf3ae512..34bd4d1d04a 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/IndividualIndexTask.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/IndividualIndexTask.java @@ -59,7 +59,7 @@ protected void run() throws Exception { StudyDBAdaptor.QueryParams.ID.key(), StudyDBAdaptor.QueryParams.FQN.key(), StudyDBAdaptor.QueryParams.VARIABLE_SET.key())) .append(DBAdaptor.INCLUDE_ACLS, true); - OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(query, options, token); + OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(organizationId, query, options, token); if (studyDataResult.getNumResults() == 0) { throw new CatalogException("Could not index catalog into solr. No studies found"); } @@ -97,7 +97,7 @@ private void indexIndividual(CatalogSolrManager catalogSolrManager, Study study) .append(DBAdaptor.INCLUDE_ACLS, true) .append(ParamConstants.FLATTEN_ANNOTATIONS, true); - catalogSolrManager.insertCatalogCollection(catalogManager.getIndividualManager().iterator(study.getFqn(), query, + catalogSolrManager.insertCatalogCollection(catalogManager.getIndividualManager().iterator(organizationId, study.getFqn(), query, individualQueryOptions, token), new CatalogIndividualToSolrIndividualConverter(study), CatalogSolrManager.INDIVIDUAL_SOLR_COLLECTION); } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/IndividualTsvAnnotationLoader.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/IndividualTsvAnnotationLoader.java index 3c53ac46524..f0d02f14b17 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/IndividualTsvAnnotationLoader.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/IndividualTsvAnnotationLoader.java @@ -31,7 +31,7 @@ public class IndividualTsvAnnotationLoader extends TsvAnnotationLoader { @Override public int count(Query query) throws CatalogException { - return catalogManager.getIndividualManager().count(study, query, token).getNumResults(); + return catalogManager.getIndividualManager().count(organizationId, study, query, token).getNumResults(); } @Override diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/qc/IndividualQcAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/qc/IndividualQcAnalysis.java index ba859bb9f49..67eba9068d2 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/qc/IndividualQcAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/qc/IndividualQcAnalysis.java @@ -82,7 +82,7 @@ protected void check() throws Exception { // Check permissions try { - Study study = catalogManager.getStudyManager().get(studyId, QueryOptions.empty(), token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyId, QueryOptions.empty(), token).first(); String userId = catalogManager.getUserManager().getUserId(token); catalogManager.getAuthorizationManager().checkStudyPermission(study.getUid(), userId, WRITE_INDIVIDUALS); } catch (CatalogException e) { diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/qc/IndividualQcUtils.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/qc/IndividualQcUtils.java index 091cea875a8..63efb7f7854 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/qc/IndividualQcUtils.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/individual/qc/IndividualQcUtils.java @@ -101,7 +101,7 @@ public static List getSamples(String study, String familyId, CatalogMana } try { - OpenCGAResult familyResult = catalogManager.getFamilyManager().get(study, familyId, QueryOptions.empty(), token); + OpenCGAResult familyResult = catalogManager.getFamilyManager().get(organizationId, study, familyId, QueryOptions.empty(), token); // Check family result if (familyResult.getResults().size() == 0) { @@ -118,7 +118,7 @@ public static List getSamples(String study, String familyId, CatalogMana Query query = new Query(IndividualDBAdaptor.QueryParams.ID.key(), individualIds); QueryOptions queryOptions = new QueryOptions(QueryOptions.INCLUDE, "samples.id"); - OpenCGAResult individualResult = catalogManager.getIndividualManager().search(study, query, queryOptions, token); + OpenCGAResult individualResult = catalogManager.getIndividualManager().search(organizationId, study, query, queryOptions, token); for (Individual individual : individualResult.getResults()) { sampleSet.addAll(individual.getSamples().stream().map(s -> s.getId()).collect(Collectors.toList())); } @@ -132,7 +132,7 @@ public static List getSamples(String study, String familyId, CatalogMana public static String getAssembly(String study, CatalogManager catalogManager, String token) throws CatalogException { String assembly = ""; OpenCGAResult projectQueryResult; - projectQueryResult = catalogManager.getProjectManager().search(new Query(ProjectDBAdaptor.QueryParams.STUDY.key(), study), + projectQueryResult = catalogManager.getProjectManager().search(organizationId, new Query(ProjectDBAdaptor.QueryParams.STUDY.key(), study), new QueryOptions(QueryOptions.INCLUDE, ProjectDBAdaptor.QueryParams.ORGANISM.key()), token); if (CollectionUtils.isNotEmpty(projectQueryResult.getResults())) { assembly = projectQueryResult.first().getOrganism().getAssembly(); @@ -147,7 +147,7 @@ public static Family getFamilyById(String studyId, String familyId, CatalogManag throws ToolException { OpenCGAResult familyResult; try { - familyResult = catalogManager.getFamilyManager().get(studyId, familyId, QueryOptions.empty(), token); + familyResult = catalogManager.getFamilyManager().get(organizationId, studyId, familyId, QueryOptions.empty(), token); } catch (CatalogException e) { throw new ToolException(e); } @@ -162,7 +162,7 @@ public static Family getFamilyByIndividualId(String studyId, String individualId query.put("members", individualId); OpenCGAResult familyResult; try { - familyResult = catalogManager.getFamilyManager().search(studyId, query, QueryOptions.empty(), token); + familyResult = catalogManager.getFamilyManager().search(organizationId, studyId, query, QueryOptions.empty(), token); } catch (CatalogException e) { throw new ToolException(e); } @@ -184,7 +184,7 @@ public static Individual getIndividualById(String studyId, String individualId, throws ToolException { OpenCGAResult individualResult; try { - individualResult = catalogManager.getIndividualManager().get(studyId, individualId, QueryOptions.empty(), + individualResult = catalogManager.getIndividualManager().get(organizationId, studyId, individualId, QueryOptions.empty(), token); } catch (CatalogException e) { throw new ToolException(e); @@ -204,7 +204,7 @@ public static Individual getIndividualBySampleId(String studyId, String sampleId query.put("samples", sampleId); OpenCGAResult individualResult; try { - individualResult = catalogManager.getIndividualManager().search(studyId, query, QueryOptions.empty(), token); + individualResult = catalogManager.getIndividualManager().search(organizationId, studyId, query, QueryOptions.empty(), token); } catch (CatalogException e) { throw new ToolException(e); } @@ -224,7 +224,7 @@ public static Sample getValidSampleByIndividualId(String studyId, String individ query.put("individualId", individualId); OpenCGAResult sampleResult; try { - sampleResult = catalogManager.getSampleManager().search(studyId, query, QueryOptions.empty(), token); + sampleResult = catalogManager.getSampleManager().search(organizationId, studyId, query, QueryOptions.empty(), token); } catch (CatalogException e) { throw new ToolException(e); } @@ -246,7 +246,7 @@ public static List getValidSamplesByIndividualId(String studyId, String query.put("individualId", individualId); OpenCGAResult sampleResult; try { - sampleResult = catalogManager.getSampleManager().search(studyId, query, QueryOptions.empty(), token); + sampleResult = catalogManager.getSampleManager().search(organizationId, studyId, query, QueryOptions.empty(), token); } catch (CatalogException e) { throw new ToolException(e); } @@ -274,7 +274,7 @@ public static Sample getValidSampleById(String studyId, String sampleId, Catalog throws ToolException { OpenCGAResult sampleResult; try { - sampleResult = catalogManager.getSampleManager().get(studyId, sampleId, QueryOptions.empty(), token); + sampleResult = catalogManager.getSampleManager().get(organizationId, studyId, sampleId, QueryOptions.empty(), token); } catch (CatalogException e) { throw new ToolException(e); } @@ -296,7 +296,7 @@ public static List getRelativeSamplesByFamilyId(String studyId, String f OpenCGAResult familyResult; try { - familyResult = catalogManager.getFamilyManager().get(studyId, familyId, QueryOptions.empty(), token); + familyResult = catalogManager.getFamilyManager().get(organizationId, studyId, familyId, QueryOptions.empty(), token); } catch (CatalogException e) { throw new ToolException(e); } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/job/JobIndexTask.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/job/JobIndexTask.java index 7eec33c901d..c76483a9f7a 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/job/JobIndexTask.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/job/JobIndexTask.java @@ -57,7 +57,7 @@ protected void run() throws Exception { StudyDBAdaptor.QueryParams.ID.key(), StudyDBAdaptor.QueryParams.FQN.key(), StudyDBAdaptor.QueryParams.VARIABLE_SET.key())) .append(DBAdaptor.INCLUDE_ACLS, true); - OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(query, options, token); + OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(organizationId, query, options, token); if (studyDataResult.getNumResults() == 0) { throw new CatalogException("Could not index catalog into solr. No studies found"); } @@ -89,7 +89,7 @@ private void indexJob(CatalogSolrManager catalogSolrManager, Study study) throws JobDBAdaptor.QueryParams.TAGS.key(), JobDBAdaptor.QueryParams.EXECUTION.key())) .append(DBAdaptor.INCLUDE_ACLS, true); - catalogSolrManager.insertCatalogCollection(catalogManager.getJobManager().iterator(study.getFqn(), query, jobQueryOptions, token), + catalogSolrManager.insertCatalogCollection(catalogManager.getJobManager().iterator(organizationId, study.getFqn(), query, jobQueryOptions, token), new JobSolrConverter(study), CatalogSolrManager.JOB_SOLR_COLLECTION); } } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/rga/RgaManager.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/rga/RgaManager.java index 5acff933d6e..035fb32ee71 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/rga/RgaManager.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/rga/RgaManager.java @@ -126,7 +126,7 @@ private void checkStorageReadMode() throws RgaException { // Data load public void index(String studyStr, String fileStr, String token) throws CatalogException, RgaException, IOException { - File file = catalogManager.getFileManager().get(studyStr, fileStr, FileManager.INCLUDE_FILE_URI_PATH, token).first(); + File file = catalogManager.getFileManager().get(organizationId, studyStr, fileStr, FileManager.INCLUDE_FILE_URI_PATH, token).first(); Path filePath = Paths.get(file.getUri()); index(studyStr, filePath, token); } @@ -143,7 +143,7 @@ public void index(String studyStr, String fileStr, String token) throws CatalogE public void index(String study, Path file, String token) throws CatalogException, IOException, RgaException { checkStorageReadMode(); String userId = catalogManager.getUserManager().getUserId(token); - Study studyObject = catalogManager.getStudyManager().get(study, QueryOptions.empty(), token).first(); + Study studyObject = catalogManager.getStudyManager().get(organizationId, study, QueryOptions.empty(), token).first(); try { catalogManager.getAuthorizationManager().isOwnerOrAdmin(studyObject.getUid(), userId); } catch (CatalogException e) { @@ -226,7 +226,7 @@ private void load(String study, Path file, String token) throws RgaException { public void generateAuxiliarCollection(String studyStr, String token) throws CatalogException, RgaException, IOException { checkStorageReadMode(); String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().get(studyStr, QueryOptions.empty(), token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first(); try { catalogManager.getAuthorizationManager().isOwnerOrAdmin(study.getUid(), userId); } catch (CatalogException e) { @@ -297,7 +297,7 @@ public void generateAuxiliarCollection(String studyStr, String token) throws Cat } // Update RGA Index status from Study - catalogManager.getStudyManager().updateSummaryIndex(studyStr, + catalogManager.getStudyManager().updateSummaryIndex(organizationId, studyStr, new RecessiveGeneSummaryIndex(RecessiveGeneSummaryIndex.Status.INDEXED, TimeUtils.getTime()), token); } @@ -432,7 +432,7 @@ private AuxiliarRgaDataModel getAuxiliarRgaDataModel(String mainCollection, Stri private OpenCGAResult updateRgaInternalIndexStatus(String studyStr, List sampleIds, RgaIndex.Status status, String token) throws CatalogException, RgaException { - Study study = catalogManager.getStudyManager().get(studyStr, QueryOptions.empty(), token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first(); String userId = catalogManager.getUserManager().getUserId(token); String collection = getMainCollectionName(study.getFqn()); @@ -475,7 +475,7 @@ private OpenCGAResult updateRgaInternalIndexStatus(String studyStr, List updateRgaInternalIndexStatus(String studyStr, String token) throws CatalogException, IOException, RgaException { - Study study = catalogManager.getStudyManager().get(studyStr, QueryOptions.empty(), token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first(); String userId = catalogManager.getUserManager().getUserId(token); String collection = getMainCollectionName(study.getFqn()); @@ -535,7 +535,7 @@ public OpenCGAResult individualQuery(String studyStr, Quer return cacheResults; } - Study study = catalogManager.getStudyManager().get(studyStr, QueryOptions.empty(), token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first(); String collection = getMainCollectionName(study.getFqn()); Preprocess preprocess; @@ -618,7 +618,7 @@ public OpenCGAResult geneQuery(String studyStr, Query query, return cacheResults; } - Study study = catalogManager.getStudyManager().get(studyStr, QueryOptions.empty(), token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first(); String userId = catalogManager.getUserManager().getUserId(token); String collection = getMainCollectionName(study.getFqn()); if (!rgaEngine.isAlive(collection)) { @@ -668,7 +668,7 @@ public OpenCGAResult geneQuery(String studyStr, Query query, .append(ACL_PARAM, userId + ":" + SamplePermissions.VIEW_VARIANTS) .append(SampleDBAdaptor.QueryParams.INTERNAL_RGA_STATUS.key(), RgaIndex.Status.INDEXED) .append(SampleDBAdaptor.QueryParams.ID.key(), includeIndividuals); - OpenCGAResult authorisedSampleIdResult = catalogManager.getSampleManager().distinct(study.getFqn(), + OpenCGAResult authorisedSampleIdResult = catalogManager.getSampleManager().distinct(organizationId, study.getFqn(), SampleDBAdaptor.QueryParams.ID.key(), sampleQuery, token); includeSampleIds = new HashSet<>((List) authorisedSampleIdResult.getResults()); } else { @@ -684,7 +684,7 @@ public OpenCGAResult geneQuery(String studyStr, Query query, // 3. Get list of sample ids for which the user has permissions Query sampleQuery = new Query(ACL_PARAM, userId + ":" + SamplePermissions.VIEW_VARIANTS) .append(SampleDBAdaptor.QueryParams.ID.key(), sampleIds); - OpenCGAResult authorisedSampleIdResult = catalogManager.getSampleManager().distinct(study.getFqn(), + OpenCGAResult authorisedSampleIdResult = catalogManager.getSampleManager().distinct(organizationId, study.getFqn(), SampleDBAdaptor.QueryParams.ID.key(), sampleQuery, token); // TODO: The number of samples to include could be really high includeSampleIds = new HashSet<>((List) authorisedSampleIdResult.getResults()); @@ -701,7 +701,7 @@ public OpenCGAResult geneQuery(String studyStr, Query query, logger.warn("Include only the samples that are actually necessary"); } - OpenCGAResult sampleResult = catalogManager.getSampleManager().distinct(study.getFqn(), + OpenCGAResult sampleResult = catalogManager.getSampleManager().distinct(organizationId, study.getFqn(), SampleDBAdaptor.QueryParams.ID.key(), sampleQuery, token); includeSampleIds = new HashSet<>((List) sampleResult.getResults()); } @@ -752,7 +752,7 @@ public OpenCGAResult variantQuery(String studyStr, Query quer return cacheResults; } - Study study = catalogManager.getStudyManager().get(studyStr, QueryOptions.empty(), token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first(); String userId = catalogManager.getUserManager().getUserId(token); String collection = getMainCollectionName(study.getFqn()); String auxCollection = getAuxCollectionName(study.getFqn()); @@ -789,7 +789,7 @@ public OpenCGAResult variantQuery(String studyStr, Query quer .append(ACL_PARAM, userId + ":" + SamplePermissions.VIEW_VARIANTS) .append(SampleDBAdaptor.QueryParams.INTERNAL_RGA_STATUS.key(), RgaIndex.Status.INDEXED) .append(SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key(), includeIndividuals); - OpenCGAResult authorisedSampleIdResult = catalogManager.getSampleManager().distinct(study.getFqn(), + OpenCGAResult authorisedSampleIdResult = catalogManager.getSampleManager().distinct(organizationId, study.getFqn(), SampleDBAdaptor.QueryParams.ID.key(), sampleQuery, token); includeSampleIds = new HashSet<>((List) authorisedSampleIdResult.getResults()); } else { @@ -808,7 +808,7 @@ public OpenCGAResult variantQuery(String studyStr, Query quer Query sampleQuery = new Query() .append(ACL_PARAM, userId + ":" + SamplePermissions.VIEW_VARIANTS) .append(SampleDBAdaptor.QueryParams.ID.key(), sampleIds); - OpenCGAResult authorisedSampleIdResult = catalogManager.getSampleManager().distinct(study.getFqn(), + OpenCGAResult authorisedSampleIdResult = catalogManager.getSampleManager().distinct(organizationId, study.getFqn(), SampleDBAdaptor.QueryParams.ID.key(), sampleQuery, token); includeSampleIds = new HashSet<>((List) authorisedSampleIdResult.getResults()); } @@ -823,7 +823,7 @@ public OpenCGAResult variantQuery(String studyStr, Query quer logger.warn("Include only the samples that are actually necessary"); } - OpenCGAResult sampleResult = catalogManager.getSampleManager().distinct(study.getFqn(), + OpenCGAResult sampleResult = catalogManager.getSampleManager().distinct(organizationId, study.getFqn(), SampleDBAdaptor.QueryParams.ID.key(), sampleQuery, token); includeSampleIds = new HashSet<>((List) sampleResult.getResults()); } @@ -920,7 +920,7 @@ public OpenCGAResult individualSummary(String study return cacheResults; } - Study study = catalogManager.getStudyManager().get(studyStr, QueryOptions.empty(), token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first(); String collection = getMainCollectionName(study.getFqn()); ExecutorService executor = Executors.newFixedThreadPool(4); @@ -1047,7 +1047,7 @@ public OpenCGAResult geneSummary(String studyStr, Query q return cacheResults; } - Study study = catalogManager.getStudyManager().get(studyStr, QueryOptions.empty(), token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first(); String userId = catalogManager.getUserManager().getUserId(token); String collection = getMainCollectionName(study.getFqn()); if (!rgaEngine.isAlive(collection)) { @@ -1131,7 +1131,7 @@ public OpenCGAResult variantSummary(String studyStr, Q return cacheResults; } - Study study = catalogManager.getStudyManager().get(studyStr, QueryOptions.empty(), token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first(); String userId = catalogManager.getUserManager().getUserId(token); String collection = getMainCollectionName(study.getFqn()); String auxCollection = getAuxCollectionName(study.getFqn()); @@ -1237,7 +1237,7 @@ public OpenCGAResult variantSummary(String studyStr, Q public OpenCGAResult aggregationStats(String studyStr, Query query, QueryOptions options, String fields, String token) throws CatalogException, IOException, RgaException { - Study study = catalogManager.getStudyManager().get(studyStr, QueryOptions.empty(), token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first(); String userId = catalogManager.getUserManager().getUserId(token); catalogManager.getAuthorizationManager().checkCanViewStudy(study.getUid(), userId); @@ -1713,7 +1713,7 @@ private Set getAuthorisedSamples(String study, Set sampleIds, Li query.put(ACL_PARAM, userId + ":" + StringUtils.join(otherPermissions, ",")); } - OpenCGAResult distinct = catalogManager.getSampleManager().distinct(study, SampleDBAdaptor.QueryParams.ID.key(), query, token); + OpenCGAResult distinct = catalogManager.getSampleManager().distinct(organizationId, study, SampleDBAdaptor.QueryParams.ID.key(), query, token); return distinct.getResults().stream().map(String::valueOf).collect(Collectors.toSet()); } @@ -1753,7 +1753,7 @@ private Preprocess individualQueryPreprocess(Study study, Query query, QueryOpti catalogQuery.put(ACL_PARAM, userId + ":" + SamplePermissions.VIEW_VARIANTS); } - OpenCGAResult search = catalogManager.getSampleManager().search(study.getFqn(), catalogQuery, catalogOptions, token); + OpenCGAResult search = catalogManager.getSampleManager().search(organizationId, study.getFqn(), catalogQuery, catalogOptions, token); stopWatch.stop(); logger.info("Fetch first {} individuals from Catalog with skip {} and count {}: {} milliseconds.", limit, skip, count, stopWatch.getTime(TimeUnit.MILLISECONDS)); @@ -1813,7 +1813,7 @@ private Preprocess individualQueryPreprocess(Study study, Query query, QueryOpti List tmpValues = values.subList(currentBatch, Math.min(values.size(), batchSize + currentBatch)); sampleQuery.put(sampleQueryField, tmpValues); - OpenCGAResult authorisedSampleIdResult = catalogManager.getSampleManager().distinct(study.getFqn(), + OpenCGAResult authorisedSampleIdResult = catalogManager.getSampleManager().distinct(organizationId, study.getFqn(), SampleDBAdaptor.QueryParams.ID.key(), sampleQuery, token); authorisedSamples.addAll((Collection) authorisedSampleIdResult.getResults()); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/sample/SampleIndexTask.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/sample/SampleIndexTask.java index 33c0800742b..1d0b2c38dd6 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/sample/SampleIndexTask.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/sample/SampleIndexTask.java @@ -58,7 +58,7 @@ protected void run() throws Exception { StudyDBAdaptor.QueryParams.ID.key(), StudyDBAdaptor.QueryParams.FQN.key(), StudyDBAdaptor.QueryParams.VARIABLE_SET.key())) .append(DBAdaptor.INCLUDE_ACLS, true); - OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(query, options, token); + OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(organizationId, query, options, token); if (studyDataResult.getNumResults() == 0) { throw new CatalogException("Could not index catalog into solr. No studies found"); } @@ -93,7 +93,7 @@ private void indexSample(CatalogSolrManager catalogSolrManager, Study study) thr .append(DBAdaptor.INCLUDE_ACLS, true) .append(ParamConstants.FLATTEN_ANNOTATIONS, true); - catalogSolrManager.insertCatalogCollection(catalogManager.getSampleManager().iterator(study.getFqn(), query, sampleQueryOptions, + catalogSolrManager.insertCatalogCollection(catalogManager.getSampleManager().iterator(organizationId, study.getFqn(), query, sampleQueryOptions, token), new CatalogSampleToSolrSampleConverter(study), CatalogSolrManager.SAMPLE_SOLR_COLLECTION); } } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/sample/SampleTsvAnnotationLoader.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/sample/SampleTsvAnnotationLoader.java index adeb819720b..382eed844d1 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/sample/SampleTsvAnnotationLoader.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/sample/SampleTsvAnnotationLoader.java @@ -31,7 +31,7 @@ public class SampleTsvAnnotationLoader extends TsvAnnotationLoader { @Override public int count(Query query) throws CatalogException { - return catalogManager.getSampleManager().count(study, query, token).getNumResults(); + return catalogManager.getSampleManager().count(organizationId, study, query, token).getNumResults(); } @Override diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/sample/qc/SampleQcAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/sample/qc/SampleQcAnalysis.java index a103568d020..62ae7fedf10 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/sample/qc/SampleQcAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/sample/qc/SampleQcAnalysis.java @@ -18,19 +18,11 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.opencb.biodata.formats.alignment.picard.HsMetrics; -import org.opencb.biodata.formats.alignment.samtools.SamtoolsFlagstats; -import org.opencb.biodata.formats.alignment.samtools.SamtoolsStats; -import org.opencb.biodata.formats.sequence.fastqc.FastQcMetrics; import org.opencb.biodata.models.clinical.qc.*; import org.opencb.commons.datastore.core.Event; import org.opencb.commons.datastore.core.ObjectMap; import org.opencb.commons.datastore.core.QueryOptions; import org.opencb.opencga.analysis.AnalysisUtils; -import org.opencb.opencga.analysis.alignment.qc.AlignmentFastQcMetricsAnalysis; -import org.opencb.opencga.analysis.alignment.qc.AlignmentFlagStatsAnalysis; -import org.opencb.opencga.analysis.alignment.qc.AlignmentHsMetricsAnalysis; -import org.opencb.opencga.analysis.alignment.qc.AlignmentStatsAnalysis; import org.opencb.opencga.analysis.individual.qc.IndividualQcUtils; import org.opencb.opencga.analysis.tools.OpenCgaToolScopeStudy; import org.opencb.opencga.analysis.variant.genomePlot.GenomePlotAnalysis; @@ -40,12 +32,8 @@ import org.opencb.opencga.core.api.ParamConstants; import org.opencb.opencga.core.common.JacksonUtils; import org.opencb.opencga.core.exceptions.ToolException; -import org.opencb.opencga.core.models.alignment.AlignmentFileQualityControl; -import org.opencb.opencga.core.models.alignment.AlignmentQcParams; import org.opencb.opencga.core.models.common.Enums; import org.opencb.opencga.core.models.file.File; -import org.opencb.opencga.core.models.file.FileQualityControl; -import org.opencb.opencga.core.models.file.FileUpdateParams; import org.opencb.opencga.core.models.job.Job; import org.opencb.opencga.core.models.sample.Sample; import org.opencb.opencga.core.models.sample.SampleQualityControl; @@ -63,7 +51,6 @@ import java.nio.file.Paths; import java.util.*; -import static org.opencb.opencga.analysis.variant.mutationalSignature.MutationalSignatureAnalysis.*; import static org.opencb.opencga.core.models.study.StudyPermissions.Permissions.WRITE_SAMPLES; @Tool(id = SampleQcAnalysis.ID, resource = Enums.Resource.SAMPLE, description = SampleQcAnalysis.DESCRIPTION) @@ -93,7 +80,7 @@ protected void check() throws Exception { // Check permissions try { - long studyUid = catalogManager.getStudyManager().get(getStudy(), QueryOptions.empty(), token).first().getUid(); + long studyUid = catalogManager.getStudyManager().get(organizationId, getStudy(), QueryOptions.empty(), token).first().getUid(); String userId = catalogManager.getUserManager().getUserId(token); catalogManager.getAuthorizationManager().checkStudyPermission(studyUid, userId, WRITE_SAMPLES); } catch (CatalogException e) { diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/templates/TemplateRunner.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/templates/TemplateRunner.java index 08797e1185e..0819866d051 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/templates/TemplateRunner.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/templates/TemplateRunner.java @@ -38,7 +38,7 @@ protected void check() throws Exception { templateManager = new TemplateManager(catalogManager, templateParams.isResume(), templateParams.isOverwrite(), token); String studyFqn = getStudyFqn(); - Study study = catalogManager.getStudyManager().get(studyFqn, + Study study = catalogManager.getStudyManager().get(organizationId, studyFqn, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.URI.key()), token).first(); // We obtain the basic studyPath where we will upload the file temporarily diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/tools/OpenCgaToolScopeStudy.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/tools/OpenCgaToolScopeStudy.java index 016ffa32058..8dc1819a70e 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/tools/OpenCgaToolScopeStudy.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/tools/OpenCgaToolScopeStudy.java @@ -46,7 +46,7 @@ public String getStudy() { } protected final String getStudyFqn() throws CatalogException { - return getCatalogManager().getStudyManager().get(getParams().getString(ParamConstants.STUDY_PARAM), StudyManager.INCLUDE_STUDY_IDS, + return getCatalogManager().getStudyManager().get(organizationId, getParams().getString(ParamConstants.STUDY_PARAM), StudyManager.INCLUDE_STUDY_IDS, getToken()).first().getFqn(); } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/tools/ToolRunner.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/tools/ToolRunner.java index 88a96004a3f..cf5d12f55e6 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/tools/ToolRunner.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/tools/ToolRunner.java @@ -64,7 +64,7 @@ public ToolRunner(String opencgaHome, CatalogManager catalogManager, VariantStor */ public ExecutionResult execute(String study, String jobId, String token) throws CatalogException, ToolException { // We get the job information. - Job job = catalogManager.getJobManager().get(study, jobId, QueryOptions.empty(), token).first(); + Job job = catalogManager.getJobManager().get(organizationId, study, jobId, QueryOptions.empty(), token).first(); return execute(job, token); } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/genomePlot/GenomePlotAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/genomePlot/GenomePlotAnalysis.java index f7f63f37706..caf9f3b9b89 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/genomePlot/GenomePlotAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/genomePlot/GenomePlotAnalysis.java @@ -83,7 +83,7 @@ protected void run() throws ToolException { // Update quality control for the catalog sample if (StringUtils.isNotEmpty(genomePlotParams.getSample())) { - OpenCGAResult sampleResult = getCatalogManager().getSampleManager().get(getStudy(), genomePlotParams.getSample(), + OpenCGAResult sampleResult = getCatalogManager().getSampleManager().get(organizationId, getStudy(), genomePlotParams.getSample(), QueryOptions.empty(), getToken()); Sample sample = sampleResult.first(); if (sample != null) { diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/gwas/GwasAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/gwas/GwasAnalysis.java index a5d2484b2d7..5695b7a13cd 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/gwas/GwasAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/gwas/GwasAnalysis.java @@ -204,7 +204,7 @@ protected void check() throws Exception { } try { - study = catalogManager.getStudyManager().get(study, null, token).first().getFqn(); + study = catalogManager.getStudyManager().get(organizationId, study, null, token).first().getFqn(); } catch (CatalogException e) { throw new ToolException(e); } @@ -363,7 +363,7 @@ private List getCohortSamples(List inputSamples, String cohort, samples = new ArrayList<>(); catalogManager.getSampleManager() - .iterator(study, query, options, token) + .iterator(organizationId, study, query, options, token) .forEachRemaining(sample -> { Phenotype.Status status = null; for (Phenotype p : sample.getPhenotypes()) { @@ -377,7 +377,7 @@ private List getCohortSamples(List inputSamples, String cohort, }); } else if (validCohort) { samples = catalogManager.getCohortManager() - .get(study, cohort, new QueryOptions(), token) + .get(organizationId, study, cohort, new QueryOptions(), token) .first() .getSamples() .stream() @@ -385,7 +385,7 @@ private List getCohortSamples(List inputSamples, String cohort, .collect(Collectors.toList()); } else { samples = catalogManager.getSampleManager() - .search(study, samplesQuery, new QueryOptions(QueryOptions.INCLUDE, "id"), token) + .search(organizationId, study, samplesQuery, new QueryOptions(QueryOptions.INCLUDE, "id"), token) .getResults() .stream() .map(Sample::getId) diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/hrdetect/HRDetectAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/hrdetect/HRDetectAnalysis.java index f6dee08bd8e..3fa54c79e47 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/hrdetect/HRDetectAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/hrdetect/HRDetectAnalysis.java @@ -298,8 +298,8 @@ public static HRDetect parseResult(HRDetectAnalysisParams hrdetectParams, Path d } private Sample checkSample(String sampleId) throws ToolException, CatalogException { - study = catalogManager.getStudyManager().get(study, QueryOptions.empty(), token).first().getFqn(); - OpenCGAResult sampleResult = catalogManager.getSampleManager().get(study, sampleId, QueryOptions.empty(), token); + study = catalogManager.getStudyManager().get(organizationId, study, QueryOptions.empty(), token).first().getFqn(); + OpenCGAResult sampleResult = catalogManager.getSampleManager().get(organizationId, study, sampleId, QueryOptions.empty(), token); if (sampleResult.getNumResults() != 1) { throw new ToolException("Unable to compute HRDetect analysis. Sample '" + hrdetectParams.getSampleId() + "' not found"); } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/inferredSex/InferredSexAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/inferredSex/InferredSexAnalysis.java index 5af0792ac38..1fd02cbf41a 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/inferredSex/InferredSexAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/inferredSex/InferredSexAnalysis.java @@ -71,7 +71,7 @@ protected void check() throws Exception { } try { - studyId = catalogManager.getStudyManager().get(studyId, null, token).first().getFqn(); + studyId = catalogManager.getStudyManager().get(organizationId, studyId, null, token).first().getFqn(); } catch (CatalogException e) { throw new ToolException(e); } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/julie/JulieTool.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/julie/JulieTool.java index 5c25bf2a4ff..06aad326c5d 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/julie/JulieTool.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/julie/JulieTool.java @@ -59,7 +59,7 @@ protected void check() throws Exception { String study = value.substring(0, idx); String cohort = value.substring(idx + 1); String studyFqn = getCatalogManager().getStudyManager() - .get(study, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.FQN.key()), getToken()) + .get(organizationId, study, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.FQN.key()), getToken()) .first() .getFqn(); cohorts.computeIfAbsent(studyFqn, key -> new LinkedList<>()).add(cohort); @@ -67,7 +67,7 @@ protected void check() throws Exception { for (Map.Entry> entry : cohorts.entrySet()) { String study = entry.getKey(); List cohorts = getCatalogManager().getCohortManager() - .get(study, entry.getValue(), new QueryOptions(QueryOptions.INCLUDE, "id"), getToken()).getResults(); + .get(organizationId, study, entry.getValue(), new QueryOptions(QueryOptions.INCLUDE, "id"), getToken()).getResults(); if (cohorts.size() != entry.getValue().size()) { // This should not happen. The previous command should throw exception if some cohort is missing throw new IllegalArgumentException("Missing cohorts from study " + study); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/knockout/KnockoutAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/knockout/KnockoutAnalysis.java index 34b337731a5..a6e17e1fa82 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/knockout/KnockoutAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/knockout/KnockoutAnalysis.java @@ -162,7 +162,7 @@ protected void run() throws Exception { if (CollectionUtils.isNotEmpty(analysisParams.getPanel())) { List panels = getCatalogManager() .getPanelManager() - .get(getStudy(), analysisParams.getPanel(), new QueryOptions(), getToken()) + .get(organizationId, getStudy(), analysisParams.getPanel(), new QueryOptions(), getToken()) .getResults(); for (Panel panel : panels) { for (DiseasePanel.GenePanel gene : panel.getGenes()) { @@ -198,7 +198,7 @@ protected void run() throws Exception { step("list-families", () -> { Query familyQuery = new Query(IndividualDBAdaptor.QueryParams.SAMPLES.key(), analysisParams.getSample()); for (Family family : getCatalogManager().getFamilyManager() - .search(getStudy(), familyQuery, new QueryOptions(), getToken()).getResults()) { + .search(organizationId, getStudy(), familyQuery, new QueryOptions(), getToken()).getResults()) { if (family == null || StringUtils.isEmpty(family.getId())) { continue; } @@ -270,7 +270,7 @@ protected void run() throws Exception { samples++; Individual individual = catalogManager .getIndividualManager() - .search(getStudy(), new Query(IndividualDBAdaptor.QueryParams.SAMPLES.key(), knockoutByIndividual.getSampleId()), + .search(organizationId, getStudy(), new Query(IndividualDBAdaptor.QueryParams.SAMPLES.key(), knockoutByIndividual.getSampleId()), new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( IndividualDBAdaptor.QueryParams.ID.key(), IndividualDBAdaptor.QueryParams.SEX_ID.key(), @@ -299,7 +299,7 @@ protected void run() throws Exception { parentsIndividuals.add(knockoutByIndividual.getMotherId()); } if (!parentsIndividuals.isEmpty()) { - for (Individual parent : catalogManager.getIndividualManager().get(study, parentsIndividuals, + for (Individual parent : catalogManager.getIndividualManager().get(organizationId, study, parentsIndividuals, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(IndividualDBAdaptor.QueryParams.ID.key(), IndividualDBAdaptor.QueryParams.SAMPLES.key() + ".id")), token).getResults()) { if (parent.getSamples() != null && !parent.getSamples().isEmpty()) { @@ -358,7 +358,7 @@ protected void run() throws Exception { if (individualId == null) { Individual individualObj = catalogManager .getIndividualManager() - .search(getStudy(), + .search(organizationId, getStudy(), new Query(IndividualDBAdaptor.QueryParams.SAMPLES.key(), individual.getSampleId()), new QueryOptions(QueryOptions.INCLUDE, IndividualDBAdaptor.QueryParams.ID.key()), getToken()) diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/knockout/KnockoutAnalysisResultReader.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/knockout/KnockoutAnalysisResultReader.java index 23c3e19e0aa..690dd861acc 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/knockout/KnockoutAnalysisResultReader.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/knockout/KnockoutAnalysisResultReader.java @@ -45,7 +45,7 @@ private DataResult readKnockoutObjectFromJob(String study, String jobId, String fileName, Class c) throws IOException, CatalogException { StopWatch started = StopWatch.createStarted(); - Job job = catalogManager.getJobManager().get(study, jobId, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( + Job job = catalogManager.getJobManager().get(organizationId, study, jobId, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( JobDBAdaptor.QueryParams.ID.key(), JobDBAdaptor.QueryParams.UUID.key(), JobDBAdaptor.QueryParams.OUTPUT.key(), diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/CatalogUtils.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/CatalogUtils.java index e13193675d5..d7fd20a3b2e 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/CatalogUtils.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/CatalogUtils.java @@ -105,7 +105,7 @@ public List getStudies(Query query, String sessionId) throws CatalogExce if (isValidParam(query, VariantCatalogQueryUtils.PROJECT)) { String project = query.getString(VariantCatalogQueryUtils.PROJECT.key()); return catalogManager.getStudyManager() - .search(project, new Query(), new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.FQN.key()), sessionId) + .search(organizationId, project, new Query(), new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.FQN.key()), sessionId) .getResults() .stream() .map(Study::getFqn) @@ -120,13 +120,13 @@ public List getStudies(Query query, String sessionId) throws CatalogExce Collections.singleton(VariantField.STUDIES)); } else { // Get all studies from user. - return catalogManager.getStudyManager().search(new Query(), StudyManager.INCLUDE_STUDY_IDS, sessionId).getResults() + return catalogManager.getStudyManager().search(organizationId, new Query(), StudyManager.INCLUDE_STUDY_IDS, sessionId).getResults() .stream() .map(Study::getFqn) .collect(Collectors.toList()); } } - return catalogManager.getStudyManager().get(studies, StudyManager.INCLUDE_STUDY_IDS, false, sessionId).getResults() + return catalogManager.getStudyManager().get(organizationId, studies, StudyManager.INCLUDE_STUDY_IDS, false, sessionId).getResults() .stream() .map(Study::getFqn) .collect(Collectors.toList()); @@ -135,11 +135,11 @@ public List getStudies(Query query, String sessionId) throws CatalogExce public Project getProjectFromQuery(Query query, String sessionId, QueryOptions options) throws CatalogException { if (isValidParam(query, VariantCatalogQueryUtils.PROJECT)) { String project = query.getString(VariantCatalogQueryUtils.PROJECT.key()); - return catalogManager.getProjectManager().get(project, options, sessionId).first(); + return catalogManager.getProjectManager().get(organizationId, project, options, sessionId).first(); } else { String studyFqn = getAnyStudy(query, sessionId); String project = catalogManager.getStudyManager().getProjectFqn(studyFqn); - return catalogManager.getProjectManager().search(new Query(ProjectDBAdaptor.QueryParams.FQN.key(), project), options, sessionId) + return catalogManager.getProjectManager().search(organizationId, new Query(ProjectDBAdaptor.QueryParams.FQN.key(), project), options, sessionId) .first(); } } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/VariantCatalogQueryUtils.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/VariantCatalogQueryUtils.java index 2d08fb77566..3b595d567ba 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/VariantCatalogQueryUtils.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/VariantCatalogQueryUtils.java @@ -320,7 +320,7 @@ public Query parseQuery(Query query, QueryOptions queryOptions, CellBaseUtils ce .append(FileDBAdaptor.QueryParams.INTERNAL_VARIANT_INDEX_STATUS_ID.key(), VariantIndexStatus.READY); for (String study : studies) { - for (File file : catalogManager.getFileManager().search(study, fileQuery, fileOptions, token) + for (File file : catalogManager.getFileManager().search(organizationId, study, fileQuery, fileOptions, token) .getResults()) { includeFiles.add(file.getName()); } @@ -339,7 +339,7 @@ public Query parseQuery(Query query, QueryOptions queryOptions, CellBaseUtils ce QueryOptions cohortOptions = new QueryOptions(INCLUDE, CohortDBAdaptor.QueryParams.SAMPLE_UIDS.key()); // Get default cohort. It contains the list of indexed samples. If it doesn't exist, or is empty, do not include any // sample from this study. - DataResult result = catalogManager.getCohortManager().search(study, cohortQuery, cohortOptions, token); + DataResult result = catalogManager.getCohortManager().search(organizationId, study, cohortQuery, cohortOptions, token); if (result.first() != null || result.first().getSamples().isEmpty()) { Set sampleIds = result .first() @@ -347,7 +347,7 @@ public Query parseQuery(Query query, QueryOptions queryOptions, CellBaseUtils ce .stream() .map(Sample::getId) .collect(Collectors.toSet()); - for (Sample s : catalogManager.getSampleManager().search(study, sampleQuery, sampleOptions, token) + for (Sample s : catalogManager.getSampleManager().search(organizationId, study, sampleQuery, sampleOptions, token) .getResults()) { if (sampleIds.contains(s.getId())) { includeSamples.add(s.getId()); @@ -364,7 +364,7 @@ public Query parseQuery(Query query, QueryOptions queryOptions, CellBaseUtils ce Query sampleQuery = parseSampleAnnotationQuery(sampleAnnotation, SampleDBAdaptor.QueryParams::getParam); sampleQuery.append(SampleDBAdaptor.QueryParams.STUDY_UID.key(), defaultStudyStr); QueryOptions options = new QueryOptions(INCLUDE, SampleDBAdaptor.QueryParams.UID); - List sampleIds = catalogManager.getSampleManager().search(defaultStudyStr, sampleQuery, options, token) + List sampleIds = catalogManager.getSampleManager().search(organizationId, defaultStudyStr, sampleQuery, options, token) .getResults() .stream() .map(Sample::getId) @@ -399,7 +399,7 @@ public Query parseQuery(Query query, QueryOptions queryOptions, CellBaseUtils ce if (StringUtils.isEmpty(defaultStudyStr)) { throw VariantQueryException.missingStudyFor("family", familyId, null); } - Family family = catalogManager.getFamilyManager().get(defaultStudyStr, familyId, null, token).first(); + Family family = catalogManager.getFamilyManager().get(organizationId, defaultStudyStr, familyId, null, token).first(); if (family.getMembers().isEmpty()) { throw VariantQueryException.malformedParam(FAMILY, familyId, "Empty family"); @@ -449,7 +449,7 @@ public Query parseQuery(Query query, QueryOptions queryOptions, CellBaseUtils ce throw VariantQueryException.malformedParam(FAMILY, familyId, "Family not indexed in storage"); } - List samples = catalogManager.getSampleManager().search(defaultStudyStr, + List samples = catalogManager.getSampleManager().search(organizationId, defaultStudyStr, new Query(SampleDBAdaptor.QueryParams.UID.key(), sampleUids), new QueryOptions(INCLUDE, Arrays.asList( SampleDBAdaptor.QueryParams.ID.key(), SampleDBAdaptor.QueryParams.UID.key())), token).getResults(); @@ -958,7 +958,7 @@ protected static Set getGenesFromPanel(Query query, Panel panel) { * @throws CatalogException on catalog exception */ private String toIndividualId(String study, String individuaOrSample, String token) throws CatalogException { - OpenCGAResult result = catalogManager.getIndividualManager().search(study, + OpenCGAResult result = catalogManager.getIndividualManager().search(organizationId, study, new Query(IndividualDBAdaptor.QueryParams.SAMPLES.key(), individuaOrSample), new QueryOptions(INCLUDE, IndividualDBAdaptor.QueryParams.ID.key()), token); @@ -995,20 +995,20 @@ private Region processSampleFilter(Query query, String defaultStudyStr, CellBase } String sampleId = sampleFilter.getValues().get(0).getKey(); - Sample sample = catalogManager.getSampleManager().get(defaultStudyStr, sampleId, new QueryOptions(), token).first(); + Sample sample = catalogManager.getSampleManager().get(organizationId, defaultStudyStr, sampleId, new QueryOptions(), token).first(); if (StringUtils.isEmpty(sample.getIndividualId())) { throw VariantQueryException.malformedParam(SAMPLE, sampleFilterValue, "Sample '" + sampleId + "' does not have an Individual associated."); } Set indexedSampleUids = fetchIndexedSampleUIds(token, defaultStudyStr); - Individual individual = catalogManager.getIndividualManager().get(defaultStudyStr, sample.getIndividualId(), new QueryOptions(), token).first(); + Individual individual = catalogManager.getIndividualManager().get(organizationId, defaultStudyStr, sample.getIndividualId(), new QueryOptions(), token).first(); Member member = new Member(sampleId, sampleId, individual.getSex()); member.setDisorders(individual.getDisorders()); if (individual.getFather() != null) { - Individual father = catalogManager.getIndividualManager().get(defaultStudyStr, individual.getFather().getId(), new QueryOptions(), token).first(); + Individual father = catalogManager.getIndividualManager().get(organizationId, defaultStudyStr, individual.getFather().getId(), new QueryOptions(), token).first(); String fatherId = null; int numSamples = 0; for (Sample s : father.getSamples()) { @@ -1025,7 +1025,7 @@ private Region processSampleFilter(Query query, String defaultStudyStr, CellBase } } if (individual.getMother() != null) { - Individual mother = catalogManager.getIndividualManager().get(defaultStudyStr, individual.getMother().getId(), new QueryOptions(), token).first(); + Individual mother = catalogManager.getIndividualManager().get(organizationId, defaultStudyStr, individual.getMother().getId(), new QueryOptions(), token).first(); String motherId = null; int numSamples = 0; for (Sample s : mother.getSamples()) { @@ -1104,7 +1104,7 @@ private Region processSampleFilter(Query query, String defaultStudyStr, CellBase private Set fetchIndexedSampleUIds(String token, String defaultStudyStr) throws CatalogException { // Use search instead of get to avoid smartResolutor to fetch all samples return catalogManager.getCohortManager() - .search(defaultStudyStr, new Query(CohortDBAdaptor.QueryParams.ID.key(), StudyEntry.DEFAULT_COHORT), + .search(organizationId, defaultStudyStr, new Query(CohortDBAdaptor.QueryParams.ID.key(), StudyEntry.DEFAULT_COHORT), new QueryOptions(INCLUDE, CohortDBAdaptor.QueryParams.SAMPLE_UIDS.key()), token) .first() .getSamples() @@ -1255,7 +1255,7 @@ public Panel getPanel(String studyId, String panelId, String sessionId) throws C Panel panel = null; if (StringUtils.isNotEmpty(studyId)) { try { - panel = catalogManager.getPanelManager().get(studyId, panelId, null, sessionId).first(); + panel = catalogManager.getPanelManager().get(organizationId, studyId, panelId, null, sessionId).first(); } catch (CatalogException e) { logger.debug("Ignore Panel not found", e); } @@ -1317,7 +1317,7 @@ public List> getTriosFromSamples( String studyFqn, VariantStorageMetadataManager metadataManager, Collection sampleIds, String token) throws CatalogException { OpenCGAResult individualResult = catalogManager.getIndividualManager() - .search(studyFqn, + .search(organizationId, studyFqn, new Query(IndividualDBAdaptor.QueryParams.SAMPLES.key(), sampleIds), new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( IndividualDBAdaptor.QueryParams.ID.key(), @@ -1343,7 +1343,7 @@ public List> getTrios( if (CollectionUtils.isNotEmpty(individual.getSamples())) { for (Sample sample : individual.getSamples()) { - sample = catalogManager.getSampleManager().search(studyFqn, + sample = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.UID.key(), sample.getUid()), new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ID.key()), sessionId).first(); Integer sampleId = metadataManager.getSampleId(studyId, sample.getId(), true); @@ -1358,14 +1358,14 @@ public List> getTrios( Individual father = membersMap.get(uid); if (father == null) { father = catalogManager.getIndividualManager() - .search(studyFqn, + .search(organizationId, studyFqn, new Query(IndividualDBAdaptor.QueryParams.UID.key(), uid), new QueryOptions(INCLUDE, IndividualDBAdaptor.QueryParams.SAMPLE_UIDS.key()), sessionId).first(); membersMap.put(uid, father); } if (CollectionUtils.isNotEmpty(father.getSamples())) { for (Sample sample : father.getSamples()) { - sample = catalogManager.getSampleManager().search(studyFqn, + sample = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.UID.key(), sample.getUid()), new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ID.key()), sessionId).first(); Integer sampleId = metadataManager.getSampleId(studyId, sample.getId(), true); @@ -1381,14 +1381,14 @@ public List> getTrios( Individual mother = membersMap.get(uid); if (mother == null) { mother = catalogManager.getIndividualManager() - .search(studyFqn, + .search(organizationId, studyFqn, new Query(IndividualDBAdaptor.QueryParams.UID.key(), uid), new QueryOptions(INCLUDE, IndividualDBAdaptor.QueryParams.SAMPLE_UIDS.key()), sessionId).first(); membersMap.put(uid, mother); } if (CollectionUtils.isNotEmpty(mother.getSamples())) { for (Sample sample : mother.getSamples()) { - sample = catalogManager.getSampleManager().search(studyFqn, + sample = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.UID.key(), sample.getUid()), new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ID.key()), sessionId).first(); Integer sampleId = metadataManager.getSampleId(studyId, sample.getId(), true); @@ -1513,7 +1513,7 @@ protected final List validate(String default Function getId, Function getRelease, Consumer valueValidator, String sessionId, Query query) throws CatalogException { - DataResult queryResult = manager.get(defaultStudyStr, values, query, RELEASE_OPTIONS, false, sessionId); + DataResult queryResult = manager.get(organizationId, defaultStudyStr, values, query, RELEASE_OPTIONS, false, sessionId); List validatedValues = new ArrayList<>(values.size()); for (T value : queryResult.getResults()) { if (valueValidator != null) { @@ -1534,12 +1534,12 @@ public class StudyFilterValidator extends FilterValidator { protected List validate(String defaultStudyStr, List values, Integer release, VariantQueryParam param, String sessionId) throws CatalogException { if (release == null) { - List studies = catalogManager.getStudyManager().get(values, StudyManager.INCLUDE_STUDY_IDS, false, sessionId) + List studies = catalogManager.getStudyManager().get(organizationId, values, StudyManager.INCLUDE_STUDY_IDS, false, sessionId) .getResults(); return studies.stream().map(Study::getFqn).collect(Collectors.toList()); } else { List validatedValues = new ArrayList<>(values.size()); - DataResult queryResult = catalogManager.getStudyManager().get(values, RELEASE_OPTIONS, false, sessionId); + DataResult queryResult = catalogManager.getStudyManager().get(organizationId, values, RELEASE_OPTIONS, false, sessionId); for (Study study : queryResult.getResults()) { validatedValues.add(study.getFqn()); checkRelease(release, study.getRelease(), param, study.getFqn()); @@ -1556,7 +1556,7 @@ protected List validate(String defaultStudyStr, List values, Int String sessionId) throws CatalogException { if (release == null) { - DataResult files = catalogManager.getFileManager().get(defaultStudyStr, values, + DataResult files = catalogManager.getFileManager().get(organizationId, defaultStudyStr, values, FileManager.INCLUDE_FILE_IDS, sessionId); return files.getResults().stream().map(File::getName).collect(Collectors.toList()); } else { @@ -1614,12 +1614,12 @@ protected List validate(String defaultStudyStr, List values, Int // DataResult samples = catalogManager.getSampleManager().get(defaultStudyStr, values, // SampleManager.INCLUDE_SAMPLE_IDS, sessionId); long numMatches = catalogManager.getSampleManager() - .count(defaultStudyStr, new Query(SampleDBAdaptor.QueryParams.ID.key(), values) + .count(organizationId, defaultStudyStr, new Query(SampleDBAdaptor.QueryParams.ID.key(), values) .append(ParamConstants.ACL_PARAM, userId + ":" + SamplePermissions.VIEW_VARIANTS), sessionId).getNumMatches(); if (numMatches != values.size()) { OpenCGAResult samples = catalogManager.getSampleManager() - .search(defaultStudyStr, new Query(SampleDBAdaptor.QueryParams.ID.key(), values), + .search(organizationId, defaultStudyStr, new Query(SampleDBAdaptor.QueryParams.ID.key(), values), SampleManager.INCLUDE_SAMPLE_IDS, sessionId); if (samples.getResults().size() != values.size()) { // Can not view some samples. May not exist @@ -1655,9 +1655,9 @@ protected List validate(String defaultStudyStr, List values, Int study = split[0]; value = split[1]; } - Cohort cohort = catalogManager.getCohortManager().get(study, value, CohortManager.INCLUDE_COHORT_IDS, sessionId) + Cohort cohort = catalogManager.getCohortManager().get(organizationId, study, value, CohortManager.INCLUDE_COHORT_IDS, sessionId) .first(); - String fqn = catalogManager.getStudyManager().get(study, + String fqn = catalogManager.getStudyManager().get(organizationId, study, new QueryOptions(INCLUDE, StudyDBAdaptor.QueryParams.FQN.key()), sessionId).first().getFqn(); if (fqn.equals(defaultStudyStr)) { validated.add(cohort.getId()); @@ -1667,7 +1667,7 @@ protected List validate(String defaultStudyStr, List values, Int } return validated; } else { - DataResult cohorts = catalogManager.getCohortManager().get(defaultStudyStr, values, + DataResult cohorts = catalogManager.getCohortManager().get(organizationId, defaultStudyStr, values, CohortManager.INCLUDE_COHORT_IDS, sessionId); return cohorts.getResults().stream().map(Cohort::getId).collect(Collectors.toList()); } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/VariantStorageManager.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/VariantStorageManager.java index 806fbb6d818..764861a839f 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/VariantStorageManager.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/VariantStorageManager.java @@ -348,13 +348,13 @@ public void variantScoreLoad(String study, URI scoreFile, String scoreName, Stri String cohort1Id; String cohort2Id; - Cohort cohort1Obj = catalogManager.getCohortManager().get(study, cohort1, new QueryOptions(), token).first(); + Cohort cohort1Obj = catalogManager.getCohortManager().get(organizationId, study, cohort1, new QueryOptions(), token).first(); List cohort1Samples = cohort1Obj.getSamples().stream().map(Sample::getId).collect(Collectors.toList()); engine.getMetadataManager().registerCohort(studyFqn, cohort1Obj.getId(), cohort1Samples); cohort1Id = cohort1Obj.getId(); if (StringUtils.isNotEmpty(cohort2)) { - Cohort cohort2Obj = catalogManager.getCohortManager().get(study, cohort2, new QueryOptions(), token).first(); + Cohort cohort2Obj = catalogManager.getCohortManager().get(organizationId, study, cohort2, new QueryOptions(), token).first(); List cohort2Samples = cohort2Obj.getSamples().stream().map(Sample::getId).collect(Collectors.toList()); engine.getMetadataManager().registerCohort(studyFqn, cohort2Obj.getId(), cohort2Samples); cohort2Id = cohort2Obj.getId(); @@ -413,14 +413,14 @@ public DataResult> familyIndex(String study, List familiesS VariantStorageMetadataManager metadataManager = engine.getMetadataManager(); VariantCatalogQueryUtils catalogUtils = new VariantCatalogQueryUtils(catalogManager); if (familiesStr.size() == 1 && familiesStr.get(0).equals(VariantQueryUtils.ALL)) { - DBIterator iterator = catalogManager.getFamilyManager().iterator(study, new Query(), new QueryOptions(), token); + DBIterator iterator = catalogManager.getFamilyManager().iterator(organizationId, study, new Query(), new QueryOptions(), token); while (iterator.hasNext()) { Family family = iterator.next(); trios.addAll(catalogUtils.getTriosFromFamily(study, family, metadataManager, true, token)); } } else { for (String familyId : familiesStr) { - Family family = catalogManager.getFamilyManager().get(study, familyId, null, token).first(); + Family family = catalogManager.getFamilyManager().get(organizationId, study, familyId, null, token).first(); trios.addAll(catalogUtils.getTriosFromFamily(study, family, metadataManager, skipIncompleteFamilies, token)); } } @@ -484,7 +484,7 @@ public ObjectMap configureProject(String projectStr, ObjectMap params, String to dataStore.getOptions().putAll(params); catalogManager.getProjectManager() - .setDatastoreVariant(projectStr, dataStore, token); + .setDatastoreVariant(organizationId, projectStr, dataStore, token); return dataStore.getOptions(); }); } @@ -492,7 +492,7 @@ public ObjectMap configureProject(String projectStr, ObjectMap params, String to public ObjectMap configureStudy(String studyStr, ObjectMap params, String token) throws CatalogException, StorageEngineException { return secureOperation("configure", studyStr, params, token, engine -> { Study study = catalogManager.getStudyManager() - .get(studyStr, + .get(organizationId, studyStr, new QueryOptions(INCLUDE, StudyDBAdaptor.QueryParams.INTERNAL_CONFIGURATION_VARIANT_ENGINE_OPTIONS.key()), token) .first(); @@ -507,7 +507,7 @@ public ObjectMap configureStudy(String studyStr, ObjectMap params, String token) } options.putAll(params); catalogManager.getStudyManager() - .setVariantEngineConfigurationOptions(studyStr, options, token); + .setVariantEngineConfigurationOptions(organizationId, studyStr, options, token); // String studyFqn = getStudyFqn(studyStr, token); // engine.getConfigurationManager().configureStudy(studyFqn, params); return options; @@ -535,7 +535,7 @@ public OpenCGAResult configureSampleIndex(String studyStr, SampleIndexConfi engine.getMetadataManager().addSampleIndexConfiguration(studyFqn, sampleIndexConfiguration, true); catalogManager.getStudyManager() - .setVariantEngineConfigurationSampleIndex(studyStr, sampleIndexConfiguration, token); + .setVariantEngineConfigurationSampleIndex(organizationId, studyStr, sampleIndexConfiguration, token); if (skipRebuild) { return new OpenCGAResult<>(0, new ArrayList<>(), 0, new ArrayList<>(), 0); } else { @@ -605,7 +605,7 @@ public OpenCGAResult setCellbaseConfiguration(String project, CellBaseConfi } } } - catalogManager.getProjectManager().setCellbaseConfiguration(project, validatedCellbaseConfiguration, false, token); + catalogManager.getProjectManager().setCellbaseConfiguration(organizationId, project, validatedCellbaseConfiguration, false, token); result.setTime((int) stopwatch.getTime(TimeUnit.MILLISECONDS)); return result; }); @@ -832,7 +832,7 @@ public DataResult getSampleData(String variant, String study, QueryOpti StopWatch checkPermissionsStopWatch = StopWatch.createStarted(); String userId = catalogManager.getUserManager().getUserId(token); List validSamples = catalogManager.getSampleManager() - .search(study, + .search(organizationId, study, new Query(SampleDBAdaptor.QueryParams.ID.key(), samplesInResult) .append(ACL_PARAM, userId + ":" + SamplePermissions.VIEW_VARIANTS), new QueryOptions(INCLUDE, SampleDBAdaptor.QueryParams.ID.key()), token) @@ -962,7 +962,7 @@ protected VariantStorageEngine getVariantStorageEngineForStudyOperation(String s throws StorageEngineException, CatalogException { // String projectFqn = catalogManager.getStudyManager().getProjectFqn(getStudyFqn(study, token)); Study study = catalogManager.getStudyManager() - .get(studyStr, new QueryOptions(INCLUDE, Arrays.asList( + .get(organizationId, studyStr, new QueryOptions(INCLUDE, Arrays.asList( StudyDBAdaptor.QueryParams.FQN.key(), StudyDBAdaptor.QueryParams.INTERNAL_CONFIGURATION_VARIANT_ENGINE.key())), token) .first(); @@ -1014,7 +1014,7 @@ protected VariantStorageEngine getVariantStorageEngineByProject(String project, private void setCellbaseConfiguration(VariantStorageEngine engine, String project, String token) throws CatalogException { CellBaseConfiguration cellbase = catalogManager.getProjectManager() - .get(project, new QueryOptions(INCLUDE, ProjectDBAdaptor.QueryParams.CELLBASE.key()), token) + .get(organizationId, project, new QueryOptions(INCLUDE, ProjectDBAdaptor.QueryParams.CELLBASE.key()), token) .first().getCellbase(); if (cellbase != null) { if (StringUtils.isEmpty(cellbase.getToken()) || storageConfiguration.getCellbase() != null) { @@ -1061,7 +1061,7 @@ public void checkQueryPermissions(Query query, QueryOptions queryOptions, String public Set getIndexedSamples(String study, String token) throws CatalogException { OpenCGAResult cohortResult = catalogManager .getCohortManager() - .search(study, new Query(CohortDBAdaptor.QueryParams.ID.key(), StudyEntry.DEFAULT_COHORT), + .search(organizationId, study, new Query(CohortDBAdaptor.QueryParams.ID.key(), StudyEntry.DEFAULT_COHORT), new QueryOptions(INCLUDE, Arrays.asList( CohortDBAdaptor.QueryParams.ID.key(), CohortDBAdaptor.QueryParams.SAMPLES.key() + "." + SampleDBAdaptor.QueryParams.ID.key() @@ -1108,7 +1108,7 @@ public boolean synchronizeCatalogStudyFromStorage(String study, List fil String studySqn = getStudyFqn(study, token); return secureOperation("synchronizeCatalogStudyFromStorage", studySqn, new ObjectMap(), token, engine -> { List filesFromCatalog = catalogManager.getFileManager() - .get(studySqn, files, FILE_GET_QUERY_OPTIONS, token).getResults(); + .get(organizationId, studySqn, files, FILE_GET_QUERY_OPTIONS, token).getResults(); return getSynchronizer(engine).synchronizeCatalogFilesFromStorage(studySqn, filesFromCatalog, token); }); } @@ -1374,7 +1374,7 @@ Map> checkSamplesPermissions(Query query, QueryOptions quer // DataResult samplesQueryResult = catalogManager.getSampleManager().get(studyId, entry.getValue(), // new QueryOptions(INCLUDE, SampleDBAdaptor.QueryParams.ID.key()), token); long numMatches = catalogManager.getSampleManager() - .count(studyId, new Query(SampleDBAdaptor.QueryParams.ID.key(), entry.getValue()) + .count(organizationId, studyId, new Query(SampleDBAdaptor.QueryParams.ID.key(), entry.getValue()) .append(ACL_PARAM, userId + ":" + SamplePermissions.VIEW_VARIANTS), token) .getNumMatches(); if (numMatches != entry.getValue().size()) { @@ -1411,7 +1411,7 @@ Map> checkSamplesPermissions(Query query, QueryOptions quer for (String study : includeStudies) { study = getStudyFqn(study, token); DBIterator iterator = catalogManager.getSampleManager().iterator( - study, + organizationId, study, new Query() .append(ACL_PARAM, userId + ":" + SamplePermissions.VIEW_VARIANTS), new QueryOptions() @@ -1466,7 +1466,7 @@ private void checkStudyPermissions(Collection studies, String userId, St } private void checkStudyPermissions(String study, String userId, String token) throws CatalogException { - long studyUid = catalogManager.getStudyManager().get(study, StudyManager.INCLUDE_STUDY_IDS, token).first().getUid(); + long studyUid = catalogManager.getStudyManager().get(organizationId, study, StudyManager.INCLUDE_STUDY_IDS, token).first().getUid(); CatalogAuthorizationException exception = null; // Check VIEW_AGGREGATED_VARIANTS @@ -1490,7 +1490,7 @@ private void checkStudyPermissions(String study, String userId, String token) th // Check VIEW_VARIANTS on any sample long count = catalogManager.getSampleManager() - .count(study, new Query(ACL_PARAM, userId + ":" + SamplePermissions.VIEW_VARIANTS), token).getNumMatches(); + .count(organizationId, study, new Query(ACL_PARAM, userId + ":" + SamplePermissions.VIEW_VARIANTS), token).getNumMatches(); if (count != 0) { return; } @@ -1608,7 +1608,7 @@ private List getStudiesFqn(List studies, String token) throws Ca } private String getStudyFqn(String study, String token) throws CatalogException { - return catalogManager.getStudyManager().get(study, StudyManager.INCLUDE_STUDY_IDS, token).first().getFqn(); + return catalogManager.getStudyManager().get(organizationId, study, StudyManager.INCLUDE_STUDY_IDS, token).first().getFqn(); } private String getProjectFqn(String projectStr, String study, String token) throws CatalogException { @@ -1617,7 +1617,7 @@ private String getProjectFqn(String projectStr, String study, String token) thro private String getProjectFqn(String projectStr, List studies, String token) throws CatalogException { if (CollectionUtils.isEmpty(studies) && StringUtils.isEmpty(projectStr)) { - List projects = catalogManager.getProjectManager().search(new Query(), new QueryOptions(), token).getResults(); + List projects = catalogManager.getProjectManager().search(organizationId, new Query(), new QueryOptions(), token).getResults(); if (projects.size() == 1) { projectStr = projects.get(0).getFqn(); } else { @@ -1628,7 +1628,7 @@ private String getProjectFqn(String projectStr, List studies, String tok if (CollectionUtils.isNotEmpty(studies)) { // Ensure all studies are valid. Convert to FQN studies = catalogManager.getStudyManager() - .get(studies, StudyManager.INCLUDE_STUDY_IDS, false, token) + .get(organizationId, studies, StudyManager.INCLUDE_STUDY_IDS, false, token) .getResults() .stream() .map(Study::getFqn) @@ -1657,7 +1657,7 @@ public DataStore getDataStoreByProjectId(String project, String token) throws Ca public static DataStore getDataStore(CatalogManager catalogManager, String studyStr, File.Bioformat bioformat, String token) throws CatalogException { - Study study = catalogManager.getStudyManager().get(studyStr, new QueryOptions(), token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyStr, new QueryOptions(), token).first(); return getDataStore(catalogManager, study, bioformat, token); } @@ -1673,7 +1673,7 @@ public static DataStore getDataStoreByProjectId(CatalogManager catalogManager, S DataStore dataStore = null; QueryOptions queryOptions = new QueryOptions(INCLUDE, Arrays.asList(ProjectDBAdaptor.QueryParams.ID.key(), ProjectDBAdaptor.QueryParams.INTERNAL_DATASTORES.key())); - Project project = catalogManager.getProjectManager().get(projectStr, queryOptions, token).first(); + Project project = catalogManager.getProjectManager().get(organizationId, projectStr, queryOptions, token).first(); if (project.getInternal() != null && project.getInternal().getDatastores() != null) { dataStore = project.getInternal().getDatastores().getDataStore(bioformat); } @@ -1696,7 +1696,7 @@ public static DataStore defaultDataStore(CatalogManager catalogManager, Project throws CatalogException { DataStore dataStore; //Must use the UserByStudyId instead of the file owner. - String userId = catalogManager.getProjectManager().getOwner(project.getUid()); + String userId = catalogManager.getProjectManager().getOwner(organizationId, project.getUid()); // Replace possible dots at the userId. Usually a special character in almost all databases. See #532 userId = userId.replace('.', '_'); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/OperationManager.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/OperationManager.java index 539dac4ce44..6ab36731a30 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/OperationManager.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/OperationManager.java @@ -73,7 +73,7 @@ public final StudyMetadata synchronizeCatalogStudyFromStorage(String study, Stri } protected final String getStudyFqn(String study, String token) throws CatalogException { - return catalogManager.getStudyManager().get(study, StudyManager.INCLUDE_STUDY_IDS, token).first().getFqn(); + return catalogManager.getStudyManager().get(organizationId, study, StudyManager.INCLUDE_STUDY_IDS, token).first().getFqn(); } public static boolean isVcfFormat(File file) { @@ -106,7 +106,7 @@ protected void toFileSystemPath(String studyFqn, ObjectMap params, String key, S } protected Path getFileSystemPath(String studyFqn, String fileId, String token) throws CatalogException { - File file = catalogManager.getFileManager().get(studyFqn, fileId, + File file = catalogManager.getFileManager().get(organizationId, studyFqn, fileId, new QueryOptions(QueryOptions.INCLUDE, FileDBAdaptor.QueryParams.URI.key()), token).first(); return Paths.get(file.getUri()).toAbsolutePath(); } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantAnnotationOperationManager.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantAnnotationOperationManager.java index 7f117f66744..c9f90ae3ce5 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantAnnotationOperationManager.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantAnnotationOperationManager.java @@ -110,7 +110,7 @@ private void annotate(String projectStr, List studies, String loadFileSt } else { throw new CatalogException("Unable to locate file '" + loadFileStr + "'. More than one study found: " + studies); } - File loadFile = catalogManager.getFileManager().get(studyStr, loadFileStr, null, token).first(); + File loadFile = catalogManager.getFileManager().get(organizationId, studyStr, loadFileStr, null, token).first(); if (loadFile == null) { throw new CatalogException("File '" + loadFileStr + "' does not exist!"); } @@ -123,7 +123,7 @@ private void annotate(String projectStr, List studies, String loadFileSt } private void synchronizeProjectMetadata(String projectStr, String token) throws CatalogException, StorageEngineException { - Project project = catalogManager.getProjectManager().get(projectStr, QueryOptions.empty(), token).first(); + Project project = catalogManager.getProjectManager().get(organizationId, projectStr, QueryOptions.empty(), token).first(); ProjectOrganism organism = project.getOrganism(); int currentRelease = project.getCurrentRelease(); CatalogStorageMetadataSynchronizer.updateProjectMetadata(variantStorageEngine.getMetadataManager(), organism, currentRelease, diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantDeleteOperationManager.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantDeleteOperationManager.java index 550c00b027a..6725192ec46 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantDeleteOperationManager.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantDeleteOperationManager.java @@ -57,7 +57,7 @@ public void removeFile(String study, List inputFiles, URI outdir, String List fileNames = new ArrayList<>(); if (inputFiles != null && !inputFiles.isEmpty()) { for (String fileStr : inputFiles) { - File file = catalogManager.getFileManager().get(study, fileStr, null, token).first(); + File file = catalogManager.getFileManager().get(organizationId, study, fileStr, null, token).first(); String catalogIndexStatus = file.getInternal().getVariant().getIndex().getStatus().getId(); if (!catalogIndexStatus.equals(VariantIndexStatus.READY)) { // Might be partially loaded in VariantStorage. Check FileMetadata diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantFileIndexerOperationManager.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantFileIndexerOperationManager.java index 48ff94151d7..ac15f040b5a 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantFileIndexerOperationManager.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantFileIndexerOperationManager.java @@ -162,7 +162,7 @@ private void updateProject(String studyFqn, String token) throws CatalogExceptio String projectFqn = catalogManager.getStudyManager().getProjectFqn(studyFqn); Project project = catalogManager .getProjectManager() - .get(projectFqn, + .get(organizationId, projectFqn, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(CURRENT_RELEASE.key(), ORGANISM.key(), CELLBASE.key())), token).first(); release = project.getCurrentRelease(); @@ -188,7 +188,7 @@ private List findFilesToIndex(ObjectMap params, String token) List inputFiles = new ArrayList<>(); for (String file : files) { - File inputFile = catalogManager.getFileManager().get(studyFqn, file, FILE_GET_QUERY_OPTIONS, token).first(); + File inputFile = catalogManager.getFileManager().get(organizationId, studyFqn, file, FILE_GET_QUERY_OPTIONS, token).first(); if (inputFile.getType() == File.Type.FILE) { // If is a transformed file, get the related VCF file @@ -203,7 +203,7 @@ private List findFilesToIndex(ObjectMap params, String token) query.append(FileDBAdaptor.QueryParams.FORMAT.key(), // Arrays.asList(File.Format.VCF, File.Format.GVCF, File.Format.AVRO)); Arrays.asList(File.Format.VCF, File.Format.GVCF)); - DataResult fileDataResult = catalogManager.getFileManager().search(studyFqn, query, FILE_GET_QUERY_OPTIONS, + DataResult fileDataResult = catalogManager.getFileManager().search(organizationId, studyFqn, query, FILE_GET_QUERY_OPTIONS, token); // fileDataResult.getResults().sort(Comparator.comparing(File::getName)); inputFiles.addAll(fileDataResult.getResults()); @@ -328,7 +328,7 @@ private List indexFiles(List fileUris, String token, if (fullSynchronize) { synchronizer.synchronizeCatalogStudyFromStorage(studyFqn, token); } else { - List inputFiles = catalogManager.getFileManager().search(studyFqn, + List inputFiles = catalogManager.getFileManager().search(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.URI.key(), fileUris), new QueryOptions(QueryOptions.INCLUDE, "id,name,path,uri"), token).getResults(); synchronizer.synchronizeCatalogFilesFromStorage(studyFqn, inputFiles, token); @@ -371,7 +371,7 @@ private void updateFileInfo(String study, List filesToIndex, VariantReader for (File indexedFile : filesToIndex) { // Fetch from catalog. {@link #copyResult} may modify the content - indexedFile = catalogManager.getFileManager().get(study, indexedFile.getId(), null, sessionId).first(); + indexedFile = catalogManager.getFileManager().get(organizationId, study, indexedFile.getId(), null, sessionId).first(); // Suppose that the missing results are due to errors, and those files were not indexed. StoragePipelineResult storagePipelineResult = map.get(indexedFile.getName()); @@ -470,7 +470,7 @@ private void updateFileInfo(String study, List filesToIndex, VariantReader if (indexStatusId.equals(VariantIndexStatus.READY) && calculateStats) { Query query = new Query(CohortDBAdaptor.QueryParams.ID.key(), StudyEntry.DEFAULT_COHORT); DataResult queryResult = catalogManager.getCohortManager() - .search(study, query, new QueryOptions(), sessionId); + .search(organizationId, study, query, new QueryOptions(), sessionId); if (queryResult.getNumResults() != 0) { logger.debug("Default cohort status set to READY"); Cohort defaultCohort = queryResult.first(); @@ -519,13 +519,13 @@ private void updateVariantFileStats(String studyFqn, VariantReaderUtils variantR private Cohort createDefaultCohortIfNeeded(String studyFqn, String sessionId) throws CatalogException { Query query = new Query(CohortDBAdaptor.QueryParams.ID.key(), StudyEntry.DEFAULT_COHORT); - Cohort cohort = catalogManager.getCohortManager().search(studyFqn, query, null, sessionId).first(); + Cohort cohort = catalogManager.getCohortManager().search(organizationId, studyFqn, query, null, sessionId).first(); if (cohort == null) { try { return createDefaultCohort(studyFqn, sessionId); } catch (CatalogDBException e) { if (e.getMessage().contains("already exists")) { - cohort = catalogManager.getCohortManager().search(studyFqn, query, null, sessionId).first(); + cohort = catalogManager.getCohortManager().search(organizationId, studyFqn, query, null, sessionId).first(); if (cohort == null) { throw e; } else { @@ -558,7 +558,7 @@ private void updateDefaultCohortStatus(Study study, StorageEngineException excep private String updateDefaultCohortStatus(String study, String status, String sessionId) throws CatalogException { Query query = new Query(CohortDBAdaptor.QueryParams.ID.key(), StudyEntry.DEFAULT_COHORT); - Cohort defaultCohort = catalogManager.getCohortManager().search(study, query, new QueryOptions(), sessionId).first(); + Cohort defaultCohort = catalogManager.getCohortManager().search(organizationId, study, query, new QueryOptions(), sessionId).first(); String prevStatus = defaultCohort.getInternal().getStatus().getId(); catalogManager.getCohortManager().setStatus(study, defaultCohort.getId(), status, null, @@ -717,7 +717,7 @@ private List filterLoadFiles(String studyFQN, List fileList, ObjectM if (!transformedToOrigFileIdsMap.isEmpty()) { Query query = new Query(ID.key(), new ArrayList<>(transformedToOrigFileIdsMap.keySet())); Set foundTransformedFiles = new HashSet<>(); - catalogManager.getFileManager().iterator(studyFQN, query, new QueryOptions(QueryOptions.INCLUDE, + catalogManager.getFileManager().iterator(organizationId, studyFQN, query, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(ID.key(), UID.key(), FileDBAdaptor.QueryParams.URI.key())), sessionId) .forEachRemaining(transformed -> { foundTransformedFiles.add(transformed.getId()); @@ -755,7 +755,7 @@ private File getOriginalFromTransformed(String study, File file, String sessionI if (FileRelatedFile.Relation.PRODUCED_FROM.equals(relatedFile.getRelation())) { long fileUid = relatedFile.getFile().getUid(); // FIXME!!! - vcfId = catalogManager.getFileManager().search(study, new Query(UID.key(), fileUid), + vcfId = catalogManager.getFileManager().search(organizationId, study, new Query(UID.key(), fileUid), new QueryOptions(QueryOptions.INCLUDE, FileDBAdaptor.QueryParams.ID.key()), sessionId).first().getId(); break; } @@ -764,7 +764,7 @@ private File getOriginalFromTransformed(String study, File file, String sessionI logger.error("This code should never be executed. Every transformed avro file should come from a registered vcf file"); throw new CatalogException("Internal error. No vcf file could be found for file " + file.getPath()); } - DataResult vcfDataResult = catalogManager.getFileManager().get(study, vcfId, FILE_GET_QUERY_OPTIONS, sessionId); + DataResult vcfDataResult = catalogManager.getFileManager().get(organizationId, study, vcfId, FILE_GET_QUERY_OPTIONS, sessionId); if (vcfDataResult.getNumResults() != 1) { logger.error("This code should never be executed. No vcf file could be found for vcf id " + vcfId); throw new CatalogException("Internal error. No vcf file could be found under id " + vcfId); @@ -776,7 +776,7 @@ private File getOriginalFromTransformed(String study, File file, String sessionI private File getTransformedFromOriginal(String sessionId, File file) throws CatalogException { String transformedFileId = getTransformedFileIdFromOriginal(file); - DataResult queryResult = catalogManager.getFileManager().get(studyFqn, transformedFileId, FILE_GET_QUERY_OPTIONS, sessionId); + DataResult queryResult = catalogManager.getFileManager().get(organizationId, studyFqn, transformedFileId, FILE_GET_QUERY_OPTIONS, sessionId); if (queryResult.getNumResults() != 1) { logger.error("This code should never be executed. No transformed file could be found under "); throw new CatalogException("Internal error. No transformed file could be found under id " + transformedFileId); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantStatsOperationManager.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantStatsOperationManager.java index 08629744157..50c0c99183b 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantStatsOperationManager.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/manager/operations/VariantStatsOperationManager.java @@ -179,7 +179,7 @@ protected List checkCohorts(String studyId, Aggregation aggregation, Lis } else { cohortIds = new ArrayList<>(cohorts.size()); for (String cohort : cohorts) { - String cohortId = catalogManager.getCohortManager().get(studyId, cohort, + String cohortId = catalogManager.getCohortManager().get(organizationId, studyId, cohort, new QueryOptions(QueryOptions.INCLUDE, CohortDBAdaptor.QueryParams.ID.key()), sessionId).first().getId(); cohortIds.add(cohortId); } @@ -209,7 +209,7 @@ protected Map> checkCanCalculateCohorts(String studyFqn, Li Map> cohortMap = new HashMap<>(cohortIds.size()); for (String cohortId : cohortIds) { Cohort cohort = catalogManager.getCohortManager() - .get(studyFqn, cohortId, CatalogStorageMetadataSynchronizer.COHORT_QUERY_OPTIONS, sessionId).first(); + .get(organizationId, studyFqn, cohortId, CatalogStorageMetadataSynchronizer.COHORT_QUERY_OPTIONS, sessionId).first(); switch (cohort.getInternal().getStatus().getId()) { case CohortStatus.NONE: case CohortStatus.INVALID: @@ -256,7 +256,7 @@ private Properties readAggregationMappingFile(String aggregationMapFile) throws private List createCohortsIfNeeded(String studyId, Set cohortNames, String sessionId) throws CatalogException { List cohorts = new ArrayList<>(); // Silent query, so it does not fail for missing cohorts - Set catalogCohorts = catalogManager.getCohortManager().get(studyId, new ArrayList<>(cohortNames), + Set catalogCohorts = catalogManager.getCohortManager().get(organizationId, studyId, new ArrayList<>(cohortNames), new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( CohortDBAdaptor.QueryParams.ID.key(), CohortDBAdaptor.QueryParams.UID.key(), diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/mendelianError/MendelianErrorAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/mendelianError/MendelianErrorAnalysis.java index cb56a748351..afea225635b 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/mendelianError/MendelianErrorAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/mendelianError/MendelianErrorAnalysis.java @@ -91,7 +91,7 @@ protected void check() throws Exception { } try { - studyId = catalogManager.getStudyManager().get(studyId, null, token).first().getFqn(); + studyId = catalogManager.getStudyManager().get(organizationId, studyId, null, token).first().getFqn(); } catch (CatalogException e) { throw new ToolException(e); } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/metadata/CatalogStorageMetadataSynchronizer.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/metadata/CatalogStorageMetadataSynchronizer.java index 4f6f7bb6452..7ee34ebde45 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/metadata/CatalogStorageMetadataSynchronizer.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/metadata/CatalogStorageMetadataSynchronizer.java @@ -113,7 +113,7 @@ public CatalogStorageMetadataSynchronizer(CatalogManager catalogManager, Variant public static void updateProjectMetadata(CatalogManager catalog, VariantStorageMetadataManager scm, String project, String sessionId) throws CatalogException, StorageEngineException { - final Project p = catalog.getProjectManager().get(project, + final Project p = catalog.getProjectManager().get(organizationId, project, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( ProjectDBAdaptor.QueryParams.ORGANISM.key(), ProjectDBAdaptor.QueryParams.CURRENT_RELEASE.key(), ProjectDBAdaptor.QueryParams.CELLBASE.key())), @@ -160,7 +160,7 @@ public boolean synchronizeCatalogFilesFromStorage(String study, List files // Files updated. Reload files from catalog for (int i = 0; i < files.size(); i++) { File file = files.get(i); - files.set(i, catalogManager.getFileManager().get(study, file.getId(), fileQueryOptions, sessionId).first()); + files.set(i, catalogManager.getFileManager().get(organizationId, study, file.getId(), fileQueryOptions, sessionId).first()); } } return modified; @@ -298,7 +298,7 @@ protected boolean synchronizeCohorts(StudyMetadata study, String sessionId) thro .map(id -> metadataManager.getSampleName(study.getId(), id)) .collect(Collectors.toSet()); Cohort defaultCohort = catalogManager.getCohortManager() - .get(study.getName(), defaultCohortName, COHORT_QUERY_OPTIONS, sessionId).first(); + .get(organizationId, study.getName(), defaultCohortName, COHORT_QUERY_OPTIONS, sessionId).first(); List cohortFromCatalog = defaultCohort .getSamples() .stream() @@ -361,7 +361,7 @@ protected boolean synchronizeCohorts(StudyMetadata study, String sessionId) thro if (!calculatedStats.isEmpty()) { Query query = new Query(CohortDBAdaptor.QueryParams.ID.key(), calculatedStats.keySet()); - try (DBIterator iterator = catalogManager.getCohortManager().iterator(study.getName(), + try (DBIterator iterator = catalogManager.getCohortManager().iterator(organizationId, study.getName(), query, COHORT_QUERY_OPTIONS, sessionId)) { while (iterator.hasNext()) { Cohort cohort = iterator.next(); @@ -404,7 +404,7 @@ protected boolean synchronizeCohorts(StudyMetadata study, String sessionId) thro //Check if any cohort stat has been invalidated if (!invalidStats.isEmpty()) { Query query = new Query(CohortDBAdaptor.QueryParams.ID.key(), invalidStats.keySet()); - try (DBIterator iterator = catalogManager.getCohortManager().iterator(study.getName(), + try (DBIterator iterator = catalogManager.getCohortManager().iterator(organizationId, study.getName(), query, COHORT_QUERY_OPTIONS, sessionId)) { while (iterator.hasNext()) { @@ -517,7 +517,7 @@ protected boolean synchronizeFiles(StudyMetadata study, List files, String for (Integer virtualFile : virtualFiles) { File file = catalogManager.getFileManager() - .get(study.getName(), filePathMap.get(virtualFile), INDEXED_FILES_QUERY_OPTIONS, token).first(); + .get(organizationId, study.getName(), filePathMap.get(virtualFile), INDEXED_FILES_QUERY_OPTIONS, token).first(); boolean annotationIndexReady = annotationReadyFilesFromStorage.contains(file.getName()); boolean secondaryIndexReady = secondaryIndexReadyFilesFromStorage.contains(file.getName()); if (synchronizeIndexedFile(study, file, fileSamplesMap, annotationIndexReady, secondaryIndexReady, token)) { @@ -540,7 +540,7 @@ protected boolean synchronizeFiles(StudyMetadata study, List files, String int processedFilesInBatch = 0; Query query = new Query(FileDBAdaptor.QueryParams.URI.key(), batch); try (DBIterator iterator = catalogManager.getFileManager() - .iterator(study.getName(), query, INDEXED_FILES_QUERY_OPTIONS, token)) { + .iterator(organizationId, study.getName(), query, INDEXED_FILES_QUERY_OPTIONS, token)) { while (iterator.hasNext()) { File file = iterator.next(); boolean annotationIndexReady = annotationReadyFilesFromStorage.contains(file.getName()); @@ -598,7 +598,7 @@ protected boolean synchronizeFiles(StudyMetadata study, List files, String indexedFilesQuery = new Query(INDEXED_FILES_QUERY).append(ID.key(), catalogFileIds); } try (DBIterator iterator = catalogManager.getFileManager() - .iterator(study.getName(), indexedFilesQuery, INDEXED_FILES_QUERY_OPTIONS, token)) { + .iterator(organizationId, study.getName(), indexedFilesQuery, INDEXED_FILES_QUERY_OPTIONS, token)) { while (iterator.hasNext()) { File file = iterator.next(); Integer fileId = fileNameMap.get(file.getName()); @@ -634,7 +634,7 @@ protected boolean synchronizeFiles(StudyMetadata study, List files, String runningIndexFilesQuery = new Query(RUNNING_INDEX_FILES_QUERY).append(ID.key(), catalogFileIds); } try (DBIterator iterator = catalogManager.getFileManager() - .iterator(study.getName(), runningIndexFilesQuery, INDEXED_FILES_QUERY_OPTIONS, token)) { + .iterator(organizationId, study.getName(), runningIndexFilesQuery, INDEXED_FILES_QUERY_OPTIONS, token)) { while (iterator.hasNext()) { File file = iterator.next(); Integer fileId = fileNameMap.get(file.getName()); @@ -649,7 +649,7 @@ protected boolean synchronizeFiles(StudyMetadata study, List files, String if (fileMetadata != null && fileMetadata.getIndexStatus().equals(TaskMetadata.Status.ERROR)) { OpenCGAResult jobsFromFile = catalogManager .getJobManager() - .search(study.getName(), + .search(organizationId, study.getName(), new Query() .append(JobDBAdaptor.QueryParams.INPUT.key(), file.getId()) .append(JobDBAdaptor.QueryParams.TOOL_ID.key(), VariantIndexOperationTool.ID) @@ -701,7 +701,7 @@ protected boolean synchronizeFiles(StudyMetadata study, List files, String if (!loadingFilesRegardingStorage.isEmpty()) { try (DBIterator iterator = catalogManager.getFileManager() - .iterator(study.getName(), new Query(URI.key(), loadingFilesRegardingStorage), + .iterator(organizationId, study.getName(), new Query(URI.key(), loadingFilesRegardingStorage), INDEXED_FILES_QUERY_OPTIONS, token)) { while (iterator.hasNext()) { File file = iterator.next(); @@ -779,7 +779,7 @@ private boolean synchronizeIndexedFile(StudyMetadata study, File file, Map samp sampleMetadataMap.put(sampleMetadata.getName(), sampleMetadata); } try (DBIterator iterator = catalogManager.getSampleManager() - .iterator(study.getName(), new Query(SampleDBAdaptor.QueryParams.ID.key(), new ArrayList<>(sampleMetadataMap.keySet())), + .iterator(organizationId, study.getName(), new Query(SampleDBAdaptor.QueryParams.ID.key(), new ArrayList<>(sampleMetadataMap.keySet())), SAMPLE_QUERY_OPTIONS, token)) { while (iterator.hasNext()) { Sample sample = iterator.next(); @@ -937,7 +937,7 @@ public void synchronizeRemovedStudyFromStorage(String study, String token) throw "Study has been removed from storage", token); try (DBIterator iterator = catalogManager.getFileManager() - .iterator(study, INDEXED_FILES_QUERY, INDEXED_FILES_QUERY_OPTIONS, token)) { + .iterator(organizationId, study, INDEXED_FILES_QUERY, INDEXED_FILES_QUERY_OPTIONS, token)) { while (iterator.hasNext()) { File file = iterator.next(); catalogManager.getFileManager().updateFileInternalVariantIndex(file, FileInternalVariantIndex.init() diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/metadata/CatalogVariantMetadataFactory.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/metadata/CatalogVariantMetadataFactory.java index cbffe4e9e21..3ea0370220a 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/metadata/CatalogVariantMetadataFactory.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/metadata/CatalogVariantMetadataFactory.java @@ -117,7 +117,7 @@ private void fillStudy(String studyId, VariantStudyMetadata studyMetadata) throw QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.DESCRIPTION.key()); // Just add file description - Study study = catalogManager.getStudyManager().get(studyId, options, sessionId).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyId, options, sessionId).first(); studyMetadata.setDescription(study.getDescription()); } @@ -128,7 +128,7 @@ private void fillIndividuals(String studyId, List(individualMap.keySet())); List catalogIndividuals = catalogManager.getIndividualManager() - .search(studyId, query, INDIVIDUAL_QUERY_OPTIONS, sessionId).getResults(); + .search(organizationId, studyId, query, INDIVIDUAL_QUERY_OPTIONS, sessionId).getResults(); for (Individual catalogIndividual : catalogIndividuals) { org.opencb.biodata.models.metadata.Individual individual = individualMap.get(catalogIndividual.getId()); @@ -155,7 +155,7 @@ private void fillSamples(String studyId, List i)); Query query = new Query(SampleDBAdaptor.QueryParams.ID.key(), new ArrayList<>(samplesMap.keySet())); - List catalogSamples = catalogManager.getSampleManager().search(studyId, query, SAMPLE_QUERY_OPTIONS, sessionId) + List catalogSamples = catalogManager.getSampleManager().search(organizationId, studyId, query, SAMPLE_QUERY_OPTIONS, sessionId) .getResults(); for (Sample catalogSample : catalogSamples) { org.opencb.biodata.models.metadata.Sample sample = samplesMap.get(catalogSample.getId()); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/mutationalSignature/MutationalSignatureAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/mutationalSignature/MutationalSignatureAnalysis.java index c81b966dcaf..4043a018a00 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/mutationalSignature/MutationalSignatureAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/mutationalSignature/MutationalSignatureAnalysis.java @@ -51,9 +51,6 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; -import java.util.Locale; - -import static org.opencb.opencga.storage.core.variant.adaptors.VariantQueryParam.STUDY; @Tool(id = MutationalSignatureAnalysis.ID, resource = Enums.Resource.VARIANT) public class MutationalSignatureAnalysis extends OpenCgaToolScopeStudy { @@ -106,8 +103,8 @@ protected void check() throws Exception { } // Check sample - study = catalogManager.getStudyManager().get(study, QueryOptions.empty(), token).first().getFqn(); - OpenCGAResult sampleResult = catalogManager.getSampleManager().get(study, signatureParams.getSample(), + study = catalogManager.getStudyManager().get(organizationId, study, QueryOptions.empty(), token).first().getFqn(); + OpenCGAResult sampleResult = catalogManager.getSampleManager().get(organizationId, study, signatureParams.getSample(), QueryOptions.empty(), token); if (sampleResult.getNumResults() != 1) { throw new ToolException("Unable to compute mutational signature analysis. Sample '" + signatureParams.getSample() @@ -234,7 +231,7 @@ protected void run() throws ToolException { // Get sample quality control again in case it was updated during the mutational signature analysis OpenCGAResult sampleResult; try { - sampleResult = catalogManager.getSampleManager().get(study, signatureParams.getSample(), + sampleResult = catalogManager.getSampleManager().get(organizationId, study, signatureParams.getSample(), QueryOptions.empty(), token); } catch (CatalogException e) { throw new ToolException("After mutational signature analysis, it could not get sample from OpenCGA catalog", e); @@ -338,7 +335,7 @@ public static File getGenomeContextFile(String sample, String study, CatalogMana try { Query fileQuery = new Query("name", indexFilename); QueryOptions fileQueryOptions = new QueryOptions("include", "uri"); - OpenCGAResult fileResult = catalogManager.getFileManager().search(study, fileQuery, + OpenCGAResult fileResult = catalogManager.getFileManager().search(organizationId, study, fileQuery, fileQueryOptions, token); long maxSize = 0; diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/mutationalSignature/MutationalSignatureLocalAnalysisExecutor.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/mutationalSignature/MutationalSignatureLocalAnalysisExecutor.java index d0b17eac64a..b162c14830c 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/mutationalSignature/MutationalSignatureLocalAnalysisExecutor.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/mutationalSignature/MutationalSignatureLocalAnalysisExecutor.java @@ -501,8 +501,8 @@ private void computeSignatureFitting() throws IOException, ToolException, Catalo // Get counts from sample CatalogManager catalogManager = getVariantStorageManager().getCatalogManager(); // Check sample - String study = catalogManager.getStudyManager().get(getStudy(), QueryOptions.empty(), getToken()).first().getFqn(); - OpenCGAResult sampleResult = catalogManager.getSampleManager().get(study, getSample(), QueryOptions.empty(), + String study = catalogManager.getStudyManager().get(organizationId, getStudy(), QueryOptions.empty(), getToken()).first().getFqn(); + OpenCGAResult sampleResult = catalogManager.getSampleManager().get(organizationId, study, getSample(), QueryOptions.empty(), getToken()); if (sampleResult.getNumResults() != 1) { throw new ToolException("Unable to compute mutational signature analysis. Sample '" + getSample() + "' not found"); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/OperationTool.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/OperationTool.java index b91273916a8..1c806210dd7 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/OperationTool.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/OperationTool.java @@ -68,7 +68,7 @@ protected Path getOutDir(boolean keepIntermediateFiles) { protected final String getProjectFqn() throws CatalogException { try { - return catalogManager.getProjectManager().get(params.getString(ParamConstants.PROJECT_PARAM), + return catalogManager.getProjectManager().get(organizationId, params.getString(ParamConstants.PROJECT_PARAM), new QueryOptions(QueryOptions.INCLUDE, ProjectDBAdaptor.QueryParams.FQN.key()), token).first().getFqn(); } catch (CatalogException e) { try { @@ -102,7 +102,7 @@ protected final String getStudyFqn() throws CatalogException { } protected String getStudyFqn(String study) throws CatalogException { - return getCatalogManager().getStudyManager().get(study, StudyManager.INCLUDE_STUDY_IDS, getToken()).first().getFqn(); + return getCatalogManager().getStudyManager().get(organizationId, study, StudyManager.INCLUDE_STUDY_IDS, getToken()).first().getFqn(); } private static boolean isVcfFormat(File.Format format) { diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantFileIndexJobLauncherTool.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantFileIndexJobLauncherTool.java index c548f0fbbca..7c23213238e 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantFileIndexJobLauncherTool.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantFileIndexJobLauncherTool.java @@ -74,7 +74,7 @@ protected void run() throws Exception { int scannedFiles = 0; List files = new ArrayList<>(200); try (DBIterator dbIterator = getCatalogManager().getFileManager() - .iterator(getStudy(), filesQuery, filesInclude, getToken())) { + .iterator(organizationId, getStudy(), filesQuery, filesInclude, getToken())) { while (dbIterator.hasNext()) { files.add(dbIterator.next()); } @@ -90,7 +90,7 @@ protected void run() throws Exception { String indexStatus = getVariantIndexStatus(file); OpenCGAResult jobsFromFile = getCatalogManager() .getJobManager() - .search(getStudy(), + .search(organizationId, getStudy(), new Query() .append(JobDBAdaptor.QueryParams.INPUT.key(), file.getId()) .append(JobDBAdaptor.QueryParams.TOOL_ID.key(), VariantIndexOperationTool.ID) diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantIndexOperationTool.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantIndexOperationTool.java index c4ba731b647..a6fd13d3f77 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantIndexOperationTool.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantIndexOperationTool.java @@ -162,7 +162,7 @@ protected void run() throws Exception { return; } OpenCGAResult fileResult = getCatalogManager().getFileManager() - .search(study, + .search(organizationId, study, new Query(FileDBAdaptor.QueryParams.URI.key(), inputFiles), new QueryOptions(QueryOptions.INCLUDE, FileDBAdaptor.QueryParams.SAMPLE_IDS.key()), getToken()); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantStatsIndexOperationTool.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantStatsIndexOperationTool.java index ae8576a84de..dd072ad47bf 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantStatsIndexOperationTool.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantStatsIndexOperationTool.java @@ -26,7 +26,6 @@ import org.opencb.opencga.storage.core.variant.VariantStorageOptions; import org.opencb.opencga.storage.core.variant.stats.DefaultVariantStatisticsManager; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -99,7 +98,7 @@ protected void run() throws Exception { private Path getFilePath(String aggregationMapFile) throws CatalogException { return Paths.get(getCatalogManager().getFileManager() - .get(studyFqn, aggregationMapFile, QueryOptions.empty(), getToken()).first().getUri()); + .get(organizationId, studyFqn, aggregationMapFile, QueryOptions.empty(), getToken()).first().getUri()); } } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantStorageMetadataRepairTool.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantStorageMetadataRepairTool.java index a8e9ba5b528..385a3a09d5a 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantStorageMetadataRepairTool.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/operations/VariantStorageMetadataRepairTool.java @@ -54,7 +54,7 @@ protected void run() throws Exception { StudyDBAdaptor.QueryParams.UID.key(), StudyDBAdaptor.QueryParams.ID.key(), StudyDBAdaptor.QueryParams.FQN.key())); - OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(query, options, token); + OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(organizationId, query, options, token); for (Study study : studyDataResult.getResults()) { fixStudy(study.getFqn(), true); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/relatedness/RelatednessAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/relatedness/RelatednessAnalysis.java index ee410da895c..7ed592cc4ce 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/relatedness/RelatednessAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/relatedness/RelatednessAnalysis.java @@ -18,7 +18,6 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.opencb.commons.utils.FileUtils; import org.opencb.opencga.analysis.AnalysisUtils; import org.opencb.opencga.analysis.family.qc.FamilyQcAnalysis; import org.opencb.opencga.analysis.individual.qc.IndividualQcUtils; @@ -31,13 +30,8 @@ import org.opencb.opencga.core.tools.annotations.Tool; import org.opencb.opencga.core.tools.variant.IBDRelatednessAnalysisExecutor; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -127,7 +121,7 @@ protected void check() throws Exception { } try { - studyId = catalogManager.getStudyManager().get(studyId, null, token).first().getFqn(); + studyId = catalogManager.getStudyManager().get(organizationId, studyId, null, token).first().getFqn(); } catch (CatalogException e) { throw new ToolException(e); } diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/samples/SampleEligibilityAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/samples/SampleEligibilityAnalysis.java index 594c00116c9..48cd8acc2e7 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/samples/SampleEligibilityAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/samples/SampleEligibilityAnalysis.java @@ -125,7 +125,7 @@ protected void check() throws Exception { throw new IllegalArgumentException("Missing cohort-id"); } Query query = new Query(CohortDBAdaptor.QueryParams.ID.key(), analysisParams.getCohortId()); - if (catalogManager.getCohortManager().count(studyFqn, query, getToken()).getNumResults() > 0) { + if (catalogManager.getCohortManager().count(organizationId, studyFqn, query, getToken()).getNumResults() > 0) { throw new IllegalArgumentException("Unable to index result. Cohort '" + analysisParams.getCohortId() + "' already exists"); } } else { @@ -206,7 +206,7 @@ protected void run() throws Exception { .setId(analysisParams.getCohortId()) .setSamples(samplesResult.stream().map(s -> new Sample().setId(s)).collect(Collectors.toList())) .setDescription("Result of analysis '" + getId() + "' after executing query " + analysisParams.getQuery()); - getCatalogManager().getCohortManager().create(studyFqn, cohort, new QueryOptions(), getToken()); + getCatalogManager().getCohortManager().create(organizationId, studyFqn, cohort, new QueryOptions(), getToken()); }); } } @@ -222,7 +222,7 @@ private void printResult(Set samplesResult) throws CatalogException, IOE if (!samplesResult.isEmpty()) { Iterator it = getCatalogManager().getIndividualManager() - .iterator(studyFqn, + .iterator(organizationId, studyFqn, new Query(IndividualDBAdaptor.QueryParams.SAMPLES.key(), samplesResult), new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( IndividualDBAdaptor.QueryParams.ID.key(), @@ -258,7 +258,7 @@ private void printResult(Set samplesResult) throws CatalogException, IOE if (!missingSamples.isEmpty()) { logger.warn("Individual not found for {} samples", missingSamples.size()); Iterator samples = catalogManager.getSampleManager() - .iterator(studyFqn, new Query(SampleDBAdaptor.QueryParams.ID.key(), new ArrayList<>(missingSamples)), + .iterator(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.ID.key(), new ArrayList<>(missingSamples)), new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( SampleDBAdaptor.QueryParams.ID.key(), SampleDBAdaptor.QueryParams.CREATION_DATE.key(), @@ -522,7 +522,7 @@ private Set resolveSampleCatalogQuery(Query sampleQuery, Set sam if (!samples.isEmpty()) { sampleQuery.put(SampleDBAdaptor.QueryParams.ID.key(), samples); samples = getCatalogManager().getSampleManager() - .search(studyFqn, sampleQuery, new QueryOptions(QueryOptions.INCLUDE, "id"), getToken()) + .search(organizationId, studyFqn, sampleQuery, new QueryOptions(QueryOptions.INCLUDE, "id"), getToken()) .getResults() .stream() .map(Sample::getId) @@ -543,7 +543,7 @@ private Set resolveIndividualCatalogQuery(Query individualQuery, Set a.getId().equals(VARIABLE_SET_ID))) { diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/stats/SampleVariantStatsAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/stats/SampleVariantStatsAnalysis.java index fc15bc487f4..214c883210c 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/stats/SampleVariantStatsAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/stats/SampleVariantStatsAnalysis.java @@ -88,7 +88,7 @@ protected void check() throws Exception { } if (toolParams.isIndex()) { String userId = getCatalogManager().getUserManager().getUserId(getToken()); - Study study = getCatalogManager().getStudyManager().get(this.study, new QueryOptions(), getToken()).first(); + Study study = getCatalogManager().getStudyManager().get(organizationId, this.study, new QueryOptions(), getToken()).first(); boolean isOwner = study.getFqn().startsWith(userId + "@"); if (!isOwner) { Group admins = study.getGroups().stream() @@ -109,7 +109,7 @@ protected void check() throws Exception { forAllSamples = true; allSamples.addAll(indexedSamples); } else { - catalogManager.getSampleManager().get(study, toolParams.getSample(), new QueryOptions(), token) + catalogManager.getSampleManager().get(organizationId, study, toolParams.getSample(), new QueryOptions(), token) .getResults() .stream() .map(Sample::getId) @@ -118,7 +118,7 @@ protected void check() throws Exception { } if (CollectionUtils.isNotEmpty(toolParams.getIndividual())) { Query query = new Query(SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key(), toolParams.getIndividual()); - catalogManager.getSampleManager().search(study, query, new QueryOptions(), token) + catalogManager.getSampleManager().search(organizationId, study, query, new QueryOptions(), token) .getResults() .stream() .map(Sample::getId) @@ -142,7 +142,7 @@ protected void check() throws Exception { if (toolParams.isIndex()) { if (!toolParams.isIndexOverwrite()) { - List alreadyIndexedSamples = getCatalogManager().getSampleManager().search(study, + List alreadyIndexedSamples = getCatalogManager().getSampleManager().search(organizationId, study, new Query(SampleDBAdaptor.QueryParams.ID.key(), allSamples) .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, toolParams.getIndexId()) .append(ParamConstants.SAMPLE_VARIANT_STATS_COUNT_PARAM, ">=0"), @@ -277,7 +277,7 @@ protected void run() throws ToolException { SampleVariantStats sampleVariantStats = it.next(); SampleQualityControl qualityControl = getCatalogManager() .getSampleManager() - .get(getStudy(), sampleVariantStats.getId(), + .get(organizationId, getStudy(), sampleVariantStats.getId(), new QueryOptions(INCLUDE, SampleDBAdaptor.QueryParams.QUALITY_CONTROL.key()), getToken()) .first() .getQualityControl(); diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/stats/VariantStatsAnalysis.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/stats/VariantStatsAnalysis.java index 81c1e2cf507..867215db770 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/stats/VariantStatsAnalysis.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/stats/VariantStatsAnalysis.java @@ -252,7 +252,7 @@ protected void run() throws Exception { String cohortName = cohorts.get(0); List samples = catalogManager.getSampleManager() - .search(studyFqn, new Query(samplesQuery), new QueryOptions(QueryOptions.INCLUDE, "id"), token) + .search(organizationId, studyFqn, new Query(samplesQuery), new QueryOptions(QueryOptions.INCLUDE, "id"), token) .getResults(); List sampleNames = samples.stream().map(Sample::getId).collect(Collectors.toList()); @@ -260,7 +260,7 @@ protected void run() throws Exception { addAttribute("dynamicCohort", true); } else { for (String cohortName : cohorts) { - Cohort cohort = catalogManager.getCohortManager().get(studyFqn, cohortName, new QueryOptions(), token).first(); + Cohort cohort = catalogManager.getCohortManager().get(organizationId, studyFqn, cohortName, new QueryOptions(), token).first(); cohortsMap.put(cohortName, cohort.getSamples().stream().map(Sample::getId).collect(Collectors.toList())); } } @@ -325,7 +325,7 @@ private Path getFilePath(String aggregationMapFile) throws CatalogException { return Paths.get(aggregationMapFile).toAbsolutePath(); } else { return Paths.get(getCatalogManager().getFileManager() - .get(studyFqn, aggregationMapFile, QueryOptions.empty(), getToken()).first().getUri()); + .get(organizationId, studyFqn, aggregationMapFile, QueryOptions.empty(), getToken()).first().getUri()); } } @@ -393,7 +393,7 @@ public static Aggregation getAggregation(CatalogManager catalogManager, String s public static Aggregation getAggregation(CatalogManager catalogManager, String studyId, Aggregation argsAggregation, String token) throws CatalogException { QueryOptions include = new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.ATTRIBUTES.key()); - Study study = catalogManager.getStudyManager().get(studyId, include, token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyId, include, token).first(); Object studyAggregationObj = study.getAttributes().get(STATS_AGGREGATION_CATALOG); Aggregation studyAggregation = null; if (studyAggregationObj != null) { @@ -414,7 +414,7 @@ public static Aggregation getAggregation(CatalogManager catalogManager, String s Map attributes = Collections.singletonMap(STATS_AGGREGATION_CATALOG, argsAggregation); StudyUpdateParams updateParams = new StudyUpdateParams() .setAttributes(attributes); - catalogManager.getStudyManager().update(studyId, updateParams, null, token); + catalogManager.getStudyManager().update(organizationId, studyId, updateParams, null, token); } } else { if (studyAggregation == null) { diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/clinical/ClinicalInterpretationAnalysisTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/clinical/ClinicalInterpretationAnalysisTest.java index 98ae847087c..8dc81e4e91e 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/clinical/ClinicalInterpretationAnalysisTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/clinical/ClinicalInterpretationAnalysisTest.java @@ -44,9 +44,7 @@ import org.opencb.opencga.catalog.utils.ParamUtils; import org.opencb.opencga.core.exceptions.ToolException; import org.opencb.opencga.core.models.clinical.ClinicalAnalysis; -import org.opencb.opencga.core.models.clinical.ClinicalAnalysisUpdateParams; import org.opencb.opencga.core.models.clinical.InterpretationUpdateParams; -import org.opencb.opencga.core.models.individual.Individual; import org.opencb.opencga.core.response.OpenCGAResult; import org.opencb.opencga.core.testclassification.duration.MediumTests; import org.opencb.opencga.core.tools.result.ExecutionResult; @@ -191,7 +189,7 @@ public void testClinicalVariantQuery() throws Exception { options, clinicalTest.token); OpenCGAResult interpretationResult = clinicalTest.catalogManager - .getInterpretationManager().get(study, interpretationId, QueryOptions.empty(), clinicalTest.token); + .getInterpretationManager().get(organizationId, study, interpretationId, QueryOptions.empty(), clinicalTest.token); org.opencb.opencga.core.models.clinical.Interpretation interpretation = interpretationResult.first(); // assertEquals(1, interpretation.getPrimaryFindings().size()); @@ -229,7 +227,7 @@ private Interpretation readInterpretation(ExecutionResult result, Path outDir) } private void deleteSecondaryInterpretations(String caId) throws CatalogException { - ClinicalAnalysis ca = opencga.getCatalogManager().getClinicalAnalysisManager().get(clinicalTest.studyFqn, + ClinicalAnalysis ca = opencga.getCatalogManager().getClinicalAnalysisManager().get(organizationId, clinicalTest.studyFqn, caId,QueryOptions.empty(), clinicalTest.token).first(); List interpretationIds = ca.getSecondaryInterpretations().stream().map(i -> i.getId()).collect(Collectors.toList()); diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/clinical/exomiser/ExomiserInterpretationAnalysisTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/clinical/exomiser/ExomiserInterpretationAnalysisTest.java index 9889af6e563..2db86327804 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/clinical/exomiser/ExomiserInterpretationAnalysisTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/clinical/exomiser/ExomiserInterpretationAnalysisTest.java @@ -7,8 +7,6 @@ import org.opencb.biodata.models.variant.Variant; import org.opencb.biodata.models.variant.exceptions.NonStandardCompliantSampleField; import org.opencb.biodata.tools.variant.VariantNormalizer; -import org.junit.*; -import org.eclipse.jetty.util.Scanner; import org.junit.experimental.categories.Category; import org.opencb.commons.datastore.core.ObjectMap; import org.opencb.commons.datastore.core.QueryOptions; @@ -27,7 +25,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; -import java.util.Optional; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; @@ -77,7 +74,7 @@ public void singleExomiserAnalysis() throws IOException, CatalogException, ToolE outDir = Paths.get(opencga.createTmpOutdir("_interpretation_analysis_single")); OpenCGAResult caResult = clinicalTest.catalogManager.getClinicalAnalysisManager() - .get(clinicalTest.studyFqn, clinicalTest.CA_ID2, QueryOptions.empty(), clinicalTest.token); + .get(organizationId, clinicalTest.studyFqn, clinicalTest.CA_ID2, QueryOptions.empty(), clinicalTest.token); ClinicalAnalysis clinicalAnalysis = caResult.getResults().get(0); assertEquals(0, clinicalAnalysis.getSecondaryInterpretations().size()); @@ -91,7 +88,7 @@ public void singleExomiserAnalysis() throws IOException, CatalogException, ToolE // Refresh clinical analysis clinicalAnalysis = clinicalTest.catalogManager.getClinicalAnalysisManager() - .get(clinicalTest.studyFqn, clinicalTest.CA_ID2, QueryOptions.empty(), clinicalTest.token).first(); + .get(organizationId, clinicalTest.studyFqn, clinicalTest.CA_ID2, QueryOptions.empty(), clinicalTest.token).first(); assertEquals(1, clinicalAnalysis.getSecondaryInterpretations().size()); assertEquals(22, clinicalAnalysis.getSecondaryInterpretations().get(0).getPrimaryFindings().size()); } @@ -104,7 +101,7 @@ public void familyExomiserAnalysis() throws IOException, CatalogException, ToolE outDir = Paths.get(opencga.createTmpOutdir("_interpretation_analysis_family")); ClinicalAnalysis clinicalAnalysis = clinicalTest.catalogManager.getClinicalAnalysisManager() - .get(clinicalTest.studyFqn, clinicalTest.CA_ID3, QueryOptions.empty(), clinicalTest.token).first(); + .get(organizationId, clinicalTest.studyFqn, clinicalTest.CA_ID3, QueryOptions.empty(), clinicalTest.token).first(); assertEquals(0, clinicalAnalysis.getSecondaryInterpretations().size()); ExomiserInterpretationAnalysis exomiser = new ExomiserInterpretationAnalysis(); @@ -117,7 +114,7 @@ public void familyExomiserAnalysis() throws IOException, CatalogException, ToolE // Refresh clinical analysis clinicalAnalysis = clinicalTest.catalogManager.getClinicalAnalysisManager() - .get(clinicalTest.studyFqn, clinicalTest.CA_ID3, QueryOptions.empty(), clinicalTest.token).first(); + .get(organizationId, clinicalTest.studyFqn, clinicalTest.CA_ID3, QueryOptions.empty(), clinicalTest.token).first(); assertEquals(1, clinicalAnalysis.getSecondaryInterpretations().size()); assertEquals(2, clinicalAnalysis.getSecondaryInterpretations().get(0).getPrimaryFindings().size()); System.out.println("results at out dir = " + outDir.toAbsolutePath()); diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/family/FamilyAnalysisTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/family/FamilyAnalysisTest.java index 129797ea078..69be7964be8 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/family/FamilyAnalysisTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/family/FamilyAnalysisTest.java @@ -215,27 +215,27 @@ private static DataResult createDummyFamily(String familyName, List 0) { Sample sample = new Sample().setId(sampleNames.get(0)); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); } if (numMembers > 1) { Sample sample = new Sample().setId(sampleNames.get(1)); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); } if (numMembers > 2) { Sample sample = new Sample().setId(sampleNames.get(2)); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); } if (numMembers > 3) { Sample sample = new Sample().setId(sampleNames.get(3)); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); } if (numMembers > 4) { Sample sample = new Sample().setId(sampleNames.get(4)); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); } Phenotype phenotype1 = new Phenotype("dis1", "Phenotype 1", "HPO"); @@ -365,7 +365,7 @@ private DataResult createThreeGenerationFamily(String familyName, boolea List sampleNames = Arrays.asList("granma-" + familyName, "pa-" + familyName, "ma-" + familyName, "child-" + familyName); int numMembers = sampleNames.size(); for (String sampleName : sampleNames) { - catalogManager.getSampleManager().create(STUDY, new Sample().setId(sampleName), QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, new Sample().setId(sampleName), QueryOptions.empty(), sessionIdUser); } Phenotype phenotype1 = new Phenotype("dis1", "Phenotype 1", "HPO"); @@ -418,10 +418,10 @@ private static DataResult create2Member2GenerationDummyFamily(String fam throws CatalogException { int numMembers = 2; Sample sample = new Sample().setId(fatherSample); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); sample = new Sample().setId(childSample); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); Phenotype phenotype1 = new Phenotype("dis1", "Phenotype 1", "HPO"); Phenotype phenotype2 = new Phenotype("dis2", "Phenotype 2", "HPO"); diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/file/PostLinkSampleAssociationTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/file/PostLinkSampleAssociationTest.java index 665ebfbfa50..95e5d357dfe 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/file/PostLinkSampleAssociationTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/file/PostLinkSampleAssociationTest.java @@ -59,11 +59,11 @@ public void linkTest() throws Exception { assertFalse(link.first().getInternal().getMissingSamples().getNonExisting().isEmpty()); Query query = new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), link.first().getId()); - OpenCGAResult search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + OpenCGAResult search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(0, search.getNumResults()); query = new Query(SampleDBAdaptor.QueryParams.ID.key(), Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685")); - search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(0, search.getNumResults()); Path outDir = Paths.get(opencga.createTmpOutdir("_postlink")); @@ -74,7 +74,7 @@ public void linkTest() throws Exception { postLinkSampleAssociation.start(); System.out.println(link); - File file = fileManager.get(studyFqn, link.first().getId(), QueryOptions.empty(), token).first(); + File file = fileManager.get(organizationId, studyFqn, link.first().getId(), QueryOptions.empty(), token).first(); assertEquals(4, file.getSampleIds().size()); assertTrue(file.getSampleIds().containsAll(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"))); @@ -83,19 +83,19 @@ public void linkTest() throws Exception { assertTrue(file.getInternal().getMissingSamples().getExisting().isEmpty()); query = new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), file.getId()); - search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(4, search.getNumResults()); assertTrue(search.getResults().stream().map(Sample::getId).collect(Collectors.toSet()) .containsAll(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"))); query = new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), file.getUuid()); - search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(4, search.getNumResults()); assertTrue(search.getResults().stream().map(Sample::getId).collect(Collectors.toSet()) .containsAll(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"))); query = new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), file.getPath()); - search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(4, search.getNumResults()); assertTrue(search.getResults().stream().map(Sample::getId).collect(Collectors.toSet()) .containsAll(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"))); @@ -108,7 +108,7 @@ public void postLinkPassingVirtualFile() throws Exception { String vcfFile = opencga.getResourceUri("biofiles/variant-test-file.vcf.gz").toString(); OpenCGAResult link = fileManager.link(studyFqn, new FileLinkParams(vcfFile, "", "", "", null, "biofiles/virtual_file.vcf", null, null, null), false, token); - OpenCGAResult virtualResult = fileManager.get(studyFqn, "virtual_file.vcf", QueryOptions.empty(), token); + OpenCGAResult virtualResult = fileManager.get(organizationId, studyFqn, "virtual_file.vcf", QueryOptions.empty(), token); assertEquals(0, link.first().getSampleIds().size()); assertEquals(FileStatus.READY, link.first().getInternal().getStatus().getId()); @@ -119,11 +119,11 @@ public void postLinkPassingVirtualFile() throws Exception { assertFalse(virtualResult.first().getInternal().getMissingSamples().getNonExisting().isEmpty()); Query query = new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), link.first().getId()); - OpenCGAResult search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + OpenCGAResult search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(0, search.getNumResults()); query = new Query(SampleDBAdaptor.QueryParams.ID.key(), Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685")); - search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(0, search.getNumResults()); Path outDir = Paths.get(opencga.createTmpOutdir("_postlink")); @@ -136,7 +136,7 @@ public void postLinkPassingVirtualFile() throws Exception { postLinkSampleAssociation.start(); System.out.println(link); - File file = fileManager.get(studyFqn, virtualResult.first().getId(), QueryOptions.empty(), token).first(); + File file = fileManager.get(organizationId, studyFqn, virtualResult.first().getId(), QueryOptions.empty(), token).first(); assertEquals(4, file.getSampleIds().size()); assertTrue(file.getSampleIds().containsAll(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"))); @@ -145,19 +145,19 @@ public void postLinkPassingVirtualFile() throws Exception { assertTrue(file.getInternal().getMissingSamples().getExisting().isEmpty()); query = new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), file.getId()); - search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(4, search.getNumResults()); assertTrue(search.getResults().stream().map(Sample::getId).collect(Collectors.toSet()) .containsAll(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"))); query = new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), file.getUuid()); - search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(4, search.getNumResults()); assertTrue(search.getResults().stream().map(Sample::getId).collect(Collectors.toSet()) .containsAll(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"))); query = new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), file.getPath()); - search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(4, search.getNumResults()); assertTrue(search.getResults().stream().map(Sample::getId).collect(Collectors.toSet()) .containsAll(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"))); @@ -170,7 +170,7 @@ public void postLinkPassingMultipartFile() throws Exception { String vcfFile = opencga.getResourceUri("biofiles/variant-test-file.vcf.gz").toString(); OpenCGAResult link = fileManager.link(studyFqn, new FileLinkParams(vcfFile, "", "", "", null, "biofiles/virtual_file.vcf", null, null, null), false, token); - OpenCGAResult virtualResult = fileManager.get(studyFqn, "virtual_file.vcf", QueryOptions.empty(), token); + OpenCGAResult virtualResult = fileManager.get(organizationId, studyFqn, "virtual_file.vcf", QueryOptions.empty(), token); assertEquals(0, link.first().getSampleIds().size()); assertEquals(FileStatus.READY, link.first().getInternal().getStatus().getId()); @@ -181,11 +181,11 @@ public void postLinkPassingMultipartFile() throws Exception { assertFalse(virtualResult.first().getInternal().getMissingSamples().getNonExisting().isEmpty()); Query query = new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), link.first().getId()); - OpenCGAResult search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + OpenCGAResult search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(0, search.getNumResults()); query = new Query(SampleDBAdaptor.QueryParams.ID.key(), Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685")); - search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(0, search.getNumResults()); Path outDir = Paths.get(opencga.createTmpOutdir("_postlink")); @@ -198,7 +198,7 @@ public void postLinkPassingMultipartFile() throws Exception { postLinkSampleAssociation.start(); System.out.println(link); - File file = fileManager.get(studyFqn, virtualResult.first().getId(), QueryOptions.empty(), token).first(); + File file = fileManager.get(organizationId, studyFqn, virtualResult.first().getId(), QueryOptions.empty(), token).first(); assertEquals(4, file.getSampleIds().size()); assertTrue(file.getSampleIds().containsAll(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"))); @@ -207,19 +207,19 @@ public void postLinkPassingMultipartFile() throws Exception { assertTrue(file.getInternal().getMissingSamples().getExisting().isEmpty()); query = new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), file.getId()); - search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(4, search.getNumResults()); assertTrue(search.getResults().stream().map(Sample::getId).collect(Collectors.toSet()) .containsAll(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"))); query = new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), file.getUuid()); - search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(4, search.getNumResults()); assertTrue(search.getResults().stream().map(Sample::getId).collect(Collectors.toSet()) .containsAll(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"))); query = new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), file.getPath()); - search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(4, search.getNumResults()); assertTrue(search.getResults().stream().map(Sample::getId).collect(Collectors.toSet()) .containsAll(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"))); @@ -237,11 +237,11 @@ public void linkTestFile() throws Exception { assertFalse(link.first().getInternal().getMissingSamples().getNonExisting().isEmpty()); Query query = new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), link.first().getId()); - OpenCGAResult search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + OpenCGAResult search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(0, search.getNumResults()); query = new Query(SampleDBAdaptor.QueryParams.ID.key(), Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685")); - search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(0, search.getNumResults()); Path outDir = Paths.get(opencga.createTmpOutdir("_postlink")); @@ -253,7 +253,7 @@ public void linkTestFile() throws Exception { postLinkSampleAssociation.start(); System.out.println(link); - File file = fileManager.get(studyFqn, link.first().getId(), QueryOptions.empty(), token).first(); + File file = fileManager.get(organizationId, studyFqn, link.first().getId(), QueryOptions.empty(), token).first(); assertEquals(4, file.getSampleIds().size()); assertTrue(file.getSampleIds().containsAll(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"))); @@ -262,7 +262,7 @@ public void linkTestFile() throws Exception { assertTrue(file.getInternal().getMissingSamples().getExisting().isEmpty()); query = new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), file.getId()); - search = catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); + search = catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token); assertEquals(4, search.getNumResults()); assertTrue(search.getResults().stream().map(Sample::getId).collect(Collectors.toSet()) .containsAll(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"))); diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/rga/RgaManagerTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/rga/RgaManagerTest.java index 475d70523d3..a2934f94015 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/rga/RgaManagerTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/rga/RgaManagerTest.java @@ -196,7 +196,7 @@ public void setUpCatalogManager() throws CatalogException { if (i % 2 == 0) { sample.setPhenotypes(Collections.singletonList(PHENOTYPE)); } - catalogManager.getSampleManager().create(STUDY, sample, null, ownerToken); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, null, ownerToken); } catalogManager.getUserManager().create(USER, "Other Name", "mail2@ebi.ac.uk", PASSWORD, "", null, Account.AccountType.GUEST, opencga.getAdminToken()); diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/OpenCGATestExternalResource.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/OpenCGATestExternalResource.java index 95f0ef297d5..4c9d0609b0d 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/OpenCGATestExternalResource.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/OpenCGATestExternalResource.java @@ -277,7 +277,7 @@ public File createFile(String studyId, String resourceName, String sessionId) th // System.out.println("resourceName = " + resourceName); // file = new FileMetadataReader(catalogManager).create(studyId, uri, "data/vcfs/", "", true, null, sessionId).first(); // new FileUtils(catalogManager).upload(uri, file, null, sessionId, false, false, true, false, Long.MAX_VALUE); - return catalogManager.getFileManager().get(studyId, resourceName, null, sessionId).first(); + return catalogManager.getFileManager().get(organizationId, studyId, resourceName, null, sessionId).first(); } public void clear() throws Exception { diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/VariantAnalysisTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/VariantAnalysisTest.java index 37ae808c6bf..1fe1c28dac3 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/VariantAnalysisTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/VariantAnalysisTest.java @@ -272,7 +272,7 @@ public void setUpCatalogManager() throws IOException, CatalogException { if (i % 2 == 0) { sample.setPhenotypes(Collections.singletonList(PHENOTYPE)); } - catalogManager.getSampleManager().create(STUDY, sample, null, token); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, null, token); } // Cancer @@ -391,7 +391,7 @@ private java.io.File getOutputFile(Path outDir) { public void testSampleStatsSampleFilter() throws Exception { Assume.assumeThat(storageEngine, CoreMatchers.is(HadoopVariantStorageEngine.STORAGE_ENGINE_ID)); // Reset quality control stats - for (Sample sample : catalogManager.getSampleManager().search(STUDY, new Query(), new QueryOptions(), token).getResults()) { + for (Sample sample : catalogManager.getSampleManager().search(organizationId, STUDY, new Query(), new QueryOptions(), token).getResults()) { SampleQualityControl qualityControl = sample.getQualityControl(); if (qualityControl != null && qualityControl.getVariant() != null && CollectionUtils.isNotEmpty(qualityControl.getVariant().getVariantStats())) { qualityControl.getVariant().setVariantStats(Collections.emptyList()); @@ -483,7 +483,7 @@ private ExecutionResult sampleVariantStats(String region, String indexId, boolea samples = file.getSampleIds(); } for (String sample : samples) { - Sample sampleObj = catalogManager.getSampleManager().get(STUDY, sample, QueryOptions.empty(), token).first(); + Sample sampleObj = catalogManager.getSampleManager().get(organizationId, STUDY, sample, QueryOptions.empty(), token).first(); List variantStats = sampleObj.getQualityControl().getVariant().getVariantStats(); assertEquals(expectedStats, variantStats.size()); assertThat(variantStats.stream().map(SampleQcVariantStats::getId).collect(Collectors.toSet()), hasItem(indexId)); @@ -518,7 +518,7 @@ public void testCohortStatsIndex() throws Exception { outDir, null, token); checkExecutionResult(result, storageEngine.equals(HadoopVariantStorageEngine.STORAGE_ENGINE_ID)); - Cohort cohort = catalogManager.getCohortManager().get(STUDY, StudyEntry.DEFAULT_COHORT, new QueryOptions(), token).first(); + Cohort cohort = catalogManager.getCohortManager().get(organizationId, STUDY, StudyEntry.DEFAULT_COHORT, new QueryOptions(), token).first(); assertEquals(1, cohort.getAnnotationSets().size()); AnnotationSet annotationSet = cohort.getAnnotationSets().get(0); assertEquals(CohortVariantStatsAnalysis.VARIABLE_SET_ID, annotationSet.getId()); @@ -543,7 +543,7 @@ public void testCohortStatsIndex() throws Exception { checkExecutionResult(result, storageEngine.equals(HadoopVariantStorageEngine.STORAGE_ENGINE_ID)); - cohort = catalogManager.getCohortManager().get(STUDY, StudyEntry.DEFAULT_COHORT, new QueryOptions(), token).first(); + cohort = catalogManager.getCohortManager().get(organizationId, STUDY, StudyEntry.DEFAULT_COHORT, new QueryOptions(), token).first(); assertEquals(1, cohort.getAnnotationSets().size()); annotationSet = cohort.getAnnotationSets().get(0); assertEquals(CohortVariantStatsAnalysis.VARIABLE_SET_ID, annotationSet.getId()); @@ -786,7 +786,7 @@ public void testMutationalSignatureFittingSNV() throws Exception { System.out.println(new String(bytes)); assertTrue(signatureFile.exists()); - OpenCGAResult sampleResult = catalogManager.getSampleManager().get(CANCER_STUDY, cancer_sample, QueryOptions.empty(), token); + OpenCGAResult sampleResult = catalogManager.getSampleManager().get(organizationId, CANCER_STUDY, cancer_sample, QueryOptions.empty(), token); Sample sample = sampleResult.first(); List signatures = sample.getQualityControl().getVariant().getSignatures(); for (Signature sig : signatures) { @@ -833,7 +833,7 @@ public void testMutationalSignatureCatalogueSV() throws Exception { System.out.println(new String(bytes)); assertTrue(signatureFile.exists()); - OpenCGAResult sampleResult = catalogManager.getSampleManager().get(CANCER_STUDY, cancer_sample, QueryOptions.empty(), token); + OpenCGAResult sampleResult = catalogManager.getSampleManager().get(organizationId, CANCER_STUDY, cancer_sample, QueryOptions.empty(), token); Sample sample = sampleResult.first(); List signatures = sample.getQualityControl().getVariant().getSignatures(); for (Signature signature : signatures) { @@ -854,7 +854,7 @@ public void testMutationalSignatureFittingSV() throws Exception { catalogManager.getFileManager().createFolder(CANCER_STUDY, "signature", true, "", new QueryOptions(), token); catalogManager.getFileManager().link(CANCER_STUDY, uri, "signature", new ObjectMap(), token); String filename = Paths.get(uri.toURL().getFile()).toFile().getName(); - File file = catalogManager.getFileManager().get(CANCER_STUDY, filename, null, token).first(); + File file = catalogManager.getFileManager().get(organizationId, CANCER_STUDY, filename, null, token).first(); String signatureFileId = file.getId(); uri = getResourceUri("mutational-signature-sv.json"); @@ -944,7 +944,7 @@ public void testHRDetect() throws Exception { catalogManager.getFileManager().createFolder(CANCER_STUDY, "signature", true, "", new QueryOptions(), token); catalogManager.getFileManager().link(CANCER_STUDY, uri, "signature", new ObjectMap(), token); String filename = Paths.get(uri.toURL().getFile()).toFile().getName(); - File file = catalogManager.getFileManager().get(CANCER_STUDY, filename, null, token).first(); + File file = catalogManager.getFileManager().get(organizationId, CANCER_STUDY, filename, null, token).first(); String signatureFileId = file.getId(); params = new MutationalSignatureAnalysisParams(); @@ -987,7 +987,7 @@ public void testHRDetect() throws Exception { System.out.println(new String(bytes)); assertTrue(hrDetectFile.exists()); - OpenCGAResult sampleResult = catalogManager.getSampleManager().get(CANCER_STUDY, cancer_sample, QueryOptions.empty(), token); + OpenCGAResult sampleResult = catalogManager.getSampleManager().get(organizationId, CANCER_STUDY, cancer_sample, QueryOptions.empty(), token); Sample sample = sampleResult.first(); List hrDetects = sample.getQualityControl().getVariant().getHrDetects(); for (HRDetect hrDetect : hrDetects) { diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantCatalogQueryUtilsTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantCatalogQueryUtilsTest.java index 58aa48f7828..b35a28bbd55 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantCatalogQueryUtilsTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantCatalogQueryUtilsTest.java @@ -126,13 +126,13 @@ public static void setUp() throws Exception { Phenotype phenotype = new Phenotype("phenotype", "phenotype", ""); Disorder disorder = new Disorder("disorder", "disorder", "", "", Collections.singletonList(phenotype), Collections.emptyMap()); - individuals.add(catalog.getIndividualManager().create("s1", new Individual("individual1", "individual1", new Individual(), new Individual(), new Location(), SexOntologyTermAnnotation.initMale(), null, null, null, null, "", + individuals.add(catalog.getIndividualManager().create(organizationId, "s1", new Individual("individual1", "individual1", new Individual(), new Individual(), new Location(), SexOntologyTermAnnotation.initMale(), null, null, null, null, "", Collections.emptyList(), false, 0, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), IndividualInternal.init(), Collections.emptyMap()), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first()); - individuals.add(catalog.getIndividualManager().create("s1", new Individual("individual2", "individual2", new Individual(), new Individual(), new Location(), SexOntologyTermAnnotation.initFemale(), null, null, null, null, "", + individuals.add(catalog.getIndividualManager().create(organizationId, "s1", new Individual("individual2", "individual2", new Individual(), new Individual(), new Location(), SexOntologyTermAnnotation.initFemale(), null, null, null, null, "", Collections.emptyList(), false, 0, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), IndividualInternal.init(), Collections.emptyMap()), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first()); - individuals.add(catalog.getIndividualManager().create("s1", new Individual("individual3", "individual3", new Individual(), new Individual(), new Location(), SexOntologyTermAnnotation.initMale(), null, null, null, null, "", + individuals.add(catalog.getIndividualManager().create(organizationId, "s1", new Individual("individual3", "individual3", new Individual(), new Individual(), new Location(), SexOntologyTermAnnotation.initMale(), null, null, null, null, "", Collections.emptyList(), false, 0, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), IndividualInternal.init(), Collections.emptyMap()).setFather(individuals.get(0)).setMother(individuals.get(1)).setDisorders(Collections.singletonList(disorder)), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first()); - individuals.add(catalog.getIndividualManager().create("s1", new Individual("individual4", "individual4", new Individual(), new Individual(), new Location(), SexOntologyTermAnnotation.initFemale(), null, null, null, null, "", + individuals.add(catalog.getIndividualManager().create(organizationId, "s1", new Individual("individual4", "individual4", new Individual(), new Individual(), new Location(), SexOntologyTermAnnotation.initFemale(), null, null, null, null, "", Collections.emptyList(), false, 0, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), IndividualInternal.init(), Collections.emptyMap()).setFather(individuals.get(0)).setMother(individuals.get(1)), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first()); catalog.getFamilyManager().create( "s1", @@ -143,18 +143,18 @@ public static void setUp() throws Exception { createSample("sample1", "individual1"); createSample("sample2", "individual2"); - catalog.getCohortManager().create("s1", new Cohort().setId("c1").setSamples(Collections.emptyList()), null, sessionId); + catalog.getCohortManager().create(organizationId, "s1", new Cohort().setId("c1").setSamples(Collections.emptyList()), null, sessionId); - catalog.getProjectManager().incrementRelease("p1", sessionId); + catalog.getProjectManager().incrementRelease(organizationId, "p1", sessionId); file3 = createFile("data/file3.vcf"); file4 = createFile("data/file4.vcf"); file5 = createFile("data/file5.vcf", false); createSample("sample3", "individual3"); createSample("sample4", "individual4"); - catalog.getCohortManager().create("s1", new Cohort().setId("c2").setSamples(Collections.emptyList()), null, sessionId); - catalog.getCohortManager().create("s1", new Cohort().setId(StudyEntry.DEFAULT_COHORT).setSamples(samples), null, sessionId); + catalog.getCohortManager().create(organizationId, "s1", new Cohort().setId("c2").setSamples(Collections.emptyList()), null, sessionId); + catalog.getCohortManager().create(organizationId, "s1", new Cohort().setId(StudyEntry.DEFAULT_COHORT).setSamples(samples), null, sessionId); - catalog.getCohortManager().create("s2", new Cohort().setId(StudyEntry.DEFAULT_COHORT).setSamples(Collections.emptyList()), null, sessionId); + catalog.getCohortManager().create(organizationId, "s2", new Cohort().setId(StudyEntry.DEFAULT_COHORT).setSamples(Collections.emptyList()), null, sessionId); catalog.getProjectManager().create("p2", "p2", "", "hsapiens", "Homo Sapiens", assembly, null, sessionId); catalog.getStudyManager().create("p2", "p2s2", "p2s2", "p2s2", null, null, null, null, null, null, sessionId); @@ -181,7 +181,7 @@ public static void setUp() throws Exception { .setName("ADSL") )); - catalog.getPanelManager().create("s1", myPanel, null, sessionId); + catalog.getPanelManager().create(organizationId, "s1", myPanel, null, sessionId); queryUtils = new VariantCatalogQueryUtils(catalog); @@ -213,13 +213,13 @@ public static void setUp() throws Exception { "X:1-1000", null)))) )) ; - catalog.getPanelManager().create("s1", myPanelWithRegions, null, sessionId); + catalog.getPanelManager().create(organizationId, "s1", myPanelWithRegions, null, sessionId); } public static void createSample(String name, String individualName) throws CatalogException { - samples.add(catalog.getSampleManager().create("s1", new Sample().setId(name).setIndividualId(individualName), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first()); + samples.add(catalog.getSampleManager().create(organizationId, "s1", new Sample().setId(name).setIndividualId(individualName), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first()); } public static File createFile(String path) throws CatalogException { @@ -236,7 +236,7 @@ public static File createFile(String path, boolean indexed) throws CatalogExcept .setBioformat(File.Bioformat.VARIANT), true, sessionId).first(); if (indexed) { - int release = catalog.getProjectManager().get("p1", null, sessionId).first().getCurrentRelease(); + int release = catalog.getProjectManager().get(organizationId, "p1", null, sessionId).first().getCurrentRelease(); catalog.getFileManager().updateFileInternalVariantIndex(file, new FileInternalVariantIndex() .setStatus(new VariantIndexStatus(InternalStatus.READY)) .setRelease(release), sessionId); @@ -780,7 +780,7 @@ public void queryByPanelIntersectSinglePositionRegions() throws Exception { new DiseasePanel.Coordinate(assembly, singlePositionRegion, null)))) )) ; - catalog.getPanelManager().create("s1", myPanelWithSinglePositionRegion, null, sessionId); + catalog.getPanelManager().create(organizationId, "s1", myPanelWithSinglePositionRegion, null, sessionId); query = queryUtils.parseQuery(new Query(STUDY.key(), "s1").append(PANEL.key(), myPanelWithSinglePositionRegion.getId()) .append(GENE.key(), "BRCA2") @@ -802,7 +802,7 @@ public void queryByPanelsWithGeneXrefs() throws Exception { String geneName = "TSC2"; Panel myPanelWithXrefGenes = new Panel("myPanelWithXrefGenes", "myPanelWithXrefGenes", 1) .setGenes(Arrays.asList(new GenePanel().setName(geneXref))); - catalog.getPanelManager().create("s1", myPanelWithXrefGenes, null, sessionId); + catalog.getPanelManager().create(organizationId, "s1", myPanelWithXrefGenes, null, sessionId); Query query = queryUtils.parseQuery(new Query(STUDY.key(), "s1").append(PANEL.key(), myPanelWithXrefGenes.getId()), null, cellBaseUtils, sessionId); assertEquals(set(geneName), set(query, GENE)); @@ -853,7 +853,7 @@ public void getAnyStudy() throws Exception { @Test public void getTriosFromFamily() throws Exception { - Family f1 = catalog.getFamilyManager().get("s1", "f1", null, sessionId).first(); + Family f1 = catalog.getFamilyManager().get(organizationId, "s1", "f1", null, sessionId).first(); VariantStorageMetadataManager metadataManager = new VariantStorageMetadataManager(new DummyVariantStorageMetadataDBAdaptorFactory()); StudyMetadata s1 = metadataManager.createStudy("s1"); List sampleIds = metadataManager.registerSamples(s1.getId(), Arrays.asList( diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantManagerFetchTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantManagerFetchTest.java index 4caca0d7c20..29465ab18de 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantManagerFetchTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantManagerFetchTest.java @@ -103,7 +103,7 @@ public void testCheckSamplePermissionNonIndexedSamples() throws Exception { Assert.assertEquals(Collections.singleton(studyFqn), map.keySet()); Assert.assertEquals(Arrays.asList("NA19600", "NA19660", "NA19661", "NA19685"), map.get(studyFqn)); - catalogManager.getSampleManager().create(studyFqn, new Sample().setId("newSample"), new QueryOptions(), sessionId); + catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("newSample"), new QueryOptions(), sessionId); queryOptions = new QueryOptions(); query = new Query().append(VariantQueryParam.INCLUDE_SAMPLE.key(), ParamConstants.ALL); @@ -140,9 +140,9 @@ public void testQueryExcludeStudies() throws Exception { @Test public void testQueryAnonymousOnlyAggregated() throws Exception { // Only Aggregated studies - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("*")), sessionId); - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), "*", + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), "*", new StudyAclParams(StudyPermissions.Permissions.VIEW_AGGREGATED_VARIANTS.name(), null), ADD, sessionId); @@ -156,9 +156,9 @@ public void testQueryAnonymousOnlyAggregated() throws Exception { @Test public void testQueryAnonymousViewSampleVariants() throws Exception { - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("*")), sessionId); - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), "*", + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), "*", new StudyAclParams(StudyPermissions.Permissions.VIEW_AGGREGATED_VARIANTS.name(), null), ADD, sessionId); catalogManager.getSampleManager().updateAcl(studyFqn, Arrays.asList("NA19600"), "*", @@ -205,7 +205,7 @@ public void testQueryAnonymousViewSampleVariantsWithoutAggregatedVariants() thro @Test public void testQueryAnonymousViewSampleVariantsWithoutAggregatedVariantsFail1() throws Exception { - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), "*", + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), "*", new StudyAclParams(StudyPermissions.Permissions.VIEW_SAMPLES.name(), null), ADD, sessionId); // Only 2 samples catalogManager.getSampleManager().updateAcl(studyFqn, Arrays.asList("NA19600", "NA19660"), "*", @@ -225,7 +225,7 @@ public void testQueryAnonymousViewSampleVariantsWithoutAggregatedVariantsFail1() @Test public void testQueryAnonymousViewSampleVariantsWithoutAggregatedVariantsFail2() throws Exception { - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), "*", + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), "*", new StudyAclParams(StudyPermissions.Permissions.VIEW_SAMPLES.name(), null), ADD, sessionId); // Only 2 samples catalogManager.getSampleManager().updateAcl(studyFqn, Arrays.asList("NA19600", "NA19660"), "*", @@ -245,7 +245,7 @@ public void testQueryAnonymousViewSampleVariantsWithoutAggregatedVariantsFail2() @Test public void testQueryAnonymousViewSampleVariantsStudyLevel() throws Exception { // All samples - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), "*", + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), "*", new StudyAclParams() // VIEW_SAMPLE_VARIANTS without VIEW_SAMPLES should be enough .setPermissions(StudyPermissions.Permissions.VIEW_SAMPLE_VARIANTS.name()), @@ -270,7 +270,7 @@ public void testQueryAnonymousWithoutPermissions() throws Exception { @Test public void testQueryAnonymousInMembersWithoutPermissions() throws Exception { - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("*")), sessionId); // Missing VIEW_AGGREGATED_VARIANTS Query query = new Query(VariantQueryParam.STUDY.key(), studyId); @@ -281,9 +281,9 @@ public void testQueryAnonymousInMembersWithoutPermissions() throws Exception { @Test public void testQueryAnonymousOneStudyPermissions() throws Exception { - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("*")), sessionId); - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), "*", + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), "*", new StudyAclParams() .setPermissions(StudyPermissions.Permissions.VIEW_AGGREGATED_VARIANTS.name()), ADD, sessionId); @@ -307,9 +307,9 @@ public void testQueryAnonymousOneStudyPermissions() throws Exception { @Test public void testQueryAnonymousOneStudyPermissionsIncludeBoth() throws Exception { - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("*")), sessionId); - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), "*", + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), "*", new StudyAclParams() .setPermissions(StudyPermissions.Permissions.VIEW_AGGREGATED_VARIANTS.name()), ADD, sessionId); @@ -331,9 +331,9 @@ public void testQueryAnonymousOneStudyPermissionsIncludeBoth() throws Exception @Test public void testQueryAnonymousTwoStudiesPermissions() throws Exception { - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("*")), sessionId); - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), "*", + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), "*", new StudyAclParams() .setPermissions(StudyPermissions.Permissions.VIEW_AGGREGATED_VARIANTS.name()), ADD, sessionId); @@ -342,9 +342,9 @@ public void testQueryAnonymousTwoStudiesPermissions() throws Exception { indexFile(file, new QueryOptions(), outputId2); - catalogManager.getStudyManager().updateGroup(studyId2, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyId2, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("*")), sessionId); - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyId2), "*", + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyId2), "*", new StudyAclParams() .setPermissions(StudyPermissions.Permissions.VIEW_AGGREGATED_VARIANTS.name()), ADD, sessionId); diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantOperationsTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantOperationsTest.java index 38ef6f98a21..3a21e49747c 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantOperationsTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantOperationsTest.java @@ -272,7 +272,7 @@ public void setUpCatalogManager() throws Exception { if (i % 2 == 0) { sample.setPhenotypes(Collections.singletonList(PHENOTYPE)); } - catalogManager.getSampleManager().create(STUDY, sample, null, token); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, null, token); } } @@ -281,20 +281,20 @@ public void setUpCatalogManager() throws Exception { public void testVariantSecondaryAnnotationIndex() throws Exception { for (String sample : samples) { - SampleInternalVariantSecondaryAnnotationIndex index = catalogManager.getSampleManager().get(STUDY, sample, new QueryOptions(), token).first().getInternal().getVariant().getSecondaryAnnotationIndex(); + SampleInternalVariantSecondaryAnnotationIndex index = catalogManager.getSampleManager().get(organizationId, STUDY, sample, new QueryOptions(), token).first().getInternal().getVariant().getSecondaryAnnotationIndex(); assertEquals(IndexStatus.NONE, index.getStatus().getId()); } - assertEquals(IndexStatus.NONE, catalogManager.getFileManager().get(STUDY, file.getId(), new QueryOptions(), token).first().getInternal().getVariant().getSecondaryAnnotationIndex().getStatus().getId()); + assertEquals(IndexStatus.NONE, catalogManager.getFileManager().get(organizationId, STUDY, file.getId(), new QueryOptions(), token).first().getInternal().getVariant().getSecondaryAnnotationIndex().getStatus().getId()); toolRunner.execute(VariantSecondaryAnnotationIndexOperationTool.class, STUDY, new VariantSecondaryAnnotationIndexParams(), Paths.get(opencga.createTmpOutdir()), "annotation_index", token); for (String sample : samples) { - SampleInternalVariantSecondaryAnnotationIndex index = catalogManager.getSampleManager().get(STUDY, sample, new QueryOptions(), token).first().getInternal().getVariant().getSecondaryAnnotationIndex(); + SampleInternalVariantSecondaryAnnotationIndex index = catalogManager.getSampleManager().get(organizationId, STUDY, sample, new QueryOptions(), token).first().getInternal().getVariant().getSecondaryAnnotationIndex(); assertEquals(IndexStatus.READY, index.getStatus().getId()); } - assertEquals(IndexStatus.READY, catalogManager.getFileManager().get(STUDY, file.getId(), new QueryOptions(), token).first().getInternal().getVariant().getSecondaryAnnotationIndex().getStatus().getId()); + assertEquals(IndexStatus.READY, catalogManager.getFileManager().get(organizationId, STUDY, file.getId(), new QueryOptions(), token).first().getInternal().getVariant().getSecondaryAnnotationIndex().getStatus().getId()); } @@ -305,7 +305,7 @@ public void testVariantSecondarySampleIndex() throws Exception { is(HadoopVariantStorageEngine.STORAGE_ENGINE_ID) )); for (String sample : samples) { - SampleInternalVariantSecondarySampleIndex sampleIndex = catalogManager.getSampleManager().get(STUDY, sample, new QueryOptions(), token).first().getInternal().getVariant().getSecondarySampleIndex(); + SampleInternalVariantSecondarySampleIndex sampleIndex = catalogManager.getSampleManager().get(organizationId, STUDY, sample, new QueryOptions(), token).first().getInternal().getVariant().getSecondarySampleIndex(); assertEquals(sample, IndexStatus.READY, sampleIndex.getStatus().getId()); assertEquals(sample, IndexStatus.NONE, sampleIndex.getFamilyStatus().getId()); assertEquals(sample, 1, sampleIndex.getVersion().intValue()); @@ -319,7 +319,7 @@ public void testVariantSecondarySampleIndex() throws Exception { Paths.get(opencga.createTmpOutdir()), "index", token); for (String sample : samples) { - SampleInternalVariantSecondarySampleIndex sampleIndex = catalogManager.getSampleManager().get(STUDY, sample, new QueryOptions(), token).first().getInternal().getVariant().getSecondarySampleIndex(); + SampleInternalVariantSecondarySampleIndex sampleIndex = catalogManager.getSampleManager().get(organizationId, STUDY, sample, new QueryOptions(), token).first().getInternal().getVariant().getSecondarySampleIndex(); assertEquals(sample, IndexStatus.READY, sampleIndex.getStatus().getId()); if (sample.equals(daughter) || sample.equals(son)) { assertEquals(sample, IndexStatus.READY, sampleIndex.getFamilyStatus().getId()); @@ -337,7 +337,7 @@ public void testVariantSecondarySampleIndex() throws Exception { Paths.get(opencga.createTmpOutdir()), "", catalogManager.getUserManager().loginAsAdmin(TestParamConstants.ADMIN_PASSWORD).getToken()); for (String sample : samples) { - SampleInternalVariantSecondarySampleIndex sampleIndex = catalogManager.getSampleManager().get(STUDY, sample, new QueryOptions(), token) + SampleInternalVariantSecondarySampleIndex sampleIndex = catalogManager.getSampleManager().get(organizationId, STUDY, sample, new QueryOptions(), token) .first().getInternal().getVariant().getSecondarySampleIndex(); assertEquals(IndexStatus.READY, sampleIndex.getStatus().getId()); if (sample.equals(daughter) || sample.equals(son)) { @@ -352,7 +352,7 @@ public void testVariantSecondarySampleIndex() throws Exception { // Everything should look the same, but with newer version for (String sample : samples) { - SampleInternalVariantSecondarySampleIndex sampleIndex = catalogManager.getSampleManager().get(STUDY, sample, new QueryOptions(), token).first().getInternal().getVariant().getSecondarySampleIndex(); + SampleInternalVariantSecondarySampleIndex sampleIndex = catalogManager.getSampleManager().get(organizationId, STUDY, sample, new QueryOptions(), token).first().getInternal().getVariant().getSecondarySampleIndex(); assertEquals(IndexStatus.READY, sampleIndex.getStatus().getId()); if (sample.equals(daughter) || sample.equals(son)) { assertEquals(sample, IndexStatus.READY, sampleIndex.getFamilyStatus().getId()); @@ -366,7 +366,7 @@ public void testVariantSecondarySampleIndex() throws Exception { toolRunner.execute(job, Paths.get(opencga.createTmpOutdir()), token); } for (String sample : samples) { - SampleInternalVariantSecondarySampleIndex sampleIndex = catalogManager.getSampleManager().get(STUDY, sample, new QueryOptions(), token).first().getInternal().getVariant().getSecondarySampleIndex(); + SampleInternalVariantSecondarySampleIndex sampleIndex = catalogManager.getSampleManager().get(organizationId, STUDY, sample, new QueryOptions(), token).first().getInternal().getVariant().getSecondarySampleIndex(); assertEquals(IndexStatus.READY, sampleIndex.getStatus().getId()); if (sample.equals(daughter) || sample.equals(son)) { assertEquals(sample, IndexStatus.READY, sampleIndex.getFamilyStatus().getId()); @@ -386,10 +386,10 @@ public void testGwasIndex() throws Exception { System.out.println("output = " + outDir.toAbsolutePath()); analysis.setUp(opencga.getOpencgaHome().toString(), catalogManager, variantStorageManager, executorParams, outDir, "", token); - List samples = catalogManager.getSampleManager().get(STUDY, file.getSampleIds().subList(0, 2), QueryOptions.empty(), token).getResults(); - catalogManager.getCohortManager().create(STUDY, new Cohort().setId("CASE").setSamples(samples), new QueryOptions(), token); - samples = catalogManager.getSampleManager().get(STUDY, file.getSampleIds().subList(2, 4), QueryOptions.empty(), token).getResults(); - catalogManager.getCohortManager().create(STUDY, new Cohort().setId("CONTROL").setSamples(samples), new QueryOptions(), token); + List samples = catalogManager.getSampleManager().get(organizationId, STUDY, file.getSampleIds().subList(0, 2), QueryOptions.empty(), token).getResults(); + catalogManager.getCohortManager().create(organizationId, STUDY, new Cohort().setId("CASE").setSamples(samples), new QueryOptions(), token); + samples = catalogManager.getSampleManager().get(organizationId, STUDY, file.getSampleIds().subList(2, 4), QueryOptions.empty(), token).getResults(); + catalogManager.getCohortManager().create(organizationId, STUDY, new Cohort().setId("CONTROL").setSamples(samples), new QueryOptions(), token); analysis.setStudy(STUDY) .setCaseCohort("CASE") diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantStorageManagerTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantStorageManagerTest.java index 0a5ac63293d..32b54176e2f 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantStorageManagerTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/VariantStorageManagerTest.java @@ -91,13 +91,13 @@ public void testConfigureSampleIndex() throws Exception { SampleIndexConfiguration conf = getRandomConf(); OpenCGAResult result = variantManager.configureSampleIndex(studyId, conf, true, sessionId); assertEquals(0, result.getResults().size()); - SampleIndexConfiguration actual = catalogManager.getStudyManager().get(studyId, null, sessionId).first().getInternal().getConfiguration().getVariantEngine().getSampleIndex(); + SampleIndexConfiguration actual = catalogManager.getStudyManager().get(organizationId, studyId, null, sessionId).first().getInternal().getConfiguration().getVariantEngine().getSampleIndex(); assertEquals(conf, actual); conf = getRandomConf(); result = variantManager.configureSampleIndex(studyId, conf, false, sessionId); assertEquals(1, result.getResults().size()); - actual = catalogManager.getStudyManager().get(studyId, null, sessionId).first().getInternal().getConfiguration().getVariantEngine().getSampleIndex(); + actual = catalogManager.getStudyManager().get(organizationId, studyId, null, sessionId).first().getInternal().getConfiguration().getVariantEngine().getSampleIndex(); assertEquals(conf, actual); } diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/AbstractVariantOperationManagerTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/AbstractVariantOperationManagerTest.java index b9f597c9b3d..a71b42ee175 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/AbstractVariantOperationManagerTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/AbstractVariantOperationManagerTest.java @@ -204,7 +204,7 @@ protected File create(String studyId, URI uri, String path) throws CatalogExcept } protected Cohort getDefaultCohort(String studyId) throws CatalogException { - return catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), + return catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), DEFAULT_COHORT), new QueryOptions(), sessionId).first(); } @@ -236,7 +236,7 @@ protected File transformFile(File inputFile, QueryOptions queryOptions, String o } finally { copyResults(Paths.get(tmpOutdir), studyId, outputId, sessionId); } - inputFile = catalogManager.getFileManager().get(studyId, inputFile.getId(), null, sessionId).first(); + inputFile = catalogManager.getFileManager().get(organizationId, studyId, inputFile.getId(), null, sessionId).first(); assertEquals(VariantIndexStatus.TRANSFORMED, inputFile.getInternal().getVariant().getIndex().getStatus().getId()); assertNotNull(inputFile.getQualityControl().getVariant().getVariantSetMetrics()); @@ -248,8 +248,8 @@ protected File transformFile(File inputFile, QueryOptions queryOptions, String o Query searchQuery = new Query(FileDBAdaptor.QueryParams.DIRECTORY.key(), outputId) .append(FileDBAdaptor.QueryParams.NAME.key(), "~" + inputFile.getName() + ".variants.(json|avro)"); - File transformedFile = catalogManager.getFileManager().search(studyId, searchQuery, new QueryOptions(), sessionId).first(); - inputFile = catalogManager.getFileManager().get(studyId, inputFile.getId(), null, sessionId).first(); + File transformedFile = catalogManager.getFileManager().search(organizationId, studyId, searchQuery, new QueryOptions(), sessionId).first(); + inputFile = catalogManager.getFileManager().get(organizationId, studyId, inputFile.getId(), null, sessionId).first(); System.out.println("transformedFile = " + transformedFile); List relatedFiles = transformedFile.getRelatedFiles().stream() @@ -344,12 +344,12 @@ protected List indexFiles(List files, List ex // Check transformed file relations for (File inputFile : expectedLoadedFiles) { - inputFile = catalogManager.getFileManager().get(studyId, inputFile.getId(), null, sessionId).first(); + inputFile = catalogManager.getFileManager().get(organizationId, studyId, inputFile.getId(), null, sessionId).first(); assertTrue(inputFile.getInternal().getVariant().getIndex().hasTransform()); assertNotNull(inputFile.getInternal().getVariant().getIndex().getTransform()); String transformedFileId = inputFile.getInternal().getVariant().getIndex().getTransform().getFileId(); - File transformedFile = catalogManager.getFileManager().get(studyId, transformedFileId, new QueryOptions(), sessionId).first(); + File transformedFile = catalogManager.getFileManager().get(organizationId, studyId, transformedFileId, new QueryOptions(), sessionId).first(); List relatedFiles = transformedFile.getRelatedFiles().stream() .filter(relatedFile -> relatedFile.getRelation().equals(FileRelatedFile.Relation.PRODUCED_FROM)) @@ -369,7 +369,7 @@ protected List indexFiles(List files, List ex */ protected List copyResults(Path tmpOutdirPath, String study, String catalogPathOutDir, String sessionId) throws CatalogException, IOException { - File outDir = catalogManager.getFileManager().get(study, catalogPathOutDir, new QueryOptions(), sessionId).first(); + File outDir = catalogManager.getFileManager().get(organizationId, study, catalogPathOutDir, new QueryOptions(), sessionId).first(); FileScanner fileScanner = new FileScanner(catalogManager); // CatalogIOManager ioManager = catalogManager.getCatalogIOManagerFactory().get(tmpOutdirPath.toUri()); @@ -407,17 +407,17 @@ protected List copyResults(Path tmpOutdirPath, String study, String catalo protected void checkEtlResults(String studyId, List etlResults, String expectedStatus) throws CatalogException { for (StoragePipelineResult etlResult : etlResults) { - File input = catalogManager.getFileManager().search(studyId, new Query(FileDBAdaptor.QueryParams.URI.key(), + File input = catalogManager.getFileManager().search(organizationId, studyId, new Query(FileDBAdaptor.QueryParams.URI.key(), etlResult.getInput()), null, sessionId).first(); String indexedFileId; if (input.getRelatedFiles().isEmpty()) { indexedFileId = input.getId(); } else { long indexedFileUid = input.getRelatedFiles().get(0).getFile().getUid(); - indexedFileId = catalogManager.getFileManager().search(studyId, new Query(FileDBAdaptor.QueryParams.UID.key(), + indexedFileId = catalogManager.getFileManager().search(organizationId, studyId, new Query(FileDBAdaptor.QueryParams.UID.key(), indexedFileUid), new QueryOptions(), sessionId).first().getId(); } - assertEquals(expectedStatus, catalogManager.getFileManager().get(studyId, indexedFileId, null, sessionId).first() + assertEquals(expectedStatus, catalogManager.getFileManager().get(organizationId, studyId, indexedFileId, null, sessionId).first() .getInternal().getVariant().getIndex().getStatus().getId()); System.out.println("etlResult = " + etlResult); } diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/PlatinumFileIndexerTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/PlatinumFileIndexerTest.java index f6082bea5d2..e8355bae92f 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/PlatinumFileIndexerTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/PlatinumFileIndexerTest.java @@ -126,12 +126,12 @@ public void testByStepsMultiRelease() throws Exception { transformFile = transformFile(inputFile, new QueryOptions()); loadFile(transformFile, new QueryOptions(), outputId); - opencga.getCatalogManager().getProjectManager().incrementRelease(projectId, sessionId); + opencga.getCatalogManager().getProjectManager().incrementRelease(organizationId, projectId, sessionId); } int i = 1; for (File inputFile : inputFiles) { - inputFile = opencga.getCatalogManager().getFileManager().get(studyId, inputFile.getId(), null, sessionId).first(); + inputFile = opencga.getCatalogManager().getFileManager().get(organizationId, studyId, inputFile.getId(), null, sessionId).first(); assertEquals(1, inputFile.getRelease()); assertEquals(i, inputFile.getInternal().getVariant().getIndex().getRelease()); i++; @@ -171,7 +171,7 @@ public void testBatchFromDirectory() throws Exception { files.add(create(name)); } - File directory = catalogManager.getFileManager().get("" + studyId, "data/vcfs/", null, sessionId).first(); + File directory = catalogManager.getFileManager().get(organizationId, "" + studyId, "data/vcfs/", null, sessionId).first(); List results = indexFiles(Collections.singletonList(directory), files, new QueryOptions(), outputId); List fileNames = results.stream().map(StoragePipelineResult::getInput).map(URI::toString).collect(Collectors.toList()); diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/RemoveVariantsTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/RemoveVariantsTest.java index 0473d55a031..4f10494a290 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/RemoveVariantsTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/RemoveVariantsTest.java @@ -131,12 +131,12 @@ private void removeFile(List files, QueryOptions options) throws Exception variantManager.removeFile(studyId, fileIds, new QueryOptions(), outdir.toUri(), sessionId); // assertEquals(files.size(), removedFiles.size()); - Cohort all = catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), + Cohort all = catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), StudyEntry.DEFAULT_COHORT), null, sessionId).first(); Set allSampleIds = all.getSamples().stream().map(Sample::getId).collect(Collectors.toSet()); assertThat(all.getInternal().getStatus().getId(), anyOf(is(CohortStatus.INVALID), is(CohortStatus.NONE))); - Set loadedSamples = catalogManager.getFileManager().search(studyId, new Query(FileDBAdaptor.QueryParams.INTERNAL_VARIANT_INDEX_STATUS_ID.key + Set loadedSamples = catalogManager.getFileManager().search(organizationId, studyId, new Query(FileDBAdaptor.QueryParams.INTERNAL_VARIANT_INDEX_STATUS_ID.key (), VariantIndexStatus.READY), null, sessionId) .getResults() .stream() @@ -145,7 +145,7 @@ private void removeFile(List files, QueryOptions options) throws Exception assertEquals(loadedSamples, allSampleIds); for (String file : fileIds) { - assertEquals(VariantIndexStatus.TRANSFORMED, catalogManager.getFileManager().get(studyId, file, null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + assertEquals(VariantIndexStatus.TRANSFORMED, catalogManager.getFileManager().get(organizationId, studyId, file, null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); } } @@ -155,9 +155,9 @@ private void removeStudy(Object study, QueryOptions options) throws Exception { variantManager.removeStudy(study.toString(), options, outdir.toUri(), sessionId); Query query = new Query(FileDBAdaptor.QueryParams.INTERNAL_VARIANT_INDEX_STATUS_ID.key(), VariantIndexStatus.READY); - assertEquals(0L, catalogManager.getFileManager().count(study.toString(), query, sessionId).getNumTotalResults()); + assertEquals(0L, catalogManager.getFileManager().count(organizationId, study.toString(), query, sessionId).getNumTotalResults()); - Cohort all = catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), StudyEntry.DEFAULT_COHORT), null, sessionId).first(); + Cohort all = catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), StudyEntry.DEFAULT_COHORT), null, sessionId).first(); assertTrue(all.getSamples().isEmpty()); } diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/StatsVariantStorageTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/StatsVariantStorageTest.java index 09bcacc2ff7..9cdbce24cbe 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/StatsVariantStorageTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/StatsVariantStorageTest.java @@ -102,7 +102,7 @@ public void before () throws Exception { QueryOptions queryOptions = new QueryOptions(VariantStorageOptions.ANNOTATE.key(), false); variantManager.index(studyId, file.getId(), createTmpOutdir(file), queryOptions, sessionId); - all = catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), + all = catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), DEFAULT_COHORT), new QueryOptions(), sessionId).first().getId(); } @@ -116,7 +116,7 @@ public File beforeAggregated(String fileName, Aggregation aggregation) throws Ex } StudyUpdateParams updateParams = new StudyUpdateParams() .setAttributes(attributes); - catalogManager.getStudyManager().update(studyId, updateParams, null, sessionId); + catalogManager.getStudyManager().update(organizationId, studyId, updateParams, null, sessionId); File file1 = opencga.createFile(studyId, fileName, sessionId); @@ -141,12 +141,12 @@ public static List createCohorts(String sessionId, String studyId, Strin List queryResults = new ArrayList<>(); Properties tagmap = new Properties(); tagmap.load(new FileInputStream(tagmapPath)); - Map cohorts = catalogManager.getCohortManager().search(studyId, new Query(), null, sessionId) + Map cohorts = catalogManager.getCohortManager().search(organizationId, studyId, new Query(), null, sessionId) .getResults().stream().collect(Collectors.toMap(Cohort::getId, c->c)); Set catalogCohorts = cohorts.keySet(); for (String cohortName : VariantAggregatedStatsCalculator.getCohorts(tagmap)) { if (!catalogCohorts.contains(cohortName)) { - DataResult cohort = catalogManager.getCohortManager().create(studyId, new Cohort() + DataResult cohort = catalogManager.getCohortManager().create(organizationId, studyId, new Cohort() .setId(cohortName) .setSamples(Collections.emptyList()) .setType(Enums.CohortType.COLLECTION), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId); @@ -176,26 +176,26 @@ public void testCalculateStatsOneByOne() throws Exception { Map cohorts = new HashMap<>(); calculateStats(coh[0]); - cohorts.put(coh[0], catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first()); + cohorts.put(coh[0], catalogManager.getCohortManager().get(organizationId, studyId, coh[0], null, sessionId).first()); // cohorts.put("all", null); checkCalculatedStats(cohorts); // Job job = variantStorage.calculateStats(outputId, Collections.singletonList(coh1), sessionId, new QueryOptions(ExecutorFactory.EXECUTE, true)).first(); // assertEquals(Status.READY, job.getStatus().getName()); - cohorts.put(coh[1], catalogManager.getCohortManager().get(studyId, coh[1], null, sessionId).first()); + cohorts.put(coh[1], catalogManager.getCohortManager().get(organizationId, studyId, coh[1], null, sessionId).first()); calculateStats(coh[1]); checkCalculatedStats(cohorts); calculateStats(coh[2]); - cohorts.put(coh[2], catalogManager.getCohortManager().get(studyId, coh[2], null, sessionId).first()); + cohorts.put(coh[2], catalogManager.getCohortManager().get(organizationId, studyId, coh[2], null, sessionId).first()); checkCalculatedStats(cohorts); calculateStats(coh[3]); - cohorts.put(coh[3], catalogManager.getCohortManager().get(studyId, coh[3], null, sessionId).first()); + cohorts.put(coh[3], catalogManager.getCohortManager().get(organizationId, studyId, coh[3], null, sessionId).first()); checkCalculatedStats(cohorts); calculateStats(coh[4]); - cohorts.put(coh[4], catalogManager.getCohortManager().get(studyId, coh[4], null, sessionId).first()); + cohorts.put(coh[4], catalogManager.getCohortManager().get(organizationId, studyId, coh[4], null, sessionId).first()); checkCalculatedStats(cohorts); } @@ -222,9 +222,9 @@ public void testCalculateStatsGroups() throws Exception { Map cohorts = new HashMap<>(); calculateStats(new VariantStatsIndexParams().setCohort(Arrays.asList(coh[0], coh[1], coh[2]))); - cohorts.put(coh[0], catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first()); - cohorts.put(coh[1], catalogManager.getCohortManager().get(studyId, coh[1], null, sessionId).first()); - cohorts.put(coh[2], catalogManager.getCohortManager().get(studyId, coh[2], null, sessionId).first()); + cohorts.put(coh[0], catalogManager.getCohortManager().get(organizationId, studyId, coh[0], null, sessionId).first()); + cohorts.put(coh[1], catalogManager.getCohortManager().get(organizationId, studyId, coh[1], null, sessionId).first()); + cohorts.put(coh[2], catalogManager.getCohortManager().get(organizationId, studyId, coh[2], null, sessionId).first()); checkCalculatedStats(cohorts); try { @@ -233,15 +233,15 @@ public void testCalculateStatsGroups() throws Exception { } catch (ToolException e) { logger.info("received expected exception. this is OK, there is no cohort " + ("-" + coh[4]) + '\n'); } - assertEquals(CohortStatus.NONE, catalogManager.getCohortManager().get(studyId, "ALL", null, sessionId).first().getInternal().getStatus().getId()); - assertEquals(CohortStatus.NONE, catalogManager.getCohortManager().get(studyId, coh[3], null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(CohortStatus.NONE, catalogManager.getCohortManager().get(organizationId, studyId, "ALL", null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(CohortStatus.NONE, catalogManager.getCohortManager().get(organizationId, studyId, coh[3], null, sessionId).first().getInternal().getStatus().getId()); - assertEquals(CohortStatus.NONE, catalogManager.getCohortManager().get(studyId, coh[4], null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(CohortStatus.NONE, catalogManager.getCohortManager().get(organizationId, studyId, coh[4], null, sessionId).first().getInternal().getStatus().getId()); calculateStats(new VariantStatsIndexParams().setCohort(Arrays.asList(all, coh[3], coh[4]))); - cohorts.put(DEFAULT_COHORT, catalogManager.getCohortManager().get(studyId, DEFAULT_COHORT, null, sessionId).first()); - cohorts.put(coh[3], catalogManager.getCohortManager().get(studyId, coh[3], null, sessionId).first()); - cohorts.put(coh[4], catalogManager.getCohortManager().get(studyId, coh[4], null, sessionId).first()); + cohorts.put(DEFAULT_COHORT, catalogManager.getCohortManager().get(organizationId, studyId, DEFAULT_COHORT, null, sessionId).first()); + cohorts.put(coh[3], catalogManager.getCohortManager().get(organizationId, studyId, coh[3], null, sessionId).first()); + cohorts.put(coh[4], catalogManager.getCohortManager().get(organizationId, studyId, coh[4], null, sessionId).first()); checkCalculatedStats(cohorts); } @@ -250,34 +250,34 @@ public void testCalculateStats() throws Exception { before(); - assertEquals(CohortStatus.NONE, catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(CohortStatus.NONE, catalogManager.getCohortManager().get(organizationId, studyId, coh[0], null, sessionId).first().getInternal().getStatus().getId()); calculateStats(coh[0]); // TODO: Check status "CALCULATING" // Job job = variantStorage.calculateStats(outputId, Collections.singletonList(coh0), sessionId, new QueryOptions()).first(); // assertEquals(Cohort.CohortStatus.CALCULATING, catalogManager.getCohort(coh0, null, sessionId).first().getStatus().getName()); // runStorageJob(job, sessionId); - assertEquals(CohortStatus.READY, catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(CohortStatus.READY, catalogManager.getCohortManager().get(organizationId, studyId, coh[0], null, sessionId).first().getInternal().getStatus().getId()); Map cohorts = new HashMap<>(); - cohorts.put("coh0", catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first()); + cohorts.put("coh0", catalogManager.getCohortManager().get(organizationId, studyId, coh[0], null, sessionId).first()); checkCalculatedStats(cohorts); catalogManager.getCohortManager().update(studyId, coh[0], new CohortUpdateParams().setDescription("NewDescription"), new QueryOptions(), sessionId); - assertEquals(CohortStatus.READY, catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(CohortStatus.READY, catalogManager.getCohortManager().get(organizationId, studyId, coh[0], null, sessionId).first().getInternal().getStatus().getId()); - List newCohort = catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first().getSamples().stream() + List newCohort = catalogManager.getCohortManager().get(organizationId, studyId, coh[0], null, sessionId).first().getSamples().stream() .map(s -> new SampleReferenceParam().setId(s.getId())) .skip(10).limit(100) .collect(Collectors.toList()); catalogManager.getCohortManager().update(studyId, coh[0], new CohortUpdateParams().setSamples(newCohort), new QueryOptions(Constants.ACTIONS, Collections.singletonMap(SAMPLES.key(), ParamUtils.BasicUpdateAction.SET)), sessionId); - assertEquals(CohortStatus.INVALID, catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(CohortStatus.INVALID, catalogManager.getCohortManager().get(organizationId, studyId, coh[0], null, sessionId).first().getInternal().getStatus().getId()); calculateStats(coh[0]); - assertEquals(CohortStatus.READY, catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first().getInternal().getStatus().getId()); - cohorts.put("coh0", catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first()); + assertEquals(CohortStatus.READY, catalogManager.getCohortManager().get(organizationId, studyId, coh[0], null, sessionId).first().getInternal().getStatus().getId()); + cohorts.put("coh0", catalogManager.getCohortManager().get(organizationId, studyId, coh[0], null, sessionId).first()); checkCalculatedStats(cohorts); } @@ -300,7 +300,7 @@ public void testCalculateInvalidStats() throws Exception { assertEquals(message, e.getCause().getCause().getMessage()); } - Cohort coh1 = catalogManager.getCohortManager().get(studyId, coh[1], null, sessionId).first(); + Cohort coh1 = catalogManager.getCohortManager().get(organizationId, studyId, coh[1], null, sessionId).first(); assertEquals(CohortStatus.INVALID, coh1.getInternal().getStatus().getId()); vsm = mockVariantStorageManager(); @@ -314,7 +314,7 @@ public void testResumeCalculateStats() throws Exception { calculateStats(coh[0]); catalogManager.getCohortManager().setStatus(studyId, coh[1], CohortStatus.CALCULATING, "", sessionId); - Cohort coh1 = catalogManager.getCohortManager().get(studyId, coh[1], null, sessionId).first(); + Cohort coh1 = catalogManager.getCohortManager().get(organizationId, studyId, coh[1], null, sessionId).first(); Exception expected = VariantStatsOperationManager.unableToCalculateCohortCalculating(coh1); try { calculateStats(coh[1]); @@ -351,7 +351,7 @@ public void testCalculateAggregatedStatsNonAggregatedStudy() throws Exception { calculateAggregatedStats(new VariantStatsIndexParams().setAggregated(Aggregation.BASIC)); - Study study = catalogManager.getStudyManager().get(studyId, null, sessionId).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyId, null, sessionId).first(); String agg = study.getAttributes().get(VariantStatsAnalysis.STATS_AGGREGATION_CATALOG).toString(); assertNotNull(agg); @@ -360,7 +360,7 @@ public void testCalculateAggregatedStatsNonAggregatedStudy() throws Exception { public void calculateAggregatedStats(VariantStatsIndexParams params) throws Exception { // coh0 = catalogManager.createCohort(studyId, "ALL", Cohort.Type.COLLECTION, "", file.getSampleIds(), null, sessionId).first().getId(); - String cohId = catalogManager.getCohortManager().search(studyId, (Query) null, null, sessionId).first().getId(); + String cohId = catalogManager.getCohortManager().search(organizationId, studyId, (Query) null, null, sessionId).first().getId(); calculateStats(params.setCohort(Collections.singletonList(cohId))); @@ -377,7 +377,7 @@ public void testCalculateAggregatedExacStats() throws Exception { calculateStats(new VariantStatsIndexParams().setCohort(cohortIds).setAggregationMappingFile("exac-tag-mapping.properties")); - List cohorts = catalogManager.getCohortManager().search(studyId, (Query) null, null, sessionId).getResults(); + List cohorts = catalogManager.getCohortManager().search(organizationId, studyId, (Query) null, null, sessionId).getResults(); Set cohortNames = cohorts .stream() .map(Cohort::getId) @@ -399,7 +399,7 @@ public void testCalculateAggregatedExacStatsExplicitCohorts() throws Exception { .setCohort(Arrays.asList("AFR", "ALL", "AMR", "EAS", "FIN", "NFE", "OTH", "SAS")) .setAggregationMappingFile("exac-tag-mapping.properties")); - List cohorts = catalogManager.getCohortManager().search(studyId, (Query) null, null, sessionId).getResults(); + List cohorts = catalogManager.getCohortManager().search(organizationId, studyId, (Query) null, null, sessionId).getResults(); Set cohortNames = cohorts .stream() .map(Cohort::getId) @@ -449,7 +449,7 @@ public void testCalculateAggregatedExacStatsWithoutCohorts() throws Exception { linkFile("exac-tag-mapping.properties"); calculateStats(new VariantStatsIndexParams().setAggregationMappingFile("exac-tag-mapping.properties")); - List cohorts = catalogManager.getCohortManager().search(studyId, (Query) null, null, sessionId).getResults(); + List cohorts = catalogManager.getCohortManager().search(organizationId, studyId, (Query) null, null, sessionId).getResults(); Set cohortNames = cohorts .stream() .map(Cohort::getId) @@ -490,7 +490,7 @@ public static void checkCalculatedStats(String studyId, Map coho } } for (Cohort cohort : cohorts.values()) { - cohort = catalogManager.getCohortManager().get(studyId, cohort.getId(), null, sessionId).first(); + cohort = catalogManager.getCohortManager().get(organizationId, studyId, cohort.getId(), null, sessionId).first(); assertEquals(CohortStatus.READY, cohort.getInternal().getStatus().getId()); } } diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantFileIndexSameNameTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantFileIndexSameNameTest.java index caa51553e01..c3acef68f24 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantFileIndexSameNameTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantFileIndexSameNameTest.java @@ -67,15 +67,15 @@ public void before() throws Exception { @Test public void testIndex1() throws Exception { indexFile(inputFile1, new QueryOptions(), outputId); - Assert.assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(studyId, inputFile1.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); - Assert.assertEquals(VariantIndexStatus.NONE, catalogManager.getFileManager().get(studyId, inputFile2.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + Assert.assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(organizationId, studyId, inputFile1.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + Assert.assertEquals(VariantIndexStatus.NONE, catalogManager.getFileManager().get(organizationId, studyId, inputFile2.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); } @Test public void testIndex2() throws Exception { indexFile(inputFile2, new QueryOptions(), outputId); - Assert.assertEquals(VariantIndexStatus.NONE, catalogManager.getFileManager().get(studyId, inputFile1.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); - Assert.assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(studyId, inputFile2.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + Assert.assertEquals(VariantIndexStatus.NONE, catalogManager.getFileManager().get(organizationId, studyId, inputFile1.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + Assert.assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(organizationId, studyId, inputFile2.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); } @Test @@ -132,20 +132,20 @@ public void testIndexBothSameTime() throws Exception { @Test public void testBySteps1() throws Exception { File transformFile = transformFile(inputFile1, new QueryOptions()); - Assert.assertEquals(VariantIndexStatus.TRANSFORMED, catalogManager.getFileManager().get(studyId, inputFile1.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); - Assert.assertEquals(VariantIndexStatus.NONE, catalogManager.getFileManager().get(studyId, inputFile2.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + Assert.assertEquals(VariantIndexStatus.TRANSFORMED, catalogManager.getFileManager().get(organizationId, studyId, inputFile1.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + Assert.assertEquals(VariantIndexStatus.NONE, catalogManager.getFileManager().get(organizationId, studyId, inputFile2.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); loadFile(transformFile, new QueryOptions(), outputId); - Assert.assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(studyId, inputFile1.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); - Assert.assertEquals(VariantIndexStatus.NONE, catalogManager.getFileManager().get(studyId, inputFile2.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + Assert.assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(organizationId, studyId, inputFile1.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + Assert.assertEquals(VariantIndexStatus.NONE, catalogManager.getFileManager().get(organizationId, studyId, inputFile2.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); } @Test public void testBySteps2() throws Exception { File transformFile = transformFile(inputFile2, new QueryOptions()); - Assert.assertEquals(VariantIndexStatus.NONE, catalogManager.getFileManager().get(studyId, inputFile1.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); - Assert.assertEquals(VariantIndexStatus.TRANSFORMED, catalogManager.getFileManager().get(studyId, inputFile2.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + Assert.assertEquals(VariantIndexStatus.NONE, catalogManager.getFileManager().get(organizationId, studyId, inputFile1.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + Assert.assertEquals(VariantIndexStatus.TRANSFORMED, catalogManager.getFileManager().get(organizationId, studyId, inputFile2.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); loadFile(transformFile, new QueryOptions(), outputId); - Assert.assertEquals(VariantIndexStatus.NONE, catalogManager.getFileManager().get(studyId, inputFile1.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); - Assert.assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(studyId, inputFile2.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + Assert.assertEquals(VariantIndexStatus.NONE, catalogManager.getFileManager().get(organizationId, studyId, inputFile1.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + Assert.assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(organizationId, studyId, inputFile2.getPath(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); } } diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantFileIndexerOperationManagerTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantFileIndexerOperationManagerTest.java index 8eaddc3eba8..090d27fe4d0 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantFileIndexerOperationManagerTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantFileIndexerOperationManagerTest.java @@ -30,7 +30,6 @@ import org.opencb.commons.datastore.core.Event; import org.opencb.commons.datastore.core.Query; import org.opencb.commons.datastore.core.QueryOptions; -import org.opencb.opencga.analysis.file.FileDeleteTask; import org.opencb.opencga.analysis.tools.ToolRunner; import org.opencb.opencga.analysis.variant.operations.VariantIndexOperationTool; import org.opencb.opencga.catalog.db.api.CohortDBAdaptor; @@ -47,7 +46,6 @@ import org.opencb.opencga.core.models.study.Study; import org.opencb.opencga.core.models.variant.VariantIndexParams; import org.opencb.opencga.core.testclassification.duration.MediumTests; -import org.opencb.opencga.core.tools.annotations.Tool; import org.opencb.opencga.core.tools.result.ExecutionResult; import org.opencb.opencga.storage.core.StorageEngineFactory; import org.opencb.opencga.storage.core.StoragePipelineResult; @@ -106,7 +104,7 @@ public void testIndexWithStats() throws Exception { variantManager.index(studyId, getFile(2).getId(), newTmpOutdir(), queryOptions, sessionId); assertEquals(1500, getDefaultCohort(studyId).getSamples().size()); assertEquals(CohortStatus.READY, getDefaultCohort(studyId).getInternal().getStatus().getId()); - checkCalculatedStats(studyId, Collections.singletonMap(DEFAULT_COHORT, catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), DEFAULT_COHORT), new QueryOptions(), sessionId).first()), catalogManager, + checkCalculatedStats(studyId, Collections.singletonMap(DEFAULT_COHORT, catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), DEFAULT_COHORT), new QueryOptions(), sessionId).first()), catalogManager, dbName, sessionId); assertNotNull(getVariantSetMetrics(getFile(2).getId())); @@ -121,12 +119,12 @@ public void testIndexWithStats() throws Exception { assertEquals(2504, getDefaultCohort(studyId).getSamples().size()); assertEquals(CohortStatus.READY, getDefaultCohort(studyId).getInternal().getStatus().getId()); assertNotNull(getVariantSetMetrics(getFile(4).getId())); - checkCalculatedStats(studyId, Collections.singletonMap(DEFAULT_COHORT, catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), DEFAULT_COHORT), new QueryOptions(), sessionId).first()), catalogManager, + checkCalculatedStats(studyId, Collections.singletonMap(DEFAULT_COHORT, catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), DEFAULT_COHORT), new QueryOptions(), sessionId).first()), catalogManager, dbName, sessionId); } private VariantSetStats getVariantSetMetrics(String fileId) throws CatalogException { - return catalogManager.getFileManager().get(studyId, fileId, null, sessionId).first().getQualityControl().getVariant().getVariantSetMetrics(); + return catalogManager.getFileManager().get(organizationId, studyId, fileId, null, sessionId).first().getQualityControl().getVariant().getVariantSetMetrics(); } @Test @@ -155,7 +153,7 @@ public void testIndexWithStatsWrongAggregationType() throws Exception { } catch (Exception e) { assertEquals(0, getDefaultCohort(studyId).getSamples().size()); assertEquals(CohortStatus.NONE, getDefaultCohort(studyId).getInternal().getStatus().getId()); - assertEquals(VariantIndexStatus.NONE, catalogManager.getFileManager().get(studyId, getFile(0).getId(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + assertEquals(VariantIndexStatus.NONE, catalogManager.getFileManager().get(organizationId, studyId, getFile(0).getId(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); assertNull(getVariantSetMetrics(getFile(0).getId())); } queryOptions.put(VariantStorageOptions.STATS_AGGREGATION.key(), "none"); @@ -202,7 +200,7 @@ public void testDeleteSampleFromIndexedFile() throws Exception { Query query = new Query(SampleDBAdaptor.QueryParams.ID.key(), inputFile.getSampleIds().get(100)); thrown.expect(CatalogException.class); thrown.expectMessage("Sample associated to the files"); - DataResult delete = catalogManager.getSampleManager().delete(studyFqn, query, null, sessionId); + DataResult delete = catalogManager.getSampleManager().delete(organizationId, studyFqn, query, null, sessionId); } @Test @@ -212,7 +210,7 @@ public void testIndexFromFolder() throws Exception { File file = getFile(0); Path pathParent = Paths.get(file.getPath()).getParent(); - File parent = catalogManager.getFileManager().search(studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), pathParent.toString() + "/"), null, sessionId).first(); + File parent = catalogManager.getFileManager().search(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), pathParent.toString() + "/"), null, sessionId).first(); indexFiles(singletonList(parent), singletonList(file), queryOptions, outputId); } @@ -234,10 +232,10 @@ public void testDeleteTransformedFile() throws Exception { File inputFile = getFile(0); File transformedFile = transformFile(inputFile, queryOptions); - catalogManager.getFileManager().delete(studyFqn, + catalogManager.getFileManager().delete(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.NAME.key(), transformedFile.getName()), new QueryOptions(Constants.SKIP_TRASH, true), sessionId); - catalogManager.getFileManager().delete(studyFqn, new Query(FileDBAdaptor.QueryParams.NAME.key(), + catalogManager.getFileManager().delete(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.NAME.key(), VariantReaderUtils.getMetaFromTransformedFile(transformedFile.getName())), new QueryOptions(Constants.SKIP_TRASH, true), sessionId); @@ -263,7 +261,7 @@ public void testDeleteCohortWithStats() throws Exception { thrown.expect(CatalogException.class); thrown.expectMessage("ALL cannot be deleted"); - catalogManager.getCohortManager().delete(studyFqn, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId); + catalogManager.getCohortManager().delete(organizationId, studyFqn, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId); } @Test diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantImportTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantImportTest.java index 124e6d9b558..2cd0a90fd76 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantImportTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantImportTest.java @@ -62,7 +62,7 @@ public void setUp() throws Exception { indexFile(getSmallFile(), new QueryOptions(VariantStorageOptions.STATS_CALCULATE.key(), true), outputId); - catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, Arrays.asList( + catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, Arrays.asList( new Variable("name", "", "", Variable.VariableType.STRING, null, true, false, null, null, 0, null, null, null, null), new Variable("age", "", "", Variable.VariableType.INTEGER, null, true, false, null, null, 0, null, null, null, null), new Variable("other", "", "", Variable.VariableType.STRING, "unknown", false, false, null, null, 0, null, null, null, null)), @@ -99,7 +99,7 @@ public void testExportSomeSamplesImport() throws Exception { String export = Paths.get(opencga.createTmpOutdir(studyId, "_EXPORT_", sessionId)).resolve("export.avro").toString(); - List samples = catalogManager.getSampleManager().search(studyId, new Query(), new QueryOptions(), sessionId).getResults(); + List samples = catalogManager.getSampleManager().search(organizationId, studyId, new Query(), new QueryOptions(), sessionId).getResults(); List someSamples = samples.stream().limit(samples.size() / 2).map(Sample::getId).collect(Collectors.toList()); Query query = new Query(VariantQueryParam.INCLUDE_STUDY.key(), studyId) .append(VariantQueryParam.INCLUDE_SAMPLE.key(), someSamples); diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantVirtualFileIndexTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantVirtualFileIndexTest.java index 594e86af3dd..f09c23ed42b 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantVirtualFileIndexTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/manager/operations/VariantVirtualFileIndexTest.java @@ -82,11 +82,11 @@ public void testIndexVirtual() throws Exception { .setLoadSplitData("REGION") , new ObjectMap(ParamConstants.STUDY_PARAM, studyId), Paths.get(opencga.createTmpOutdir()), null, sessionId); - File file = catalogManager.getFileManager().get(studyId, "chr20.variant-test-file.vcf.gz", null, sessionId).first(); + File file = catalogManager.getFileManager().get(organizationId, studyId, "chr20.variant-test-file.vcf.gz", null, sessionId).first(); assertTrue(FileUtils.isPartial(file)); assertEquals("READY", file.getInternal().getVariant().getIndex().getStatus().getId()); - file = catalogManager.getFileManager().get(studyId, "variant-test-file.vcf", null, sessionId).first(); + file = catalogManager.getFileManager().get(organizationId, studyId, "variant-test-file.vcf", null, sessionId).first(); assertFalse(FileUtils.isPartial(file)); assertEquals(File.Type.VIRTUAL, file.getType()); assertEquals("READY", file.getInternal().getVariant().getIndex().getStatus().getId()); diff --git a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/metadata/CatalogStorageMetadataSynchronizerTest.java b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/metadata/CatalogStorageMetadataSynchronizerTest.java index fad5fb53ded..42e0caa9c12 100644 --- a/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/metadata/CatalogStorageMetadataSynchronizerTest.java +++ b/opencga-analysis/src/test/java/org/opencb/opencga/analysis/variant/metadata/CatalogStorageMetadataSynchronizerTest.java @@ -120,7 +120,7 @@ public static void beforeClass() throws Exception { @Before public void setUp() throws Exception { metadataManager = new VariantStorageMetadataManager(new DummyVariantStorageMetadataDBAdaptorFactory()); - Study study = catalogManager.getStudyManager().get(studyId, null, sessionId).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyId, null, sessionId).first(); StudyMetadata studyMetadata = metadataManager.createStudy(study.getFqn()); for (File file : files) { @@ -158,7 +158,7 @@ public static File create(String resourceName, boolean indexed) throws IOExcepti catalogManager.getCohortManager().update(studyId, cohortId, new CohortUpdateParams().setSamples(sampleReferenceParams), true, null, sessionId); } - return catalogManager.getFileManager().get(studyId, file.getId(), null, sessionId).first(); + return catalogManager.getFileManager().get(organizationId, studyId, file.getId(), null, sessionId).first(); } @Test @@ -183,7 +183,7 @@ public void updateCatalogFromStorageTest() throws Exception { studyConfigurationFactory.synchronizeCatalogStudyFromStorage(sm, sessionId); - nonIndexedFile = catalogManager.getFileManager().get(studyId, nonIndexedFile.getName(), null, sessionId).first(); + nonIndexedFile = catalogManager.getFileManager().get(organizationId, studyId, nonIndexedFile.getName(), null, sessionId).first(); assertEquals(VariantIndexStatus.READY, nonIndexedFile.getInternal().getVariant().getIndex().getStatus().getId()); @@ -193,7 +193,7 @@ public void updateCatalogFromStorageTest() throws Exception { studyConfigurationFactory.synchronizeCatalogStudyFromStorage(sm, sessionId); - nonIndexedFile = catalogManager.getFileManager().get(studyId, nonIndexedFile.getName(), null, sessionId).first(); + nonIndexedFile = catalogManager.getFileManager().get(organizationId, studyId, nonIndexedFile.getName(), null, sessionId).first(); assertEquals(VariantIndexStatus.INDEXING, nonIndexedFile.getInternal().getVariant().getIndex().getStatus().getId()); } @@ -202,13 +202,13 @@ public void updateCatalogFromStorageTest() throws Exception { public void testInternalSampleStatuses() throws Exception { StudyMetadata sm = studyConfigurationFactory.getStudyMetadata(studyId); String fileName = indexedFiles.iterator().next(); - String sampleName = catalogManager.getFileManager().get(studyId, fileName, null, sessionId).first().getSampleIds().get(0); + String sampleName = catalogManager.getFileManager().get(organizationId, studyId, fileName, null, sessionId).first().getSampleIds().get(0); int version = sm.getSampleIndexConfigurationLatest().getVersion(); Sample sample; //-------------- studyConfigurationFactory.synchronizeCatalogStudyFromStorage(sm, sessionId); - sample = catalogManager.getSampleManager().get(studyId, sampleName, null, sessionId).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyId, sampleName, null, sessionId).first(); assertEquals(IndexStatus.READY, secureGet(sample, s -> s.getInternal().getVariant().getIndex().getStatus().getId(), null)); assertEquals(IndexStatus.NONE, secureGet(sample, s->s.getInternal().getVariant().getAnnotationIndex().getStatus().getId(), null)); @@ -219,7 +219,7 @@ public void testInternalSampleStatuses() throws Exception { metadataManager.updateSampleMetadata(sm.getId(), metadataManager.getSampleId(sm.getId(), sampleName), s -> s.setAnnotationStatus(TaskMetadata.Status.READY)); studyConfigurationFactory.synchronizeCatalogStudyFromStorage(sm, sessionId); - sample = catalogManager.getSampleManager().get(studyId, sampleName, null, sessionId).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyId, sampleName, null, sessionId).first(); assertEquals(IndexStatus.READY, secureGet(sample, s->s.getInternal().getVariant().getIndex().getStatus().getId(), null)); assertEquals(IndexStatus.READY, secureGet(sample, s->s.getInternal().getVariant().getAnnotationIndex().getStatus().getId(), null)); assertEquals(IndexStatus.NONE, secureGet(sample, s->s.getInternal().getVariant().getSecondarySampleIndex().getStatus().getId(), null)); @@ -229,7 +229,7 @@ public void testInternalSampleStatuses() throws Exception { metadataManager.updateSampleMetadata(sm.getId(), metadataManager.getSampleId(sm.getId(), sampleName), s -> s.setSampleIndexStatus(TaskMetadata.Status.READY, version)); studyConfigurationFactory.synchronizeCatalogStudyFromStorage(sm, sessionId); - sample = catalogManager.getSampleManager().get(studyId, sampleName, null, sessionId).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyId, sampleName, null, sessionId).first(); assertEquals(IndexStatus.READY, secureGet(sample, s->s.getInternal().getVariant().getIndex().getStatus().getId(), null)); assertEquals(IndexStatus.READY, secureGet(sample, s->s.getInternal().getVariant().getAnnotationIndex().getStatus().getId(), null)); assertEquals(IndexStatus.NONE, secureGet(sample, s->s.getInternal().getVariant().getSecondarySampleIndex().getStatus().getId(), null)); @@ -240,7 +240,7 @@ public void testInternalSampleStatuses() throws Exception { metadataManager.updateSampleMetadata(sm.getId(), metadataManager.getSampleId(sm.getId(), sampleName), s -> s.setSampleIndexAnnotationStatus(TaskMetadata.Status.READY, version)); studyConfigurationFactory.synchronizeCatalogStudyFromStorage(sm, sessionId); - sample = catalogManager.getSampleManager().get(studyId, sampleName, null, sessionId).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyId, sampleName, null, sessionId).first(); assertEquals(IndexStatus.READY, secureGet(sample, s->s.getInternal().getVariant().getIndex().getStatus().getId(), null)); assertEquals(IndexStatus.READY, secureGet(sample, s->s.getInternal().getVariant().getAnnotationIndex().getStatus().getId(), null)); assertEquals(IndexStatus.READY, secureGet(sample, s->s.getInternal().getVariant().getSecondarySampleIndex().getStatus().getId(), null)); @@ -250,7 +250,7 @@ public void testInternalSampleStatuses() throws Exception { metadataManager.updateSampleMetadata(sm.getId(), metadataManager.getSampleId(sm.getId(), sampleName), s -> s.setFamilyIndexStatus(TaskMetadata.Status.READY, version)); studyConfigurationFactory.synchronizeCatalogStudyFromStorage(sm, sessionId); - sample = catalogManager.getSampleManager().get(studyId, sampleName, null, sessionId).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyId, sampleName, null, sessionId).first(); assertEquals(IndexStatus.READY, secureGet(sample, s->s.getInternal().getVariant().getIndex().getStatus().getId(), null)); assertEquals(IndexStatus.READY, secureGet(sample, s->s.getInternal().getVariant().getAnnotationIndex().getStatus().getId(), null)); assertEquals(IndexStatus.READY, secureGet(sample, s->s.getInternal().getVariant().getSecondarySampleIndex().getStatus().getId(), null)); @@ -265,7 +265,7 @@ public void testInternalSampleStatuses() throws Exception { }); studyConfigurationFactory.synchronizeCatalogStudyFromStorage(sm, sessionId); - sample = catalogManager.getSampleManager().get(studyId, sampleName, null, sessionId).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyId, sampleName, null, sessionId).first(); assertEquals(IndexStatus.READY, secureGet(sample, s -> s.getInternal().getVariant().getIndex().getStatus().getId(), null)); assertEquals(IndexStatus.READY, secureGet(sample, s -> s.getInternal().getVariant().getAnnotationIndex().getStatus().getId(), null)); assertEquals((Integer) 1, secureGet(sample, s -> s.getInternal().getVariant().getSecondarySampleIndex().getVersion(), null)); @@ -281,7 +281,7 @@ public void testInternalFileStatuses() throws Exception { File file; // -------------------- - file = catalogManager.getFileManager().get(studyId, fileName, null, sessionId).first(); + file = catalogManager.getFileManager().get(organizationId, studyId, fileName, null, sessionId).first(); assertEquals(IndexStatus.READY, file.getInternal().getVariant().getIndex().getStatus().getId()); assertEquals(IndexStatus.NONE, file.getInternal().getVariant().getAnnotationIndex().getStatus().getId()); @@ -292,7 +292,7 @@ public void testInternalFileStatuses() throws Exception { fm -> fm.setAnnotationStatus(TaskMetadata.Status.READY)); studyConfigurationFactory.synchronizeCatalogStudyFromStorage(sm, sessionId); - file = catalogManager.getFileManager().get(studyId, fileName, null, sessionId).first(); + file = catalogManager.getFileManager().get(organizationId, studyId, fileName, null, sessionId).first(); assertEquals(IndexStatus.READY, file.getInternal().getVariant().getIndex().getStatus().getId()); assertEquals(IndexStatus.READY, file.getInternal().getVariant().getAnnotationIndex().getStatus().getId()); assertEquals(IndexStatus.NONE, file.getInternal().getVariant().getSecondaryAnnotationIndex().getStatus().getId()); @@ -302,7 +302,7 @@ public void testInternalFileStatuses() throws Exception { fm -> fm.setSecondaryAnnotationIndexStatus(TaskMetadata.Status.READY)); studyConfigurationFactory.synchronizeCatalogStudyFromStorage(sm, sessionId); - file = catalogManager.getFileManager().get(studyId, fileName, null, sessionId).first(); + file = catalogManager.getFileManager().get(organizationId, studyId, fileName, null, sessionId).first(); assertEquals(IndexStatus.READY, file.getInternal().getVariant().getIndex().getStatus().getId()); assertEquals(IndexStatus.READY, file.getInternal().getVariant().getAnnotationIndex().getStatus().getId()); assertEquals(IndexStatus.READY, file.getInternal().getVariant().getSecondaryAnnotationIndex().getStatus().getId()); @@ -312,7 +312,7 @@ public void testInternalFileStatuses() throws Exception { fm -> fm.setAnnotationStatus(TaskMetadata.Status.NONE)); studyConfigurationFactory.synchronizeCatalogStudyFromStorage(sm, sessionId); - file = catalogManager.getFileManager().get(studyId, fileName, null, sessionId).first(); + file = catalogManager.getFileManager().get(organizationId, studyId, fileName, null, sessionId).first(); assertEquals(IndexStatus.READY, file.getInternal().getVariant().getIndex().getStatus().getId()); assertEquals(IndexStatus.NONE, file.getInternal().getVariant().getAnnotationIndex().getStatus().getId()); assertEquals(IndexStatus.READY, file.getInternal().getVariant().getSecondaryAnnotationIndex().getStatus().getId()); @@ -326,13 +326,13 @@ public void testMissingSamples() throws CatalogException { catalogManager.getCohortManager().update(studyId, "ALL", new CohortUpdateParams() .setSamples(Collections.singletonList(new SampleReferenceParam().setId("NA12878"))), true, new QueryOptions(Constants.ACTIONS, Collections.singletonMap(CohortDBAdaptor.QueryParams.SAMPLES.key(), ParamUtils.BasicUpdateAction.REMOVE)), sessionId); - catalogManager.getSampleManager().delete(studyId, Collections.singletonList("NA12878"), new QueryOptions(), sessionId); + catalogManager.getSampleManager().delete(organizationId, studyId, Collections.singletonList("NA12878"), new QueryOptions(), sessionId); - assertEquals(0, catalogManager.getFileManager().get(studyId, fileId, new QueryOptions(), sessionId).first().getSampleIds().size()); + assertEquals(0, catalogManager.getFileManager().get(organizationId, studyId, fileId, new QueryOptions(), sessionId).first().getSampleIds().size()); studyConfigurationFactory.synchronizeCatalogStudyFromStorage(studyId, sessionId); - assertEquals(1, catalogManager.getFileManager().get(studyId, fileId, new QueryOptions(), sessionId).first().getSampleIds().size()); + assertEquals(1, catalogManager.getFileManager().get(organizationId, studyId, fileId, new QueryOptions(), sessionId).first().getSampleIds().size()); } @Test @@ -346,12 +346,12 @@ public void testWrongSamples() throws CatalogException { catalogManager.getFileManager().update(studyId, fileId, new FileUpdateParams().setSampleIds(Collections.singletonList(wrongSampleId)), new QueryOptions(Constants.ACTIONS, Collections.singletonMap(FileDBAdaptor.QueryParams.SAMPLE_IDS.key(), "SET")), sessionId); - assertEquals(1, catalogManager.getFileManager().get(studyId, fileId, new QueryOptions(), sessionId).first().getSampleIds().size()); - assertEquals(wrongSampleId, catalogManager.getFileManager().get(studyId, fileId, new QueryOptions(), sessionId).first().getSampleIds().get(0)); + assertEquals(1, catalogManager.getFileManager().get(organizationId, studyId, fileId, new QueryOptions(), sessionId).first().getSampleIds().size()); + assertEquals(wrongSampleId, catalogManager.getFileManager().get(organizationId, studyId, fileId, new QueryOptions(), sessionId).first().getSampleIds().get(0)); studyConfigurationFactory.synchronizeCatalogStudyFromStorage(studyId, sessionId); - assertEquals(1, catalogManager.getFileManager().get(studyId, fileId, new QueryOptions(), sessionId).first().getSampleIds().size()); - assertEquals(correctSampleId, catalogManager.getFileManager().get(studyId, fileId, new QueryOptions(), sessionId).first().getSampleIds().get(0)); + assertEquals(1, catalogManager.getFileManager().get(organizationId, studyId, fileId, new QueryOptions(), sessionId).first().getSampleIds().size()); + assertEquals(correctSampleId, catalogManager.getFileManager().get(organizationId, studyId, fileId, new QueryOptions(), sessionId).first().getSampleIds().get(0)); } } \ No newline at end of file diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/CatalogCommandExecutor.java b/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/CatalogCommandExecutor.java index 5140d8e8a21..52d6c4351cc 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/CatalogCommandExecutor.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/CatalogCommandExecutor.java @@ -93,10 +93,10 @@ private void export() throws CatalogException { String token = catalogManager.getUserManager().loginAsAdmin(adminPassword).getToken(); if (StringUtils.isNotEmpty(commandOptions.project)) { - catalogManager.getProjectManager().exportReleases(commandOptions.project, commandOptions.release, commandOptions.outputDir, + catalogManager.getProjectManager().exportReleases(organizationId, commandOptions.project, commandOptions.release, commandOptions.outputDir, token); } else if (StringUtils.isNotEmpty(commandOptions.study) && StringUtils.isNotEmpty(commandOptions.inputFile)) { - catalogManager.getProjectManager().exportByFileNames(commandOptions.study, Paths.get(commandOptions.outputDir).toFile(), + catalogManager.getProjectManager().exportByFileNames(organizationId, commandOptions.study, Paths.get(commandOptions.outputDir).toFile(), Paths.get(commandOptions.inputFile).toFile(), token); } } @@ -108,7 +108,7 @@ private void importDatabase() throws CatalogException, IOException { CatalogManager catalogManager = new CatalogManager(configuration); String token = catalogManager.getUserManager().loginAsAdmin(adminPassword).getToken(); - catalogManager.getProjectManager().importReleases(commandOptions.owner, commandOptions.directory, token); + catalogManager.getProjectManager().importReleases(organizationId, commandOptions.owner, commandOptions.directory, token); } private void status() throws CatalogException, JsonProcessingException { diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/StorageCommandExecutor.java b/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/StorageCommandExecutor.java index a03ddae1bfc..856e2eecf4a 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/StorageCommandExecutor.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/StorageCommandExecutor.java @@ -142,7 +142,7 @@ private void updateDatabasePrefix() throws Exception { variantStorageProjects = new HashSet<>(getVariantStorageProjects(catalogManager, variantStorageManager)); } - for (Project project : catalogManager.getProjectManager().search(new Query(), new QueryOptions(), token).getResults()) { + for (Project project : catalogManager.getProjectManager().search(organizationId, new Query(), new QueryOptions(), token).getResults()) { if (projects != null && !projects.contains(project.getFqn())) { logger.info("Skip project '{}'", project.getFqn()); continue; @@ -198,7 +198,7 @@ private void updateDatabasePrefix() throws Exception { } logger.info("New DBName: " + newDataStore.getDbName()); - catalogManager.getProjectManager().setDatastoreVariant(project.getUuid(), newDataStore, token); catalogManager.getProjectManager().setDatastoreVariant(project.getUuid(), defaultDataStore, token); + catalogManager.getProjectManager().setDatastoreVariant(organizationId, project.getUuid(), newDataStore, token); catalogManager.getProjectManager().setDatastoreVariant(organizationId, project.getUuid(), defaultDataStore, token); } } } @@ -225,7 +225,7 @@ protected final List getVariantStorageProjects(CatalogManager catalogMan */ protected final List getVariantStorageStudies(CatalogManager catalogManager, VariantStorageManager variantStorageManager) throws Exception { Set studies = new LinkedHashSet<>(); - for (Study study : catalogManager.getStudyManager().search(new Query(), new QueryOptions(QueryOptions.INCLUDE, + for (Study study : catalogManager.getStudyManager().search(organizationId, new Query(), new QueryOptions(QueryOptions.INCLUDE, Arrays.asList("fqn")), token).getResults()) { if (variantStorageManager.exists(study.getFqn(), token)) { studies.add(study.getFqn()); diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/migration/storage/AbstractStorageMigrator.java b/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/migration/storage/AbstractStorageMigrator.java index 21a0be6c4a5..2df7e161839 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/migration/storage/AbstractStorageMigrator.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/migration/storage/AbstractStorageMigrator.java @@ -42,7 +42,7 @@ public void migrate(String sessionId) throws CatalogException, StorageEngineExce StorageEngineFactory storageEngineFactory = StorageEngineFactory.get(storageConfiguration); - List projects = catalogManager.getProjectManager().search(new Query(), new QueryOptions( + List projects = catalogManager.getProjectManager().search(organizationId, new Query(), new QueryOptions( QueryOptions.INCLUDE, Arrays.asList( ProjectDBAdaptor.QueryParams.NAME.key(), ProjectDBAdaptor.QueryParams.ID.key(), diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/migration/storage/AddFilePathToStudyConfigurationMigration.java b/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/migration/storage/AddFilePathToStudyConfigurationMigration.java index 9bbe716cd24..c272a671770 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/migration/storage/AddFilePathToStudyConfigurationMigration.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/executors/migration/storage/AddFilePathToStudyConfigurationMigration.java @@ -34,7 +34,7 @@ public AddFilePathToStudyConfigurationMigration(CatalogManager catalogManager) { public String getFilePath(String studyName, String fileName, String sessionId) throws CatalogException { // Search filePath in catalog logger.info("Register path from file = " + fileName); - DataResult queryResult = catalogManager.getFileManager().search(studyName, new Query() + DataResult queryResult = catalogManager.getFileManager().search(organizationId, studyName, new Query() .append(ID.key(), fileName), QUERY_OPTIONS, sessionId); File file = null; if (queryResult.getResults().size() == 1) { diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/cli/internal/executors/InternalCommandExecutor.java b/opencga-app/src/main/java/org/opencb/opencga/app/cli/internal/executors/InternalCommandExecutor.java index bffc809a1da..86d1ec0b8c1 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/cli/internal/executors/InternalCommandExecutor.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/cli/internal/executors/InternalCommandExecutor.java @@ -56,7 +56,7 @@ protected void configure() throws IllegalAccessException, ClassNotFoundException } protected Map getStudyIds(String sessionId) throws CatalogException { - return catalogManager.getStudyManager().search(new Query(), new QueryOptions("include", "projects.studies.id,projects.studies" + + return catalogManager.getStudyManager().search(organizationId, new Query(), new QueryOptions("include", "projects.studies.id,projects.studies" + ".alias"), sessionId) .getResults() .stream() diff --git a/opencga-app/src/main/java/org/opencb/opencga/app/migrations/StorageMigrationTool.java b/opencga-app/src/main/java/org/opencb/opencga/app/migrations/StorageMigrationTool.java index 16914627d5b..8bb961db868 100644 --- a/opencga-app/src/main/java/org/opencb/opencga/app/migrations/StorageMigrationTool.java +++ b/opencga-app/src/main/java/org/opencb/opencga/app/migrations/StorageMigrationTool.java @@ -64,7 +64,7 @@ protected final List getVariantStorageProjects() throws Exception { protected final List getVariantStorageStudies() throws Exception { Set studies = new LinkedHashSet<>(); VariantStorageManager variantStorageManager = getVariantStorageManager(); - for (Study study : catalogManager.getStudyManager().search(new Query(), new QueryOptions(QueryOptions.INCLUDE, + for (Study study : catalogManager.getStudyManager().search(organizationId, new Query(), new QueryOptions(QueryOptions.INCLUDE, Arrays.asList("fqn")), token).getResults()) { if (variantStorageManager.exists(study.getFqn(), token)) { studies.add(study.getFqn()); diff --git a/opencga-app/src/test/java/org/opencb/opencga/app/cli/analysis/InternalMainTest.java b/opencga-app/src/test/java/org/opencb/opencga/app/cli/analysis/InternalMainTest.java index e8548e128b2..27c90c4fd5e 100644 --- a/opencga-app/src/test/java/org/opencb/opencga/app/cli/analysis/InternalMainTest.java +++ b/opencga-app/src/test/java/org/opencb/opencga/app/cli/analysis/InternalMainTest.java @@ -141,9 +141,9 @@ public void testVariantIndex() throws Exception { "--study", "user@p1:s1", "-o", opencga.createTmpOutdir(studyId, "index_1", sessionId), "--file", file1.getPath()); - assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(studyId, file1.getId(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(organizationId, studyId, file1.getId(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); - assertEquals(CohortStatus.NONE, catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(CohortStatus.NONE, catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId).first().getInternal().getStatus().getId()); // job = catalogManager.getJobManager().get(studyId, new Query(JobDBAdaptor.QueryParams.INPUT.key(), file1.getId()), null, sessionId).first(); // assertEquals(Job.JobStatus.READY, job.getStatus().getName()); @@ -163,7 +163,7 @@ public void testVariantIndex() throws Exception { "--output-file-name", "myAnnot", "--path", outdirId); - File outputFile = catalogManager.getFileManager().search(studyId, new Query(FileDBAdaptor.QueryParams.NAME.key(), + File outputFile = catalogManager.getFileManager().search(organizationId, studyId, new Query(FileDBAdaptor.QueryParams.NAME.key(), "~myAnnot"), null, sessionId).first(); assertNotNull(outputFile); // job = catalogManager.getJobManager().get(outputFile.getJob().getId(), null, sessionId).first(); @@ -177,9 +177,9 @@ public void testVariantIndex() throws Exception { "--calculate-stats", "-o", opencga.createTmpOutdir(studyId, "index_2", sessionId)); - assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(studyId, file2.getId(), null, sessionId).first().getInternal().getVariant().getIndex() + assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(organizationId, studyId, file2.getId(), null, sessionId).first().getInternal().getVariant().getIndex() .getStatus().getId()); - assertEquals(CohortStatus.READY, catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(CohortStatus.READY, catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId).first().getInternal().getStatus().getId()); // job = catalogManager.getJobManager().get(studyId, new Query(JobDBAdaptor.QueryParams.INPUT.key(), file2.getId()), null, sessionId).first(); // assertEquals(Job.JobStatus.READY, job.getStatus().getName()); @@ -196,8 +196,8 @@ public void testVariantIndex() throws Exception { "--session-id", sessionId, "--file", String.valueOf(file3.getId()), "-o", opencga.createTmpOutdir(studyId, "index_3", sessionId)); - assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(studyId, file3.getId(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); - assertEquals(CohortStatus.INVALID, catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(organizationId, studyId, file3.getId(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + assertEquals(CohortStatus.INVALID, catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId).first().getInternal().getStatus().getId()); // job = catalogManager.getJobManager().get(studyId, new Query(JobDBAdaptor.QueryParams.INPUT.key(), file3.getId()), null, sessionId).first(); // assertEquals(Job.JobStatus.READY, job.getStatus().getName()); // assertNotEquals(outdirId, job.getOutDir().getId()); @@ -224,8 +224,8 @@ public void testVariantIndex() throws Exception { "--file", file5.getId(), "-o", opencga.createTmpOutdir(studyId, "index_5", sessionId), "--annotate"); - assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(studyId, file5.getId(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); - assertEquals(CohortStatus.INVALID, catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(organizationId, studyId, file5.getId(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + assertEquals(CohortStatus.INVALID, catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId).first().getInternal().getStatus().getId()); // job = catalogManager.getJobManager().get(studyId, new Query(JobDBAdaptor.QueryParams.INPUT.key(), file5.getId()), null, sessionId).first(); // assertEquals(Job.JobStatus.READY, job.getStatus().getName()); @@ -235,7 +235,7 @@ public void testVariantIndex() throws Exception { "--study", studyId, "--cohort-ids", "ALL", "-o", opencga.createTmpOutdir(studyId, "stats_all", sessionId)); - assertEquals(CohortStatus.READY, catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(CohortStatus.READY, catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId).first().getInternal().getStatus().getId()); catalogManager.getCohortManager().create(studyId, new CohortCreateParams("coh1", "", Enums.CohortType.CONTROL_SET, "", null, null, file1.getSampleIds().stream().map(s -> new SampleReferenceParam().setId(s)).collect(Collectors.toList()), null, null, null), @@ -249,8 +249,8 @@ public void testVariantIndex() throws Exception { "--study", studyId, "--cohort-ids", "coh1", "-o", opencga.createTmpOutdir(studyId, "stats_coh1", sessionId)); - assertEquals(CohortStatus.READY, catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "coh1"), null, sessionId).first().getInternal().getStatus().getId()); - assertEquals(CohortStatus.NONE, catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "coh2"), null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(CohortStatus.READY, catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "coh1"), null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(CohortStatus.NONE, catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "coh2"), null, sessionId).first().getInternal().getStatus().getId()); // execute(new String[]{"variant", "query", "--session-id", sessionId, "--study", studyId, "--limit", "10"}); } @@ -263,7 +263,7 @@ public void testVariantIndexAndQuery() throws CatalogException, IOException { // File file1 = opencga.createFile(studyId, "100k.chr22.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz", sessionId); // File file1 = opencga.createFile(studyId, "10k.chr22.phase3_shapeit2_mvncall_integrated_v5.20130502.genotypes.vcf.gz", sessionId); - DataResult allSamples = catalogManager.getSampleManager().search(studyId, new Query(), new QueryOptions(), sessionId); + DataResult allSamples = catalogManager.getSampleManager().search(organizationId, studyId, new Query(), new QueryOptions(), sessionId); List sampleIds = allSamples.getResults().stream().map(Sample::getId).collect(Collectors.toList()); String c1 = catalogManager.getCohortManager().create(studyId, new CohortCreateParams("C1", "", Enums.CohortType.CONTROL_SET, "", null, @@ -274,7 +274,7 @@ public void testVariantIndexAndQuery() throws CatalogException, IOException { .map(s -> new SampleReferenceParam().setId(s)).collect(Collectors.toList()), null, null, null), null, null, null, sessionId).first().getId(); String c3 = catalogManager.getCohortManager().create(studyId, new CohortCreateParams("C3", "", Enums.CohortType.CONTROL_SET, "", null, null, sampleIds.subList(0, 1).stream().map(s -> new SampleReferenceParam().setId(s)).collect(Collectors.toList()), null, null, null), null, null, null, sessionId).first().getId(); - Sample sample = catalogManager.getSampleManager().create(studyId, new Sample().setId("Sample"), null, sessionId).first(); + Sample sample = catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("Sample"), null, sessionId).first(); String c4 = catalogManager.getCohortManager().create(studyId, new CohortCreateParams("C4", "", Enums.CohortType.CONTROL_SET, "", null, null, Collections.singletonList(new SampleReferenceParam().setId(sample.getId())), null, null, null), null, null, null, sessionId).first().getId(); @@ -287,8 +287,8 @@ public void testVariantIndexAndQuery() throws CatalogException, IOException { "--calculate-stats", "--annotate"); - assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(studyId, file1.getId(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); - assertEquals(CohortStatus.READY, catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId).first().getInternal().getStatus().getId()); + assertEquals(VariantIndexStatus.READY, catalogManager.getFileManager().get(organizationId, studyId, file1.getId(), null, sessionId).first().getInternal().getVariant().getIndex().getStatus().getId()); + assertEquals(CohortStatus.READY, catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId).first().getInternal().getStatus().getId()); // job = catalogManager.getJobManager().get(studyId, new Query(JobDBAdaptor.QueryParams.INPUT.key(), file1.getId()), null, sessionId).first(); // assertEquals(Job.JobStatus.READY, job.getStatus().getName()); diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/DBAdaptorFactory.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/DBAdaptorFactory.java index 2c7437bd10e..6d57497be2f 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/DBAdaptorFactory.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/DBAdaptorFactory.java @@ -22,6 +22,8 @@ import org.opencb.opencga.catalog.exceptions.CatalogException; import org.opencb.opencga.core.config.Configuration; +import java.util.List; + /** * Created by hpccoll1 on 19/06/15. */ @@ -67,6 +69,10 @@ default String getCatalogOrganizationDatabase(String prefix, String organization void close(); + void createIndexes(String organization) throws CatalogDBException; + + List getOrganizationIds(); + OrganizationDBAdaptor getCatalogOrganizationDBAdaptor(); MigrationDBAdaptor getMigrationDBAdaptor(String organization) throws CatalogDBException; diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/MongoDBAdaptorFactory.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/MongoDBAdaptorFactory.java index c2cfdf3dfe2..076fed562a7 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/MongoDBAdaptorFactory.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/MongoDBAdaptorFactory.java @@ -37,10 +37,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; +import java.util.*; import static org.opencb.opencga.core.common.JacksonUtils.getDefaultObjectMapper; @@ -130,6 +127,17 @@ public void close() { mongoManager.close(mongoDataStore.getDatabaseName()); } + @Override + public void createIndexes(String organization) throws CatalogDBException { + OrganizationMongoDBAdaptorFactory orgFactory = getOrganizationMongoDBAdaptorFactory(organization); + orgFactory.createIndexes(); + } + + @Override + public List getOrganizationIds() { + return new ArrayList<>(organizationDBAdaptorMap.keySet()); + } + public MongoDataStore getMongoDataStore() { return mongoDataStore; } diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/iterators/ProjectCatalogMongoDBIterator.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/iterators/ProjectCatalogMongoDBIterator.java index 52aa62fb1e0..bd769152926 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/iterators/ProjectCatalogMongoDBIterator.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/iterators/ProjectCatalogMongoDBIterator.java @@ -10,7 +10,7 @@ import org.opencb.opencga.catalog.db.api.ProjectDBAdaptor; import org.opencb.opencga.catalog.db.api.StudyDBAdaptor; import org.opencb.opencga.catalog.db.mongodb.MongoDBAdaptor; -import org.opencb.opencga.catalog.db.mongodb.MongoDBAdaptorFactory; +import org.opencb.opencga.catalog.db.mongodb.OrganizationMongoDBAdaptorFactory; import org.opencb.opencga.catalog.db.mongodb.StudyMongoDBAdaptor; import org.opencb.opencga.catalog.exceptions.CatalogAuthorizationException; import org.opencb.opencga.catalog.exceptions.CatalogDBException; @@ -37,7 +37,7 @@ public class ProjectCatalogMongoDBIterator extends CatalogMongoDBIterator private static final String UID = ProjectDBAdaptor.QueryParams.UID.key(); public ProjectCatalogMongoDBIterator(MongoDBIterator mongoCursor, ClientSession clientSession, - GenericDocumentComplexConverter converter, MongoDBAdaptorFactory dbAdaptorFactory, + GenericDocumentComplexConverter converter, OrganizationMongoDBAdaptorFactory dbAdaptorFactory, QueryOptions options, String user) { super(mongoCursor, clientSession, converter, null); diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AbstractManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AbstractManager.java index 149f61bc075..c0174123815 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AbstractManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AbstractManager.java @@ -91,7 +91,7 @@ protected UserDBAdaptor getUserDBAdaptor(String organization) throws CatalogDBEx return catalogDBAdaptorFactory.getCatalogUserDBAdaptor(organization); } - protected ProjectDBAdaptor getProjectDbAdaptor(String organization) throws CatalogDBException { + protected ProjectDBAdaptor getProjectDBAdaptor(String organization) throws CatalogDBException { return catalogDBAdaptorFactory.getCatalogProjectDbAdaptor(organization); } diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AdminManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AdminManager.java index b57426ebf04..aa8b1fb2881 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AdminManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AdminManager.java @@ -106,7 +106,7 @@ public OpenCGAResult updateGroups(String userId, List studyIds, L } // Check studyIds exist - List studies = catalogManager.getStudyManager().resolveIds(studyIds, authenticatedUser); + List studies = catalogManager.getStudyManager().resolveIds(organizationId, studyIds, authenticatedUser); List studyUids = new ArrayList<>(studies.size()); for (Study study : studies) { if (ParamConstants.ADMIN_STUDY_FQN.equals(study.getFqn())) { diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AnnotationSetManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AnnotationSetManager.java index cf3e601e498..5ba1fa4efbb 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AnnotationSetManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AnnotationSetManager.java @@ -115,7 +115,7 @@ protected void validateNewAnnotationSets(List variableSetList, List public OpenCGAResult loadTsvAnnotations(String studyStr, String variableSetId, String path, TsvAnnotationParams tsvParams, ObjectMap params, String toolId, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); ParamUtils.checkObj(variableSetId, "VariableSetId"); ParamUtils.checkObj(tsvParams, "AnnotationTsvParams"); @@ -144,7 +144,7 @@ public OpenCGAResult loadTsvAnnotations(String studyStr, String variableSet } Query query = new Query(FileDBAdaptor.QueryParams.PATH.key(), path); - OpenCGAResult search = catalogManager.getFileManager().search(study.getFqn(), query, FileManager.INCLUDE_FILE_URI_PATH, + OpenCGAResult search = catalogManager.getFileManager().search(organizationId, study.getFqn(), query, FileManager.INCLUDE_FILE_URI_PATH, token); if (search.getNumResults() == 0) { // File not found under the path. User must have provided a content so we can create the file. diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AuditManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AuditManager.java index b95d3b0ff0e..b1237cb65ae 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AuditManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/AuditManager.java @@ -218,7 +218,7 @@ public OpenCGAResult search(String studyStr, Query query, QueryOpti options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); ObjectMap auditParams = new ObjectMap() .append("studyId", studyStr) diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/CatalogManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/CatalogManager.java index 488a1c0f872..23d72820959 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/CatalogManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/CatalogManager.java @@ -243,8 +243,8 @@ private void privateInstall(String secretKey, String password, String email, boo // Add OPENCGA as owner of ADMIN_ORGANIZATION organizationManager.update(ADMIN_ORGANIZATION, new OrganizationUpdateParams().setOwner(OPENCGA), QueryOptions.empty(), token); - projectManager.create(new ProjectCreateParams().setId(ADMIN_PROJECT).setDescription("Default project"), null, token); - studyManager.create(ADMIN_PROJECT, new Study().setId(ADMIN_STUDY).setDescription("Default study"), QueryOptions.empty(), token); + projectManager.create(organizationId, new ProjectCreateParams().setId(ADMIN_PROJECT).setDescription("Default project"), null, token); + studyManager.create(organizationId, ADMIN_PROJECT, new Study().setId(ADMIN_STUDY).setDescription("Default study"), QueryOptions.empty(), token); // Skip old available migrations migrationManager.skipPendingMigrations(token); @@ -254,7 +254,10 @@ public void installIndexes(String token) throws CatalogException { if (!OPENCGA.equals(userManager.getUserId(token))) { throw new CatalogAuthorizationException("Only the admin can install new indexes"); } - catalogDBAdaptorFactory.createIndexes(); + + for (String organizationId : catalogDBAdaptorFactory.getOrganizationIds()) { + catalogDBAdaptorFactory.createIndexes(organizationId); + } } public void deleteCatalogDB(String password) throws CatalogException { diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/ClinicalAnalysisManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/ClinicalAnalysisManager.java index da22c3da07b..ce5a24db7c6 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/ClinicalAnalysisManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/ClinicalAnalysisManager.java @@ -19,7 +19,10 @@ import com.fasterxml.jackson.core.JsonProcessingException; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.opencb.biodata.models.clinical.*; +import org.opencb.biodata.models.clinical.ClinicalAnalyst; +import org.opencb.biodata.models.clinical.ClinicalAudit; +import org.opencb.biodata.models.clinical.ClinicalComment; +import org.opencb.biodata.models.clinical.Disorder; import org.opencb.biodata.models.common.Status; import org.opencb.commons.datastore.core.Event; import org.opencb.commons.datastore.core.ObjectMap; @@ -130,9 +133,9 @@ Enums.Resource getEntity() { // } // // QueryOptions queryOptions = options != null ? new QueryOptions(options) : new QueryOptions(); -// OpenCGAResult analysisDataResult = clinicalDBAdaptor.get(studyUid, queryCopy, queryOptions, user); +// OpenCGAResult analysisDataResult = getClinicalAnalysisDBAdaptor(organizationId).get(studyUid, queryCopy, queryOptions, user); // if (analysisDataResult.getNumResults() == 0) { -// analysisDataResult = clinicalDBAdaptor.get(queryCopy, queryOptions); +// analysisDataResult = getClinicalAnalysisDBAdaptor(organizationId).get(queryCopy, queryOptions); // if (analysisDataResult.getNumResults() == 0) { // throw new CatalogException("Clinical Analysis '" + entry + "' not found"); // } else { @@ -147,7 +150,7 @@ Enums.Resource getEntity() { // } @Override - InternalGetDataResult internalGet(long studyUid, List entryList, @Nullable Query query, + InternalGetDataResult internalGet(String organizationId, long studyUid, List entryList, @Nullable Query query, QueryOptions options, String user, boolean ignoreException) throws CatalogException { if (ListUtils.isEmpty(entryList)) { @@ -180,13 +183,13 @@ InternalGetDataResult internalGet(long studyUid, List // Ensure the field by which we are querying for will be kept in the results queryOptions = keepFieldInQueryOptions(queryOptions, idQueryParam.key()); - OpenCGAResult analysisDataResult = clinicalDBAdaptor.get(studyUid, queryCopy, queryOptions, user); + OpenCGAResult analysisDataResult = getClinicalAnalysisDBAdaptor(organizationId).get(studyUid, queryCopy, queryOptions, user); if (ignoreException || analysisDataResult.getNumResults() == uniqueList.size()) { return keepOriginalOrder(uniqueList, clinicalStringFunction, analysisDataResult, ignoreException, false); } // Query without adding the user check - OpenCGAResult resultsNoCheck = clinicalDBAdaptor.get(queryCopy, queryOptions); + OpenCGAResult resultsNoCheck = getClinicalAnalysisDBAdaptor(organizationId).get(queryCopy, queryOptions); if (resultsNoCheck.getNumResults() == analysisDataResult.getNumResults()) { throw CatalogException.notFound("clinical analyses", @@ -198,33 +201,34 @@ InternalGetDataResult internalGet(long studyUid, List } @Override - public DBIterator iterator(String studyStr, Query query, QueryOptions options, String sessionId) + public DBIterator iterator(String organizationId, String studyStr, Query query, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = catalogManager.getUserManager().getUserId(sessionId); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); - fixQueryObject(study, query, userId, sessionId); + fixQueryObject(organizationId, study, query, userId, sessionId); query.append(ClinicalAnalysisDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); - return clinicalDBAdaptor.iterator(study.getUid(), query, options, userId); + return getClinicalAnalysisDBAdaptor(organizationId).iterator(study.getUid(), query, options, userId); } @Override - public OpenCGAResult create(String studyStr, ClinicalAnalysis clinicalAnalysis, QueryOptions options, String token) + public OpenCGAResult create(String organizationId, String studyStr, ClinicalAnalysis clinicalAnalysis, QueryOptions options, String token) throws CatalogException { - return create(studyStr, clinicalAnalysis, null, options, token); + return create(organizationId, studyStr, clinicalAnalysis, null, options, token); } - public OpenCGAResult create(String studyStr, ClinicalAnalysis clinicalAnalysis, + public OpenCGAResult create(String organizationId, String studyStr, ClinicalAnalysis clinicalAnalysis, Boolean skipCreateDefaultInterpretation, QueryOptions options, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("study", studyStr) .append("clinicalAnalysis", clinicalAnalysis) .append("skipCreateDefaultInterpretation", skipCreateDefaultInterpretation) @@ -282,7 +286,7 @@ public OpenCGAResult create(String studyStr, ClinicalAnalysis Set panelIds = clinicalAnalysis.getPanels().stream().map(Panel::getId).collect(Collectors.toSet()); Query query = new Query(PanelDBAdaptor.QueryParams.ID.key(), panelIds); OpenCGAResult panelResult = - panelDBAdaptor.get(study.getUid(), query, PanelManager.INCLUDE_PANEL_IDS, userId); + getPanelDBAdaptor(organizationId).get(study.getUid(), query, PanelManager.INCLUDE_PANEL_IDS, userId); if (panelResult.getNumResults() < panelIds.size()) { throw new CatalogException("Some panels were not found or user doesn't have permissions to see them"); } @@ -295,10 +299,10 @@ public OpenCGAResult create(String studyStr, ClinicalAnalysis UserDBAdaptor.QueryParams.NAME.key(), UserDBAdaptor.QueryParams.EMAIL.key())); User user; if (clinicalAnalysis.getAnalyst() == null || StringUtils.isEmpty(clinicalAnalysis.getAnalyst().getId())) { - user = userDBAdaptor.get(userId, userInclude).first(); + user = getUserDBAdaptor(organizationId).get(userId, userInclude).first(); } else { // Validate user - OpenCGAResult result = userDBAdaptor.get(clinicalAnalysis.getAnalyst().getId(), userInclude); + OpenCGAResult result = getUserDBAdaptor(organizationId).get(clinicalAnalysis.getAnalyst().getId(), userInclude); if (result.getNumResults() == 0) { throw new CatalogException("User '" + clinicalAnalysis.getAnalyst().getId() + "' not found"); } @@ -320,7 +324,7 @@ public OpenCGAResult create(String studyStr, ClinicalAnalysis throw new CatalogException("Missing family id"); } - OpenCGAResult familyDataResult = catalogManager.getFamilyManager().get(study.getFqn(), + OpenCGAResult familyDataResult = catalogManager.getFamilyManager().get(organizationId, study.getFqn(), clinicalAnalysis.getFamily().getId(), new QueryOptions(), token); if (familyDataResult.getNumResults() == 0) { throw new CatalogException("Family " + clinicalAnalysis.getFamily().getId() + " not found"); @@ -332,7 +336,7 @@ public OpenCGAResult create(String studyStr, ClinicalAnalysis if (member.getSamples() != null && !member.getSamples().isEmpty()) { Query query = new Query(SampleDBAdaptor.QueryParams.UID.key(), member.getSamples().stream().map(Sample::getUid).collect(Collectors.toList())); - OpenCGAResult sampleResult = sampleDBAdaptor.get(study.getUid(), query, new QueryOptions(), userId); + OpenCGAResult sampleResult = getSampleDBAdaptor(organizationId).get(study.getUid(), query, new QueryOptions(), userId); member.setSamples(sampleResult.getResults()); } } @@ -454,7 +458,7 @@ public OpenCGAResult create(String studyStr, ClinicalAnalysis // Validate the proband has a disorder validateDisorder(clinicalAnalysis); } else { - OpenCGAResult individualOpenCGAResult = catalogManager.getIndividualManager().internalGet(study.getUid(), + OpenCGAResult individualOpenCGAResult = catalogManager.getIndividualManager().internalGet(organizationId, study.getUid(), clinicalAnalysis.getProband().getId(), new Query(), new QueryOptions(), userId); if (individualOpenCGAResult.getNumResults() == 0) { throw new CatalogException("Proband '" + clinicalAnalysis.getProband().getId() + "' not found."); @@ -502,9 +506,9 @@ public OpenCGAResult create(String studyStr, ClinicalAnalysis } } if (clinicalAnalysis.getFiles() != null && !clinicalAnalysis.getFiles().isEmpty()) { - validateFiles(study, clinicalAnalysis, userId); + validateFiles(organizationId, study, clinicalAnalysis, userId); } else { - obtainFiles(study, clinicalAnalysis, userId); + obtainFiles(organizationId, study, clinicalAnalysis, userId); } clinicalAnalysis.setCreationDate(ParamUtils.checkDateOrGetCurrentDate(clinicalAnalysis.getCreationDate(), @@ -561,7 +565,7 @@ public OpenCGAResult create(String studyStr, ClinicalAnalysis clinicalAuditList.add(new ClinicalAudit(userId, ClinicalAudit.Action.CREATE_CLINICAL_ANALYSIS, "Create ClinicalAnalysis '" + clinicalAnalysis.getId() + "'", TimeUtils.getTime())); - OpenCGAResult insert = clinicalDBAdaptor.insert(study.getUid(), clinicalAnalysis, clinicalAuditList, options); + OpenCGAResult insert = getClinicalAnalysisDBAdaptor(organizationId).insert(study.getUid(), clinicalAnalysis, clinicalAuditList, options); insert.addEvents(events); auditManager.auditCreate(userId, Enums.Resource.CLINICAL_ANALYSIS, clinicalAnalysis.getId(), clinicalAnalysis.getUuid(), @@ -569,7 +573,7 @@ public OpenCGAResult create(String studyStr, ClinicalAnalysis if (options.getBoolean(ParamConstants.INCLUDE_RESULT_PARAM)) { // Fetch updated clinical analysis - OpenCGAResult queryResult = clinicalDBAdaptor.get(study.getUid(), clinicalAnalysis.getId(), + OpenCGAResult queryResult = getClinicalAnalysisDBAdaptor(organizationId).get(study.getUid(), clinicalAnalysis.getId(), QueryOptions.empty()); insert.setResults(queryResult.getResults()); } @@ -747,7 +751,7 @@ private void validateDisorder(ClinicalAnalysis clinicalAnalysis) throws CatalogE } } - private void obtainFiles(Study study, ClinicalAnalysis clinicalAnalysis, String userId) throws CatalogException { + private void obtainFiles(String organizationId, Study study, ClinicalAnalysis clinicalAnalysis, String userId) throws CatalogException { Set sampleSet = new HashSet<>(); if (clinicalAnalysis.getFamily() != null && clinicalAnalysis.getFamily().getMembers() != null) { for (Individual member : clinicalAnalysis.getFamily().getMembers()) { @@ -771,12 +775,12 @@ private void obtainFiles(Study study, ClinicalAnalysis clinicalAnalysis, String Query query = new Query() .append(FileDBAdaptor.QueryParams.SAMPLE_IDS.key(), new ArrayList<>(sampleSet)) .append(FileDBAdaptor.QueryParams.BIOFORMAT.key(), Arrays.asList(File.Bioformat.ALIGNMENT, File.Bioformat.VARIANT)); - OpenCGAResult fileResults = fileDBAdaptor.get(study.getUid(), query, FileManager.INCLUDE_FILE_URI_PATH, userId); + OpenCGAResult fileResults = getFileDBAdaptor(organizationId).get(study.getUid(), query, FileManager.INCLUDE_FILE_URI_PATH, userId); clinicalAnalysis.setFiles(fileResults.getResults()); } } - private void validateFiles(Study study, ClinicalAnalysis clinicalAnalysis, String userId) throws CatalogException { + private void validateFiles(String organizationId, Study study, ClinicalAnalysis clinicalAnalysis, String userId) throws CatalogException { Map sampleMap = new HashMap<>(); if (clinicalAnalysis.getFamily() != null && clinicalAnalysis.getFamily().getMembers() != null) { for (Individual member : clinicalAnalysis.getFamily().getMembers()) { @@ -800,7 +804,7 @@ private void validateFiles(Study study, ClinicalAnalysis clinicalAnalysis, Strin Query query = new Query(FileDBAdaptor.QueryParams.ID.key(), clinicalAnalysis.getFiles().stream().map(File::getId).collect(Collectors.toList())); QueryOptions fileOptions = keepFieldInQueryOptions(FileManager.INCLUDE_FILE_URI_PATH, FileDBAdaptor.QueryParams.SAMPLE_IDS.key()); - OpenCGAResult fileResults = fileDBAdaptor.get(study.getUid(), query, fileOptions, userId); + OpenCGAResult fileResults = getFileDBAdaptor(organizationId).get(study.getUid(), query, fileOptions, userId); if (fileResults.getNumResults() != clinicalAnalysis.getFiles().size()) { Set fileIds = clinicalAnalysis.getFiles().stream().map(File::getId).collect(Collectors.toSet()); @@ -844,7 +848,7 @@ private void validateFiles(Study study, ClinicalAnalysis clinicalAnalysis, Strin // } } - private Family getFullValidatedFamily(Family family, Study study, String sessionId) throws CatalogException { + private Family getFullValidatedFamily(String organizationId, Family family, Study study, String token) throws CatalogException { if (family == null) { return null; } @@ -856,8 +860,8 @@ private Family getFullValidatedFamily(Family family, Study study, String session // List of members relevant for the clinical analysis List selectedMembers = family.getMembers(); - OpenCGAResult familyDataResult = catalogManager.getFamilyManager().get(study.getFqn(), family.getId(), new QueryOptions(), - sessionId); + OpenCGAResult familyDataResult = catalogManager.getFamilyManager().get(organizationId, study.getFqn(), family.getId(), new QueryOptions(), + token); if (familyDataResult.getNumResults() == 0) { throw new CatalogException("Family " + family.getId() + " not found"); } @@ -880,7 +884,7 @@ private Family getFullValidatedFamily(Family family, Study study, String session throw new CatalogException("Member " + selectedMember.getId() + " does not belong to family " + family.getId()); } fullMember.setSamples(selectedMember.getSamples()); - finalMembers.add(getFullValidatedMember(fullMember, study, sessionId)); + finalMembers.add(getFullValidatedMember(organizationId, fullMember, study, token)); } finalFamily.setMembers(finalMembers); @@ -890,8 +894,8 @@ private Family getFullValidatedFamily(Family family, Study study, String session .append(IndividualDBAdaptor.QueryParams.UID.key(), finalFamily.getMembers().stream() .map(Individual::getUid).collect(Collectors.toList())) .append(IndividualDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); - OpenCGAResult individuals = individualDBAdaptor.get(study.getUid(), query, QueryOptions.empty(), - catalogManager.getUserManager().getUserId(sessionId)); + OpenCGAResult individuals = getIndividualDBAdaptor(organizationId).get(study.getUid(), query, QueryOptions.empty(), + catalogManager.getUserManager().getUserId(token)); finalFamily.setMembers(individuals.getResults()); } } @@ -899,7 +903,7 @@ private Family getFullValidatedFamily(Family family, Study study, String session return finalFamily; } - private Individual getFullValidatedMember(Individual member, Study study, String sessionId) throws CatalogException { + private Individual getFullValidatedMember(String organizationId, Individual member, Study study, String sessionId) throws CatalogException { if (member == null) { return null; } @@ -914,7 +918,7 @@ private Individual getFullValidatedMember(Individual member, Study study, String List samples = member.getSamples(); if (member.getUid() <= 0) { - OpenCGAResult individualDataResult = catalogManager.getIndividualManager().get(study.getFqn(), member.getId(), + OpenCGAResult individualDataResult = catalogManager.getIndividualManager().get(organizationId, study.getFqn(), member.getId(), new QueryOptions(), sessionId); if (individualDataResult.getNumResults() == 0) { throw new CatalogException("Member " + member.getId() + " not found"); @@ -925,7 +929,7 @@ private Individual getFullValidatedMember(Individual member, Study study, String finalMember = member; if (ListUtils.isNotEmpty(samples) && StringUtils.isEmpty(samples.get(0).getUuid())) { // We don't have the full sample information... - OpenCGAResult individualDataResult = catalogManager.getIndividualManager().get(study.getFqn(), + OpenCGAResult individualDataResult = catalogManager.getIndividualManager().get(organizationId, study.getFqn(), finalMember.getId(), new QueryOptions(QueryOptions.INCLUDE, IndividualDBAdaptor.QueryParams.SAMPLES.key()), sessionId); if (individualDataResult.getNumResults() == 0) { @@ -958,15 +962,16 @@ private Individual getFullValidatedMember(Individual member, Study study, String return finalMember; } - public OpenCGAResult update(String studyStr, Query query, ClinicalAnalysisUpdateParams updateParams, - QueryOptions options, String token) throws CatalogException { - return update(studyStr, query, updateParams, false, options, token); + public OpenCGAResult update(String organizationId, String studyStr, Query query, + ClinicalAnalysisUpdateParams updateParams, QueryOptions options, String token) + throws CatalogException { + return update(organizationId, studyStr, query, updateParams, false, options, token); } - public OpenCGAResult update(String studyStr, Query query, ClinicalAnalysisUpdateParams updateParams, + public OpenCGAResult update(String organizationId, String studyStr, Query query, ClinicalAnalysisUpdateParams updateParams, boolean ignoreException, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -978,6 +983,7 @@ public OpenCGAResult update(String studyStr, Query query, Clin } ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("study", studyStr) .append("query", query) .append("updateParams", updateMap) @@ -987,9 +993,9 @@ public OpenCGAResult update(String studyStr, Query query, Clin DBIterator iterator; try { - fixQueryObject(study, query, userId, token); + fixQueryObject(organizationId, study, query, userId, token); query.append(ClinicalAnalysisDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); - iterator = clinicalDBAdaptor.iterator(study.getUid(), query, new QueryOptions(), userId); + iterator = getClinicalAnalysisDBAdaptor(organizationId).iterator(study.getUid(), query, new QueryOptions(), userId); } catch (CatalogException e) { auditManager.auditUpdate(operationId, userId, Enums.Resource.CLINICAL_ANALYSIS, "", "", study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.ERROR, e.getError())); @@ -1001,7 +1007,7 @@ public OpenCGAResult update(String studyStr, Query query, Clin while (iterator.hasNext()) { ClinicalAnalysis clinicalAnalysis = iterator.next(); try { - OpenCGAResult queryResult = update(study, clinicalAnalysis, updateParams, userId, options); + OpenCGAResult queryResult = update(organizationId, study, clinicalAnalysis, updateParams, userId, options); result.append(queryResult); auditManager.auditUpdate(operationId, userId, Enums.Resource.CLINICAL_ANALYSIS, clinicalAnalysis.getId(), @@ -1023,10 +1029,11 @@ public OpenCGAResult update(String studyStr, Query query, Clin return endResult(result, ignoreException); } - public OpenCGAResult update(String studyStr, String clinicalId, ClinicalAnalysisUpdateParams updateParams, - QueryOptions options, String token) throws CatalogException { + public OpenCGAResult update(String organizationId, String studyStr, String clinicalId, + ClinicalAnalysisUpdateParams updateParams, QueryOptions options, String token) + throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -1038,6 +1045,7 @@ public OpenCGAResult update(String studyStr, String clinicalId } ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("study", studyStr) .append("clinicalId", clinicalId) .append("updateParams", updateMap) @@ -1047,7 +1055,7 @@ public OpenCGAResult update(String studyStr, String clinicalId OpenCGAResult result = OpenCGAResult.empty(); String clinicalUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), clinicalId, QueryOptions.empty(), userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), clinicalId, QueryOptions.empty(), userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Clinical analysis '" + clinicalId + "' not found"); } @@ -1057,7 +1065,7 @@ public OpenCGAResult update(String studyStr, String clinicalId clinicalId = clinicalAnalysis.getId(); clinicalUuid = clinicalAnalysis.getUuid(); - OpenCGAResult updateResult = update(study, clinicalAnalysis, updateParams, userId, options); + OpenCGAResult updateResult = update(organizationId, study, clinicalAnalysis, updateParams, userId, options); result.append(updateResult); auditManager.auditUpdate(operationId, userId, Enums.Resource.CLINICAL_ANALYSIS, clinicalAnalysis.getId(), @@ -1080,24 +1088,27 @@ public OpenCGAResult update(String studyStr, String clinicalId /** * Update a Clinical Analysis from catalog. * - * @param studyStr Study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. - * @param clinicalIds List of clinical analysis ids. Could be either the id or uuid. - * @param updateParams Data model filled only with the parameters to be updated. - * @param options QueryOptions object. - * @param token Session id of the user logged in. + * @param organizationId Organization id. + * @param studyStr Study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. + * @param clinicalIds List of clinical analysis ids. Could be either the id or uuid. + * @param updateParams Data model filled only with the parameters to be updated. + * @param options QueryOptions object. + * @param token Session id of the user logged in. * @return A OpenCGAResult. * @throws CatalogException if there is any internal error, the user does not have proper permissions or a parameter passed does not * exist or is not allowed to be updated. */ - public OpenCGAResult update(String studyStr, List clinicalIds, ClinicalAnalysisUpdateParams updateParams, - QueryOptions options, String token) throws CatalogException { - return update(studyStr, clinicalIds, updateParams, false, options, token); + public OpenCGAResult update(String organizationId, String studyStr, List clinicalIds, + ClinicalAnalysisUpdateParams updateParams, QueryOptions options, String token) + throws CatalogException { + return update(organizationId, studyStr, clinicalIds, updateParams, false, options, token); } - public OpenCGAResult update(String studyStr, List clinicalIds, ClinicalAnalysisUpdateParams updateParams, - boolean ignoreException, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult update(String organizationId, String studyStr, List clinicalIds, + ClinicalAnalysisUpdateParams updateParams, boolean ignoreException, QueryOptions options, + String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -1109,6 +1120,7 @@ public OpenCGAResult update(String studyStr, List clin } ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("study", studyStr) .append("clinicalIds", clinicalIds) .append("updateParams", updateMap) @@ -1123,7 +1135,7 @@ public OpenCGAResult update(String studyStr, List clin String clinicalAnalysisId = id; String clinicalAnalysisUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), id, QueryOptions.empty(), userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, QueryOptions.empty(), userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Clinical analysis '" + id + "' not found"); } @@ -1133,7 +1145,7 @@ public OpenCGAResult update(String studyStr, List clin clinicalAnalysisId = clinicalAnalysis.getId(); clinicalAnalysisUuid = clinicalAnalysis.getUuid(); - OpenCGAResult updateResult = update(study, clinicalAnalysis, updateParams, userId, options); + OpenCGAResult updateResult = update(organizationId, study, clinicalAnalysis, updateParams, userId, options); result.append(updateResult); auditManager.auditUpdate(operationId, userId, Enums.Resource.CLINICAL_ANALYSIS, clinicalAnalysis.getId(), @@ -1154,7 +1166,7 @@ public OpenCGAResult update(String studyStr, List clin return endResult(result, ignoreException); } - private OpenCGAResult update(Study study, ClinicalAnalysis clinicalAnalysis, + private OpenCGAResult update(String organizationId, Study study, ClinicalAnalysis clinicalAnalysis, ClinicalAnalysisUpdateParams updateParams, String userId, QueryOptions options) throws CatalogException { options = ParamUtils.defaultObject(options, QueryOptions::new); @@ -1235,7 +1247,7 @@ private OpenCGAResult update(Study study, ClinicalAnalysis cli QueryOptions userOptions = new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(UserDBAdaptor.QueryParams.ID.key(), UserDBAdaptor.QueryParams.NAME.key(), UserDBAdaptor.QueryParams.EMAIL.key())); // Check user exists - OpenCGAResult userResult = userDBAdaptor.get(updateParams.getAnalyst().getId(), userOptions); + OpenCGAResult userResult = getUserDBAdaptor(organizationId).get(updateParams.getAnalyst().getId(), userOptions); if (userResult.getNumResults() == 0) { throw new CatalogException("User '" + updateParams.getAnalyst().getId() + "' not found"); } @@ -1263,7 +1275,7 @@ private OpenCGAResult update(Study study, ClinicalAnalysis cli clinicalAnalysis.setFiles(updateParams.getFiles().stream().map(FileReferenceParam::toFile).collect(Collectors.toList())); // Validate files - validateFiles(study, clinicalAnalysis, userId); + validateFiles(organizationId, study, clinicalAnalysis, userId); } if (CollectionUtils.isNotEmpty(updateParams.getPanels()) && updateParams.getPanelLock() != null && updateParams.getPanelLock()) { @@ -1280,7 +1292,7 @@ private OpenCGAResult update(Study study, ClinicalAnalysis cli List panelIds = updateParams.getPanels().stream().map(PanelReferenceParam::getId).collect(Collectors.toList()); Query query = new Query(PanelDBAdaptor.QueryParams.ID.key(), panelIds); OpenCGAResult panelResult = - panelDBAdaptor.get(study.getUid(), query, PanelManager.INCLUDE_PANEL_IDS, userId); + getPanelDBAdaptor(organizationId).get(study.getUid(), query, PanelManager.INCLUDE_PANEL_IDS, userId); if (panelResult.getNumResults() < panelIds.size()) { throw new CatalogException("Some panels were not found or user doesn't have permissions to see them."); } @@ -1332,7 +1344,7 @@ private OpenCGAResult update(Study study, ClinicalAnalysis cli Query query = new Query(PanelDBAdaptor.QueryParams.ID.key(), updateParams.getPanels().stream().map(PanelReferenceParam::getId).collect(Collectors.toList())); OpenCGAResult panelResult = - panelDBAdaptor.get(study.getUid(), query, PanelManager.INCLUDE_PANEL_IDS, userId); + getPanelDBAdaptor(organizationId).get(study.getUid(), query, PanelManager.INCLUDE_PANEL_IDS, userId); if (panelResult.getNumResults() < updateParams.getPanels().size()) { throw new CatalogException("Some panels were not found or user doesn't have permissions to see them"); } @@ -1417,12 +1429,12 @@ private OpenCGAResult update(Study study, ClinicalAnalysis cli ClinicalAudit clinicalAudit = new ClinicalAudit(userId, ClinicalAudit.Action.UPDATE_CLINICAL_ANALYSIS, "Update ClinicalAnalysis '" + clinicalAnalysis.getId() + "'", TimeUtils.getTime()); - OpenCGAResult update = clinicalDBAdaptor.update(clinicalAnalysis.getUid(), parameters, + OpenCGAResult update = getClinicalAnalysisDBAdaptor(organizationId).update(clinicalAnalysis.getUid(), parameters, Collections.singletonList(clinicalAudit), options); update.addEvents(events); if (options.getBoolean(ParamConstants.INCLUDE_RESULT_PARAM)) { // Fetch updated clinical analysis - OpenCGAResult result = clinicalDBAdaptor.get(study.getUid(), + OpenCGAResult result = getClinicalAnalysisDBAdaptor(organizationId).get(study.getUid(), new Query(ClinicalAnalysisDBAdaptor.QueryParams.UID.key(), clinicalAnalysis.getUid()), options, userId); update.setResults(result.getResults()); } @@ -1489,36 +1501,39 @@ private boolean sortMembersFromFamily(ClinicalAnalysis clinicalAnalysis) { return true; } - public OpenCGAResult search(String studyId, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult search(String organizationId, String studyId, Query query, QueryOptions options, String token) + throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); - fixQueryObject(study, query, userId, token); + fixQueryObject(organizationId, study, query, userId, token); query.append(ClinicalAnalysisDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); - return clinicalDBAdaptor.get(study.getUid(), query, options, userId); + return getClinicalAnalysisDBAdaptor(organizationId).get(study.getUid(), query, options, userId); } @Override - public OpenCGAResult distinct(String studyId, List fields, Query query, String token) throws CatalogException { + public OpenCGAResult distinct(String organizationId, String studyId, List fields, Query query, String token) + throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyId) .append("field", fields) .append("query", new Query(query)) .append("token", token); try { - fixQueryObject(study, query, userId, token); + fixQueryObject(organizationId, study, query, userId, token); query.append(ClinicalAnalysisDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); - OpenCGAResult result = clinicalDBAdaptor.distinct(study.getUid(), fields, query, userId); + OpenCGAResult result = getClinicalAnalysisDBAdaptor(organizationId).distinct(study.getUid(), fields, query, userId); auditManager.auditDistinct(userId, Enums.Resource.CLINICAL_ANALYSIS, study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); @@ -1531,7 +1546,7 @@ public OpenCGAResult distinct(String studyId, List fields, Query quer } } - protected void fixQueryObject(Study study, Query query, String user, String token) throws CatalogException { + protected void fixQueryObject(String organizationId, Study study, Query query, String user, String token) throws CatalogException { changeQueryId(query, ParamConstants.CLINICAL_DISORDER_PARAM, ClinicalAnalysisDBAdaptor.QueryParams.DISORDER.key()); changeQueryId(query, ParamConstants.CLINICAL_ANALYST_ID_PARAM, ClinicalAnalysisDBAdaptor.QueryParams.ANALYST_ID.key()); changeQueryId(query, ParamConstants.CLINICAL_PRIORITY_PARAM, ClinicalAnalysisDBAdaptor.QueryParams.PRIORITY_ID.key()); @@ -1548,7 +1563,7 @@ protected void fixQueryObject(Study study, Query query, String user, String toke PanelDBAdaptor.QueryParams fieldFilter = catalogManager.getPanelManager().getFieldFilter(panelList); Query tmpQuery = new Query(fieldFilter.key(), panelList); - OpenCGAResult result = panelDBAdaptor.get(study.getUid(), tmpQuery, PanelManager.INCLUDE_PANEL_IDS, user); + OpenCGAResult result = getPanelDBAdaptor(organizationId).get(study.getUid(), tmpQuery, PanelManager.INCLUDE_PANEL_IDS, user); if (result.getNumResults() > 0) { query.put(ClinicalAnalysisDBAdaptor.QueryParams.PANELS_UID.key(), result.getResults().stream().map(Panel::getUid).collect(Collectors.toList())); @@ -1564,7 +1579,7 @@ protected void fixQueryObject(Study study, Query query, String user, String toke FileDBAdaptor.QueryParams fieldFilter = catalogManager.getFileManager().getFieldFilter(fileList); Query tmpQuery = new Query(fieldFilter.key(), fileList); - OpenCGAResult result = fileDBAdaptor.get(study.getUid(), tmpQuery, FileManager.INCLUDE_FILE_IDS, user); + OpenCGAResult result = getFileDBAdaptor(organizationId).get(study.getUid(), tmpQuery, FileManager.INCLUDE_FILE_IDS, user); if (result.getNumResults() > 0) { query.put(ClinicalAnalysisDBAdaptor.QueryParams.FILES_UID.key(), result.getResults().stream().map(File::getUid).collect(Collectors.toList())); @@ -1580,7 +1595,7 @@ protected void fixQueryObject(Study study, Query query, String user, String toke IndividualDBAdaptor.QueryParams fieldFilter = catalogManager.getIndividualManager().getFieldFilter(probandList); Query tmpQuery = new Query(fieldFilter.key(), probandList); - OpenCGAResult result = individualDBAdaptor.get(study.getUid(), tmpQuery, IndividualManager.INCLUDE_INDIVIDUAL_IDS, + OpenCGAResult result = getIndividualDBAdaptor(organizationId).get(study.getUid(), tmpQuery, IndividualManager.INCLUDE_INDIVIDUAL_IDS, user); if (result.getNumResults() > 0) { query.put(ClinicalAnalysisDBAdaptor.QueryParams.PROBAND_UID.key(), @@ -1596,7 +1611,7 @@ protected void fixQueryObject(Study study, Query query, String user, String toke SampleDBAdaptor.QueryParams fieldFilter = catalogManager.getSampleManager().getFieldFilter(sampleList); Query tmpQuery = new Query(fieldFilter.key(), sampleList); - OpenCGAResult result = sampleDBAdaptor.get(study.getUid(), tmpQuery, SampleManager.INCLUDE_SAMPLE_IDS, user); + OpenCGAResult result = getSampleDBAdaptor(organizationId).get(study.getUid(), tmpQuery, SampleManager.INCLUDE_SAMPLE_IDS, user); if (result.getNumResults() > 0) { query.put(ClinicalAnalysisDBAdaptor.QueryParams.PROBAND_SAMPLES_UID.key(), result.getResults().stream().map(Sample::getUid).collect(Collectors.toList())); @@ -1611,7 +1626,7 @@ protected void fixQueryObject(Study study, Query query, String user, String toke FamilyDBAdaptor.QueryParams fieldFilter = catalogManager.getFamilyManager().getFieldFilter(familyList); Query tmpQuery = new Query(fieldFilter.key(), familyList); - OpenCGAResult result = familyDBAdaptor.get(study.getUid(), tmpQuery, FamilyManager.INCLUDE_FAMILY_IDS, user); + OpenCGAResult result = getFamilyDBAdaptor(organizationId).get(study.getUid(), tmpQuery, FamilyManager.INCLUDE_FAMILY_IDS, user); if (result.getNumResults() > 0) { query.put(ClinicalAnalysisDBAdaptor.QueryParams.FAMILY_UID.key(), result.getResults().stream().map(Family::getUid).collect(Collectors.toList())); @@ -1626,7 +1641,7 @@ protected void fixQueryObject(Study study, Query query, String user, String toke IndividualDBAdaptor.QueryParams fieldFilter = catalogManager.getIndividualManager().getFieldFilter(probandList); Query tmpQuery = new Query(fieldFilter.key(), probandList); - OpenCGAResult result = individualDBAdaptor.get(study.getUid(), tmpQuery, IndividualManager.INCLUDE_INDIVIDUAL_IDS, + OpenCGAResult result = getIndividualDBAdaptor(organizationId).get(study.getUid(), tmpQuery, IndividualManager.INCLUDE_INDIVIDUAL_IDS, user); if (result.getNumResults() > 0) { query.put(ClinicalAnalysisDBAdaptor.QueryParams.FAMILY_MEMBERS_UID.key(), @@ -1642,7 +1657,7 @@ protected void fixQueryObject(Study study, Query query, String user, String toke SampleDBAdaptor.QueryParams fieldFilter = catalogManager.getSampleManager().getFieldFilter(sampleList); Query tmpQuery = new Query(fieldFilter.key(), sampleList); - OpenCGAResult result = sampleDBAdaptor.get(study.getUid(), tmpQuery, SampleManager.INCLUDE_SAMPLE_IDS, user); + OpenCGAResult result = getSampleDBAdaptor(organizationId).get(study.getUid(), tmpQuery, SampleManager.INCLUDE_SAMPLE_IDS, user); if (result.getNumResults() > 0) { query.put(ClinicalAnalysisDBAdaptor.QueryParams.FAMILY_MEMBERS_SAMPLES_UID.key(), result.getResults().stream().map(Sample::getUid).collect(Collectors.toList())); @@ -1659,7 +1674,7 @@ protected void fixQueryObject(Study study, Query query, String user, String toke IndividualDBAdaptor.QueryParams fieldFilter = catalogManager.getIndividualManager().getFieldFilter(individualList); Query tmpQuery = new Query(fieldFilter.key(), individualList); - OpenCGAResult result = individualDBAdaptor.get(study.getUid(), tmpQuery, IndividualManager.INCLUDE_INDIVIDUAL_IDS, + OpenCGAResult result = getIndividualDBAdaptor(organizationId).get(study.getUid(), tmpQuery, IndividualManager.INCLUDE_INDIVIDUAL_IDS, user); if (result.getNumResults() > 0) { query.put(ClinicalAnalysisDBAdaptor.QueryParams.INDIVIDUAL.key(), @@ -1675,7 +1690,7 @@ protected void fixQueryObject(Study study, Query query, String user, String toke SampleDBAdaptor.QueryParams fieldFilter = catalogManager.getSampleManager().getFieldFilter(sampleList); Query tmpQuery = new Query(fieldFilter.key(), sampleList); - OpenCGAResult result = sampleDBAdaptor.get(study.getUid(), tmpQuery, SampleManager.INCLUDE_SAMPLE_IDS, user); + OpenCGAResult result = getSampleDBAdaptor(organizationId).get(study.getUid(), tmpQuery, SampleManager.INCLUDE_SAMPLE_IDS, user); if (result.getNumResults() > 0) { query.put(ClinicalAnalysisDBAdaptor.QueryParams.SAMPLE.key(), result.getResults().stream().map(Sample::getUid).collect(Collectors.toList())); @@ -1686,20 +1701,21 @@ protected void fixQueryObject(Study study, Query query, String user, String toke } } - public OpenCGAResult count(String studyId, Query query, String token) + public OpenCGAResult count(String organizationId, String studyId, Query query, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyId) .append("query", new Query(query)) .append("token", token); try { - fixQueryObject(study, query, userId, token); + fixQueryObject(organizationId, study, query, userId, token); query.append(ClinicalAnalysisDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); - OpenCGAResult queryResultAux = clinicalDBAdaptor.count(query, userId); + OpenCGAResult queryResultAux = getClinicalAnalysisDBAdaptor(organizationId).count(query, userId); auditManager.auditCount(userId, Enums.Resource.CLINICAL_ANALYSIS, study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); @@ -1714,23 +1730,24 @@ public OpenCGAResult count(String studyId, Query query, String } @Override - public OpenCGAResult delete(String studyStr, List clinicalAnalysisIds, QueryOptions options, String token) + public OpenCGAResult delete(String organizationId, String studyStr, List clinicalAnalysisIds, QueryOptions options, String token) throws CatalogException { - return delete(studyStr, clinicalAnalysisIds, options, false, token); + return delete(organizationId, studyStr, clinicalAnalysisIds, options, false, token); } - public OpenCGAResult delete(String studyStr, List clinicalAnalysisIds, QueryOptions options, boolean ignoreException, - String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, List clinicalAnalysisIds, QueryOptions options, + boolean ignoreException, String token) throws CatalogException { if (CollectionUtils.isEmpty(clinicalAnalysisIds)) { throw new CatalogException("Missing list of Clinical Analysis ids"); } String userId = catalogManager.getUserManager().getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("study", studyStr) .append("clinicalAnalysisIds", clinicalAnalysisIds) .append("options", options) @@ -1755,7 +1772,7 @@ public OpenCGAResult delete(String studyStr, List clinicalAnalysisIds, Q String clinicalId = id; String clinicalUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), id, + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, keepFieldsInQueryOptions(INCLUDE_CLINICAL_INTERPRETATION_IDS, Arrays.asList( ClinicalAnalysisDBAdaptor.QueryParams.INTERPRETATION.key() + "." + InterpretationDBAdaptor.QueryParams.PRIMARY_FINDINGS_ID.key(), @@ -1782,7 +1799,7 @@ public OpenCGAResult delete(String studyStr, List clinicalAnalysisIds, Q ClinicalAudit clinicalAudit = new ClinicalAudit(userId, ClinicalAudit.Action.DELETE_CLINICAL_ANALYSIS, "Delete Clinical Analysis '" + clinicalId + "'", TimeUtils.getTime()); - result.append(clinicalDBAdaptor.delete(clinicalAnalysis, Collections.singletonList(clinicalAudit))); + result.append(getClinicalAnalysisDBAdaptor(organizationId).delete(clinicalAnalysis, Collections.singletonList(clinicalAudit))); auditManager.auditDelete(operationId, userId, Enums.Resource.CLINICAL_ANALYSIS, clinicalAnalysis.getId(), clinicalAnalysis.getUuid(), study.getId(), study.getUuid(), auditParams, @@ -1825,23 +1842,24 @@ private void checkClinicalAnalysisCanBeDeleted(ClinicalAnalysis clinicalAnalysis } @Override - public OpenCGAResult delete(String studyStr, Query query, QueryOptions options, String token) throws CatalogException { - return delete(studyStr, query, options, false, token); + public OpenCGAResult delete(String organizationId, String studyStr, Query query, QueryOptions options, String token) throws CatalogException { + return delete(organizationId, studyStr, query, options, false, token); } - public OpenCGAResult delete(String studyStr, Query query, QueryOptions options, boolean ignoreException, String token) - throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, Query query, QueryOptions options, boolean ignoreException, + String token) throws CatalogException { Query finalQuery = new Query(ParamUtils.defaultObject(query, Query::new)); options = ParamUtils.defaultObject(options, QueryOptions::new); OpenCGAResult result = OpenCGAResult.empty(); String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); String operationUuid = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("study", studyStr) .append("query", new Query(query)) .append("options", options) @@ -1854,10 +1872,10 @@ public OpenCGAResult delete(String studyStr, Query query, QueryOptions options, // We try to get an iterator containing all the ClinicalAnalyses to be deleted DBIterator iterator; try { - fixQueryObject(study, finalQuery, userId, token); + fixQueryObject(organizationId, study, finalQuery, userId, token); finalQuery.append(ClinicalAnalysisDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); - iterator = clinicalDBAdaptor.iterator(study.getUid(), finalQuery, INCLUDE_CLINICAL_INTERPRETATION_IDS, userId); + iterator = getClinicalAnalysisDBAdaptor(organizationId).iterator(study.getUid(), finalQuery, INCLUDE_CLINICAL_INTERPRETATION_IDS, userId); // If the user is the owner or the admin, we won't check if he has permissions for every single entry checkPermissions = !authorizationManager.isOwnerOrAdmin(study.getUid(), userId); @@ -1883,7 +1901,7 @@ public OpenCGAResult delete(String studyStr, Query query, QueryOptions options, ClinicalAudit clinicalAudit = new ClinicalAudit(userId, ClinicalAudit.Action.DELETE_CLINICAL_ANALYSIS, "Delete Clinical Analysis '" + clinicalAnalysis.getId() + "'", TimeUtils.getTime()); - result.append(clinicalDBAdaptor.delete(clinicalAnalysis, Collections.singletonList(clinicalAudit))); + result.append(getClinicalAnalysisDBAdaptor(organizationId).delete(clinicalAnalysis, Collections.singletonList(clinicalAudit))); auditManager.auditDelete(operationUuid, userId, Enums.Resource.CLINICAL_ANALYSIS, clinicalAnalysis.getId(), clinicalAnalysis.getUuid(), study.getId(), study.getUuid(), auditParams, @@ -1907,13 +1925,13 @@ public OpenCGAResult delete(String studyStr, Query query, QueryOptions options, } @Override - public OpenCGAResult rank(String studyStr, Query query, String field, int numResults, boolean asc, String sessionId) + public OpenCGAResult rank(String organizationId, String studyStr, Query query, String field, int numResults, boolean asc, String sessionId) throws CatalogException { return null; } @Override - public OpenCGAResult groupBy(@Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) + public OpenCGAResult groupBy(String organizationId, @Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); @@ -1922,31 +1940,33 @@ public OpenCGAResult groupBy(@Nullable String studyStr, Query query, List> getAcls( - String studyStr, List clinicalList, String member, boolean ignoreException, String token) throws CatalogException { - return getAcls(studyStr, clinicalList, StringUtils.isNotEmpty(member) ? Collections.singletonList(member) : Collections.emptyList(), + String organizationId, String studyStr, List clinicalList, String member, boolean ignoreException, String token) + throws CatalogException { + return getAcls(organizationId, studyStr, clinicalList, StringUtils.isNotEmpty(member) ? Collections.singletonList(member) : Collections.emptyList(), ignoreException, token); } - public OpenCGAResult> getAcls(String studyId, List clinicalList, List members, + public OpenCGAResult> getAcls(String organizationId, String studyId, List clinicalList, List members, boolean ignoreException, String token) throws CatalogException { String user = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, user); + Study study = studyManager.resolveId(organizationId, studyId, user); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyId) .append("clinicalList", clinicalList) .append("members", members) @@ -1957,7 +1977,7 @@ public OpenCGAResult> getAcls(String s Map missingMap = new HashMap<>(); try { auditManager.initAuditBatch(operationId); - InternalGetDataResult queryResult = internalGet(study.getUid(), clinicalList, INCLUDE_CLINICAL_IDS, user, + InternalGetDataResult queryResult = internalGet(organizationId, study.getUid(), clinicalList, INCLUDE_CLINICAL_IDS, user, ignoreException); if (queryResult.getMissing() != null) { @@ -2021,12 +2041,13 @@ public OpenCGAResult> getAcls(String s } public OpenCGAResult> updateAcl( - String studyStr, List clinicalList, String memberIds, AclParams clinicalAclParams, ParamUtils.AclAction action, - boolean propagate, String token) throws CatalogException { + String organizationId, String studyStr, List clinicalList, String memberIds, AclParams clinicalAclParams, + ParamUtils.AclAction action, boolean propagate, String token) throws CatalogException { String user = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, user); + Study study = studyManager.resolveId(organizationId, studyStr, user); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyStr) .append("clinicalList", clinicalList) .append("memberIds", memberIds) @@ -2053,7 +2074,7 @@ public OpenCGAResult> updateAcl( checkPermissions(permissions, ClinicalAnalysisPermissions::valueOf); } - OpenCGAResult queryResult = internalGet(study.getUid(), clinicalList, INCLUDE_CATALOG_DATA, user, false); + OpenCGAResult queryResult = internalGet(organizationId, study.getUid(), clinicalList, INCLUDE_CATALOG_DATA, user, false); authorizationManager.checkCanAssignOrSeePermissions(study.getUid(), user); @@ -2065,7 +2086,7 @@ public OpenCGAResult> updateAcl( members = Collections.emptyList(); } authorizationManager.checkNotAssigningPermissionsToAdminsGroup(members); - checkMembers(study.getUid(), members); + checkMembers(organizationId, study.getUid(), members); List clinicalUidList = queryResult.getResults().stream().map(ClinicalAnalysis::getUid).collect(Collectors.toList()); List aclParamsList = new LinkedList<>(); @@ -2179,12 +2200,13 @@ public OpenCGAResult> updateAcl( } } - public OpenCGAResult configureStudy(String studyStr, ClinicalAnalysisStudyConfiguration clinicalConfiguration, String token) + public OpenCGAResult configureStudy(String organizationId, String studyStr, ClinicalAnalysisStudyConfiguration clinicalConfiguration, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyStr) .append("clinicalConfiguration", clinicalConfiguration) .append("token", token); @@ -2209,7 +2231,7 @@ public OpenCGAResult configureStudy(String studyStr, ClinicalAnalysisStudyConfig throw new CatalogException("Jackson casting error: " + e.getMessage(), e); } - OpenCGAResult updateResult = studyDBAdaptor.update(study.getUid(), update, QueryOptions.empty()); + OpenCGAResult updateResult = getStudyDBAdaptor(organizationId).update(study.getUid(), update, QueryOptions.empty()); auditManager.auditUpdate(userId, Enums.Resource.STUDY, study.getId(), study.getUuid(), study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/CohortManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/CohortManager.java index 36c14a4adc4..5cc65ad33bf 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/CohortManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/CohortManager.java @@ -94,7 +94,7 @@ Enums.Resource getEntity() { } @Override - InternalGetDataResult internalGet(long studyUid, List entryList, @Nullable Query query, QueryOptions options, + InternalGetDataResult internalGet(String organizationId, long studyUid, List entryList, @Nullable Query query, QueryOptions options, String user, boolean ignoreException) throws CatalogException { if (ListUtils.isEmpty(entryList)) { throw new CatalogException("Missing cohort entries."); @@ -154,7 +154,7 @@ public OpenCGAResult create(String studyStr, CohortCreateParams cohortPa options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); authorizationManager.checkStudyPermission(study.getUid(), userId, StudyPermissions.Permissions.WRITE_COHORTS); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -186,7 +186,7 @@ public OpenCGAResult create(String studyStr, CohortCreateParams cohortPa throw new CatalogParameterException("Found samples with missing id and uuid."); } } - List sampleList = catalogManager.getSampleManager().internalGet(study.getUid(), sampleIds, + List sampleList = catalogManager.getSampleManager().internalGet(organizationId, study.getUid(), sampleIds, SampleManager.INCLUDE_SAMPLE_IDS, userId, false).getResults(); cohorts.add(new Cohort(cohortParams.getId(), cohortParams.getName(), cohortParams.getType(), cohortParams.getCreationDate(), cohortParams.getModificationDate(), cohortParams.getDescription(), sampleList, 0, @@ -224,7 +224,7 @@ public OpenCGAResult create(String studyStr, CohortCreateParams cohortPa + "variable"); } for (String value : variable.getAllowedValues()) { - OpenCGAResult sampleResults = catalogManager.getSampleManager().search(study.getFqn(), + OpenCGAResult sampleResults = catalogManager.getSampleManager().search(organizationId, study.getFqn(), new Query(Constants.ANNOTATION, variableSetId + ":" + variableId + "=" + value), SampleManager.INCLUDE_SAMPLE_IDS, token); @@ -287,7 +287,7 @@ public OpenCGAResult create(String studyStr, CohortCreateParams cohortPa public OpenCGAResult generate(String studyStr, Query sampleQuery, Cohort cohort, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); authorizationManager.checkStudyPermission(study.getUid(), userId, StudyPermissions.Permissions.WRITE_COHORTS); ObjectMap auditParams = new ObjectMap() @@ -321,11 +321,11 @@ public OpenCGAResult generate(String studyStr, Query sampleQuery, Cohort } @Override - public OpenCGAResult create(String studyStr, Cohort cohort, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult create(String organizationId, String studyStr, Cohort cohort, QueryOptions options, String token) throws CatalogException { options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); authorizationManager.checkStudyPermission(study.getUid(), userId, StudyPermissions.Permissions.WRITE_COHORTS); ObjectMap auditParams = new ObjectMap() @@ -336,7 +336,7 @@ public OpenCGAResult create(String studyStr, Cohort cohort, QueryOptions try { if (CollectionUtils.isNotEmpty(cohort.getSamples())) { // Look for the samples - InternalGetDataResult sampleResult = catalogManager.getSampleManager().internalGet(study.getUid(), + InternalGetDataResult sampleResult = catalogManager.getSampleManager().internalGet(organizationId, study.getUid(), cohort.getSamples().stream().map(Sample::getId).collect(Collectors.toList()), SampleManager.INCLUDE_SAMPLE_IDS, userId, false); cohort.setSamples(sampleResult.getResults()); @@ -418,8 +418,8 @@ public Long getStudyId(long cohortId) throws CatalogException { */ public OpenCGAResult getSamples(String studyStr, String cohortStr, String sessionId) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(sessionId); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); - OpenCGAResult cohortDataResult = internalGet(study.getUid(), cohortStr, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); + OpenCGAResult cohortDataResult = internalGet(organizationId, study.getUid(), cohortStr, new QueryOptions(QueryOptions.INCLUDE, CohortDBAdaptor.QueryParams.SAMPLES.key()), userId); if (cohortDataResult == null || cohortDataResult.getNumResults() == 0) { @@ -434,12 +434,12 @@ public OpenCGAResult getSamples(String studyStr, String cohortStr, Strin } @Override - public DBIterator iterator(String studyStr, Query query, QueryOptions options, String sessionId) throws CatalogException { + public DBIterator iterator(String organizationId, String studyStr, Query query, QueryOptions options, String sessionId) throws CatalogException { options = ParamUtils.defaultObject(options, QueryOptions::new); query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(sessionId); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); // Fix query if it contains any annotation Query finalQuery = new Query(query); @@ -452,12 +452,12 @@ public DBIterator iterator(String studyStr, Query query, QueryOptions op } @Override - public OpenCGAResult search(String studyId, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult search(String organizationId, String studyId, Query query, QueryOptions options, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -486,11 +486,11 @@ public OpenCGAResult search(String studyId, Query query, QueryOptions op } @Override - public OpenCGAResult distinct(String studyId, List fields, Query query, String token) throws CatalogException { + public OpenCGAResult distinct(String organizationId, String studyId, List fields, Query query, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -525,7 +525,7 @@ private void fixQueryObject(Study study, Query query, String userId) throws Cata QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.UID.key()); // First look for the sample ids. - List sampleList = catalogManager.getSampleManager().internalGet(study.getUid(), + List sampleList = catalogManager.getSampleManager().internalGet(organizationId, study.getUid(), query.getAsStringList(ParamConstants.COHORT_SAMPLES_PARAM), SampleManager.INCLUDE_SAMPLE_IDS, userId, true) .getResults(); if (CollectionUtils.isNotEmpty(sampleList)) { @@ -541,11 +541,11 @@ private void fixQueryObject(Study study, Query query, String userId) throws Cata } @Override - public OpenCGAResult count(String studyId, Query query, String token) throws CatalogException { + public OpenCGAResult count(String organizationId, String studyId, Query query, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -573,7 +573,7 @@ public OpenCGAResult count(String studyId, Query query, String token) th } @Override - public OpenCGAResult delete(String studyStr, List cohortIds, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, List cohortIds, QueryOptions options, String token) throws CatalogException { return delete(studyStr, cohortIds, options, false, token); } @@ -584,7 +584,7 @@ public OpenCGAResult delete(String studyStr, List cohortIds, ObjectMap p } String userId = catalogManager.getUserManager().getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -613,7 +613,7 @@ public OpenCGAResult delete(String studyStr, List cohortIds, ObjectMap p String cohortId = id; String cohortUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), id, INCLUDE_COHORT_IDS, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, INCLUDE_COHORT_IDS, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Cohort '" + id + "' not found"); } @@ -648,7 +648,7 @@ public OpenCGAResult delete(String studyStr, List cohortIds, ObjectMap p } @Override - public OpenCGAResult delete(String studyStr, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, Query query, QueryOptions options, String token) throws CatalogException { return delete(studyStr, query, options, false, token); } @@ -658,7 +658,7 @@ public OpenCGAResult delete(String studyStr, Query query, ObjectMap params, bool OpenCGAResult result = OpenCGAResult.empty(); String userId = catalogManager.getUserManager().getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); String operationUuid = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -787,7 +787,7 @@ public OpenCGAResult update(String studyStr, String cohortId, CohortUpda public OpenCGAResult update(String studyStr, String cohortId, CohortUpdateParams updateParams, boolean allowModifyCohortAll, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -810,7 +810,7 @@ public OpenCGAResult update(String studyStr, String cohortId, CohortUpda String cohortUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), cohortId, INCLUDE_COHORT_STATUS, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), cohortId, INCLUDE_COHORT_STATUS, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Cohort '" + cohortId + "' not found"); } @@ -862,7 +862,7 @@ public OpenCGAResult update(String studyStr, List cohortIds, Coh boolean allowModifyCohortAll, boolean ignoreException, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -889,7 +889,7 @@ public OpenCGAResult update(String studyStr, List cohortIds, Coh String cohortUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), id, INCLUDE_COHORT_STATUS, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, INCLUDE_COHORT_STATUS, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Cohort '" + id + "' not found"); } @@ -941,7 +941,7 @@ public OpenCGAResult update(String studyStr, Query query, CohortUpdatePa Query finalQuery = new Query(ParamUtils.defaultObject(query, Query::new)); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -1079,7 +1079,7 @@ private OpenCGAResult update(Study study, Cohort cohort, CohortUpdatePar } } - InternalGetDataResult sampleResult = catalogManager.getSampleManager().internalGet(study.getUid(), + InternalGetDataResult sampleResult = catalogManager.getSampleManager().internalGet(organizationId, study.getUid(), new ArrayList<>(sampleIds), SampleManager.INCLUDE_SAMPLE_IDS, userId, false); if (sampleResult.getNumResults() != sampleIds.size()) { @@ -1103,14 +1103,14 @@ private OpenCGAResult update(Study study, Cohort cohort, CohortUpdatePar } @Override - public OpenCGAResult groupBy(@Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) + public OpenCGAResult groupBy(String organizationId, @Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); ParamUtils.checkObj(fields, "fields"); String userId = userManager.getUserId(sessionId); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); // Fix query if it contains any annotation AnnotationUtils.fixQueryAnnotationSearch(study, userId, query, authorizationManager); @@ -1126,7 +1126,7 @@ public OpenCGAResult groupBy(@Nullable String studyStr, Query query, List> getAcls(String studyId, Li public OpenCGAResult> getAcls(String studyId, List cohortList, List members, boolean ignoreException, String token) throws CatalogException { String user = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, user); + Study study = studyManager.resolveId(organizationId, studyId, user); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); ObjectMap auditParams = new ObjectMap() @@ -1212,7 +1212,7 @@ public OpenCGAResult> getAcls(String studyId, Li Map missingMap = new HashMap<>(); try { auditManager.initAuditBatch(operationId); - InternalGetDataResult queryResult = internalGet(study.getUid(), cohortList, INCLUDE_COHORT_IDS, user, ignoreException); + InternalGetDataResult queryResult = internalGet(organizationId, study.getUid(), cohortList, INCLUDE_COHORT_IDS, user, ignoreException); if (queryResult.getMissing() != null) { missingMap = queryResult.getMissing().stream() @@ -1278,7 +1278,7 @@ public OpenCGAResult> updateAcl(String studyId, ParamUtils.AclAction action, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId, StudyManager.INCLUDE_STUDY_UID); + Study study = studyManager.resolveId(organizationId, studyId, userId, StudyManager.INCLUDE_STUDY_UID); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -1306,7 +1306,7 @@ public OpenCGAResult> updateAcl(String studyId, checkPermissions(permissions, CohortPermissions::valueOf); } - List cohortList = internalGet(study.getUid(), cohortStrList, INCLUDE_COHORT_IDS, userId, false).getResults(); + List cohortList = internalGet(organizationId, study.getUid(), cohortStrList, INCLUDE_COHORT_IDS, userId, false).getResults(); authorizationManager.checkCanAssignOrSeePermissions(study.getUid(), userId); @@ -1376,7 +1376,7 @@ public DataResult facet(String studyId, Query query, QueryOptions op String userId = userManager.getUserId(token); // We need to add variableSets and groups to avoid additional queries as it will be used in the catalogSolrManager - Study study = catalogManager.getStudyManager().resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(StudyDBAdaptor.QueryParams.VARIABLE_SET.key(), StudyDBAdaptor.QueryParams.GROUPS.key()))); ObjectMap auditParams = new ObjectMap() diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/FamilyManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/FamilyManager.java index d7183adabae..42fbf247730 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/FamilyManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/FamilyManager.java @@ -132,7 +132,7 @@ Enums.Resource getEntity() { } @Override - InternalGetDataResult internalGet(long studyUid, List entryList, @Nullable Query query, QueryOptions options, + InternalGetDataResult internalGet(String organizationId, long studyUid, List entryList, @Nullable Query query, QueryOptions options, String user, boolean ignoreException) throws CatalogException { if (ListUtils.isEmpty(entryList)) { throw new CatalogException("Missing family entries."); @@ -201,13 +201,13 @@ private OpenCGAResult getFamily(long studyUid, String familyUuid, QueryO } @Override - public DBIterator iterator(String studyStr, Query query, QueryOptions options, String token) throws CatalogException { + public DBIterator iterator(String organizationId, String studyStr, Query query, QueryOptions options, String token) throws CatalogException { ParamUtils.checkObj(token, "sessionId"); query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); Query finalQuery = new Query(query); fixQueryObject(study, finalQuery, token); @@ -220,7 +220,7 @@ public DBIterator iterator(String studyStr, Query query, QueryOptions op } @Override - public OpenCGAResult create(String studyStr, Family family, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult create(String organizationId, String studyStr, Family family, QueryOptions options, String token) throws CatalogException { return create(studyStr, family, null, options, token); } @@ -228,7 +228,7 @@ public OpenCGAResult create(String studyStr, Family family, List throws CatalogException { options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -295,13 +295,13 @@ public OpenCGAResult create(String studyStr, Family family, List } } - public OpenCGAResult search(String studyId, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult search(String organizationId, String studyId, Query query, QueryOptions options, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); Query finalQuery = new Query(query); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = catalogManager.getUserManager().getUserId(token); - Study study = studyManager.resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -332,11 +332,11 @@ public OpenCGAResult search(String studyId, Query query, QueryOptions op } @Override - public OpenCGAResult distinct(String studyId, List fields, Query query, String token) throws CatalogException { + public OpenCGAResult distinct(String organizationId, String studyId, List fields, Query query, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -378,7 +378,7 @@ private void fixQueryObject(Study study, Query query, String sessionId) throws C if (query.containsKey(FamilyDBAdaptor.QueryParams.MEMBERS.key())) { String userId = userManager.getUserId(sessionId); - List memberList = catalogManager.getIndividualManager().internalGet(study.getUid(), + List memberList = catalogManager.getIndividualManager().internalGet(organizationId, study.getUid(), query.getAsStringList(FamilyDBAdaptor.QueryParams.MEMBERS.key()), IndividualManager.INCLUDE_INDIVIDUAL_IDS, userId, true).getResults(); if (ListUtils.isNotEmpty(memberList)) { @@ -400,7 +400,7 @@ private void fixQueryObject(Study study, Query query, String sessionId) throws C query.getString(IndividualDBAdaptor.QueryParams.SAMPLES.key())); QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, IndividualDBAdaptor.QueryParams.UID.key()); OpenCGAResult individualResult = catalogManager.getIndividualManager() - .search(study.getFqn(), newQuery, options, sessionId); + .search(organizationId, study.getFqn(), newQuery, options, sessionId); if (individualResult.getNumResults() == 0) { // Add -1 to query so no results are obtained @@ -416,12 +416,12 @@ private void fixQueryObject(Study study, Query query, String sessionId) throws C } } - public OpenCGAResult count(String studyId, Query query, String token) throws CatalogException { + public OpenCGAResult count(String organizationId, String studyId, Query query, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); Query finalQuery = new Query(query); String userId = catalogManager.getUserManager().getUserId(token); - Study study = studyManager.resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -449,14 +449,14 @@ public OpenCGAResult count(String studyId, Query query, String token) th } @Override - public OpenCGAResult delete(String studyStr, List familyIds, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, List familyIds, QueryOptions options, String token) throws CatalogException { return delete(studyStr, familyIds, options, false, token); } public OpenCGAResult delete(String studyStr, List familyIds, ObjectMap params, boolean ignoreException, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); String operationUuid = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -485,7 +485,7 @@ public OpenCGAResult delete(String studyStr, List familyIds, ObjectMap p String familyUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), id, INCLUDE_FAMILY_IDS, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, INCLUDE_FAMILY_IDS, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Family '" + id + "' not found"); } @@ -535,7 +535,7 @@ private void checkCanBeDeleted(Study study, Family family) throws CatalogExcepti } @Override - public OpenCGAResult delete(String studyStr, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, Query query, QueryOptions options, String token) throws CatalogException { return delete(studyStr, query, options, false, token); } @@ -545,7 +545,7 @@ public OpenCGAResult delete(String studyStr, Query query, ObjectMap params, bool OpenCGAResult result = OpenCGAResult.empty(); String userId = catalogManager.getUserManager().getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); String operationUuid = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -613,13 +613,13 @@ public OpenCGAResult delete(String studyStr, Query query, ObjectMap params, bool } @Override - public OpenCGAResult rank(String studyStr, Query query, String field, int numResults, boolean asc, String sessionId) throws + public OpenCGAResult rank(String organizationId, String studyStr, Query query, String field, int numResults, boolean asc, String sessionId) throws CatalogException { return null; } @Override - public OpenCGAResult groupBy(@Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) + public OpenCGAResult groupBy(String organizationId, @Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); @@ -628,7 +628,7 @@ public OpenCGAResult groupBy(@Nullable String studyStr, Query query, List update(String studyStr, Query query, FamilyUpdatePa public OpenCGAResult update(String studyStr, Query query, FamilyUpdateParams updateParams, boolean ignoreException, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -788,7 +788,7 @@ public OpenCGAResult update(String studyStr, Query query, FamilyUpdatePa public OpenCGAResult update(String studyStr, String familyId, FamilyUpdateParams updateParams, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -810,7 +810,7 @@ public OpenCGAResult update(String studyStr, String familyId, FamilyUpda String familyUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), familyId, QueryOptions.empty(), userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), familyId, QueryOptions.empty(), userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Family '" + familyId + "' not found"); } @@ -859,7 +859,7 @@ public OpenCGAResult update(String studyStr, List familyIds, Fam public OpenCGAResult update(String studyStr, List familyIds, FamilyUpdateParams updateParams, boolean ignoreException, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -885,7 +885,7 @@ public OpenCGAResult update(String studyStr, List familyIds, Fam String familyUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), familyId, QueryOptions.empty(), userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), familyId, QueryOptions.empty(), userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Family '" + id + "' not found"); } @@ -1037,7 +1037,7 @@ public Map> calculateFamilyGenotypes(String studyStr, Strin Disorder disorder = null; if (StringUtils.isNotEmpty(clinicalAnalysisId)) { - OpenCGAResult clinicalAnalysisDataResult = catalogManager.getClinicalAnalysisManager().get(studyStr, + OpenCGAResult clinicalAnalysisDataResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyStr, clinicalAnalysisId, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( ClinicalAnalysisDBAdaptor.QueryParams.PROBAND.key(), ClinicalAnalysisDBAdaptor.QueryParams.FAMILY.key(), ClinicalAnalysisDBAdaptor.QueryParams.DISORDER.key())), token); @@ -1050,7 +1050,7 @@ clinicalAnalysisId, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( clinicalAnalysisDataResult.first().getProband().getId()); } else if (StringUtils.isNotEmpty(familyId) && StringUtils.isNotEmpty(disorderId)) { - OpenCGAResult familyDataResult = get(studyStr, familyId, QueryOptions.empty(), token); + OpenCGAResult familyDataResult = get(organizationId, studyStr, familyId, QueryOptions.empty(), token); if (familyDataResult.getNumResults() == 0) { throw new CatalogException("Family " + familyId + " not found"); @@ -1103,7 +1103,7 @@ public OpenCGAResult> getAcls(String studyId, Li public OpenCGAResult> getAcls(String studyId, List familyList, List members, boolean ignoreException, String token) throws CatalogException { String user = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, user); + Study study = studyManager.resolveId(organizationId, studyId, user); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); ObjectMap auditParams = new ObjectMap() @@ -1117,7 +1117,7 @@ public OpenCGAResult> getAcls(String studyId, Li Map missingMap = new HashMap<>(); try { auditManager.initAuditBatch(operationId); - InternalGetDataResult queryResult = internalGet(study.getUid(), familyList, INCLUDE_FAMILY_IDS, user, ignoreException); + InternalGetDataResult queryResult = internalGet(organizationId, study.getUid(), familyList, INCLUDE_FAMILY_IDS, user, ignoreException); if (queryResult.getMissing() != null) { missingMap = queryResult.getMissing().stream() @@ -1182,7 +1182,7 @@ public OpenCGAResult> getAcls(String studyId, Li public OpenCGAResult> updateAcl(String studyId, FamilyAclParams aclParams, String memberList, ParamUtils.AclAction action, String token) throws CatalogException { String user = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, user); + Study study = studyManager.resolveId(organizationId, studyId, user); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -1220,18 +1220,18 @@ public OpenCGAResult> updateAcl(String studyId, String individualStr = aclParams.getIndividual(); if (StringUtils.isNotEmpty(aclParams.getSample())) { - OpenCGAResult sampleResult = catalogManager.getSampleManager().get(studyId, aclParams.getSample(), + OpenCGAResult sampleResult = catalogManager.getSampleManager().get(organizationId, studyId, aclParams.getSample(), new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key()), token); individualStr = sampleResult.getResults().stream().map(Sample::getIndividualId).collect(Collectors.joining(",")); } if (StringUtils.isNotEmpty(individualStr)) { - familyList = catalogManager.getFamilyManager().search(studyId, + familyList = catalogManager.getFamilyManager().search(organizationId, studyId, new Query(FamilyDBAdaptor.QueryParams.MEMBERS.key(), individualStr), FamilyManager.INCLUDE_FAMILY_MEMBERS, token) .getResults(); } else if (StringUtils.isNotEmpty(aclParams.getFamily())) { - familyList = catalogManager.getFamilyManager().get(studyId, Arrays.asList(aclParams.getFamily().split(",")), + familyList = catalogManager.getFamilyManager().get(organizationId, studyId, Arrays.asList(aclParams.getFamily().split(",")), FamilyManager.INCLUDE_FAMILY_MEMBERS, token).getResults(); } @@ -1340,7 +1340,7 @@ public DataResult facet(String studyId, Query query, QueryOptions op String userId = userManager.getUserId(token); // We need to add variableSets and groups to avoid additional queries as it will be used in the catalogSolrManager - Study study = catalogManager.getStudyManager().resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(StudyDBAdaptor.QueryParams.VARIABLE_SET.key(), StudyDBAdaptor.QueryParams.GROUPS.key()))); ObjectMap auditParams = new ObjectMap() @@ -1405,7 +1405,7 @@ private List autoCompleteFamilyMembers(Study study, Family family, L // We remove any possible duplicate ArrayList deduplicatedMemberIds = new ArrayList<>(new HashSet<>(members)); - InternalGetDataResult individualDataResult = catalogManager.getIndividualManager().internalGet(study.getUid(), + InternalGetDataResult individualDataResult = catalogManager.getIndividualManager().internalGet(organizationId, study.getUid(), deduplicatedMemberIds, IndividualManager.INCLUDE_INDIVIDUAL_DISORDERS_PHENOTYPES, userId, false); return individualDataResult.getResults(); diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/FileManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/FileManager.java index d1e64dfdb19..aafc17ec566 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/FileManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/FileManager.java @@ -144,17 +144,17 @@ Enums.Resource getEntity() { } @Override - OpenCGAResult internalGet(long studyUid, String entry, @Nullable Query query, QueryOptions options, String user) + OpenCGAResult internalGet(String organizationId, long studyUid, String entry, @Nullable Query query, QueryOptions options, String user) throws CatalogException { // We make this comparison because in File, the absence of a fileName means the user is actually looking for the / directory if (StringUtils.isNotEmpty(entry) || entry == null) { ParamUtils.checkIsSingleID(entry); } - return internalGet(studyUid, Collections.singletonList(entry), query, options, user, false); + return internalGet(organizationId, studyUid, Collections.singletonList(entry), query, options, user, false); } @Override - InternalGetDataResult internalGet(long studyUid, List entryList, @Nullable Query query, QueryOptions options, + InternalGetDataResult internalGet(String organizationId, long studyUid, List entryList, @Nullable Query query, QueryOptions options, String user, boolean ignoreException) throws CatalogException { if (org.apache.commons.collections4.CollectionUtils.isEmpty(entryList)) { throw new CatalogException("Missing file entries."); @@ -310,7 +310,7 @@ public Study getStudy(File file, String sessionId) throws CatalogException { public void matchUpVariantFiles(String studyStr, List transformedFiles, String sessionId) throws CatalogException { String userId = userManager.getUserId(sessionId); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); for (File transformedFile : transformedFiles) { authorizationManager.checkFilePermission(study.getUid(), transformedFile.getUid(), userId, FilePermissions.WRITE); @@ -521,7 +521,7 @@ public OpenCGAResult createFolder(String studyStr, String path, boolean pa options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); if (path.startsWith("/")) { path = path.substring(1); @@ -556,14 +556,14 @@ public OpenCGAResult createFolder(String studyStr, String path, boolean pa } @Override - public OpenCGAResult create(String studyStr, File entry, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult create(String organizationId, String studyStr, File entry, QueryOptions options, String token) throws CatalogException { throw new NotImplementedException("Call to create passing parents and content variables"); } public OpenCGAResult create(String studyStr, FileCreateParams createParams, boolean parents, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -634,7 +634,7 @@ public OpenCGAResult create(String studyStr, FileCreateParams createParams if (createParams.getType().equals(File.Type.FILE)) { if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(createParams.getSampleIds())) { // Check samples - InternalGetDataResult sampleResult = catalogManager.getSampleManager().internalGet(study.getUid(), + InternalGetDataResult sampleResult = catalogManager.getSampleManager().internalGet(organizationId, study.getUid(), createParams.getSampleIds(), SampleManager.INCLUDE_SAMPLE_IDS, userId, true); if (!sampleResult.getMissing().isEmpty()) { throw new CatalogException("Could not find samples: '" + sampleResult.getMissing() @@ -867,7 +867,7 @@ private void validateNewSamples(Study study, File file, List existingSam String userId = catalogManager.getUserManager().getUserId(sessionId); - InternalGetDataResult sampleResult = catalogManager.getSampleManager().internalGet(study.getUid(), file.getSampleIds(), + InternalGetDataResult sampleResult = catalogManager.getSampleManager().internalGet(organizationId, study.getUid(), file.getSampleIds(), SampleManager.INCLUDE_SAMPLE_IDS, userId, true); existingSamples.addAll(sampleResult.getResults()); @@ -920,7 +920,7 @@ public OpenCGAResult upload(String studyStr, InputStream fileInputStream, calculateChecksum = true; } String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); ObjectMap auditParams = new ObjectMap() .append("studyStr", studyStr) @@ -1136,7 +1136,7 @@ public OpenCGAResult upload(String studyStr, InputStream fileInputStream, public OpenCGAResult moveAndRegister(String studyStr, Path fileSource, @Nullable Path folderDestiny, @Nullable String path, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); ObjectMap auditParams = new ObjectMap() .append("studyStr", studyStr) @@ -1265,7 +1265,7 @@ public OpenCGAResult moveAndRegister(String studyStr, Path fileSource, @Nu @Deprecated public OpenCGAResult get(Long fileId, QueryOptions options, String sessionId) throws CatalogException { - return get(null, String.valueOf(fileId), options, sessionId); + return get(organizationId, null, String.valueOf(fileId), options, sessionId); } public OpenCGAResult getTree(@Nullable String studyId, String fileId, int maxDepth, QueryOptions options, String token) @@ -1275,7 +1275,7 @@ public OpenCGAResult getTree(@Nullable String studyId, String fileId, options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId); + Study study = studyManager.resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -1309,7 +1309,7 @@ public OpenCGAResult getTree(@Nullable String studyId, String fileId, } } - File file = internalGet(study.getUid(), fileId, options, userId).first(); + File file = internalGet(organizationId, study.getUid(), fileId, options, userId).first(); // Check if the id does not correspond to a directory if (!file.getType().equals(File.Type.DIRECTORY)) { @@ -1357,9 +1357,9 @@ public OpenCGAResult getFilesFromFolder(String folderStr, String studyStr, throws CatalogException { ParamUtils.checkObj(folderStr, "folder"); String userId = userManager.getUserId(sessionId); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); - File file = internalGet(study.getUid(), folderStr, new QueryOptions(QueryOptions.INCLUDE, + File file = internalGet(organizationId, study.getUid(), folderStr, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(FileDBAdaptor.QueryParams.PATH.key(), FileDBAdaptor.QueryParams.TYPE.key())), userId).first(); options = ParamUtils.defaultObject(options, QueryOptions::new); @@ -1368,15 +1368,15 @@ public OpenCGAResult getFilesFromFolder(String folderStr, String studyStr, throw new CatalogDBException("File {path:'" + file.getPath() + "'} is not a folder."); } Query query = new Query(FileDBAdaptor.QueryParams.DIRECTORY.key(), file.getPath()); - return search(studyStr, query, options, sessionId); + return search(organizationId, studyStr, query, options, sessionId); } @Override - public DBIterator iterator(String studyStr, Query query, QueryOptions options, String sessionId) throws CatalogException { + public DBIterator iterator(String organizationId, String studyStr, Query query, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(sessionId); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); Query finalQuery = new Query(query); // Fix query if it contains any annotation @@ -1389,13 +1389,13 @@ public DBIterator iterator(String studyStr, Query query, QueryOptions opti } @Override - public OpenCGAResult search(String studyId, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult search(String organizationId, String studyId, Query query, QueryOptions options, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); Query finalQuery = new Query(query); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -1423,11 +1423,11 @@ public OpenCGAResult search(String studyId, Query query, QueryOptions opti } @Override - public OpenCGAResult distinct(String studyId, List fields, Query query, String token) throws CatalogException { + public OpenCGAResult distinct(String organizationId, String studyId, List fields, Query query, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -1501,11 +1501,11 @@ private void validateQueryPath(Query query, String key) { } @Override - public OpenCGAResult count(String studyId, Query query, String token) throws CatalogException { + public OpenCGAResult count(String organizationId, String studyId, Query query, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -1534,14 +1534,14 @@ public OpenCGAResult count(String studyId, Query query, String token) thro } @Override - public OpenCGAResult delete(String studyStr, List fileIds, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, List fileIds, QueryOptions options, String token) throws CatalogException { return delete(studyStr, fileIds, options, false, token); } public OpenCGAResult delete(String studyStr, List fileIds, ObjectMap params, boolean ignoreException, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); String operationUuid = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -1564,7 +1564,7 @@ public OpenCGAResult delete(String studyStr, List fileIds, ObjectMap par String fileUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), id, INCLUDE_FILE_URI_PATH, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, INCLUDE_FILE_URI_PATH, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("File '" + id + "' not found"); } @@ -1604,7 +1604,7 @@ public OpenCGAResult delete(String studyStr, List fileIds, ObjectMap par } @Override - public OpenCGAResult delete(String studyStr, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, Query query, QueryOptions options, String token) throws CatalogException { return delete(studyStr, query, options, false, token); } @@ -1616,7 +1616,7 @@ public OpenCGAResult delete(String studyStr, Query query, ObjectMap params, bool OpenCGAResult dataResult = OpenCGAResult.empty(); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); StopWatch watch = StopWatch.createStarted(); @@ -1739,9 +1739,9 @@ public OpenCGAResult syncUntrackedFiles(String studyId, String folderId, P public OpenCGAResult syncUntrackedFiles(String studyId, String folderId, Predicate filter, String jobId, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId); + Study study = studyManager.resolveId(organizationId, studyId, userId); - File folder = internalGet(study.getUid(), folderId, INCLUDE_FILE_URI_PATH, userId).first(); + File folder = internalGet(organizationId, study.getUid(), folderId, INCLUDE_FILE_URI_PATH, userId).first(); if (folder.getType() == File.Type.FILE) { throw new CatalogException("Provided folder '" + folderId + "' is actually a file"); @@ -1784,7 +1784,7 @@ public OpenCGAResult syncUntrackedFiles(String studyId, String folderId, P } try { - File registeredFile = internalGet(study.getUid(), finalCatalogPath, INCLUDE_FILE_URI_PATH, userId).first(); + File registeredFile = internalGet(organizationId, study.getUid(), finalCatalogPath, INCLUDE_FILE_URI_PATH, userId).first(); if (!registeredFile.getUri().equals(fileUri)) { eventList.add(new Event(Event.Type.WARNING, registeredFile.getPath(), "The uri registered in Catalog '" + registeredFile.getUri().getPath() + "' for the path does not match the uri that would have been synced '" @@ -1809,7 +1809,7 @@ public OpenCGAResult syncUntrackedFiles(String studyId, String folderId, P public OpenCGAResult unlink(@Nullable String studyId, String fileId, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId); + Study study = studyManager.resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() .append("study", studyId) @@ -1819,7 +1819,7 @@ public OpenCGAResult unlink(@Nullable String studyId, String fileId, Strin try { ParamUtils.checkParameter(fileId, "File"); - File file = internalGet(study.getUid(), fileId, QueryOptions.empty(), userId).first(); + File file = internalGet(organizationId, study.getUid(), fileId, QueryOptions.empty(), userId).first(); if (!file.isExternal()) { throw new CatalogException("Only previously linked files can be unlinked. Please, use delete instead."); @@ -1966,7 +1966,7 @@ public OpenCGAResult update(String studyStr, Query query, FileUpdateParams public OpenCGAResult update(String studyStr, Query query, FileUpdateParams updateParams, boolean ignoreException, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -2028,7 +2028,7 @@ public OpenCGAResult update(String studyStr, Query query, FileUpdateParams public OpenCGAResult update(String studyStr, String fileId, FileUpdateParams updateParams, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -2049,7 +2049,7 @@ public OpenCGAResult update(String studyStr, String fileId, FileUpdatePara OpenCGAResult result = OpenCGAResult.empty(); String fileUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), fileId, EXCLUDE_FILE_ATTRIBUTES, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), fileId, EXCLUDE_FILE_ATTRIBUTES, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("File '" + fileId + "' not found"); } @@ -2097,7 +2097,7 @@ public OpenCGAResult update(String studyStr, List fileIds, FileUpd public OpenCGAResult update(String studyStr, List fileIds, FileUpdateParams updateParams, boolean ignoreException, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -2123,7 +2123,7 @@ public OpenCGAResult update(String studyStr, List fileIds, FileUpd String fileUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), fileId, EXCLUDE_FILE_ATTRIBUTES, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), fileId, EXCLUDE_FILE_ATTRIBUTES, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("File '" + id + "' not found"); } @@ -2191,7 +2191,7 @@ private OpenCGAResult update(Study study, File file, FileUpdateParams upda if (StringUtils.isEmpty(relatedFile.getFile()) || relatedFile.getRelation() == null) { throw new CatalogException("Missing file or relation in relatedFiles list"); } - File relatedFileFile = internalGet(study.getUid(), relatedFile.getFile(), null, INCLUDE_FILE_URI_PATH, userId).first(); + File relatedFileFile = internalGet(organizationId, study.getUid(), relatedFile.getFile(), null, INCLUDE_FILE_URI_PATH, userId).first(); relatedFileList.add(new FileRelatedFile(relatedFileFile, relatedFile.getRelation())); } parameters.put(FileDBAdaptor.QueryParams.RELATED_FILES.key(), relatedFileList); @@ -2222,7 +2222,7 @@ private OpenCGAResult update(Study study, File file, FileUpdateParams upda // We make a query to check both if the samples exists and if the user has permissions to see them if (updateParams != null && ListUtils.isNotEmpty(updateParams.getSampleIds())) { - catalogManager.getSampleManager().internalGet(study.getUid(), updateParams.getSampleIds(), SampleManager.INCLUDE_SAMPLE_IDS, + catalogManager.getSampleManager().internalGet(organizationId, study.getUid(), updateParams.getSampleIds(), SampleManager.INCLUDE_SAMPLE_IDS, userId, false); } @@ -2252,9 +2252,9 @@ public OpenCGAResult update(String studyStr, String entryStr, ObjectMap pa options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); - File file = internalGet(study.getUid(), entryStr, QueryOptions.empty(), userId).first(); + File file = internalGet(organizationId, study.getUid(), entryStr, QueryOptions.empty(), userId).first(); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -2285,7 +2285,7 @@ public OpenCGAResult update(String studyStr, String entryStr, ObjectMap pa if (parameters.get(FileDBAdaptor.QueryParams.SAMPLE_IDS.key()) != null && ListUtils.isNotEmpty(parameters.getAsStringList(FileDBAdaptor.QueryParams.SAMPLE_IDS.key()))) { List sampleIds = parameters.getAsStringList(FileDBAdaptor.QueryParams.SAMPLE_IDS.key()); - catalogManager.getSampleManager().internalGet(study.getUid(), sampleIds, SampleManager.INCLUDE_SAMPLE_IDS, userId, false); + catalogManager.getSampleManager().internalGet(organizationId, study.getUid(), sampleIds, SampleManager.INCLUDE_SAMPLE_IDS, userId, false); } //Name must be changed with "rename". @@ -2327,7 +2327,7 @@ public OpenCGAResult link(String studyStr, FileLinkParams params, boolean // We make two attempts to link to ensure the behaviour remains even if it is being called at the same time link from different // threads String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -2370,14 +2370,14 @@ public OpenCGAResult link(String studyStr, URI uriOrigin, String pathDesti } @Override - public OpenCGAResult rank(String studyStr, Query query, String field, int numResults, boolean asc, String sessionId) + public OpenCGAResult rank(String organizationId, String studyStr, Query query, String field, int numResults, boolean asc, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); ParamUtils.checkObj(field, "field"); ParamUtils.checkObj(sessionId, "sessionId"); String userId = userManager.getUserId(sessionId); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); authorizationManager.checkStudyPermission(study.getUid(), userId, StudyPermissions.Permissions.VIEW_FILES); @@ -2394,7 +2394,7 @@ public OpenCGAResult rank(String studyStr, Query query, String field, int numRes } @Override - public OpenCGAResult groupBy(@Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) + public OpenCGAResult groupBy(String organizationId, @Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); @@ -2403,7 +2403,7 @@ public OpenCGAResult groupBy(@Nullable String studyStr, Query query, List rename(String studyStr, String fileStr, String newName, Stri ParamUtils.checkFileName(newName, "name"); String userId = userManager.getUserId(sessionId); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); - File file = internalGet(study.getUid(), fileStr, EXCLUDE_FILE_ATTRIBUTES, userId).first(); + File file = internalGet(organizationId, study.getUid(), fileStr, EXCLUDE_FILE_ATTRIBUTES, userId).first(); authorizationManager.checkFilePermission(study.getUid(), file.getUid(), userId, FilePermissions.WRITE); if (file.getName().equals(newName)) { @@ -2483,7 +2483,7 @@ public OpenCGAResult grep(String studyId, String fileId, String pat long startTime = System.currentTimeMillis(); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId); + Study study = studyManager.resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -2493,7 +2493,7 @@ public OpenCGAResult grep(String studyId, String fileId, String pat .append("numLines", numLines) .append("token", token); try { - File file = internalGet(study.getUid(), fileId, INCLUDE_FILE_URI, userId).first(); + File file = internalGet(organizationId, study.getUid(), fileId, INCLUDE_FILE_URI, userId).first(); authorizationManager.checkFilePermission(study.getUid(), file.getUid(), userId, FilePermissions.VIEW_CONTENT); URI fileUri = getUri(file); @@ -2518,7 +2518,7 @@ public OpenCGAResult grep(String studyId, String fileId, String pat public OpenCGAResult image(String studyStr, String fileId, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); long startTime = System.currentTimeMillis(); @@ -2528,7 +2528,7 @@ public OpenCGAResult image(String studyStr, String fileId, String t .append("token", token); File file; try { - file = internalGet(study.getUid(), fileId, INCLUDE_FILE_URI_PATH, userId).first(); + file = internalGet(organizationId, study.getUid(), fileId, INCLUDE_FILE_URI_PATH, userId).first(); authorizationManager.checkFilePermission(study.getUid(), file.getUid(), userId, FilePermissions.VIEW_CONTENT); if (file.getFormat() != File.Format.IMAGE) { @@ -2557,7 +2557,7 @@ public OpenCGAResult image(String studyStr, String fileId, String t public OpenCGAResult head(String studyStr, String fileId, long offset, int lines, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); long startTime = System.currentTimeMillis(); @@ -2569,7 +2569,7 @@ public OpenCGAResult head(String studyStr, String fileId, long offs .append("token", token); File file; try { - file = internalGet(study.getUid(), fileId, INCLUDE_FILE_URI, userId).first(); + file = internalGet(organizationId, study.getUid(), fileId, INCLUDE_FILE_URI, userId).first(); authorizationManager.checkFilePermission(study.getUid(), file.getUid(), userId, FilePermissions.VIEW_CONTENT); URI fileUri = getUri(file); FileContent fileContent; @@ -2592,7 +2592,7 @@ public OpenCGAResult head(String studyStr, String fileId, long offs public OpenCGAResult tail(String studyStr, String fileId, int lines, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); long startTime = System.currentTimeMillis(); @@ -2603,7 +2603,7 @@ public OpenCGAResult tail(String studyStr, String fileId, int lines .append("token", token); File file; try { - file = internalGet(study.getUid(), fileId, INCLUDE_FILE_URI, userId).first(); + file = internalGet(organizationId, study.getUid(), fileId, INCLUDE_FILE_URI, userId).first(); authorizationManager.checkFilePermission(study.getUid(), file.getUid(), userId, FilePermissions.VIEW_CONTENT); URI fileUri = getUri(file); FileContent fileContent; @@ -2630,7 +2630,7 @@ public DataInputStream download(String studyStr, String fileId, String token) th public DataInputStream download(String studyStr, String fileId, int start, int limit, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -2640,7 +2640,7 @@ public DataInputStream download(String studyStr, String fileId, int start, int l .append("token", token); File file; try { - file = internalGet(study.getUid(), fileId, INCLUDE_FILE_URI, userId).first(); + file = internalGet(organizationId, study.getUid(), fileId, INCLUDE_FILE_URI, userId).first(); authorizationManager.checkFilePermission(study.getUid(), file.getUid(), userId, FilePermissions.DOWNLOAD); URI fileUri = getUri(file); DataInputStream dataInputStream; @@ -2670,7 +2670,7 @@ public OpenCGAResult> getAcls(String studyId, List public OpenCGAResult> getAcls(String studyId, List fileList, List members, boolean ignoreException, String token) throws CatalogException { String user = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, user); + Study study = studyManager.resolveId(organizationId, studyId, user); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); ObjectMap auditParams = new ObjectMap() @@ -2684,7 +2684,7 @@ public OpenCGAResult> getAcls(String studyId, List Map missingMap = new HashMap<>(); try { auditManager.initAuditBatch(operationId); - InternalGetDataResult queryResult = internalGet(study.getUid(), fileList, INCLUDE_FILE_IDS, user, ignoreException); + InternalGetDataResult queryResult = internalGet(organizationId, study.getUid(), fileList, INCLUDE_FILE_IDS, user, ignoreException); if (queryResult.getMissing() != null) { missingMap = queryResult.getMissing().stream() @@ -2749,7 +2749,7 @@ public OpenCGAResult> updateAcl(String studyId, Li String token) throws CatalogException { String user = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, user); + Study study = studyManager.resolveId(organizationId, studyId, user); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -2786,14 +2786,14 @@ public OpenCGAResult> updateAcl(String studyId, Li List extendedFileList; if (StringUtils.isNotEmpty(aclParams.getSample())) { // Obtain the sample ids - OpenCGAResult sampleDataResult = catalogManager.getSampleManager().internalGet(study.getUid(), + OpenCGAResult sampleDataResult = catalogManager.getSampleManager().internalGet(organizationId, study.getUid(), Arrays.asList(StringUtils.split(aclParams.getSample(), ",")), SampleManager.INCLUDE_SAMPLE_IDS, user, false); Query query = new Query(FileDBAdaptor.QueryParams.SAMPLE_IDS.key(), sampleDataResult.getResults().stream().map(Sample::getId).collect(Collectors.toList())); - extendedFileList = catalogManager.getFileManager().search(studyId, query, EXCLUDE_FILE_ATTRIBUTES, token).getResults(); + extendedFileList = catalogManager.getFileManager().search(organizationId, studyId, query, EXCLUDE_FILE_ATTRIBUTES, token).getResults(); } else { - extendedFileList = internalGet(study.getUid(), fileStrList, EXCLUDE_FILE_ATTRIBUTES, user, false).getResults(); + extendedFileList = internalGet(organizationId, study.getUid(), fileStrList, EXCLUDE_FILE_ATTRIBUTES, user, false).getResults(); } authorizationManager.checkCanAssignOrSeePermissions(study.getUid(), user); @@ -2863,7 +2863,7 @@ public OpenCGAResult> updateAcl(String studyId, Li public OpenCGAResult getParents(String studyStr, String path, boolean rootFirst, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); List paths = calculateAllPossiblePaths(path); @@ -3031,7 +3031,7 @@ private boolean isExternal(Study study, String catalogFilePath, URI fileUri) thr */ public void checkCanDeleteFile(String studyStr, String fileId, boolean unlink, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); checkCanDeleteFile(study, fileId, unlink, Arrays.asList(FileStatus.READY, FileStatus.TRASHED), userId); } @@ -3056,7 +3056,7 @@ private void checkCanDeleteFile(Study study, String fileId, boolean unlink, List FileDBAdaptor.QueryParams.SIZE.key(), FileDBAdaptor.QueryParams.URI.key(), FileDBAdaptor.QueryParams.PATH.key(), FileDBAdaptor.QueryParams.INTERNAL.key(), FileDBAdaptor.QueryParams.EXTERNAL.key())); - OpenCGAResult fileOpenCGAResult = internalGet(study.getUid(), fileId, options, userId); + OpenCGAResult fileOpenCGAResult = internalGet(organizationId, study.getUid(), fileId, options, userId); if (fileOpenCGAResult.getNumResults() == 0) { throw new CatalogException("File " + fileId + " not found"); } @@ -3209,7 +3209,7 @@ public DataResult facet(String studyId, Query query, QueryOptions op String userId = userManager.getUserId(token); // We need to add variableSets and groups to avoid additional queries as it will be used in the catalogSolrManager - Study study = studyManager.resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(StudyDBAdaptor.QueryParams.VARIABLE_SET.key(), StudyDBAdaptor.QueryParams.GROUPS.key()))); ObjectMap auditParams = new ObjectMap() @@ -3422,7 +3422,7 @@ private OpenCGAResult privateLink(Study study, FileLinkParams params, bool if (relatedFilesParams != null) { relatedFiles = new ArrayList<>(relatedFilesParams.size()); for (SmallRelatedFileParams relatedFileParams : relatedFilesParams) { - File tmpFile = internalGet(study.getUid(), relatedFileParams.getFile(), INCLUDE_FILE_URI_PATH, userId).first(); + File tmpFile = internalGet(organizationId, study.getUid(), relatedFileParams.getFile(), INCLUDE_FILE_URI_PATH, userId).first(); relatedFiles.add(new FileRelatedFile(tmpFile, relatedFileParams.getRelation())); } } else { @@ -3705,7 +3705,7 @@ OpenCGAResult registerFile(Study study, String filePath, URI fileUri, Stri long size = ioManager.getFileSize(fileUri); String parentPath = getParentPath(filePath); - File parentFile = internalGet(study.getUid(), parentPath, INCLUDE_FILE_URI_PATH, userId).first(); + File parentFile = internalGet(organizationId, study.getUid(), parentPath, INCLUDE_FILE_URI_PATH, userId).first(); // We obtain the permissions set in the parent folder and set them to the file or folder being created OpenCGAResult> allFileAcls = authorizationManager.getAcls(study.getUid(), parentFile.getUid(), Enums.Resource.FILE, FilePermissions.class); diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/FileUtils.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/FileUtils.java index 46423ef9a2f..31a9c54c7ad 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/FileUtils.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/FileUtils.java @@ -98,7 +98,7 @@ public File checkFile(String studyStr, File file, boolean calculateChecksum, Str ObjectMap params = new ObjectMap(FileDBAdaptor.UpdateParams.INTERNAL_STATUS.key(), new FileStatus(FileStatus.MISSING)); catalogManager.getFileManager().update(studyStr, file.getPath(), params, null, sessionId); - modifiedFile = catalogManager.getFileManager().get(studyStr, file.getPath(), null, sessionId).first(); + modifiedFile = catalogManager.getFileManager().get(organizationId, studyStr, file.getPath(), null, sessionId).first(); } } else if (file.getInternal().getStatus().getId().equals(FileStatus.MISSING)) { logger.info("File { path:\"" + file.getPath() + "\" } recover tracking from file " + fileUri); @@ -107,7 +107,7 @@ public File checkFile(String studyStr, File file, boolean calculateChecksum, Str params.put(FileDBAdaptor.UpdateParams.INTERNAL_STATUS.key(), new FileStatus(FileStatus.READY)); catalogManager.getFileManager().update(studyStr, file.getPath(), params, QueryOptions.empty(), sessionId); - modifiedFile = catalogManager.getFileManager().get(studyStr, file.getPath(), null, sessionId).first(); + modifiedFile = catalogManager.getFileManager().get(organizationId, studyStr, file.getPath(), null, sessionId).first(); } break; } diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/IndividualManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/IndividualManager.java index 07d03a295ce..f621f03d2a3 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/IndividualManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/IndividualManager.java @@ -143,7 +143,7 @@ Enums.Resource getEntity() { // } @Override - InternalGetDataResult internalGet(long studyUid, List entryList, @Nullable Query query, QueryOptions options, + InternalGetDataResult internalGet(String organizationId, long studyUid, List entryList, @Nullable Query query, QueryOptions options, String user, boolean ignoreException) throws CatalogException { if (ListUtils.isEmpty(entryList)) { throw new CatalogException("Missing individual entries."); @@ -258,12 +258,12 @@ void validateNewIndividual(Study study, Individual individual, List samp if (linkParents) { if (individual.getFather() != null && StringUtils.isNotEmpty(individual.getFather().getId())) { - OpenCGAResult fatherResult = internalGet(study.getUid(), individual.getFather().getId(), INCLUDE_INDIVIDUAL_IDS, + OpenCGAResult fatherResult = internalGet(organizationId, study.getUid(), individual.getFather().getId(), INCLUDE_INDIVIDUAL_IDS, userId); individual.setFather(fatherResult.first()); } if (individual.getMother() != null && StringUtils.isNotEmpty(individual.getMother().getId())) { - OpenCGAResult motherResult = internalGet(study.getUid(), individual.getMother().getId(), INCLUDE_INDIVIDUAL_IDS, + OpenCGAResult motherResult = internalGet(organizationId, study.getUid(), individual.getMother().getId(), INCLUDE_INDIVIDUAL_IDS, userId); individual.setMother(motherResult.first()); } @@ -288,7 +288,7 @@ private void validateSamples(Study study, Individual individual, List sa // We remove any possible duplicate ArrayList deduplicatedSampleIds = new ArrayList<>(new HashSet<>(samples)); - InternalGetDataResult sampleDataResult = catalogManager.getSampleManager().internalGet(study.getUid(), + InternalGetDataResult sampleDataResult = catalogManager.getSampleManager().internalGet(organizationId, study.getUid(), deduplicatedSampleIds, SampleManager.INCLUDE_SAMPLE_IDS, userId, false); // Check the samples are not attached to other individual @@ -303,7 +303,7 @@ private void validateSamples(Study study, Individual individual, List sa } @Override - public OpenCGAResult create(String studyStr, Individual individual, QueryOptions options, String token) + public OpenCGAResult create(String organizationId, String studyStr, Individual individual, QueryOptions options, String token) throws CatalogException { return create(studyStr, individual, null, options, token); } @@ -313,7 +313,7 @@ public OpenCGAResult create(String studyStr, Individual individual, options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -376,13 +376,13 @@ private void checkSamplesNotInUseInOtherIndividual(Set sampleIds, long stu } @Override - public DBIterator iterator(String studyStr, Query query, QueryOptions options, String sessionId) throws CatalogException { + public DBIterator iterator(String organizationId, String studyStr, Query query, QueryOptions options, String sessionId) throws CatalogException { ParamUtils.checkObj(sessionId, "sessionId"); query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(sessionId); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); Query finalQuery = new Query(query); fixQuery(study, finalQuery, userId); @@ -395,13 +395,13 @@ public DBIterator iterator(String studyStr, Query query, QueryOption } @Override - public OpenCGAResult search(String studyId, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult search(String organizationId, String studyId, Query query, QueryOptions options, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); Query finalQuery = new Query(query); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -432,11 +432,11 @@ public OpenCGAResult search(String studyId, Query query, QueryOption } @Override - public OpenCGAResult distinct(String studyId, List fields, Query query, String token) throws CatalogException { + public OpenCGAResult distinct(String organizationId, String studyId, List fields, Query query, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -464,12 +464,12 @@ public OpenCGAResult distinct(String studyId, List fields, Query quer } @Override - public OpenCGAResult count(String studyId, Query query, String token) throws CatalogException { + public OpenCGAResult count(String organizationId, String studyId, Query query, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); Query finalQuery = new Query(query); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -499,7 +499,7 @@ public OpenCGAResult count(String studyId, Query query, String token public OpenCGAResult relatives(String studyId, String individualId, int degree, QueryOptions options, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = studyManager.resolveId(studyId, userId); + Study study = studyManager.resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -519,7 +519,7 @@ public OpenCGAResult relatives(String studyId, String individualId, } List individualList = new LinkedList<>(); - Individual proband = internalGet(study.getUid(), individualId, queryOptions, userId).first(); + Individual proband = internalGet(organizationId, study.getUid(), individualId, queryOptions, userId).first(); individualDBAdaptor.addRelativeToList(proband, Family.FamiliarRelationship.PROBAND, 0, individualList); individualId = proband.getId(); @@ -548,14 +548,14 @@ public OpenCGAResult relatives(String studyId, String individualId, } @Override - public OpenCGAResult delete(String studyStr, List individualIds, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, List individualIds, QueryOptions options, String token) throws CatalogException { return delete(studyStr, individualIds, options, false, token); } public OpenCGAResult delete(String studyStr, List individualIds, ObjectMap params, boolean ignoreException, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); String operationUuid = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -584,7 +584,7 @@ public OpenCGAResult delete(String studyStr, List individualIds, ObjectM String individualUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), id, INCLUDE_INDIVIDUAL_IDS, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, INCLUDE_INDIVIDUAL_IDS, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Individual '" + id + "' not found"); } @@ -619,7 +619,7 @@ public OpenCGAResult delete(String studyStr, List individualIds, ObjectM } @Override - public OpenCGAResult delete(String studyStr, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, Query query, QueryOptions options, String token) throws CatalogException { return delete(studyStr, query, options, false, token); } @@ -629,7 +629,7 @@ public OpenCGAResult delete(String studyStr, Query query, ObjectMap params, bool OpenCGAResult result = OpenCGAResult.empty(); String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationUuid = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -802,7 +802,7 @@ public OpenCGAResult update(String studyStr, Query query, Individual public OpenCGAResult update(String studyStr, Query query, IndividualUpdateParams updateParams, boolean ignoreException, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -867,7 +867,7 @@ public OpenCGAResult update(String studyStr, Query query, Individual public OpenCGAResult update(String studyStr, String individualId, IndividualUpdateParams updateParams, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -889,7 +889,7 @@ public OpenCGAResult update(String studyStr, String individualId, In String individualUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), individualId, QueryOptions.empty(), userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), individualId, QueryOptions.empty(), userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Individual '" + individualId + "' not found"); } @@ -938,7 +938,7 @@ public OpenCGAResult update(String studyStr, List individual public OpenCGAResult update(String studyStr, List individualIds, IndividualUpdateParams updateParams, boolean ignoreException, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -964,7 +964,7 @@ public OpenCGAResult update(String studyStr, List individual String individualUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), id, QueryOptions.empty(), userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, QueryOptions.empty(), userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Individual '" + id + "' not found"); } @@ -1075,7 +1075,7 @@ private OpenCGAResult update(Study study, Individual individual, IndividualUpdat throw new CatalogException("Missing id or uuid in 'samples'"); } } - List sampleList = catalogManager.getSampleManager().internalGet(studyUid, idList, SampleManager.INCLUDE_SAMPLE_IDS, + List sampleList = catalogManager.getSampleManager().internalGet(organizationId, studyUid, idList, SampleManager.INCLUDE_SAMPLE_IDS, userId, false).getResults(); // Check those samples are not in use by other individuals @@ -1090,7 +1090,7 @@ private OpenCGAResult update(Study study, Individual individual, IndividualUpdat if (StringUtils.isNotEmpty(updateParams.getFather().getId()) || StringUtils.isNotEmpty(updateParams.getFather().getUuid())) { String fatherId = StringUtils.isNotEmpty(updateParams.getFather().getId()) ? updateParams.getFather().getId() : updateParams.getFather().getUuid(); - OpenCGAResult queryResult = internalGet(studyUid, fatherId, INCLUDE_INDIVIDUAL_IDS, userId); + OpenCGAResult queryResult = internalGet(organizationId, studyUid, fatherId, INCLUDE_INDIVIDUAL_IDS, userId); parameters.put(IndividualDBAdaptor.QueryParams.FATHER_UID.key(), queryResult.first().getUid()); } else { parameters.put(IndividualDBAdaptor.QueryParams.FATHER_UID.key(), -1L); @@ -1101,7 +1101,7 @@ private OpenCGAResult update(Study study, Individual individual, IndividualUpdat if (StringUtils.isNotEmpty(updateParams.getMother().getId()) || StringUtils.isNotEmpty(updateParams.getMother().getUuid())) { String motherId = StringUtils.isNotEmpty(updateParams.getMother().getId()) ? updateParams.getMother().getId() : updateParams.getMother().getUuid(); - OpenCGAResult queryResult = internalGet(studyUid, motherId, INCLUDE_INDIVIDUAL_IDS, userId); + OpenCGAResult queryResult = internalGet(organizationId, studyUid, motherId, INCLUDE_INDIVIDUAL_IDS, userId); parameters.put(IndividualDBAdaptor.QueryParams.MOTHER_UID.key(), queryResult.first().getUid()); } else { parameters.put(IndividualDBAdaptor.QueryParams.MOTHER_UID.key(), -1L); @@ -1123,14 +1123,14 @@ private OpenCGAResult update(Study study, Individual individual, IndividualUpdat } @Override - public OpenCGAResult rank(String studyStr, Query query, String field, int numResults, boolean asc, String sessionId) + public OpenCGAResult rank(String organizationId, String studyStr, Query query, String field, int numResults, boolean asc, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); ParamUtils.checkObj(field, "field"); ParamUtils.checkObj(sessionId, "sessionId"); String userId = userManager.getUserId(sessionId); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); authorizationManager.checkStudyPermission(study.getUid(), userId, StudyPermissions.Permissions.VIEW_INDIVIDUALS); @@ -1150,14 +1150,14 @@ public OpenCGAResult rank(String studyStr, Query query, String field, int numRes } @Override - public OpenCGAResult groupBy(@Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) + public OpenCGAResult groupBy(String organizationId, @Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); ParamUtils.checkObj(fields, "fields"); String userId = userManager.getUserId(sessionId); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); Query finalQuery = new Query(query); @@ -1194,7 +1194,7 @@ public OpenCGAResult> getAcls(String studyId List members, boolean ignoreException, String token) throws CatalogException { String user = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, user); + Study study = studyManager.resolveId(organizationId, studyId, user); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); ObjectMap auditParams = new ObjectMap() @@ -1208,7 +1208,7 @@ public OpenCGAResult> getAcls(String studyId Map missingMap = new HashMap<>(); try { auditManager.initAuditBatch(operationId); - InternalGetDataResult queryResult = internalGet(study.getUid(), individualList, INCLUDE_INDIVIDUAL_IDS, user, + InternalGetDataResult queryResult = internalGet(organizationId, study.getUid(), individualList, INCLUDE_INDIVIDUAL_IDS, user, ignoreException); if (queryResult.getMissing() != null) { @@ -1276,7 +1276,7 @@ public OpenCGAResult> updateAcl(String study ParamUtils.AclAction action, boolean propagate, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId, StudyManager.INCLUDE_STUDY_UID); + Study study = studyManager.resolveId(organizationId, studyId, userId, StudyManager.INCLUDE_STUDY_UID); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -1314,13 +1314,13 @@ public OpenCGAResult> updateAcl(String study if (StringUtils.isNotEmpty(aclParams.getSample())) { Query query = new Query(IndividualDBAdaptor.QueryParams.SAMPLES.key(), aclParams.getSample()); QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, IndividualDBAdaptor.QueryParams.ID.key()); - OpenCGAResult indDataResult = catalogManager.getIndividualManager().search(studyId, query, options, token); + OpenCGAResult indDataResult = catalogManager.getIndividualManager().search(organizationId, studyId, query, options, token); individualStrList = indDataResult.getResults().stream().map(Individual::getId).collect(Collectors.toList()); } // Obtain the resource ids - List individualList = internalGet(study.getUid(), individualStrList, INCLUDE_INDIVIDUAL_IDS, userId, false) + List individualList = internalGet(organizationId, study.getUid(), individualStrList, INCLUDE_INDIVIDUAL_IDS, userId, false) .getResults(); authorizationManager.checkCanAssignOrSeePermissions(study.getUid(), userId); @@ -1397,7 +1397,7 @@ public DataResult facet(String studyId, Query query, QueryOptions op String userId = userManager.getUserId(token); // We need to add variableSets and groups to avoid additional queries as it will be used in the catalogSolrManager - Study study = catalogManager.getStudyManager().resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(StudyDBAdaptor.QueryParams.VARIABLE_SET.key(), StudyDBAdaptor.QueryParams.GROUPS.key()))); ObjectMap auditParams = new ObjectMap() @@ -1462,7 +1462,7 @@ private void fixQuery(Study study, Query query, String userId) throws CatalogExc if (query.containsKey(IndividualDBAdaptor.QueryParams.FATHER.key())) { if (StringUtils.isNotEmpty(query.getString(IndividualDBAdaptor.QueryParams.FATHER.key()))) { - Individual ind = internalGet(study.getUid(), query.getString(IndividualDBAdaptor.QueryParams.FATHER.key()), + Individual ind = internalGet(organizationId, study.getUid(), query.getString(IndividualDBAdaptor.QueryParams.FATHER.key()), INCLUDE_INDIVIDUAL_IDS, userId).first(); query.append(IndividualDBAdaptor.QueryParams.FATHER_UID.key(), ind.getUid()); } @@ -1470,7 +1470,7 @@ private void fixQuery(Study study, Query query, String userId) throws CatalogExc } if (query.containsKey(IndividualDBAdaptor.QueryParams.MOTHER.key())) { if (StringUtils.isNotEmpty(query.getString(IndividualDBAdaptor.QueryParams.MOTHER.key()))) { - Individual ind = internalGet(study.getUid(), query.getString(IndividualDBAdaptor.QueryParams.MOTHER.key()), + Individual ind = internalGet(organizationId, study.getUid(), query.getString(IndividualDBAdaptor.QueryParams.MOTHER.key()), INCLUDE_INDIVIDUAL_IDS, userId).first(); query.append(IndividualDBAdaptor.QueryParams.MOTHER_UID.key(), ind.getUid()); } @@ -1478,7 +1478,7 @@ private void fixQuery(Study study, Query query, String userId) throws CatalogExc } if (query.containsKey(IndividualDBAdaptor.QueryParams.SAMPLES.key())) { if (StringUtils.isNotEmpty(query.getString(IndividualDBAdaptor.QueryParams.SAMPLES.key()))) { - OpenCGAResult sampleDataResult = catalogManager.getSampleManager().internalGet(study.getUid(), + OpenCGAResult sampleDataResult = catalogManager.getSampleManager().internalGet(organizationId, study.getUid(), query.getAsStringList(IndividualDBAdaptor.QueryParams.SAMPLES.key()), SampleManager.INCLUDE_SAMPLE_IDS, userId, true); query.append(IndividualDBAdaptor.QueryParams.SAMPLE_UIDS.key(), sampleDataResult.getResults().stream().map(Sample::getUid) diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/InterpretationManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/InterpretationManager.java index 4294998ca19..282400cce95 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/InterpretationManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/InterpretationManager.java @@ -98,7 +98,7 @@ Enums.Resource getEntity() { } @Override - InternalGetDataResult internalGet(long studyUid, List entryList, @Nullable Query query, QueryOptions options, + InternalGetDataResult internalGet(String organizationId, long studyUid, List entryList, @Nullable Query query, QueryOptions options, String user, boolean ignoreException) throws CatalogException { if (ListUtils.isEmpty(entryList)) { throw new CatalogException("Missing interpretation entries."); @@ -152,7 +152,7 @@ InternalGetDataResult internalGet(long studyUid, List en Interpretation interpretation = iterator.next(); // Check if the user has access to the corresponding clinical analysis try { - catalogManager.getClinicalAnalysisManager().internalGet(studyUid, + catalogManager.getClinicalAnalysisManager().internalGet(organizationId, studyUid, interpretation.getClinicalAnalysisId(), ClinicalAnalysisManager.INCLUDE_CLINICAL_IDS, user); } catch (CatalogAuthorizationException e) { if (ignoreException) { @@ -169,7 +169,7 @@ InternalGetDataResult internalGet(long studyUid, List en interpretationList = interpretationDataResult.getResults(); Interpretation interpretation = interpretationDataResult.first(); try { - catalogManager.getClinicalAnalysisManager().internalGet(studyUid, + catalogManager.getClinicalAnalysisManager().internalGet(organizationId, studyUid, interpretation.getClinicalAnalysisId(), ClinicalAnalysisManager.INCLUDE_CLINICAL_IDS, user); } catch (CatalogAuthorizationException e) { if (!ignoreException) { @@ -190,7 +190,7 @@ InternalGetDataResult internalGet(long studyUid, List en } @Override - public OpenCGAResult create(String studyStr, Interpretation entry, QueryOptions options, String sessionId) + public OpenCGAResult create(String organizationId, String studyStr, Interpretation entry, QueryOptions options, String sessionId) throws CatalogException { throw new CatalogException("Non-supported. Use other create method"); } @@ -200,7 +200,7 @@ public OpenCGAResult create(String studyStr, String clinicalAnal throws CatalogException { // We check if the user can create interpretations in the clinical analysis String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -217,7 +217,7 @@ public OpenCGAResult create(String studyStr, String clinicalAnal ClinicalAnalysisDBAdaptor.QueryParams.AUDIT.key(), ClinicalAnalysisDBAdaptor.QueryParams.INTERPRETATION_ID.key(), ClinicalAnalysisDBAdaptor.QueryParams.SECONDARY_INTERPRETATIONS_ID.key())); - ClinicalAnalysis clinicalAnalysis = catalogManager.getClinicalAnalysisManager().internalGet(study.getUid(), clinicalAnalysisStr, + ClinicalAnalysis clinicalAnalysis = catalogManager.getClinicalAnalysisManager().internalGet(organizationId, study.getUid(), clinicalAnalysisStr, clinicalOptions, userId).first(); authorizationManager.checkClinicalAnalysisPermission(study.getUid(), clinicalAnalysis.getUid(), @@ -394,7 +394,7 @@ void validateNewInterpretation(Study study, Interpretation interpretation, Clini public OpenCGAResult clear(String studyStr, String clinicalAnalysisId, List interpretationList, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -411,7 +411,7 @@ public OpenCGAResult clear(String studyStr, String clinicalAnaly try { QueryOptions clinicalOptions = keepFieldInQueryOptions(INCLUDE_CLINICAL_ANALYSIS, ClinicalAnalysisDBAdaptor.QueryParams.PANELS.key()); - OpenCGAResult clinicalResult = catalogManager.getClinicalAnalysisManager().internalGet(study.getUid(), + OpenCGAResult clinicalResult = catalogManager.getClinicalAnalysisManager().internalGet(organizationId, study.getUid(), clinicalAnalysisId, clinicalOptions, userId); if (clinicalResult.getNumResults() == 0) { throw new CatalogException("ClinicalAnalysis '" + clinicalAnalysisId + "' not found"); @@ -422,7 +422,7 @@ public OpenCGAResult clear(String studyStr, String clinicalAnaly + "made to the Interpretation."); } - OpenCGAResult tmpResult = internalGet(study.getUid(), interpretationStr, INCLUDE_INTERPRETATION_IDS, + OpenCGAResult tmpResult = internalGet(organizationId, study.getUid(), interpretationStr, INCLUDE_INTERPRETATION_IDS, userId); if (tmpResult.getNumResults() == 0) { throw new CatalogException("Interpretation '" + interpretationStr + "' not found."); @@ -630,7 +630,7 @@ public OpenCGAResult update(String studyStr, Query query, Interp options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -703,7 +703,7 @@ public OpenCGAResult update(String studyStr, String clinicalAnal options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -730,7 +730,7 @@ public OpenCGAResult update(String studyStr, String clinicalAnal ParamUtils.checkParameter(clinicalAnalysisId, "ClinicalAnalysisId"); ParamUtils.checkParameter(intepretationId, "InterpretationId"); - OpenCGAResult interpretationOpenCGAResult = internalGet(study.getUid(), intepretationId, + OpenCGAResult interpretationOpenCGAResult = internalGet(organizationId, study.getUid(), intepretationId, INCLUDE_INTERPRETATION_FINDING_IDS, userId); if (interpretationOpenCGAResult.getNumResults() == 0) { throw new CatalogException("Interpretation '" + interpretationId + "' not found."); @@ -801,7 +801,7 @@ public OpenCGAResult update(String studyStr, String clinicalAnal options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -829,7 +829,7 @@ public OpenCGAResult update(String studyStr, String clinicalAnal String interpretationUuid = ""; try { - OpenCGAResult tmpResult = internalGet(study.getUid(), interpretationId, INCLUDE_INTERPRETATION_FINDING_IDS, + OpenCGAResult tmpResult = internalGet(organizationId, study.getUid(), interpretationId, INCLUDE_INTERPRETATION_FINDING_IDS, userId); if (tmpResult.getNumResults() == 0) { throw new CatalogException("Interpretation '" + interpretationId + "' not found."); @@ -887,7 +887,7 @@ private OpenCGAResult update(Study study, Interpretation interpretation, Interpr Map actionMap = options.getMap(Constants.ACTIONS); // Check if user has permissions to write clinical analysis - ClinicalAnalysis clinicalAnalysis = catalogManager.getClinicalAnalysisManager().internalGet(study.getUid(), + ClinicalAnalysis clinicalAnalysis = catalogManager.getClinicalAnalysisManager().internalGet(organizationId, study.getUid(), interpretation.getClinicalAnalysisId(), INCLUDE_CLINICAL_ANALYSIS, userId).first(); authorizationManager.checkClinicalAnalysisPermission(study.getUid(), clinicalAnalysis.getUid(), userId, ClinicalAnalysisPermissions.WRITE); @@ -1075,7 +1075,7 @@ private OpenCGAResult update(Study study, Interpretation interpretation, Interpr public OpenCGAResult revert(String studyStr, String clinicalAnalysisId, String interpretationId, int version, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_CONFIGURATION); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -1086,7 +1086,7 @@ public OpenCGAResult revert(String studyStr, String clinicalAnal String interpretationUuid = ""; try { - OpenCGAResult clinicalResult = catalogManager.getClinicalAnalysisManager().internalGet(study.getUid(), + OpenCGAResult clinicalResult = catalogManager.getClinicalAnalysisManager().internalGet(organizationId, study.getUid(), clinicalAnalysisId, INCLUDE_CLINICAL_ANALYSIS, userId); if (clinicalResult.getNumResults() == 0) { throw new CatalogException("Could not find ClinicalAnalysis '" + clinicalAnalysisId + "'"); @@ -1103,7 +1103,7 @@ public OpenCGAResult revert(String studyStr, String clinicalAnal + " can be made to the Interpretation."); } - OpenCGAResult result = internalGet(study.getUid(), interpretationId, INCLUDE_INTERPRETATION_IDS, userId); + OpenCGAResult result = internalGet(organizationId, study.getUid(), interpretationId, INCLUDE_INTERPRETATION_IDS, userId); if (result.getNumResults() == 0) { throw new CatalogException("Could not find interpretation '" + interpretationId + "'"); } @@ -1157,19 +1157,19 @@ public OpenCGAResult revert(String studyStr, String clinicalAnal } @Override - public DBIterator iterator(String studyStr, Query query, QueryOptions options, String sessionId) + public DBIterator iterator(String organizationId, String studyStr, Query query, QueryOptions options, String sessionId) throws CatalogException { return null; } @Override - public OpenCGAResult search(String studyId, Query query, QueryOptions options, String token) + public OpenCGAResult search(String organizationId, String studyId, Query query, QueryOptions options, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); fixQueryObject(study, query, userId); query.append(InterpretationDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); @@ -1180,7 +1180,7 @@ public OpenCGAResult search(String studyId, Query query, QueryOp for (Interpretation interpretation : queryResult.getResults()) { if (StringUtils.isNotEmpty(interpretation.getClinicalAnalysisId())) { try { - catalogManager.getClinicalAnalysisManager().internalGet(study.getUid(), interpretation.getClinicalAnalysisId(), + catalogManager.getClinicalAnalysisManager().internalGet(organizationId, study.getUid(), interpretation.getClinicalAnalysisId(), ClinicalAnalysisManager.INCLUDE_CLINICAL_IDS, userId); results.add(interpretation); } catch (CatalogException e) { @@ -1188,7 +1188,7 @@ public OpenCGAResult search(String studyId, Query query, QueryOp Query clinicalQuery = new Query(ClinicalAnalysisDBAdaptor.QueryParams.DELETED.key(), true); try { - catalogManager.getClinicalAnalysisManager().internalGet(study.getUid(), interpretation.getClinicalAnalysisId(), + catalogManager.getClinicalAnalysisManager().internalGet(organizationId, study.getUid(), interpretation.getClinicalAnalysisId(), clinicalQuery, ClinicalAnalysisManager.INCLUDE_CLINICAL_IDS, userId); results.add(interpretation); } catch (CatalogException e1) { @@ -1206,11 +1206,11 @@ public OpenCGAResult search(String studyId, Query query, QueryOp } @Override - public OpenCGAResult distinct(String studyId, List fields, Query query, String token) throws CatalogException { + public OpenCGAResult distinct(String organizationId, String studyId, List fields, Query query, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -1235,12 +1235,12 @@ public OpenCGAResult distinct(String studyId, List fields, Query quer } @Override - public OpenCGAResult count(String studyId, Query query, String token) throws CatalogException { + public OpenCGAResult count(String organizationId, String studyId, Query query, String token) throws CatalogException { return null; } @Override - public OpenCGAResult delete(String studyStr, List ids, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, List ids, QueryOptions options, String token) throws CatalogException { throw new NotImplementedException("Use other implemented delete method"); } @@ -1256,7 +1256,7 @@ public OpenCGAResult delete(String studyStr, String clinicalAnalysisId, List internalResult = internalGet(study.getUid(), id, INCLUDE_INTERPRETATION_IDS, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, INCLUDE_INTERPRETATION_IDS, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Interpretation '" + id + "' not found"); } @@ -1348,7 +1348,7 @@ public OpenCGAResult delete(String studyStr, String clinicalAnalysisId, List fields, QueryOptions options, String sessionId) + public OpenCGAResult groupBy(String organizationId, @Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) throws CatalogException { return null; } diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/JobManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/JobManager.java index a084a6bfb82..a9220bfb430 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/JobManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/JobManager.java @@ -123,7 +123,7 @@ Enums.Resource getEntity() { // } @Override - InternalGetDataResult internalGet(long studyUid, List entryList, @Nullable Query query, QueryOptions options, String user, + InternalGetDataResult internalGet(String organizationId, long studyUid, List entryList, @Nullable Query query, QueryOptions options, String user, boolean ignoreException) throws CatalogException { if (ListUtils.isEmpty(entryList)) { throw new CatalogException("Missing job entries."); @@ -215,7 +215,7 @@ public Study getStudy(Job job, String sessionId) throws CatalogException { public OpenCGAResult visit(String studyId, String jobId, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId); + Study study = studyManager.resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -223,7 +223,7 @@ public OpenCGAResult visit(String studyId, String jobId, String token) thro .append("token", token); try { JobUpdateParams updateParams = new JobUpdateParams().setVisited(true); - Job job = internalGet(study.getUid(), jobId, INCLUDE_JOB_IDS, userId).first(); + Job job = internalGet(organizationId, study.getUid(), jobId, INCLUDE_JOB_IDS, userId).first(); OpenCGAResult result = update(study, job, updateParams, QueryOptions.empty(), userId); auditManager.audit(userId, Enums.Action.VISIT, Enums.Resource.JOB, job.getId(), job.getUuid(), study.getId(), @@ -238,9 +238,9 @@ public OpenCGAResult visit(String studyId, String jobId, String token) thro } @Override - public OpenCGAResult create(String studyStr, Job job, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult create(String organizationId, String studyStr, Job job, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -351,10 +351,10 @@ private void autoCompleteNewJob(Study study, Job job, String token) throws Catal // If uuid is provided, we will remove the study uid from the query so it can be searched across any study InternalGetDataResult dependsOnResult; if (uuidProvided) { - dependsOnResult = internalGet(0, job.getDependsOn().stream().map(Job::getId).collect(Collectors.toList()), null, + dependsOnResult = internalGet(organizationId, 0, job.getDependsOn().stream().map(Job::getId).collect(Collectors.toList()), null, INCLUDE_JOB_IDS, job.getUserId(), false); } else { - dependsOnResult = internalGet(study.getUid(), job.getDependsOn().stream().map(Job::getId).collect(Collectors.toList()), + dependsOnResult = internalGet(organizationId, study.getUid(), job.getDependsOn().stream().map(Job::getId).collect(Collectors.toList()), null, INCLUDE_JOB_IDS, job.getUserId(), false); } job.setDependsOn(dependsOnResult.getResults()); @@ -384,7 +384,7 @@ public List getJobInputFilesFromParams(String study, Job job, String token for (String fileStr : StringUtils.split((String) entry.getValue(), ',')) { try { // Validate the user has access to the file - File file = catalogManager.getFileManager().get(study, fileStr, + File file = catalogManager.getFileManager().get(organizationId, study, fileStr, FileManager.INCLUDE_FILE_URI_PATH, token).first(); inputFiles.add(file); } catch (CatalogException e) { @@ -401,7 +401,7 @@ public List getJobInputFilesFromParams(String study, Job job, String token // catalog try { // Validate the user has access to the file - File file = catalogManager.getFileManager().get(study, (String) subEntry.getValue(), + File file = catalogManager.getFileManager().get(organizationId, study, (String) subEntry.getValue(), FileManager.INCLUDE_FILE_URI_PATH, token).first(); inputFiles.add(file); } catch (CatalogException e) { @@ -419,7 +419,7 @@ public List getJobInputFilesFromParams(String study, Job job, String token public OpenCGAResult retry(String studyStr, JobRetryParams jobRetry, Enums.Priority priority, String jobId, String jobDescription, List jobDependsOn, List jobTags, String token) throws CatalogException { - Job job = get(studyStr, jobRetry.getJob(), new QueryOptions(), token).first(); + Job job = get(organizationId, studyStr, jobRetry.getJob(), new QueryOptions(), token).first(); if (jobRetry.isForce() || job.getInternal().getStatus().getId().equals(Enums.ExecutionStatus.ERROR) || job.getInternal().getStatus().getId().equals(Enums.ExecutionStatus.ABORTED)) { @@ -451,7 +451,7 @@ public OpenCGAResult submitProject(String projectStr, String toolId, Enums. QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.FQN.key()); // Peek any study. The ExecutionDaemon will take care of filling up the rest of studies. List studies = catalogManager.getStudyManager() - .search(projectStr, new Query(), options, token) + .search(organizationId, projectStr, new Query(), options, token) .getResults() .stream() .map(Study::getFqn) @@ -473,7 +473,7 @@ public OpenCGAResult submit(String studyStr, String toolId, Enums.Priority Map attributes, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -576,7 +576,7 @@ private OpenCGAResult getJobToReuse(Study study, String inputJobId, Job job .append(QueryOptions.LIMIT, 10) .append(QueryOptions.INCLUDE, Arrays.asList(JobDBAdaptor.QueryParams.UID.key(), JobDBAdaptor.QueryParams.PARAMS.key())); - DBIterator it = iterator(study.getUuid(), query, options, token); + DBIterator it = iterator(organizationId, study.getUuid(), query, options, token); while (it.hasNext()) { Job candidateJob = it.next(); // Compare params orderless @@ -636,7 +636,7 @@ public DBIterator iterator(Query query, QueryOptions options, String token) } public OpenCGAResult get(long jobId, QueryOptions options, String sessionId) throws CatalogException { - return get(null, String.valueOf(jobId), options, sessionId); + return get(organizationId, null, String.valueOf(jobId), options, sessionId); } // public OpenCGAResult get(List jobIds, QueryOptions options, boolean ignoreException, String sessionId) @@ -652,7 +652,7 @@ private void fixQueryObject(Study study, Query query, String userId) throws Cata changeQueryId(query, ParamConstants.JOB_STATUS_PARAM, JobDBAdaptor.QueryParams.STATUS_ID.key()); if (query.containsKey(ParamConstants.JOB_INPUT_FILES_PARAM)) { - List inputFiles = catalogManager.getFileManager().internalGet(study.getUid(), + List inputFiles = catalogManager.getFileManager().internalGet(organizationId, study.getUid(), query.getAsStringList(ParamConstants.JOB_INPUT_FILES_PARAM), FileManager.INCLUDE_FILE_IDS, userId, true).getResults(); if (ListUtils.isNotEmpty(inputFiles)) { query.put(JobDBAdaptor.QueryParams.INPUT_UID.key(), inputFiles.stream().map(File::getUid).collect(Collectors.toList())); @@ -663,7 +663,7 @@ private void fixQueryObject(Study study, Query query, String userId) throws Cata query.remove(ParamConstants.JOB_INPUT_FILES_PARAM); } if (query.containsKey(ParamConstants.JOB_OUTPUT_FILES_PARAM)) { - List inputFiles = catalogManager.getFileManager().internalGet(study.getUid(), + List inputFiles = catalogManager.getFileManager().internalGet(organizationId, study.getUid(), query.getAsStringList(ParamConstants.JOB_OUTPUT_FILES_PARAM), FileManager.INCLUDE_FILE_IDS, userId, true).getResults(); if (ListUtils.isNotEmpty(inputFiles)) { query.put(JobDBAdaptor.QueryParams.OUTPUT_UID.key(), inputFiles.stream().map(File::getUid).collect(Collectors.toList())); @@ -676,12 +676,12 @@ private void fixQueryObject(Study study, Query query, String userId) throws Cata } @Override - public OpenCGAResult search(String studyId, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult search(String organizationId, String studyId, Query query, QueryOptions options, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -705,11 +705,11 @@ public OpenCGAResult search(String studyId, Query query, QueryOptions optio } @Override - public OpenCGAResult distinct(String studyId, List fields, Query query, String token) throws CatalogException { + public OpenCGAResult distinct(String organizationId, String studyId, List fields, Query query, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -734,12 +734,12 @@ public OpenCGAResult distinct(String studyId, List fields, Query quer } @Override - public DBIterator iterator(String studyId, Query query, QueryOptions options, String token) throws CatalogException { + public DBIterator iterator(String organizationId, String studyId, Query query, QueryOptions options, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); fixQueryObject(study, query, userId); query.put(JobDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); @@ -748,11 +748,11 @@ public DBIterator iterator(String studyId, Query query, QueryOptions option } @Override - public OpenCGAResult count(String studyId, Query query, String token) throws CatalogException { + public OpenCGAResult count(String organizationId, String studyId, Query query, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -777,14 +777,14 @@ public OpenCGAResult count(String studyId, Query query, String token) throw } @Override - public OpenCGAResult delete(String studyStr, List jobIds, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, List jobIds, QueryOptions options, String token) throws CatalogException { return delete(studyStr, jobIds, options, false, token); } public OpenCGAResult delete(String studyStr, List jobIds, ObjectMap params, boolean ignoreException, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); String operationUuid = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -812,7 +812,7 @@ public OpenCGAResult delete(String studyStr, List jobIds, ObjectMap para String jobUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), id, INCLUDE_JOB_IDS, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, INCLUDE_JOB_IDS, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Job '" + id + "' not found"); } @@ -849,7 +849,7 @@ public OpenCGAResult delete(String studyStr, List jobIds, ObjectMap para } @Override - public OpenCGAResult delete(String studyId, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyId, Query query, QueryOptions options, String token) throws CatalogException { return delete(studyId, query, options, false, token); } @@ -859,7 +859,7 @@ public OpenCGAResult delete(String studyId, Query query, ObjectMap params, boole OpenCGAResult result = OpenCGAResult.empty(); String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); String operationUuid = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -941,7 +941,7 @@ public OpenCGAResult log(String studyId, String jobId, long offset, long startTime = System.currentTimeMillis(); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId); + Study study = studyManager.resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -963,7 +963,7 @@ public OpenCGAResult log(String studyId, String jobId, long offset, Arrays.asList(JobDBAdaptor.QueryParams.ID.key(), JobDBAdaptor.QueryParams.UUID.key(), JobDBAdaptor.QueryParams.INTERNAL_STATUS.key(), JobDBAdaptor.QueryParams.STDOUT.key(), JobDBAdaptor.QueryParams.OUT_DIR.key())); - Job job = internalGet(study.getUid(), jobId, options, userId).first(); + Job job = internalGet(organizationId, study.getUid(), jobId, options, userId).first(); Path logFile; if ("stderr".equalsIgnoreCase(type)) { @@ -1027,7 +1027,7 @@ public OpenCGAResult update(String studyStr, Query query, JobUpdateParams u Query finalQuery = new Query(ParamUtils.defaultObject(query, Query::new)); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -1103,7 +1103,7 @@ public OpenCGAResult update(String studyStr, List jobIds, JobUpdate public OpenCGAResult update(String studyStr, List jobIds, JobUpdateParams updateParams, boolean ignoreException, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -1129,7 +1129,7 @@ public OpenCGAResult update(String studyStr, List jobIds, JobUpdate String jobUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), id, INCLUDE_JOB_IDS, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, INCLUDE_JOB_IDS, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Job '" + id + "' not found"); } @@ -1162,7 +1162,7 @@ public OpenCGAResult update(String studyStr, List jobIds, JobUpdate public OpenCGAResult update(String studyStr, String jobId, JobUpdateParams updateParams, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -1183,7 +1183,7 @@ public OpenCGAResult update(String studyStr, String jobId, JobUpdateParams OpenCGAResult result = OpenCGAResult.empty(); String jobUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), jobId, INCLUDE_JOB_IDS, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), jobId, INCLUDE_JOB_IDS, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Job '" + jobId + "' not found"); } @@ -1286,7 +1286,7 @@ private File getFile(long studyUid, String path, String userId) throws CatalogEx throw new CatalogException("Missing file path"); } - OpenCGAResult fileResult = catalogManager.getFileManager().internalGet(studyUid, path, FileManager.INCLUDE_FILE_URI_PATH, + OpenCGAResult fileResult = catalogManager.getFileManager().internalGet(organizationId, studyUid, path, FileManager.INCLUDE_FILE_URI_PATH, userId); if (fileResult.getNumResults() == 0) { throw new CatalogException("File/Folder '" + path + "' not found"); @@ -1302,7 +1302,7 @@ public OpenCGAResult update(String studyId, Query query, ObjectMap paramete public OpenCGAResult update(String studyId, Query query, ObjectMap parameters, boolean ignoreException, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId); + Study study = studyManager.resolveId(organizationId, studyId, userId); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -1360,7 +1360,7 @@ public OpenCGAResult update(String studyId, Query query, ObjectMap paramete public OpenCGAResult update(String studyId, String jobId, ObjectMap parameters, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId); + Study study = studyManager.resolveId(organizationId, studyId, userId); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -1376,7 +1376,7 @@ public OpenCGAResult update(String studyId, String jobId, ObjectMap paramet OpenCGAResult result = OpenCGAResult.empty(); String jobUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), jobId, QueryOptions.empty(), userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), jobId, QueryOptions.empty(), userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Job '" + jobId + "' not found"); } @@ -1417,7 +1417,7 @@ public OpenCGAResult update(String studyId, List jobIds, ObjectMap public OpenCGAResult update(String studyId, List jobIds, ObjectMap parameters, boolean ignoreException, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId); + Study study = studyManager.resolveId(organizationId, studyId, userId); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -1437,7 +1437,7 @@ public OpenCGAResult update(String studyId, List jobIds, ObjectMap String jobUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), id, QueryOptions.empty(), userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, QueryOptions.empty(), userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Job '" + id + "' not found"); } @@ -1472,7 +1472,7 @@ public OpenCGAResult update(String studyId, List jobIds, ObjectMap public OpenCGAResult top(Query baseQuery, int limit, String token) throws CatalogException { String userId = userManager.getUserId(token); - List studies = studyManager.search(new Query(StudyDBAdaptor.QueryParams.OWNER.key(), userId), + List studies = studyManager.search(organizationId, new Query(StudyDBAdaptor.QueryParams.OWNER.key(), userId), new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.UUID.key()), token).getResults() .stream() .map(Study::getUuid) @@ -1493,7 +1493,7 @@ public OpenCGAResult top(List studiesStr, Query baseQuery, int l fixQueryObject(null, baseQuery, userId); List studies = new ArrayList<>(studiesStr.size()); for (String studyStr : studiesStr) { - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); authorizationManager.checkCanViewStudy(study.getUid(), userId); studies.add(study); } @@ -1650,14 +1650,14 @@ public OpenCGAResult top(List studiesStr, Query baseQuery, int l } @Override - public OpenCGAResult rank(String studyId, Query query, String field, int numResults, boolean asc, String token) + public OpenCGAResult rank(String organizationId, String studyId, Query query, String field, int numResults, boolean asc, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); ParamUtils.checkObj(field, "field"); ParamUtils.checkObj(token, "sessionId"); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); authorizationManager.checkStudyPermission(study.getUid(), userId, StudyPermissions.Permissions.VIEW_JOBS); // TODO: In next release, we will have to check the count parameter from the queryOptions object. @@ -1673,7 +1673,7 @@ public OpenCGAResult rank(String studyId, Query query, String field, int numResu } @Override - public OpenCGAResult groupBy(@Nullable String studyId, Query query, List fields, QueryOptions options, String token) + public OpenCGAResult groupBy(String organizationId, @Nullable String studyId, Query query, List fields, QueryOptions options, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); @@ -1683,7 +1683,7 @@ public OpenCGAResult groupBy(@Nullable String studyId, Query query, List } String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); // Add study id to the query query.put(SampleDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); @@ -1703,7 +1703,7 @@ public OpenCGAResult> getAcls(String studyId, List< public OpenCGAResult> getAcls(String studyId, List jobList, List members, boolean ignoreException, String token) throws CatalogException { String user = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, user); + Study study = studyManager.resolveId(organizationId, studyId, user); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); ObjectMap auditParams = new ObjectMap() @@ -1717,7 +1717,7 @@ public OpenCGAResult> getAcls(String studyId, List< Map missingMap = new HashMap<>(); try { auditManager.initAuditBatch(operationId); - InternalGetDataResult queryResult = internalGet(study.getUid(), jobList, INCLUDE_JOB_IDS, user, ignoreException); + InternalGetDataResult queryResult = internalGet(organizationId, study.getUid(), jobList, INCLUDE_JOB_IDS, user, ignoreException); if (queryResult.getMissing() != null) { missingMap = queryResult.getMissing().stream() @@ -1782,7 +1782,7 @@ public OpenCGAResult> updateAcl(String studyId, Lis AclParams aclParams, ParamUtils.AclAction action, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId); + Study study = studyManager.resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -1810,7 +1810,7 @@ public OpenCGAResult> updateAcl(String studyId, Lis checkPermissions(permissions, JobPermissions::valueOf); } - List jobList = internalGet(study.getUid(), jobStrList, INCLUDE_JOB_IDS, userId, false).getResults(); + List jobList = internalGet(organizationId, study.getUid(), jobStrList, INCLUDE_JOB_IDS, userId, false).getResults(); authorizationManager.checkCanAssignOrSeePermissions(study.getUid(), userId); @@ -1874,7 +1874,7 @@ public DataResult facet(String studyId, Query query, QueryOptions op throws CatalogException, IOException { String userId = userManager.getUserId(token); // We need to add variableSets and groups to avoid additional queries as it will be used in the catalogSolrManager - Study study = catalogManager.getStudyManager().resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(StudyDBAdaptor.QueryParams.VARIABLE_SET.key(), StudyDBAdaptor.QueryParams.GROUPS.key()))); ParamUtils.defaultObject(query, Query::new); diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/PanelManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/PanelManager.java index e0f6b2284fe..b2bd9344849 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/PanelManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/PanelManager.java @@ -92,7 +92,7 @@ Enums.Resource getEntity() { } @Override - InternalGetDataResult internalGet(long studyUid, List entryList, @Nullable Query query, QueryOptions options, + InternalGetDataResult internalGet(String organizationId, long studyUid, List entryList, @Nullable Query query, QueryOptions options, String user, boolean ignoreException) throws CatalogException { if (ListUtils.isEmpty(entryList)) { throw new CatalogException("Missing panel entries."); @@ -160,9 +160,9 @@ private OpenCGAResult getPanel(long studyUid, String panelUuid, QueryOpti } @Override - public OpenCGAResult create(String studyStr, Panel panel, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult create(String organizationId, String studyStr, Panel panel, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -195,7 +195,7 @@ public OpenCGAResult create(String studyStr, Panel panel, QueryOptions op public OpenCGAResult importFromSource(String studyId, String source, String panelIds, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -345,7 +345,7 @@ public OpenCGAResult update(String studyId, Query query, PanelUpdateParam Query finalQuery = new Query(ParamUtils.defaultObject(query, Query::new)); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId); + Study study = studyManager.resolveId(organizationId, studyId, userId); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -403,7 +403,7 @@ public OpenCGAResult update(String studyId, Query query, PanelUpdateParam public OpenCGAResult update(String studyStr, String panelId, PanelUpdateParams updateParams, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -424,7 +424,7 @@ public OpenCGAResult update(String studyStr, String panelId, PanelUpdateP OpenCGAResult result = OpenCGAResult.empty(); String panelUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), panelId, QueryOptions.empty(), userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), panelId, QueryOptions.empty(), userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Panel '" + panelId + "' not found"); } @@ -473,7 +473,7 @@ public OpenCGAResult update(String studyStr, List panelIds, Panel public OpenCGAResult update(String studyStr, List panelIds, PanelUpdateParams updateParams, boolean ignoreException, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -499,7 +499,7 @@ public OpenCGAResult update(String studyStr, List panelIds, Panel String panelUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), panelId, QueryOptions.empty(), userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), panelId, QueryOptions.empty(), userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Panel '" + id + "' not found"); } @@ -563,12 +563,12 @@ private OpenCGAResult update(Study study, Panel panel, PanelUpdateParams updateP } @Override - public DBIterator iterator(String studyStr, Query query, QueryOptions options, String sessionId) throws CatalogException { + public DBIterator iterator(String organizationId, String studyStr, Query query, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(sessionId); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); fixQueryObject(query); query.append(PanelDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); @@ -576,12 +576,12 @@ public DBIterator iterator(String studyStr, Query query, QueryOptions opt } @Override - public OpenCGAResult search(String studyId, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult search(String organizationId, String studyId, Query query, QueryOptions options, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -606,11 +606,11 @@ public OpenCGAResult search(String studyId, Query query, QueryOptions opt } @Override - public OpenCGAResult distinct(String studyId, List fields, Query query, String token) throws CatalogException { + public OpenCGAResult distinct(String organizationId, String studyId, List fields, Query query, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -636,11 +636,11 @@ public OpenCGAResult distinct(String studyId, List fields, Query quer } @Override - public OpenCGAResult count(String studyId, Query query, String token) throws CatalogException { + public OpenCGAResult count(String organizationId, String studyId, Query query, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -667,7 +667,7 @@ public OpenCGAResult count(String studyId, Query query, String token) thr } @Override - public OpenCGAResult delete(String studyStr, List panelIds, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, List panelIds, QueryOptions options, String token) throws CatalogException { return delete(studyStr, panelIds, options, false, token); } @@ -678,7 +678,7 @@ public OpenCGAResult delete(String studyStr, List panelIds, ObjectMap pa } String userId = catalogManager.getUserManager().getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -706,7 +706,7 @@ public OpenCGAResult delete(String studyStr, List panelIds, ObjectMap pa String panelId = id; String panelUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), id, INCLUDE_PANEL_IDS, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, INCLUDE_PANEL_IDS, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Panel '" + id + "' not found"); } @@ -745,7 +745,7 @@ public OpenCGAResult delete(String studyStr, List panelIds, ObjectMap pa } @Override - public OpenCGAResult delete(String studyStr, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, Query query, QueryOptions options, String token) throws CatalogException { return delete(studyStr, query, options, false, token); } @@ -755,7 +755,7 @@ public OpenCGAResult delete(String studyStr, Query query, ObjectMap params, bool OpenCGAResult result = OpenCGAResult.empty(); String userId = catalogManager.getUserManager().getUserId(token); - Study study = studyManager.resolveId(studyStr, userId); + Study study = studyManager.resolveId(organizationId, studyStr, userId); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -821,14 +821,14 @@ public OpenCGAResult delete(String studyStr, Query query, ObjectMap params, bool } @Override - public OpenCGAResult rank(String studyStr, Query query, String field, int numResults, boolean asc, String sessionId) + public OpenCGAResult rank(String organizationId, String studyStr, Query query, String field, int numResults, boolean asc, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); ParamUtils.checkObj(field, "field"); ParamUtils.checkObj(sessionId, "sessionId"); String userId = userManager.getUserId(sessionId); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); authorizationManager.checkStudyPermission(study.getUid(), userId, StudyPermissions.Permissions.VIEW_PANELS); @@ -847,7 +847,7 @@ public OpenCGAResult rank(String studyStr, Query query, String field, int numRes } @Override - public OpenCGAResult groupBy(@Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) + public OpenCGAResult groupBy(String organizationId, @Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); fixQueryObject(query); @@ -857,7 +857,7 @@ public OpenCGAResult groupBy(@Nullable String studyStr, Query query, List> getAcls(String studyId, Lis public OpenCGAResult> getAcls(String studyId, List panelList, List members, boolean ignoreException, String token) throws CatalogException { String user = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, user); + Study study = studyManager.resolveId(organizationId, studyId, user); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); ObjectMap auditParams = new ObjectMap() @@ -890,7 +890,7 @@ public OpenCGAResult> getAcls(String studyId, Lis Map missingMap = new HashMap<>(); try { auditManager.initAuditBatch(operationId); - InternalGetDataResult queryResult = internalGet(study.getUid(), panelList, INCLUDE_PANEL_IDS, user, ignoreException); + InternalGetDataResult queryResult = internalGet(organizationId, study.getUid(), panelList, INCLUDE_PANEL_IDS, user, ignoreException); if (queryResult.getMissing() != null) { missingMap = queryResult.getMissing().stream() @@ -957,7 +957,7 @@ public OpenCGAResult> updateAcl(String studyId, L ParamUtils.AclAction action, String token) throws CatalogException { String user = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, user); + Study study = studyManager.resolveId(organizationId, studyId, user); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -985,7 +985,7 @@ public OpenCGAResult> updateAcl(String studyId, L checkPermissions(permissions, PanelPermissions::valueOf); } - OpenCGAResult panelDataResult = internalGet(study.getUid(), panelStrList, INCLUDE_PANEL_IDS, user, false); + OpenCGAResult panelDataResult = internalGet(organizationId, study.getUid(), panelStrList, INCLUDE_PANEL_IDS, user, false); authorizationManager.checkCanAssignOrSeePermissions(study.getUid(), user); // Validate that the members are actually valid members diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/ProjectManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/ProjectManager.java index 72eb35b67a1..868d21c0a6c 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/ProjectManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/ProjectManager.java @@ -85,19 +85,20 @@ public class ProjectManager extends AbstractManager { this.catalogIOManager = catalogIOManager; } - public String getOwner(long projectId) throws CatalogException { - return projectDBAdaptor.getOwnerId(projectId); + public String getOwner(String organizationId, long projectId) throws CatalogException { + return getProjectDBAdaptor(organizationId).getOwnerId(projectId); } /** * Fetch the project qualifying the projectStr structure as long as userId has permissions to see it. * - * @param projectStr string that can contain the full qualified name (owner@projectId) or just the projectId. - * @param userId user asking for the project information. + * @param organizationId + * @param projectStr string that can contain the full qualified name (owner@projectId) or just the projectId. + * @param userId user asking for the project information. * @return a OpenCGAResult containing the project. * @throws CatalogException if multiple projects are found. */ - Project resolveId(String projectStr, String userId) throws CatalogException { + Project resolveId(String organizationId, String projectStr, String userId) throws CatalogException { if (StringUtils.isEmpty(userId)) { throw new CatalogException("Missing mandatory parameter userId"); } @@ -137,7 +138,7 @@ Project resolveId(String projectStr, String userId) throws CatalogException { query.putIfNotEmpty(ProjectDBAdaptor.QueryParams.ID.key(), auxProject); } - OpenCGAResult projectDataResult = projectDBAdaptor.get(query, projectOptions); + OpenCGAResult projectDataResult = getProjectDBAdaptor(organizationId).get(query, projectOptions); if (projectDataResult.getNumResults() > 1) { throw new CatalogException("Please be more concrete with the project. More than one project found for " + userId + " user"); } else if (projectDataResult.getNumResults() == 1) { @@ -155,7 +156,7 @@ Project resolveId(String projectStr, String userId) throws CatalogException { } QueryOptions queryOptions = new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.FQN.key()); - OpenCGAResult studyDataResult = studyDBAdaptor.get(query, queryOptions, userId); + OpenCGAResult studyDataResult = getStudyDBAdaptor(organizationId).get(query, queryOptions, userId); if (studyDataResult.getNumResults() > 0) { Set projectFqnSet = new HashSet<>(); @@ -165,7 +166,7 @@ Project resolveId(String projectStr, String userId) throws CatalogException { if (projectFqnSet.size() == 1) { query = new Query(ProjectDBAdaptor.QueryParams.FQN.key(), projectFqnSet); - return projectDBAdaptor.get(query, projectOptions).first(); + return getProjectDBAdaptor(organizationId).get(query, projectOptions).first(); } else { throw new CatalogException("More than one project shared with user " + userId + ". Please, be more specific. " + "The accepted pattern is [ownerId@projectId]"); @@ -173,7 +174,7 @@ Project resolveId(String projectStr, String userId) throws CatalogException { } else { if (StringUtils.isNotEmpty(projectStr)) { // Check if it is a matter of permissions - if (studyDBAdaptor.count(query).getNumMatches() == 0) { + if (getStudyDBAdaptor(organizationId).count(query).getNumMatches() == 0) { throw new CatalogException("Project " + projectStr + " not found"); } else { throw CatalogAuthorizationException.deny(userId, "view", "project", projectStr, null); @@ -184,25 +185,27 @@ Project resolveId(String projectStr, String userId) throws CatalogException { } } - private OpenCGAResult getProject(String userId, String projectUuid, QueryOptions options) throws CatalogDBException { + private OpenCGAResult getProject(String organizationId, String userId, String projectUuid, QueryOptions options) + throws CatalogDBException { Query query = new Query() .append(ProjectDBAdaptor.QueryParams.USER_ID.key(), userId) .append(ProjectDBAdaptor.QueryParams.UUID.key(), projectUuid); options = ParamUtils.defaultObject(options, QueryOptions::new); - return projectDBAdaptor.get(query, options); + return getProjectDBAdaptor(organizationId).get(query, options); } /** * Obtain the list of projects and studies that are shared with the user. * - * @param userId user whose projects and studies are being shared with. - * @param queryOptions QueryOptions object. - * @param sessionId Session id which should correspond to userId. + * @param organizationId + * @param userId user whose projects and studies are being shared with. + * @param queryOptions QueryOptions object. + * @param sessionId Session id which should correspond to userId. * @return A OpenCGAResult object containing the list of projects and studies that are shared with the user. * @throws CatalogException CatalogException */ - public OpenCGAResult getSharedProjects(String userId, QueryOptions queryOptions, String sessionId) throws CatalogException { - OpenCGAResult result = search(new Query(ProjectDBAdaptor.QueryParams.USER_ID.key(), "!=" + userId), queryOptions, + public OpenCGAResult getSharedProjects(String organizationId, String userId, QueryOptions queryOptions, String sessionId) throws CatalogException { + OpenCGAResult result = search(organizationId, new Query(ProjectDBAdaptor.QueryParams.USER_ID.key(), "!=" + userId), queryOptions, sessionId); for (Event event : result.getEvents()) { if (event.getType() == Event.Type.ERROR) { @@ -217,10 +220,10 @@ public OpenCGAResult create(String id, String name, String description, String assembly, QueryOptions options, String sessionId) throws CatalogException { ProjectCreateParams projectCreateParams = new ProjectCreateParams(id, name, description, null, null, new ProjectOrganism(scientificName, commonName, assembly), null, null); - return create(projectCreateParams, options, sessionId); + return create(organizationId, projectCreateParams, options, sessionId); } - public OpenCGAResult create(ProjectCreateParams projectCreateParams, QueryOptions options, String token) + public OpenCGAResult create(String organizationId, ProjectCreateParams projectCreateParams, QueryOptions options, String token) throws CatalogException { // Only the organization owner or the administrators can create a project JwtPayload payload = this.catalogManager.getUserManager().getTokenPayload(token); @@ -229,6 +232,7 @@ public OpenCGAResult create(ProjectCreateParams projectCreateParams, Qu } ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("project", projectCreateParams) .append("options", options) .append("token", token); @@ -255,8 +259,8 @@ public OpenCGAResult create(ProjectCreateParams projectCreateParams, Qu project = projectCreateParams.toProject(); validateProjectForCreation(project); - queryResult = projectDBAdaptor.insert(organization.getId(), project, options); - OpenCGAResult result = getProject(organization.getId(), project.getUuid(), options); + queryResult = getProjectDBAdaptor(organizationId).insert(organization.getId(), project, options); + OpenCGAResult result = getProject(organizationId, organization.getId(), project.getUuid(), options); project = result.first(); if (options.getBoolean(ParamConstants.INCLUDE_RESULT_PARAM)) { // Fetch created project @@ -274,7 +278,7 @@ public OpenCGAResult create(ProjectCreateParams projectCreateParams, Qu auditManager.auditCreate(payload.getUserId(), Enums.Resource.PROJECT, project.getId(), "", "", "", auditParams, new AuditRecord.Status(AuditRecord.Status.Result.ERROR, e.getError())); try { - projectDBAdaptor.delete(project); + getProjectDBAdaptor(organizationId).delete(project); } catch (Exception e1) { logger.error("Error deleting project from catalog after failing creating the folder in the filesystem", e1); throw e; @@ -322,22 +326,24 @@ private void validateProjectForCreation(Project project) throws CatalogParameter /** * Reads a project from Catalog given a project id or alias. * - * @param projectId Project id or alias. - * @param options Read options - * @param token sessionId + * @param organizationId Organization id. + * @param projectId Project id or alias. + * @param options Read options + * @param token sessionId * @return The specified object * @throws CatalogException CatalogException */ - public OpenCGAResult get(String projectId, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult get(String organizationId, String projectId, QueryOptions options, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("projectId", projectId) .append("options", options) .append("token", token); try { - Project project = resolveId(projectId, userId); - OpenCGAResult queryResult = projectDBAdaptor.get(project.getUid(), options); + Project project = resolveId(organizationId, projectId, userId); + OpenCGAResult queryResult = getProjectDBAdaptor(organizationId).get(project.getUid(), options); auditManager.auditInfo(userId, Enums.Resource.PROJECT, project.getId(), project.getUuid(), "", "", auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); return queryResult; @@ -348,14 +354,14 @@ public OpenCGAResult get(String projectId, QueryOptions options, String } } - public OpenCGAResult get(List projectList, QueryOptions options, boolean ignoreException, String sessionId) + public OpenCGAResult get(String organizationId, List projectList, QueryOptions options, boolean ignoreException, String sessionId) throws CatalogException { OpenCGAResult result = OpenCGAResult.empty(); for (int i = 0; i < projectList.size(); i++) { String project = projectList.get(i); try { - OpenCGAResult projectResult = get(project, options, sessionId); + OpenCGAResult projectResult = get(organizationId, project, options, sessionId); result.append(projectResult); } catch (CatalogException e) { Event event = new Event(Event.Type.ERROR, projectList.get(i), e.getMessage()); @@ -375,19 +381,21 @@ public OpenCGAResult get(List projectList, QueryOptions options /** * Fetch all the project objects matching the query. * - * @param query Query to catalog. - * @param options Query options, like "include", "exclude", "limit" and "skip" - * @param token sessionId + * @param organizationId Organization id. + * @param query Query to catalog. + * @param options Query options, like "include", "exclude", "limit" and "skip" + * @param token sessionId * @return All matching elements. * @throws CatalogException CatalogException */ - public OpenCGAResult search(Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult search(String organizationId, Query query, QueryOptions options, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = catalogManager.getUserManager().getUserId(token); query = new Query(query); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("query", query) .append("options", options) .append("token", token); @@ -397,12 +405,12 @@ public OpenCGAResult search(Query query, QueryOptions options, String t // If study is provided, we need to check if it will be study alias or id if (StringUtils.isNotEmpty(query.getString(ProjectDBAdaptor.QueryParams.STUDY.key()))) { List studies = catalogManager.getStudyManager() - .resolveIds(query.getAsStringList(ProjectDBAdaptor.QueryParams.STUDY.key()), userId); + .resolveIds(organizationId, query.getAsStringList(ProjectDBAdaptor.QueryParams.STUDY.key()), userId); query.remove(ProjectDBAdaptor.QueryParams.STUDY.key()); query.put(ProjectDBAdaptor.QueryParams.STUDY_UID.key(), studies.stream().map(Study::getUid).collect(Collectors.toList())); } - OpenCGAResult queryResult = projectDBAdaptor.get(query, options, userId); + OpenCGAResult queryResult = getProjectDBAdaptor(organizationId).get(query, options, userId); auditManager.auditSearch(userId, Enums.Resource.PROJECT, "", "", auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); return queryResult; @@ -417,21 +425,23 @@ public OpenCGAResult search(Query query, QueryOptions options, String t /** * Update metada from projects. * - * @param projectId Project id or alias. - * @param parameters Parameters to change. - * @param options options - * @param token sessionId + * @param organizationId + * @param projectId Project id or alias. + * @param parameters Parameters to change. + * @param options options + * @param token sessionId * @return The modified entry. * @throws CatalogException CatalogException */ - public OpenCGAResult update(String projectId, ObjectMap parameters, QueryOptions options, String token) + public OpenCGAResult update(String organizationId, String projectId, ObjectMap parameters, QueryOptions options, String token) throws CatalogException { - return update(projectId, parameters, options, false, token); + return update(organizationId, projectId, parameters, options, false, token); } /** * Update metada from projects. * + * @param organizationId Organization id. * @param projectId Project id or alias. * @param parameters Parameters to change. * @param options options @@ -440,12 +450,12 @@ public OpenCGAResult update(String projectId, ObjectMap parameters, Que * @return The modified entry. * @throws CatalogException CatalogException */ - private OpenCGAResult update(String projectId, ObjectMap parameters, QueryOptions options, boolean allowProtectedUpdates, - String token) - throws CatalogException { + private OpenCGAResult update(String organizationId, String projectId, ObjectMap parameters, QueryOptions options, + boolean allowProtectedUpdates, String token) throws CatalogException { String userId = this.catalogManager.getUserManager().getUserId(token); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("project", projectId) .append("updateParams", parameters) .append("options", options) @@ -453,7 +463,7 @@ private OpenCGAResult update(String projectId, ObjectMap parameters, Qu Project project; try { - project = resolveId(projectId, userId); + project = resolveId(organizationId, projectId, userId); } catch (CatalogException e) { auditManager.auditUpdate(userId, Enums.Resource.PROJECT, projectId, "", "", "", auditParams, new AuditRecord.Status(AuditRecord.Status.Result.ERROR, e.getError())); @@ -493,7 +503,7 @@ private OpenCGAResult update(String projectId, ObjectMap parameters, Qu if (parameters.containsKey(ProjectDBAdaptor.QueryParams.ORGANISM_SCIENTIFIC_NAME.key()) || parameters.containsKey(ProjectDBAdaptor.QueryParams.ORGANISM_COMMON_NAME.key()) || parameters.containsKey(ProjectDBAdaptor.QueryParams.ORGANISM_ASSEMBLY.key())) { - OpenCGAResult projectQR = projectDBAdaptor + OpenCGAResult projectQR = getProjectDBAdaptor(organizationId) .get(projectUid, new QueryOptions(QueryOptions.INCLUDE, ProjectDBAdaptor.QueryParams.ORGANISM.key())); if (projectQR.getNumResults() == 0) { throw new CatalogException("Project " + projectUid + " not found"); @@ -520,13 +530,13 @@ private OpenCGAResult update(String projectId, ObjectMap parameters, Qu ParamUtils.checkIdentifier(parameters.getString(ProjectDBAdaptor.QueryParams.ID.key()), "id"); } - OpenCGAResult update = projectDBAdaptor.update(projectUid, parameters, QueryOptions.empty()); + OpenCGAResult update = getProjectDBAdaptor(organizationId).update(projectUid, parameters, QueryOptions.empty()); auditManager.auditUpdate(userId, Enums.Resource.PROJECT, project.getId(), project.getUuid(), "", "", auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); if (options.getBoolean(ParamConstants.INCLUDE_RESULT_PARAM)) { // Fetch updated project - OpenCGAResult result = projectDBAdaptor.get(new Query(ProjectDBAdaptor.QueryParams.UID.key(), projectUid), options, + OpenCGAResult result = getProjectDBAdaptor(organizationId).get(new Query(ProjectDBAdaptor.QueryParams.UID.key(), projectUid), options, userId); update.setResults(result.getResults()); } @@ -539,50 +549,50 @@ private OpenCGAResult update(String projectId, ObjectMap parameters, Qu } } - public OpenCGAResult setDatastoreVariant(String projectStr, DataStore dataStore, String token) throws CatalogException { - return update(projectStr, + public OpenCGAResult setDatastoreVariant(String organizationId, String projectStr, DataStore dataStore, String token) + throws CatalogException { + return update(organizationId, projectStr, new ObjectMap(ProjectDBAdaptor.QueryParams.INTERNAL_DATASTORES_VARIANT.key(), dataStore), new QueryOptions(), true, token); } - public OpenCGAResult setCellbaseConfiguration(String projectStr, CellBaseConfiguration configuration, boolean validate, - String token) - throws CatalogException { + public OpenCGAResult setCellbaseConfiguration(String organizationId, String projectStr, CellBaseConfiguration configuration, + boolean validate, String token) throws CatalogException { if (validate) { try { - ProjectOrganism organism = get(projectStr, + ProjectOrganism organism = get(organizationId, projectStr, new QueryOptions(QueryOptions.INCLUDE, ProjectDBAdaptor.QueryParams.ORGANISM.key()), token).first().getOrganism(); configuration = CellBaseValidator.validate(configuration, organism.getScientificName(), organism.getAssembly(), true); } catch (IOException e) { throw new CatalogParameterException(e); } } - return update(projectStr, + return update(organizationId, projectStr, new ObjectMap(ProjectDBAdaptor.QueryParams.CELLBASE.key(), configuration), new QueryOptions(), true, token); } - public Map facet(String projectStr, String fileFields, String sampleFields, String individualFields, - String cohortFields, String familyFields, String jobFields, boolean defaultStats, String sessionId) - throws CatalogException, IOException { - String userId = catalogManager.getUserManager().getUserId(sessionId); - Project project = resolveId(projectStr, userId); + public Map facet(String organizationId, String projectStr, String fileFields, String sampleFields, + String individualFields, String cohortFields, String familyFields, String jobFields, + boolean defaultStats, String token) throws CatalogException, IOException { + String userId = catalogManager.getUserManager().getUserId(token); + Project project = resolveId(organizationId, projectStr, userId); Query query = new Query(StudyDBAdaptor.QueryParams.PROJECT_UID.key(), project.getUid()); - OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(query, new QueryOptions(QueryOptions.INCLUDE, - Arrays.asList(StudyDBAdaptor.QueryParams.FQN.key(), StudyDBAdaptor.QueryParams.ID.key())), sessionId); + OpenCGAResult studyDataResult = catalogManager.getStudyManager().search(organizationId, query, new QueryOptions(QueryOptions.INCLUDE, + Arrays.asList(StudyDBAdaptor.QueryParams.FQN.key(), StudyDBAdaptor.QueryParams.ID.key())), token); Map result = new HashMap<>(); for (Study study : studyDataResult.getResults()) { - result.put(study.getId(), catalogManager.getStudyManager().facet(study.getFqn(), fileFields, sampleFields, individualFields, - cohortFields, familyFields, jobFields, defaultStats, sessionId)); + result.put(study.getId(), catalogManager.getStudyManager().facet(organizationId, study.getFqn(), fileFields, sampleFields, individualFields, + cohortFields, familyFields, jobFields, defaultStats, token)); } return result; } - public OpenCGAResult incrementRelease(String projectStr, String sessionId) throws CatalogException { + public OpenCGAResult incrementRelease(String organizationId, String projectStr, String sessionId) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(sessionId); try { - Project project = resolveId(projectStr, userId); + Project project = resolveId(organizationId, projectStr, userId); long projectUid = project.getUid(); authorizationManager.checkCanEditProject(projectUid, userId); @@ -596,21 +606,21 @@ public OpenCGAResult incrementRelease(String projectStr, String session throw new CatalogException("Cannot increment current release number. No studies found for release " + currentRelease); } - if (checkCurrentReleaseInUse(allStudiesInProject, currentRelease)) { + if (checkCurrentReleaseInUse(organizationId, allStudiesInProject, currentRelease)) { // Increment current project release - OpenCGAResult writeResult = projectDBAdaptor.incrementCurrentRelease(projectUid); - OpenCGAResult projectDataResult = projectDBAdaptor.get(projectUid, + OpenCGAResult writeResult = getProjectDBAdaptor(organizationId).incrementCurrentRelease(projectUid); + OpenCGAResult projectDataResult = getProjectDBAdaptor(organizationId).get(projectUid, new QueryOptions(QueryOptions.INCLUDE, ProjectDBAdaptor.QueryParams.CURRENT_RELEASE.key())); OpenCGAResult queryResult = new OpenCGAResult<>(projectDataResult.getTime() + writeResult.getTime(), Collections.emptyList(), 1, Collections.singletonList(projectDataResult.first().getCurrentRelease()), 1); // Upgrade release in every versioned data model for (Study study : allStudiesInProject) { - sampleDBAdaptor.updateProjectRelease(study.getUid(), queryResult.first()); - individualDBAdaptor.updateProjectRelease(study.getUid(), queryResult.first()); - familyDBAdaptor.updateProjectRelease(study.getUid(), queryResult.first()); - panelDBAdaptor.updateProjectRelease(study.getUid(), queryResult.first()); - interpretationDBAdaptor.updateProjectRelease(study.getUid(), queryResult.first()); + getSampleDBAdaptor(organizationId).updateProjectRelease(study.getUid(), queryResult.first()); + getIndividualDBAdaptor(organizationId).updateProjectRelease(study.getUid(), queryResult.first()); + getFamilyDBAdaptor(organizationId).updateProjectRelease(study.getUid(), queryResult.first()); + getPanelDBAdaptor(organizationId).updateProjectRelease(study.getUid(), queryResult.first()); + getInterpretationDBAdaptor(organizationId).updateProjectRelease(study.getUid(), queryResult.first()); } auditManager.audit(userId, Enums.Action.INCREMENT_PROJECT_RELEASE, Enums.Resource.PROJECT, project.getId(), @@ -628,13 +638,14 @@ public OpenCGAResult incrementRelease(String projectStr, String session } } - public void importReleases(String owner, String inputDirStr, String sessionId) throws CatalogException, IOException { + public void importReleases(String organizationId, String owner, String inputDirStr, String sessionId) + throws CatalogException, IOException { String userId = catalogManager.getUserManager().getUserId(sessionId); if (!authorizationManager.isInstallationAdministrator(userId)) { throw new CatalogAuthorizationException("Only admin of OpenCGA is authorised to import data"); } - OpenCGAResult userDataResult = userDBAdaptor.get(owner, new QueryOptions(QueryOptions.INCLUDE, + OpenCGAResult userDataResult = getUserDBAdaptor(organizationId).get(owner, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(UserDBAdaptor.QueryParams.ACCOUNT.key(), UserDBAdaptor.QueryParams.PROJECTS.key()))); if (userDataResult.getNumResults() == 0) { throw new CatalogException("User " + owner + " not found"); @@ -664,19 +675,19 @@ public void importReleases(String owner, String inputDirStr, String sessionId) t project.put(ProjectDBAdaptor.QueryParams.UID.key(), ParamUtils.getAsLong(project.get(ProjectDBAdaptor.QueryParams.UID.key()))); // Check the projectId - if (projectDBAdaptor.exists((Long) project.get(ProjectDBAdaptor.QueryParams.UID.key()))) { + if (getProjectDBAdaptor(organizationId).exists((Long) project.get(ProjectDBAdaptor.QueryParams.UID.key()))) { throw new CatalogException("The database is not empty. Project " + project.get(ProjectDBAdaptor.QueryParams.NAME.key()) + " already exists"); } logger.info("Importing projects..."); - projectDBAdaptor.nativeInsert(project, owner); + getProjectDBAdaptor(organizationId).nativeInsert(project, owner); // Reading studies try (BufferedReader br = new BufferedReader(new FileReader(inputDir.resolve("studies.json").toFile()))) { logger.info("Importing studies..."); for (String line = br.readLine(); line != null; line = br.readLine()) { Map study = objectMapper.readValue(line, Map.class); - studyDBAdaptor.nativeInsert(study, owner); + getStudyDBAdaptor(organizationId).nativeInsert(study, owner); } } @@ -685,7 +696,7 @@ public void importReleases(String owner, String inputDirStr, String sessionId) t logger.info("Importing files..."); for (String line = br.readLine(); line != null; line = br.readLine()) { Map file = objectMapper.readValue(line, Map.class); - fileDBAdaptor.nativeInsert(file, owner); + getFileDBAdaptor(organizationId).nativeInsert(file, owner); } } @@ -694,7 +705,7 @@ public void importReleases(String owner, String inputDirStr, String sessionId) t logger.info("Importing samples..."); for (String line = br.readLine(); line != null; line = br.readLine()) { Map sample = objectMapper.readValue(line, Map.class); - sampleDBAdaptor.nativeInsert(sample, owner); + getSampleDBAdaptor(organizationId).nativeInsert(sample, owner); } } @@ -703,7 +714,7 @@ public void importReleases(String owner, String inputDirStr, String sessionId) t logger.info("Importing individuals..."); for (String line = br.readLine(); line != null; line = br.readLine()) { Map file = objectMapper.readValue(line, Map.class); - individualDBAdaptor.nativeInsert(file, owner); + getIndividualDBAdaptor(organizationId).nativeInsert(file, owner); } } @@ -712,7 +723,7 @@ public void importReleases(String owner, String inputDirStr, String sessionId) t logger.info("Importing families..."); for (String line = br.readLine(); line != null; line = br.readLine()) { Map file = objectMapper.readValue(line, Map.class); - familyDBAdaptor.nativeInsert(file, owner); + getFamilyDBAdaptor(organizationId).nativeInsert(file, owner); } } @@ -721,7 +732,7 @@ public void importReleases(String owner, String inputDirStr, String sessionId) t logger.info("Importing clinical analysis..."); for (String line = br.readLine(); line != null; line = br.readLine()) { Map file = objectMapper.readValue(line, Map.class); - clinicalDBAdaptor.nativeInsert(file, owner); + getClinicalAnalysisDBAdaptor(organizationId).nativeInsert(file, owner); } } @@ -730,7 +741,7 @@ public void importReleases(String owner, String inputDirStr, String sessionId) t logger.info("Importing cohorts..."); for (String line = br.readLine(); line != null; line = br.readLine()) { Map file = objectMapper.readValue(line, Map.class); - cohortDBAdaptor.nativeInsert(file, owner); + getCohortDBAdaptor(organizationId).nativeInsert(file, owner); } } @@ -739,12 +750,13 @@ public void importReleases(String owner, String inputDirStr, String sessionId) t logger.info("Importing jobs..."); for (String line = br.readLine(); line != null; line = br.readLine()) { Map file = objectMapper.readValue(line, Map.class); - jobDBAdaptor.nativeInsert(file, owner); + getJobDBAdaptor(organizationId).nativeInsert(file, owner); } } } - public void exportByFileNames(String studyStr, File outputDir, File filePath, String token) throws CatalogException { + public void exportByFileNames(String organizationId, String studyStr, File outputDir, File filePath, String token) + throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); if (!authorizationManager.isInstallationAdministrator(userId)) { throw new CatalogAuthorizationException("Only admin of OpenCGA is authorised to export data"); @@ -764,7 +776,7 @@ public void exportByFileNames(String studyStr, File outputDir, File filePath, St ObjectMapper objectMapper = new ObjectMapper(); // We obtain the owner of the study - OpenCGAResult studyDataResult = catalogManager.getStudyManager().get(studyStr, + OpenCGAResult studyDataResult = catalogManager.getStudyManager().get(organizationId, studyStr, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(StudyDBAdaptor.QueryParams.ID.key(), StudyDBAdaptor.QueryParams.FQN.key(), StudyDBAdaptor.QueryParams.VARIABLE_SET.key())), token); @@ -790,7 +802,7 @@ public void exportByFileNames(String studyStr, File outputDir, File filePath, St Query query = new Query(FileDBAdaptor.QueryParams.URI.key(), "file://" + vcfFile); OpenCGAResult fileDataResult = catalogManager.getFileManager() - .search(studyStr, query, QueryOptions.empty(), ownerToken); + .search(organizationId, studyStr, query, QueryOptions.empty(), ownerToken); if (fileDataResult.getNumResults() == 0) { logger.error("File " + vcfFile + " not found. Skipping..."); continue; @@ -811,7 +823,7 @@ public void exportByFileNames(String studyStr, File outputDir, File filePath, St org.opencb.opencga.core.models.file.File.Format.BIGWIG)); OpenCGAResult otherFiles = catalogManager.getFileManager() - .search(studyStr, query, QueryOptions.empty(), ownerToken); + .search(organizationId, studyStr, query, QueryOptions.empty(), ownerToken); if (otherFiles.getNumResults() > 0) { fileList.addAll(otherFiles.getResults()); } @@ -819,7 +831,7 @@ public void exportByFileNames(String studyStr, File outputDir, File filePath, St // Look for the whole sample information query = new Query(SampleDBAdaptor.QueryParams.ID.key(), sampleIds); OpenCGAResult sampleDataResult = catalogManager.getSampleManager() - .search(studyStr, query, QueryOptions.empty(), ownerToken); + .search(organizationId, studyStr, query, QueryOptions.empty(), ownerToken); if (sampleDataResult.getNumResults() == 0 || sampleDataResult.getNumResults() != sampleIds.size()) { logger.error("Unexpected error when looking for whole sample information. Could only find {} results. " + "Samples ids {}", sampleDataResult.getNumResults(), sampleIds); @@ -833,7 +845,7 @@ public void exportByFileNames(String studyStr, File outputDir, File filePath, St // Look for the whole sample information query = new Query(IndividualDBAdaptor.QueryParams.SAMPLES.key(), sampleIds); OpenCGAResult individualDataResult = catalogManager.getIndividualManager() - .search(studyStr, query, QueryOptions.empty(), ownerToken); + .search(organizationId, studyStr, query, QueryOptions.empty(), ownerToken); // for (Individual individual : individualDataResult.getResults()) { // OpenCGAResult annotationSetAsMap = catalogManager.getIndividualManager() @@ -853,7 +865,7 @@ public void exportByFileNames(String studyStr, File outputDir, File filePath, St .append(CohortDBAdaptor.QueryParams.SAMPLES.key(), sampleIds) .append(CohortDBAdaptor.QueryParams.ID.key(), "!=ALL"); OpenCGAResult cohortDataResult = catalogManager.getCohortManager() - .search(studyStr, query, QueryOptions.empty(), ownerToken); + .search(organizationId, studyStr, query, QueryOptions.empty(), ownerToken); // for (Cohort cohort : cohortDataResult.getResults()) { // OpenCGAResult annotationSetAsMap = catalogManager.getCohortManager() @@ -928,8 +940,9 @@ private void exportToFile(List dataList, File file, ObjectMapper objectM } } - public void exportReleases(String projectStr, int release, String outputDirStr, String sessionId) throws CatalogException { - String userId = catalogManager.getUserManager().getUserId(sessionId); + public void exportReleases(String organizationId, String projectStr, int release, String outputDirStr, String token) + throws CatalogException { + String userId = catalogManager.getUserManager().getUserId(token); if (!authorizationManager.isInstallationAdministrator(userId)) { throw new CatalogAuthorizationException("Only admin of OpenCGA is authorised to export data"); } @@ -957,7 +970,7 @@ public void exportReleases(String projectStr, int release, String outputDirStr, ProjectDBAdaptor.QueryParams.CURRENT_RELEASE.key() )) .append(QueryOptions.EXCLUDE, "studies"); - Project project = resolveId(projectStr, userId); + Project project = resolveId(organizationId, projectStr, userId); long projectId = project.getUid(); int currentRelease = project.getCurrentRelease(); @@ -967,20 +980,20 @@ public void exportReleases(String projectStr, int release, String outputDirStr, ObjectMapper objectMapper = getDefaultObjectMapper(); Query query = new Query(ProjectDBAdaptor.QueryParams.UID.key(), projectId); - DBIterator dbIterator = projectDBAdaptor.nativeIterator(query, QueryOptions.empty()); + DBIterator dbIterator = getProjectDBAdaptor(organizationId).nativeIterator(query, QueryOptions.empty()); exportToFile(dbIterator, outputDir.resolve("projects.json").toFile(), objectMapper, "project"); // Get all the studies contained in the project query = new Query() .append(StudyDBAdaptor.QueryParams.PROJECT_ID.key(), projectId) .append(StudyDBAdaptor.QueryParams.RELEASE.key(), "<=" + release); - OpenCGAResult studyDataResult = studyDBAdaptor.get(query, + OpenCGAResult studyDataResult = getStudyDBAdaptor(organizationId).get(query, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.UID.key())); if (studyDataResult.getNumResults() == 0) { logger.info("The project does not contain any study under the specified release"); return; } - dbIterator = studyDBAdaptor.nativeIterator(query, QueryOptions.empty()); + dbIterator = getStudyDBAdaptor(organizationId).nativeIterator(query, QueryOptions.empty()); exportToFile(dbIterator, outputDir.resolve("studies.json").toFile(), objectMapper, "studies"); List studyIds = studyDataResult.getResults().stream().map(Study::getUid).collect(Collectors.toList()); @@ -989,45 +1002,45 @@ public void exportReleases(String projectStr, int release, String outputDirStr, .append(SampleDBAdaptor.QueryParams.STUDY_UID.key(), studyIds) .append(SampleDBAdaptor.QueryParams.SNAPSHOT.key(), "<=" + release) .append(Constants.ALL_VERSIONS, true); - dbIterator = sampleDBAdaptor.nativeIterator(query, QueryOptions.empty()); + dbIterator = getSampleDBAdaptor(organizationId).nativeIterator(query, QueryOptions.empty()); exportToFile(dbIterator, outputDir.resolve("samples.json").toFile(), objectMapper, "samples"); query = new Query() .append(IndividualDBAdaptor.QueryParams.STUDY_UID.key(), studyIds) .append(IndividualDBAdaptor.QueryParams.SNAPSHOT.key(), "<=" + release) .append(Constants.ALL_VERSIONS, true); - dbIterator = individualDBAdaptor.nativeIterator(query, QueryOptions.empty()); + dbIterator = getIndividualDBAdaptor(organizationId).nativeIterator(query, QueryOptions.empty()); exportToFile(dbIterator, outputDir.resolve("individuals.json").toFile(), objectMapper, "individuals"); query = new Query() .append(FamilyDBAdaptor.QueryParams.STUDY_UID.key(), studyIds) .append(FamilyDBAdaptor.QueryParams.SNAPSHOT.key(), "<=" + release) .append(Constants.ALL_VERSIONS, true); - dbIterator = familyDBAdaptor.nativeIterator(query, QueryOptions.empty()); + dbIterator = getFamilyDBAdaptor(organizationId).nativeIterator(query, QueryOptions.empty()); exportToFile(dbIterator, outputDir.resolve("families.json").toFile(), objectMapper, "families"); query = new Query() .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), studyIds) .append(FileDBAdaptor.QueryParams.RELEASE.key(), "<=" + release); - dbIterator = fileDBAdaptor.nativeIterator(query, QueryOptions.empty()); + dbIterator = getFileDBAdaptor(organizationId).nativeIterator(query, QueryOptions.empty()); exportToFile(dbIterator, outputDir.resolve("files.json").toFile(), objectMapper, "files"); query = new Query() .append(ClinicalAnalysisDBAdaptor.QueryParams.STUDY_UID.key(), studyIds) .append(ClinicalAnalysisDBAdaptor.QueryParams.RELEASE.key(), "<=" + release); - dbIterator = clinicalDBAdaptor.nativeIterator(query, QueryOptions.empty()); + dbIterator = getClinicalAnalysisDBAdaptor(organizationId).nativeIterator(query, QueryOptions.empty()); exportToFile(dbIterator, outputDir.resolve("clinical_analysis.json").toFile(), objectMapper, "clinical analysis"); query = new Query() .append(CohortDBAdaptor.QueryParams.STUDY_UID.key(), studyIds) .append(CohortDBAdaptor.QueryParams.RELEASE.key(), "<=" + release); - dbIterator = cohortDBAdaptor.nativeIterator(query, QueryOptions.empty()); + dbIterator = getCohortDBAdaptor(organizationId).nativeIterator(query, QueryOptions.empty()); exportToFile(dbIterator, outputDir.resolve("cohorts.json").toFile(), objectMapper, "cohorts"); query = new Query() .append(JobDBAdaptor.QueryParams.STUDY_UID.key(), studyIds) .append(JobDBAdaptor.QueryParams.RELEASE.key(), "<=" + release); - dbIterator = jobDBAdaptor.nativeIterator(query, QueryOptions.empty()); + dbIterator = getJobDBAdaptor(organizationId).nativeIterator(query, QueryOptions.empty()); exportToFile(dbIterator, outputDir.resolve("jobs.json").toFile(), objectMapper, "jobs"); } @@ -1064,14 +1077,14 @@ private void exportToFile(DBIterator dbIterator, File file, ObjectMapper objectM } } - public OpenCGAResult rank(String userId, Query query, String field, int numResults, boolean asc, String sessionId) + public OpenCGAResult rank(String organizationId, String userId, Query query, String field, int numResults, boolean asc, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); ParamUtils.checkObj(field, "field"); ParamUtils.checkObj(userId, "userId"); - ParamUtils.checkObj(sessionId, "sessionId"); + ParamUtils.checkObj(token, "sessionId"); - String userOfQuery = this.catalogManager.getUserManager().getUserId(sessionId); + String userOfQuery = this.catalogManager.getUserManager().getUserId(token); if (!userOfQuery.equals(userId)) { // The user cannot read projects of other users. throw CatalogAuthorizationException.cantRead(userOfQuery, "Project", null, userId); @@ -1083,20 +1096,21 @@ public OpenCGAResult rank(String userId, Query query, String field, int numResul OpenCGAResult queryResult = null; if (count) { // We do not need to check for permissions when we show the count of files - queryResult = projectDBAdaptor.rank(query, field, numResults, asc); + queryResult = getProjectDBAdaptor(organizationId).rank(query, field, numResults, asc); } return ParamUtils.defaultObject(queryResult, OpenCGAResult::new); } - public OpenCGAResult groupBy(String userId, Query query, String field, QueryOptions options, String sessionId) throws CatalogException { + public OpenCGAResult groupBy(String organizationId, String userId, Query query, String field, QueryOptions options, String token) + throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); ParamUtils.checkObj(field, "field"); ParamUtils.checkObj(userId, "userId"); - ParamUtils.checkObj(sessionId, "sessionId"); + ParamUtils.checkObj(token, "sessionId"); - String userOfQuery = this.catalogManager.getUserManager().getUserId(sessionId); + String userOfQuery = this.catalogManager.getUserManager().getUserId(token); if (!userOfQuery.equals(userId)) { // The user cannot read projects of other users. throw CatalogAuthorizationException.cantRead(userOfQuery, "Project", null, userId); @@ -1107,21 +1121,21 @@ public OpenCGAResult groupBy(String userId, Query query, String field, QueryOpti OpenCGAResult queryResult = null; if (count) { // We do not need to check for permissions when we show the count of files - queryResult = projectDBAdaptor.groupBy(query, field, options); + queryResult = getProjectDBAdaptor(organizationId).groupBy(query, field, options); } return ParamUtils.defaultObject(queryResult, OpenCGAResult::new); } - public OpenCGAResult groupBy(String userId, Query query, List fields, QueryOptions options, String sessionId) + public OpenCGAResult groupBy(String organizationId, String userId, Query query, List fields, QueryOptions options, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); ParamUtils.checkObj(fields, "fields"); ParamUtils.checkObj(userId, "userId"); - ParamUtils.checkObj(sessionId, "sessionId"); + ParamUtils.checkObj(token, "sessionId"); - String userOfQuery = this.catalogManager.getUserManager().getUserId(sessionId); + String userOfQuery = this.catalogManager.getUserManager().getUserId(token); if (!userOfQuery.equals(userId)) { // The user cannot read projects of other users. throw CatalogAuthorizationException.cantRead(userOfQuery, "Project", null, userId); @@ -1132,14 +1146,15 @@ public OpenCGAResult groupBy(String userId, Query query, List fields, Qu OpenCGAResult queryResult = null; if (count) { // We do not need to check for permissions when we show the count of files - queryResult = projectDBAdaptor.groupBy(query, fields, options); + queryResult = getProjectDBAdaptor(organizationId).groupBy(query, fields, options); } return ParamUtils.defaultObject(queryResult, OpenCGAResult::new); } // Return true if currentRelease is found in any entry - private boolean checkCurrentReleaseInUse(List allStudiesInProject, int currentRelease) throws CatalogException { + private boolean checkCurrentReleaseInUse(String organizationId, List allStudiesInProject, int currentRelease) + throws CatalogException { for (Study study : allStudiesInProject) { if (study.getRelease() == currentRelease) { return true; @@ -1149,28 +1164,28 @@ private boolean checkCurrentReleaseInUse(List allStudiesInProject, int cu Query query = new Query() .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), studyIds) .append(FileDBAdaptor.QueryParams.RELEASE.key(), currentRelease); - if (fileDBAdaptor.count(query).getNumMatches() > 0) { + if (getFileDBAdaptor(organizationId).count(query).getNumMatches() > 0) { return true; } - if (sampleDBAdaptor.count(query).getNumMatches() > 0) { + if (getSampleDBAdaptor(organizationId).count(query).getNumMatches() > 0) { return true; } - if (individualDBAdaptor.count(query).getNumMatches() > 0) { + if (getIndividualDBAdaptor(organizationId).count(query).getNumMatches() > 0) { return true; } - if (cohortDBAdaptor.count(query).getNumMatches() > 0) { + if (getCohortDBAdaptor(organizationId).count(query).getNumMatches() > 0) { return true; } - if (familyDBAdaptor.count(query).getNumMatches() > 0) { + if (getFamilyDBAdaptor(organizationId).count(query).getNumMatches() > 0) { return true; } - if (jobDBAdaptor.count(query).getNumMatches() > 0) { + if (getJobDBAdaptor(organizationId).count(query).getNumMatches() > 0) { return true; } // if (diseasePanelDBAdaptor.count(query).getNumMatches() > 0) { // return true; // } - if (clinicalDBAdaptor.count(query).getNumMatches() > 0) { + if (getClinicalAnalysisDBAdaptor(organizationId).count(query).getNumMatches() > 0) { return true; } diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/ResourceManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/ResourceManager.java index a6e14d9942c..a9dac803033 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/ResourceManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/ResourceManager.java @@ -53,80 +53,87 @@ public abstract class ResourceManager extends Abstra abstract Enums.Resource getEntity(); - OpenCGAResult internalGet(long studyUid, String entry, QueryOptions options, String user) throws CatalogException { - return internalGet(studyUid, entry, null, options, user); + OpenCGAResult internalGet(String organizationId, long studyUid, String entry, QueryOptions options, String user) throws CatalogException { + return internalGet(organizationId, studyUid, entry, null, options, user); } - OpenCGAResult internalGet(long studyUid, String entry, @Nullable Query query, QueryOptions options, String user) - throws CatalogException { + OpenCGAResult internalGet(String organizationId, long studyUid, String entry, @Nullable Query query, QueryOptions options, + String user) throws CatalogException { ParamUtils.checkIsSingleID(entry); - return internalGet(studyUid, Collections.singletonList(entry), query, options, user, false); + return internalGet(organizationId, studyUid, Collections.singletonList(entry), query, options, user, false); } - InternalGetDataResult internalGet(long studyUid, List entryList, QueryOptions options, String user, boolean ignoreException) - throws CatalogException { - return internalGet(studyUid, entryList, null, options, user, ignoreException); + InternalGetDataResult internalGet(String organizationId, long studyUid, List entryList, QueryOptions options, String user, + boolean ignoreException) throws CatalogException { + return internalGet(organizationId, studyUid, entryList, null, options, user, ignoreException); } - abstract InternalGetDataResult internalGet(long studyUid, List entryList, @Nullable Query query, QueryOptions options, - String user, boolean ignoreException) throws CatalogException; + abstract InternalGetDataResult internalGet(String organizationId, long studyUid, List entryList, @Nullable Query query, + QueryOptions options, String user, boolean ignoreException) throws CatalogException; /** * Create an entry in catalog. * - * @param studyStr Study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. - * @param entry entry that needs to be added in Catalog. - * @param options QueryOptions object. - * @param token Session id of the user logged in. + * @param organizationId Organization id. + * @param studyStr Study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. + * @param entry entry that needs to be added in Catalog. + * @param options QueryOptions object. + * @param token Session id of the user logged in. * @return A OpenCGAResult of the object created. * @throws CatalogException if any parameter from the entry is incorrect, the user does not have permissions... */ - public abstract OpenCGAResult create(String studyStr, R entry, QueryOptions options, String token) throws CatalogException; + public abstract OpenCGAResult create(String organizationId, String studyStr, R entry, QueryOptions options, String token) + throws CatalogException; /** * Fetch the R object. * - * @param studyStr Study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. - * @param entryStr Entry id to be fetched. - * @param options QueryOptions object, like "include", "exclude", "limit" and "skip". - * @param token token + * @param organizationId Organization id. + * @param studyStr Study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. + * @param entryStr Entry id to be fetched. + * @param options QueryOptions object, like "include", "exclude", "limit" and "skip". + * @param token token * @return All matching elements. * @throws CatalogException CatalogException. */ - public OpenCGAResult get(String studyStr, String entryStr, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult get(String organizationId, String studyStr, String entryStr, QueryOptions options, String token) + throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); - return internalGet(study.getUid(), entryStr, options, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); + return internalGet(organizationId, study.getUid(), entryStr, options, userId); } /** * Fetch all the R objects matching the query. * - * @param studyStr Study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. - * @param entryList Comma separated list of entries to be fetched. - * @param options QueryOptions object, like "include", "exclude", "limit" and "skip". - * @param token token + * @param organizationId Organization id. + * @param studyStr Study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. + * @param entryList Comma separated list of entries to be fetched. + * @param options QueryOptions object, like "include", "exclude", "limit" and "skip". + * @param token token * @return All matching elements. * @throws CatalogException CatalogException. */ - public OpenCGAResult get(String studyStr, List entryList, QueryOptions options, String token) throws CatalogException { - return get(studyStr, entryList, new Query(), options, false, token); + public OpenCGAResult get(String organizationId, String studyStr, List entryList, QueryOptions options, String token) + throws CatalogException { + return get(organizationId, studyStr, entryList, new Query(), options, false, token); } - public OpenCGAResult get(String studyStr, List entryList, QueryOptions options, boolean ignoreException, String token) + public OpenCGAResult get(String organizationId, String studyStr, List entryList, QueryOptions options, boolean ignoreException, String token) throws CatalogException { - return get(studyStr, entryList, new Query(), options, ignoreException, token); + return get(organizationId, studyStr, entryList, new Query(), options, ignoreException, token); } - public OpenCGAResult get(String studyId, List entryList, Query query, QueryOptions options, boolean ignoreException, - String token) throws CatalogException { + public OpenCGAResult get(String organizationId, String studyId, List entryList, Query query, QueryOptions options, + boolean ignoreException, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId); query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyId) .append("entryList", entryList) .append("query", new Query(query)) @@ -140,7 +147,7 @@ public OpenCGAResult get(String studyId, List entryList, Query query, OpenCGAResult result = OpenCGAResult.empty(); options.remove(QueryOptions.LIMIT); - InternalGetDataResult responseResult = internalGet(study.getUid(), entryList, query, options, userId, ignoreException); + InternalGetDataResult responseResult = internalGet(organizationId, study.getUid(), entryList, query, options, userId, ignoreException); Map missingMap = new HashMap<>(); if (responseResult.getMissing() != null) { @@ -184,125 +191,140 @@ public OpenCGAResult get(String studyId, List entryList, Query query, /** * Obtain an entry iterator to iterate over the matching entries. * - * @param studyStr study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. - * @param query Query object. - * @param options QueryOptions object. - * @param token Session id of the user logged in. + * @param organizationId Organization id. + * @param studyStr study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. + * @param query Query object. + * @param options QueryOptions object. + * @param token Session id of the user logged in. * @return An iterator. * @throws CatalogException if there is any internal error. */ - public abstract DBIterator iterator(String studyStr, Query query, QueryOptions options, String token) throws CatalogException; + public abstract DBIterator iterator(String organizationId, String studyStr, Query query, QueryOptions options, String token) + throws CatalogException; /** * Search of entries in catalog. * - * @param studyId study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. - * @param query Query object. - * @param options QueryOptions object. - * @param token Session id of the user logged in. + * @param organizationId Organization id. + * @param studyId study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. + * @param query Query object. + * @param options QueryOptions object. + * @param token Session id of the user logged in. * @return The list of entries matching the query. * @throws CatalogException catalogException. */ - public abstract OpenCGAResult search(String studyId, Query query, QueryOptions options, String token) throws CatalogException; + public abstract OpenCGAResult search(String organizationId, String studyId, Query query, QueryOptions options, String token) + throws CatalogException; /** * Fetch a list containing all the distinct values of the key {@code field}. * - * @param studyId study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. - * @param field The field for which to return distinct values. - * @param query Query object. - * @param token Token of the user logged in. + * @param organizationId + * @param studyId study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. + * @param field The field for which to return distinct values. + * @param query Query object. + * @param token Token of the user logged in. * @return The list of distinct values. * @throws CatalogException CatalogException. */ - public OpenCGAResult distinct(String studyId, String field, Query query, String token) throws CatalogException { - return distinct(studyId, Collections.singletonList(field), query, token); + public OpenCGAResult distinct(String organizationId, String studyId, String field, Query query, String token) + throws CatalogException { + return distinct(organizationId, studyId, Collections.singletonList(field), query, token); } /** * Fetch a list containing all the distinct values of the key {@code field}. * - * @param studyId study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. - * @param fields Fields for which to return distinct values. - * @param query Query object. - * @param token Token of the user logged in. + * @param organizationId Organization id. + * @param studyId study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. + * @param fields Fields for which to return distinct values. + * @param query Query object. + * @param token Token of the user logged in. * @return The list of distinct values. * @throws CatalogException CatalogException. */ - public abstract OpenCGAResult distinct(String studyId, List fields, Query query, String token) throws CatalogException; + public abstract OpenCGAResult distinct(String organizationId, String studyId, List fields, Query query, String token) + throws CatalogException; /** * Count matching entries in catalog. * - * @param studyId study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. - * @param query Query object. - * @param token Session id of the user logged in. + * @param organizationId Organization id. + * @param studyId study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. + * @param query Query object. + * @param token Session id of the user logged in. * @return A OpenCGAResult with the total number of entries matching the query. * @throws CatalogException catalogException. */ - public abstract OpenCGAResult count(String studyId, Query query, String token) throws CatalogException; + public abstract OpenCGAResult count(String organizationId, String studyId, Query query, String token) throws CatalogException; - public abstract OpenCGAResult delete(String studyStr, List ids, QueryOptions options, String token) throws CatalogException; + public abstract OpenCGAResult delete(String organizationId, String studyStr, List ids, QueryOptions options, String token) + throws CatalogException; /** * Delete all entries matching the query. * - * @param studyStr Study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. - * @param query Query object. - * @param options Map containing additional parameters to be considered for the deletion. - * @param token Session id of the user logged in. - * @throws CatalogException if the study or the user do not exist. + * @param organizationId Organization id. + * @param studyStr Study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. + * @param query Query object. + * @param options Map containing additional parameters to be considered for the deletion. + * @param token Session id of the user logged in. * @return A OpenCGAResult object containing the number of matching elements, deleted and elements that could not be deleted. + * @throws CatalogException if the study or the user do not exist. */ - public abstract OpenCGAResult delete(String studyStr, Query query, QueryOptions options, String token) throws CatalogException; + public abstract OpenCGAResult delete(String organizationId, String studyStr, Query query, QueryOptions options, String token) + throws CatalogException; /** * Ranks the elements queried, groups them by the field(s) given and return it sorted. * - * @param studyStr study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. - * @param query Query object containing the query that will be executed. - * @param field A field or a comma separated list of fields by which the results will be grouped in. - * @param numResults Maximum number of results to be reported. - * @param asc Order in which the results will be reported. - * @param token Session id of the user logged in. + * @param organizationId Organization id. + * @param studyStr study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. + * @param query Query object containing the query that will be executed. + * @param field A field or a comma separated list of fields by which the results will be grouped in. + * @param numResults Maximum number of results to be reported. + * @param asc Order in which the results will be reported. + * @param token Session id of the user logged in. * @return A OpenCGAResult object containing each of the fields in field and the count of them matching the query. * @throws CatalogException CatalogException */ - public abstract OpenCGAResult rank(String studyStr, Query query, String field, int numResults, boolean asc, String token) - throws CatalogException; + public abstract OpenCGAResult rank(String organizationId, String studyStr, Query query, String field, int numResults, boolean asc, + String token) throws CatalogException; /** * Groups the matching entries by some fields. * - * @param studyStr study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. - * @param query Query object. - * @param fields A field or a comma separated list of fields by which the results will be grouped in. - * @param options QueryOptions object. - * @param token Session id of the user logged in. + * @param organizationId Organization id. + * @param studyStr study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. + * @param query Query object. + * @param fields A field or a comma separated list of fields by which the results will be grouped in. + * @param options QueryOptions object. + * @param token Session id of the user logged in. * @return A OpenCGAResult object containing the results of the query grouped by the fields. * @throws CatalogException CatalogException */ - public OpenCGAResult groupBy(@Nullable String studyStr, Query query, String fields, QueryOptions options, String token) - throws CatalogException { + public OpenCGAResult groupBy(String organizationId, @Nullable String studyStr, Query query, String fields, QueryOptions options, + String token) throws CatalogException { if (StringUtils.isEmpty(fields)) { throw new CatalogException("Empty fields parameter."); } - return groupBy(studyStr, query, Arrays.asList(fields.split(",")), options, token); + return groupBy(organizationId, studyStr, query, Arrays.asList(fields.split(",")), options, token); } /** * Groups the matching entries by some fields. * - * @param studyStr study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. - * @param query Query object. - * @param options QueryOptions object. - * @param fields A field or a comma separated list of fields by which the results will be grouped in. - * @param token Session id of the user logged in. + * @param organizationId Organization id. + * @param studyStr study id in string format. Could be one of [id|user@aliasProject:aliasStudy|aliasProject:aliasStudy|aliasStudy]. + * @param query Query object. + * @param fields A field or a comma separated list of fields by which the results will be grouped in. + * @param options QueryOptions object. + * @param token Session id of the user logged in. * @return A OpenCGAResult object containing the results of the query grouped by the fields. * @throws CatalogException CatalogException */ - public abstract OpenCGAResult groupBy(@Nullable String studyStr, Query query, List fields, QueryOptions options, String token) - throws CatalogException; + public abstract OpenCGAResult groupBy(String organizationId, @Nullable String studyStr, Query query, List fields, + QueryOptions options, String token) throws CatalogException; /** * Returns result if there are no ERROR events or ignoreException is true. Otherwise, raise an exception with all error messages. diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/SampleManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/SampleManager.java index 5ab592050d2..3016e647e5f 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/SampleManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/SampleManager.java @@ -98,7 +98,7 @@ Enums.Resource getEntity() { } @Override - InternalGetDataResult internalGet(long studyUid, List entryList, @Nullable Query query, QueryOptions options, + InternalGetDataResult internalGet(String organizationId, long studyUid, List entryList, @Nullable Query query, QueryOptions options, String user, boolean ignoreException) throws CatalogException { if (ListUtils.isEmpty(entryList)) { throw new CatalogException("Missing sample entries."); @@ -179,7 +179,7 @@ void validateNewSample(Study study, Sample sample, String userId) throws Catalog if (StringUtils.isNotEmpty(sample.getIndividualId())) { // Check individual exists - OpenCGAResult individualDataResult = catalogManager.getIndividualManager().internalGet(study.getUid(), + OpenCGAResult individualDataResult = catalogManager.getIndividualManager().internalGet(organizationId, study.getUid(), sample.getIndividualId(), IndividualManager.INCLUDE_INDIVIDUAL_IDS, userId); if (individualDataResult.getNumResults() == 0) { throw new CatalogException("Individual '" + sample.getIndividualId() + "' not found."); @@ -223,11 +223,11 @@ void validateNewSample(Study study, Sample sample, String userId) throws Catalog } @Override - public OpenCGAResult create(String studyStr, Sample sample, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult create(String organizationId, String studyStr, Sample sample, QueryOptions options, String token) throws CatalogException { options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -258,12 +258,12 @@ public OpenCGAResult create(String studyStr, Sample sample, QueryOptions } @Override - public DBIterator iterator(String studyStr, Query query, QueryOptions options, String sessionId) throws CatalogException { + public DBIterator iterator(String organizationId, String studyStr, Query query, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(sessionId); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); Query finalQuery = new Query(query); fixQueryObject(study, finalQuery, userId); @@ -274,12 +274,12 @@ public DBIterator iterator(String studyStr, Query query, QueryOptions op } @Override - public OpenCGAResult search(String studyId, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult search(String organizationId, String studyId, Query query, QueryOptions options, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -307,11 +307,11 @@ public OpenCGAResult search(String studyId, Query query, QueryOptions op } @Override - public OpenCGAResult distinct(String studyId, List fields, Query query, String token) throws CatalogException { + public OpenCGAResult distinct(String organizationId, String studyId, List fields, Query query, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); ObjectMap auditParams = new ObjectMap() @@ -370,7 +370,7 @@ void fixQueryObject(Study study, Query query, String userId) throws CatalogExcep if (queryFileManager) { // Obtain the corresponding fileIds - InternalGetDataResult result = catalogManager.getFileManager().internalGet(study.getUid(), + InternalGetDataResult result = catalogManager.getFileManager().internalGet(organizationId, study.getUid(), query.getAsStringList(SampleDBAdaptor.QueryParams.FILE_IDS.key()), FileManager.INCLUDE_FILE_IDS, userId, true); if (result.getMissing() == null || result.getMissing().isEmpty()) { @@ -398,7 +398,7 @@ void fixQueryObject(Study study, Query query, String userId) throws CatalogExcep } if (queryIndividualManager) { - InternalGetDataResult result = catalogManager.getIndividualManager().internalGet(study.getUid(), + InternalGetDataResult result = catalogManager.getIndividualManager().internalGet(organizationId, study.getUid(), query.getAsStringList(SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key()), IndividualManager.INCLUDE_INDIVIDUAL_IDS, userId, true); if (result.getMissing() == null || result.getMissing().isEmpty()) { @@ -416,9 +416,9 @@ void fixQueryObject(Study study, Query query, String userId) throws CatalogExcep } @Override - public OpenCGAResult count(String studyId, Query query, String token) throws CatalogException { + public OpenCGAResult count(String organizationId, String studyId, Query query, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); query = new Query(ParamUtils.defaultObject(query, Query::new)); @@ -446,7 +446,7 @@ public OpenCGAResult count(String studyId, Query query, String token) th } @Override - public OpenCGAResult delete(String studyStr, List sampleIds, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, List sampleIds, QueryOptions options, String token) throws CatalogException { return delete(studyStr, sampleIds, options, false, token); } @@ -457,7 +457,7 @@ public OpenCGAResult delete(String studyStr, List sampleIds, ObjectMap p } String userId = catalogManager.getUserManager().getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = studyManager.resolveId(organizationId, studyStr, userId, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -485,7 +485,7 @@ public OpenCGAResult delete(String studyStr, List sampleIds, ObjectMap p String sampleId = id; String sampleUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), id, INCLUDE_SAMPLE_IDS, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, INCLUDE_SAMPLE_IDS, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Sample '" + id + "' not found"); } @@ -525,7 +525,7 @@ public OpenCGAResult delete(String studyStr, List sampleIds, ObjectMap p } @Override - public OpenCGAResult delete(String studyStr, Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult delete(String organizationId, String studyStr, Query query, QueryOptions options, String token) throws CatalogException { return delete(studyStr, query, options, false, token); } @@ -537,7 +537,7 @@ public OpenCGAResult delete(String studyStr, Query query, ObjectMap params, bool OpenCGAResult result = OpenCGAResult.empty(); String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationUuid = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -617,7 +617,7 @@ public OpenCGAResult delete(String studyStr, Query query, ObjectMap params, bool // TODO: This method should be private. This should only be accessible internally. public OpenCGAResult resetRgaIndexes(String studyStr, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -643,7 +643,7 @@ public OpenCGAResult resetRgaIndexes(String studyStr, String token) thro public OpenCGAResult updateRgaIndexes(String studyStr, List samples, RgaIndex rgaIndex, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); ObjectMap auditParams = new ObjectMap() .append("study", studyStr) @@ -666,7 +666,7 @@ public OpenCGAResult updateRgaIndexes(String studyStr, List samp rgaIndex.setDate(TimeUtils.getTime()); - sampleResult = internalGet(study.getUid(), samples, INCLUDE_SAMPLE_IDS, userId, false); + sampleResult = internalGet(organizationId, study.getUid(), samples, INCLUDE_SAMPLE_IDS, userId, false); result = sampleDBAdaptor.setRgaIndexes(study.getUid(), sampleResult.getResults().stream().map(Sample::getUid).collect(Collectors.toList()), rgaIndex); @@ -900,7 +900,7 @@ public OpenCGAResult update(String studyStr, Query query, SampleUpdatePa Query finalQuery = new Query(ParamUtils.defaultObject(query, Query::new)); String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -960,7 +960,7 @@ public OpenCGAResult update(String studyStr, Query query, SampleUpdatePa public OpenCGAResult update(String studyStr, String sampleId, SampleUpdateParams updateParams, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -981,7 +981,7 @@ public OpenCGAResult update(String studyStr, String sampleId, SampleUpda OpenCGAResult result = OpenCGAResult.empty(); String sampleUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), sampleId, INCLUDE_SAMPLE_IDS, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), sampleId, INCLUDE_SAMPLE_IDS, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Sample '" + sampleId + "' not found"); } @@ -1030,7 +1030,7 @@ public OpenCGAResult update(String studyStr, List sampleIds, Sam public OpenCGAResult update(String studyStr, List sampleIds, SampleUpdateParams updateParams, boolean ignoreException, QueryOptions options, String token) throws CatalogException { String userId = userManager.getUserId(token); - Study study = studyManager.resolveId(studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = studyManager.resolveId(organizationId, studyStr, userId, StudyManager.INCLUDE_VARIABLE_SET); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); @@ -1056,7 +1056,7 @@ public OpenCGAResult update(String studyStr, List sampleIds, Sam String sampleUuid = ""; try { - OpenCGAResult internalResult = internalGet(study.getUid(), id, INCLUDE_SAMPLE_IDS, userId); + OpenCGAResult internalResult = internalGet(organizationId, study.getUid(), id, INCLUDE_SAMPLE_IDS, userId); if (internalResult.getNumResults() == 0) { throw new CatalogException("Sample '" + id + "' not found"); } @@ -1148,7 +1148,7 @@ private OpenCGAResult update(Study study, Sample sample, SampleUpdateParams upda if (updateParamsClone != null && StringUtils.isNotEmpty(updateParamsClone.getIndividualId())) { // Check individual id exists - OpenCGAResult individualDataResult = catalogManager.getIndividualManager().internalGet(study.getUid(), + OpenCGAResult individualDataResult = catalogManager.getIndividualManager().internalGet(organizationId, study.getUid(), updateParamsClone.getIndividualId(), IndividualManager.INCLUDE_INDIVIDUAL_IDS, userId); if (individualDataResult.getNumResults() == 0) { throw new CatalogException("Individual '" + updateParamsClone.getIndividualId() + "' not found."); @@ -1171,14 +1171,14 @@ private OpenCGAResult update(Study study, Sample sample, SampleUpdateParams upda } @Override - public OpenCGAResult rank(String studyStr, Query query, String field, int numResults, boolean asc, String sessionId) + public OpenCGAResult rank(String organizationId, String studyStr, Query query, String field, int numResults, boolean asc, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); ParamUtils.checkObj(field, "field"); ParamUtils.checkObj(sessionId, "sessionId"); String userId = userManager.getUserId(sessionId); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); // Fix query if it contains any annotation AnnotationUtils.fixQueryAnnotationSearch(study, userId, query, authorizationManager); @@ -1198,7 +1198,7 @@ public OpenCGAResult rank(String studyStr, Query query, String field, int numRes } @Override - public OpenCGAResult groupBy(@Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) + public OpenCGAResult groupBy(String organizationId, @Nullable String studyStr, Query query, List fields, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); @@ -1207,7 +1207,7 @@ public OpenCGAResult groupBy(@Nullable String studyStr, Query query, List> getAcls(String studyId, Li List members, boolean ignoreException, String token) throws CatalogException { String user = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, user); + Study study = studyManager.resolveId(organizationId, studyId, user); String operationId = UuidUtils.generateOpenCgaUuid(UuidUtils.Entity.AUDIT); ObjectMap auditParams = new ObjectMap() @@ -1247,7 +1247,7 @@ public OpenCGAResult> getAcls(String studyId, Li Map missingMap = new HashMap<>(); try { auditManager.initAuditBatch(operationId); - InternalGetDataResult queryResult = internalGet(study.getUid(), sampleList, INCLUDE_SAMPLE_IDS, user, ignoreException); + InternalGetDataResult queryResult = internalGet(organizationId, study.getUid(), sampleList, INCLUDE_SAMPLE_IDS, user, ignoreException); if (queryResult.getMissing() != null) { missingMap = queryResult.getMissing().stream() @@ -1314,7 +1314,7 @@ public OpenCGAResult> updateAcl(String studyId, ParamUtils.AclAction action, String token) throws CatalogException { String user = userManager.getUserId(token); - Study study = studyManager.resolveId(studyId, user); + Study study = studyManager.resolveId(organizationId, studyId, user); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -1358,7 +1358,7 @@ public OpenCGAResult> updateAcl(String studyId, if (StringUtils.isNotEmpty(sampleAclParams.getIndividual())) { Query query = new Query(IndividualDBAdaptor.QueryParams.ID.key(), sampleAclParams.getIndividual()); QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, IndividualDBAdaptor.QueryParams.SAMPLES.key()); - OpenCGAResult indDataResult = catalogManager.getIndividualManager().search(studyId, query, options, token); + OpenCGAResult indDataResult = catalogManager.getIndividualManager().search(organizationId, studyId, query, options, token); Set sampleSet = new HashSet<>(); for (Individual individual : indDataResult.getResults()) { @@ -1369,7 +1369,7 @@ public OpenCGAResult> updateAcl(String studyId, } if (StringUtils.isNotEmpty(sampleAclParams.getFamily())) { - OpenCGAResult familyDataResult = catalogManager.getFamilyManager().get(studyId, + OpenCGAResult familyDataResult = catalogManager.getFamilyManager().get(organizationId, studyId, Arrays.asList(sampleAclParams.getFamily().split(",")), FamilyManager.INCLUDE_FAMILY_MEMBERS, token); Set sampleSet = new HashSet<>(); @@ -1389,7 +1389,7 @@ public OpenCGAResult> updateAcl(String studyId, if (StringUtils.isNotEmpty(sampleAclParams.getFile())) { // // Obtain the samples of the files QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, FileDBAdaptor.QueryParams.SAMPLE_IDS.key()); - OpenCGAResult fileDataResult = catalogManager.getFileManager().internalGet(study.getUid(), + OpenCGAResult fileDataResult = catalogManager.getFileManager().internalGet(organizationId, study.getUid(), Arrays.asList(StringUtils.split(sampleAclParams.getFile(), ",")), options, user, false); Set sampleSet = new HashSet<>(); @@ -1403,7 +1403,7 @@ public OpenCGAResult> updateAcl(String studyId, if (StringUtils.isNotEmpty(sampleAclParams.getCohort())) { Query query = new Query(CohortDBAdaptor.QueryParams.ID.key(), sampleAclParams.getCohort()); QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, CohortDBAdaptor.QueryParams.SAMPLES.key()); - OpenCGAResult cohortDataResult = catalogManager.getCohortManager().search(studyId, query, options, token); + OpenCGAResult cohortDataResult = catalogManager.getCohortManager().search(organizationId, studyId, query, options, token); Set sampleSet = new HashSet<>(); for (Cohort cohort : cohortDataResult.getResults()) { @@ -1413,7 +1413,7 @@ public OpenCGAResult> updateAcl(String studyId, sampleStringList.addAll(sampleSet); } - sampleList = internalGet(study.getUid(), sampleStringList, INCLUDE_SAMPLE_IDS, user, false).getResults(); + sampleList = internalGet(organizationId, study.getUid(), sampleStringList, INCLUDE_SAMPLE_IDS, user, false).getResults(); authorizationManager.checkCanAssignOrSeePermissions(study.getUid(), user); // Validate that the members are actually valid members @@ -1513,7 +1513,7 @@ public DataResult facet(String studyId, Query query, QueryOptions op throws CatalogException { String userId = userManager.getUserId(token); // We need to add variableSets and groups to avoid additional queries as it will be used in the catalogSolrManager - Study study = catalogManager.getStudyManager().resolveId(studyId, userId, new QueryOptions(QueryOptions.INCLUDE, + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyId, userId, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(StudyDBAdaptor.QueryParams.VARIABLE_SET.key(), StudyDBAdaptor.QueryParams.GROUPS.key()))); ParamUtils.defaultObject(query, Query::new); diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/StudyManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/StudyManager.java index e9e48ab01f4..1b01581b904 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/StudyManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/StudyManager.java @@ -126,33 +126,33 @@ public class StudyManager extends AbstractManager { logger = LoggerFactory.getLogger(StudyManager.class); } - public String getProjectId(long studyId) throws CatalogException { - return studyDBAdaptor.getProjectIdByStudyUid(studyId); - } +// public String getProjectId(long studyId) throws CatalogException { +// return studyDBAdaptor.getProjectIdByStudyUid(studyId); +// } - List resolveIds(List studyList, String userId) throws CatalogException { + List resolveIds(String organizationId, List studyList, String userId) throws CatalogException { if (studyList == null || studyList.isEmpty() || (studyList.size() == 1 && studyList.get(0).endsWith("*"))) { String studyStr = "*"; if (studyList != null && !studyList.isEmpty()) { studyStr = studyList.get(0); } - return smartResolutor(studyStr, userId, INCLUDE_STUDY_IDS).getResults(); + return smartResolutor(organizationId, studyStr, userId, INCLUDE_STUDY_IDS).getResults(); } List returnList = new ArrayList<>(studyList.size()); for (String study : studyList) { - returnList.add(resolveId(study, userId, INCLUDE_STUDY_IDS)); + returnList.add(resolveId(organizationId, study, userId, INCLUDE_STUDY_IDS)); } return returnList; } - Study resolveId(String studyStr, String userId) throws CatalogException { - return resolveId(studyStr, userId, INCLUDE_STUDY_IDS); + Study resolveId(String organizationId, String studyStr, String userId) throws CatalogException { + return resolveId(organizationId, studyStr, userId, INCLUDE_STUDY_IDS); } - Study resolveId(String studyStr, String userId, QueryOptions options) throws CatalogException { - OpenCGAResult studyDataResult = smartResolutor(studyStr, userId, options); + Study resolveId(String organizationId, String studyStr, String userId, QueryOptions options) throws CatalogException { + OpenCGAResult studyDataResult = smartResolutor(organizationId, studyStr, userId, options); if (studyDataResult.getNumResults() > 1) { String studyMessage = ""; @@ -166,7 +166,8 @@ Study resolveId(String studyStr, String userId, QueryOptions options) throws Cat return studyDataResult.first(); } - private OpenCGAResult smartResolutor(String studyStr, String userId, QueryOptions options) throws CatalogException { + private OpenCGAResult smartResolutor(String organizationId, String studyStr, String userId, QueryOptions options) + throws CatalogException { String owner = null; String project = null; @@ -220,14 +221,14 @@ private OpenCGAResult smartResolutor(String studyStr, String userId, Quer fixQueryOptions(queryOptions, INCLUDE_STUDY_IDS.getAsStringList(QueryOptions.INCLUDE)); } - OpenCGAResult studyDataResult = studyDBAdaptor.get(query, queryOptions, userId); + OpenCGAResult studyDataResult = getStudyDBAdaptor(organizationId).get(query, queryOptions, userId); if (studyDataResult.getNumResults() == 0) { if (!query.containsKey(StudyDBAdaptor.QueryParams.FQN.key())) { // By default, exclude the opencga study for the validation query.put(StudyDBAdaptor.QueryParams.FQN.key(), "!=" + OPENCGA + "@" + ADMIN_PROJECT + ":" + ADMIN_STUDY); } - studyDataResult = studyDBAdaptor.get(query, queryOptions); + studyDataResult = getStudyDBAdaptor(organizationId).get(query, queryOptions); if (studyDataResult.getNumResults() == 0) { String studyMessage = ""; if (StringUtils.isNotEmpty(studyStr)) { @@ -266,11 +267,12 @@ private void fixQueryOptions(QueryOptions queryOptions, List includeFiel } } - private OpenCGAResult getStudy(long projectUid, String studyUuid, QueryOptions options) throws CatalogDBException { + private OpenCGAResult getStudy(String organizationId, long projectUid, String studyUuid, QueryOptions options) + throws CatalogDBException { Query query = new Query() .append(StudyDBAdaptor.QueryParams.PROJECT_UID.key(), projectUid) .append(StudyDBAdaptor.QueryParams.UUID.key(), studyUuid); - return studyDBAdaptor.get(query, options); + return getStudyDBAdaptor(organizationId).get(query, options); } @Deprecated @@ -286,17 +288,19 @@ public OpenCGAResult create(String projectStr, String id, String alias, S .setInternal(internal) .setStatus(status) .setAttributes(attributes); - return create(projectStr, study, options, token); + return create(organizationId, projectStr, study, options, token); } - public OpenCGAResult create(String projectStr, Study study, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult create(String organizationId, String projectStr, Study study, QueryOptions options, String token) + throws CatalogException { ParamUtils.checkObj(study, "study"); ParamUtils.checkIdentifier(study.getId(), "id"); String userId = catalogManager.getUserManager().getUserId(token); - Project project = catalogManager.getProjectManager().resolveId(projectStr, userId); + Project project = catalogManager.getProjectManager().resolveId(organizationId, projectStr, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("projectId", projectStr) .append("study", study) .append("options", options) @@ -355,8 +359,8 @@ public OpenCGAResult create(String projectStr, Study study, QueryOptions study.setGroups(groups); /* CreateStudy */ - studyDBAdaptor.insert(project, study, options); - OpenCGAResult result = getStudy(projectUid, study.getUuid(), options); + getStudyDBAdaptor(organizationId).insert(project, study, options); + OpenCGAResult result = getStudy(organizationId, projectUid, study.getUuid(), options); study = result.getResults().get(0); URI uri; @@ -364,7 +368,7 @@ public OpenCGAResult create(String projectStr, Study study, QueryOptions uri = catalogIOManager.createStudy(userId, Long.toString(project.getUid()), Long.toString(study.getUid())); } catch (CatalogIOException e) { try { - studyDBAdaptor.delete(study); + getStudyDBAdaptor(organizationId).delete(study); } catch (Exception e1) { logger.error("Can't delete study after failure creating study", e1); } @@ -372,14 +376,14 @@ public OpenCGAResult create(String projectStr, Study study, QueryOptions } // Update uri of study - studyDBAdaptor.update(study.getUid(), new ObjectMap("uri", uri), QueryOptions.empty()); + getStudyDBAdaptor(organizationId).update(study.getUid(), new ObjectMap("uri", uri), QueryOptions.empty()); study.setUri(uri); - long rootFileId = fileDBAdaptor.getId(study.getUid(), ""); //Set studyUri to the root folder too - fileDBAdaptor.update(rootFileId, new ObjectMap("uri", uri), QueryOptions.empty()); + long rootFileId = getFileDBAdaptor(organizationId).getId(study.getUid(), ""); //Set studyUri to the root folder too + getFileDBAdaptor(organizationId).update(rootFileId, new ObjectMap("uri", uri), QueryOptions.empty()); // Read and process installation variable sets - createDefaultVariableSets(study, token); + createDefaultVariableSets(organizationId, study, token); auditManager.auditCreate(userId, Enums.Resource.STUDY, study.getId(), study.getUuid(), study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); @@ -395,12 +399,12 @@ public OpenCGAResult create(String projectStr, Study study, QueryOptions } } - public void createDefaultVariableSets(String studyStr, String token) throws CatalogException { - Study study = get(studyStr, new QueryOptions(), token).first(); - createDefaultVariableSets(study, token); + public void createDefaultVariableSets(String organizationId, String studyStr, String token) throws CatalogException { + Study study = get(organizationId, studyStr, new QueryOptions(), token).first(); + createDefaultVariableSets(organizationId, study, token); } - private void createDefaultVariableSets(Study study, String token) throws CatalogException { + private void createDefaultVariableSets(String organizationId, Study study, String token) throws CatalogException { Set variablesets = new Reflections(new ResourcesScanner(), "variablesets/").getResources(Pattern.compile(".*\\.json")); for (String variableSetFile : variablesets) { VariableSet vs; @@ -420,14 +424,14 @@ private void createDefaultVariableSets(Study study, String token) throws Catalog if (study.getVariableSets().stream().anyMatch(tvs -> tvs.getId().equals(vs.getId()))) { logger.debug("Skip already existing variable set " + vs.getId()); } else { - createVariableSet(study, vs, token); + createVariableSet(organizationId, study, vs, token); } } } } - public int getCurrentRelease(Study study, String sessionId) throws CatalogException { - String userId = catalogManager.getUserManager().getUserId(sessionId); + public int getCurrentRelease(Study study, String token) throws CatalogException { + String userId = catalogManager.getUserManager().getUserId(token); authorizationManager.checkCanViewStudy(study.getUid(), userId); return getCurrentRelease(study); } @@ -435,10 +439,11 @@ public int getCurrentRelease(Study study, String sessionId) throws CatalogExcept int getCurrentRelease(Study study) throws CatalogException { String[] split = StringUtils.split(study.getFqn(), ":"); String userId = StringUtils.split(split[0], "@")[0]; - return catalogManager.getProjectManager().resolveId(split[0], userId).getCurrentRelease(); + return catalogManager.getProjectManager().resolveId(organizationId, split[0], userId).getCurrentRelease(); } - MyResourceId getVariableSetId(String variableStr, @Nullable String studyStr, String sessionId) throws CatalogException { + MyResourceId getVariableSetId(String organizationId, String variableStr, @Nullable String studyStr, String sessionId) + throws CatalogException { if (StringUtils.isEmpty(variableStr)) { throw new CatalogException("Missing variableSet parameter"); } @@ -452,14 +457,14 @@ MyResourceId getVariableSetId(String variableStr, @Nullable String studyStr, Str } userId = catalogManager.getUserManager().getUserId(sessionId); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId); studyId = study.getUid(); Query query = new Query() .append(StudyDBAdaptor.VariableSetParams.STUDY_UID.key(), study.getUid()) .append(StudyDBAdaptor.VariableSetParams.ID.key(), variableStr); QueryOptions queryOptions = new QueryOptions(); - OpenCGAResult variableSetDataResult = studyDBAdaptor.getVariableSets(query, queryOptions); + OpenCGAResult variableSetDataResult = getStudyDBAdaptor(organizationId).getVariableSets(query, queryOptions); if (variableSetDataResult.getNumResults() == 0) { throw new CatalogException("Variable set " + variableStr + " not found in study " + studyStr); } else if (variableSetDataResult.getNumResults() > 1) { @@ -473,23 +478,25 @@ MyResourceId getVariableSetId(String variableStr, @Nullable String studyStr, Str /** * Fetch a study from Catalog given a study id or alias. * - * @param studyStr Study id or alias. - * @param options Read options - * @param token sessionId + * @param organizationId + * @param studyStr Study id or alias. + * @param options Read options + * @param token sessionId * @return The specified object * @throws CatalogException CatalogException */ - public OpenCGAResult get(String studyStr, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult get(String organizationId, String studyStr, QueryOptions options, String token) throws CatalogException { options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = catalogManager.getUserManager().getUserId(token); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyStr", studyStr) .append("options", options) .append("token", token); try { StopWatch stopWatch = StopWatch.createStarted(); - Study study = catalogManager.getStudyManager().resolveId(studyStr, userId, options); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyStr, userId, options); auditManager.auditInfo(userId, Enums.Resource.STUDY, study.getId(), study.getUuid(), study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); OpenCGAResult studyDataResult = new OpenCGAResult<>((int) stopWatch.getTime(TimeUnit.MILLISECONDS), null, 1, @@ -502,12 +509,12 @@ public OpenCGAResult get(String studyStr, QueryOptions options, String to } } - public OpenCGAResult get(List studyList, QueryOptions queryOptions, boolean ignoreException, String sessionId) - throws CatalogException { + public OpenCGAResult get(String organizationId, List studyList, QueryOptions queryOptions, boolean ignoreException, + String token) throws CatalogException { OpenCGAResult result = OpenCGAResult.empty(Study.class); for (String study : studyList) { try { - OpenCGAResult studyObj = get(study, queryOptions, sessionId); + OpenCGAResult studyObj = get(organizationId, study, queryOptions, token); result.append(studyObj); } catch (CatalogException e) { String warning = "Missing " + study + ": " + e.getMessage(); @@ -527,14 +534,16 @@ public OpenCGAResult get(List studyList, QueryOptions queryOption /** * Fetch all the study objects matching the query. * - * @param projectStr Project id or alias. - * @param query Query to catalog. - * @param options Query options, like "include", "exclude", "limit" and "skip" - * @param sessionId sessionId + * @param organizationId + * @param projectStr Project id or alias. + * @param query Query to catalog. + * @param options Query options, like "include", "exclude", "limit" and "skip" + * @param token sessionId * @return All matching elements. * @throws CatalogException CatalogException */ - public OpenCGAResult search(String projectStr, Query query, QueryOptions options, String sessionId) throws CatalogException { + public OpenCGAResult search(String organizationId, String projectStr, Query query, QueryOptions options, String token) + throws CatalogException { ParamUtils.checkParameter(projectStr, "project"); ParamUtils.defaultObject(query, Query::new); ParamUtils.defaultObject(options, QueryOptions::new); @@ -556,25 +565,27 @@ public OpenCGAResult search(String projectStr, Query query, QueryOptions query.putIfNotNull(StudyDBAdaptor.QueryParams.PROJECT_ID.key(), auxProject); query.putIfNotNull(StudyDBAdaptor.QueryParams.OWNER.key(), auxOwner); - return search(query, options, sessionId); + return search(organizationId, query, options, token); } /** * Fetch all the study objects matching the query. * - * @param query Query to catalog. - * @param options Query options, like "include", "exclude", "limit" and "skip" - * @param token sessionId + * @param organizationId + * @param query Query to catalog. + * @param options Query options, like "include", "exclude", "limit" and "skip" + * @param token sessionId * @return All matching elements. * @throws CatalogException CatalogException */ - public OpenCGAResult search(Query query, QueryOptions options, String token) throws CatalogException { + public OpenCGAResult search(String organizationId, Query query, QueryOptions options, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); QueryOptions qOptions = options != null ? new QueryOptions(options) : new QueryOptions(); String userId = catalogManager.getUserManager().getUserId(token); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("query", query) .append("options", options) .append("token", token); @@ -585,7 +596,7 @@ public OpenCGAResult search(Query query, QueryOptions options, String tok try { fixQueryObject(query); - OpenCGAResult studyDataResult = studyDBAdaptor.get(query, qOptions, userId); + OpenCGAResult studyDataResult = getStudyDBAdaptor(organizationId).get(query, qOptions, userId); auditManager.auditSearch(userId, Enums.Resource.STUDY, "", "", auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); return filterResults(studyDataResult); @@ -612,25 +623,27 @@ private OpenCGAResult filterResults(OpenCGAResult result) { /** * Update an existing catalog study. * - * @param studyId Study id or alias. - * @param parameters Parameters to change. - * @param options options - * @param token sessionId + * @param organizationId + * @param studyId Study id or alias. + * @param parameters Parameters to change. + * @param options options + * @param token sessionId * @return The modified entry. * @throws CatalogException CatalogException */ - public OpenCGAResult update(String studyId, StudyUpdateParams parameters, QueryOptions options, String token) - throws CatalogException { + public OpenCGAResult update(String organizationId, String studyId, StudyUpdateParams parameters, QueryOptions options, + String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyId) .append("updateParams", parameters) .append("options", options) .append("token", token); Study study; try { - study = resolveId(studyId, userId); + study = resolveId(organizationId, studyId, userId); } catch (CatalogException e) { auditManager.auditUpdate(userId, Enums.Resource.STUDY, studyId, "", "", "", auditParams, new AuditRecord.Status(AuditRecord.Status.Result.ERROR, e.getError())); @@ -661,13 +674,13 @@ public OpenCGAResult update(String studyId, StudyUpdateParams parameters, throw new CatalogException("Jackson casting error: " + e.getMessage(), e); } - OpenCGAResult updateResult = studyDBAdaptor.update(study.getUid(), update, options); + OpenCGAResult updateResult = getStudyDBAdaptor(organizationId).update(study.getUid(), update, options); auditManager.auditUpdate(userId, Enums.Resource.STUDY, study.getId(), study.getUuid(), study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); if (options.getBoolean(ParamConstants.INCLUDE_RESULT_PARAM)) { // Fetch updated study - OpenCGAResult result = studyDBAdaptor.get(study.getUid(), options); + OpenCGAResult result = getStudyDBAdaptor(organizationId).get(study.getUid(), options); updateResult.setResults(result.getResults()); } @@ -679,12 +692,13 @@ public OpenCGAResult update(String studyId, StudyUpdateParams parameters, } } - public OpenCGAResult createPermissionRule(String studyId, Enums.Entity entry, PermissionRule permissionRule, - String token) throws CatalogException { + public OpenCGAResult createPermissionRule(String organizationId, String studyId, Enums.Entity entry, + PermissionRule permissionRule, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyId, userId, INCLUDE_STUDY_IDS); + Study study = resolveId(organizationId, studyId, userId, INCLUDE_STUDY_IDS); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyId) .append("entry", entry) .append("permissionRule", permissionRule) @@ -694,9 +708,9 @@ public OpenCGAResult createPermissionRule(String studyId, Enums. ParamUtils.checkObj(permissionRule, "permission rule"); authorizationManager.checkCanUpdatePermissionRules(study.getUid(), userId); - validatePermissionRules(study.getUid(), entry, permissionRule); + validatePermissionRules(organizationId, study.getUid(), entry, permissionRule); - OpenCGAResult result = studyDBAdaptor.createPermissionRule(study.getUid(), entry, permissionRule); + OpenCGAResult result = getStudyDBAdaptor(organizationId).createPermissionRule(study.getUid(), entry, permissionRule); auditManager.audit(userId, Enums.Action.ADD_STUDY_PERMISSION_RULE, Enums.Resource.STUDY, study.getId(), study.getUuid(), study.getId(), study.getUuid(), auditParams, @@ -712,12 +726,13 @@ public OpenCGAResult createPermissionRule(String studyId, Enums. } } - public void markDeletedPermissionRule(String studyId, Enums.Entity entry, String permissionRuleId, + public void markDeletedPermissionRule(String organizationId, String studyId, Enums.Entity entry, String permissionRuleId, PermissionRule.DeleteAction deleteAction, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyId, userId); + Study study = resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyId) .append("entry", entry) .append("permissionRuleId", permissionRuleId) @@ -729,7 +744,7 @@ public void markDeletedPermissionRule(String studyId, Enums.Entity entry, String ParamUtils.checkObj(permissionRuleId, "permission rule id"); authorizationManager.checkCanUpdatePermissionRules(study.getUid(), userId); - studyDBAdaptor.markDeletedPermissionRule(study.getUid(), entry, permissionRuleId, deleteAction); + getStudyDBAdaptor(organizationId).markDeletedPermissionRule(study.getUid(), entry, permissionRuleId, deleteAction); auditManager.audit(userId, Enums.Action.REMOVE_STUDY_PERMISSION_RULE, Enums.Resource.STUDY, study.getId(), study.getUuid(), study.getId(), study.getUuid(), auditParams, @@ -742,17 +757,19 @@ public void markDeletedPermissionRule(String studyId, Enums.Entity entry, String } } - public OpenCGAResult getPermissionRules(String studyId, Enums.Entity entry, String token) throws CatalogException { + public OpenCGAResult getPermissionRules(String organizationId, String studyId, Enums.Entity entry, String token) + throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyId, userId); + Study study = resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyId) .append("entry", entry) .append("token", token); try { authorizationManager.checkCanViewStudy(study.getUid(), userId); - OpenCGAResult result = studyDBAdaptor.getPermissionRules(study.getUid(), entry); + OpenCGAResult result = getStudyDBAdaptor(organizationId).getPermissionRules(study.getUid(), entry); auditManager.audit(userId, Enums.Action.FETCH_STUDY_PERMISSION_RULES, Enums.Resource.STUDY, study.getId(), study.getUuid(), study.getId(), study.getUuid(), auditParams, @@ -766,13 +783,13 @@ public OpenCGAResult getPermissionRules(String studyId, Enums.En } } - public OpenCGAResult rank(long projectId, Query query, String field, int numResults, boolean asc, String sessionId) + public OpenCGAResult rank(String organizationId, long projectId, Query query, String field, int numResults, boolean asc, String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); ParamUtils.checkObj(field, "field"); ParamUtils.checkObj(projectId, "projectId"); - String userId = catalogManager.getUserManager().getUserId(sessionId); + String userId = catalogManager.getUserManager().getUserId(token); authorizationManager.checkCanViewProject(projectId, userId); // TODO: In next release, we will have to check the count parameter from the queryOptions object. @@ -781,25 +798,25 @@ public OpenCGAResult rank(long projectId, Query query, String field, int numResu OpenCGAResult queryResult = null; if (count) { // We do not need to check for permissions when we show the count of files - queryResult = studyDBAdaptor.rank(query, field, numResults, asc); + queryResult = getStudyDBAdaptor(organizationId).rank(query, field, numResults, asc); } return ParamUtils.defaultObject(queryResult, OpenCGAResult::new); } - public OpenCGAResult groupBy(long projectId, Query query, String field, QueryOptions options, String sessionId) + public OpenCGAResult groupBy(String organizationId, long projectId, Query query, String field, QueryOptions options, String token) throws CatalogException { - return groupBy(projectId, query, Collections.singletonList(field), options, sessionId); + return groupBy(organizationId, projectId, query, Collections.singletonList(field), options, token); } - public OpenCGAResult groupBy(long projectId, Query query, List fields, QueryOptions options, String sessionId) - throws CatalogException { + public OpenCGAResult groupBy(String organizationId, long projectId, Query query, List fields, QueryOptions options, + String token) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); ParamUtils.checkObj(fields, "fields"); ParamUtils.checkObj(projectId, "projectId"); - String userId = catalogManager.getUserManager().getUserId(sessionId); + String userId = catalogManager.getUserManager().getUserId(token); authorizationManager.checkCanViewProject(projectId, userId); // TODO: In next release, we will have to check the count parameter from the queryOptions object. @@ -807,16 +824,17 @@ public OpenCGAResult groupBy(long projectId, Query query, List fields, Q OpenCGAResult queryResult = null; if (count) { // We do not need to check for permissions when we show the count of files - queryResult = studyDBAdaptor.groupBy(query, fields, options); + queryResult = getStudyDBAdaptor(organizationId).groupBy(query, fields, options); } return ParamUtils.defaultObject(queryResult, OpenCGAResult::new); } - public OpenCGAResult getSummary(String studyStr, QueryOptions queryOptions, String sessionId) throws CatalogException { + public OpenCGAResult getSummary(String organizationId, String studyStr, QueryOptions queryOptions, String token) + throws CatalogException { long startTime = System.currentTimeMillis(); - Study study = get(studyStr, queryOptions, sessionId).first(); + Study study = get(organizationId, studyStr, queryOptions, token).first(); StudySummary studySummary = new StudySummary() .setAlias(study.getId()) @@ -829,7 +847,7 @@ public OpenCGAResult getSummary(String studyStr, QueryOptions quer .setInternal(study.getInternal()) .setVariableSets(study.getVariableSets()); - Long nFiles = fileDBAdaptor.count( + Long nFiles = getFileDBAdaptor(organizationId).count( new Query(FileDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()) .append(FileDBAdaptor.QueryParams.TYPE.key(), File.Type.FILE) .append(FileDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), "!=" + FileStatus.TRASHED + ";!=" @@ -837,16 +855,16 @@ public OpenCGAResult getSummary(String studyStr, QueryOptions quer .getNumMatches(); studySummary.setFiles(nFiles); - Long nSamples = sampleDBAdaptor.count(new Query(SampleDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid())).getNumMatches(); + Long nSamples = getSampleDBAdaptor(organizationId).count(new Query(SampleDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid())).getNumMatches(); studySummary.setSamples(nSamples); - Long nJobs = jobDBAdaptor.count(new Query(JobDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid())).getNumMatches(); + Long nJobs = getJobDBAdaptor(organizationId).count(new Query(JobDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid())).getNumMatches(); studySummary.setJobs(nJobs); - Long nCohorts = cohortDBAdaptor.count(new Query(CohortDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid())).getNumMatches(); + Long nCohorts = getCohortDBAdaptor(organizationId).count(new Query(CohortDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid())).getNumMatches(); studySummary.setCohorts(nCohorts); - Long nIndividuals = individualDBAdaptor.count(new Query(IndividualDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid())) + Long nIndividuals = getIndividualDBAdaptor(organizationId).count(new Query(IndividualDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid())) .getNumMatches(); studySummary.setIndividuals(nIndividuals); @@ -854,12 +872,12 @@ public OpenCGAResult getSummary(String studyStr, QueryOptions quer Collections.singletonList(studySummary), 1); } - public List> getSummary(List studyList, QueryOptions queryOptions, boolean ignoreException, - String token) throws CatalogException { + public List> getSummary(String organizationId, List studyList, QueryOptions queryOptions, + boolean ignoreException, String token) throws CatalogException { List> results = new ArrayList<>(studyList.size()); for (String study : studyList) { try { - OpenCGAResult summaryObj = getSummary(study, queryOptions, token); + OpenCGAResult summaryObj = getSummary(organizationId, study, queryOptions, token); results.add(summaryObj); } catch (CatalogException e) { if (ignoreException) { @@ -873,17 +891,18 @@ public List> getSummary(List studyList, Quer return results; } - public OpenCGAResult createGroup(String studyStr, String groupId, List users, String sessionId) + public OpenCGAResult createGroup(String organizationId, String studyStr, String groupId, List users, String token) throws CatalogException { ParamUtils.checkParameter(groupId, "group id"); - return createGroup(studyStr, new Group(groupId, users, null), sessionId); + return createGroup(organizationId, studyStr, new Group(groupId, users, null), token); } - public OpenCGAResult createGroup(String studyId, Group group, String token) throws CatalogException { + public OpenCGAResult createGroup(String organizationId, String studyId, Group group, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyId, userId); + Study study = resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyId) .append("group", group) .append("token", token); @@ -905,7 +924,7 @@ public OpenCGAResult createGroup(String studyId, Group group, String toke authorizationManager.checkCreateDeleteGroupPermissions(study.getUid(), userId, group.getId()); // Check group exists - if (existsGroup(study.getUid(), group.getId())) { + if (existsGroup(organizationId, study.getUid(), group.getId())) { throw new CatalogException("The group " + group.getId() + " already exists."); } @@ -913,7 +932,7 @@ public OpenCGAResult createGroup(String studyId, Group group, String toke if (CollectionUtils.isNotEmpty(users)) { // We remove possible duplicates users = users.stream().collect(Collectors.toSet()).stream().collect(Collectors.toList()); - userDBAdaptor.checkIds(users); + getUserDBAdaptor(organizationId).checkIds(users); } else { users = Collections.emptyList(); } @@ -921,13 +940,13 @@ public OpenCGAResult createGroup(String studyId, Group group, String toke // Add those users to the members group if (CollectionUtils.isNotEmpty(users)) { - studyDBAdaptor.addUsersToGroup(study.getUid(), MEMBERS, users); + getStudyDBAdaptor(organizationId).addUsersToGroup(study.getUid(), MEMBERS, users); } // Create the group - OpenCGAResult result = studyDBAdaptor.createGroup(study.getUid(), group); + OpenCGAResult result = getStudyDBAdaptor(organizationId).createGroup(study.getUid(), group); - OpenCGAResult queryResult = studyDBAdaptor.getGroup(study.getUid(), group.getId(), null); + OpenCGAResult queryResult = getStudyDBAdaptor(organizationId).getGroup(study.getUid(), group.getId(), null); queryResult.setTime(queryResult.getTime() + result.getTime()); auditManager.audit(userId, Enums.Action.ADD_STUDY_GROUP, Enums.Resource.STUDY, study.getId(), study.getUuid(), @@ -941,11 +960,12 @@ public OpenCGAResult createGroup(String studyId, Group group, String toke } } - public OpenCGAResult getGroup(String studyId, String groupId, String token) throws CatalogException { + public OpenCGAResult getGroup(String organizationId, String studyId, String groupId, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyId, userId); + Study study = resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyId) .append("groupId", groupId) .append("token", token); @@ -957,7 +977,7 @@ public OpenCGAResult getGroup(String studyId, String groupId, String toke groupId = "@" + groupId; } - OpenCGAResult result = studyDBAdaptor.getGroup(study.getUid(), groupId, Collections.emptyList()); + OpenCGAResult result = getStudyDBAdaptor(organizationId).getGroup(study.getUid(), groupId, Collections.emptyList()); auditManager.audit(userId, Enums.Action.FETCH_STUDY_GROUPS, Enums.Resource.STUDY, study.getId(), study.getUuid(), study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); return result; @@ -968,11 +988,13 @@ public OpenCGAResult getGroup(String studyId, String groupId, String toke } } - public OpenCGAResult getCustomGroups(String studyId, String groupId, String token) throws CatalogException { + public OpenCGAResult getCustomGroups(String organizationId, String studyId, String groupId, String token) + throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyId, userId); + Study study = resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyId) .append("groupId", groupId) .append("token", token); @@ -987,7 +1009,7 @@ public OpenCGAResult getCustomGroups(String studyId, String groupId groupId = "@" + groupId; } - OpenCGAResult result = studyDBAdaptor.getGroup(study.getUid(), groupId, Collections.emptyList()); + OpenCGAResult result = getStudyDBAdaptor(organizationId).getGroup(study.getUid(), groupId, Collections.emptyList()); // Extract all users from all groups Set userIds = new HashSet<>(); @@ -999,7 +1021,7 @@ public OpenCGAResult getCustomGroups(String studyId, String groupId QueryOptions userOptions = new QueryOptions(QueryOptions.EXCLUDE, Arrays.asList( UserDBAdaptor.QueryParams.PROJECTS.key(), UserDBAdaptor.QueryParams.SHARED_PROJECTS.key() )); - OpenCGAResult userResult = userDBAdaptor.get(userQuery, userOptions); + OpenCGAResult userResult = getUserDBAdaptor(organizationId).get(userQuery, userOptions); Map userMap = new HashMap<>(); for (User user : userResult.getResults()) { userMap.put(user.getId(), user); @@ -1035,12 +1057,13 @@ public OpenCGAResult getCustomGroups(String studyId, String groupId } } - public OpenCGAResult updateGroup(String studyId, String groupId, ParamUtils.BasicUpdateAction action, + public OpenCGAResult updateGroup(String organizationId, String studyId, String groupId, ParamUtils.BasicUpdateAction action, GroupUpdateParams updateParams, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyId, userId); + Study study = resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyId) .append("groupId", groupId) .append("action", action) @@ -1069,7 +1092,7 @@ public OpenCGAResult updateGroup(String studyId, String groupId, ParamUti .collect(Collectors.toList()); } if (tmpUsers.size() > 0) { - userDBAdaptor.checkIds(tmpUsers); + getUserDBAdaptor(organizationId).checkIds(tmpUsers); } } else { updateParams.setUsers(Collections.emptyList()); @@ -1080,28 +1103,28 @@ public OpenCGAResult updateGroup(String studyId, String groupId, ParamUti if (MEMBERS.equals(groupId)) { throw new CatalogException("Operation not valid. Valid actions over the '@members' group are ADD or REMOVE."); } - studyDBAdaptor.setUsersToGroup(study.getUid(), groupId, updateParams.getUsers()); - studyDBAdaptor.addUsersToGroup(study.getUid(), MEMBERS, updateParams.getUsers()); + getStudyDBAdaptor(organizationId).setUsersToGroup(study.getUid(), groupId, updateParams.getUsers()); + getStudyDBAdaptor(organizationId).addUsersToGroup(study.getUid(), MEMBERS, updateParams.getUsers()); break; case ADD: - studyDBAdaptor.addUsersToGroup(study.getUid(), groupId, updateParams.getUsers()); + getStudyDBAdaptor(organizationId).addUsersToGroup(study.getUid(), groupId, updateParams.getUsers()); if (!MEMBERS.equals(groupId)) { - studyDBAdaptor.addUsersToGroup(study.getUid(), MEMBERS, updateParams.getUsers()); + getStudyDBAdaptor(organizationId).addUsersToGroup(study.getUid(), MEMBERS, updateParams.getUsers()); } break; case REMOVE: if (MEMBERS.equals(groupId)) { // Check we are not trying to remove the owner of the study from the group - String owner = getOwner(study); + String owner = getOwner(organizationId, study); if (updateParams.getUsers().contains(owner)) { throw new CatalogException("Cannot remove owner of the study from the '@members' group"); } // We remove the users from all the groups and acls authorizationManager.resetPermissionsFromAllEntities(study.getUid(), updateParams.getUsers()); - studyDBAdaptor.removeUsersFromAllGroups(study.getUid(), updateParams.getUsers()); + getStudyDBAdaptor(organizationId).removeUsersFromAllGroups(study.getUid(), updateParams.getUsers()); } else { - studyDBAdaptor.removeUsersFromGroup(study.getUid(), groupId, updateParams.getUsers()); + getStudyDBAdaptor(organizationId).removeUsersFromGroup(study.getUid(), groupId, updateParams.getUsers()); } break; default: @@ -1112,7 +1135,7 @@ public OpenCGAResult updateGroup(String studyId, String groupId, ParamUti study.getUuid(), study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); - return studyDBAdaptor.getGroup(study.getUid(), groupId, Collections.emptyList()); + return getStudyDBAdaptor(organizationId).getGroup(study.getUid(), groupId, Collections.emptyList()); } catch (CatalogException e) { auditManager.audit(userId, Enums.Action.UPDATE_USERS_FROM_STUDY_GROUP, Enums.Resource.STUDY, study.getId(), study.getUuid(), study.getId(), study.getUuid(), auditParams, @@ -1121,12 +1144,13 @@ public OpenCGAResult updateGroup(String studyId, String groupId, ParamUti } } - public OpenCGAResult updateSummaryIndex(String studyStr, RecessiveGeneSummaryIndex summaryIndex, + public OpenCGAResult updateSummaryIndex(String organizationId, String studyStr, RecessiveGeneSummaryIndex summaryIndex, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyStr, userId); + Study study = resolveId(organizationId, studyStr, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyStr) .append("recessiveGeneSummaryIndex", summaryIndex) .append("token", token); @@ -1144,7 +1168,7 @@ public OpenCGAResult updateSummaryIndex(String studyStr, RecessiveGeneSummary throw new CatalogException("Jackson casting error: " + e.getMessage(), e); } - OpenCGAResult result = studyDBAdaptor.update(study.getUid(), update, QueryOptions.empty()); + OpenCGAResult result = getStudyDBAdaptor(organizationId).update(study.getUid(), update, QueryOptions.empty()); auditManager.audit(userId, Enums.Action.UPDATE_INTERNAL, Enums.Resource.STUDY, study.getId(), study.getUuid(), study.getId(), study.getUuid(), auditParams, @@ -1197,11 +1221,12 @@ public OpenCGAResult updateSummaryIndex(String studyStr, RecessiveGeneSummary // return studyDBAdaptor.getGroup(study.getUid(), groupId, Collections.emptyList()); // } - public OpenCGAResult deleteGroup(String studyId, String groupId, String token) throws CatalogException { + public OpenCGAResult deleteGroup(String organizationId, String studyId, String groupId, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyId, userId); + Study study = resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyId", studyId) .append("groupId", groupId) .append("token", token); @@ -1217,13 +1242,13 @@ public OpenCGAResult deleteGroup(String studyId, String groupId, String t authorizationManager.checkCreateDeleteGroupPermissions(study.getUid(), userId, groupId); - OpenCGAResult group = studyDBAdaptor.getGroup(study.getUid(), groupId, Collections.emptyList()); + OpenCGAResult group = getStudyDBAdaptor(organizationId).getGroup(study.getUid(), groupId, Collections.emptyList()); // Remove the permissions the group might have had StudyAclParams aclParams = new StudyAclParams(null, null); - updateAcl(Collections.singletonList(studyId), groupId, aclParams, ParamUtils.AclAction.RESET, token); + updateAcl(organizationId, Collections.singletonList(studyId), groupId, aclParams, ParamUtils.AclAction.RESET, token); - studyDBAdaptor.deleteGroup(study.getUid(), groupId); + getStudyDBAdaptor(organizationId).deleteGroup(study.getUid(), groupId); auditManager.audit(userId, Enums.Action.REMOVE_STUDY_GROUP, Enums.Resource.STUDY, study.getId(), study.getUuid(), study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); @@ -1236,13 +1261,14 @@ public OpenCGAResult deleteGroup(String studyId, String groupId, String t } } - public OpenCGAResult getVariableSetSummary(String studyStr, String variableSetStr, String sessionId) - throws CatalogException { - MyResourceId resource = getVariableSetId(variableSetStr, studyStr, sessionId); + public OpenCGAResult getVariableSetSummary(String organizationId, String studyStr, String variableSetStr, + String token) throws CatalogException { + MyResourceId resource = getVariableSetId(organizationId, variableSetStr, studyStr, token); String userId = resource.getUser(); - OpenCGAResult variableSet = studyDBAdaptor.getVariableSet(resource.getResourceId(), new QueryOptions(), userId); + OpenCGAResult variableSet = getStudyDBAdaptor(organizationId).getVariableSet(resource.getResourceId(), + new QueryOptions(), userId); if (variableSet.getNumResults() == 0) { logger.error("getVariableSetSummary: Could not find variable set id {}. {} results returned", variableSetStr, variableSet.getNumResults()); @@ -1253,20 +1279,20 @@ public OpenCGAResult getVariableSetSummary(String studyStr, VariableSetSummary variableSetSummary = new VariableSetSummary(resource.getResourceId(), variableSet.first().getId()); - OpenCGAResult annotationSummary = sampleDBAdaptor.getAnnotationSummary(resource.getStudyId(), + OpenCGAResult annotationSummary = getSampleDBAdaptor(organizationId).getAnnotationSummary(resource.getStudyId(), resource.getResourceId()); dbTime += annotationSummary.getTime(); variableSetSummary.setSamples(annotationSummary.getResults()); - annotationSummary = cohortDBAdaptor.getAnnotationSummary(resource.getStudyId(), resource.getResourceId()); + annotationSummary = getCohortDBAdaptor(organizationId).getAnnotationSummary(resource.getStudyId(), resource.getResourceId()); dbTime += annotationSummary.getTime(); variableSetSummary.setCohorts(annotationSummary.getResults()); - annotationSummary = individualDBAdaptor.getAnnotationSummary(resource.getStudyId(), resource.getResourceId()); + annotationSummary = getIndividualDBAdaptor(organizationId).getAnnotationSummary(resource.getStudyId(), resource.getResourceId()); dbTime += annotationSummary.getTime(); variableSetSummary.setIndividuals(annotationSummary.getResults()); - annotationSummary = familyDBAdaptor.getAnnotationSummary(resource.getStudyId(), resource.getResourceId()); + annotationSummary = getFamilyDBAdaptor(organizationId).getAnnotationSummary(resource.getStudyId(), resource.getResourceId()); dbTime += annotationSummary.getTime(); variableSetSummary.setFamilies(annotationSummary.getResults()); @@ -1277,7 +1303,7 @@ public OpenCGAResult getVariableSetSummary(String studyStr, /* * Variables Methods */ - private OpenCGAResult createVariableSet(Study study, VariableSet variableSet, String token) + private OpenCGAResult createVariableSet(String organizationId, Study study, VariableSet variableSet, String token) throws CatalogException { ParamUtils.checkParameter(variableSet.getId(), "id"); ParamUtils.checkObj(variableSet.getVariables(), "Variables from VariableSet"); @@ -1304,31 +1330,34 @@ private OpenCGAResult createVariableSet(Study study, VariableSet va variableSet.setRelease(getCurrentRelease(study)); AnnotationUtils.checkVariableSet(variableSet); - OpenCGAResult result = studyDBAdaptor.createVariableSet(study.getUid(), variableSet); - OpenCGAResult queryResult = studyDBAdaptor.getVariableSet(study.getUid(), variableSet.getId(), QueryOptions.empty()); + OpenCGAResult result = getStudyDBAdaptor(organizationId).createVariableSet(study.getUid(), variableSet); + OpenCGAResult queryResult = getStudyDBAdaptor(organizationId).getVariableSet(study.getUid(), variableSet.getId(), + QueryOptions.empty()); return OpenCGAResult.merge(Arrays.asList(result, queryResult)); } @Deprecated - public OpenCGAResult createVariableSet(String studyId, String id, String name, Boolean unique, Boolean confidential, - String description, Map attributes, List variables, - List entities, String token) - throws CatalogException { - return createVariableSet(studyId, new VariableSet(id, name, unique != null ? unique : true, + public OpenCGAResult createVariableSet(String organizationId, String studyId, String id, String name, Boolean unique, + Boolean confidential, String description, Map attributes, + List variables, List entities, + String token) throws CatalogException { + return createVariableSet(organizationId, studyId, new VariableSet(id, name, unique != null ? unique : true, confidential != null ? confidential : false, false, description, new HashSet<>(variables), entities, 1, attributes), token); } - public OpenCGAResult createVariableSet(String studyId, VariableSet variableSet, String token) throws CatalogException { + public OpenCGAResult createVariableSet(String organizationId, String studyId, VariableSet variableSet, String token) + throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyId, userId); + Study study = resolveId(organizationId, studyId, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("study", studyId) .append("variableSet", variableSet) .append("token", token); try { - OpenCGAResult queryResult = createVariableSet(study, variableSet, token); + OpenCGAResult queryResult = createVariableSet(organizationId, study, variableSet, token); auditManager.audit(userId, Enums.Action.ADD_VARIABLE_SET, Enums.Resource.STUDY, queryResult.first().getId(), "", study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); return queryResult; @@ -1339,10 +1368,10 @@ public OpenCGAResult createVariableSet(String studyId, VariableSet } } - public OpenCGAResult getVariableSet(String studyId, String variableSetId, QueryOptions options, String token) - throws CatalogException { + public OpenCGAResult getVariableSet(String organizationId, String studyId, String variableSetId, QueryOptions options, + String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyId, userId, StudyManager.INCLUDE_VARIABLE_SET); + Study study = resolveId(organizationId, studyId, userId, StudyManager.INCLUDE_VARIABLE_SET); ObjectMap auditParams = new ObjectMap() .append("studyId", studyId) @@ -1351,8 +1380,8 @@ public OpenCGAResult getVariableSet(String studyId, String variable .append("token", token); try { options = ParamUtils.defaultObject(options, QueryOptions::new); - VariableSet variableSet = extractVariableSet(study, variableSetId, userId); - OpenCGAResult result = studyDBAdaptor.getVariableSet(variableSet.getUid(), options, userId); + VariableSet variableSet = extractVariableSet(organizationId, study, variableSetId, userId); + OpenCGAResult result = getStudyDBAdaptor(organizationId).getVariableSet(variableSet.getUid(), options, userId); auditManager.audit(userId, Enums.Action.FETCH_VARIABLE_SET, Enums.Resource.STUDY, variableSet.getId(), "", study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); @@ -1365,36 +1394,37 @@ public OpenCGAResult getVariableSet(String studyId, String variable } } - public OpenCGAResult searchVariableSets(String studyStr, Query query, QueryOptions options, String sessionId) - throws CatalogException { - String userId = catalogManager.getUserManager().getUserId(sessionId); - Study study = resolveId(studyStr, userId); + public OpenCGAResult searchVariableSets(String organizationId, String studyStr, Query query, QueryOptions options, + String token) throws CatalogException { + String userId = catalogManager.getUserManager().getUserId(token); + Study study = resolveId(organizationId, studyStr, userId); // authorizationManager.checkStudyPermission(studyId, userId, StudyAclEntry.StudyPermissions.VIEW_VARIABLE_SET); options = ParamUtils.defaultObject(options, QueryOptions::new); query = ParamUtils.defaultObject(query, Query::new); if (query.containsKey(StudyDBAdaptor.VariableSetParams.UID.key())) { // Id could be either the id or the name - MyResourceId resource = getVariableSetId(query.getString(StudyDBAdaptor.VariableSetParams.UID.key()), studyStr, sessionId); + MyResourceId resource = getVariableSetId(organizationId, query.getString(StudyDBAdaptor.VariableSetParams.UID.key()), studyStr, token); query.put(StudyDBAdaptor.VariableSetParams.UID.key(), resource.getResourceId()); } query.put(StudyDBAdaptor.VariableSetParams.STUDY_UID.key(), study.getUid()); - return studyDBAdaptor.getVariableSets(query, options, userId); + return getStudyDBAdaptor(organizationId).getVariableSets(query, options, userId); } - public OpenCGAResult deleteVariableSet(String studyId, String variableSetId, boolean force, String token) - throws CatalogException { + public OpenCGAResult deleteVariableSet(String organizationId, String studyId, String variableSetId, boolean force, + String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyId, userId, StudyManager.INCLUDE_VARIABLE_SET); - VariableSet variableSet = extractVariableSet(study, variableSetId, userId); + Study study = resolveId(organizationId, studyId, userId, StudyManager.INCLUDE_VARIABLE_SET); + VariableSet variableSet = extractVariableSet(organizationId, study, variableSetId, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("study", studyId) .append("variableSetId", variableSetId) .append("force", force) .append("token", token); try { authorizationManager.checkCanCreateUpdateDeleteVariableSets(study.getUid(), userId); - OpenCGAResult writeResult = studyDBAdaptor.deleteVariableSet(study.getUid(), variableSet, force); + OpenCGAResult writeResult = getStudyDBAdaptor(organizationId).deleteVariableSet(study.getUid(), variableSet, force); auditManager.audit(userId, Enums.Action.DELETE_VARIABLE_SET, Enums.Resource.STUDY, variableSet.getId(), "", study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); @@ -1406,13 +1436,14 @@ public OpenCGAResult deleteVariableSet(String studyId, String varia } } - public OpenCGAResult addFieldToVariableSet(String studyId, String variableSetId, Variable variable, String token) - throws CatalogException { + public OpenCGAResult addFieldToVariableSet(String organizationId, String studyId, String variableSetId, Variable variable, + String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyId, userId, StudyManager.INCLUDE_VARIABLE_SET); - VariableSet variableSet = extractVariableSet(study, variableSetId, userId); + Study study = resolveId(organizationId, studyId, userId, StudyManager.INCLUDE_VARIABLE_SET); + VariableSet variableSet = extractVariableSet(organizationId, study, variableSetId, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("study", studyId) .append("variableSetId", variableSetId) .append("variable", variable) @@ -1426,11 +1457,11 @@ public OpenCGAResult addFieldToVariableSet(String studyId, String v } authorizationManager.checkCanCreateUpdateDeleteVariableSets(study.getUid(), userId); - OpenCGAResult result = studyDBAdaptor.addFieldToVariableSet(variableSet.getUid(), variable, userId); + OpenCGAResult result = getStudyDBAdaptor(organizationId).addFieldToVariableSet(variableSet.getUid(), variable, userId); auditManager.audit(userId, Enums.Action.ADD_VARIABLE_TO_VARIABLE_SET, Enums.Resource.STUDY, variableSet.getId(), "", study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); - OpenCGAResult queryResult = studyDBAdaptor.getVariableSet(variableSet.getUid(), QueryOptions.empty()); + OpenCGAResult queryResult = getStudyDBAdaptor(organizationId).getVariableSet(variableSet.getUid(), QueryOptions.empty()); queryResult.setTime(queryResult.getTime() + result.getTime()); return queryResult; } catch (CatalogException e) { @@ -1440,13 +1471,14 @@ public OpenCGAResult addFieldToVariableSet(String studyId, String v } } - public OpenCGAResult removeFieldFromVariableSet(String studyId, String variableSetId, String variableId, String token) - throws CatalogException { + public OpenCGAResult removeFieldFromVariableSet(String organizationId, String studyId, String variableSetId, + String variableId, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyId, userId, StudyManager.INCLUDE_VARIABLE_SET); - VariableSet variableSet = extractVariableSet(study, variableSetId, userId); + Study study = resolveId(organizationId, studyId, userId, StudyManager.INCLUDE_VARIABLE_SET); + VariableSet variableSet = extractVariableSet(organizationId, study, variableSetId, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("study", studyId) .append("variableSetId", variableSetId) .append("variableId", variableId) @@ -1454,12 +1486,12 @@ public OpenCGAResult removeFieldFromVariableSet(String studyId, Str try { authorizationManager.checkCanCreateUpdateDeleteVariableSets(study.getUid(), userId); - OpenCGAResult result = studyDBAdaptor.removeFieldFromVariableSet(variableSet.getUid(), variableId, userId); + OpenCGAResult result = getStudyDBAdaptor(organizationId).removeFieldFromVariableSet(variableSet.getUid(), variableId, userId); auditManager.audit(userId, Enums.Action.REMOVE_VARIABLE_FROM_VARIABLE_SET, Enums.Resource.STUDY, variableSet.getId(), "", study.getId(), study.getUuid(), auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); - OpenCGAResult queryResult = studyDBAdaptor.getVariableSet(variableSet.getUid(), QueryOptions.empty()); + OpenCGAResult queryResult = getStudyDBAdaptor(organizationId).getVariableSet(variableSet.getUid(), QueryOptions.empty()); queryResult.setTime(queryResult.getTime() + result.getTime()); return queryResult; } catch (CatalogException e) { @@ -1470,7 +1502,7 @@ public OpenCGAResult removeFieldFromVariableSet(String studyId, Str } } - private VariableSet extractVariableSet(Study study, String variableSetId, String userId) throws CatalogException { + private VariableSet extractVariableSet(String organizationId, Study study, String variableSetId, String userId) throws CatalogException { if (study == null || study.getVariableSets() == null || study.getVariableSets().isEmpty()) { throw new CatalogException(variableSetId + " not found."); } @@ -1482,35 +1514,22 @@ private VariableSet extractVariableSet(Study study, String variableSetId, String .append(StudyDBAdaptor.VariableSetParams.ID.key(), variableSetId); // We query again because we only want to return the variable set if the user can access it - OpenCGAResult queryResult = studyDBAdaptor.getVariableSets(query, new QueryOptions(), userId); + OpenCGAResult queryResult = getStudyDBAdaptor(organizationId).getVariableSets(query, new QueryOptions(), userId); if (queryResult.getNumResults() == 0) { throw new CatalogException(variableSetId + " not found."); } return queryResult.first(); } - public OpenCGAResult renameFieldFromVariableSet(String studyStr, String variableSetStr, String oldName, String newName, - String sessionId) throws CatalogException { - throw new UnsupportedOperationException("Operation not yet supported"); - -// MyResourceId resource = getVariableSetId(variableSetStr, studyStr, sessionId); -// String userId = resource.getUser(); -// -// authorizationManager.checkCanCreateUpdateDeleteVariableSets(resource.getStudyId(), userId); -// OpenCGAResult queryResult = studyDBAdaptor.renameFieldVariableSet(resource.getResourceId(), oldName, newName,userId); -// auditManager.recordDeletion(AuditRecord.Resource.variableSet, resource.getResourceId(), userId, queryResult.first(), null, null); -// return queryResult; - } - - // ************************** ACLs ******************************** // - public OpenCGAResult> getAcls(List studyIdList, String member, + public OpenCGAResult> getAcls(String organizationId, List studyIdList, String member, boolean ignoreException, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - List studyList = resolveIds(studyIdList, userId); + List studyList = resolveIds(organizationId, studyIdList, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyIdList", studyIdList) .append("member", member) .append("ignoreException", ignoreException) @@ -1549,19 +1568,21 @@ public OpenCGAResult> getAcls(List> updateAcl(String studyId, String memberIds, StudyAclParams aclParams, - ParamUtils.AclAction action, String token) - throws CatalogException { - return updateAcl(Collections.singletonList(studyId), memberIds, aclParams, action, token); - } - - public OpenCGAResult> updateAcl(List studyIdList, String memberIds, + public OpenCGAResult> updateAcl(String organizationId, String studyId, String memberIds, StudyAclParams aclParams, ParamUtils.AclAction action, String token) throws CatalogException { + return updateAcl(organizationId, Collections.singletonList(studyId), memberIds, aclParams, action, token); + } + + public OpenCGAResult> updateAcl(String organizationId, List studyIdList, + String memberIds, StudyAclParams aclParams, + ParamUtils.AclAction action, String token) + throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - List studies = resolveIds(studyIdList, userId); + List studies = resolveIds(organizationId, studyIdList, userId); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyIdList", studyIdList) .append("memberIds", memberIds) .append("aclParams", aclParams) @@ -1630,7 +1651,7 @@ public OpenCGAResult> updateAcl(List< } authorizationManager.checkNotAssigningPermissionsToAdminsGroup(members); for (Study study : studies) { - checkMembers(study.getUid(), members); + checkMembers(organizationId, study.getUid(), members); } List studyUidList = studies @@ -1676,9 +1697,9 @@ public OpenCGAResult> updateAcl(List< } } - public Map facet(String studyStr, String fileFields, String sampleFields, String individualFields, String cohortFields, - String familyFields, String jobFields, boolean defaultStats, String sessionId) - throws CatalogException, IOException { + public Map facet(String organizationId, String studyStr, String fileFields, String sampleFields, + String individualFields, String cohortFields, String familyFields, String jobFields, + boolean defaultStats, String sessionId) throws CatalogException, IOException { Map result = new HashMap<>(); result.put("sample", catalogManager.getSampleManager().facet(studyStr, new Query(), setFacetFields(sampleFields), defaultStats, sessionId)); @@ -1704,9 +1725,10 @@ private QueryOptions setFacetFields(String fields) { // ************************** Protected internal methods ******************************** // - public void setVariantEngineConfigurationOptions(String studyStr, ObjectMap options, String token) throws CatalogException { + public void setVariantEngineConfigurationOptions(String organizationId, String studyStr, ObjectMap options, String token) + throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = get(studyStr, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( + Study study = get(organizationId, studyStr, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( StudyDBAdaptor.QueryParams.UID.key(), StudyDBAdaptor.QueryParams.INTERNAL_CONFIGURATION_VARIANT_ENGINE.key())), token).first(); @@ -1718,13 +1740,14 @@ public void setVariantEngineConfigurationOptions(String studyStr, ObjectMap opti configuration.setOptions(options); ObjectMap parameters = new ObjectMap(StudyDBAdaptor.QueryParams.INTERNAL_CONFIGURATION_VARIANT_ENGINE.key(), configuration); - studyDBAdaptor.update(study.getUid(), parameters, QueryOptions.empty()); + getStudyDBAdaptor(organizationId).update(study.getUid(), parameters, QueryOptions.empty()); } - public void setVariantEngineConfigurationSampleIndex(String studyStr, SampleIndexConfiguration sampleIndexConfiguration, String token) + public void setVariantEngineConfigurationSampleIndex(String organizationId, String studyStr, + SampleIndexConfiguration sampleIndexConfiguration, String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = get(studyStr, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( + Study study = get(organizationId, studyStr, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( StudyDBAdaptor.QueryParams.UID.key(), StudyDBAdaptor.QueryParams.INTERNAL_CONFIGURATION_VARIANT_ENGINE.key())), token).first(); @@ -1736,19 +1759,20 @@ public void setVariantEngineConfigurationSampleIndex(String studyStr, SampleInde configuration.setSampleIndex(sampleIndexConfiguration); ObjectMap parameters = new ObjectMap(StudyDBAdaptor.QueryParams.INTERNAL_CONFIGURATION_VARIANT_ENGINE.key(), configuration); - studyDBAdaptor.update(study.getUid(), parameters, QueryOptions.empty()); + getStudyDBAdaptor(organizationId).update(study.getUid(), parameters, QueryOptions.empty()); } // ************************** Private methods ******************************** // - private boolean existsGroup(long studyId, String groupId) throws CatalogDBException { + private boolean existsGroup(String organizationId, long studyId, String groupId) throws CatalogDBException { Query query = new Query() .append(StudyDBAdaptor.QueryParams.UID.key(), studyId) .append(StudyDBAdaptor.QueryParams.GROUP_ID.key(), groupId); - return studyDBAdaptor.count(query).getNumMatches() > 0; + return getStudyDBAdaptor(organizationId).count(query).getNumMatches() > 0; } - private void validatePermissionRules(long studyId, Enums.Entity entry, PermissionRule permissionRule) throws CatalogException { + private void validatePermissionRules(String organizationId, long studyId, Enums.Entity entry, PermissionRule permissionRule) + throws CatalogException { ParamUtils.checkIdentifier(permissionRule.getId(), "PermissionRules"); if (permissionRule.getPermissions() == null || permissionRule.getPermissions().isEmpty()) { @@ -1781,7 +1805,7 @@ private void validatePermissionRules(long studyId, Enums.Entity entry, Permissio throw new CatalogException("Unexpected entry found"); } - checkMembers(studyId, permissionRule.getMembers()); + checkMembers(organizationId, studyId, permissionRule.getMembers()); } private void validatePermissions(List permissions, Function valueOf) throws CatalogException { @@ -1795,11 +1819,11 @@ private void validatePermissions(List permissions, Function uploadTemplate(String studyStr, String filename, InputStream inputStream, String token) - throws CatalogException { + public OpenCGAResult uploadTemplate(String organizationId, String studyStr, String filename, InputStream inputStream, + String token) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyStr, userId, QueryOptions.empty()); + Study study = resolveId(organizationId, studyStr, userId, QueryOptions.empty()); String templateId = "template." + TimeUtils.getTime() + "." + RandomStringUtils.random(6, true, false); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyStr", studyStr) + .append("filename", filename) .append("token", token); try { StopWatch stopWatch = StopWatch.createStarted(); @@ -1914,17 +1941,20 @@ public OpenCGAResult uploadTemplate(String studyStr, String filename, In /** * Delete a template from Catalog. * - * @param studyStr study where the template belongs to. - * @param templateId Template id. - * @param token Token of the user performing the upload. + * @param organizationId + * @param studyStr study where the template belongs to. + * @param templateId Template id. + * @param token Token of the user performing the upload. * @return an empty OpenCGAResult if it successfully uploaded. * @throws CatalogException if there is any issue with the upload. */ - public OpenCGAResult deleteTemplate(String studyStr, String templateId, String token) throws CatalogException { + public OpenCGAResult deleteTemplate(String organizationId, String studyStr, String templateId, String token) + throws CatalogException { String userId = catalogManager.getUserManager().getUserId(token); - Study study = resolveId(studyStr, userId, QueryOptions.empty()); + Study study = resolveId(organizationId, studyStr, userId, QueryOptions.empty()); ObjectMap auditParams = new ObjectMap() + .append("organizationId", organizationId) .append("studyStr", studyStr) .append("templateId", templateId) .append("token", token); diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/UserManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/UserManager.java index db7a0cdfa17..84683c87509 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/UserManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/managers/UserManager.java @@ -346,7 +346,7 @@ public void syncAllUsersOfExternalGroup(String study, String authOrigin, String throw new CatalogAuthorizationException("Only the root user can perform this action"); } - OpenCGAResult allGroups = catalogManager.getStudyManager().getGroup(study, null, token); + OpenCGAResult allGroups = catalogManager.getStudyManager().getGroup(organizationId, study, null, token); boolean foundAny = false; for (Group group : allGroups.getResults()) { @@ -365,7 +365,7 @@ public void syncAllUsersOfExternalGroup(String study, String authOrigin, String group.getId(), group.getSyncedFrom().getAuthOrigin()); logger.info("Please, manually remove group '{}' if external group '{}' was removed from the authentication origin", group.getId(), group.getSyncedFrom().getAuthOrigin()); - catalogManager.getStudyManager().updateGroup(study, group.getId(), ParamUtils.BasicUpdateAction.SET, + catalogManager.getStudyManager().updateGroup(organizationId, study, group.getId(), ParamUtils.BasicUpdateAction.SET, new GroupUpdateParams(Collections.emptyList()), token); continue; } @@ -394,7 +394,7 @@ public void syncAllUsersOfExternalGroup(String study, String authOrigin, String logger.info("Associating members to the internal OpenCGA group"); updateParams = new GroupUpdateParams(new ArrayList<>(userList.stream().map(User::getId).collect(Collectors.toSet()))); } - catalogManager.getStudyManager().updateGroup(study, group.getId(), ParamUtils.BasicUpdateAction.SET, updateParams, token); + catalogManager.getStudyManager().updateGroup(organizationId, study, group.getId(), ParamUtils.BasicUpdateAction.SET, updateParams, token); } } if (!foundAny) { @@ -458,7 +458,7 @@ public void importRemoteGroupOfUsers(String authOrigin, String remoteGroup, @Nul if (StringUtils.isNotEmpty(internalGroup) && StringUtils.isNotEmpty(study)) { // Check if the group already exists - OpenCGAResult groupResult = catalogManager.getStudyManager().getGroup(study, internalGroup, token); + OpenCGAResult groupResult = catalogManager.getStudyManager().getGroup(organizationId, study, internalGroup, token); if (groupResult.getNumResults() == 1) { logger.error("Cannot synchronise with group {}. The group already exists and is already in use.", internalGroup); throw new CatalogException("Cannot synchronise with group " + internalGroup @@ -474,7 +474,7 @@ public void importRemoteGroupOfUsers(String authOrigin, String remoteGroup, @Nul } Group group = new Group(internalGroup, userList.stream().map(User::getId).collect(Collectors.toList())) .setSyncedFrom(groupSync); - catalogManager.getStudyManager().createGroup(study, group, token); + catalogManager.getStudyManager().createGroup(organizationId, study, group, token); logger.info("Group '{}' created and synchronised with external group", internalGroup); auditManager.audit(userId, Enums.Action.IMPORT_EXTERNAL_GROUP_OF_USERS, Enums.Resource.USER, group.getId(), "", study, "", auditParams, new AuditRecord.Status(AuditRecord.Status.Result.SUCCESS)); @@ -551,10 +551,10 @@ public void importRemoteEntities(String authOrigin, List idList, boolean if (StringUtils.isNotEmpty(internalGroup) && StringUtils.isNotEmpty(study)) { // Check if the group already exists try { - OpenCGAResult group = catalogManager.getStudyManager().getGroup(study, internalGroup, token); + OpenCGAResult group = catalogManager.getStudyManager().getGroup(organizationId, study, internalGroup, token); if (group.getNumResults() == 1) { // We will add those users to the existing group - catalogManager.getStudyManager().updateGroup(study, internalGroup, ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, study, internalGroup, ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(idList), token); return; } @@ -566,7 +566,7 @@ public void importRemoteEntities(String authOrigin, List idList, boolean try { logger.info("Attempting to register group '{}' in study '{}'", internalGroup, study); Group group = new Group(internalGroup, idList); - catalogManager.getStudyManager().createGroup(study, group, token); + catalogManager.getStudyManager().createGroup(organizationId, study, group, token); } catch (CatalogException e) { logger.error("Could not register group '{}' in study '{}'\n{}", internalGroup, study, e.getMessage()); } diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/migration/MigrationManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/migration/MigrationManager.java index 13f93e824b5..7a0c6d98d26 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/migration/MigrationManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/migration/MigrationManager.java @@ -364,7 +364,7 @@ private MigrationRun.MigrationStatus getOnHoldMigrationRunStatus(Migration migra boolean anyError = false; for (JobReferenceParam jobR : migrationRun.getJobs()) { Job job = catalogManager.getJobManager() - .get(jobR.getStudyId(), jobR.getId(), new QueryOptions(QueryOptions.INCLUDE, "id,internal"), token).first(); + .get(organizationId, jobR.getStudyId(), jobR.getId(), new QueryOptions(QueryOptions.INCLUDE, "id,internal"), token).first(); String jobStatus = job.getInternal().getStatus().getId(); if (jobStatus.equals(Enums.ExecutionStatus.ERROR) || jobStatus.equals(Enums.ExecutionStatus.ABORTED)) { @@ -711,7 +711,7 @@ private MigrationRun run(Class runnableMigration, Path .setEvents(migrationRun.getEvents())); break; } - catalogManager.getJobManager().create(adminStudy, job, new QueryOptions(), token); + catalogManager.getJobManager().create(organizationId, adminStudy, job, new QueryOptions(), token); } catch (CatalogException e) { exceptionToThrow = new MigrationException("Could not register migration in OpenCGA", e); } diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/templates/TemplateManager.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/templates/TemplateManager.java index bb59584363b..dca6f5e5de7 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/templates/TemplateManager.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/templates/TemplateManager.java @@ -171,7 +171,7 @@ private void checkVersion(String opencgaVersion, String templateVersion) { private Study getStudy(String projectId, String studyId) throws CatalogException { OpenCGAResult studyOpenCGAResult = - catalogManager.getStudyManager().get(projectId + ":" + studyId, QueryOptions.empty(), token); + catalogManager.getStudyManager().get(organizationId, projectId + ":" + studyId, QueryOptions.empty(), token); return studyOpenCGAResult.first(); } @@ -202,7 +202,7 @@ private String addStudyMetadata(String projectId, TemplateStudy tmplStudy) throw logger.info("Study '{}' already exists. Updating the values.", tmplStudy.getId()); try { - catalogManager.getStudyManager().update(fqn, studyUpdateParams, QueryOptions.empty(), token); + catalogManager.getStudyManager().update(organizationId, fqn, studyUpdateParams, QueryOptions.empty(), token); } catch (CatalogException e) { logger.warn(e.getMessage()); } @@ -220,14 +220,14 @@ private String addStudyMetadata(String projectId, TemplateStudy tmplStudy) throw if (existingGroups.contains(group.getId())) { if (overwrite) { logger.info("Updating users from group '{}'", group.getId()); - catalogManager.getStudyManager().updateGroup(fqn, group.getId(), ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, fqn, group.getId(), ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(group.getUsers()), token); } else { logger.info("Group '{}' already exists", group.getId()); } } else { logger.info("Adding group '{}'", group.getId()); - catalogManager.getStudyManager().createGroup(fqn, group.getId(), group.getUsers(), token); + catalogManager.getStudyManager().createGroup(organizationId, fqn, group.getId(), group.getUsers(), token); } } } @@ -241,7 +241,7 @@ private String addStudyMetadata(String projectId, TemplateStudy tmplStudy) throw logger.info("VariableSet '{}' already exists", variableSetCreateParams.getId()); } else { logger.info("Adding VariableSet '{}'", variableSetCreateParams.getId()); - catalogManager.getStudyManager().createVariableSet(fqn, variableSetCreateParams.toVariableSet(), token); + catalogManager.getStudyManager().createVariableSet(organizationId, fqn, variableSetCreateParams.toVariableSet(), token); } } } @@ -249,7 +249,7 @@ private String addStudyMetadata(String projectId, TemplateStudy tmplStudy) throw // Set permissions for (AclEntry studyAclEntry : tmplStudy.getAcl().getAcl()) { logger.info("Setting permissions for '{}'", studyAclEntry.getMember()); - catalogManager.getStudyManager().updateAcl(fqn, studyAclEntry.getMember(), + catalogManager.getStudyManager().updateAcl(organizationId, fqn, studyAclEntry.getMember(), new StudyAclParams(StringUtils.join(studyAclEntry.getPermissions(), ","), ""), ParamUtils.AclAction.SET, token); } } @@ -271,7 +271,7 @@ private void createIndividuals(String studyFqn, Path path) throws CatalogExcepti IndividualUpdateParams individual = iterator.next(); Query query = new Query(IndividualDBAdaptor.QueryParams.ID.key(), individual.getId()); - boolean exists = catalogManager.getIndividualManager().count(studyFqn, query, token).getNumMatches() > 0; + boolean exists = catalogManager.getIndividualManager().count(organizationId, studyFqn, query, token).getNumMatches() > 0; if (exists && !resume) { throw new CatalogException("Individual '" + individual.getId() + "' already exists. Do you want to resume the load?"); @@ -293,7 +293,7 @@ private void createIndividuals(String studyFqn, Path path) throws CatalogExcepti // Create individual logger.info("Create individual '{}'", individual.getId()); - catalogManager.getIndividualManager().create(studyFqn, individual.toIndividual(), QueryOptions.empty(), token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, individual.toIndividual(), QueryOptions.empty(), token); count++; } else if (overwrite) { @@ -432,7 +432,7 @@ private void createSamples(String studyFqn, Path path) throws CatalogException { SampleUpdateParams sample = iterator.next(); Query query = new Query(SampleDBAdaptor.QueryParams.ID.key(), sample.getId()); - boolean exists = catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches() > 0; + boolean exists = catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches() > 0; if (exists && !resume) { throw new CatalogException("Sample '" + sample.getId() + "' already exists. Do you want to resume the load?"); @@ -444,7 +444,7 @@ private void createSamples(String studyFqn, Path path) throws CatalogException { } // Create sample logger.info("Create sample '{}'", sample.getId()); - catalogManager.getSampleManager().create(studyFqn, sample.toSample(), QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample.toSample(), QueryOptions.empty(), token); count++; } else if (overwrite) { @@ -473,7 +473,7 @@ private void createCohorts(String studyFqn, Path path) throws CatalogException { CohortUpdateParams cohort = iterator.next(); Query query = new Query(CohortDBAdaptor.QueryParams.ID.key(), cohort.getId()); - boolean exists = catalogManager.getCohortManager().count(studyFqn, query, token).getNumMatches() > 0; + boolean exists = catalogManager.getCohortManager().count(organizationId, studyFqn, query, token).getNumMatches() > 0; if (exists && !resume) { throw new CatalogException("Cohort '" + cohort.getId() + "' already exists. Do you want to resume the load?"); @@ -486,7 +486,7 @@ private void createCohorts(String studyFqn, Path path) throws CatalogException { // Create cohort logger.info("Create cohort '{}'", cohort.getId()); - catalogManager.getCohortManager().create(studyFqn, cohort.toCohort(), QueryOptions.empty(), token); + catalogManager.getCohortManager().create(organizationId, studyFqn, cohort.toCohort(), QueryOptions.empty(), token); count++; } else if (overwrite) { @@ -515,7 +515,7 @@ private void createFamilies(String studyFqn, Path path) throws CatalogException FamilyUpdateParams family = iterator.next(); Query query = new Query(FamilyDBAdaptor.QueryParams.ID.key(), family.getId()); - boolean exists = catalogManager.getFamilyManager().count(studyFqn, query, token).getNumMatches() > 0; + boolean exists = catalogManager.getFamilyManager().count(organizationId, studyFqn, query, token).getNumMatches() > 0; if (exists && !resume) { throw new CatalogException("Family '" + family.getId() + "' already exists. Do you want to resume the load?"); @@ -534,7 +534,7 @@ private void createFamilies(String studyFqn, Path path) throws CatalogException completeFamily.setMembers(null); catalogManager.getFamilyManager().create(studyFqn, completeFamily, memberIds, QueryOptions.empty(), token); } else { - catalogManager.getFamilyManager().create(studyFqn, family.toFamily(), QueryOptions.empty(), token); + catalogManager.getFamilyManager().create(organizationId, studyFqn, family.toFamily(), QueryOptions.empty(), token); } count++; @@ -564,7 +564,7 @@ private void createPanels(String studyFqn, Path path) throws CatalogException { PanelUpdateParams panel = iterator.next(); Query query = new Query(PanelDBAdaptor.QueryParams.ID.key(), panel.getId()); - boolean exists = catalogManager.getPanelManager().count(studyFqn, query, token).getNumMatches() > 0; + boolean exists = catalogManager.getPanelManager().count(organizationId, studyFqn, query, token).getNumMatches() > 0; if (exists && !resume) { throw new CatalogException("Panel '" + panel.getId() + "' already exists. Do you want to resume the load?"); @@ -577,7 +577,7 @@ private void createPanels(String studyFqn, Path path) throws CatalogException { // Create family logger.info("Create panel '{}'", panel.getId()); - catalogManager.getPanelManager().create(studyFqn, panel.toPanel(), QueryOptions.empty(), token); + catalogManager.getPanelManager().create(organizationId, studyFqn, panel.toPanel(), QueryOptions.empty(), token); count++; } else if (overwrite) { @@ -606,7 +606,7 @@ private void createClinicalAnalyses(String studyFqn, Path path) throws CatalogEx ClinicalAnalysisUpdateParams clinical = iterator.next(); Query query = new Query(ClinicalAnalysisDBAdaptor.QueryParams.ID.key(), clinical.getId()); - boolean exists = catalogManager.getClinicalAnalysisManager().count(studyFqn, query, token).getNumMatches() > 0; + boolean exists = catalogManager.getClinicalAnalysisManager().count(organizationId, studyFqn, query, token).getNumMatches() > 0; if (exists && !resume) { throw new CatalogException("Clinical Analysis '" + clinical.getId() @@ -620,7 +620,7 @@ private void createClinicalAnalyses(String studyFqn, Path path) throws CatalogEx // Create Clinical Analysis logger.info("Create Clinical Analysis '{}'", clinical.getId()); - catalogManager.getClinicalAnalysisManager().create(studyFqn, clinical.toClinicalAnalysis(), QueryOptions.empty(), + catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, clinical.toClinicalAnalysis(), QueryOptions.empty(), token); count++; @@ -630,7 +630,7 @@ private void createClinicalAnalyses(String studyFqn, Path path) throws CatalogEx clinical.setId(null); logger.info("Update Clinical Analysis '{}'", clinical.getId()); - catalogManager.getClinicalAnalysisManager().update(studyFqn, clinicalId, clinical, QueryOptions.empty(), token); + catalogManager.getClinicalAnalysisManager().update(organizationId, studyFqn, clinicalId, clinical, QueryOptions.empty(), token); count++; } @@ -653,7 +653,7 @@ private void createFiles(String studyFqn, Path path) throws CatalogException { throw new CatalogException("Missing mandatory parameter 'path'"); } Query query = new Query(FileDBAdaptor.QueryParams.PATH.key(), file.getPath()); - boolean exists = catalogManager.getFileManager().count(studyFqn, query, token).getNumMatches() > 0; + boolean exists = catalogManager.getFileManager().count(organizationId, studyFqn, query, token).getNumMatches() > 0; if (exists && !resume) { throw new CatalogException("File '" + file.getPath() + "' already exists. Do you want to resume the load?"); diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/CatalogDemo.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/CatalogDemo.java index 3d2331d6eda..2072a429f00 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/CatalogDemo.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/CatalogDemo.java @@ -95,17 +95,17 @@ private static void populateDatabase(CatalogManager catalogManager) throws Catal String sessionId = userSessions.get("user5"); // user5 will be in the @admins group - catalogManager.getStudyManager().updateGroup(studyId, "@admins", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyId, "@admins", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("user5")), userSessions.get("user1")); // user5 will add the rest of users. user2, user3 and user4 go to group "members" - catalogManager.getStudyManager().createGroup(studyId, new Group("analyst", Arrays.asList("user2", "user3", "user4")), + catalogManager.getStudyManager().createGroup(organizationId, studyId, new Group("analyst", Arrays.asList("user2", "user3", "user4")), sessionId); // // @members will have the role "analyst" StudyAclParams aclParams1 = new StudyAclParams("", "analyst"); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyId), "@analyst", aclParams1, ParamUtils.AclAction.ADD, sessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyId), "@analyst", aclParams1, ParamUtils.AclAction.ADD, sessionId); // // Add anonymous user to the role "denyAll". Later we will give it permissions to see some concrete samples. StudyAclParams aclParams = new StudyAclParams("", "locked"); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyId), "*", aclParams, ParamUtils.AclAction.ADD, sessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyId), "*", aclParams, ParamUtils.AclAction.ADD, sessionId); } } diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoader.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoader.java index 25e618a4e68..a3fc4e2da0d 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoader.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoader.java @@ -76,7 +76,7 @@ public DataResult loadSampleAnnotations(File pedFile, String variableSet //Take or infer the VariableSet VariableSet variableSet; if (variableSetId != null) { - variableSet = catalogManager.getStudyManager().getVariableSet(study.getFqn(), variableSetId, null, sessionId).first(); + variableSet = catalogManager.getStudyManager().getVariableSet(organizationId, study.getFqn(), variableSetId, null, sessionId).first(); } else { variableSet = getVariableSetFromPedFile(ped); AnnotationUtils.checkVariableSet(variableSet); @@ -105,7 +105,7 @@ public DataResult loadSampleAnnotations(File pedFile, String variableSet List variableList = new ArrayList<>(); variableList.addAll(variableSet.getVariables()); String name = pedFile.getName(); - variableSet = catalogManager.getStudyManager().createVariableSet(study.getFqn(), name, name, true, false, "Auto-generated " + variableSet = catalogManager.getStudyManager().createVariableSet(organizationId, study.getFqn(), name, name, true, false, "Auto-generated " + "VariableSet from File = {path: " + pedFile.getPath() + ", name: \"" + pedFile.getName() + "\"}", null, variableList, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), sessionId).getResults().get(0); variableSetId = variableSet.getId(); @@ -115,7 +115,7 @@ public DataResult loadSampleAnnotations(File pedFile, String variableSet //Add Samples Query samplesQuery = new Query(SampleDBAdaptor.QueryParams.ID.key(), new LinkedList<>(ped.getIndividuals().keySet())); Map loadedSamples = new HashMap<>(); - for (Sample sample : catalogManager.getSampleManager().search(study.getFqn(), samplesQuery, null, sessionId).getResults()) { + for (Sample sample : catalogManager.getSampleManager().search(organizationId, study.getFqn(), samplesQuery, null, sessionId).getResults()) { loadedSamples.put(sample.getId(), sample); } @@ -133,7 +133,7 @@ public DataResult loadSampleAnnotations(File pedFile, String variableSet catalogManager.getSampleManager().update(study.getFqn(), individual.getId(), new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(annotationSet)), options, sessionId); } else { - DataResult sampleDataResult = catalogManager.getSampleManager().create(study.getFqn(), + DataResult sampleDataResult = catalogManager.getSampleManager().create(organizationId, study.getFqn(), new Sample() .setId(individual.getId()) .setFileIds(Collections.singletonList(pedFile.getPath())) @@ -163,7 +163,7 @@ public DataResult loadSampleAnnotations(File pedFile, String variableSet //TODO: Create Cohort - DataResult sampleDataResult = catalogManager.getSampleManager().search(study.getFqn(), + DataResult sampleDataResult = catalogManager.getSampleManager().search(organizationId, study.getFqn(), new Query(SampleDBAdaptor.QueryParams.ANNOTATION.key(), Constants.VARIABLE_SET + "=" + variableSetId), null, sessionId); return new DataResult<>((int) (System.currentTimeMillis() - startTime), Collections.emptyList(), sampleMap.size(), sampleDataResult.getResults(), sampleMap.size()); diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/FileMetadataReader.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/FileMetadataReader.java index 12cdbf83801..952814ecbed 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/FileMetadataReader.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/FileMetadataReader.java @@ -88,7 +88,7 @@ public File updateMetadataInformation(String studyId, File file, String token) t // Check and create missing samples List missingSamples = new LinkedList<>(updateParams.getSampleIds()); catalogManager.getSampleManager() - .iterator(studyId, + .iterator(organizationId, studyId, new Query(SampleDBAdaptor.QueryParams.ID.key(), updateParams.getSampleIds()), new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ID.key()), token) .forEachRemaining(sample -> { @@ -96,7 +96,7 @@ public File updateMetadataInformation(String studyId, File file, String token) t }); if (!missingSamples.isEmpty()) { for (String missingSample : missingSamples) { - catalogManager.getSampleManager().create(studyId, new Sample().setId(missingSample), new QueryOptions(), token); + catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId(missingSample), new QueryOptions(), token); } } } @@ -130,7 +130,7 @@ public File updateMetadataInformation(String studyId, File file, String token) t Collections.singletonMap(FileDBAdaptor.QueryParams.SAMPLE_IDS.key(), ParamUtils.BasicUpdateAction.SET.toString())), token); } - return catalogManager.getFileManager().get(studyId, file.getUuid(), QueryOptions.empty(), token).first(); + return catalogManager.getFileManager().get(organizationId, studyId, file.getUuid(), QueryOptions.empty(), token).first(); } } catch (JsonProcessingException e) { throw new CatalogException("Unexpected error converting FileUpdateParams object: " + e.getMessage(), e); diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/FileScanner.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/FileScanner.java index a9f81ecd312..6fc4e8119a5 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/FileScanner.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/FileScanner.java @@ -84,7 +84,7 @@ public List checkStudyFiles(Study study, boolean calculateChecksum, String query.put(FileDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), Arrays.asList( FileStatus.READY, FileStatus.MISSING, FileStatus.TRASHED)); - DBIterator iterator = catalogManager.getFileManager().iterator(study.getFqn(), query, new QueryOptions(), sessionId); + DBIterator iterator = catalogManager.getFileManager().iterator(organizationId, study.getFqn(), query, new QueryOptions(), sessionId); List modifiedFiles = new LinkedList<>(); while (iterator.hasNext()) { @@ -110,7 +110,7 @@ public List checkStudyFiles(Study study, boolean calculateChecksum, String */ public List reSync(Study study, boolean calculateChecksum, String sessionId) throws CatalogException, IOException { Query query = new Query(FileDBAdaptor.QueryParams.TYPE.key(), File.Type.DIRECTORY); - DBIterator iterator = catalogManager.getFileManager().iterator(study.getFqn(), query, null, sessionId); + DBIterator iterator = catalogManager.getFileManager().iterator(organizationId, study.getFqn(), query, null, sessionId); List scan = new LinkedList<>(); while (iterator.hasNext()) { @@ -147,7 +147,7 @@ public Map untrackedFiles(Study study, String sessionId) throws Cat linkedFolders.put("", studyUri); Query query = new Query(FileDBAdaptor.QueryParams.URI.key(), "~.*"); //Where URI exists) QueryOptions queryOptions = new QueryOptions("include", "projects.studies.files.path,projects.studies.files.uri"); - catalogManager.getFileManager().search(String.valueOf(studyId), query, queryOptions, sessionId).getResults() + catalogManager.getFileManager().search(organizationId, String.valueOf(studyId), query, queryOptions, sessionId).getResults() .forEach(f -> linkedFolders.put(f.getPath(), f.getUri())); Map untrackedFiles = new HashMap<>(); @@ -164,7 +164,7 @@ public Map untrackedFiles(Study study, String sessionId) throws Cat URI uri = iterator.next(); String filePath = entry.getKey() + entry.getValue().relativize(uri).toString(); - DataResult searchFile = catalogManager.getFileManager().search(String.valueOf(studyId), + DataResult searchFile = catalogManager.getFileManager().search(organizationId, String.valueOf(studyId), new Query("path", filePath), new QueryOptions("include", "projects.studies.files.id"), sessionId); if (searchFile.getResults().isEmpty()) { untrackedFiles.put(filePath, uri); @@ -248,7 +248,7 @@ public List scan(File directory, URI directoryToScan, FileScannerPolicy po } Query query = new Query(FileDBAdaptor.QueryParams.PATH.key(), filePath); - DataResult searchFile = catalogManager.getFileManager().search(study.getFqn(), query, null, sessionId); + DataResult searchFile = catalogManager.getFileManager().search(organizationId, study.getFqn(), query, null, sessionId); File file = null; boolean overwrite = true; boolean returnFile = false; @@ -267,7 +267,7 @@ public List scan(File directory, URI directoryToScan, FileScannerPolicy po sessionId); // Delete completely the file/folder ! - catalogManager.getFileManager().delete(study.getFqn(), tmpQuery, new QueryOptions(Constants.SKIP_TRASH, + catalogManager.getFileManager().delete(organizationId, study.getFqn(), tmpQuery, new QueryOptions(Constants.SKIP_TRASH, true), sessionId); overwrite = false; break; diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/auth/authorization/CatalogAuthorizationManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/auth/authorization/CatalogAuthorizationManagerTest.java index 837c17c85f8..dd3118f5a7d 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/auth/authorization/CatalogAuthorizationManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/auth/authorization/CatalogAuthorizationManagerTest.java @@ -175,14 +175,14 @@ public void before() throws Exception { false, ownerSessionId); // Add studyAdminUser1 and studyAdminUser2 to admin group and admin role. - catalogManager.getStudyManager().updateGroup(studyFqn, groupAdmin, ParamUtils.BasicUpdateAction.SET, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, groupAdmin, ParamUtils.BasicUpdateAction.SET, new GroupUpdateParams(Arrays.asList(studyAdminUser1, studyAdminUser2)), ownerSessionId); StudyAclParams aclParams1 = new StudyAclParams("", AuthorizationManager.ROLE_ANALYST); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), memberUser, aclParams1, ADD, + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), memberUser, aclParams1, ADD, studyAdmin1SessionId); StudyAclParams aclParams = new StudyAclParams("", AuthorizationManager.ROLE_LOCKED); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), externalUser, aclParams, ADD, + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), externalUser, aclParams, ADD, studyAdmin1SessionId); fileManager.updateAcl(studyFqn, Arrays.asList(data_d1), externalUser, new FileAclParams(null, ALL_FILE_PERMISSIONS), @@ -192,14 +192,14 @@ public void before() throws Exception { fileManager.updateAcl(studyFqn, Arrays.asList(data_d1_d2_d3_d4_txt), externalUser, new FileAclParams(null, ALL_FILE_PERMISSIONS), SET, ownerSessionId); - smp1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("smp1"), INCLUDE_RESULT, ownerSessionId).first(); - smp2 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("smp2"), INCLUDE_RESULT, ownerSessionId).first(); - smp3 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("smp3"), INCLUDE_RESULT, ownerSessionId).first(); - smp4 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("smp4"), INCLUDE_RESULT, ownerSessionId).first(); - smp5 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("smp5"), INCLUDE_RESULT, ownerSessionId).first(); - smp6 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("smp6"), INCLUDE_RESULT, ownerSessionId).first(); + smp1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("smp1"), INCLUDE_RESULT, ownerSessionId).first(); + smp2 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("smp2"), INCLUDE_RESULT, ownerSessionId).first(); + smp3 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("smp3"), INCLUDE_RESULT, ownerSessionId).first(); + smp4 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("smp4"), INCLUDE_RESULT, ownerSessionId).first(); + smp5 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("smp5"), INCLUDE_RESULT, ownerSessionId).first(); + smp6 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("smp6"), INCLUDE_RESULT, ownerSessionId).first(); - catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("all").setSamples(Arrays.asList(smp1, smp2, smp3)), + catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("all").setSamples(Arrays.asList(smp1, smp2, smp3)), QueryOptions.empty(), ownerSessionId); catalogManager.getIndividualManager().create(studyFqn, new Individual().setId(ind1), Collections.singletonList(smp1.getId()), @@ -245,7 +245,7 @@ private DataResult updateGroup(String studyStr, String groupId, @Nullable if (groupParams == null) { throw new CatalogException("No action"); } - return catalogManager.getStudyManager().updateGroup(studyStr, groupId, action, groupParams, sessionId); + return catalogManager.getStudyManager().updateGroup(organizationId, studyStr, groupId, action, groupParams, sessionId); } @Test @@ -270,7 +270,7 @@ public void changeGroupMembership() throws CatalogException { // thrown.expect(CatalogException.class); // catalogManager.addUsersToGroup(s1, groupMember, externalUser, ownerSessionId); updateGroup(studyFqn, groupAdmin, null, externalUser, null, ownerSessionId); - catalogManager.getStudyManager().createGroup(studyFqn, new Group(groupMember, Collections.singletonList(externalUser)), + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, new Group(groupMember, Collections.singletonList(externalUser)), ownerSessionId); // catalogManager.updateGroup(Long.toString(s1), groupMember, externalUser, null, null, ownerSessionId); groups = getGroupMap(); @@ -282,7 +282,7 @@ public void changeGroupMembership() throws CatalogException { public void adminUserRemovesFromAdminsGroup() throws CatalogException { thrown.expectMessage("Only the owner"); thrown.expect(CatalogAuthorizationException.class); - catalogManager.getStudyManager().updateGroup(studyFqn, groupAdmin, ParamUtils.BasicUpdateAction.REMOVE, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, groupAdmin, ParamUtils.BasicUpdateAction.REMOVE, new GroupUpdateParams(Collections.singletonList(studyAdminUser2)), studyAdmin1SessionId); } @@ -290,7 +290,7 @@ public void adminUserRemovesFromAdminsGroup() throws CatalogException { public void adminUserAddsFromAdminsGroup() throws CatalogException { thrown.expectMessage("Only the owner"); thrown.expect(CatalogAuthorizationException.class); - catalogManager.getStudyManager().updateGroup(studyFqn, groupAdmin, ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, groupAdmin, ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList(externalUser)), studyAdmin1SessionId); } @@ -298,7 +298,7 @@ public void adminUserAddsFromAdminsGroup() throws CatalogException { public void adminUserSetsFromAdminsGroup() throws CatalogException { thrown.expectMessage("Only the owner"); thrown.expect(CatalogAuthorizationException.class); - catalogManager.getStudyManager().updateGroup(studyFqn, groupAdmin, ParamUtils.BasicUpdateAction.SET, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, groupAdmin, ParamUtils.BasicUpdateAction.SET, new GroupUpdateParams(Collections.singletonList(studyAdminUser1)), studyAdmin1SessionId); } @@ -316,7 +316,7 @@ public void adminUserSetsFromAdminsGroup() throws CatalogException { @Test public void removeMemberFromGroup() throws CatalogException { // Create new group - catalogManager.getStudyManager().createGroup(studyFqn, + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, new Group(groupMember, Arrays.asList(studyAdminUser1, studyAdminUser2)), ownerSessionId); // Remove one of the users @@ -330,7 +330,7 @@ public void removeMemberFromGroup() throws CatalogException { // // Cannot remove group with defined ACLs // thrown.expect(CatalogDBException.class); // thrown.expectMessage("ACL defined"); - catalogManager.getStudyManager().deleteGroup(studyFqn, groupMember, ownerSessionId); + catalogManager.getStudyManager().deleteGroup(organizationId, studyFqn, groupMember, ownerSessionId); assertNull(getGroupMap().get(groupMember)); } @@ -366,7 +366,7 @@ public void addExistingUserToRole() throws CatalogException { String newUser = "newUser"; catalogManager.getUserManager().create(newUser, newUser, "email@ccc.ccc", TestParamConstants.PASSWORD, "ASDF", null, Account.AccountType.FULL, opencgaToken); StudyAclParams aclParams = new StudyAclParams("", AuthorizationManager.ROLE_ANALYST); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), newUser, aclParams, ParamUtils.AclAction.ADD, ownerSessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), newUser, aclParams, ParamUtils.AclAction.ADD, ownerSessionId); } // A user with no permissions tries to add an existing user to a role @@ -377,7 +377,7 @@ public void addExistingUserToRole2() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); thrown.expectMessage("Only owners or administrative users"); StudyAclParams aclParams = new StudyAclParams("", AuthorizationManager.ROLE_ANALYST); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), newUser, aclParams, ParamUtils.AclAction.ADD, memberSessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), newUser, aclParams, ParamUtils.AclAction.ADD, memberSessionId); } @Test @@ -386,9 +386,9 @@ public void addExistingGroupToRole() throws CatalogException { catalogManager.getUserManager().create(newUser, newUser, "email@ccc.ccc", TestParamConstants.PASSWORD, "ASDF", null, Account.AccountType.FULL, opencgaToken); String group = "@newGroup"; // catalogManager.addUsersToGroup(studyFqn, group, newUser, studyAdmin1SessionId); - catalogManager.getStudyManager().createGroup(studyFqn, group, Collections.singletonList(newUser), studyAdmin1SessionId); + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, group, Collections.singletonList(newUser), studyAdmin1SessionId); StudyAclParams aclParams = new StudyAclParams("", AuthorizationManager.ROLE_ANALYST); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), group, aclParams, ParamUtils.AclAction.ADD, studyAdmin1SessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), group, aclParams, ParamUtils.AclAction.ADD, studyAdmin1SessionId); OpenCGAResult> studyAcls = catalogManager.getAuthorizationManager() .getStudyAcl(studyAdminUser1, studyUid, group); assertEquals(1, studyAcls.getNumResults()); @@ -406,7 +406,7 @@ public void addNonExistingUserToRole() throws CatalogException { thrown.expect(CatalogDBException.class); thrown.expectMessage("does not exist"); StudyAclParams aclParams = new StudyAclParams("", AuthorizationManager.ROLE_ANALYST); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), userNotRegistered, aclParams, ParamUtils.AclAction.ADD, + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), userNotRegistered, aclParams, ParamUtils.AclAction.ADD, studyAdmin1SessionId); } @@ -415,14 +415,14 @@ public void addNonExistingGroupToRole() throws CatalogException { String groupNotRegistered = "@groupNotRegistered"; thrown.expect(CatalogDBException.class); thrown.expectMessage("not found"); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), groupNotRegistered, new StudyAclParams("", + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), groupNotRegistered, new StudyAclParams("", AuthorizationManager.ROLE_ANALYST), ParamUtils.AclAction.SET, studyAdmin1SessionId); } @Test public void changeUserRole() throws CatalogException { OpenCGAResult> studyAcls = catalogManager.getStudyManager() - .getAcls(Collections.singletonList(studyFqn), externalUser, false, studyAdmin1SessionId); + .getAcls(organizationId, Collections.singletonList(studyFqn), externalUser, false, studyAdmin1SessionId); assertEquals(1, studyAcls.getNumResults()); assertEquals(1, studyAcls.first().getAcl().size()); @@ -430,13 +430,13 @@ public void changeUserRole() throws CatalogException { // Change role StudyAclParams aclParams1 = new StudyAclParams(null, null); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), externalUser, aclParams1, RESET, + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), externalUser, aclParams1, RESET, studyAdmin1SessionId); StudyAclParams aclParams = new StudyAclParams("", AuthorizationManager.ROLE_ANALYST); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), externalUser, aclParams, ParamUtils.AclAction.ADD, + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), externalUser, aclParams, ParamUtils.AclAction.ADD, studyAdmin1SessionId); - studyAcls = catalogManager.getStudyManager().getAcls(Collections.singletonList(studyFqn), externalUser, false, + studyAcls = catalogManager.getStudyManager().getAcls(organizationId, Collections.singletonList(studyFqn), externalUser, false, studyAdmin1SessionId); assertEquals(1, studyAcls.getNumResults()); @@ -456,10 +456,10 @@ public void changeUserRole() throws CatalogException { @Test public void removeUserFromRole() throws CatalogException { StudyAclParams aclParams = new StudyAclParams(null, null); - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), externalUser, aclParams, RESET, studyAdmin1SessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), externalUser, aclParams, RESET, studyAdmin1SessionId); OpenCGAResult> studyAcls = catalogManager.getStudyManager().getAcls( - Collections.singletonList(studyFqn), externalUser, false, studyAdmin1SessionId); + organizationId, Collections.singletonList(studyFqn), externalUser, false, studyAdmin1SessionId); assertEquals(1, studyAcls.getNumResults()); assertEquals(1, studyAcls.first().getAcl().size()); assertEquals(externalUser, studyAcls.first().getAcl().get(0).getMember()); @@ -470,10 +470,10 @@ public void removeUserFromRole() throws CatalogException { @Test public void denyAllPermissions() throws CatalogException { StudyAclParams aclParams = new StudyAclParams("", null); - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), externalUser, aclParams, SET, studyAdmin1SessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), externalUser, aclParams, SET, studyAdmin1SessionId); OpenCGAResult> studyAcls = catalogManager.getStudyManager().getAcls( - Collections.singletonList(studyFqn), externalUser, false, studyAdmin1SessionId); + organizationId, Collections.singletonList(studyFqn), externalUser, false, studyAdmin1SessionId); assertEquals(1, studyAcls.getNumResults()); assertEquals(1, studyAcls.first().getAcl().size()); assertEquals(externalUser, studyAcls.first().getAcl().get(0).getMember()); @@ -486,17 +486,17 @@ public void denyAllPermissions() throws CatalogException { public void removeUserFromRole2() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); StudyAclParams aclParams = new StudyAclParams(null, null); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), externalUser, aclParams, RESET, memberSessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), externalUser, aclParams, RESET, memberSessionId); } @Test public void removeGroupFromRole() throws CatalogException { String group = "@newGroup"; - catalogManager.getStudyManager().createGroup(studyFqn, new Group(group, Arrays.asList(studyAdminUser1, studyAdminUser2)), + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, new Group(group, Arrays.asList(studyAdminUser1, studyAdminUser2)), studyAdmin1SessionId); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), group, new StudyAclParams("", "admin"), SET, ownerSessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), group, new StudyAclParams("", "admin"), SET, ownerSessionId); - Study study = catalogManager.getStudyManager().get(studyFqn, QueryOptions.empty(), studyAdmin1SessionId).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyFqn, QueryOptions.empty(), studyAdmin1SessionId).first(); OpenCGAResult> studyAcls = catalogManager.getAuthorizationManager().getStudyAcl(studyAdminUser1, study.getUid(), group); assertEquals(1, studyAcls.getNumResults()); @@ -508,7 +508,7 @@ public void removeGroupFromRole() throws CatalogException { } StudyAclParams aclParams = new StudyAclParams(null, null); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), group, aclParams, RESET, ownerSessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), group, aclParams, RESET, ownerSessionId); String userId = catalogManager.getUserManager().getUserId(ownerSessionId); studyAcls = catalogManager.getAuthorizationManager().getStudyAcl(userId, study.getUid(), group); assertEquals(1, studyAcls.getNumResults()); @@ -524,7 +524,7 @@ public void removeNonExistingUserFromRole() throws CatalogException { thrown.expectMessage("does not exist"); // catalogManager.unshareStudy(studyFqn, userNotRegistered, ownerSessionId); StudyAclParams aclParams = new StudyAclParams(null, null); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), userNotRegistered, aclParams, RESET, ownerSessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), userNotRegistered, aclParams, RESET, ownerSessionId); } @Test @@ -533,7 +533,7 @@ public void removeNonExistingGroupFromRole() throws CatalogException { thrown.expect(CatalogException.class); thrown.expectMessage("not found"); StudyAclParams aclParams = new StudyAclParams(null, null); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), groupNotRegistered, aclParams, RESET, ownerSessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), groupNotRegistered, aclParams, RESET, ownerSessionId); } /*--------------------------*/ @@ -542,18 +542,18 @@ public void removeNonExistingGroupFromRole() throws CatalogException { @Test public void readProject() throws CatalogException { - DataResult project = catalogManager.getProjectManager().get(p1, null, ownerSessionId); + DataResult project = catalogManager.getProjectManager().get(organizationId, p1, null, ownerSessionId); assertEquals(1, project.getNumResults()); - project = catalogManager.getProjectManager().get(p1, null, memberSessionId); + project = catalogManager.getProjectManager().get(organizationId, p1, null, memberSessionId); assertEquals(1, project.getNumResults()); } @Test public void readProjectDeny() throws CatalogException { - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.REMOVE, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.REMOVE, new GroupUpdateParams(Arrays.asList(externalUser, ParamConstants.ANONYMOUS_USER_ID)), ownerSessionId); thrown.expect(CatalogAuthorizationException.class); - catalogManager.getProjectManager().get(p1, null, externalSessionId); + catalogManager.getProjectManager().get(organizationId, p1, null, externalSessionId); } /*--------------------------*/ @@ -562,18 +562,18 @@ public void readProjectDeny() throws CatalogException { @Test public void readStudy() throws CatalogException { - DataResult study = catalogManager.getStudyManager().get(studyFqn, null, ownerSessionId); + DataResult study = catalogManager.getStudyManager().get(organizationId, studyFqn, null, ownerSessionId); assertEquals(1, study.getNumResults()); - study = catalogManager.getStudyManager().get(studyFqn, null, memberSessionId); + study = catalogManager.getStudyManager().get(organizationId, studyFqn, null, memberSessionId); assertEquals(1, study.getNumResults()); } @Test public void readStudyDeny() throws CatalogException { - catalogManager.getStudyManager().updateGroup(String.valueOf(studyFqn), "@members", ParamUtils.BasicUpdateAction.REMOVE, + catalogManager.getStudyManager().updateGroup(organizationId, String.valueOf(studyFqn), "@members", ParamUtils.BasicUpdateAction.REMOVE, new GroupUpdateParams(Arrays.asList(externalUser, ParamConstants.ANONYMOUS_USER_ID)), ownerSessionId); thrown.expect(CatalogAuthorizationException.class); - catalogManager.getStudyManager().get(studyFqn, null, externalSessionId); + catalogManager.getStudyManager().get(organizationId, studyFqn, null, externalSessionId); } /*--------------------------*/ @@ -582,53 +582,53 @@ public void readStudyDeny() throws CatalogException { @Test public void readFileByOwner() throws CatalogException { - DataResult file = catalogManager.getFileManager().get(studyFqn, data_d1, null, ownerSessionId); + DataResult file = catalogManager.getFileManager().get(organizationId, studyFqn, data_d1, null, ownerSessionId); assertEquals(1, file.getNumResults()); } @Test public void readExplicitlySharedFolder() throws CatalogException { - catalogManager.getFileManager().get(studyFqn, data_d1, null, externalSessionId); + catalogManager.getFileManager().get(organizationId, studyFqn, data_d1, null, externalSessionId); } @Test public void readExplicitlyUnsharedFile() throws CatalogException { - DataResult file = catalogManager.getFileManager().get(studyFqn, data_d1, null, memberSessionId); + DataResult file = catalogManager.getFileManager().get(organizationId, studyFqn, data_d1, null, memberSessionId); assertEquals(1, file.getNumResults()); // Set an ACL with no permissions fileManager.updateAcl(studyFqn, Arrays.asList(data_d1), memberUser, new FileAclParams(null, null), SET, ownerSessionId); thrown.expect(CatalogAuthorizationException.class); - catalogManager.getFileManager().get(studyFqn, data_d1, null, memberSessionId); + catalogManager.getFileManager().get(organizationId, studyFqn, data_d1, null, memberSessionId); } @Test public void readInheritedSharedFile() throws CatalogException { - DataResult file = catalogManager.getFileManager().get(studyFqn, data_d1_d2, null, externalSessionId); + DataResult file = catalogManager.getFileManager().get(organizationId, studyFqn, data_d1_d2, null, externalSessionId); assertEquals(1, file.getNumResults()); } @Test public void readExplicitlyForbiddenFile() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); - catalogManager.getFileManager().get(studyFqn, data_d1_d2_d3, null, externalSessionId); + catalogManager.getFileManager().get(organizationId, studyFqn, data_d1_d2_d3, null, externalSessionId); } @Test public void readInheritedForbiddenFile() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); - catalogManager.getFileManager().get(studyFqn, data_d1_d2_d3_d4, null, externalSessionId); + catalogManager.getFileManager().get(organizationId, studyFqn, data_d1_d2_d3_d4, null, externalSessionId); } @Test public void readExplicitlySharedFile() throws CatalogException { - DataResult file = catalogManager.getFileManager().get(studyFqn, data_d1_d2_d3_d4_txt, null, externalSessionId); + DataResult file = catalogManager.getFileManager().get(organizationId, studyFqn, data_d1_d2_d3_d4_txt, null, externalSessionId); assertEquals(1, file.getNumResults()); } @Test public void readNonSharedFile() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); - catalogManager.getFileManager().get(studyFqn, data, null, externalSessionId); + catalogManager.getFileManager().get(organizationId, studyFqn, data, null, externalSessionId); } @Test @@ -637,7 +637,7 @@ public void readFileNoStudyMember() throws CatalogException, IOException { catalogManager.getUserManager().create(newUser, newUser, "asda@mail.com", TestParamConstants.PASSWORD, "org", 1000L, Account.AccountType.FULL, opencgaToken); String sessionId = catalogManager.getUserManager().login(newUser, TestParamConstants.PASSWORD).getToken(); thrown.expect(CatalogAuthorizationException.class); - catalogManager.getFileManager().get(studyFqn, data, null, sessionId); + catalogManager.getFileManager().get(organizationId, studyFqn, data, null, sessionId); } @Test @@ -648,26 +648,26 @@ public void readFileSharedForGroup() throws CatalogException, IOException { String sessionId = catalogManager.getUserManager().login(newUser, TestParamConstants.PASSWORD).getToken(); String newGroup = "@external"; // catalogManager.addUsersToGroup(studyFqn, "@external", newUser, ownerSessionId); - catalogManager.getStudyManager().createGroup(studyFqn, newGroup, Collections.singletonList(newUser), ownerSessionId); + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, newGroup, Collections.singletonList(newUser), ownerSessionId); // Add the group to the locked role, so no permissions will be given StudyAclParams aclParams = new StudyAclParams("", AuthorizationManager.ROLE_LOCKED); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), newGroup, aclParams, ADD, ownerSessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), newGroup, aclParams, ADD, ownerSessionId); // Specify all file permissions for that concrete file fileManager.updateAcl(studyFqn, Arrays.asList(data_d1_d2_d3_d4), newGroup, new FileAclParams(null, ALL_FILE_PERMISSIONS), SET, ownerSessionId); - catalogManager.getFileManager().get(studyFqn, data_d1_d2_d3_d4, null, sessionId); + catalogManager.getFileManager().get(organizationId, studyFqn, data_d1_d2_d3_d4, null, sessionId); } @Test public void readFileForbiddenForUser() throws CatalogException { // Remove all permissions to the admin group in that folder - catalogManager.getStudyManager().createGroup(studyFqn, groupMember, Collections.singletonList(externalUser), ownerSessionId); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), groupMember, new StudyAclParams("", "admin"), SET, + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, groupMember, Collections.singletonList(externalUser), ownerSessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), groupMember, new StudyAclParams("", "admin"), SET, ownerSessionId); fileManager.updateAcl(studyFqn, Arrays.asList(data_d1_d2), externalUser, new FileAclParams(null, DENY_FILE_PERMISSIONS), SET, ownerSessionId); thrown.expect(CatalogAuthorizationException.class); - catalogManager.getFileManager().get(studyFqn, data_d1_d2, null, externalSessionId); + catalogManager.getFileManager().get(organizationId, studyFqn, data_d1_d2, null, externalSessionId); } @Test @@ -678,12 +678,12 @@ public void readFileForbiddenForGroupSharedWithUser() throws CatalogException, I String sessionId = catalogManager.getUserManager().login(ownerUser, TestParamConstants.PASSWORD).getToken(); String newGroup = "@external"; // catalogManager.addUsersToGroup(studyFqn, "@external", newUser, ownerSessionId); - catalogManager.getStudyManager().createGroup(studyFqn, newGroup, Collections.singletonList(newUser), ownerSessionId); + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, newGroup, Collections.singletonList(newUser), ownerSessionId); // Add the group to the locked role, so no permissions will be given StudyAclParams aclParams = new StudyAclParams("", AuthorizationManager.ROLE_LOCKED); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), newGroup, aclParams, ADD, ownerSessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), newGroup, aclParams, ADD, ownerSessionId); fileManager.updateAcl(studyFqn, Arrays.asList(data_d1_d2), newGroup, new FileAclParams(null, ALL_FILE_PERMISSIONS), SET, ownerSessionId); - DataResult file = catalogManager.getFileManager().get(studyFqn, data_d1_d2, null, sessionId); + DataResult file = catalogManager.getFileManager().get(organizationId, studyFqn, data_d1_d2, null, sessionId); assertEquals(1, file.getNumResults()); } @@ -747,49 +747,49 @@ public void createFileNoStudyMember() throws CatalogException, IOException { @Test public void readSampleOwnerUser() throws CatalogException { - DataResult sample = catalogManager.getSampleManager().get(studyFqn, smp1.getId(), null, ownerSessionId); + DataResult sample = catalogManager.getSampleManager().get(organizationId, studyFqn, smp1.getId(), null, ownerSessionId); assertEquals(1, sample.getNumResults()); - sample = catalogManager.getSampleManager().get(studyFqn, smp2.getId(), null, ownerSessionId); + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, smp2.getId(), null, ownerSessionId); assertEquals(1, sample.getNumResults()); - sample = catalogManager.getSampleManager().get(studyFqn, smp3.getId(), null, ownerSessionId); + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, smp3.getId(), null, ownerSessionId); assertEquals(1, sample.getNumResults()); // Owner always have access even if he has been removed all the permissions StudyAclParams aclParams = new StudyAclParams("", null); - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), ownerUser, aclParams, ADD, ownerSessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), ownerUser, aclParams, ADD, ownerSessionId); catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList(smp1.getId()), ownerUser, noSamplePermissions, SET, ownerSessionId); - sample = catalogManager.getSampleManager().get(studyFqn, smp1.getId(), null, ownerSessionId); + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, smp1.getId(), null, ownerSessionId); assertEquals(1, sample.getNumResults()); } @Test public void readSampleExplicitShared() throws CatalogException { - DataResult sample = catalogManager.getSampleManager().get(studyFqn, smp1.getId(), null, externalSessionId); + DataResult sample = catalogManager.getSampleManager().get(organizationId, studyFqn, smp1.getId(), null, externalSessionId); assertEquals(1, sample.getNumResults()); } @Test public void readSampleExplicitUnshared() throws CatalogException { - DataResult sample = catalogManager.getSampleManager().get(studyFqn, smp1.getId(), null, externalSessionId); + DataResult sample = catalogManager.getSampleManager().get(organizationId, studyFqn, smp1.getId(), null, externalSessionId); assertEquals(1, sample.getNumResults()); catalogManager.getAuthorizationManager().removeAcls(Collections.singletonList(externalUser), new AuthorizationManager.CatalogAclParams(Collections.singletonList(smp1.getUid()), null, Enums.Resource.SAMPLE)); thrown.expect(CatalogAuthorizationException.class); - catalogManager.getSampleManager().get(studyFqn, smp1.getId(), null, externalSessionId); + catalogManager.getSampleManager().get(organizationId, studyFqn, smp1.getId(), null, externalSessionId); } @Test public void readSampleNoShared() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); - catalogManager.getSampleManager().get(studyFqn, smp2.getId(), null, externalSessionId); + catalogManager.getSampleManager().get(organizationId, studyFqn, smp2.getId(), null, externalSessionId); } @Test public void readSampleExplicitForbidden() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); - catalogManager.getSampleManager().get(studyFqn, smp3.getId(), null, externalSessionId); + catalogManager.getSampleManager().get(organizationId, studyFqn, smp3.getId(), null, externalSessionId); } @Test @@ -798,14 +798,14 @@ public void readSampleExternalUser() throws CatalogException, IOException { catalogManager.getUserManager().create(newUser, newUser, "asda@mail.com", TestParamConstants.PASSWORD, "org", 1000L, Account.AccountType.FULL, opencgaToken); String sessionId = catalogManager.getUserManager().login(newUser, TestParamConstants.PASSWORD).getToken(); thrown.expect(CatalogAuthorizationException.class); - catalogManager.getSampleManager().get(studyFqn, smp2.getId(), null, sessionId); + catalogManager.getSampleManager().get(organizationId, studyFqn, smp2.getId(), null, sessionId); } @Test public void readSampleAdminUser() throws CatalogException { - DataResult sample = catalogManager.getSampleManager().get(studyFqn, smp1.getId(), null, studyAdmin1SessionId); + DataResult sample = catalogManager.getSampleManager().get(organizationId, studyFqn, smp1.getId(), null, studyAdmin1SessionId); assertEquals(1, sample.getNumResults()); - sample = catalogManager.getSampleManager().get(studyFqn, smp3.getId(), null, studyAdmin1SessionId); + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, smp3.getId(), null, studyAdmin1SessionId); assertEquals(1, sample.getNumResults()); } @@ -814,7 +814,7 @@ public void readSampleForbiddenForExternalUser() throws CatalogException { catalogManager.getSampleManager().updateAcl(String.valueOf(studyFqn), Arrays.asList(smp2.getId()), externalUser, new SampleAclParams(null, null, null, null, ""), SET, ownerSessionId); thrown.expect(CatalogAuthorizationException.class); - catalogManager.getSampleManager().get(studyFqn, smp2.getId(), null, externalSessionId); + catalogManager.getSampleManager().get(organizationId, studyFqn, smp2.getId(), null, externalSessionId); } @Test @@ -825,22 +825,22 @@ public void readSampleSharedForGroup() throws CatalogException, IOException { String sessionId = catalogManager.getUserManager().login(ownerUser, TestParamConstants.PASSWORD).getToken(); String newGroup = "@external"; // catalogManager.addUsersToGroup(studyFqn, "@external", newUser, ownerSessionId); - catalogManager.getStudyManager().createGroup(studyFqn, newGroup, Collections.singletonList(newUser), ownerSessionId); + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, newGroup, Collections.singletonList(newUser), ownerSessionId); // Add the group to the locked role, so no permissions will be given StudyAclParams aclParams = new StudyAclParams("", AuthorizationManager.ROLE_LOCKED); - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), newGroup, aclParams, ADD, ownerSessionId); + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), newGroup, aclParams, ADD, ownerSessionId); // Share the sample with the group catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList(smp4.getId()), newGroup, allSamplePermissions, SET, ownerSessionId); - DataResult sample = catalogManager.getSampleManager().get(studyFqn, smp4.getId(), null, sessionId); + DataResult sample = catalogManager.getSampleManager().get(organizationId, studyFqn, smp4.getId(), null, sessionId); assertEquals(1, sample.getNumResults()); } @Test public void readSampleSharedForOthers() throws CatalogException { - DataResult sample = catalogManager.getSampleManager().get(studyFqn, smp6.getId(), null, externalSessionId); + DataResult sample = catalogManager.getSampleManager().get(organizationId, studyFqn, smp6.getId(), null, externalSessionId); assertEquals(1, sample.getNumResults()); } @@ -851,10 +851,10 @@ public void readSampleSharedForOthersNotWithStudyPermissions() throws CatalogExc String newUser = "newUser"; catalogManager.getUserManager().create(newUser, newUser, "asda@mail.com", TestParamConstants.PASSWORD, "org", 1000L, Account.AccountType.FULL, opencgaToken); String sessionId = catalogManager.getUserManager().login(ownerUser, TestParamConstants.PASSWORD).getToken(); - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList(newUser)), ownerSessionId); - DataResult sample = catalogManager.getSampleManager().get(studyFqn, smp6.getId(), null, sessionId); + DataResult sample = catalogManager.getSampleManager().get(organizationId, studyFqn, smp6.getId(), null, sessionId); assertEquals(1, sample.getNumResults()); } @@ -862,13 +862,13 @@ public void readSampleSharedForOthersNotWithStudyPermissions() throws CatalogExc public void adminShareSampleWithOtherUser() throws CatalogException { catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList(smp4.getId()), externalUser, allSamplePermissions, SET, studyAdmin1SessionId); - DataResult sample = catalogManager.getSampleManager().get(studyFqn, smp4.getId(), null, externalSessionId); + DataResult sample = catalogManager.getSampleManager().get(organizationId, studyFqn, smp4.getId(), null, externalSessionId); assertEquals(1, sample.getNumResults()); } @Test public void readAllSamplesOwner() throws CatalogException { - Map sampleMap = catalogManager.getSampleManager().search(studyFqn, new Query(), new QueryOptions(), ownerSessionId) + Map sampleMap = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(), new QueryOptions(), ownerSessionId) .getResults().stream().collect(Collectors.toMap(Sample::getUid, f -> f)); assertTrue(sampleMap.containsKey(smp1.getUid())); @@ -888,7 +888,7 @@ public void readAllSamplesOwner() throws CatalogException { @Test public void readAllSamplesMember() throws CatalogException { - Map sampleMap = catalogManager.getSampleManager().search(studyFqn, new Query(), new QueryOptions(), externalSessionId) + Map sampleMap = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(), new QueryOptions(), externalSessionId) .getResults().stream().collect(Collectors.toMap(Sample::getUid, f -> f)); assertTrue(sampleMap.containsKey(smp1.getUid())); @@ -900,11 +900,11 @@ public void readAllSamplesMember() throws CatalogException { public void aclQuery() throws CatalogException { SampleManager sampleManager = catalogManager.getSampleManager(); - sampleManager.create(studyFqn, new Sample().setId("s1"), QueryOptions.empty(), ownerSessionId); - sampleManager.create(studyFqn, new Sample().setId("s2"), QueryOptions.empty(), ownerSessionId); - sampleManager.create(studyFqn, new Sample().setId("s3"), QueryOptions.empty(), ownerSessionId); - sampleManager.create(studyFqn, new Sample().setId("s4"), QueryOptions.empty(), ownerSessionId); - sampleManager.create(studyFqn, new Sample().setId("s5"), QueryOptions.empty(), ownerSessionId); + sampleManager.create(organizationId, studyFqn, new Sample().setId("s1"), QueryOptions.empty(), ownerSessionId); + sampleManager.create(organizationId, studyFqn, new Sample().setId("s2"), QueryOptions.empty(), ownerSessionId); + sampleManager.create(organizationId, studyFqn, new Sample().setId("s3"), QueryOptions.empty(), ownerSessionId); + sampleManager.create(organizationId, studyFqn, new Sample().setId("s4"), QueryOptions.empty(), ownerSessionId); + sampleManager.create(organizationId, studyFqn, new Sample().setId("s5"), QueryOptions.empty(), ownerSessionId); sampleManager.updateAcl(studyFqn, Collections.singletonList("s1"), memberUser, new SampleAclParams(null, null, null, null, SamplePermissions.DELETE.name()), SET, ownerSessionId); @@ -920,14 +920,14 @@ public void aclQuery() throws CatalogException { // member user wants to know the samples for which he has DELETE permissions Query query = new Query(ParamConstants.ACL_PARAM, memberUser + ":" + SamplePermissions.DELETE.name()); - List results = sampleManager.search(studyFqn, query, options, memberSessionId).getResults(); + List results = sampleManager.search(organizationId, studyFqn, query, options, memberSessionId).getResults(); assertEquals(3, results.stream().map(Sample::getId).collect(Collectors.toSet()).size()); assertTrue(Arrays.asList("s1", "s3", "smp6").containsAll(results.stream().map(Sample::getId).collect(Collectors.toSet()))); // member user wants to know the samples for which he has UPDATE permissions // He should have UPDATE permissions in the same samples where he has DELETE permissions query = new Query(ParamConstants.ACL_PARAM, memberUser + ":" + SamplePermissions.WRITE.name()); - results = sampleManager.search(studyFqn, query, options, memberSessionId).getResults(); + results = sampleManager.search(organizationId, studyFqn, query, options, memberSessionId).getResults(); System.out.println(results.stream().map(Sample::getId).collect(Collectors.toSet())); assertEquals(8, results.stream().map(Sample::getId).collect(Collectors.toSet()).size()); assertTrue(Arrays.asList("s1", "s3", "s5", "smp1", "smp3", "smp4", "smp5", "smp6") @@ -935,7 +935,7 @@ public void aclQuery() throws CatalogException { // Owner user wants to know the samples for which member user has DELETE permissions query = new Query(ParamConstants.ACL_PARAM, memberUser + ":" + SamplePermissions.DELETE.name()); - results = sampleManager.search(studyFqn, query, options, ownerSessionId).getResults(); + results = sampleManager.search(organizationId, studyFqn, query, options, ownerSessionId).getResults(); assertEquals(3, results.stream().map(Sample::getId).collect(Collectors.toSet()).size()); assertTrue(Arrays.asList("s1", "s3", "smp6").containsAll(results.stream().map(Sample::getId).collect(Collectors.toSet()))); @@ -943,22 +943,22 @@ public void aclQuery() throws CatalogException { query = new Query(ParamConstants.ACL_PARAM, ownerUser + ":" + SamplePermissions.DELETE.name()); thrown.expect(CatalogAuthorizationException.class); thrown.expectMessage("Only study owners or admins"); - sampleManager.search(studyFqn, query, options, memberSessionId); + sampleManager.search(organizationId, studyFqn, query, options, memberSessionId); } @Test public void getAclsTest() throws CatalogException { StudyManager studyManager = catalogManager.getStudyManager(); - studyManager.createGroup(studyFqn, "group1", Collections.singletonList(externalUser), ownerSessionId); - studyManager.createGroup(studyFqn, "group2", Collections.singletonList(externalUser), ownerSessionId); + studyManager.createGroup(organizationId, studyFqn, "group1", Collections.singletonList(externalUser), ownerSessionId); + studyManager.createGroup(organizationId, studyFqn, "group2", Collections.singletonList(externalUser), ownerSessionId); - studyManager.updateAcl(Collections.singletonList(studyFqn), "@group1", + studyManager.updateAcl(organizationId, Collections.singletonList(studyFqn), "@group1", new StudyAclParams(StudyPermissions.Permissions.VIEW_COHORTS.name(), ""), ADD, ownerSessionId); - studyManager.updateAcl(Collections.singletonList(studyFqn), externalUser, + studyManager.updateAcl(organizationId, Collections.singletonList(studyFqn), externalUser, new StudyAclParams(StudyPermissions.Permissions.VIEW_FILES.name(), ""), ADD, ownerSessionId); - OpenCGAResult> acls = studyManager.getAcls(Collections.singletonList(studyFqn), externalUser, false, + OpenCGAResult> acls = studyManager.getAcls(organizationId, Collections.singletonList(studyFqn), externalUser, false, externalSessionId); assertEquals(1, acls.getNumResults()); assertEquals(1, acls.first().getAcl().size()); @@ -966,9 +966,9 @@ public void getAclsTest() throws CatalogException { assertEquals(1, acls.first().getAcl().get(0).getGroups().stream().filter(g -> "@group1".equals(g.getId())).count()); // assertTrue(acls.first().keySet().containsAll(Arrays.asList(externalUser, "@group1"))); - studyManager.updateAcl(Collections.singletonList(studyFqn), "@group2", + studyManager.updateAcl(organizationId, Collections.singletonList(studyFqn), "@group2", new StudyAclParams(StudyPermissions.Permissions.VIEW_SAMPLES.name(), ""), ADD, ownerSessionId); - acls = studyManager.getAcls(Collections.singletonList(studyFqn), externalUser, false, + acls = studyManager.getAcls(organizationId, Collections.singletonList(studyFqn), externalUser, false, externalSessionId); assertEquals(1, acls.getNumResults()); assertEquals(1, acls.first().getAcl().size()); @@ -994,8 +994,8 @@ public void getAclsTest() throws CatalogException { @Test public void readCohort() throws CatalogException { - assertEquals(1, catalogManager.getCohortManager().search(studyFqn, new Query(), null, ownerSessionId).getNumResults()); - assertEquals(0, catalogManager.getCohortManager().search(studyFqn, new Query(), null, externalSessionId).getNumResults()); + assertEquals(1, catalogManager.getCohortManager().search(organizationId, studyFqn, new Query(), null, ownerSessionId).getNumResults()); + assertEquals(0, catalogManager.getCohortManager().search(organizationId, studyFqn, new Query(), null, externalSessionId).getNumResults()); } /*--------------------------*/ @@ -1004,25 +1004,25 @@ public void readCohort() throws CatalogException { @Test public void readIndividualByReadingSomeSample() throws CatalogException { - catalogManager.getIndividualManager().get(null, ind1, null, memberSessionId); + catalogManager.getIndividualManager().get(organizationId, null, ind1, null, memberSessionId); } @Test public void readIndividualForbidden() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); - catalogManager.getIndividualManager().get(null, ind2, null, externalSessionId); + catalogManager.getIndividualManager().get(organizationId, null, ind2, null, externalSessionId); } @Test public void readIndividualStudyManager() throws CatalogException { - catalogManager.getIndividualManager().get(null, ind2, null, studyAdmin1SessionId); + catalogManager.getIndividualManager().get(organizationId, null, ind2, null, studyAdmin1SessionId); } @Test public void readAllIndividuals() throws CatalogException { - assertEquals(2, catalogManager.getIndividualManager().search(studyFqn, new Query(), null, ownerSessionId).getNumResults()); - assertEquals(2, catalogManager.getIndividualManager().search(studyFqn, new Query(), null, studyAdmin1SessionId).getNumResults()); - assertEquals(0, catalogManager.getIndividualManager().search(studyFqn, new Query(), null, externalSessionId).getNumResults()); + assertEquals(2, catalogManager.getIndividualManager().search(organizationId, studyFqn, new Query(), null, ownerSessionId).getNumResults()); + assertEquals(2, catalogManager.getIndividualManager().search(organizationId, studyFqn, new Query(), null, studyAdmin1SessionId).getNumResults()); + assertEquals(0, catalogManager.getIndividualManager().search(organizationId, studyFqn, new Query(), null, externalSessionId).getNumResults()); } /*--------------------------*/ @@ -1034,16 +1034,16 @@ public void getAllJobs() throws CatalogException { Job job = new Job() .setId("job1") .setOutDir(new File().setPath(data_d1_d2)); - long job1 = catalogManager.getJobManager().create(studyFqn, job, INCLUDE_RESULT, ownerSessionId).first().getUid(); + long job1 = catalogManager.getJobManager().create(organizationId, studyFqn, job, INCLUDE_RESULT, ownerSessionId).first().getUid(); job.setId("job2"); - long job2 = catalogManager.getJobManager().create(studyFqn, job, INCLUDE_RESULT, ownerSessionId).first().getUid(); + long job2 = catalogManager.getJobManager().create(organizationId, studyFqn, job, INCLUDE_RESULT, ownerSessionId).first().getUid(); job.setId("job3"); - long job3 = catalogManager.getJobManager().create(studyFqn, job, INCLUDE_RESULT, ownerSessionId).first().getUid(); + long job3 = catalogManager.getJobManager().create(organizationId, studyFqn, job, INCLUDE_RESULT, ownerSessionId).first().getUid(); job.setId("job4"); - long job4 = catalogManager.getJobManager().create(studyFqn, job, INCLUDE_RESULT, ownerSessionId).first().getUid(); + long job4 = catalogManager.getJobManager().create(organizationId, studyFqn, job, INCLUDE_RESULT, ownerSessionId).first().getUid(); checkGetAllJobs(Arrays.asList(job1, job2, job3, job4), ownerSessionId); //Owner can see everything @@ -1051,7 +1051,7 @@ public void getAllJobs() throws CatalogException { } private void checkGetAllJobs(Collection expectedJobs, String sessionId) throws CatalogException { - DataResult allJobs = catalogManager.getJobManager().search(studyFqn, null, null, sessionId); + DataResult allJobs = catalogManager.getJobManager().search(organizationId, studyFqn, null, null, sessionId); assertEquals(expectedJobs.size(), allJobs.getNumResults()); allJobs.getResults().forEach(job -> assertTrue(expectedJobs + " does not contain job " + job.getId(), expectedJobs.contains(job @@ -1060,7 +1060,7 @@ private void checkGetAllJobs(Collection expectedJobs, String sessionId) th /////////// Aux methods private Map getGroupMap() throws CatalogException { - return catalogManager.getStudyManager().get(studyFqn, null, ownerSessionId).first().getGroups().stream() + return catalogManager.getStudyManager().get(organizationId, studyFqn, null, ownerSessionId).first().getGroups().stream() .collect(Collectors.toMap(Group::getId, f -> f)); } diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/AbstractClinicalManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/AbstractClinicalManagerTest.java index 58b08381342..be831ae14e6 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/AbstractClinicalManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/AbstractClinicalManagerTest.java @@ -92,7 +92,7 @@ public void setUpCatalogManager() throws IOException, CatalogException, URISynta null, null, null, token).first(); studyFqn = study.getFqn(); - family = catalogManager.getFamilyManager().create(studyFqn, getFamily(), QueryOptions.empty(), token).first(); + family = catalogManager.getFamilyManager().create(organizationId, studyFqn, getFamily(), QueryOptions.empty(), token).first(); // // Clinical analysis auxClinicalAnalysis = new ClinicalAnalysis() @@ -102,7 +102,7 @@ public void setUpCatalogManager() throws IOException, CatalogException, URISynta .setProband(getChild()) .setFamily(getFamily()); // - clinicalAnalysis = catalogManager.getClinicalAnalysisManager().create(studyFqn, auxClinicalAnalysis, + clinicalAnalysis = catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, auxClinicalAnalysis, new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), token) .first(); // @@ -112,7 +112,7 @@ public void setUpCatalogManager() throws IOException, CatalogException, URISynta // Clinical analysis for exomiser test (SINGLE, manuel) //--------------------------------------------------------------------- - catalogManager.getIndividualManager().create(studyFqn, getMamuel(), QueryOptions.empty(), token).first(); + catalogManager.getIndividualManager().create(organizationId, studyFqn, getMamuel(), QueryOptions.empty(), token).first(); auxClinicalAnalysis = new ClinicalAnalysis() .setId(CA_ID2).setDescription("My description - exomiser").setType(ClinicalAnalysis.Type.SINGLE) @@ -121,7 +121,7 @@ public void setUpCatalogManager() throws IOException, CatalogException, URISynta .setProband(getMamuel()); clinicalAnalysis2 = catalogManager.getClinicalAnalysisManager() - .create(studyFqn, auxClinicalAnalysis, new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), token) + .create(organizationId, studyFqn, auxClinicalAnalysis, new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), token) .first(); catalogUploadFile("/biofiles/exomiser.vcf.gz"); @@ -157,7 +157,7 @@ public void setUpCatalogManager() throws IOException, CatalogException, URISynta Family chineseFamily = new Family("chinese_family", "chinese_family", null, null, Arrays.asList(hg005Individual, hg006Individual, hg007Individual, hg004Individual), "", 4, Collections.emptyList(), Collections.emptyMap()); - catalogManager.getFamilyManager().create(studyFqn, chineseFamily, QueryOptions.empty(), token).first(); + catalogManager.getFamilyManager().create(organizationId, studyFqn, chineseFamily, QueryOptions.empty(), token).first(); auxClinicalAnalysis = new ClinicalAnalysis() .setId(CA_ID3) @@ -168,7 +168,7 @@ public void setUpCatalogManager() throws IOException, CatalogException, URISynta .setProband(hg005Individual) .setFamily(chineseFamily); - catalogManager.getClinicalAnalysisManager().create(studyFqn, auxClinicalAnalysis, QueryOptions.empty(), token) + catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, auxClinicalAnalysis, QueryOptions.empty(), token) .first(); catalogUploadFile("/biofiles/HG004.1k.vcf.gz"); diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/AbstractManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/AbstractManagerTest.java index e71696593d8..bc23e333644 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/AbstractManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/AbstractManagerTest.java @@ -144,7 +144,7 @@ public void setUpCatalogManager(CatalogManager catalogManager) throws IOExceptio .setType(File.Type.FILE), false, token); - File fileTest1k = catalogManager.getFileManager().get(studyFqn, queryResult2.first().getPath(), INCLUDE_RESULT, token).first(); + File fileTest1k = catalogManager.getFileManager().get(organizationId, studyFqn, queryResult2.first().getPath(), INCLUDE_RESULT, token).first(); attributes = new ObjectMap(); attributes.put("field", "value"); attributes.put("name", "fileTest1k"); @@ -162,7 +162,7 @@ public void setUpCatalogManager(CatalogManager catalogManager) throws IOExceptio .setType(File.Type.FILE), false, token); - File fileTest05k = catalogManager.getFileManager().get(studyFqn, queryResult1.first().getPath(), INCLUDE_RESULT, token).first(); + File fileTest05k = catalogManager.getFileManager().get(organizationId, studyFqn, queryResult1.first().getPath(), INCLUDE_RESULT, token).first(); attributes = new ObjectMap(); attributes.put("field", "valuable"); attributes.put("name", "fileTest05k"); @@ -179,7 +179,7 @@ public void setUpCatalogManager(CatalogManager catalogManager) throws IOExceptio .setType(File.Type.FILE), false, token); - File test01k = catalogManager.getFileManager().get(studyFqn, queryResult.first().getPath(), INCLUDE_RESULT, token).first(); + File test01k = catalogManager.getFileManager().get(organizationId, studyFqn, queryResult.first().getPath(), INCLUDE_RESULT, token).first(); attributes = new ObjectMap(); attributes.put("field", "other"); attributes.put("name", "test01k"); @@ -203,52 +203,52 @@ public void setUpCatalogManager(CatalogManager catalogManager) throws IOExceptio new Variable("EXTRA", "", "", Variable.VariableType.STRING, "", false, false, Collections.emptyList(), null, 5, "", "", null, Collections.emptyMap()) )); - VariableSet vs = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs", "vs", true, false, "", null, variables, + VariableSet vs = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs", "vs", true, false, "", null, variables, null, token).first(); Sample sample = new Sample().setId("s_1"); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot1", vs.getId(), new ObjectMap("NAME", "s_1").append("AGE", 6).append("ALIVE", true).append("PHEN", "CONTROL")))); - s_1 = catalogManager.getSampleManager().create(studyFqn, sample, INCLUDE_RESULT, token).first().getId(); + s_1 = catalogManager.getSampleManager().create(organizationId, studyFqn, sample, INCLUDE_RESULT, token).first().getId(); sample.setId("s_2"); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot1", vs.getId(), new ObjectMap("NAME", "s_2").append("AGE", 10).append("ALIVE", false).append("PHEN", "CASE")))); - s_2 = catalogManager.getSampleManager().create(studyFqn, sample, INCLUDE_RESULT, token).first().getId(); + s_2 = catalogManager.getSampleManager().create(organizationId, studyFqn, sample, INCLUDE_RESULT, token).first().getId(); sample.setId("s_3"); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot1", vs.getId(), new ObjectMap("NAME", "s_3").append("AGE", 15).append("ALIVE", true).append("PHEN", "CONTROL")))); - s_3 = catalogManager.getSampleManager().create(studyFqn, sample, INCLUDE_RESULT, token).first().getId(); + s_3 = catalogManager.getSampleManager().create(organizationId, studyFqn, sample, INCLUDE_RESULT, token).first().getId(); sample.setId("s_4"); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot1", vs.getId(), new ObjectMap("NAME", "s_4").append("AGE", 22).append("ALIVE", false).append("PHEN", "CONTROL")))); - s_4 = catalogManager.getSampleManager().create(studyFqn, sample, INCLUDE_RESULT, token).first().getId(); + s_4 = catalogManager.getSampleManager().create(organizationId, studyFqn, sample, INCLUDE_RESULT, token).first().getId(); sample.setId("s_5"); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot1", vs.getId(), new ObjectMap("NAME", "s_5").append("AGE", 29).append("ALIVE", true).append("PHEN", "CASE")))); - s_5 = catalogManager.getSampleManager().create(studyFqn, sample, INCLUDE_RESULT, token).first().getId(); + s_5 = catalogManager.getSampleManager().create(organizationId, studyFqn, sample, INCLUDE_RESULT, token).first().getId(); sample.setId("s_6"); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot2", vs.getId(), new ObjectMap("NAME", "s_6").append("AGE", 38).append("ALIVE", true).append("PHEN", "CONTROL")))); - s_6 = catalogManager.getSampleManager().create(studyFqn, sample, INCLUDE_RESULT, token).first().getId(); + s_6 = catalogManager.getSampleManager().create(organizationId, studyFqn, sample, INCLUDE_RESULT, token).first().getId(); sample.setId("s_7"); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot2", vs.getId(), new ObjectMap("NAME", "s_7").append("AGE", 46).append("ALIVE", false).append("PHEN", "CASE")))); - s_7 = catalogManager.getSampleManager().create(studyFqn, sample, INCLUDE_RESULT, token).first().getId(); + s_7 = catalogManager.getSampleManager().create(organizationId, studyFqn, sample, INCLUDE_RESULT, token).first().getId(); sample.setId("s_8"); sample.setAnnotationSets(Collections.singletonList(new AnnotationSet("annot2", vs.getId(), new ObjectMap("NAME", "s_8").append("AGE", 72).append("ALIVE", true).append("PHEN", "CONTROL")))); - s_8 = catalogManager.getSampleManager().create(studyFqn, sample, INCLUDE_RESULT, token).first().getId(); + s_8 = catalogManager.getSampleManager().create(organizationId, studyFqn, sample, INCLUDE_RESULT, token).first().getId(); sample.setId("s_9"); sample.setAnnotationSets(Collections.emptyList()); - s_9 = catalogManager.getSampleManager().create(studyFqn, sample, INCLUDE_RESULT, token).first().getId(); + s_9 = catalogManager.getSampleManager().create(organizationId, studyFqn, sample, INCLUDE_RESULT, token).first().getId(); catalogManager.getFileManager().update(studyFqn, test01k.getPath(), new FileUpdateParams() .setSampleIds(Arrays.asList(s_1, s_2, s_3, s_4, s_5)), INCLUDE_RESULT, token); diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/CatalogManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/CatalogManagerTest.java index 8e468806d04..8b60a419504 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/CatalogManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/CatalogManagerTest.java @@ -67,7 +67,7 @@ public class CatalogManagerTest extends AbstractManagerTest { @Test public void createStudyFailMoreThanOneProject() throws CatalogException { - catalogManager.getProjectManager().incrementRelease(project1, token); + catalogManager.getProjectManager().incrementRelease(organizationId, project1, token); catalogManager.getProjectManager().create("1000G2", "Project about some genomes", "", "Homo sapiens", null, "GRCh38", new QueryOptions(), token); @@ -141,7 +141,7 @@ public void testGetUserInfo() throws CatalogException { OpenCGAResult result = catalogManager.getUserManager().get("user2", new QueryOptions(), token); assertEquals(Event.Type.ERROR, result.getEvents().get(0).getType()); - catalogManager.getStudyManager().updateGroup(studyFqn, StudyManager.MEMBERS, ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, StudyManager.MEMBERS, ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("user2")), token); result = catalogManager.getUserManager().get("user2", new QueryOptions(), token); assertTrue(result.getEvents().isEmpty()); @@ -174,7 +174,7 @@ public void testUserInfoProjections() throws CatalogException { assertEquals(0, user.first().getSharedProjects().size()); // Grant permissions to user2 to access study of user1 - catalogManager.getStudyManager().updateGroup(studyFqn, StudyManager.MEMBERS, ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, StudyManager.MEMBERS, ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("user2")), token); options = new QueryOptions() @@ -279,9 +279,9 @@ private String getAdminToken() throws CatalogException, IOException { @Test public void getGroupsTest() throws CatalogException { Group group = new Group("groupId", Arrays.asList("user2", "user3")).setSyncedFrom(new Group.Sync("ldap", "bio")); - catalogManager.getStudyManager().createGroup(studyFqn, group, token); + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, group, token); - OpenCGAResult customGroups = catalogManager.getStudyManager().getCustomGroups(studyFqn, null, token); + OpenCGAResult customGroups = catalogManager.getStudyManager().getCustomGroups(organizationId, studyFqn, null, token); assertEquals(3, customGroups.getNumResults()); for (CustomGroup customGroup : customGroups.getResults()) { @@ -290,7 +290,7 @@ public void getGroupsTest() throws CatalogException { } } - customGroups = catalogManager.getStudyManager().getCustomGroups(studyFqn, group.getId(), token); + customGroups = catalogManager.getStudyManager().getCustomGroups(organizationId, studyFqn, group.getId(), token); assertEquals(1, customGroups.getNumResults()); assertEquals(group.getId(), customGroups.first().getId()); assertEquals(2, customGroups.first().getUsers().size()); @@ -300,7 +300,7 @@ public void getGroupsTest() throws CatalogException { thrown.expect(CatalogAuthorizationException.class); thrown.expectMessage("Only owners"); - catalogManager.getStudyManager().getCustomGroups(studyFqn, group.getId(), sessionIdUser2); + catalogManager.getStudyManager().getCustomGroups(organizationId, studyFqn, group.getId(), sessionIdUser2); } @Ignore @@ -318,18 +318,18 @@ public void importLdapUsers() throws CatalogException, NamingException, IOExcept public void loginNotRegisteredUsers() throws CatalogException { // Action only for admins Group group = new Group("ldap", Collections.emptyList()).setSyncedFrom(new Group.Sync("ldap", "bio")); - catalogManager.getStudyManager().createGroup(studyFqn, group, token); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), "@ldap", new StudyAclParams("", "view_only"), + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, group, token); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), "@ldap", new StudyAclParams("", "view_only"), ParamUtils.AclAction.SET, token); String token = catalogManager.getUserManager().login("user", "password").getToken(); - assertEquals(9, catalogManager.getSampleManager().count(studyFqn, new Query(), token).getNumTotalResults()); + assertEquals(9, catalogManager.getSampleManager().count(organizationId, studyFqn, new Query(), token).getNumTotalResults()); // We remove the permissions for group ldap - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), "@ldap", new StudyAclParams("", ""), + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), "@ldap", new StudyAclParams("", ""), ParamUtils.AclAction.RESET, this.token); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, new Query(), token).getNumTotalResults()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, new Query(), token).getNumTotalResults()); } @Ignore @@ -339,13 +339,13 @@ public void syncUsers() throws CatalogException { String token = catalogManager.getUserManager().loginAsAdmin("admin").getToken(); catalogManager.getUserManager().importRemoteGroupOfUsers("ldap", "bio", "bio", studyFqn, true, token); - DataResult bio = catalogManager.getStudyManager().getGroup(studyFqn, "bio", this.token); + DataResult bio = catalogManager.getStudyManager().getGroup(organizationId, studyFqn, "bio", this.token); assertEquals(1, bio.getNumResults()); assertEquals(0, bio.first().getUserIds().size()); catalogManager.getUserManager().syncAllUsersOfExternalGroup(studyFqn, "ldap", token); - bio = catalogManager.getStudyManager().getGroup(studyFqn, "bio", this.token); + bio = catalogManager.getStudyManager().getGroup(organizationId, studyFqn, "bio", this.token); assertEquals(1, bio.getNumResults()); assertTrue(!bio.first().getUserIds().isEmpty()); @@ -360,7 +360,7 @@ public void importLdapGroups() throws CatalogException, IOException { String study = "user@1000G:phase1"; catalogManager.getUserManager().importRemoteGroupOfUsers("ldap", remoteGroup, internalGroup, study, true, getAdminToken()); - DataResult test = catalogManager.getStudyManager().getGroup("user@1000G:phase1", "test", token); + DataResult test = catalogManager.getStudyManager().getGroup(organizationId, "user@1000G:phase1", "test", token); assertEquals(1, test.getNumResults()); assertEquals("@test", test.first().getId()); assertTrue(test.first().getUserIds().size() > 0); @@ -383,8 +383,8 @@ public void importLdapGroups() throws CatalogException, IOException { @Test public void createEmptyGroup() throws CatalogException { catalogManager.getUserManager().create("test", "test", "test@mail.com", TestParamConstants.PASSWORD, null, 100L, Account.AccountType.GUEST, opencgaToken); - catalogManager.getStudyManager().createGroup("user@1000G:phase1", "group_cancer_some_thing_else", null, token); - catalogManager.getStudyManager().updateGroup("user@1000G:phase1", "group_cancer_some_thing_else", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().createGroup(organizationId, "user@1000G:phase1", "group_cancer_some_thing_else", null, token); + catalogManager.getStudyManager().updateGroup(organizationId, "user@1000G:phase1", "group_cancer_some_thing_else", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("test")), token); } @@ -392,20 +392,20 @@ public void createEmptyGroup() throws CatalogException { public void testAssignPermissions() throws CatalogException { catalogManager.getUserManager().create("test", "test", "test@mail.com", TestParamConstants.PASSWORD, null, 100L, Account.AccountType.GUEST, opencgaToken); - catalogManager.getStudyManager().createGroup("user@1000G:phase1", "group_cancer_some_thing_else", + catalogManager.getStudyManager().createGroup(organizationId, "user@1000G:phase1", "group_cancer_some_thing_else", Collections.singletonList("test"), token); DataResult> permissions = catalogManager.getStudyManager().updateAcl( - Collections.singletonList("user@1000G:phase1"), "@group_cancer_some_thing_else", + organizationId, Collections.singletonList("user@1000G:phase1"), "@group_cancer_some_thing_else", new StudyAclParams("", "view_only"), ParamUtils.AclAction.SET, token); assertEquals("@group_cancer_some_thing_else", permissions.first().getAcl().get(0).getMember()); assertFalse(permissions.first().getAcl().get(0).getPermissions().isEmpty()); String token = catalogManager.getUserManager().login("test", TestParamConstants.PASSWORD).getToken(); - DataResult studyDataResult = catalogManager.getStudyManager().get("user@1000G:phase1", QueryOptions.empty(), token); + DataResult studyDataResult = catalogManager.getStudyManager().get(organizationId, "user@1000G:phase1", QueryOptions.empty(), token); assertEquals(1, studyDataResult.getNumResults()); assertTrue(studyDataResult.first().getAttributes().isEmpty()); - studyDataResult = catalogManager.getStudyManager().get("user@1000G:phase1", new QueryOptions(DBAdaptor.INCLUDE_ACLS, true), token); + studyDataResult = catalogManager.getStudyManager().get(organizationId, "user@1000G:phase1", new QueryOptions(DBAdaptor.INCLUDE_ACLS, true), token); assertEquals(1, studyDataResult.getNumResults()); assertTrue(!studyDataResult.first().getAttributes().isEmpty()); assertTrue(studyDataResult.first().getAttributes().containsKey("OPENCGA_ACL")); @@ -422,10 +422,10 @@ public void testAssignPermissions() throws CatalogException { @Test public void testGetAllProjects() throws Exception { Query query = new Query(ProjectDBAdaptor.QueryParams.USER_ID.key(), "user"); - DataResult projects = catalogManager.getProjectManager().search(query, null, token); + DataResult projects = catalogManager.getProjectManager().search(organizationId, query, null, token); assertEquals(1, projects.getNumResults()); - projects = catalogManager.getProjectManager().search(query, null, sessionIdUser2); + projects = catalogManager.getProjectManager().search(organizationId, query, null, sessionIdUser2); assertEquals(0, projects.getNumResults()); } @@ -456,8 +456,8 @@ public void testModifyProject() throws CatalogException { attributes.put("object", new ObjectMap("id", 1234)); options.put("attributes", attributes); - catalogManager.getProjectManager().update(projectId, options, null, token); - DataResult result = catalogManager.getProjectManager().get(projectId, null, token); + catalogManager.getProjectManager().update(organizationId, projectId, options, null, token); + DataResult result = catalogManager.getProjectManager().get(organizationId, projectId, null, token); Project project = result.first(); System.out.println(result); @@ -469,32 +469,32 @@ public void testModifyProject() throws CatalogException { options = new ObjectMap(); options.put(ProjectDBAdaptor.QueryParams.CREATION_DATE.key(), "20180101120000"); - catalogManager.getProjectManager().update(projectId, options, null, token); - project = catalogManager.getProjectManager().get(projectId, null, token).first(); + catalogManager.getProjectManager().update(organizationId, projectId, options, null, token); + project = catalogManager.getProjectManager().get(organizationId, projectId, null, token).first(); assertEquals("20180101120000", project.getCreationDate()); options = new ObjectMap(); options.put(ProjectDBAdaptor.QueryParams.ID.key(), "newProjectId"); - catalogManager.getProjectManager().update(projectId, options, null, token); + catalogManager.getProjectManager().update(organizationId, projectId, options, null, token); thrown.expect(CatalogException.class); thrown.expectMessage("not found"); - catalogManager.getProjectManager().update(projectId, options, null, token); + catalogManager.getProjectManager().update(organizationId, projectId, options, null, token); } @Test public void testLimitProjects() throws CatalogException { for (int i = 0; i < 20; i++) { - catalogManager.getProjectManager().create(new ProjectCreateParams() + catalogManager.getProjectManager().create(organizationId, new ProjectCreateParams() .setId("project_" + i) .setOrganism(new ProjectOrganism("hsapiens", "grch38")), QueryOptions.empty(), token); for (int j = 0; j < 2; j++) { - catalogManager.getStudyManager().create("project_" + i, new Study().setId("study_" + i + "_" + j), QueryOptions.empty(), + catalogManager.getStudyManager().create(organizationId, "project_" + i, new Study().setId("study_" + i + "_" + j), QueryOptions.empty(), token); } } - OpenCGAResult results = catalogManager.getProjectManager().search(new Query(), new QueryOptions(QueryOptions.LIMIT, 10), + OpenCGAResult results = catalogManager.getProjectManager().search(organizationId, new Query(), new QueryOptions(QueryOptions.LIMIT, 10), token); assertEquals(10, results.getNumResults()); } @@ -506,7 +506,7 @@ public void testLimitProjects() throws CatalogException { @Test public void testModifyStudy() throws Exception { Query query = new Query(StudyDBAdaptor.QueryParams.OWNER.key(), "user"); - String studyId = catalogManager.getStudyManager().search(query, null, token).first().getId(); + String studyId = catalogManager.getStudyManager().search(organizationId, query, null, token).first().getId(); String newName = "Phase 1 " + RandomStringUtils.randomAlphanumeric(20); String newDescription = RandomStringUtils.randomAlphanumeric(500); @@ -517,9 +517,9 @@ public void testModifyStudy() throws Exception { .setName(newName) .setDescription(newDescription) .setAttributes(attributes); - catalogManager.getStudyManager().update(studyId, updateParams, null, token); + catalogManager.getStudyManager().update(organizationId, studyId, updateParams, null, token); - DataResult result = catalogManager.getStudyManager().get(studyId, null, token); + DataResult result = catalogManager.getStudyManager().get(organizationId, studyId, null, token); System.out.println(result); Study study = result.first(); assertEquals(study.getName(), newName); @@ -529,16 +529,16 @@ public void testModifyStudy() throws Exception { } assertNotEquals("20180101120000", study.getCreationDate()); - catalogManager.getStudyManager().update(studyId, new StudyUpdateParams().setCreationDate("20180101120000"), null, token); - study = catalogManager.getStudyManager().get(studyId, null, token).first(); + catalogManager.getStudyManager().update(organizationId, studyId, new StudyUpdateParams().setCreationDate("20180101120000"), null, token); + study = catalogManager.getStudyManager().get(organizationId, studyId, null, token).first(); assertEquals("20180101120000", study.getCreationDate()); } @Test public void testGetAllStudies() throws CatalogException { Query query = new Query(ProjectDBAdaptor.QueryParams.USER_ID.key(), "user"); - String projectId = catalogManager.getProjectManager().search(query, null, token).first().getId(); - Study study_1 = catalogManager.getStudyManager().create(projectId, new Study().setId("study_1").setCreationDate("20150101120000") + String projectId = catalogManager.getProjectManager().search(organizationId, query, null, token).first().getId(); + Study study_1 = catalogManager.getStudyManager().create(organizationId, projectId, new Study().setId("study_1").setCreationDate("20150101120000") , null, token).first(); assertEquals("20150101120000", study_1.getCreationDate()); @@ -549,27 +549,27 @@ public void testGetAllStudies() throws CatalogException { String study_4 = catalogManager.getStudyManager().create(projectId, "study_4", null, "study_4", "description", null, null, null, null, null, token).first().getId(); - assertEquals(new HashSet<>(Collections.emptyList()), catalogManager.getStudyManager().search(new Query(StudyDBAdaptor.QueryParams + assertEquals(new HashSet<>(Collections.emptyList()), catalogManager.getStudyManager().search(organizationId, new Query(StudyDBAdaptor.QueryParams .GROUP_USER_IDS.key(), "user2"), null, token).getResults().stream().map(Study::getId) .collect(Collectors.toSet())); // catalogManager.getStudyManager().createGroup(Long.toString(study_4), "admins", "user3", sessionIdUser); - catalogManager.getStudyManager().updateGroup(study_4, "admins", ParamUtils.BasicUpdateAction.SET, + catalogManager.getStudyManager().updateGroup(organizationId, study_4, "admins", ParamUtils.BasicUpdateAction.SET, new GroupUpdateParams(Collections.singletonList("user3")), token); - assertEquals(new HashSet<>(Arrays.asList("study_4")), catalogManager.getStudyManager().search(new Query(StudyDBAdaptor.QueryParams + assertEquals(new HashSet<>(Arrays.asList("study_4")), catalogManager.getStudyManager().search(organizationId, new Query(StudyDBAdaptor.QueryParams .GROUP_USER_IDS.key(), "user3"), null, token).getResults().stream().map(Study::getId) .collect(Collectors.toSet())); assertEquals(new HashSet<>(Arrays.asList("phase1", "phase3", "study_1", "study_2", "study_3", "study_4")), - catalogManager.getStudyManager().search(new Query(StudyDBAdaptor.QueryParams.PROJECT_ID.key(), projectId), null, token) + catalogManager.getStudyManager().search(organizationId, new Query(StudyDBAdaptor.QueryParams.PROJECT_ID.key(), projectId), null, token) .getResults().stream().map(Study::getId).collect(Collectors.toSet())); assertEquals(new HashSet<>(Arrays.asList("phase1", "phase3", "study_1", "study_2", "study_3", "study_4")), - catalogManager.getStudyManager().search(new Query(), null, token).getResults().stream().map(Study::getId) + catalogManager.getStudyManager().search(organizationId, new Query(), null, token).getResults().stream().map(Study::getId) .collect(Collectors.toSet())); - assertEquals(new HashSet<>(Arrays.asList("study_1", "study_2", "study_3", "study_4")), catalogManager.getStudyManager().search(new + assertEquals(new HashSet<>(Arrays.asList("study_1", "study_2", "study_3", "study_4")), catalogManager.getStudyManager().search(organizationId, new Query(StudyDBAdaptor.QueryParams.ID.key(), "~^study"), null, token).getResults().stream() .map(Study::getId).collect(Collectors.toSet())); - assertEquals(Collections.singleton("s1"), catalogManager.getStudyManager().search(new Query(), null, sessionIdUser2).getResults() + assertEquals(Collections.singleton("s1"), catalogManager.getStudyManager().search(organizationId, new Query(), null, sessionIdUser2).getResults() .stream() .map(Study::getId).collect(Collectors.toSet())); } @@ -580,62 +580,62 @@ public void testGetId() throws CatalogException { catalogManager.getStudyManager().create(project2, "phase3", null, "Phase 3", "d", null, null, null, null, null, sessionIdUser2); String userId = catalogManager.getUserManager().getUserId(token); - List uids = catalogManager.getStudyManager().resolveIds(Arrays.asList("*"), userId) + List uids = catalogManager.getStudyManager().resolveIds(organizationId, Arrays.asList("*"), userId) .stream() .map(Study::getUid) .collect(Collectors.toList()); assertTrue(uids.contains(studyUid) && uids.contains(studyUid2)); - uids = catalogManager.getStudyManager().resolveIds(Collections.emptyList(), userId) + uids = catalogManager.getStudyManager().resolveIds(organizationId, Collections.emptyList(), userId) .stream() .map(Study::getUid) .collect(Collectors.toList()); assertTrue(uids.contains(studyUid) && uids.contains(studyUid2)); - uids = catalogManager.getStudyManager().resolveIds(Collections.emptyList(), userId) + uids = catalogManager.getStudyManager().resolveIds(organizationId, Collections.emptyList(), userId) .stream() .map(Study::getUid) .collect(Collectors.toList()); assertTrue(uids.contains(studyUid) && uids.contains(studyUid2)); - uids = catalogManager.getStudyManager().resolveIds(Arrays.asList("1000G:*"), userId) + uids = catalogManager.getStudyManager().resolveIds(organizationId, Arrays.asList("1000G:*"), userId) .stream() .map(Study::getUid) .collect(Collectors.toList()); assertTrue(uids.contains(studyUid) && uids.contains(studyUid2)); - uids = catalogManager.getStudyManager().resolveIds(Arrays.asList(userId + "@1000G:*"), userId) + uids = catalogManager.getStudyManager().resolveIds(organizationId, Arrays.asList(userId + "@1000G:*"), userId) .stream() .map(Study::getUid) .collect(Collectors.toList()); assertTrue(uids.contains(studyUid) && uids.contains(studyUid2)); - uids = catalogManager.getStudyManager().resolveIds(Arrays.asList(userId + "@1000G:phase1", userId + "@1000G:phase3"), userId) + uids = catalogManager.getStudyManager().resolveIds(organizationId, Arrays.asList(userId + "@1000G:phase1", userId + "@1000G:phase3"), userId) .stream() .map(Study::getUid) .collect(Collectors.toList()); assertTrue(uids.contains(studyUid) && uids.contains(studyUid2)); - uids = catalogManager.getStudyManager().resolveIds(Arrays.asList(userId + "@1000G:phase1", "phase3"), userId) + uids = catalogManager.getStudyManager().resolveIds(organizationId, Arrays.asList(userId + "@1000G:phase1", "phase3"), userId) .stream() .map(Study::getUid) .collect(Collectors.toList()); assertTrue(uids.contains(studyUid) && uids.contains(studyUid2)); - uids = catalogManager.getStudyManager().resolveIds(Arrays.asList(userId + "@1000G:phase3", studyFqn), userId) + uids = catalogManager.getStudyManager().resolveIds(organizationId, Arrays.asList(userId + "@1000G:phase3", studyFqn), userId) .stream() .map(Study::getUid) .collect(Collectors.toList()); assertTrue(uids.contains(studyUid) && uids.contains(studyUid2)); try { - catalogManager.getStudyManager().resolveId(null, userId); + catalogManager.getStudyManager().resolveId(organizationId, null, userId); fail("This method should fail because it should find several studies"); } catch (CatalogException e) { assertTrue(e.getMessage().contains("More than one study")); } - Study study = catalogManager.getStudyManager().resolveId("phase3", userId); + Study study = catalogManager.getStudyManager().resolveId(organizationId, "phase3", userId); assertEquals(studyUid2, study.getUid()); } @@ -644,7 +644,7 @@ public void testGetOnlyStudyUserAnonymousCanSee() throws CatalogException { StudyManager studyManager = catalogManager.getStudyManager(); try { - studyManager.resolveIds(Collections.emptyList(), "*"); + studyManager.resolveIds(organizationId, Collections.emptyList(), "*"); fail("This should throw an exception. No studies should be found for user anonymous"); } catch (CatalogException e) { } @@ -653,15 +653,15 @@ public void testGetOnlyStudyUserAnonymousCanSee() throws CatalogException { DataResult study = catalogManager.getStudyManager().create(String.valueOf(project2), "phase3", null, "Phase 3", "d", null, null, null, null, null, sessionIdUser2); try { - studyManager.resolveIds(Collections.emptyList(), "*"); + studyManager.resolveIds(organizationId, Collections.emptyList(), "*"); fail("This should throw an exception. No studies should be found for user anonymous"); } catch (CatalogException e) { } - catalogManager.getStudyManager().updateGroup("phase3", "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, "phase3", "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("*")), sessionIdUser2); - List studies = studyManager.resolveIds(Collections.emptyList(), "*"); + List studies = studyManager.resolveIds(organizationId, Collections.emptyList(), "*"); assertEquals(1, studies.size()); assertEquals(study.first().getUid(), studies.get(0).getUid()); } @@ -671,7 +671,7 @@ public void testGetSelectedStudyUserAnonymousCanSee() throws CatalogException { StudyManager studyManager = catalogManager.getStudyManager(); try { - studyManager.resolveIds(Collections.singletonList("phase3"), "*"); + studyManager.resolveIds(organizationId, Collections.singletonList("phase3"), "*"); fail("This should throw an exception. No studies should be found for user anonymous"); } catch (CatalogException e) { } @@ -679,10 +679,10 @@ public void testGetSelectedStudyUserAnonymousCanSee() throws CatalogException { // Create another study with alias phase3 DataResult study = catalogManager.getStudyManager().create(project2, "phase3", null, "Phase 3", "d", null, null, null, null, null, sessionIdUser2); - catalogManager.getStudyManager().updateGroup("phase3", "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, "phase3", "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("*")), sessionIdUser2); - List studies = studyManager.resolveIds(Collections.singletonList("phase3"), "*"); + List studies = studyManager.resolveIds(organizationId, Collections.singletonList("phase3"), "*"); assertEquals(1, studies.size()); assertEquals(study.first().getUid(), studies.get(0).getUid()); } @@ -692,7 +692,7 @@ public void testCreatePermissionRules() throws CatalogException { PermissionRule rules = new PermissionRule("rules1", new Query("a", "b"), Arrays.asList("user2", "user3"), Arrays.asList(SamplePermissions.VIEW.name(), SamplePermissions.WRITE.name())); DataResult permissionRulesDataResult = catalogManager.getStudyManager().createPermissionRule( - studyFqn, Enums.Entity.SAMPLES, rules, token); + organizationId, studyFqn, Enums.Entity.SAMPLES, rules, token); assertEquals(1, permissionRulesDataResult.getNumResults()); assertEquals("rules1", permissionRulesDataResult.first().getId()); assertEquals(1, permissionRulesDataResult.first().getQuery().size()); @@ -701,7 +701,7 @@ public void testCreatePermissionRules() throws CatalogException { // Add new permission rules object rules.setId("rules2"); - permissionRulesDataResult = catalogManager.getStudyManager().createPermissionRule(studyFqn, Enums.Entity.SAMPLES, rules, + permissionRulesDataResult = catalogManager.getStudyManager().createPermissionRule(organizationId, studyFqn, Enums.Entity.SAMPLES, rules, token); assertEquals(1, permissionRulesDataResult.getNumResults()); assertEquals(rules, permissionRulesDataResult.first()); @@ -713,7 +713,7 @@ public void testUpdatePermissionRulesIncorrectPermission() throws CatalogExcepti Arrays.asList("VV", "UPDATE")); thrown.expect(CatalogException.class); thrown.expectMessage("Detected unsupported"); - catalogManager.getStudyManager().createPermissionRule(studyFqn, Enums.Entity.SAMPLES, rules, token); + catalogManager.getStudyManager().createPermissionRule(organizationId, studyFqn, Enums.Entity.SAMPLES, rules, token); } @Test @@ -722,7 +722,7 @@ public void testUpdatePermissionRulesNonExistingUser() throws CatalogException { Arrays.asList(SamplePermissions.VIEW.name(), SamplePermissions.WRITE.name())); thrown.expect(CatalogException.class); thrown.expectMessage("does not exist"); - catalogManager.getStudyManager().createPermissionRule(studyFqn, Enums.Entity.SAMPLES, rules, token); + catalogManager.getStudyManager().createPermissionRule(organizationId, studyFqn, Enums.Entity.SAMPLES, rules, token); } @Test @@ -731,7 +731,7 @@ public void testUpdatePermissionRulesNonExistingGroup() throws CatalogException Arrays.asList(SamplePermissions.VIEW.name(), SamplePermissions.WRITE.name())); thrown.expect(CatalogException.class); thrown.expectMessage("not found"); - catalogManager.getStudyManager().createPermissionRule(studyFqn, Enums.Entity.SAMPLES, rules, token); + catalogManager.getStudyManager().createPermissionRule(organizationId, studyFqn, Enums.Entity.SAMPLES, rules, token); } @Test @@ -739,13 +739,13 @@ public void removeAllPermissionsToMember() throws CatalogException { StudyManager studyManager = catalogManager.getStudyManager(); // Assign permissions to study - DataResult groupDataResult = studyManager.updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + DataResult groupDataResult = studyManager.updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Arrays.asList("user2", "user3")), token); assertEquals(3, groupDataResult.first().getUserIds().size()); assertEquals("@members", groupDataResult.first().getId()); // Obtain all samples from study - DataResult sampleDataResult = catalogManager.getSampleManager().search(studyFqn, new Query(), QueryOptions + DataResult sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(), QueryOptions .empty(), token); assertTrue(sampleDataResult.getNumResults() > 0); @@ -769,7 +769,7 @@ public void removeAllPermissionsToMember() throws CatalogException { } // Remove all the permissions to both users in the study. That should also remove the permissions they had in all the samples. - groupDataResult = studyManager.updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.REMOVE, + groupDataResult = studyManager.updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.REMOVE, new GroupUpdateParams(Arrays.asList("user2", "user3")), token); assertEquals(1, groupDataResult.first().getUserIds().size()); @@ -797,13 +797,13 @@ public void removeUsersFromStudies() throws CatalogException { StudyManager studyManager = catalogManager.getStudyManager(); // Assign permissions to study - DataResult groupDataResult = studyManager.updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + DataResult groupDataResult = studyManager.updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Arrays.asList("user2", "user3")), token); assertEquals(3, groupDataResult.first().getUserIds().size()); assertEquals("@members", groupDataResult.first().getId()); // Obtain all samples from study - DataResult sampleDataResult = catalogManager.getSampleManager().search(studyFqn, new Query(), QueryOptions + DataResult sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(), QueryOptions .empty(), token); assertTrue(sampleDataResult.getNumResults() > 0); @@ -825,11 +825,11 @@ public void removeUsersFromStudies() throws CatalogException { SamplePermissions.WRITE))); } - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.REMOVE, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.REMOVE, new GroupUpdateParams(Arrays.asList("user2", "user3")), token); String userId1 = catalogManager.getUserManager().getUserId(token); - Study study3 = catalogManager.getStudyManager().resolveId(studyFqn, userId1); + Study study3 = catalogManager.getStudyManager().resolveId(organizationId, studyFqn, userId1); OpenCGAResult> studyAcl = catalogManager.getAuthorizationManager() .getStudyAcl(userId1, study3.getUid(), "user2"); @@ -838,14 +838,14 @@ public void removeUsersFromStudies() throws CatalogException { assertEquals("user2", studyAcl.first().getAcl().get(0).getMember()); assertNull(studyAcl.first().getAcl().get(0).getPermissions()); String userId = catalogManager.getUserManager().getUserId(token); - Study study1 = catalogManager.getStudyManager().resolveId(studyFqn, userId); + Study study1 = catalogManager.getStudyManager().resolveId(organizationId, studyFqn, userId); studyAcl = catalogManager.getAuthorizationManager().getStudyAcl(userId, study1.getUid(), "user3"); assertEquals(1, studyAcl.getNumResults()); assertEquals(1, studyAcl.first().getAcl().size()); assertEquals("user3", studyAcl.first().getAcl().get(0).getMember()); assertNull(studyAcl.first().getAcl().get(0).getPermissions()); - groupDataResult = catalogManager.getStudyManager().getGroup(studyFqn, null, token); + groupDataResult = catalogManager.getStudyManager().getGroup(organizationId, studyFqn, null, token); for (Group group : groupDataResult.getResults()) { assertTrue(!group.getUserIds().contains("user2")); assertTrue(!group.getUserIds().contains("user3")); @@ -875,31 +875,31 @@ public void removeUsersFromStudies() throws CatalogException { @Test public void testCreateJob() throws CatalogException { Query query = new Query(StudyDBAdaptor.QueryParams.OWNER.key(), "user"); - String studyId = catalogManager.getStudyManager().search(query, null, token).first().getId(); + String studyId = catalogManager.getStudyManager().search(organizationId, query, null, token).first().getId(); catalogManager.getJobManager().submit(studyId, "command-subcommand", null, Collections.emptyMap(), token); catalogManager.getJobManager().submit(studyId, "command-subcommand2", null, Collections.emptyMap(), token); - catalogManager.getJobManager().create(studyId, + catalogManager.getJobManager().create(organizationId, studyId, new Job().setId("job1").setInternal(new JobInternal(new Enums.ExecutionStatus(Enums.ExecutionStatus.DONE))), QueryOptions.empty(), token); - catalogManager.getJobManager().create(studyId, + catalogManager.getJobManager().create(organizationId, studyId, new Job().setId("job2").setInternal(new JobInternal(new Enums.ExecutionStatus(Enums.ExecutionStatus.ERROR))), QueryOptions.empty(), token); - catalogManager.getJobManager().create(studyId, + catalogManager.getJobManager().create(organizationId, studyId, new Job().setId("job3").setInternal(new JobInternal(new Enums.ExecutionStatus(Enums.ExecutionStatus.UNREGISTERED))), QueryOptions.empty(), token); query = new Query(JobDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), Enums.ExecutionStatus.PENDING); - DataResult unfinishedJobs = catalogManager.getJobManager().search(String.valueOf(studyId), query, null, token); + DataResult unfinishedJobs = catalogManager.getJobManager().search(organizationId, String.valueOf(studyId), query, null, token); assertEquals(2, unfinishedJobs.getNumResults()); - DataResult allJobs = catalogManager.getJobManager().search(String.valueOf(studyId), (Query) null, null, token); + DataResult allJobs = catalogManager.getJobManager().search(organizationId, String.valueOf(studyId), (Query) null, null, token); assertEquals(5, allJobs.getNumResults()); thrown.expectMessage("status different"); thrown.expect(CatalogException.class); - catalogManager.getJobManager().create(studyId, + catalogManager.getJobManager().create(organizationId, studyId, new Job().setId("job5").setInternal(new JobInternal(new Enums.ExecutionStatus(Enums.ExecutionStatus.PENDING))), QueryOptions.empty(), token); } @@ -914,9 +914,9 @@ public void testCreateJobAndReuse() throws CatalogException { String project2 = catalogManager.getProjectManager().create("testCreateJobAndReuse_project2", "", "", "Homo sapiens", null, "GRCh38", INCLUDE_RESULT, token).first().getId(); - String study1 = catalogManager.getStudyManager().create(project1, new Study() + String study1 = catalogManager.getStudyManager().create(organizationId, project1, new Study() .setId("studyWithDuplicatedID"), INCLUDE_RESULT, token).first().getUuid(); - String study2 = catalogManager.getStudyManager().create(project2, new Study() + String study2 = catalogManager.getStudyManager().create(organizationId, project2, new Study() .setId("studyWithDuplicatedID"), INCLUDE_RESULT, token).first().getUuid(); // catalogManager.getConfiguration().getAnalysis().getExecution().getOptions() @@ -964,12 +964,12 @@ public void submitJobWithDependenciesFromDifferentStudies() throws CatalogExcept @Test public void testGetAllJobs() throws CatalogException { Query query = new Query(StudyDBAdaptor.QueryParams.OWNER.key(), "user"); - String studyId = catalogManager.getStudyManager().search(query, null, token).first().getId(); + String studyId = catalogManager.getStudyManager().search(organizationId, query, null, token).first().getId(); - catalogManager.getJobManager().create(studyId, new Job().setId("myErrorJob"), null, token); + catalogManager.getJobManager().create(organizationId, studyId, new Job().setId("myErrorJob"), null, token); QueryOptions options = new QueryOptions(QueryOptions.COUNT, true); - DataResult allJobs = catalogManager.getJobManager().search(studyId, null, options, token); + DataResult allJobs = catalogManager.getJobManager().search(organizationId, studyId, null, options, token); assertEquals(1, allJobs.getNumMatches()); assertEquals(1, allJobs.getNumResults()); @@ -978,12 +978,12 @@ public void testGetAllJobs() throws CatalogException { @Test public void testJobsTop() throws CatalogException { Query query = new Query(StudyDBAdaptor.QueryParams.OWNER.key(), "user"); - List studies = catalogManager.getStudyManager().search(query, null, token).getResults(); + List studies = catalogManager.getStudyManager().search(organizationId, query, null, token).getResults(); System.out.println(studies.size()); for (int i = 99; i > 0; i--) { String studyId = studies.get(i % studies.size()).getId(); - String id = catalogManager.getJobManager().create(studyId, new Job().setId("myJob-" + i), INCLUDE_RESULT, token).first().getId(); + String id = catalogManager.getJobManager().create(organizationId, studyId, new Job().setId("myJob-" + i), INCLUDE_RESULT, token).first().getId(); String status; switch (i % 3) { case 0: @@ -1042,7 +1042,7 @@ public void submitJobWithDependencies() throws CatalogException { @Test public void submitJobFromAdminsGroup() throws CatalogException { // Add user to admins group - catalogManager.getStudyManager().updateGroup(studyFqn, "@admins", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@admins", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("user3")), token); OpenCGAResult job = catalogManager.getJobManager().submit(studyFqn, "variant-index", Enums.Priority.MEDIUM, new ObjectMap(), @@ -1056,10 +1056,10 @@ public void submitJobFromAdminsGroup() throws CatalogException { public void submitJobWithoutPermissions() throws CatalogException { // Check there are no ABORTED jobs Query query = new Query(JobDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), Enums.ExecutionStatus.ABORTED); - assertEquals(0, catalogManager.getJobManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getJobManager().count(organizationId, studyFqn, query, token).getNumMatches()); // Grant view permissions, but no EXECUTION permission - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), "user3", + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), "user3", new StudyAclParams("", ""), ParamUtils.AclAction.SET, token); try { @@ -1070,7 +1070,7 @@ public void submitJobWithoutPermissions() throws CatalogException { } // The previous execution should have created an ABORTED job - OpenCGAResult search = catalogManager.getJobManager().search(studyFqn, query, null, token); + OpenCGAResult search = catalogManager.getJobManager().search(organizationId, studyFqn, query, null, token); assertEquals(1, search.getNumResults()); assertEquals("variant-index", search.first().getTool().getId()); } @@ -1079,10 +1079,10 @@ public void submitJobWithoutPermissions() throws CatalogException { public void submitJobWithPermissions() throws CatalogException { // Check there are no ABORTED jobs Query query = new Query(JobDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), Enums.ExecutionStatus.ABORTED); - assertEquals(0, catalogManager.getJobManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getJobManager().count(organizationId, studyFqn, query, token).getNumMatches()); // Grant view permissions, but no EXECUTION permission - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), "user3", + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), "user3", new StudyAclParams(StudyPermissions.Permissions.EXECUTE_JOBS.name(), AuthorizationManager.ROLE_VIEW_ONLY), ParamUtils.AclAction.SET, token); OpenCGAResult search = catalogManager.getJobManager().submit(studyFqn, "variant-index", Enums.Priority.MEDIUM, new ObjectMap(), @@ -1094,7 +1094,7 @@ public void submitJobWithPermissions() throws CatalogException { @Test public void deleteJobTest() throws CatalogException { // Grant view permissions, but no EXECUTION permission - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), "user3", + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), "user3", new StudyAclParams(StudyPermissions.Permissions.EXECUTE_JOBS.name(), AuthorizationManager.ROLE_VIEW_ONLY), ParamUtils.AclAction.SET, token); OpenCGAResult search = catalogManager.getJobManager().submit(studyFqn, "variant-index", Enums.Priority.MEDIUM, new ObjectMap(), @@ -1104,7 +1104,7 @@ public void deleteJobTest() throws CatalogException { thrown.expect(CatalogException.class); thrown.expectMessage("stop the job"); - catalogManager.getJobManager().delete(studyFqn, Collections.singletonList(search.first().getId()), QueryOptions.empty(), token); + catalogManager.getJobManager().delete(organizationId, studyFqn, Collections.singletonList(search.first().getId()), QueryOptions.empty(), token); } @Test @@ -1113,22 +1113,22 @@ public void visitJob() throws CatalogException { .first(); Query query = new Query(JobDBAdaptor.QueryParams.VISITED.key(), false); - assertEquals(1, catalogManager.getJobManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getJobManager().count(organizationId, studyFqn, query, token).getNumMatches()); // Now we visit the job catalogManager.getJobManager().visit(studyFqn, job.getId(), token); - assertEquals(0, catalogManager.getJobManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getJobManager().count(organizationId, studyFqn, query, token).getNumMatches()); query.put(JobDBAdaptor.QueryParams.VISITED.key(), true); - assertEquals(1, catalogManager.getJobManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getJobManager().count(organizationId, studyFqn, query, token).getNumMatches()); // Now we update setting job to visited false again JobUpdateParams updateParams = new JobUpdateParams().setVisited(false); catalogManager.getJobManager().update(studyFqn, job.getId(), updateParams, QueryOptions.empty(), token); - assertEquals(0, catalogManager.getJobManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getJobManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(JobDBAdaptor.QueryParams.VISITED.key(), false); - assertEquals(1, catalogManager.getJobManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getJobManager().count(organizationId, studyFqn, query, token).getNumMatches()); } /** @@ -1137,7 +1137,7 @@ public void visitJob() throws CatalogException { @Test public void testCreateVariableSet() throws CatalogException { - Study study = catalogManager.getStudyManager().get("user@1000G:phase1", null, token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, "user@1000G:phase1", null, token).first(); long variableSetNum = study.getVariableSets().size(); List variables = new ArrayList<>(); @@ -1155,18 +1155,18 @@ public void testCreateVariableSet() throws CatalogException { "", "", null, Collections.emptyMap()) )); - DataResult queryResult = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", true, + DataResult queryResult = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", true, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token); assertEquals(1, queryResult.getResults().size()); - study = catalogManager.getStudyManager().get(study.getId(), null, token).first(); + study = catalogManager.getStudyManager().get(organizationId, study.getId(), null, token).first(); assertEquals(variableSetNum + 1, study.getVariableSets().size()); } @Test public void testCreateRepeatedVariableSet() throws CatalogException { - Study study = catalogManager.getStudyManager().get("user@1000G:phase1", null, token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, "user@1000G:phase1", null, token).first(); List variables = Arrays.asList( new Variable("NAME", "", Variable.VariableType.STRING, "", true, false, Collections.emptyList(), null, 0, "", "", @@ -1183,13 +1183,13 @@ public void testCreateRepeatedVariableSet() throws CatalogException { null, Collections.emptyMap()) ); thrown.expect(CatalogException.class); - catalogManager.getStudyManager().createVariableSet(study.getFqn(), "vs1", "vs1", true, false, "", null, variables, + catalogManager.getStudyManager().createVariableSet(organizationId, study.getFqn(), "vs1", "vs1", true, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token); } @Test public void testDeleteVariableSet() throws CatalogException { - Study study = catalogManager.getStudyManager().resolveId("1000G:phase1", "user"); + Study study = catalogManager.getStudyManager().resolveId(organizationId, "1000G:phase1", "user"); List variables = Arrays.asList( new Variable("NAME", "", Variable.VariableType.STRING, "", true, false, Collections.emptyList(), null, 0, "", "", @@ -1198,20 +1198,20 @@ public void testDeleteVariableSet() throws CatalogException { new Variable("AGE", "", Variable.VariableType.DOUBLE, null, true, false, Collections.singletonList("0:99"), null, 1, "", "", null, Collections.emptyMap()) ); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(study.getFqn(), "vs1", "vs1", true, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, study.getFqn(), "vs1", "vs1", true, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); - DataResult result = catalogManager.getStudyManager().deleteVariableSet(studyFqn, vs1.getId(), false, token); + DataResult result = catalogManager.getStudyManager().deleteVariableSet(organizationId, studyFqn, vs1.getId(), false, token); assertEquals(0, result.getNumResults()); thrown.expect(CatalogException.class); //VariableSet does not exist thrown.expectMessage("not found"); - catalogManager.getStudyManager().getVariableSet(studyFqn, vs1.getId(), null, token); + catalogManager.getStudyManager().getVariableSet(organizationId, studyFqn, vs1.getId(), null, token); } @Test public void testGetAllVariableSet() throws CatalogException { - Study study = catalogManager.getStudyManager().resolveId("1000G:phase1", "user"); + Study study = catalogManager.getStudyManager().resolveId(organizationId, "1000G:phase1", "user"); List variables = Arrays.asList( new Variable("NAME", "", Variable.VariableType.STRING, "", true, false, Collections.emptyList(), null, 0, "", "", @@ -1220,48 +1220,48 @@ public void testGetAllVariableSet() throws CatalogException { new Variable("AGE", "", Variable.VariableType.DOUBLE, null, true, false, Collections.singletonList("0:99"), null, 1, "", "", null, Collections.emptyMap()) ); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(study.getFqn(), "vs1", "vs1", true, false, "Cancer", null, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, study.getFqn(), "vs1", "vs1", true, false, "Cancer", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); - VariableSet vs2 = catalogManager.getStudyManager().createVariableSet(study.getFqn(), "vs2", "vs2", true, false, "Virgo", null, + VariableSet vs2 = catalogManager.getStudyManager().createVariableSet(organizationId, study.getFqn(), "vs2", "vs2", true, false, "Virgo", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); - VariableSet vs3 = catalogManager.getStudyManager().createVariableSet(study.getFqn(), "vs3", "vs3", true, false, "Piscis", null, + VariableSet vs3 = catalogManager.getStudyManager().createVariableSet(organizationId, study.getFqn(), "vs3", "vs3", true, false, "Piscis", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); - VariableSet vs4 = catalogManager.getStudyManager().createVariableSet(study.getFqn(), "vs4", "vs4", true, false, "Aries", null, + VariableSet vs4 = catalogManager.getStudyManager().createVariableSet(organizationId, study.getFqn(), "vs4", "vs4", true, false, "Aries", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); long numResults; - numResults = catalogManager.getStudyManager().searchVariableSets(study.getFqn(), + numResults = catalogManager.getStudyManager().searchVariableSets(organizationId, study.getFqn(), new Query(StudyDBAdaptor.VariableSetParams.ID.key(), "vs1"), QueryOptions.empty(), token).getNumResults(); assertEquals(1, numResults); - numResults = catalogManager.getStudyManager().searchVariableSets(study.getFqn(), + numResults = catalogManager.getStudyManager().searchVariableSets(organizationId, study.getFqn(), new Query(StudyDBAdaptor.VariableSetParams.ID.key(), "vs1,vs2"), QueryOptions.empty(), token) .getNumResults(); assertEquals(2, numResults); - numResults = catalogManager.getStudyManager().searchVariableSets(study.getFqn(), + numResults = catalogManager.getStudyManager().searchVariableSets(organizationId, study.getFqn(), new Query(StudyDBAdaptor.VariableSetParams.ID.key(), "VS1"), QueryOptions.empty(), token).getNumResults(); assertEquals(0, numResults); - numResults = catalogManager.getStudyManager().searchVariableSets(study.getFqn(), + numResults = catalogManager.getStudyManager().searchVariableSets(organizationId, study.getFqn(), new Query(StudyDBAdaptor.VariableSetParams.UID.key(), vs1.getId()), QueryOptions.empty(), token).getNumResults(); assertEquals(1, numResults); // numResults = catalogManager.getStudyManager().searchVariableSets(studyFqn, // new Query(StudyDBAdaptor.VariableSetParams.ID.key(), vs1.getId() + "," + vs3.getId()), QueryOptions.empty(), // sessionIdUser).getNumResults(); - numResults = catalogManager.getStudyManager().searchVariableSets(study.getFqn(), + numResults = catalogManager.getStudyManager().searchVariableSets(organizationId, study.getFqn(), new Query(StudyDBAdaptor.VariableSetParams.UID.key(), vs3.getId()), QueryOptions.empty(), token).getNumResults(); assertEquals(1, numResults); } @Test public void testDeleteVariableSetInUse() throws CatalogException { - String sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), + String sampleId1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first().getId(); List variables = Arrays.asList( new Variable("NAME", "", "", Variable.VariableType.STRING, "", true, false, Collections.emptyList(), null, 0, "", "", null, @@ -1270,7 +1270,7 @@ public void testDeleteVariableSetInUse() throws CatalogException { "", "", null, Collections.emptyMap()) ); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", true, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", true, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); Map annotations = new HashMap<>(); @@ -1280,9 +1280,9 @@ public void testDeleteVariableSetInUse() throws CatalogException { QueryOptions.empty(), token); try { - catalogManager.getStudyManager().deleteVariableSet(studyFqn, vs1.getId(), false, token); + catalogManager.getStudyManager().deleteVariableSet(organizationId, studyFqn, vs1.getId(), false, token); } finally { - VariableSet variableSet = catalogManager.getStudyManager().getVariableSet(studyFqn, vs1.getId(), null, token).first(); + VariableSet variableSet = catalogManager.getStudyManager().getVariableSet(organizationId, studyFqn, vs1.getId(), null, token).first(); assertEquals(vs1.getUid(), variableSet.getUid()); thrown.expect(CatalogDBException.class); //Expect the exception from the try @@ -1299,10 +1299,10 @@ public void testDeleteVariableSetInUse() throws CatalogException { */ @Test public void testCreateCohort() throws CatalogException { - Sample sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); - Sample sampleId2 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); - Sample sampleId3 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); - Cohort myCohort = catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort") + Sample sampleId1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); + Sample sampleId2 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); + Sample sampleId3 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); + Cohort myCohort = catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("MyCohort") .setSamples(Arrays.asList(sampleId1, sampleId2, sampleId3)) .setStatus(new Status("custom", "custom", "description", TimeUtils.getTime())), INCLUDE_RESULT, token).first(); @@ -1318,12 +1318,12 @@ public void testCreateCohort() throws CatalogException { @Test public void createSampleCohortTest() throws Exception { - Sample sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); - Sample sampleId2 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); - Sample sampleId3 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); - catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort1") + Sample sampleId1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); + Sample sampleId2 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); + Sample sampleId3 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); + catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("MyCohort1") .setSamples(Arrays.asList(sampleId1, sampleId2)), null, token).first(); - catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort2") + catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("MyCohort2") .setSamples(Arrays.asList(sampleId2, sampleId3)), null, token).first(); List ids = new ArrayList<>(); @@ -1333,7 +1333,7 @@ public void createSampleCohortTest() throws Exception { QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.COHORT_IDS.key()); - OpenCGAResult sampleDataResult = catalogManager.getSampleManager().get(studyFqn, ids, options, token); + OpenCGAResult sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, ids, options, token); assertEquals(3, sampleDataResult.getNumResults()); for (Sample sample : sampleDataResult.getResults()) { switch (sample.getId()) { @@ -1357,12 +1357,12 @@ public void createSampleCohortTest() throws Exception { @Test public void updateSampleCohortTest() throws Exception { - Sample sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); - Sample sampleId2 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); - Sample sampleId3 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); - catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort1") + Sample sampleId1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); + Sample sampleId2 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); + Sample sampleId3 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); + catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("MyCohort1") .setSamples(Arrays.asList(sampleId1)), null, token).first(); - catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort2") + catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("MyCohort2") .setSamples(Arrays.asList(sampleId2, sampleId3)), null, token).first(); catalogManager.getCohortManager().update(studyFqn, "MyCohort1", @@ -1377,9 +1377,9 @@ public void updateSampleCohortTest() throws Exception { QueryOptions optionsSample = new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.COHORT_IDS.key()); QueryOptions optionsCohort = new QueryOptions(QueryOptions.INCLUDE, CohortDBAdaptor.QueryParams.SAMPLES.key()); - OpenCGAResult sampleDataResult = catalogManager.getSampleManager().get(studyFqn, ids, optionsSample, token); + OpenCGAResult sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, ids, optionsSample, token); - Cohort cohortResult = catalogManager.getCohortManager().get(studyFqn, "MyCohort1", optionsCohort, token).first(); + Cohort cohortResult = catalogManager.getCohortManager().get(organizationId, studyFqn, "MyCohort1", optionsCohort, token).first(); assertEquals(2, cohortResult.getSamples().size()); assertTrue(cohortResult.getSamples().stream().map(Sample::getId).collect(Collectors.toSet()) @@ -1408,12 +1408,12 @@ public void updateSampleCohortTest() throws Exception { @Test public void deleteSampleCohortTest() throws Exception { - Sample sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); - Sample sampleId2 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); - Sample sampleId3 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); - catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort1") + Sample sampleId1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); + Sample sampleId2 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); + Sample sampleId3 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); + catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("MyCohort1") .setSamples(Arrays.asList(sampleId1)), null, token).first(); - catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort2") + catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("MyCohort2") .setSamples(Arrays.asList(sampleId2, sampleId3)), null, token).first(); catalogManager.getCohortManager().update(studyFqn, "MyCohort1", @@ -1436,9 +1436,9 @@ public void deleteSampleCohortTest() throws Exception { QueryOptions optionsSample = new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.COHORT_IDS.key()); QueryOptions optionsCohort = new QueryOptions(QueryOptions.INCLUDE, CohortDBAdaptor.QueryParams.SAMPLES.key()); - OpenCGAResult sampleDataResult = catalogManager.getSampleManager().get(studyFqn, ids, optionsSample, token); + OpenCGAResult sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, ids, optionsSample, token); - Cohort cohortResult = catalogManager.getCohortManager().get(studyFqn, "MyCohort1", optionsCohort, token).first(); + Cohort cohortResult = catalogManager.getCohortManager().get(organizationId, studyFqn, "MyCohort1", optionsCohort, token).first(); assertEquals(1, cohortResult.getSamples().size()); assertTrue(cohortResult.getSamples().stream().map(Sample::getId).collect(Collectors.toSet()) @@ -1466,10 +1466,10 @@ public void deleteSampleCohortTest() throws Exception { @Test public void setSampleCohortTest() throws Exception { - Sample sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); - Sample sampleId2 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); - Sample sampleId3 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); - catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort1") + Sample sampleId1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); + Sample sampleId2 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); + Sample sampleId3 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); + catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("MyCohort1") .setSamples(Arrays.asList(sampleId1)), null, token).first(); Map actionMap = new HashMap<>(); @@ -1490,9 +1490,9 @@ public void setSampleCohortTest() throws Exception { QueryOptions optionsSample = new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.COHORT_IDS.key()); QueryOptions optionsCohort = new QueryOptions(QueryOptions.INCLUDE, CohortDBAdaptor.QueryParams.SAMPLES.key()); - OpenCGAResult sampleDataResult = catalogManager.getSampleManager().get(studyFqn, ids, optionsSample, token); + OpenCGAResult sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, ids, optionsSample, token); - Cohort cohortResult = catalogManager.getCohortManager().get(studyFqn, "MyCohort1", optionsCohort, token).first(); + Cohort cohortResult = catalogManager.getCohortManager().get(organizationId, studyFqn, "MyCohort1", optionsCohort, token).first(); assertEquals(2, cohortResult.getSamples().size()); assertTrue(cohortResult.getSamples().stream().map(Sample::getId).collect(Collectors.toSet()) @@ -1550,49 +1550,49 @@ public void setSampleCohortTest() throws Exception { public void testGetAllCohorts() throws CatalogException { String studyId = "1000G:phase1"; - Sample sampleId1 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); - Sample sampleId2 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); - Sample sampleId3 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); - Sample sampleId4 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_4"), INCLUDE_RESULT, token).first(); - Sample sampleId5 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_5"), INCLUDE_RESULT, token).first(); - Cohort myCohort1 = catalogManager.getCohortManager().create(studyId, + Sample sampleId1 = catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); + Sample sampleId2 = catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); + Sample sampleId3 = catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); + Sample sampleId4 = catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("SAMPLE_4"), INCLUDE_RESULT, token).first(); + Sample sampleId5 = catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("SAMPLE_5"), INCLUDE_RESULT, token).first(); + Cohort myCohort1 = catalogManager.getCohortManager().create(organizationId, studyId, new Cohort().setId("MyCohort1").setType(Enums.CohortType.FAMILY).setSamples(Arrays.asList(sampleId1, sampleId2, sampleId3)), INCLUDE_RESULT, token).first(); - Cohort myCohort2 = catalogManager.getCohortManager().create(studyId, + Cohort myCohort2 = catalogManager.getCohortManager().create(organizationId, studyId, new Cohort().setId("MyCohort2").setType(Enums.CohortType.FAMILY) .setSamples(Arrays.asList(sampleId1, sampleId2, sampleId3, sampleId4)), INCLUDE_RESULT, token).first(); - Cohort myCohort3 = catalogManager.getCohortManager().create(studyId, new Cohort().setId("MyCohort3") + Cohort myCohort3 = catalogManager.getCohortManager().create(organizationId, studyId, new Cohort().setId("MyCohort3") .setType(Enums.CohortType.CASE_CONTROL).setSamples(Arrays.asList(sampleId3, sampleId4)), INCLUDE_RESULT, token).first(); - catalogManager.getCohortManager().create(studyId, new Cohort().setId("MyCohort4").setType(Enums.CohortType.TRIO) + catalogManager.getCohortManager().create(organizationId, studyId, new Cohort().setId("MyCohort4").setType(Enums.CohortType.TRIO) .setSamples(Arrays.asList(sampleId5, sampleId3)), null, token).first(); long numResults; - numResults = catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.SAMPLES.key(), + numResults = catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.SAMPLES.key(), sampleId1.getId()), new QueryOptions(), token).getNumResults(); assertEquals(2, numResults); - numResults = catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.SAMPLES.key(), + numResults = catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.SAMPLES.key(), sampleId1.getId() + "," + sampleId5.getId()), new QueryOptions(), token).getNumResults(); assertEquals(3, numResults); - numResults = catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "MyCohort2"), new + numResults = catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "MyCohort2"), new QueryOptions(), token).getNumResults(); assertEquals(1, numResults); - numResults = catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "~MyCohort."), new + numResults = catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "~MyCohort."), new QueryOptions(), token).getNumResults(); assertEquals(4, numResults); - numResults = catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.TYPE.key(), + numResults = catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.TYPE.key(), Enums.CohortType.FAMILY), new QueryOptions(), token).getNumResults(); assertEquals(2, numResults); - numResults = catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.TYPE.key(), "CASE_CONTROL"), + numResults = catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.TYPE.key(), "CASE_CONTROL"), new QueryOptions(), token).getNumResults(); assertEquals(1, numResults); - numResults = catalogManager.getCohortManager().search(studyId, new Query(CohortDBAdaptor.QueryParams.UID.key(), myCohort1.getUid() + + numResults = catalogManager.getCohortManager().search(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.UID.key(), myCohort1.getUid() + "," + myCohort2.getUid() + "," + myCohort3.getUid()), new QueryOptions(), token).getNumResults(); assertEquals(3, numResults); } @@ -1601,31 +1601,31 @@ public void testGetAllCohorts() throws CatalogException { public void testCreateCohortFail() throws CatalogException { thrown.expect(CatalogException.class); List sampleList = Arrays.asList(new Sample().setId("a"), new Sample().setId("b"), new Sample().setId("c")); - catalogManager.getCohortManager().create(studyFqn, + catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("MyCohort").setType(Enums.CohortType.FAMILY).setSamples(sampleList), null, token); } @Test public void testCreateCohortAlreadyExisting() throws CatalogException { - Sample sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); - catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort").setType(Enums.CohortType.FAMILY) + Sample sampleId1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); + catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("MyCohort").setType(Enums.CohortType.FAMILY) .setSamples(Collections.singletonList(sampleId1)), null, token).first(); thrown.expect(CatalogDBException.class); - catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort").setType(Enums.CohortType.FAMILY) + catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("MyCohort").setType(Enums.CohortType.FAMILY) .setSamples(Collections.singletonList(sampleId1)), null, token).first(); } @Test public void testUpdateCohort() throws CatalogException { - Sample sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); - Sample sampleId2 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); - Sample sampleId3 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); - Sample sampleId4 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_4"), INCLUDE_RESULT, token).first(); - Sample sampleId5 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_5"), INCLUDE_RESULT, token).first(); + Sample sampleId1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); + Sample sampleId2 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); + Sample sampleId3 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); + Sample sampleId4 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_4"), INCLUDE_RESULT, token).first(); + Sample sampleId5 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_5"), INCLUDE_RESULT, token).first(); - Cohort myCohort = catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort").setType(Enums.CohortType.FAMILY) + Cohort myCohort = catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("MyCohort").setType(Enums.CohortType.FAMILY) .setSamples(Arrays.asList(sampleId1, sampleId2, sampleId3, sampleId1)), INCLUDE_RESULT, token).first(); assertEquals("MyCohort", myCohort.getId()); @@ -1650,7 +1650,7 @@ public void testUpdateCohort() throws CatalogException { options, token); assertEquals(1, result.getNumUpdated()); - Cohort myModifiedCohort = catalogManager.getCohortManager().get(studyFqn, "myModifiedCohort", QueryOptions.empty(), token).first(); + Cohort myModifiedCohort = catalogManager.getCohortManager().get(organizationId, studyFqn, "myModifiedCohort", QueryOptions.empty(), token).first(); assertEquals("myModifiedCohort", myModifiedCohort.getId()); assertEquals(4, myModifiedCohort.getSamples().size()); assertEquals(4, myModifiedCohort.getNumSamples()); @@ -1660,7 +1660,7 @@ public void testUpdateCohort() throws CatalogException { assertTrue(myModifiedCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId5.getUid())); QueryOptions options1 = new QueryOptions(QueryOptions.INCLUDE, CohortDBAdaptor.QueryParams.NUM_SAMPLES.key()); - myModifiedCohort = catalogManager.getCohortManager().get(studyFqn, "myModifiedCohort", options1, token).first(); + myModifiedCohort = catalogManager.getCohortManager().get(organizationId, studyFqn, "myModifiedCohort", options1, token).first(); assertEquals(4, myModifiedCohort.getNumSamples()); assertNull(myModifiedCohort.getSamples()); @@ -1672,7 +1672,7 @@ public void testUpdateCohort() throws CatalogException { options, token); assertEquals(1, result.getNumUpdated()); - myModifiedCohort = catalogManager.getCohortManager().get(studyFqn, "myModifiedCohort", QueryOptions.empty(), token).first(); + myModifiedCohort = catalogManager.getCohortManager().get(organizationId, studyFqn, "myModifiedCohort", QueryOptions.empty(), token).first(); assertEquals(0, myModifiedCohort.getSamples().size()); assertEquals(0, myModifiedCohort.getNumSamples()); @@ -1687,7 +1687,7 @@ public void testUpdateCohort() throws CatalogException { new SampleReferenceParam().setId(sampleId3.getId()))), options, token); assertEquals(1, result.getNumUpdated()); - myModifiedCohort = catalogManager.getCohortManager().get(studyFqn, "myModifiedCohort", QueryOptions.empty(), token).first(); + myModifiedCohort = catalogManager.getCohortManager().get(organizationId, studyFqn, "myModifiedCohort", QueryOptions.empty(), token).first(); assertEquals(2, myModifiedCohort.getSamples().size()); assertEquals(2, myModifiedCohort.getNumSamples()); @@ -1700,7 +1700,7 @@ public void testUpdateCohort() throws CatalogException { new SampleReferenceParam().setId(sampleId3.getId()))), options, token); assertEquals(1, result.getNumUpdated()); - myModifiedCohort = catalogManager.getCohortManager().get(studyFqn, "myModifiedCohort", QueryOptions.empty(), token).first(); + myModifiedCohort = catalogManager.getCohortManager().get(organizationId, studyFqn, "myModifiedCohort", QueryOptions.empty(), token).first(); assertEquals(1, myModifiedCohort.getSamples().size()); assertEquals(1, myModifiedCohort.getNumSamples()); assertTrue(myModifiedCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId1.getUid())); @@ -1714,11 +1714,11 @@ public void testUpdateCohort() throws CatalogException { public void testDeleteCohort() throws CatalogException { String studyId = "user@1000G:phase1"; - Sample sampleId1 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); - Sample sampleId2 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); - Sample sampleId3 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); + Sample sampleId1 = catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); + Sample sampleId2 = catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); + Sample sampleId3 = catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); - Cohort myCohort = catalogManager.getCohortManager().create(studyId, new Cohort().setId("MyCohort").setType(Enums.CohortType.FAMILY) + Cohort myCohort = catalogManager.getCohortManager().create(organizationId, studyId, new Cohort().setId("MyCohort").setType(Enums.CohortType.FAMILY) .setSamples(Arrays.asList(sampleId1, sampleId2, sampleId3)), INCLUDE_RESULT, token).first(); assertEquals("MyCohort", myCohort.getId()); @@ -1727,14 +1727,14 @@ public void testDeleteCohort() throws CatalogException { assertTrue(myCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId2.getUid())); assertTrue(myCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId3.getUid())); - DataResult deleteResult = catalogManager.getCohortManager().delete(studyId, + DataResult deleteResult = catalogManager.getCohortManager().delete(organizationId, studyId, new Query(CohortDBAdaptor.QueryParams.UID.key(), myCohort.getUid()), null, token); assertEquals(1, deleteResult.getNumDeleted()); Query query = new Query() .append(CohortDBAdaptor.QueryParams.UID.key(), myCohort.getUid()) .append(CohortDBAdaptor.QueryParams.DELETED.key(), true); - Cohort cohort = catalogManager.getCohortManager().search(studyId, query, null, token).first(); + Cohort cohort = catalogManager.getCohortManager().search(organizationId, studyId, query, null, token).first(); assertEquals(InternalStatus.DELETED, cohort.getInternal().getStatus().getId()); } @@ -1742,14 +1742,14 @@ public void testDeleteCohort() throws CatalogException { public void getSamplesFromCohort() throws CatalogException, IOException { String studyId = "user@1000G:phase1"; - Sample sampleId1 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, + Sample sampleId1 = catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first(); - Sample sampleId2 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, + Sample sampleId2 = catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first(); - Sample sampleId3 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, + Sample sampleId3 = catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token).first(); - Cohort myCohort = catalogManager.getCohortManager().create(studyId, new Cohort().setId("MyCohort").setType(Enums.CohortType.FAMILY) + Cohort myCohort = catalogManager.getCohortManager().create(organizationId, studyId, new Cohort().setId("MyCohort").setType(Enums.CohortType.FAMILY) .setSamples(Arrays.asList(sampleId1, sampleId2, sampleId3)), INCLUDE_RESULT, token).first(); DataResult myCohort1 = catalogManager.getCohortManager().getSamples(studyId, "MyCohort", token); @@ -1767,19 +1767,19 @@ public void testDeleteVariableSetWithAnnotations() throws CatalogException { VariableSet variableSet = createVariableSetAndAnnotationSets(); thrown.expect(CatalogException.class); thrown.expectMessage("in use"); - catalogManager.getStudyManager().deleteVariableSet(studyFqn, variableSet.getId(), false, token); + catalogManager.getStudyManager().deleteVariableSet(organizationId, studyFqn, variableSet.getId(), false, token); } private VariableSet createVariableSetAndAnnotationSets() throws CatalogException { - VariableSet variableSet = catalogManager.getStudyManager().getVariableSet(studyFqn, "vs", null, token).first(); + VariableSet variableSet = catalogManager.getStudyManager().getVariableSet(organizationId, studyFqn, "vs", null, token).first(); - String individualId1 = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("INDIVIDUAL_1") + String individualId1 = catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("INDIVIDUAL_1") .setKaryotypicSex(IndividualProperty.KaryotypicSex.UNKNOWN).setLifeStatus(IndividualProperty.LifeStatus.UNKNOWN), INCLUDE_RESULT, token).first().getId(); - String individualId2 = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("INDIVIDUAL_2") + String individualId2 = catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("INDIVIDUAL_2") .setKaryotypicSex(IndividualProperty.KaryotypicSex.UNKNOWN).setLifeStatus(IndividualProperty.LifeStatus.UNKNOWN), INCLUDE_RESULT, token).first().getId(); - String individualId3 = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("INDIVIDUAL_3") + String individualId3 = catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("INDIVIDUAL_3") .setKaryotypicSex(IndividualProperty.KaryotypicSex.UNKNOWN).setLifeStatus(IndividualProperty.LifeStatus.UNKNOWN), INCLUDE_RESULT, token).first().getId(); @@ -1801,12 +1801,12 @@ private VariableSet createVariableSetAndAnnotationSets() throws CatalogException QueryOptions options = new QueryOptions() .append(QueryOptions.LIMIT, 0) .append(QueryOptions.COUNT, true); - OpenCGAResult result = catalogManager.getIndividualManager().search(studyFqn, + OpenCGAResult result = catalogManager.getIndividualManager().search(organizationId, studyFqn, new Query(IndividualDBAdaptor.QueryParams.ANNOTATION.key(), Constants.VARIABLE_SET + "=" + variableSet.getId()), options, token); assertEquals(3, result.getNumMatches()); - result = catalogManager.getSampleManager().search(studyFqn, + result = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.ANNOTATION.key(), Constants.VARIABLE_SET + "=" + variableSet.getId()), options, token); assertEquals(8, result.getNumMatches()); @@ -1816,13 +1816,13 @@ private VariableSet createVariableSetAndAnnotationSets() throws CatalogException @Test public void testForceDeleteVariableSetWithAnnotations() throws CatalogException { VariableSet variableSet = createVariableSetAndAnnotationSets(); - catalogManager.getStudyManager().deleteVariableSet(studyFqn, variableSet.getId(), true, token); + catalogManager.getStudyManager().deleteVariableSet(organizationId, studyFqn, variableSet.getId(), true, token); QueryOptions options = new QueryOptions() .append(QueryOptions.LIMIT, 0) .append(QueryOptions.COUNT, true); try { - catalogManager.getIndividualManager().search(studyFqn, + catalogManager.getIndividualManager().search(organizationId, studyFqn, new Query(IndividualDBAdaptor.QueryParams.ANNOTATION.key(), Constants.VARIABLE_SET + "=" + variableSet.getId()), options, token); fail("It should fail saying Variable set does not exist"); @@ -1831,7 +1831,7 @@ public void testForceDeleteVariableSetWithAnnotations() throws CatalogException } try { - catalogManager.getSampleManager().search(studyFqn, + catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.ANNOTATION.key(), Constants.VARIABLE_SET + "=" + variableSet.getId()), options, token); fail("It should fail saying Variable set does not exist"); @@ -1840,7 +1840,7 @@ public void testForceDeleteVariableSetWithAnnotations() throws CatalogException } try { - catalogManager.getStudyManager().getVariableSet(studyFqn, variableSet.getId(), QueryOptions.empty(), token); + catalogManager.getStudyManager().getVariableSet(organizationId, studyFqn, variableSet.getId(), QueryOptions.empty(), token); fail("It should fail saying Variable set does not exist"); } catch (CatalogException e) { assertTrue(e.getMessage().contains("not found")); @@ -1852,9 +1852,9 @@ public void testForceDeleteVariableSetWithAnnotations() throws CatalogException public void generateCohortFromSampleQuery() throws CatalogException, IOException { String studyId = "user@1000G:phase1"; - catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token); - catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token); - catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token); + catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token); + catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token); + catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("SAMPLE_3"), INCLUDE_RESULT, token); Query query = new Query(); Cohort myCohort = catalogManager.getCohortManager().generate(studyId, query, new Cohort().setId("MyCohort"), INCLUDE_RESULT, token).first(); diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/ClinicalAnalysisManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/ClinicalAnalysisManagerTest.java index d703b598e44..21b2434839a 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/ClinicalAnalysisManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/ClinicalAnalysisManagerTest.java @@ -187,7 +187,7 @@ private Family getDummyFamily() { private DataResult createDummyFamily() throws CatalogException { Family family = getDummyFamily(); - return familyManager.create(STUDY, family, INCLUDE_RESULT, sessionIdUser); + return familyManager.create(organizationId, STUDY, family, INCLUDE_RESULT, sessionIdUser); } private DataResult createDummyEnvironment(boolean createFamily, boolean createDefaultInterpretation) throws CatalogException { @@ -204,7 +204,7 @@ private DataResult createDummyEnvironment(boolean createFamily clinicalAnalysis.setFamily(new Family().setId("family") .setMembers(Arrays.asList(new Individual().setId("child1").setSamples(Arrays.asList(new Sample().setId("sample2")))))); - return catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, !createDefaultInterpretation, + return catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, !createDefaultInterpretation, INCLUDE_RESULT, sessionIdUser); } @@ -237,7 +237,7 @@ public void createAndTestStatusIdIsNotNull() throws CatalogException { .setFamily(new Family().setId("family") .setMembers(Collections.singletonList(new Individual().setId("child1").setSamples(Arrays.asList(new Sample().setId("sample2")))))); - OpenCGAResult result = catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, false, + OpenCGAResult result = catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, false, INCLUDE_RESULT, sessionIdUser); assertEquals("", result.first().getStatus().getId()); @@ -248,14 +248,14 @@ public void createAndTestStatusIdIsNotNull() throws CatalogException { .setProband(new Individual().setId("child1").setSamples(Arrays.asList(new Sample().setId("sample2")))) .setFamily(new Family().setId("family") .setMembers(Collections.singletonList(new Individual().setId("child1").setSamples(Arrays.asList(new Sample().setId("sample2")))))); - result = catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, false, INCLUDE_RESULT, sessionIdUser); + result = catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, false, INCLUDE_RESULT, sessionIdUser); assertEquals("", result.first().getStatus().getId()); - result = catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), + result = catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams().setStatus(new StatusParam(null)), INCLUDE_RESULT, sessionIdUser); assertEquals("", result.first().getStatus().getId()); - result = catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), + result = catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams().setStatus(new StatusParam("")), INCLUDE_RESULT, sessionIdUser); assertEquals("", result.first().getStatus().getId()); } @@ -268,12 +268,12 @@ public void createMultipleCasesSameFamily() throws CatalogException { createDummyEnvironment(false, true).first(); createDummyEnvironment(false, true).first(); - catalogManager.getClinicalAnalysisManager().update(STUDY, case1.getId(), new ClinicalAnalysisUpdateParams().setLocked(true), QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, case1.getId(), new ClinicalAnalysisUpdateParams().setLocked(true), QueryOptions.empty(), sessionIdUser); // Update proband's sample catalogManager.getSampleManager().update(STUDY, case1.getProband().getSamples().get(0).getId(), new SampleUpdateParams().setDescription("new description"), QueryOptions.empty(), sessionIdUser); - OpenCGAResult search = catalogManager.getClinicalAnalysisManager().search(STUDY, new Query(), new QueryOptions(), + OpenCGAResult search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, new Query(), new QueryOptions(), sessionIdUser); assertEquals(5, search.getNumResults()); for (ClinicalAnalysis casee : search.getResults()) { @@ -292,7 +292,7 @@ public void createMultipleCasesSameFamily() throws CatalogException { @Test public void createAndUpdateClinicalAnalysisWithQualityControl() throws CatalogException, InterruptedException { Individual individual = new Individual().setId("child1").setSamples(Arrays.asList(new Sample().setId("sample2"))); - catalogManager.getIndividualManager().create(STUDY, individual, null, sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, individual, null, sessionIdUser); ClinicalComment comment = new ClinicalComment("user", "my comment", new ArrayList<>(), ""); ClinicalAnalysis clinicalAnalysis = new ClinicalAnalysis() @@ -302,7 +302,7 @@ public void createAndUpdateClinicalAnalysisWithQualityControl() throws CatalogEx Collections.singletonList(comment), Collections.emptyList())) .setProband(individual); - ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, true, INCLUDE_RESULT, + ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, true, INCLUDE_RESULT, sessionIdUser).first(); assertEquals(ClinicalAnalysisQualityControl.QualityControlSummary.LOW, ca.getQualityControl().getSummary()); @@ -319,8 +319,8 @@ public void createAndUpdateClinicalAnalysisWithQualityControl() throws CatalogEx Collections.singletonList("other"), Collections.emptyList()); ClinicalAnalysisUpdateParams updateParams = new ClinicalAnalysisUpdateParams().setQualityControl(qualityControlUpdateParam); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), updateParams, null, sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), null, sessionIdUser).first(); + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), updateParams, null, sessionIdUser); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), null, sessionIdUser).first(); assertEquals(ClinicalAnalysisQualityControl.QualityControlSummary.HIGH, ca.getQualityControl().getSummary()); assertEquals("other", ca.getQualityControl().getComments().get(0).getMessage()); @@ -334,18 +334,18 @@ public void automaticallyLockCaseTest() throws CatalogException { Individual individual = new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))); - catalogManager.getIndividualManager().create(STUDY, individual, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, individual, QueryOptions.empty(), sessionIdUser); ClinicalAnalysis clinicalAnalysis = new ClinicalAnalysis() .setId("Clinical") .setType(ClinicalAnalysis.Type.SINGLE) .setProband(individual); - OpenCGAResult clinical = catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, + OpenCGAResult clinical = catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertTrue(StringUtils.isEmpty(clinical.first().getStatus().getId())); assertFalse(clinical.first().isLocked()); - clinical = catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), + clinical = catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams().setStatus(new StatusParam("CLOSED")), INCLUDE_RESULT, sessionIdUser); assertEquals("CLOSED", clinical.first().getStatus().getId()); assertTrue(clinical.first().isLocked()); @@ -355,7 +355,7 @@ public void automaticallyLockCaseTest() throws CatalogException { .setType(ClinicalAnalysis.Type.SINGLE) .setStatus(new ClinicalAnalysisStatus().setId("CLOSED")) .setProband(individual); - clinical = catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); + clinical = catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertEquals("CLOSED", clinical.first().getStatus().getId()); assertTrue(clinical.first().isLocked()); } @@ -365,13 +365,13 @@ public void createSingleClinicalAnalysisTestWithoutDisorder() throws CatalogExce Individual individual = new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))); - catalogManager.getIndividualManager().create(STUDY, individual, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, individual, QueryOptions.empty(), sessionIdUser); ClinicalAnalysis clinicalAnalysis = new ClinicalAnalysis() .setId("Clinical") .setType(ClinicalAnalysis.Type.SINGLE) .setProband(individual); - OpenCGAResult clinical = catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, + OpenCGAResult clinical = catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertEquals(1, clinical.getNumResults()); assertTrue(StringUtils.isNotEmpty(clinical.first().getDueDate())); @@ -386,20 +386,20 @@ public void queryClinicalAnalysisByDate() throws CatalogException { .append(ClinicalAnalysisDBAdaptor.QueryParams.DUE_DATE.key(), ">=" + TimeUtils.getTime(TimeUtils.add24HtoDate(TimeUtils.getDate())) ); - OpenCGAResult search = catalogManager.getClinicalAnalysisManager().search(STUDY, query, QueryOptions.empty(), sessionIdUser); + OpenCGAResult search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, query, QueryOptions.empty(), sessionIdUser); assertEquals(1, search.getNumResults()); assertEquals(result.first().getId(), search.first().getId()); String dueDate = TimeUtils.getTime(); ClinicalAnalysisUpdateParams updateParams = new ClinicalAnalysisUpdateParams() .setDueDate(dueDate); - catalogManager.getClinicalAnalysisManager().update(STUDY, result.first().getId(), updateParams, QueryOptions.empty(), sessionIdUser); - search = catalogManager.getClinicalAnalysisManager().search(STUDY, query, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, result.first().getId(), updateParams, QueryOptions.empty(), sessionIdUser); + search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, query, QueryOptions.empty(), sessionIdUser); assertEquals(0, search.getNumResults()); query.put(ClinicalAnalysisDBAdaptor.QueryParams.DUE_DATE.key(), "<" + TimeUtils.getTime(TimeUtils.add24HtoDate(TimeUtils.getDate()))); - search = catalogManager.getClinicalAnalysisManager().search(STUDY, query, QueryOptions.empty(), sessionIdUser); + search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, query, QueryOptions.empty(), sessionIdUser); assertEquals(1, search.getNumResults()); assertEquals(result.first().getId(), search.first().getId()); assertEquals(dueDate, search.first().getDueDate()); @@ -410,7 +410,7 @@ public void createClinicalWithComments() throws CatalogException { Individual individual = new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))); - catalogManager.getIndividualManager().create(STUDY, individual, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, individual, QueryOptions.empty(), sessionIdUser); ClinicalAnalysis clinicalAnalysis = new ClinicalAnalysis() .setId("Clinical") @@ -419,7 +419,7 @@ public void createClinicalWithComments() throws CatalogException { new ClinicalComment("", "My first comment", Arrays.asList("tag1", "tag2"), ""), new ClinicalComment("", "My second comment", Arrays.asList("1tag", "2tag"), ""))) .setProband(individual); - OpenCGAResult clinical = catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, + OpenCGAResult clinical = catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertEquals(1, clinical.getNumResults()); assertEquals(2, clinical.first().getComments().size()); @@ -444,7 +444,7 @@ public void createClinicalWithMissingSamplesInFamily() throws CatalogException { member.setSamples(Collections.emptyList()); } } - familyManager.create(STUDY, family, QueryOptions.empty(), sessionIdUser); + familyManager.create(organizationId, STUDY, family, QueryOptions.empty(), sessionIdUser); // And only add sample to proband for (Individual member : family.getMembers()) { @@ -458,7 +458,7 @@ public void createClinicalWithMissingSamplesInFamily() throws CatalogException { .setDueDate("20180510100000") .setProband(new Individual().setId("child1")); clinicalAnalysis.setFamily(family); - DataResult clinicalAnalysisDataResult = catalogManager.getClinicalAnalysisManager().create(STUDY, + DataResult clinicalAnalysisDataResult = catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertEquals("child1", clinicalAnalysisDataResult.first().getFamily().getMembers().get(0).getId()); @@ -478,7 +478,7 @@ public void updateClinicalComments() throws CatalogException { Individual individual = new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))); - catalogManager.getIndividualManager().create(STUDY, individual, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, individual, QueryOptions.empty(), sessionIdUser); ClinicalAnalysis clinicalAnalysis = new ClinicalAnalysis() .setId("Clinical") @@ -486,7 +486,7 @@ public void updateClinicalComments() throws CatalogException { .setComments(Collections.singletonList(new ClinicalComment("", "My first comment", Arrays.asList("tag1", "tag2"), ""))) .setProband(individual); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); List commentParamList = new ArrayList<>(); commentParamList.add(new ClinicalCommentParam("My second comment", Arrays.asList("myTag"))); @@ -495,10 +495,10 @@ public void updateClinicalComments() throws CatalogException { ObjectMap actionMap = new ObjectMap(ClinicalAnalysisDBAdaptor.QueryParams.COMMENTS.key(), ParamUtils.AddRemoveAction.ADD); QueryOptions options = new QueryOptions(Constants.ACTIONS, actionMap); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setComments(commentParamList), options, sessionIdUser); - OpenCGAResult clinical = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), + OpenCGAResult clinical = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); assertEquals(1, clinical.getNumResults()); assertEquals(3, clinical.first().getComments().size()); @@ -524,9 +524,9 @@ public void updateClinicalComments() throws CatalogException { actionMap = new ObjectMap(ClinicalAnalysisDBAdaptor.QueryParams.COMMENTS.key(), ParamUtils.AddRemoveReplaceAction.REPLACE); options = new QueryOptions(Constants.ACTIONS, actionMap); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setComments(commentParamList), options, sessionIdUser); - clinical = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); + clinical = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); assertEquals(1, clinical.getNumResults()); assertEquals(3, clinical.first().getComments().size()); assertEquals("user", clinical.first().getComments().get(1).getAuthor()); @@ -551,10 +551,10 @@ public void updateClinicalComments() throws CatalogException { actionMap = new ObjectMap(ClinicalAnalysisDBAdaptor.QueryParams.COMMENTS.key(), ParamUtils.AddRemoveAction.REMOVE); options = new QueryOptions(Constants.ACTIONS, actionMap); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setComments(commentParamList), options, sessionIdUser); - clinical = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); + clinical = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); assertEquals(1, clinical.getNumResults()); assertEquals(1, clinical.first().getComments().size()); assertEquals("user", clinical.first().getComments().get(0).getAuthor()); @@ -570,10 +570,10 @@ public void updateClinicalComments() throws CatalogException { actionMap = new ObjectMap(ClinicalAnalysisDBAdaptor.QueryParams.COMMENTS.key(), ParamUtils.AddRemoveAction.REMOVE); options = new QueryOptions(Constants.ACTIONS, actionMap); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setComments(commentParamList), options, sessionIdUser); - clinical = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); + clinical = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); assertEquals(1, clinical.getNumResults()); assertEquals(0, clinical.first().getComments().size()); @@ -583,7 +583,7 @@ public void updateClinicalComments() throws CatalogException { options = new QueryOptions(Constants.ACTIONS, actionMap); try { - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setComments(commentParamList), options, sessionIdUser); fail("It should fail because the comment has no date"); } catch (CatalogException e) { @@ -597,7 +597,7 @@ public void updateClinicalComments() throws CatalogException { thrown.expect(CatalogException.class); thrown.expectMessage("date"); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setComments(commentParamList), options, sessionIdUser); } @@ -606,7 +606,7 @@ public void updateClinicalAnalysis() throws CatalogException { Individual individual = new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))); - catalogManager.getIndividualManager().create(STUDY, individual, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, individual, QueryOptions.empty(), sessionIdUser); ClinicalAnalysis clinicalAnalysis = new ClinicalAnalysis() .setId("Clinical") @@ -614,7 +614,7 @@ public void updateClinicalAnalysis() throws CatalogException { .setComments(Collections.singletonList(new ClinicalComment("", "My first comment", Arrays.asList("tag1", "tag2"), ""))) .setProband(individual); - ClinicalAnalysis clinical = catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser).first(); + ClinicalAnalysis clinical = catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser).first(); assertTrue(clinical.getAttributes().isEmpty()); Map attributes = new HashMap<>(); @@ -623,7 +623,7 @@ public void updateClinicalAnalysis() throws CatalogException { ClinicalAnalysisUpdateParams updateParams = new ClinicalAnalysisUpdateParams() .setAttributes(attributes); - clinical = catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), updateParams, INCLUDE_RESULT, sessionIdUser).first(); + clinical = catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), updateParams, INCLUDE_RESULT, sessionIdUser).first(); assertFalse(clinical.getAttributes().isEmpty()); assertEquals(2, clinical.getAttributes().size()); assertEquals(attributes.get("a"), clinical.getAttributes().get("a")); @@ -635,7 +635,7 @@ public void createRepeatedInterpretationPrimaryFindings() throws CatalogExceptio Individual individual = new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))); - catalogManager.getIndividualManager().create(STUDY, individual, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, individual, QueryOptions.empty(), sessionIdUser); List findingList = new ArrayList<>(); VariantAvro variantAvro = new VariantAvro("id1", null, "chr2", 1, 2, "", "", "+", null, 1, null, null, null); @@ -658,7 +658,7 @@ public void createRepeatedInterpretationPrimaryFindings() throws CatalogExceptio ); thrown.expect(CatalogException.class); thrown.expectMessage("repeated"); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); } @Test @@ -666,7 +666,7 @@ public void createRepeatedInterpretationSecondaryFindings() throws CatalogExcept Individual individual = new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))); - catalogManager.getIndividualManager().create(STUDY, individual, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, individual, QueryOptions.empty(), sessionIdUser); List findingList = new ArrayList<>(); VariantAvro variantAvro = new VariantAvro("id1", null, "chr2", 1, 2, "", "", "+", null, 1, null, null, null); @@ -689,7 +689,7 @@ public void createRepeatedInterpretationSecondaryFindings() throws CatalogExcept ); thrown.expect(CatalogException.class); thrown.expectMessage("repeated"); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); } @Test @@ -697,7 +697,7 @@ public void updatePrimaryFindings() throws CatalogException { Individual individual = new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))); - catalogManager.getIndividualManager().create(STUDY, individual, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, individual, QueryOptions.empty(), sessionIdUser); List findingList = new ArrayList<>(); VariantAvro variantAvro = new VariantAvro("id1", null, "chr2", 1, 2, "", "", "+", null, 1, null, null, null); @@ -717,9 +717,9 @@ public void updatePrimaryFindings() throws CatalogException { .setInterpretation(new Interpretation() .setPrimaryFindings(findingList) ); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); - Interpretation interpretation = catalogManager.getInterpretationManager().get(STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), + Interpretation interpretation = catalogManager.getInterpretationManager().get(organizationId, STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(2, interpretation.getPrimaryFindings().size()); assertEquals(2, interpretation.getStats().getPrimaryFindings().getNumVariants()); @@ -741,7 +741,7 @@ public void updatePrimaryFindings() throws CatalogException { catalogManager.getInterpretationManager().update(STUDY, clinicalAnalysis.getId(), clinicalAnalysis.getId() + ".1", updateParams, null, options, sessionIdUser); interpretation = - catalogManager.getInterpretationManager().get(STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); + catalogManager.getInterpretationManager().get(organizationId, STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(3, interpretation.getPrimaryFindings().size()); assertEquals("method2", interpretation.getPrimaryFindings().get(2).getEvidences().get(0).getInterpretationMethodName()); assertEquals("id3", interpretation.getPrimaryFindings().get(2).getId()); @@ -767,7 +767,7 @@ public void updatePrimaryFindings() throws CatalogException { catalogManager.getInterpretationManager().update(STUDY, clinicalAnalysis.getId(), clinicalAnalysis.getId() + ".1", updateParams, null, options, sessionIdUser); interpretation = - catalogManager.getInterpretationManager().get(STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); + catalogManager.getInterpretationManager().get(organizationId, STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(1, interpretation.getPrimaryFindings().size()); assertEquals("method", interpretation.getPrimaryFindings().get(0).getEvidences().get(0).getInterpretationMethodName()); assertEquals("id2", interpretation.getPrimaryFindings().get(0).getId()); @@ -783,7 +783,7 @@ public void updatePrimaryFindings() throws CatalogException { catalogManager.getInterpretationManager().update(STUDY, clinicalAnalysis.getId(), clinicalAnalysis.getId() + ".1", updateParams, null, options, sessionIdUser); interpretation = - catalogManager.getInterpretationManager().get(STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); + catalogManager.getInterpretationManager().get(organizationId, STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(3, interpretation.getPrimaryFindings().size()); assertEquals("method", interpretation.getPrimaryFindings().get(0).getEvidences().get(0).getInterpretationMethodName()); assertEquals("id1", interpretation.getPrimaryFindings().get(0).getId()); @@ -810,7 +810,7 @@ public void updatePrimaryFindings() throws CatalogException { catalogManager.getInterpretationManager().update(STUDY, clinicalAnalysis.getId(), clinicalAnalysis.getId() + ".1", updateParams, null, options, sessionIdUser); interpretation = - catalogManager.getInterpretationManager().get(STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); + catalogManager.getInterpretationManager().get(organizationId, STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(3, interpretation.getPrimaryFindings().size()); assertEquals("method", interpretation.getPrimaryFindings().get(0).getEvidences().get(0).getInterpretationMethodName()); assertEquals("id1", interpretation.getPrimaryFindings().get(0).getId()); @@ -859,7 +859,7 @@ public void updateSecondaryFindings() throws CatalogException { Individual individual = new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))); - catalogManager.getIndividualManager().create(STUDY, individual, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, individual, QueryOptions.empty(), sessionIdUser); List findingList = new ArrayList<>(); VariantAvro variantAvro = new VariantAvro("id1", null, "chr2", 1, 2, "", "", "+", null, 1, null, null, null); @@ -879,9 +879,9 @@ public void updateSecondaryFindings() throws CatalogException { .setInterpretation(new Interpretation() .setSecondaryFindings(findingList) ); - catalogManager.getClinicalAnalysisManager().create(STUDY, ca, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, ca, QueryOptions.empty(), sessionIdUser); - Interpretation interpretation = catalogManager.getInterpretationManager().get(STUDY, ca.getId() + ".1", QueryOptions.empty(), + Interpretation interpretation = catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(2, interpretation.getSecondaryFindings().size()); assertNotNull(interpretation.getStats()); @@ -905,7 +905,7 @@ public void updateSecondaryFindings() throws CatalogException { catalogManager.getInterpretationManager().update(STUDY, ca.getId(), ca.getId() + ".1", updateParams, null, options, sessionIdUser); interpretation = - catalogManager.getInterpretationManager().get(STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); + catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(3, interpretation.getSecondaryFindings().size()); assertEquals("method2", interpretation.getSecondaryFindings().get(2).getEvidences().get(0).getInterpretationMethodName()); assertEquals("id3", interpretation.getSecondaryFindings().get(2).getId()); @@ -932,7 +932,7 @@ public void updateSecondaryFindings() throws CatalogException { catalogManager.getInterpretationManager().update(STUDY, ca.getId(), ca.getId() + ".1", updateParams, null, options, sessionIdUser); interpretation = - catalogManager.getInterpretationManager().get(STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); + catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(1, interpretation.getSecondaryFindings().size()); assertEquals("method", interpretation.getSecondaryFindings().get(0).getEvidences().get(0).getInterpretationMethodName()); assertEquals("id2", interpretation.getSecondaryFindings().get(0).getId()); @@ -950,7 +950,7 @@ public void updateSecondaryFindings() throws CatalogException { catalogManager.getInterpretationManager().update(STUDY, ca.getId(), ca.getId() + ".1", updateParams, null, options, sessionIdUser); interpretation = - catalogManager.getInterpretationManager().get(STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); + catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(3, interpretation.getSecondaryFindings().size()); assertEquals("method", interpretation.getSecondaryFindings().get(0).getEvidences().get(0).getInterpretationMethodName()); assertEquals("id1", interpretation.getSecondaryFindings().get(0).getId()); @@ -975,7 +975,7 @@ public void updateSecondaryFindings() throws CatalogException { catalogManager.getInterpretationManager().update(STUDY, ca.getId(), ca.getId() + ".1", updateParams, null, options, sessionIdUser); interpretation = - catalogManager.getInterpretationManager().get(STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); + catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(3, interpretation.getSecondaryFindings().size()); assertEquals("method", interpretation.getSecondaryFindings().get(0).getEvidences().get(0).getInterpretationMethodName()); assertEquals("id1", interpretation.getSecondaryFindings().get(0).getId()); @@ -1026,7 +1026,7 @@ public void updateInterpretationComments() throws CatalogException { Individual individual = new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))); - catalogManager.getIndividualManager().create(STUDY, individual, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, individual, QueryOptions.empty(), sessionIdUser); ClinicalAnalysis clinicalAnalysis = new ClinicalAnalysis() .setId("Clinical") @@ -1036,7 +1036,7 @@ public void updateInterpretationComments() throws CatalogException { .setComments(Collections.singletonList(new ClinicalComment("", "My first comment", Arrays.asList("tag1", "tag2"), ""))) ); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); List commentParamList = new ArrayList<>(); commentParamList.add(new ClinicalCommentParam("My second comment", Arrays.asList("myTag"))); @@ -1048,7 +1048,7 @@ public void updateInterpretationComments() throws CatalogException { catalogManager.getInterpretationManager().update(STUDY, clinicalAnalysis.getId(), clinicalAnalysis.getId() + ".1", new InterpretationUpdateParams() .setComments(commentParamList), null, options, sessionIdUser); - OpenCGAResult interpretation = catalogManager.getInterpretationManager().get(STUDY, clinicalAnalysis.getId() + ".1", + OpenCGAResult interpretation = catalogManager.getInterpretationManager().get(organizationId, STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser); assertEquals(1, interpretation.getNumResults()); assertEquals(3, interpretation.first().getComments().size()); @@ -1076,7 +1076,7 @@ public void updateInterpretationComments() throws CatalogException { catalogManager.getInterpretationManager().update(STUDY, clinicalAnalysis.getId(), clinicalAnalysis.getId() + ".1", new InterpretationUpdateParams() .setComments(commentParamList), null, options, sessionIdUser); - interpretation = catalogManager.getInterpretationManager().get(STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser); + interpretation = catalogManager.getInterpretationManager().get(organizationId, STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser); assertEquals(1, interpretation.getNumResults()); assertEquals(3, interpretation.first().getComments().size()); assertEquals("user", interpretation.first().getComments().get(1).getAuthor()); @@ -1104,7 +1104,7 @@ public void updateInterpretationComments() throws CatalogException { catalogManager.getInterpretationManager().update(STUDY, clinicalAnalysis.getId(), clinicalAnalysis.getId() + ".1", new InterpretationUpdateParams() .setComments(commentParamList), null, options, sessionIdUser); - interpretation = catalogManager.getInterpretationManager().get(STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser); + interpretation = catalogManager.getInterpretationManager().get(organizationId, STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser); assertEquals(1, interpretation.getNumResults()); assertEquals(1, interpretation.first().getComments().size()); assertEquals("user", interpretation.first().getComments().get(0).getAuthor()); @@ -1122,7 +1122,7 @@ public void updateInterpretationComments() throws CatalogException { catalogManager.getInterpretationManager().update(STUDY, clinicalAnalysis.getId(), clinicalAnalysis.getId() + ".1", new InterpretationUpdateParams() .setComments(commentParamList), null, options, sessionIdUser); - interpretation = catalogManager.getInterpretationManager().get(STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser); + interpretation = catalogManager.getInterpretationManager().get(organizationId, STUDY, clinicalAnalysis.getId() + ".1", QueryOptions.empty(), sessionIdUser); assertEquals(1, interpretation.getNumResults()); assertEquals(0, interpretation.first().getComments().size()); @@ -1158,7 +1158,7 @@ public void assignPermissions() throws CatalogException { Account.AccountType.GUEST, opencgaToken); OpenCGAResult> aclResult = - catalogManager.getClinicalAnalysisManager().getAcls(STUDY, Collections.singletonList(clinicalAnalysis.getId()), "external", + catalogManager.getClinicalAnalysisManager().getAcls(organizationId, STUDY, Collections.singletonList(clinicalAnalysis.getId()), "external", false, sessionIdUser); assertEquals(1, aclResult.getNumResults()); assertEquals(1, aclResult.first().getAcl().size()); @@ -1187,10 +1187,10 @@ public void assignPermissions() throws CatalogException { assertNull(sAclResult.first().getAcl().get(0).getPermissions()); // Assign permissions to clinical analysis without propagating the permissions - catalogManager.getClinicalAnalysisManager().updateAcl(STUDY, Collections.singletonList(clinicalAnalysis.getId()), "external", + catalogManager.getClinicalAnalysisManager().updateAcl(organizationId, STUDY, Collections.singletonList(clinicalAnalysis.getId()), "external", new AclParams(ClinicalAnalysisPermissions.DELETE.name()), ParamUtils.AclAction.ADD, false, sessionIdUser); - aclResult = catalogManager.getClinicalAnalysisManager().getAcls(STUDY, + aclResult = catalogManager.getClinicalAnalysisManager().getAcls(organizationId, STUDY, Collections.singletonList(clinicalAnalysis.getId()), "external", false, sessionIdUser); assertEquals(1, aclResult.getNumResults()); assertEquals(3, aclResult.first().getAcl().get(0).getPermissions().size()); @@ -1217,11 +1217,11 @@ public void assignPermissions() throws CatalogException { assertNull(sAclResult.first().getAcl().get(0).getPermissions()); // Assign permissions to clinical analysis PROPAGATING the permissions - catalogManager.getClinicalAnalysisManager().updateAcl(STUDY, Collections.singletonList(clinicalAnalysis.getId()), "external", + catalogManager.getClinicalAnalysisManager().updateAcl(organizationId, STUDY, Collections.singletonList(clinicalAnalysis.getId()), "external", new AclParams(ClinicalAnalysisPermissions.DELETE.name()), ParamUtils.AclAction.ADD, true, sessionIdUser); - aclResult = catalogManager.getClinicalAnalysisManager().getAcls(STUDY, + aclResult = catalogManager.getClinicalAnalysisManager().getAcls(organizationId, STUDY, Collections.singletonList(clinicalAnalysis.getId()), "external", false, sessionIdUser); assertEquals(1, aclResult.getNumResults()); assertEquals(3, aclResult.first().getAcl().get(0).getPermissions().size()); @@ -1263,7 +1263,7 @@ public void createClinicalAnalysisTest() throws CatalogException { assertEquals(1, dummyEnvironment.first().getProband().getSamples().size()); assertEquals("sample2", dummyEnvironment.first().getProband().getSamples().get(0).getId()); - assertEquals(catalogManager.getSampleManager().get(STUDY, "sample2", SampleManager.INCLUDE_SAMPLE_IDS, sessionIdUser) + assertEquals(catalogManager.getSampleManager().get(organizationId, STUDY, "sample2", SampleManager.INCLUDE_SAMPLE_IDS, sessionIdUser) .first().getUid(), dummyEnvironment.first().getProband().getSamples().get(0).getUid()); dummyEnvironment = createDummyEnvironment(false, true); @@ -1281,11 +1281,11 @@ public void updateClinicalAnalysisTest() throws CatalogException { .setDescription("My description") .setPriority(new PriorityParam("URGENT")); - OpenCGAResult update = catalogManager.getClinicalAnalysisManager().update(STUDY, dummyEnvironment.first().getId(), + OpenCGAResult update = catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, dummyEnvironment.first().getId(), updateParams, QueryOptions.empty(), sessionIdUser); assertEquals(1, update.getNumUpdated()); - ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().get(STUDY, dummyEnvironment.first().getId(), QueryOptions.empty(), + ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, dummyEnvironment.first().getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals("My description", ca.getDescription()); assertEquals("URGENT", ca.getPriority().getId()); @@ -1293,7 +1293,7 @@ public void updateClinicalAnalysisTest() throws CatalogException { @Test public void updateCustomStatusTest() throws CatalogException { - Study study = catalogManager.getStudyManager().get(STUDY, QueryOptions.empty(), sessionIdUser).first(); + Study study = catalogManager.getStudyManager().get(organizationId, STUDY, QueryOptions.empty(), sessionIdUser).first(); ClinicalAnalysisStudyConfiguration configuration = study.getInternal().getConfiguration().getClinical(); DataResult dummyEnvironment = createDummyEnvironment(true, false); @@ -1302,11 +1302,11 @@ public void updateCustomStatusTest() throws CatalogException { ClinicalAnalysisUpdateParams updateParams = new ClinicalAnalysisUpdateParams() .setStatus(new StatusParam(status.getId())); - OpenCGAResult update = catalogManager.getClinicalAnalysisManager().update(STUDY, dummyEnvironment.first().getId(), + OpenCGAResult update = catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, dummyEnvironment.first().getId(), updateParams, QueryOptions.empty(), sessionIdUser); assertEquals(1, update.getNumUpdated()); - ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().get(STUDY, dummyEnvironment.first().getId(), QueryOptions.empty(), + ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, dummyEnvironment.first().getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(status.getId(), ca.getStatus().getId()); assertEquals(status.getDescription(), ca.getStatus().getDescription()); @@ -1315,7 +1315,7 @@ public void updateCustomStatusTest() throws CatalogException { @Test public void updateCustomPriorityTest() throws CatalogException { - Study study = catalogManager.getStudyManager().get(STUDY, QueryOptions.empty(), sessionIdUser).first(); + Study study = catalogManager.getStudyManager().get(organizationId, STUDY, QueryOptions.empty(), sessionIdUser).first(); ClinicalAnalysisStudyConfiguration configuration = study.getInternal().getConfiguration().getClinical(); DataResult dummyEnvironment = createDummyEnvironment(true, false); @@ -1324,11 +1324,11 @@ public void updateCustomPriorityTest() throws CatalogException { ClinicalAnalysisUpdateParams updateParams = new ClinicalAnalysisUpdateParams() .setPriority(new PriorityParam(priority.getId())); - OpenCGAResult update = catalogManager.getClinicalAnalysisManager().update(STUDY, dummyEnvironment.first().getId(), + OpenCGAResult update = catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, dummyEnvironment.first().getId(), updateParams, QueryOptions.empty(), sessionIdUser); assertEquals(1, update.getNumUpdated()); - ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().get(STUDY, dummyEnvironment.first().getId(), QueryOptions.empty(), + ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, dummyEnvironment.first().getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(priority.getId(), ca.getPriority().getId()); assertEquals(priority.getDescription(), ca.getPriority().getDescription()); @@ -1338,7 +1338,7 @@ public void updateCustomPriorityTest() throws CatalogException { @Test public void updateCustomFlagTest() throws CatalogException { - Study study = catalogManager.getStudyManager().get(STUDY, QueryOptions.empty(), sessionIdUser).first(); + Study study = catalogManager.getStudyManager().get(organizationId, STUDY, QueryOptions.empty(), sessionIdUser).first(); ClinicalAnalysisStudyConfiguration configuration = study.getInternal().getConfiguration().getClinical(); DataResult dummyEnvironment = createDummyEnvironment(true, false); @@ -1353,17 +1353,17 @@ public void updateCustomFlagTest() throws CatalogException { ClinicalAnalysisUpdateParams updateParams = new ClinicalAnalysisUpdateParams() .setFlags(Arrays.asList(new FlagValueParam(flag1.getId()), new FlagValueParam(flag1.getId()), new FlagValueParam(flag2.getId()))); - OpenCGAResult update = catalogManager.getClinicalAnalysisManager().update(STUDY, dummyEnvironment.first().getId(), + OpenCGAResult update = catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, dummyEnvironment.first().getId(), updateParams, options, sessionIdUser); assertEquals(1, update.getNumUpdated()); updateParams = new ClinicalAnalysisUpdateParams() .setFlags(Arrays.asList(new FlagValueParam(flag2.getId()), new FlagValueParam(flag3.getId()))); - update = catalogManager.getClinicalAnalysisManager().update(STUDY, dummyEnvironment.first().getId(), updateParams, options, + update = catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, dummyEnvironment.first().getId(), updateParams, options, sessionIdUser); assertEquals(1, update.getNumUpdated()); - ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().get(STUDY, dummyEnvironment.first().getId(), QueryOptions.empty(), + ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, dummyEnvironment.first().getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(3, ca.getFlags().size()); for (FlagAnnotation flag : ca.getFlags()) { @@ -1390,11 +1390,11 @@ public void updateCustomFlagTest() throws CatalogException { updateParams = new ClinicalAnalysisUpdateParams() .setFlags(Arrays.asList(new FlagValueParam(flag1.getId()), new FlagValueParam(flag2.getId()))); - update = catalogManager.getClinicalAnalysisManager().update(STUDY, dummyEnvironment.first().getId(), updateParams, options, + update = catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, dummyEnvironment.first().getId(), updateParams, options, sessionIdUser); assertEquals(1, update.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, dummyEnvironment.first().getId(), QueryOptions.empty(), + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, dummyEnvironment.first().getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(2, ca.getFlags().size()); assertEquals(flag1.getId(), ca.getFlags().get(0).getId()); @@ -1411,11 +1411,11 @@ public void updateCustomFlagTest() throws CatalogException { updateParams = new ClinicalAnalysisUpdateParams() .setFlags(Collections.singletonList(new FlagValueParam(flag1.getId()))); - update = catalogManager.getClinicalAnalysisManager().update(STUDY, dummyEnvironment.first().getId(), updateParams, options, + update = catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, dummyEnvironment.first().getId(), updateParams, options, sessionIdUser); assertEquals(1, update.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, dummyEnvironment.first().getId(), QueryOptions.empty(), + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, dummyEnvironment.first().getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(1, ca.getFlags().size()); assertEquals(flag2.getId(), ca.getFlags().get(0).getId()); @@ -1425,7 +1425,7 @@ public void updateCustomFlagTest() throws CatalogException { @Test public void updateCustomConsentTest() throws CatalogException { - Study study = catalogManager.getStudyManager().get(STUDY, QueryOptions.empty(), sessionIdUser).first(); + Study study = catalogManager.getStudyManager().get(organizationId, STUDY, QueryOptions.empty(), sessionIdUser).first(); ClinicalAnalysisStudyConfiguration configuration = study.getInternal().getConfiguration().getClinical(); DataResult dummyEnvironment = createDummyEnvironment(true, false); @@ -1439,11 +1439,11 @@ public void updateCustomConsentTest() throws CatalogException { ClinicalAnalysisUpdateParams updateParams = new ClinicalAnalysisUpdateParams() .setConsent(new ClinicalConsentAnnotationParam(Collections.singletonList( new ClinicalConsentAnnotationParam.ClinicalConsentParam(consents.get(1).getId(), ClinicalConsentParam.Value.YES)))); - OpenCGAResult update = catalogManager.getClinicalAnalysisManager().update(STUDY, dummyEnvironment.first().getId(), + OpenCGAResult update = catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, dummyEnvironment.first().getId(), updateParams, QueryOptions.empty(), sessionIdUser); assertEquals(1, update.getNumUpdated()); - ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().get(STUDY, dummyEnvironment.first().getId(), QueryOptions.empty(), + ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, dummyEnvironment.first().getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(consents.size(), ca.getConsent().getConsents().size()); assertNotNull(ca.getConsent().getDate()); @@ -1462,7 +1462,7 @@ public void updateCustomConsentTest() throws CatalogException { @Test public void updateInterpretationCustomStatusTest() throws CatalogException { - Study study = catalogManager.getStudyManager().get(STUDY, QueryOptions.empty(), sessionIdUser).first(); + Study study = catalogManager.getStudyManager().get(organizationId, STUDY, QueryOptions.empty(), sessionIdUser).first(); InterpretationStudyConfiguration configuration = study.getInternal().getConfiguration().getClinical().getInterpretation(); DataResult dummyEnvironment = createDummyEnvironment(true, true); @@ -1474,7 +1474,7 @@ public void updateInterpretationCustomStatusTest() throws CatalogException { dummyEnvironment.first().getInterpretation().getId(), updateParams, null, QueryOptions.empty(), sessionIdUser); assertEquals(1, update.getNumUpdated()); - Interpretation interpretation = catalogManager.getInterpretationManager().get(STUDY, + Interpretation interpretation = catalogManager.getInterpretationManager().get(organizationId, STUDY, dummyEnvironment.first().getInterpretation().getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(status.getId(), interpretation.getStatus().getId()); assertEquals(status.getDescription(), interpretation.getStatus().getDescription()); @@ -1487,7 +1487,7 @@ public void createInterpretationTest() throws CatalogException { catalogManager.getInterpretationManager().create(STUDY, ca.getId(), new Interpretation(), ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".1", ca.getInterpretation().getId()); @@ -1496,15 +1496,15 @@ public void createInterpretationTest() throws CatalogException { ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); catalogManager.getInterpretationManager().delete(STUDY, ca.getId(), Collections.singletonList(ca.getId() + ".1"), sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".2", ca.getInterpretation().getId()); assertEquals(0, ca.getSecondaryInterpretations().size()); - assertEquals(0, catalogManager.getInterpretationManager().search(STUDY, + assertEquals(0, catalogManager.getInterpretationManager().search(organizationId, STUDY, new Query(InterpretationDBAdaptor.QueryParams.ID.key(), ca.getId() + ".1"), QueryOptions.empty(), sessionIdUser) .getNumResults()); // Old interpretation was deleted - assertEquals(1, catalogManager.getInterpretationManager().search(STUDY, new Query() + assertEquals(1, catalogManager.getInterpretationManager().search(organizationId, STUDY, new Query() .append(InterpretationDBAdaptor.QueryParams.ID.key(), ca.getId() + ".1") .append(InterpretationDBAdaptor.QueryParams.DELETED.key(), true), QueryOptions.empty(), sessionIdUser) .getNumResults()); @@ -1512,7 +1512,7 @@ public void createInterpretationTest() throws CatalogException { // Interpretation2 should be moved to secondary interpretations catalogManager.getInterpretationManager().create(STUDY, ca.getId(), new Interpretation(), ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".3", ca.getInterpretation().getId()); assertEquals(1, ca.getSecondaryInterpretations().size()); @@ -1521,7 +1521,7 @@ public void createInterpretationTest() throws CatalogException { // Interpretation4 should be added to secondary interpretations catalogManager.getInterpretationManager().create(STUDY, ca.getId(), new Interpretation(), ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".3", ca.getInterpretation().getId()); assertEquals(2, ca.getSecondaryInterpretations().size()); @@ -1548,7 +1548,7 @@ public void clearPrimaryInterpretation() throws CatalogException { catalogManager.getInterpretationManager().create(STUDY, ca.getId(), interpretation, ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); - Interpretation interpretationResult = catalogManager.getInterpretationManager().get(STUDY, ca.getId() + ".1", + Interpretation interpretationResult = catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(ca.getId() + ".1", interpretationResult.getId()); assertEquals(1, interpretationResult.getVersion()); @@ -1560,7 +1560,7 @@ public void clearPrimaryInterpretation() throws CatalogException { assertEquals(1, interpretationResult.getComments().size()); catalogManager.getInterpretationManager().clear(STUDY, ca.getId(), Collections.singletonList(ca.getId() + ".1"), sessionIdUser); - interpretationResult = catalogManager.getInterpretationManager().get(STUDY, ca.getId() + ".1", QueryOptions.empty(), + interpretationResult = catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(ca.getId() + ".1", interpretationResult.getId()); assertEquals(2, interpretationResult.getVersion()); @@ -1587,7 +1587,7 @@ public void clearSecondaryInterpretation() throws CatalogException { catalogManager.getInterpretationManager().create(STUDY, ca.getId(), interpretation, ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); - Interpretation interpretationResult = catalogManager.getInterpretationManager().get(STUDY, ca.getId() + ".1", + Interpretation interpretationResult = catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(ca.getId() + ".1", interpretationResult.getId()); assertEquals(1, interpretationResult.getVersion()); @@ -1599,7 +1599,7 @@ public void clearSecondaryInterpretation() throws CatalogException { assertEquals(1, interpretationResult.getComments().size()); catalogManager.getInterpretationManager().clear(STUDY, ca.getId(), Collections.singletonList(ca.getId() + ".1"), sessionIdUser); - interpretationResult = catalogManager.getInterpretationManager().get(STUDY, ca.getId() + ".1", QueryOptions.empty(), + interpretationResult = catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(ca.getId() + ".1", interpretationResult.getId()); assertEquals(2, interpretationResult.getVersion()); @@ -1742,20 +1742,20 @@ public void searchInterpretationVersion() throws CatalogException { assertEquals(1, result.getNumUpdated()); QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, InterpretationDBAdaptor.QueryParams.VERSION.key()); - result = catalogManager.getInterpretationManager().get(STUDY, Collections.singletonList(ca.getId() + ".1"), + result = catalogManager.getInterpretationManager().get(organizationId, STUDY, Collections.singletonList(ca.getId() + ".1"), new Query(Constants.ALL_VERSIONS, true), options, false, sessionIdUser); assertEquals(2, result.getNumResults()); - result = catalogManager.getInterpretationManager().get(STUDY, Collections.singletonList(ca.getId() + ".1"), + result = catalogManager.getInterpretationManager().get(organizationId, STUDY, Collections.singletonList(ca.getId() + ".1"), new Query(InterpretationDBAdaptor.QueryParams.VERSION.key(), "1,2"), options, false, sessionIdUser); assertEquals(2, result.getNumResults()); - result = catalogManager.getInterpretationManager().get(STUDY, Collections.singletonList(ca.getId() + ".1"), + result = catalogManager.getInterpretationManager().get(organizationId, STUDY, Collections.singletonList(ca.getId() + ".1"), new Query(InterpretationDBAdaptor.QueryParams.VERSION.key(), "All"), options, false, sessionIdUser); assertEquals(2, result.getNumResults()); try { - catalogManager.getInterpretationManager().get(STUDY, Arrays.asList(ca.getId() + ".1", ca.getId() + ".2"), + catalogManager.getInterpretationManager().get(organizationId, STUDY, Arrays.asList(ca.getId() + ".1", ca.getId() + ".2"), new Query(Constants.ALL_VERSIONS, true), options, false, sessionIdUser); fail("The previous call should fail because it should not be possible to fetch all versions of multiple interpretations"); } catch (CatalogException e) { @@ -1763,7 +1763,7 @@ public void searchInterpretationVersion() throws CatalogException { } try { - catalogManager.getInterpretationManager().get(STUDY, Arrays.asList(ca.getId() + ".1", "interpretation2"), + catalogManager.getInterpretationManager().get(organizationId, STUDY, Arrays.asList(ca.getId() + ".1", "interpretation2"), new Query(InterpretationDBAdaptor.QueryParams.VERSION.key(), "1"), options, false, sessionIdUser); fail("The previous call should fail users cannot fetch a concrete version for multiple interpretations"); } catch (CatalogException e) { @@ -1797,7 +1797,7 @@ public void revertInterpretationVersion() throws CatalogException { // Current status Interpretation interpretation = - catalogManager.getInterpretationManager().get(STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); + catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(4, interpretation.getVersion()); assertEquals("user2", interpretation.getAnalyst().getId()); assertEquals(2, interpretation.getComments().size()); @@ -1824,7 +1824,7 @@ public void revertInterpretationVersion() throws CatalogException { assertEquals(1, result.getNumUpdated()); interpretation = - catalogManager.getInterpretationManager().get(STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); + catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(5, interpretation.getVersion()); assertEquals("user2", interpretation.getAnalyst().getId()); assertEquals(0, interpretation.getComments().size()); @@ -1833,7 +1833,7 @@ public void revertInterpretationVersion() throws CatalogException { assertEquals(1, result.getNumUpdated()); interpretation = - catalogManager.getInterpretationManager().get(STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); + catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(6, interpretation.getVersion()); assertEquals("user2", interpretation.getAnalyst().getId()); assertEquals(1, interpretation.getComments().size()); @@ -1844,7 +1844,7 @@ public void revertInterpretationVersion() throws CatalogException { assertEquals(1, result.getNumUpdated()); interpretation = - catalogManager.getInterpretationManager().get(STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); + catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getId() + ".1", QueryOptions.empty(), sessionIdUser).first(); assertEquals(7, interpretation.getVersion()); assertEquals("user2", interpretation.getAnalyst().getId()); assertEquals(2, interpretation.getComments().size()); @@ -1854,11 +1854,11 @@ public void revertInterpretationVersion() throws CatalogException { assertEquals("tag2", interpretation.getComments().get(1).getTags().get(0)); Query query = new Query(Constants.ALL_VERSIONS, true); - result = catalogManager.getInterpretationManager().get(STUDY, Collections.singletonList(ca.getId() + ".1"), query, + result = catalogManager.getInterpretationManager().get(organizationId, STUDY, Collections.singletonList(ca.getId() + ".1"), query, QueryOptions.empty(), false, sessionIdUser); assertEquals(7, result.getNumResults()); - ClinicalAnalysis clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), + ClinicalAnalysis clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(8, clinicalAnalysis.getAudit().size()); assertEquals(7, clinicalAnalysis.getInterpretation().getVersion()); @@ -1880,7 +1880,7 @@ public void updateInterpretationTest() throws CatalogException { catalogManager.getInterpretationManager().create(STUDY, ca.getId(), new Interpretation(), ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(5, ca.getAudit().size()); assertEquals(ClinicalAudit.Action.CREATE_INTERPRETATION, ca.getAudit().get(4).getAction()); @@ -1895,7 +1895,7 @@ public void updateInterpretationTest() throws CatalogException { params, null, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(6, ca.getAudit().size()); assertEquals(ClinicalAudit.Action.UPDATE_INTERPRETATION, ca.getAudit().get(5).getAction()); assertNotNull(ca.getInterpretation().getAnalyst()); @@ -1909,7 +1909,7 @@ public void updateInterpretationTest() throws CatalogException { sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(7, ca.getAudit().size()); assertEquals(ClinicalAudit.Action.UPDATE_INTERPRETATION, ca.getAudit().get(6).getAction()); assertEquals("my description", ca.getSecondaryInterpretations().get(1).getDescription()); @@ -1923,7 +1923,7 @@ public void updateInterpretationTest() throws CatalogException { catalogManager.getInterpretationManager().delete(STUDY, ca.getId(), Collections.singletonList(ca.getId() + ".1"), sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(10, ca.getAudit().size()); assertEquals(ClinicalAudit.Action.UPDATE_INTERPRETATION, ca.getAudit().get(7).getAction()); assertEquals(ClinicalAudit.Action.SWAP_INTERPRETATION, ca.getAudit().get(8).getAction()); @@ -1941,7 +1941,7 @@ public void updateInterpretationTest() throws CatalogException { ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(12, ca.getAudit().size()); assertEquals(ClinicalAudit.Action.UPDATE_INTERPRETATION, ca.getAudit().get(10).getAction()); @@ -1958,7 +1958,7 @@ public void updateInterpretationTest() throws CatalogException { ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".3", ca.getInterpretation().getId()); assertEquals(2, ca.getInterpretation().getVersion()); @@ -1973,7 +1973,7 @@ public void updateInterpretationTest() throws CatalogException { ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNull(ca.getInterpretation()); assertEquals(3, ca.getSecondaryInterpretations().size()); assertEquals(ca.getId() + ".2", ca.getSecondaryInterpretations().get(0).getId()); @@ -1987,7 +1987,7 @@ public void updateInterpretationTest() throws CatalogException { ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".2", ca.getInterpretation().getId()); assertEquals(1, ca.getInterpretation().getVersion()); @@ -2001,7 +2001,7 @@ public void updateInterpretationTest() throws CatalogException { ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNull(ca.getInterpretation()); assertEquals(3, ca.getSecondaryInterpretations().size()); assertEquals(ca.getId() + ".4", ca.getSecondaryInterpretations().get(0).getId()); @@ -2015,7 +2015,7 @@ public void updateInterpretationTest() throws CatalogException { ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".2", ca.getInterpretation().getId()); assertEquals(1, ca.getInterpretation().getVersion()); @@ -2029,7 +2029,7 @@ public void updateInterpretationTest() throws CatalogException { ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNull(ca.getInterpretation()); assertEquals(3, ca.getSecondaryInterpretations().size()); assertEquals(ca.getId() + ".4", ca.getSecondaryInterpretations().get(0).getId()); @@ -2043,7 +2043,7 @@ public void updateInterpretationTest() throws CatalogException { ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".2", ca.getInterpretation().getId()); assertEquals(1, ca.getInterpretation().getVersion()); @@ -2068,7 +2068,7 @@ public void updatePrimarySecondaryLockedInterpretationTest() throws CatalogExcep catalogManager.getInterpretationManager().create(STUDY, ca.getId(), new Interpretation().setLocked(true), ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertFalse(ca.getInterpretation().isLocked()); assertEquals(5, ca.getAudit().size()); @@ -2090,7 +2090,7 @@ public void updatePrimarySecondaryLockedInterpretationTest() throws CatalogExcep catalogManager.getInterpretationManager().delete(STUDY, ca.getId(), Collections.singletonList(ca.getId() + ".1"), sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(8, ca.getAudit().size()); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".3", ca.getInterpretation().getId()); @@ -2104,7 +2104,7 @@ public void updatePrimarySecondaryLockedInterpretationTest() throws CatalogExcep ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".4", ca.getInterpretation().getId()); assertEquals(2, ca.getSecondaryInterpretations().size()); @@ -2116,7 +2116,7 @@ public void updatePrimarySecondaryLockedInterpretationTest() throws CatalogExcep ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".3", ca.getInterpretation().getId()); assertEquals(2, ca.getSecondaryInterpretations().size()); @@ -2129,7 +2129,7 @@ public void updatePrimarySecondaryLockedInterpretationTest() throws CatalogExcep ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNull(ca.getInterpretation()); assertEquals(3, ca.getSecondaryInterpretations().size()); assertEquals(ca.getId() + ".2", ca.getSecondaryInterpretations().get(0).getId()); @@ -2142,7 +2142,7 @@ public void updatePrimarySecondaryLockedInterpretationTest() throws CatalogExcep ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".2", ca.getInterpretation().getId()); assertEquals(2, ca.getSecondaryInterpretations().size()); @@ -2155,7 +2155,7 @@ public void updatePrimarySecondaryLockedInterpretationTest() throws CatalogExcep ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNull(ca.getInterpretation()); assertEquals(3, ca.getSecondaryInterpretations().size()); assertEquals(ca.getId() + ".4", ca.getSecondaryInterpretations().get(0).getId()); @@ -2168,7 +2168,7 @@ public void updatePrimarySecondaryLockedInterpretationTest() throws CatalogExcep ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".2", ca.getInterpretation().getId()); assertEquals(2, ca.getSecondaryInterpretations().size()); @@ -2181,7 +2181,7 @@ public void updatePrimarySecondaryLockedInterpretationTest() throws CatalogExcep ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNull(ca.getInterpretation()); assertEquals(3, ca.getSecondaryInterpretations().size()); assertEquals(ca.getId() + ".4", ca.getSecondaryInterpretations().get(0).getId()); @@ -2194,7 +2194,7 @@ public void updatePrimarySecondaryLockedInterpretationTest() throws CatalogExcep ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumUpdated()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".2", ca.getInterpretation().getId()); assertEquals(2, ca.getSecondaryInterpretations().size()); @@ -2222,7 +2222,7 @@ public void deleteInterpretationTest() throws CatalogException { catalogManager.getInterpretationManager().update(STUDY, ca.getId(), ca.getId() + ".1", new InterpretationUpdateParams() .setDescription("my description"), null, QueryOptions.empty(), sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(ca.getInterpretation()); assertEquals(ca.getId() + ".1", ca.getInterpretation().getId()); assertEquals(3, ca.getSecondaryInterpretations().size()); @@ -2237,11 +2237,11 @@ public void deleteInterpretationTest() throws CatalogException { Query query = new Query() .append(InterpretationDBAdaptor.QueryParams.ID.key(), Arrays.asList(ca.getId() + ".1", ca.getId() + ".3")) .append(Constants.ALL_VERSIONS, true); - OpenCGAResult search = catalogManager.getInterpretationManager().search(STUDY, query, QueryOptions.empty(), + OpenCGAResult search = catalogManager.getInterpretationManager().search(organizationId, STUDY, query, QueryOptions.empty(), sessionIdUser); assertEquals(0, search.getNumResults()); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNull(ca.getInterpretation()); assertEquals(2, ca.getSecondaryInterpretations().size()); assertEquals(ca.getId() + ".2", ca.getSecondaryInterpretations().get(0).getId()); @@ -2249,14 +2249,14 @@ public void deleteInterpretationTest() throws CatalogException { query = new Query() .append(InterpretationDBAdaptor.QueryParams.ID.key(), Arrays.asList(ca.getId() + ".1", ca.getId() + ".3")); - OpenCGAResult result = catalogManager.getInterpretationManager().search(STUDY, query, QueryOptions.empty(), + OpenCGAResult result = catalogManager.getInterpretationManager().search(organizationId, STUDY, query, QueryOptions.empty(), sessionIdUser); assertEquals(0, result.getNumResults()); query = new Query() .append(InterpretationDBAdaptor.QueryParams.ID.key(), Arrays.asList(ca.getId() + ".1", ca.getId() + ".3")) .append(InterpretationDBAdaptor.QueryParams.DELETED.key(), true); - result = catalogManager.getInterpretationManager().search(STUDY, query, QueryOptions.empty(), sessionIdUser); + result = catalogManager.getInterpretationManager().search(organizationId, STUDY, query, QueryOptions.empty(), sessionIdUser); assertEquals(3, result.getNumResults()); } @@ -2265,7 +2265,7 @@ public void searchClinicalAnalysisByProband() throws CatalogException { createDummyEnvironment(true, false); createDummyEnvironment(false, false); - OpenCGAResult search = catalogManager.getClinicalAnalysisManager().search(STUDY, + OpenCGAResult search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, new Query(ParamConstants.CLINICAL_PROBAND_PARAM, "^chil"), new QueryOptions(QueryOptions.INCLUDE, ClinicalAnalysisDBAdaptor.QueryParams.PROBAND_ID.key()), sessionIdUser); assertEquals(2, search.getNumResults()); @@ -2278,12 +2278,12 @@ public void searchClinicalAnalysisByStatus() throws CatalogException { createDummyEnvironment(true, false); createDummyEnvironment(false, false); - OpenCGAResult search = catalogManager.getClinicalAnalysisManager().search(STUDY, + OpenCGAResult search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, new Query(ParamConstants.STATUS_PARAM, ClinicalAnalysisStatus.DONE), new QueryOptions(QueryOptions.INCLUDE, ClinicalAnalysisDBAdaptor.QueryParams.PROBAND_ID.key()), sessionIdUser); assertEquals(0, search.getNumResults()); - search = catalogManager.getClinicalAnalysisManager().search(STUDY, + search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, new Query(ParamConstants.STATUS_PARAM, ClinicalAnalysisStatus.READY_FOR_INTERPRETATION), new QueryOptions(), sessionIdUser); assertEquals(2, search.getNumResults()); @@ -2291,10 +2291,10 @@ public void searchClinicalAnalysisByStatus() throws CatalogException { assertEquals(ClinicalAnalysisStatus.READY_FOR_INTERPRETATION, result.getStatus().getId()); } - catalogManager.getClinicalAnalysisManager().update(STUDY, search.first().getId(), + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, search.first().getId(), new ClinicalAnalysisUpdateParams().setStatus(new StatusParam(ClinicalAnalysisStatus.REJECTED)), QueryOptions.empty(), sessionIdUser); - search = catalogManager.getClinicalAnalysisManager().search(STUDY, + search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, new Query(ParamConstants.STATUS_PARAM, ClinicalAnalysisStatus.READY_FOR_INTERPRETATION), new QueryOptions(), sessionIdUser); assertEquals(1, search.getNumResults()); @@ -2302,7 +2302,7 @@ public void searchClinicalAnalysisByStatus() throws CatalogException { assertEquals(ClinicalAnalysisStatus.READY_FOR_INTERPRETATION, result.getStatus().getId()); } - search = catalogManager.getClinicalAnalysisManager().search(STUDY, + search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, new Query(ParamConstants.STATUS_PARAM, ClinicalAnalysisStatus.REJECTED), new QueryOptions(), sessionIdUser); assertEquals(1, search.getNumResults()); @@ -2314,18 +2314,18 @@ public void searchClinicalAnalysisByStatus() throws CatalogException { @Test public void deleteClinicalAnalysisTest() throws CatalogException { DataResult dummyEnvironment = createDummyEnvironment(true, false); - OpenCGAResult delete = catalogManager.getClinicalAnalysisManager().delete(STUDY, + OpenCGAResult delete = catalogManager.getClinicalAnalysisManager().delete(organizationId, STUDY, Collections.singletonList(dummyEnvironment.first().getId()), null, sessionIdUser); assertEquals(1, delete.getNumDeleted()); - OpenCGAResult clinicalResult = catalogManager.getClinicalAnalysisManager().get(STUDY, + OpenCGAResult clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, Collections.singletonList(dummyEnvironment.first().getId()), new Query(ClinicalAnalysisDBAdaptor.QueryParams.DELETED.key(), true), new QueryOptions(), false, sessionIdUser); assertEquals(1, clinicalResult.getNumResults()); thrown.expect(CatalogException.class); thrown.expectMessage("not found"); - catalogManager.getClinicalAnalysisManager().get(STUDY, dummyEnvironment.first().getId(), new QueryOptions(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, dummyEnvironment.first().getId(), new QueryOptions(), sessionIdUser); } @Test @@ -2344,22 +2344,22 @@ public void deleteClinicalAnalysisWithEmptyInterpretations() throws CatalogExcep catalogManager.getInterpretationManager().create(STUDY, ca.getId(), new Interpretation(), ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); - catalogManager.getClinicalAnalysisManager().delete(STUDY, Collections.singletonList(ca.getId()), null, sessionIdUser); + catalogManager.getClinicalAnalysisManager().delete(organizationId, STUDY, Collections.singletonList(ca.getId()), null, sessionIdUser); assertEquals(0, - catalogManager.getClinicalAnalysisManager().search(STUDY, new Query(ClinicalAnalysisDBAdaptor.QueryParams.ID.key(), + catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, new Query(ClinicalAnalysisDBAdaptor.QueryParams.ID.key(), ca.getId()), QueryOptions.empty(), sessionIdUser).getNumResults()); assertEquals(0, - catalogManager.getInterpretationManager().search(STUDY, new Query(InterpretationDBAdaptor.QueryParams.ID.key(), + catalogManager.getInterpretationManager().search(organizationId, STUDY, new Query(InterpretationDBAdaptor.QueryParams.ID.key(), ca.getId() + ".1"), QueryOptions.empty(), sessionIdUser).getNumResults()); assertEquals(0, - catalogManager.getInterpretationManager().search(STUDY, new Query(InterpretationDBAdaptor.QueryParams.ID.key(), + catalogManager.getInterpretationManager().search(organizationId, STUDY, new Query(InterpretationDBAdaptor.QueryParams.ID.key(), ca.getId() + ".2"), QueryOptions.empty(), sessionIdUser).getNumResults()); assertEquals(0, - catalogManager.getInterpretationManager().search(STUDY, new Query(InterpretationDBAdaptor.QueryParams.ID.key(), + catalogManager.getInterpretationManager().search(organizationId, STUDY, new Query(InterpretationDBAdaptor.QueryParams.ID.key(), ca.getId() + ".3"), QueryOptions.empty(), sessionIdUser).getNumResults()); assertEquals(0, - catalogManager.getInterpretationManager().search(STUDY, new Query(InterpretationDBAdaptor.QueryParams.ID.key(), + catalogManager.getInterpretationManager().search(organizationId, STUDY, new Query(InterpretationDBAdaptor.QueryParams.ID.key(), ca.getId() + ".4"), QueryOptions.empty(), sessionIdUser).getNumResults()); } @@ -2396,27 +2396,27 @@ public void deleteClinicalAnalysisWithInterpretations() throws CatalogException )), null, QueryOptions.empty(), sessionIdUser); try { - catalogManager.getClinicalAnalysisManager().delete(STUDY, Collections.singletonList(ca.getId()), null, sessionIdUser); + catalogManager.getClinicalAnalysisManager().delete(organizationId, STUDY, Collections.singletonList(ca.getId()), null, sessionIdUser); fail("It should not allow deleting Clinical Analyses with interpretations containing primary findings"); } catch (CatalogException e) { assertTrue(e.getMessage().contains("findings")); } - OpenCGAResult delete = catalogManager.getClinicalAnalysisManager().delete(STUDY, Collections.singletonList(ca.getId()), + OpenCGAResult delete = catalogManager.getClinicalAnalysisManager().delete(organizationId, STUDY, Collections.singletonList(ca.getId()), new QueryOptions(Constants.FORCE, true), sessionIdUser); assertEquals(1, delete.getNumDeleted()); - OpenCGAResult clinicalResult = catalogManager.getClinicalAnalysisManager().get(STUDY, + OpenCGAResult clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, Collections.singletonList(ca.getId()), new Query(ClinicalAnalysisDBAdaptor.QueryParams.DELETED.key(), true), new QueryOptions(), false, sessionIdUser); assertEquals(1, clinicalResult.getNumResults()); - assertEquals(0, catalogManager.getInterpretationManager().search(STUDY, + assertEquals(0, catalogManager.getInterpretationManager().search(organizationId, STUDY, new Query(InterpretationDBAdaptor.QueryParams.ID.key(), Arrays.asList(ca.getId() + ".1", ca.getId() + ".2", ca.getId() + ".3", ca.getId() + ".4")), QueryOptions.empty(), sessionIdUser).getNumResults()); // Old interpretations were deleted - assertEquals(5, catalogManager.getInterpretationManager().search(STUDY, new Query() + assertEquals(5, catalogManager.getInterpretationManager().search(organizationId, STUDY, new Query() .append(InterpretationDBAdaptor.QueryParams.ID.key(), Arrays.asList(ca.getId() + ".1", ca.getId() + ".2", ca.getId() + ".3", ca.getId() + ".4")) .append(InterpretationDBAdaptor.QueryParams.DELETED.key(), true), QueryOptions.empty(), sessionIdUser) @@ -2427,21 +2427,21 @@ public void deleteClinicalAnalysisWithInterpretations() throws CatalogException public void deleteLockedClinicalAnalysis() throws CatalogException { ClinicalAnalysis ca = createDummyEnvironment(true, false).first(); - catalogManager.getClinicalAnalysisManager().update(STUDY, ca.getId(), new ClinicalAnalysisUpdateParams().setLocked(true), + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, ca.getId(), new ClinicalAnalysisUpdateParams().setLocked(true), QueryOptions.empty(), sessionIdUser); try { - catalogManager.getClinicalAnalysisManager().delete(STUDY, Collections.singletonList(ca.getId()), null, sessionIdUser); + catalogManager.getClinicalAnalysisManager().delete(organizationId, STUDY, Collections.singletonList(ca.getId()), null, sessionIdUser); fail("It should not allow deleting locked Clinical Analyses"); } catch (CatalogException e) { assertTrue(e.getMessage().contains("locked")); } - OpenCGAResult delete = catalogManager.getClinicalAnalysisManager().delete(STUDY, Collections.singletonList(ca.getId()), + OpenCGAResult delete = catalogManager.getClinicalAnalysisManager().delete(organizationId, STUDY, Collections.singletonList(ca.getId()), new QueryOptions(Constants.FORCE, true), sessionIdUser); assertEquals(1, delete.getNumDeleted()); - OpenCGAResult clinicalResult = catalogManager.getClinicalAnalysisManager().get(STUDY, + OpenCGAResult clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, Collections.singletonList(ca.getId()), new Query(ClinicalAnalysisDBAdaptor.QueryParams.DELETED.key(), true), new QueryOptions(), false, sessionIdUser); assertEquals(1, clinicalResult.getNumResults()); @@ -2452,17 +2452,17 @@ public void searchByDisorderTest() throws CatalogException { DataResult dummyEnvironment = createDummyEnvironment(true, false); ClinicalAnalysisUpdateParams updateParams = new ClinicalAnalysisUpdateParams() .setDisorder(new DisorderReferenceParam("dis1")); - catalogManager.getClinicalAnalysisManager().update(STUDY, dummyEnvironment.first().getId(), updateParams, QueryOptions.empty(), + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, dummyEnvironment.first().getId(), updateParams, QueryOptions.empty(), sessionIdUser); createDummyEnvironment(false, false); - OpenCGAResult result = catalogManager.getClinicalAnalysisManager().search(STUDY, + OpenCGAResult result = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, new Query(ParamConstants.CLINICAL_DISORDER_PARAM, "dis1"), QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(dummyEnvironment.first().getId(), result.first().getId()); - result = catalogManager.getClinicalAnalysisManager().search(STUDY, new Query(), QueryOptions.empty(), sessionIdUser); + result = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, new Query(), QueryOptions.empty(), sessionIdUser); assertEquals(2, result.getNumResults()); } @@ -2473,9 +2473,9 @@ public void updateDisorder() throws CatalogException { ClinicalAnalysisUpdateParams updateParams = new ClinicalAnalysisUpdateParams() .setDisorder(new DisorderReferenceParam("dis1")); - catalogManager.getClinicalAnalysisManager().update(STUDY, dummyEnvironment.first().getId(), updateParams, QueryOptions.empty(), + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, dummyEnvironment.first().getId(), updateParams, QueryOptions.empty(), sessionIdUser); - OpenCGAResult result1 = catalogManager.getClinicalAnalysisManager().get(STUDY, dummyEnvironment.first().getId(), + OpenCGAResult result1 = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, dummyEnvironment.first().getId(), new QueryOptions(), sessionIdUser); assertEquals("dis1", result1.first().getDisorder().getId()); @@ -2485,7 +2485,7 @@ public void updateDisorder() throws CatalogException { .setDisorder(new DisorderReferenceParam("non_existing")); thrown.expect(CatalogException.class); thrown.expectMessage("proband disorders"); - catalogManager.getClinicalAnalysisManager().update(STUDY, dummyEnvironment.first().getId(), updateParams, QueryOptions.empty(), + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, dummyEnvironment.first().getId(), updateParams, QueryOptions.empty(), sessionIdUser); } @@ -2514,7 +2514,7 @@ public void checkFamilyMembersOrder() throws CatalogException { .setDueDate("20180510100000") .setProband(new Individual().setId("child1")); clinicalAnalysis.setFamily(dummyFamily.first()); - DataResult clinicalAnalysisDataResult = catalogManager.getClinicalAnalysisManager().create(STUDY, + DataResult clinicalAnalysisDataResult = catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertTrue(clinicalAnalysisDataResult.first().getFamily().getMembers().stream().map(Individual::getId).collect(Collectors.toList()) @@ -2526,7 +2526,7 @@ public void checkFamilyMembersOrder() throws CatalogException { @Test public void createClinicalAnalysisWithPanels() throws CatalogException { catalogManager.getPanelManager().importFromSource(STUDY, "gene-census", "", sessionIdUser); - Panel panel = catalogManager.getPanelManager().search(STUDY, new Query(), QueryOptions.empty(), sessionIdUser).first(); + Panel panel = catalogManager.getPanelManager().search(organizationId, STUDY, new Query(), QueryOptions.empty(), sessionIdUser).first(); DataResult dummyFamily = createDummyFamily(); // Leave only sample2 for child1 in family @@ -2549,7 +2549,7 @@ public void createClinicalAnalysisWithPanels() throws CatalogException { .setFamily(dummyFamily.first()) .setProband(new Individual().setId("child1")); - ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, INCLUDE_RESULT, + ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser).first(); assertEquals(1, ca.getPanels().size()); @@ -2562,7 +2562,7 @@ public void createClinicalAnalysisWithPanels() throws CatalogException { @Test public void createInterpretationWithPanels() throws CatalogException { catalogManager.getPanelManager().importFromSource(STUDY, "gene-census", "", sessionIdUser); - Panel panel = catalogManager.getPanelManager().search(STUDY, new Query(), QueryOptions.empty(), sessionIdUser).first(); + Panel panel = catalogManager.getPanelManager().search(organizationId, STUDY, new Query(), QueryOptions.empty(), sessionIdUser).first(); ClinicalAnalysis ca = createDummyEnvironment(true, false).first(); @@ -2571,7 +2571,7 @@ public void createInterpretationWithPanels() throws CatalogException { interpretation = catalogManager.getInterpretationManager().create(STUDY, ca.getId(), interpretation, ParamUtils.SaveInterpretationAs.PRIMARY, INCLUDE_RESULT, sessionIdUser).first(); - interpretation = catalogManager.getInterpretationManager().get(STUDY, interpretation.getId(), QueryOptions.empty(), sessionIdUser) + interpretation = catalogManager.getInterpretationManager().get(organizationId, STUDY, interpretation.getId(), QueryOptions.empty(), sessionIdUser) .first(); assertEquals(1, interpretation.getPanels().size()); @@ -2581,7 +2581,7 @@ public void createInterpretationWithPanels() throws CatalogException { @Test public void updatePanelsInClinicalAnalysis() throws CatalogException { catalogManager.getPanelManager().importFromSource(STUDY, "gene-census", "", sessionIdUser); - Panel panel = catalogManager.getPanelManager().search(STUDY, new Query(), QueryOptions.empty(), sessionIdUser).first(); + Panel panel = catalogManager.getPanelManager().search(organizationId, STUDY, new Query(), QueryOptions.empty(), sessionIdUser).first(); DataResult dummyFamily = createDummyFamily(); // Leave only sample2 for child1 in family @@ -2604,12 +2604,12 @@ public void updatePanelsInClinicalAnalysis() throws CatalogException { .setProband(new Individual().setId("child1")); // Create without a panel and update the panel - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser).first(); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser).first(); + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams().setPanels(Collections.singletonList(new PanelReferenceParam(panel.getId()))), QueryOptions.empty(), sessionIdUser); - ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), + ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(1, ca.getPanels().size()); @@ -2644,7 +2644,7 @@ public void testQueriesInFamilyCase() throws CatalogException { .setDueDate("20180510100000") .setProband(new Individual().setId("child1")); clinicalAnalysis.setFamily(dummyFamily.first()); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); catalogManager.getFamilyManager().update(STUDY, dummyFamily.first().getId(), new FamilyUpdateParams() .setId("familyId"), QueryOptions.empty(), sessionIdUser); @@ -2652,33 +2652,33 @@ public void testQueriesInFamilyCase() throws CatalogException { QueryOptions includeClinicalIds = ClinicalAnalysisManager.INCLUDE_CLINICAL_IDS; // Query by members Query query = new Query(ClinicalAnalysisDBAdaptor.QueryParams.INDIVIDUAL.key(), "child3"); - OpenCGAResult search = catalogManager.getClinicalAnalysisManager().search(STUDY, query, includeClinicalIds, + OpenCGAResult search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, query, includeClinicalIds, sessionIdUser); assertEquals(1, search.getNumResults()); query = new Query(ClinicalAnalysisDBAdaptor.QueryParams.INDIVIDUAL.key(), "child1"); - search = catalogManager.getClinicalAnalysisManager().search(STUDY, query, includeClinicalIds, sessionIdUser); + search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, query, includeClinicalIds, sessionIdUser); assertEquals(1, search.getNumResults()); query = new Query(ClinicalAnalysisDBAdaptor.QueryParams.INDIVIDUAL.key(), "child4"); - search = catalogManager.getClinicalAnalysisManager().search(STUDY, query, includeClinicalIds, sessionIdUser); + search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, query, includeClinicalIds, sessionIdUser); assertEquals(0, search.getNumResults()); // Query by samples query = new Query(ParamConstants.CLINICAL_SAMPLE_PARAM, "sample2"); - search = catalogManager.getClinicalAnalysisManager().search(STUDY, query, includeClinicalIds, sessionIdUser); + search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, query, includeClinicalIds, sessionIdUser); assertEquals(1, search.getNumResults()); query = new Query(ParamConstants.CLINICAL_SAMPLE_PARAM, "sample5"); - search = catalogManager.getClinicalAnalysisManager().search(STUDY, query, includeClinicalIds, sessionIdUser); + search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, query, includeClinicalIds, sessionIdUser); assertEquals(1, search.getNumResults()); query = new Query(ParamConstants.CLINICAL_SAMPLE_PARAM, "sample4"); - search = catalogManager.getClinicalAnalysisManager().search(STUDY, query, includeClinicalIds, sessionIdUser); + search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, query, includeClinicalIds, sessionIdUser); assertEquals(0, search.getNumResults()); query = new Query(ClinicalAnalysisDBAdaptor.QueryParams.FAMILY.key(), "familyId"); - search = catalogManager.getClinicalAnalysisManager().search(STUDY, query, includeClinicalIds, sessionIdUser); + search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, query, includeClinicalIds, sessionIdUser); assertEquals(1, search.getNumResults()); } @@ -2688,13 +2688,13 @@ public void testQueriesInCancerCase() throws CatalogException { sample.setSomatic(true); Individual individual = DummyModelUtils.getDummyIndividual("individual", SexOntologyTermAnnotation.initMale(), Collections.singletonList(sample), null, null); - catalogManager.getIndividualManager().create(STUDY, individual, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, individual, QueryOptions.empty(), sessionIdUser); ClinicalAnalysis clinicalAnalysis = new ClinicalAnalysis() .setId("analysis").setDescription("My description").setType(ClinicalAnalysis.Type.CANCER) .setDueDate("20180510100000") .setProband(new Individual().setId(individual.getId())); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); // Update to force a version increment and therefore, an update over the case catalogManager.getSampleManager().update(STUDY, sample.getId(), new SampleUpdateParams().setDescription("descr"), @@ -2703,13 +2703,13 @@ public void testQueriesInCancerCase() throws CatalogException { QueryOptions includeClinicalIds = ClinicalAnalysisManager.INCLUDE_CLINICAL_IDS; // Query by members Query query = new Query(ClinicalAnalysisDBAdaptor.QueryParams.INDIVIDUAL.key(), "individual"); - OpenCGAResult search = catalogManager.getClinicalAnalysisManager().search(STUDY, query, includeClinicalIds, + OpenCGAResult search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, query, includeClinicalIds, sessionIdUser); assertEquals(1, search.getNumResults()); assertEquals(clinicalAnalysis.getId(), search.first().getId()); query = new Query(ParamConstants.CLINICAL_SAMPLE_PARAM, "sample"); - search = catalogManager.getClinicalAnalysisManager().search(STUDY, query, includeClinicalIds, sessionIdUser); + search = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, query, includeClinicalIds, sessionIdUser); assertEquals(1, search.getNumResults()); assertEquals(clinicalAnalysis.getId(), search.first().getId()); } @@ -2741,7 +2741,7 @@ public void sampleNotFoundInMember() throws CatalogException { clinicalAnalysis.setFamily(dummyFamily.first()); thrown.expect(CatalogException.class); thrown.expectMessage("could not be found in member"); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); } @Test @@ -2760,7 +2760,7 @@ public void checkMoreThanOneSample() throws CatalogException { clinicalAnalysis.setFamily(dummyFamily.first()); thrown.expect(CatalogException.class); thrown.expectMessage("More than one sample"); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); } @Test @@ -2771,7 +2771,7 @@ public void createClinicalAnalysisWithoutFamily() throws CatalogException { thrown.expect(CatalogException.class); thrown.expectMessage("missing"); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); } @Test @@ -2782,7 +2782,7 @@ public void createClinicalAnalysisWithoutProband() throws CatalogException { thrown.expect(CatalogException.class); thrown.expectMessage("missing"); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); } @Test @@ -2793,13 +2793,13 @@ public void createClinicalAnalysisWithoutType() throws CatalogException { thrown.expect(CatalogException.class); thrown.expectMessage("missing"); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); } private List createPanels(int nPanels) throws CatalogException { List panelList = new ArrayList<>(nPanels); for (int i = 0; i < nPanels; i++) { - panelList.add(catalogManager.getPanelManager().create(STUDY, new Panel().setId("panel" + i), INCLUDE_RESULT, + panelList.add(catalogManager.getPanelManager().create(organizationId, STUDY, new Panel().setId("panel" + i), INCLUDE_RESULT, sessionIdUser).first()); } return panelList; @@ -2808,7 +2808,7 @@ private List createPanels(int nPanels) throws CatalogException { @Test public void createClinicalAnalysisWithPanelsTest() throws CatalogException { List panels = createPanels(2); - Individual proband = catalogManager.getIndividualManager().create(STUDY, + Individual proband = catalogManager.getIndividualManager().create(organizationId, STUDY, new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))), @@ -2821,7 +2821,7 @@ public void createClinicalAnalysisWithPanelsTest() throws CatalogException { .setPanels(panels); OpenCGAResult result = - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(2, result.first().getPanels().size()); for (Panel panel : result.first().getPanels()) { @@ -2838,7 +2838,7 @@ public void createClinicalAnalysisWithPanelsTest() throws CatalogException { @Test public void fetchInterpretationWithFullPanelInformationTest() throws CatalogException { List panels = createPanels(2); - Individual proband = catalogManager.getIndividualManager().create(STUDY, + Individual proband = catalogManager.getIndividualManager().create(organizationId, STUDY, new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))), @@ -2849,9 +2849,9 @@ public void fetchInterpretationWithFullPanelInformationTest() throws CatalogExce .setProband(proband) .setPanels(panels); OpenCGAResult result = - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); - Interpretation interpretation = catalogManager.getInterpretationManager().search(STUDY, + Interpretation interpretation = catalogManager.getInterpretationManager().search(organizationId, STUDY, new Query(InterpretationDBAdaptor.QueryParams.CLINICAL_ANALYSIS_ID.key(), clinicalAnalysis.getId()), QueryOptions.empty(), sessionIdUser).first(); assertEquals(2, interpretation.getPanels().size()); @@ -2864,7 +2864,7 @@ public void fetchInterpretationWithFullPanelInformationTest() throws CatalogExce @Test public void updatePanelsActionTest() throws CatalogException { List panels = createPanels(5); - Individual proband = catalogManager.getIndividualManager().create(STUDY, + Individual proband = catalogManager.getIndividualManager().create(organizationId, STUDY, new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))), @@ -2877,17 +2877,17 @@ public void updatePanelsActionTest() throws CatalogException { .setProband(proband); OpenCGAResult result = - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(2, result.first().getPanels().size()); Map actionMap = new HashMap<>(); actionMap.put(ClinicalAnalysisDBAdaptor.QueryParams.PANELS.key(), ParamUtils.BasicUpdateAction.ADD); QueryOptions options = new QueryOptions(Constants.ACTIONS, actionMap); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanels(Collections.singletonList(new PanelReferenceParam(panels.get(2).getId()))), options, sessionIdUser); - result = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); + result = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(3, result.first().getPanels().size()); assertTrue(panels.subList(0, 3).stream().map(Panel::getId).collect(Collectors.toList()).containsAll( @@ -2896,13 +2896,13 @@ public void updatePanelsActionTest() throws CatalogException { actionMap = new HashMap<>(); actionMap.put(ClinicalAnalysisDBAdaptor.QueryParams.PANELS.key(), ParamUtils.BasicUpdateAction.REMOVE); options = new QueryOptions(Constants.ACTIONS, actionMap); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanels(Arrays.asList( new PanelReferenceParam(panels.get(0).getId()), new PanelReferenceParam(panels.get(2).getId())) ), options, sessionIdUser); - result = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); + result = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(1, result.first().getPanels().size()); assertEquals(panels.get(1).getId(), result.first().getPanels().get(0).getId()); @@ -2910,13 +2910,13 @@ public void updatePanelsActionTest() throws CatalogException { actionMap = new HashMap<>(); actionMap.put(ClinicalAnalysisDBAdaptor.QueryParams.PANELS.key(), ParamUtils.BasicUpdateAction.SET); options = new QueryOptions(Constants.ACTIONS, actionMap); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanels(Arrays.asList( new PanelReferenceParam(panels.get(3).getId()), new PanelReferenceParam(panels.get(4).getId())) ), options, sessionIdUser); - result = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); + result = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(2, result.first().getPanels().size()); assertTrue(panels.subList(3, 5).stream().map(Panel::getId).collect(Collectors.toList()).containsAll( @@ -2927,7 +2927,7 @@ public void updatePanelsActionTest() throws CatalogException { @Test public void updateInterpretationPanelsActionTest() throws CatalogException { List panels = createPanels(5); - Individual proband = catalogManager.getIndividualManager().create(STUDY, + Individual proband = catalogManager.getIndividualManager().create(organizationId, STUDY, new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))), @@ -2940,7 +2940,7 @@ public void updateInterpretationPanelsActionTest() throws CatalogException { .setProband(proband); OpenCGAResult result = - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(0, result.first().getPanels().size()); @@ -3008,7 +3008,7 @@ intepretationId, new InterpretationUpdateParams() @Test public void updatePanelsAndPanelLockFromClinicalAnalysisTest() throws CatalogException { List panels = createPanels(2); - Individual proband = catalogManager.getIndividualManager().create(STUDY, + Individual proband = catalogManager.getIndividualManager().create(organizationId, STUDY, new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))), @@ -3020,7 +3020,7 @@ public void updatePanelsAndPanelLockFromClinicalAnalysisTest() throws CatalogExc .setProband(proband); OpenCGAResult result = - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, true, INCLUDE_RESULT, sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, true, INCLUDE_RESULT, sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(0, result.first().getPanels().size()); assertFalse(result.first().isPanelLock()); @@ -3030,7 +3030,7 @@ public void updatePanelsAndPanelLockFromClinicalAnalysisTest() throws CatalogExc QueryOptions updateOptions = new QueryOptions(Constants.ACTIONS, actionMap); try { - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanels(panels.stream().map(p -> new PanelReferenceParam(p.getId())).collect(Collectors.toList())) .setPanelLock(true), updateOptions, sessionIdUser); @@ -3039,32 +3039,32 @@ public void updatePanelsAndPanelLockFromClinicalAnalysisTest() throws CatalogExc assertTrue(e.getMessage().contains("not allowed")); } - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanels(panels.stream().map(p -> new PanelReferenceParam(p.getId())).collect(Collectors.toList())), updateOptions, sessionIdUser); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanelLock(true), updateOptions, sessionIdUser); - result = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); + result = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(2, result.first().getPanels().size()); assertTrue(result.first().isPanelLock()); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanels(Collections.singletonList(new PanelReferenceParam(panels.get(0).getId()))) .setPanelLock(false), updateOptions, sessionIdUser); - result = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); + result = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(1, result.first().getPanels().size()); assertFalse(result.first().isPanelLock()); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanelLock(true), updateOptions, sessionIdUser); thrown.expect(CatalogException.class); thrown.expectMessage("panelLock"); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanels(panels.stream().map(p -> new PanelReferenceParam(p.getId())).collect(Collectors.toList())), updateOptions, sessionIdUser); } @@ -3072,7 +3072,7 @@ public void updatePanelsAndPanelLockFromClinicalAnalysisTest() throws CatalogExc @Test public void updatePanelsAndPanelLockFromClinicalAnalysisWithInterpretationTest() throws CatalogException { List panels = createPanels(2); - Individual proband = catalogManager.getIndividualManager().create(STUDY, + Individual proband = catalogManager.getIndividualManager().create(organizationId, STUDY, new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))), @@ -3084,14 +3084,14 @@ public void updatePanelsAndPanelLockFromClinicalAnalysisWithInterpretationTest() .setProband(proband); OpenCGAResult result = - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, null, INCLUDE_RESULT, sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, null, INCLUDE_RESULT, sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(0, result.first().getPanels().size()); assertFalse(result.first().isPanelLock()); thrown.expect(CatalogException.class); thrown.expectMessage("not allowed"); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanels(panels.stream().map(p -> new PanelReferenceParam(p.getId())).collect(Collectors.toList())) .setPanelLock(true), QueryOptions.empty(), sessionIdUser); @@ -3100,7 +3100,7 @@ public void updatePanelsAndPanelLockFromClinicalAnalysisWithInterpretationTest() @Test public void setPanelLockWithInterpretationWithNoPanelsTest() throws CatalogException { List panels = createPanels(2); - Individual proband = catalogManager.getIndividualManager().create(STUDY, + Individual proband = catalogManager.getIndividualManager().create(organizationId, STUDY, new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))), @@ -3112,21 +3112,21 @@ public void setPanelLockWithInterpretationWithNoPanelsTest() throws CatalogExcep .setProband(proband); OpenCGAResult result = - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, null, INCLUDE_RESULT, sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, null, INCLUDE_RESULT, sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(0, result.first().getPanels().size()); assertFalse(result.first().isPanelLock()); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanels(panels.stream().map(p -> new PanelReferenceParam(p.getId())).collect(Collectors.toList())), QueryOptions.empty(), sessionIdUser); - clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); + clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(2, clinicalAnalysis.getPanels().size()); assertEquals(0, clinicalAnalysis.getInterpretation().getPanels().size()); thrown.expect(CatalogException.class); thrown.expectMessage("any of the case panels"); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanelLock(true), QueryOptions.empty(), sessionIdUser); } @@ -3134,7 +3134,7 @@ public void setPanelLockWithInterpretationWithNoPanelsTest() throws CatalogExcep @Test public void setPanelLockWithInterpretationWithPanelSubsetTest() throws CatalogException { List panels = createPanels(2); - Individual proband = catalogManager.getIndividualManager().create(STUDY, + Individual proband = catalogManager.getIndividualManager().create(organizationId, STUDY, new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))), @@ -3146,15 +3146,15 @@ public void setPanelLockWithInterpretationWithPanelSubsetTest() throws CatalogEx .setProband(proband); OpenCGAResult result = - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, null, INCLUDE_RESULT, sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, null, INCLUDE_RESULT, sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(0, result.first().getPanels().size()); assertFalse(result.first().isPanelLock()); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanels(panels.stream().map(p -> new PanelReferenceParam(p.getId())).collect(Collectors.toList())), QueryOptions.empty(), sessionIdUser); - clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); + clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(2, clinicalAnalysis.getPanels().size()); assertEquals(0, clinicalAnalysis.getInterpretation().getPanels().size()); @@ -3162,15 +3162,15 @@ public void setPanelLockWithInterpretationWithPanelSubsetTest() throws CatalogEx new InterpretationUpdateParams() .setPanels(Collections.singletonList(new PanelReferenceParam(panels.get(0).getId()))), null, QueryOptions.empty(), sessionIdUser); - clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); + clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); assertFalse(clinicalAnalysis.isPanelLock()); assertEquals(2, clinicalAnalysis.getPanels().size()); assertEquals(1, clinicalAnalysis.getInterpretation().getPanels().size()); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanelLock(true), QueryOptions.empty(), sessionIdUser); - clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); + clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); assertTrue(clinicalAnalysis.isPanelLock()); assertEquals(2, clinicalAnalysis.getPanels().size()); assertEquals(1, clinicalAnalysis.getInterpretation().getPanels().size()); @@ -3179,7 +3179,7 @@ public void setPanelLockWithInterpretationWithPanelSubsetTest() throws CatalogEx @Test public void setPanelLockWithInterpretationWithDifferentPanelsTest() throws CatalogException { List panels = createPanels(2); - Individual proband = catalogManager.getIndividualManager().create(STUDY, + Individual proband = catalogManager.getIndividualManager().create(organizationId, STUDY, new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))), @@ -3191,15 +3191,15 @@ public void setPanelLockWithInterpretationWithDifferentPanelsTest() throws Catal .setProband(proband); OpenCGAResult result = - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, null, INCLUDE_RESULT, sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, null, INCLUDE_RESULT, sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(0, result.first().getPanels().size()); assertFalse(result.first().isPanelLock()); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanels(Collections.singletonList(new PanelReferenceParam(panels.get(0).getId()))), QueryOptions.empty(), sessionIdUser); - clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); + clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(1, clinicalAnalysis.getPanels().size()); assertEquals(0, clinicalAnalysis.getInterpretation().getPanels().size()); @@ -3207,13 +3207,13 @@ public void setPanelLockWithInterpretationWithDifferentPanelsTest() throws Catal new InterpretationUpdateParams() .setPanels(panels.stream().map(p -> new PanelReferenceParam(p.getId())).collect(Collectors.toList())), null, QueryOptions.empty(), sessionIdUser); - clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); + clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(1, clinicalAnalysis.getPanels().size()); assertEquals(2, clinicalAnalysis.getInterpretation().getPanels().size()); thrown.expect(CatalogException.class); thrown.expectMessage("not defined by the case"); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanelLock(true), QueryOptions.empty(), sessionIdUser); } @@ -3221,7 +3221,7 @@ public void setPanelLockWithInterpretationWithDifferentPanelsTest() throws Catal @Test public void updatePanelsFromClinicalAnalysisWithPanelLockTest() throws CatalogException { List panels = createPanels(3); - Individual proband = catalogManager.getIndividualManager().create(STUDY, + Individual proband = catalogManager.getIndividualManager().create(organizationId, STUDY, new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))), @@ -3234,7 +3234,7 @@ public void updatePanelsFromClinicalAnalysisWithPanelLockTest() throws CatalogEx .setPanels(panels.subList(0, 2)); OpenCGAResult result = - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(2, result.first().getPanels().size()); assertFalse(result.first().isPanelLock()); @@ -3244,14 +3244,14 @@ public void updatePanelsFromClinicalAnalysisWithPanelLockTest() throws CatalogEx assertEquals(2, interpretation.getPanels().size()); // Set panelLock to true - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanelLock(true), QueryOptions.empty(), sessionIdUser); - clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); + clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); assertTrue(clinicalAnalysis.isPanelLock()); thrown.expect(CatalogException.class); thrown.expectMessage("panelLock"); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanels(Collections.singletonList(new PanelReferenceParam(panels.get(2).getId()))), QueryOptions.empty(), sessionIdUser); } @@ -3259,7 +3259,7 @@ public void updatePanelsFromClinicalAnalysisWithPanelLockTest() throws CatalogEx @Test public void updatePanelLockWithDifferentPanels() throws CatalogException { List panels = createPanels(3); - Individual proband = catalogManager.getIndividualManager().create(STUDY, + Individual proband = catalogManager.getIndividualManager().create(organizationId, STUDY, new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))), @@ -3272,7 +3272,7 @@ public void updatePanelLockWithDifferentPanels() throws CatalogException { .setPanels(panels.subList(0, 2)); OpenCGAResult result = - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(2, result.first().getPanels().size()); assertFalse(result.first().isPanelLock()); @@ -3282,15 +3282,15 @@ public void updatePanelLockWithDifferentPanels() throws CatalogException { assertEquals(2, interpretation.getPanels().size()); // Set panelLock to true - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanelLock(true), QueryOptions.empty(), sessionIdUser); - clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); + clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); assertTrue(clinicalAnalysis.isPanelLock()); // Set panelLock to false - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanelLock(false), QueryOptions.empty(), sessionIdUser); - clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); + clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); assertFalse(clinicalAnalysis.isPanelLock()); Map actionMap = new HashMap<>(); @@ -3299,23 +3299,23 @@ public void updatePanelLockWithDifferentPanels() throws CatalogException { catalogManager.getInterpretationManager().update(STUDY, clinicalAnalysis.getId(), interpretation.getId(), new InterpretationUpdateParams().setPanels(Collections.singletonList(new PanelReferenceParam(panels.get(2).getId()))), null, options, sessionIdUser); - interpretation = catalogManager.getInterpretationManager().get(STUDY, interpretation.getId(), QueryOptions.empty(), sessionIdUser).first(); + interpretation = catalogManager.getInterpretationManager().get(organizationId, STUDY, interpretation.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(1, interpretation.getPanels().size()); assertEquals(panels.get(2).getId(), interpretation.getPanels().get(0).getId()); thrown.expect(CatalogException.class); thrown.expectMessage("panels"); // Set panelLock to true - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setPanelLock(true), QueryOptions.empty(), sessionIdUser); - clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); + clinicalAnalysis = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); assertTrue(clinicalAnalysis.isPanelLock()); } @Test public void updatePanelsFromInterpretationWithLockedCATest() throws CatalogException { List panels = createPanels(3); - Individual proband = catalogManager.getIndividualManager().create(STUDY, + Individual proband = catalogManager.getIndividualManager().create(organizationId, STUDY, new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))), @@ -3329,7 +3329,7 @@ public void updatePanelsFromInterpretationWithLockedCATest() throws CatalogExcep .setPanels(panels.subList(0, 2)); OpenCGAResult result = - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(2, result.first().getPanels().size()); assertTrue(result.first().isPanelLock()); @@ -3348,7 +3348,7 @@ public void updatePanelsFromInterpretationWithLockedCATest() throws CatalogExcep @Test public void updatePanelsFromInterpretationWithUnlockedCATest() throws CatalogException { List panels = createPanels(3); - Individual proband = catalogManager.getIndividualManager().create(STUDY, + Individual proband = catalogManager.getIndividualManager().create(organizationId, STUDY, new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))), @@ -3361,7 +3361,7 @@ public void updatePanelsFromInterpretationWithUnlockedCATest() throws CatalogExc .setPanels(panels.subList(0, 2)); OpenCGAResult result = - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(2, result.first().getPanels().size()); assertFalse(result.first().isPanelLock()); @@ -3374,7 +3374,7 @@ public void updatePanelsFromInterpretationWithUnlockedCATest() throws CatalogExc catalogManager.getInterpretationManager().update(STUDY, clinicalAnalysis.getId(), interpretation.getId(), new InterpretationUpdateParams().setPanels(Collections.singletonList(new PanelReferenceParam(panels.get(2).getId()))), null, QueryOptions.empty(), sessionIdUser); - interpretation = catalogManager.getInterpretationManager().get(STUDY, interpretation.getId(), QueryOptions.empty(), + interpretation = catalogManager.getInterpretationManager().get(organizationId, STUDY, interpretation.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(3, interpretation.getPanels().size()); @@ -3385,7 +3385,7 @@ public void createClinicalAnalysisWithFiles() throws CatalogException { Individual individual = new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))); - catalogManager.getIndividualManager().create(STUDY, individual, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, individual, QueryOptions.empty(), sessionIdUser); // Register and associate files to sample "sample" List files = registerDummyFiles(); @@ -3398,7 +3398,7 @@ public void createClinicalAnalysisWithFiles() throws CatalogException { .setId("Clinical") .setType(ClinicalAnalysis.Type.SINGLE) .setProband(individual); - OpenCGAResult clinical = catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, + OpenCGAResult clinical = catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertEquals(1, clinical.getNumResults()); assertEquals(4, clinical.first().getFiles().size()); @@ -3413,7 +3413,7 @@ public void updateClinicalAnalysisFiles() throws CatalogException { Individual individual = new Individual() .setId("proband") .setSamples(Collections.singletonList(new Sample().setId("sample"))); - catalogManager.getIndividualManager().create(STUDY, individual, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, individual, QueryOptions.empty(), sessionIdUser); // Register and associate files to sample "sample" List files = registerDummyFiles(); @@ -3427,7 +3427,7 @@ public void updateClinicalAnalysisFiles() throws CatalogException { .setId("Clinical") .setType(ClinicalAnalysis.Type.SINGLE) .setProband(individual); - OpenCGAResult clinical = catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, + OpenCGAResult clinical = catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, INCLUDE_RESULT, sessionIdUser); assertEquals(1, clinical.getNumResults()); assertEquals(4, clinical.first().getFiles().size()); @@ -3435,9 +3435,9 @@ public void updateClinicalAnalysisFiles() throws CatalogException { // Remove first and last file ObjectMap actionMap = new ObjectMap(ClinicalAnalysisDBAdaptor.QueryParams.FILES.key(), ParamUtils.BasicUpdateAction.REMOVE); QueryOptions options = new QueryOptions(Constants.ACTIONS, actionMap); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams().setFiles(Arrays.asList(fileRefs.get(0), fileRefs.get(3))), options, sessionIdUser); - ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), + ClinicalAnalysis ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(2, ca.getFiles().size()); assertTrue(files.subList(1, 3).stream().map(File::getPath).collect(Collectors.toSet()) @@ -3446,9 +3446,9 @@ public void updateClinicalAnalysisFiles() throws CatalogException { // Add first file again actionMap = new ObjectMap(ClinicalAnalysisDBAdaptor.QueryParams.FILES.key(), ParamUtils.BasicUpdateAction.ADD); options = new QueryOptions(Constants.ACTIONS, actionMap); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams().setFiles(Collections.singletonList(fileRefs.get(0))), options, sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(3, ca.getFiles().size()); assertTrue(files.subList(0, 3).stream().map(File::getPath).collect(Collectors.toSet()) .containsAll(ca.getFiles().stream().map(File::getPath).collect(Collectors.toSet()))); @@ -3456,9 +3456,9 @@ public void updateClinicalAnalysisFiles() throws CatalogException { // Set file 3 and 4 actionMap = new ObjectMap(ClinicalAnalysisDBAdaptor.QueryParams.FILES.key(), ParamUtils.BasicUpdateAction.SET); options = new QueryOptions(Constants.ACTIONS, actionMap); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams().setFiles(Arrays.asList(fileRefs.get(2), fileRefs.get(3))), options, sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, clinicalAnalysis.getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(2, ca.getFiles().size()); assertTrue(files.subList(2, 4).stream().map(File::getPath).collect(Collectors.toSet()) .containsAll(ca.getFiles().stream().map(File::getPath).collect(Collectors.toSet()))); @@ -3471,18 +3471,18 @@ public void fetchCasesWithSameProbandAndDifferentSample() throws CatalogExceptio Individual proband = DummyModelUtils.getDummyIndividual("proband", SexOntologyTermAnnotation.initMale(), Arrays.asList(sample1, sample2), null, null); - catalogManager.getIndividualManager().create(STUDY, proband, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, proband, QueryOptions.empty(), sessionIdUser); Individual probandCopy = JacksonUtils.copy(proband, Individual.class); probandCopy.setSamples(Collections.singletonList(proband.getSamples().get(0))); ClinicalAnalysis case1 = DummyModelUtils.getDummyClinicalAnalysis("case1", probandCopy, null, null); - catalogManager.getClinicalAnalysisManager().create(STUDY, case1, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, case1, QueryOptions.empty(), sessionIdUser); probandCopy.setSamples(Collections.singletonList(proband.getSamples().get(1))); ClinicalAnalysis case2 = DummyModelUtils.getDummyClinicalAnalysis("case2", probandCopy, null, null); - catalogManager.getClinicalAnalysisManager().create(STUDY, case2, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, case2, QueryOptions.empty(), sessionIdUser); - OpenCGAResult result = catalogManager.getClinicalAnalysisManager().search(STUDY, new Query(), + OpenCGAResult result = catalogManager.getClinicalAnalysisManager().search(organizationId, STUDY, new Query(), QueryOptions.empty(), sessionIdUser); assertEquals(2, result.getNumResults()); assertEquals(case1.getId(), result.getResults().get(0).getId()); diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/DummyModelUtils.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/DummyModelUtils.java index 950d35506bf..e30112b0b5f 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/DummyModelUtils.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/DummyModelUtils.java @@ -169,7 +169,7 @@ public static void createFullFamily(CatalogManager catalogManager, String study, for (Individual member : family.getMembers()) { if ((member.getFather() == null || createdIndividuals.contains(member.getFather().getId())) && (member.getMother() == null || createdIndividuals.contains(member.getMother().getId()))) { - catalogManager.getIndividualManager().create(study, member, QueryOptions.empty(), token); + catalogManager.getIndividualManager().create(organizationId, study, member, QueryOptions.empty(), token); createdIndividuals.add(member.getId()); } } diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/FamilyManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/FamilyManagerTest.java index 4d082414de8..2dbc8836272 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/FamilyManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/FamilyManagerTest.java @@ -165,16 +165,16 @@ public void deleteFamilyTest() throws CatalogException { assertEquals(familyId, member.getFamilyIds().get(0)); } - catalogManager.getFamilyManager().delete(STUDY, Collections.singletonList(familyId), QueryOptions.empty(), sessionIdUser); + catalogManager.getFamilyManager().delete(organizationId, STUDY, Collections.singletonList(familyId), QueryOptions.empty(), sessionIdUser); try { - catalogManager.getFamilyManager().get(STUDY, familyId, QueryOptions.empty(), sessionIdUser); + catalogManager.getFamilyManager().get(organizationId, STUDY, familyId, QueryOptions.empty(), sessionIdUser); fail("Family should not exist"); } catch (CatalogException e) { // empty block } List members = familyDataResult.first().getMembers().stream().map(Individual::getId).collect(Collectors.toList()); - OpenCGAResult result = catalogManager.getIndividualManager().get(STUDY, members, QueryOptions.empty(), sessionIdUser); + OpenCGAResult result = catalogManager.getIndividualManager().get(organizationId, STUDY, members, QueryOptions.empty(), sessionIdUser); for (Individual member : result.getResults()) { assertTrue(member.getFamilyIds().isEmpty()); @@ -184,16 +184,16 @@ public void deleteFamilyTest() throws CatalogException { @Test public void deleteWithClinicalAnalysisTest() throws CatalogException { Sample sample = new Sample().setId("sample1"); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); sample = new Sample().setId("sample2"); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); sample = new Sample().setId("sample3"); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); sample = new Sample().setId("sample4"); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); Individual individual = new Individual() .setId("proband") @@ -218,26 +218,26 @@ public void deleteWithClinicalAnalysisTest() throws CatalogException { .setFamily(family) .setLocked(true) .setType(ClinicalAnalysis.Type.FAMILY); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); try { - catalogManager.getFamilyManager().delete(STUDY, Collections.singletonList(family.getId()), QueryOptions.empty(), sessionIdUser); + catalogManager.getFamilyManager().delete(organizationId, STUDY, Collections.singletonList(family.getId()), QueryOptions.empty(), sessionIdUser); fail("Clinical is locked. It should not delete anything"); } catch (CatalogException e) { System.out.println(e.getMessage()); // empty block } - OpenCGAResult result = catalogManager.getFamilyManager().get(STUDY, family.getId(), QueryOptions.empty(), sessionIdUser); + OpenCGAResult result = catalogManager.getFamilyManager().get(organizationId, STUDY, family.getId(), QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumResults()); - catalogManager.getClinicalAnalysisManager().update(STUDY, clinicalAnalysis.getId(), + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, clinicalAnalysis.getId(), new ClinicalAnalysisUpdateParams() .setLocked(false), QueryOptions.empty(), sessionIdUser); try { - catalogManager.getFamilyManager().delete(STUDY, Collections.singletonList(family.getId()), QueryOptions.empty(), sessionIdUser); + catalogManager.getFamilyManager().delete(organizationId, STUDY, Collections.singletonList(family.getId()), QueryOptions.empty(), sessionIdUser); fail("Clinical is not locked. It should not delete anything either"); } catch (CatalogException e) { System.out.println(e.getMessage()); @@ -254,7 +254,7 @@ public void updateFamilyReferencesInIndividualTest() throws CatalogException { } // Create a new individual - catalogManager.getIndividualManager().create(STUDY, new Individual().setId("john"), QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, new Individual().setId("john"), QueryOptions.empty(), sessionIdUser); FamilyUpdateParams updateParams = new FamilyUpdateParams() .setMembers(Arrays.asList( new IndividualReferenceParam().setId("john"), @@ -264,7 +264,7 @@ public void updateFamilyReferencesInIndividualTest() throws CatalogException { )); familyManager.update(STUDY, familyDataResult.first().getId(), updateParams, QueryOptions.empty(), sessionIdUser); - Family family = familyManager.get(STUDY, familyDataResult.first().getId(), QueryOptions.empty(), sessionIdUser).first(); + Family family = familyManager.get(organizationId, STUDY, familyDataResult.first().getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals(4, family.getMembers().size()); assertTrue(Arrays.asList("john", "father", "mother", "child1") .containsAll(family.getMembers().stream().map(Individual::getId).collect(Collectors.toList()))); @@ -274,7 +274,7 @@ public void updateFamilyReferencesInIndividualTest() throws CatalogException { } // Check removed members no longer belong to the family - List individualList = catalogManager.getIndividualManager().get(STUDY, Arrays.asList("child2", "child3"), + List individualList = catalogManager.getIndividualManager().get(organizationId, STUDY, Arrays.asList("child2", "child3"), QueryOptions.empty(), sessionIdUser).getResults(); assertEquals(2, individualList.size()); for (Individual individual : individualList) { @@ -282,7 +282,7 @@ public void updateFamilyReferencesInIndividualTest() throws CatalogException { } createDummyFamily("Other-Family-Name", false); - individualList = catalogManager.getIndividualManager().get(STUDY, Arrays.asList("john", "father", "mother", "child1", "child2", + individualList = catalogManager.getIndividualManager().get(organizationId, STUDY, Arrays.asList("john", "father", "mother", "child1", "child2", "child3"), QueryOptions.empty(), sessionIdUser).getResults(); for (Individual individual : individualList) { switch (individual.getId()) { @@ -322,10 +322,10 @@ public void createComplexFamily() throws CatalogException { .setFather(father).setMother(mother).setSex(SexOntologyTermAnnotation.initFemale()); Individual sibling = new Individual().setId("sibling").setFather(father).setMother(mother); - catalogManager.getFamilyManager().create(STUDY, new Family().setId("family").setMembers( + catalogManager.getFamilyManager().create(organizationId, STUDY, new Family().setId("family").setMembers( Arrays.asList(paternalGrandfather, paternalGrandmother, maternalGrandfather, maternalGrandmother, mother, father, proband, brother, sister, sibling)), QueryOptions.empty(), sessionIdUser); - OpenCGAResult family = catalogManager.getFamilyManager().get(STUDY, "family", QueryOptions.empty(), sessionIdUser); + OpenCGAResult family = catalogManager.getFamilyManager().get(organizationId, STUDY, "family", QueryOptions.empty(), sessionIdUser); Map> roles = family.first().getRoles(); assertEquals(10, family.first().getMembers().size()); @@ -441,10 +441,10 @@ public void updateFamilyRoles() throws CatalogException { Individual sister = new Individual().setId("sister").setSex(SexOntologyTermAnnotation.initFemale()); Individual sibling = new Individual().setId("sibling"); - catalogManager.getFamilyManager().create(STUDY, new Family().setId("family").setMembers( + catalogManager.getFamilyManager().create(organizationId, STUDY, new Family().setId("family").setMembers( Arrays.asList(paternalGrandfather, paternalGrandmother, maternalGrandfather, maternalGrandmother, mother, father, proband, brother, sister, sibling)), QueryOptions.empty(), sessionIdUser); - OpenCGAResult family = catalogManager.getFamilyManager().get(STUDY, "family", QueryOptions.empty(), sessionIdUser); + OpenCGAResult family = catalogManager.getFamilyManager().get(organizationId, STUDY, "family", QueryOptions.empty(), sessionIdUser); Map> roles = family.first().getRoles(); assertEquals(10, family.first().getMembers().size()); for (Map.Entry> entry : family.first().getRoles().entrySet()) { @@ -473,7 +473,7 @@ public void updateFamilyRoles() throws CatalogException { // new QueryOptions(ParamConstants.FAMILY_UPDATE_ROLES_PARAM, true), sessionIdUser); // Roles should have been automatically updated containing up to date roles - family = catalogManager.getFamilyManager().get(STUDY, "family", QueryOptions.empty(), sessionIdUser); + family = catalogManager.getFamilyManager().get(organizationId, STUDY, "family", QueryOptions.empty(), sessionIdUser); roles = family.first().getRoles(); assertEquals(10, family.first().getMembers().size()); Map pGrandfather = roles.get("p_grandfather"); @@ -581,7 +581,7 @@ public void searchFamily() throws CatalogException { createDummyFamily("Martinez", false); createDummyFamily("Furio", false); - OpenCGAResult search = catalogManager.getFamilyManager().search(STUDY, + OpenCGAResult search = catalogManager.getFamilyManager().search(organizationId, STUDY, new Query(FamilyDBAdaptor.QueryParams.ID.key(), "~^Mart"), QueryOptions.empty(), sessionIdUser); assertEquals(2, search.getNumResults()); for (Family result : search.getResults()) { @@ -626,14 +626,14 @@ public void testPropagateFamilyPermission() throws CatalogException { String token = catalogManager.getUserManager().login("user2", TestParamConstants.PASSWORD).getToken(); try { - familyManager.get(STUDY, "Martinez-Martinez", QueryOptions.empty(), token); + familyManager.get(organizationId, STUDY, "Martinez-Martinez", QueryOptions.empty(), token); fail("Expected authorization exception. user2 should not be able to see the study"); } catch (CatalogAuthorizationException ignored) { } familyManager.updateAcl(STUDY, new FamilyAclParams("VIEW", "Martinez-Martinez", null, null, FamilyAclParams.Propagate.NO), "user2", ParamUtils.AclAction.SET, sessionIdUser); - DataResult familyDataResult = familyManager.get(STUDY, "Martinez-Martinez", QueryOptions.empty(), token); + DataResult familyDataResult = familyManager.get(organizationId, STUDY, "Martinez-Martinez", QueryOptions.empty(), token); assertEquals(1, familyDataResult.getNumResults()); assertEquals(0, familyDataResult.first().getMembers().size()); int nsamples = 0; @@ -644,7 +644,7 @@ public void testPropagateFamilyPermission() throws CatalogException { familyManager.updateAcl(STUDY, new FamilyAclParams("VIEW", "Martinez-Martinez", null, null, FamilyAclParams.Propagate.YES), "user2", ParamUtils.AclAction.SET, sessionIdUser); - familyDataResult = familyManager.get(STUDY, "Martinez-Martinez", QueryOptions.empty(), token); + familyDataResult = familyManager.get(organizationId, STUDY, "Martinez-Martinez", QueryOptions.empty(), token); assertEquals(1, familyDataResult.getNumResults()); assertEquals(5, familyDataResult.first().getMembers().size()); List sampleList = new ArrayList<>(3); @@ -662,7 +662,7 @@ public void testPropagateFamilyPermission() throws CatalogException { familyManager.updateAcl(STUDY, new FamilyAclParams("VIEW", "Martinez-Martinez", null, null, FamilyAclParams.Propagate.YES_AND_VARIANT_VIEW), "user2", ParamUtils.AclAction.SET, sessionIdUser); - familyDataResult = familyManager.get(STUDY, "Martinez-Martinez", QueryOptions.empty(), token); + familyDataResult = familyManager.get(organizationId, STUDY, "Martinez-Martinez", QueryOptions.empty(), token); assertEquals(1, familyDataResult.getNumResults()); assertEquals(5, familyDataResult.first().getMembers().size()); sampleList = new ArrayList<>(3); @@ -688,38 +688,38 @@ public void getFamilyWithOnlyAllowedMembers2() throws CatalogException, IOExcept String token = catalogManager.getUserManager().login("user2", TestParamConstants.PASSWORD).getToken(); try { - familyManager.get(STUDY, "Martinez-Martinez", QueryOptions.empty(), token); + familyManager.get(organizationId, STUDY, "Martinez-Martinez", QueryOptions.empty(), token); fail("Expected authorization exception. user2 should not be able to see the study"); } catch (CatalogAuthorizationException ignored) { } familyManager.updateAcl(STUDY, new FamilyAclParams("VIEW", "Martinez-Martinez", null, null, FamilyAclParams.Propagate.NO), "user2", ParamUtils.AclAction.SET, sessionIdUser); - DataResult familyDataResult = familyManager.get(STUDY, "Martinez-Martinez", QueryOptions.empty(), token); + DataResult familyDataResult = familyManager.get(organizationId, STUDY, "Martinez-Martinez", QueryOptions.empty(), token); assertEquals(1, familyDataResult.getNumResults()); assertEquals(0, familyDataResult.first().getMembers().size()); catalogManager.getIndividualManager().updateAcl(STUDY, Collections.singletonList("child2"), "user2", new IndividualAclParams("", "VIEW"), ParamUtils.AclAction.SET, false, sessionIdUser); - familyDataResult = familyManager.get(STUDY, "Martinez-Martinez", QueryOptions.empty(), token); + familyDataResult = familyManager.get(organizationId, STUDY, "Martinez-Martinez", QueryOptions.empty(), token); assertEquals(1, familyDataResult.getNumResults()); assertEquals(1, familyDataResult.first().getMembers().size()); assertEquals("child2", familyDataResult.first().getMembers().get(0).getId()); catalogManager.getIndividualManager().updateAcl(STUDY, Collections.singletonList("child3"), "user2", new IndividualAclParams("", "VIEW"), ParamUtils.AclAction.SET, false, sessionIdUser); - familyDataResult = familyManager.get(STUDY, "Martinez-Martinez", QueryOptions.empty(), token); + familyDataResult = familyManager.get(organizationId, STUDY, "Martinez-Martinez", QueryOptions.empty(), token); assertEquals(1, familyDataResult.getNumResults()); assertEquals(2, familyDataResult.first().getMembers().size()); assertEquals("child2", familyDataResult.first().getMembers().get(0).getId()); assertEquals("child3", familyDataResult.first().getMembers().get(1).getId()); - familyDataResult = familyManager.get(STUDY, "Martinez-Martinez", + familyDataResult = familyManager.get(organizationId, STUDY, "Martinez-Martinez", new QueryOptions(QueryOptions.EXCLUDE, FamilyDBAdaptor.QueryParams.MEMBERS.key()), token); assertEquals(1, familyDataResult.getNumResults()); assertEquals(null, familyDataResult.first().getMembers()); - familyDataResult = familyManager.get(STUDY, "Martinez-Martinez", + familyDataResult = familyManager.get(organizationId, STUDY, "Martinez-Martinez", new QueryOptions(QueryOptions.INCLUDE, FamilyDBAdaptor.QueryParams.MEMBERS.key() + "." + IndividualDBAdaptor.QueryParams.NAME.key()), token); @@ -735,16 +735,16 @@ public void getFamilyWithOnlyAllowedMembers2() throws CatalogException, IOExcept @Test public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { Sample sample = new Sample().setId("sample1"); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); sample = new Sample().setId("sample2"); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); sample = new Sample().setId("sample3"); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); sample = new Sample().setId("sample4"); - catalogManager.getSampleManager().create(STUDY, sample, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample, QueryOptions.empty(), sessionIdUser); Individual individual = new Individual() .setId("proband") @@ -768,7 +768,7 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { .setProband(new Individual().setId("proband")) .setFamily(family) .setType(ClinicalAnalysis.Type.FAMILY); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); // We will create another clinical analysis with the same information. In this test, we will not lock clinical2 clinicalAnalysis = new ClinicalAnalysis() @@ -776,55 +776,55 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { .setProband(new Individual().setId("proband")) .setFamily(family) .setType(ClinicalAnalysis.Type.FAMILY); - catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); // Update family not used in Clinical Analysis catalogManager.getFamilyManager().update(STUDY, "family", new FamilyUpdateParams() .setDescription(RandomStringUtils.randomAlphanumeric(10)), new QueryOptions(), sessionIdUser); - Family familyResult = catalogManager.getFamilyManager().get(STUDY, "family", QueryOptions.empty(), sessionIdUser).first(); + Family familyResult = catalogManager.getFamilyManager().get(organizationId, STUDY, "family", QueryOptions.empty(), sessionIdUser).first(); assertEquals(2, familyResult.getVersion()); assertEquals(2, familyResult.getMembers().size()); assertEquals(2, familyResult.getMembers().get(0).getVersion()); assertEquals(2, familyResult.getMembers().get(1).getVersion()); - ClinicalAnalysis clinicalResult = catalogManager.getClinicalAnalysisManager().get(STUDY, "clinical", QueryOptions.empty(), + ClinicalAnalysis clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, "clinical", QueryOptions.empty(), sessionIdUser).first(); assertEquals(2, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample1 version assertEquals(2, clinicalResult.getFamily().getVersion()); assertEquals(2, clinicalResult.getFamily().getMembers().size()); - clinicalResult = catalogManager.getClinicalAnalysisManager().get(STUDY, "clinical2", QueryOptions.empty(), sessionIdUser).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, "clinical2", QueryOptions.empty(), sessionIdUser).first(); assertEquals(2, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample1 version assertEquals(2, clinicalResult.getFamily().getVersion()); assertEquals(2, clinicalResult.getFamily().getMembers().size()); // proband version // LOCK CLINICAL ANALYSIS - catalogManager.getClinicalAnalysisManager().update(STUDY, "clinical", new ClinicalAnalysisUpdateParams().setLocked(true), + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, "clinical", new ClinicalAnalysisUpdateParams().setLocked(true), QueryOptions.empty(), sessionIdUser); - clinicalResult = catalogManager.getClinicalAnalysisManager().get(STUDY, "clinical", QueryOptions.empty(), sessionIdUser).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, "clinical", QueryOptions.empty(), sessionIdUser).first(); assertTrue(clinicalResult.isLocked()); // Update family with version increment catalogManager.getFamilyManager().update(STUDY, "family", new FamilyUpdateParams().setName("bl"), new QueryOptions(), sessionIdUser); - familyResult = catalogManager.getFamilyManager().get(STUDY, "family", QueryOptions.empty(), sessionIdUser).first(); + familyResult = catalogManager.getFamilyManager().get(organizationId, STUDY, "family", QueryOptions.empty(), sessionIdUser).first(); assertEquals(3, familyResult.getVersion()); assertEquals(2, familyResult.getMembers().size()); assertEquals(2, familyResult.getMembers().get(0).getVersion()); assertEquals(2, familyResult.getMembers().get(1).getVersion()); - clinicalResult = catalogManager.getClinicalAnalysisManager().get(STUDY, "clinical", QueryOptions.empty(), sessionIdUser).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, "clinical", QueryOptions.empty(), sessionIdUser).first(); assertEquals(2, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample1 version assertEquals(2, clinicalResult.getFamily().getVersion()); assertEquals(2, clinicalResult.getFamily().getMembers().size()); - clinicalResult = catalogManager.getClinicalAnalysisManager().get(STUDY, "clinical2", QueryOptions.empty(), sessionIdUser).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, "clinical2", QueryOptions.empty(), sessionIdUser).first(); assertEquals(2, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample1 version assertEquals(3, clinicalResult.getFamily().getVersion()); @@ -837,7 +837,7 @@ public void includeMemberIdOnly() throws CatalogException { QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, FamilyDBAdaptor.QueryParams.MEMBERS.key() + "." + IndividualDBAdaptor.QueryParams.ID.key()); - DataResult family = familyManager.get(STUDY, "family", options, sessionIdUser); + DataResult family = familyManager.get(organizationId, STUDY, "family", options, sessionIdUser); for (Individual individual : family.first().getMembers()) { assertTrue(StringUtils.isNotEmpty(individual.getId())); @@ -896,13 +896,13 @@ public void includeMemberIdOnly() throws CatalogException { private DataResult createDummyFamily(String familyName, boolean createMissingMembers) throws CatalogException { if (createMissingMembers) { Sample sample1 = new Sample().setId("sample1"); - catalogManager.getSampleManager().create(STUDY, sample1, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample1, QueryOptions.empty(), sessionIdUser); Sample sample2 = new Sample().setId("sample2"); - catalogManager.getSampleManager().create(STUDY, sample2, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample2, QueryOptions.empty(), sessionIdUser); Sample sample3 = new Sample().setId("sample3"); - catalogManager.getSampleManager().create(STUDY, sample3, QueryOptions.empty(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, STUDY, sample3, QueryOptions.empty(), sessionIdUser); } Phenotype phenotype1 = new Phenotype("dis1", "Phenotype 1", "HPO"); @@ -980,11 +980,11 @@ public void updateFamilyDisordersWhenIndividualDisorderIsUpdated() throws Catalo IndividualUpdateParams params = new IndividualUpdateParams().setDisorders(disorderList); catalogManager.getIndividualManager().update(STUDY, "child1", params, new QueryOptions(), sessionIdUser); - DataResult child1 = catalogManager.getIndividualManager().get(STUDY, "child1", QueryOptions.empty(), sessionIdUser); + DataResult child1 = catalogManager.getIndividualManager().get(organizationId, STUDY, "child1", QueryOptions.empty(), sessionIdUser); assertEquals(1, child1.first().getDisorders().size()); assertEquals(3, child1.first().getVersion()); - family = catalogManager.getFamilyManager().get(STUDY, "family", QueryOptions.empty(), sessionIdUser); + family = catalogManager.getFamilyManager().get(organizationId, STUDY, "family", QueryOptions.empty(), sessionIdUser); assertEquals(1, family.first().getDisorders().size()); disorderList = Collections.emptyList(); @@ -993,10 +993,10 @@ public void updateFamilyDisordersWhenIndividualDisorderIsUpdated() throws Catalo actionMap.put(IndividualDBAdaptor.QueryParams.DISORDERS.key(), ParamUtils.BasicUpdateAction.SET); QueryOptions queryOptions = new QueryOptions(Constants.ACTIONS, actionMap); catalogManager.getIndividualManager().update(STUDY, "child1", params, queryOptions, sessionIdUser); - child1 = catalogManager.getIndividualManager().get(STUDY, "child1", QueryOptions.empty(), sessionIdUser); + child1 = catalogManager.getIndividualManager().get(organizationId, STUDY, "child1", QueryOptions.empty(), sessionIdUser); assertEquals(0, child1.first().getDisorders().size()); - family = catalogManager.getFamilyManager().get(STUDY, "family", QueryOptions.empty(), sessionIdUser); + family = catalogManager.getFamilyManager().get(organizationId, STUDY, "family", QueryOptions.empty(), sessionIdUser); assertEquals(0, family.first().getDisorders().size()); // Now we will update increasing the version. No changes should be produced in the family @@ -1004,11 +1004,11 @@ public void updateFamilyDisordersWhenIndividualDisorderIsUpdated() throws Catalo params.setDisorders(disorderList); catalogManager.getIndividualManager().update(STUDY, "child1", params, new QueryOptions(), sessionIdUser); - child1 = catalogManager.getIndividualManager().get(STUDY, "child1", QueryOptions.empty(), sessionIdUser); + child1 = catalogManager.getIndividualManager().get(organizationId, STUDY, "child1", QueryOptions.empty(), sessionIdUser); assertEquals(1, child1.first().getDisorders().size()); assertEquals(5, child1.first().getVersion()); - family = catalogManager.getFamilyManager().get(STUDY, "family", QueryOptions.empty(), sessionIdUser); + family = catalogManager.getFamilyManager().get(organizationId, STUDY, "family", QueryOptions.empty(), sessionIdUser); for (Individual member : family.first().getMembers()) { if (member.getId().equals(child1.first().getId())) { assertEquals(child1.first().getVersion(), member.getVersion()); @@ -1031,7 +1031,7 @@ public void disordersDistinctTest() throws CatalogException { catalogManager.getIndividualManager().update(STUDY, "child1", params1, new QueryOptions(), sessionIdUser); catalogManager.getIndividualManager().update(STUDY, "child2", params2, new QueryOptions(), sessionIdUser); - OpenCGAResult distinct = catalogManager.getFamilyManager().distinct(STUDY, "disorders.name", new Query(), sessionIdUser); + OpenCGAResult distinct = catalogManager.getFamilyManager().distinct(organizationId, STUDY, "disorders.name", new Query(), sessionIdUser); System.out.println(distinct); assertEquals(2, distinct.getNumResults()); @@ -1046,7 +1046,7 @@ public void createFamilyDuo() throws CatalogException { .setMembers(Arrays.asList(new Individual().setId("proband").setSex(SexOntologyTermAnnotation.initMale()), new Individual().setFather(new Individual().setId("proband")).setId("child") .setSex(SexOntologyTermAnnotation.initFemale()))); - DataResult familyDataResult = familyManager.create(STUDY, family, INCLUDE_RESULT, sessionIdUser); + DataResult familyDataResult = familyManager.create(organizationId, STUDY, family, INCLUDE_RESULT, sessionIdUser); assertEquals(2, familyDataResult.first().getMembers().size()); } @@ -1085,7 +1085,7 @@ public void createFamilyMissingMember() throws CatalogException { Family family = new Family("Martinez-Martinez", "Martinez-Martinez", Arrays.asList(phenotype1, phenotype2), null, Arrays.asList(relFather, relChild1, relChild2), "", 3, Collections.emptyList(), Collections.emptyMap()); - family = familyManager.create(STUDY, family, new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionIdUser).first(); + family = familyManager.create(organizationId, STUDY, family, new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionIdUser).first(); assertEquals(3, family.getMembers().size()); assertTrue(Arrays.asList(relFather.getId(), relChild2.getId(), relChild1.getId()) .containsAll(family.getMembers().stream().map(Individual::getId).collect(Collectors.toList()))); @@ -1120,7 +1120,7 @@ public void createFamilyPhenotypeNotPassed() throws CatalogException { thrown.expect(CatalogException.class); thrown.expectMessage("not present in any member of the family"); - familyManager.create(STUDY, family, QueryOptions.empty(), sessionIdUser); + familyManager.create(organizationId, STUDY, family, QueryOptions.empty(), sessionIdUser); } @Test(expected = CatalogException.class) @@ -1161,14 +1161,14 @@ public void createFamilyRepeatedMember() throws CatalogException { Arrays.asList(relFather, relMother, relChild1, relChild2, relChild1), "", -1, Collections.emptyList(), Collections.emptyMap ()); - DataResult familyDataResult = familyManager.create(STUDY, family, INCLUDE_RESULT, sessionIdUser); + DataResult familyDataResult = familyManager.create(organizationId, STUDY, family, INCLUDE_RESULT, sessionIdUser); assertEquals(4, familyDataResult.first().getMembers().size()); } @Test public void createEmptyFamily() throws CatalogException { Family family = new Family("xxx", "xxx", null, null, null, "", -1, Collections.emptyList(), Collections.emptyMap()); - DataResult familyDataResult = familyManager.create(STUDY, family, INCLUDE_RESULT, sessionIdUser); + DataResult familyDataResult = familyManager.create(organizationId, STUDY, family, INCLUDE_RESULT, sessionIdUser); assertEquals(1, familyDataResult.getNumResults()); } @@ -1259,7 +1259,7 @@ public void updateFamilyQualityControl() throws CatalogException { updateParams, QueryOptions.empty(), sessionIdUser); assertEquals(1, updatedFamily.getNumUpdated()); - updatedFamily = familyManager.get(STUDY, originalFamily.first().getId(), QueryOptions.empty(), sessionIdUser); + updatedFamily = familyManager.get(organizationId, STUDY, originalFamily.first().getId(), QueryOptions.empty(), sessionIdUser); assertTrue(Arrays.asList("file1", "file2").containsAll(updatedFamily.first().getQualityControl().getFiles())); assertEquals(1, updatedFamily.first().getQualityControl().getComments().size()); assertEquals("author", updatedFamily.first().getQualityControl().getComments().get(0).getAuthor()); @@ -1275,7 +1275,7 @@ public void incrementVersionTest() throws CatalogException { Family dummyFamily2 = DummyModelUtils.getDummyFamily(); for (int i = dummyFamily1.getMembers().size() - 1; i >= 0; i--) { - catalogManager.getIndividualManager().create(STUDY, dummyFamily1.getMembers().get(i), QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, dummyFamily1.getMembers().get(i), QueryOptions.empty(), sessionIdUser); } List members = dummyFamily1.getMembers().stream().map(Individual::getId).collect(Collectors.toList()); @@ -1284,7 +1284,7 @@ public void incrementVersionTest() throws CatalogException { dummyFamily2.setMembers(null); catalogManager.getFamilyManager().create(STUDY, dummyFamily2, members, QueryOptions.empty(), sessionIdUser); - OpenCGAResult result = catalogManager.getFamilyManager().get(STUDY, Arrays.asList(dummyFamily1.getId(), + OpenCGAResult result = catalogManager.getFamilyManager().get(organizationId, STUDY, Arrays.asList(dummyFamily1.getId(), dummyFamily2.getId()), QueryOptions.empty(), sessionIdUser); assertEquals(2, result.getNumResults()); for (Family family : result.getResults()) { @@ -1301,7 +1301,7 @@ public void incrementVersionTest() throws CatalogException { QueryOptions.empty(), sessionIdUser); catalogManager.getFamilyManager().update(STUDY, dummyFamily1.getId(), new FamilyUpdateParams().setName("name22"), QueryOptions.empty(), sessionIdUser); - result = catalogManager.getFamilyManager().get(STUDY, Arrays.asList(dummyFamily1.getId(), dummyFamily2.getId()), + result = catalogManager.getFamilyManager().get(organizationId, STUDY, Arrays.asList(dummyFamily1.getId(), dummyFamily2.getId()), QueryOptions.empty(), sessionIdUser); assertEquals(2, result.getNumResults()); assertEquals(4, result.first().getVersion()); @@ -1310,7 +1310,7 @@ public void incrementVersionTest() throws CatalogException { Query query = new Query() .append(FamilyDBAdaptor.QueryParams.ID.key(), dummyFamily1.getId()) .append(Constants.ALL_VERSIONS, true); - result = catalogManager.getFamilyManager().search(STUDY, query, QueryOptions.empty(), sessionIdUser); + result = catalogManager.getFamilyManager().search(organizationId, STUDY, query, QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getResults().get(0).getVersion()); assertEquals(2, result.getResults().get(1).getVersion()); @@ -1327,7 +1327,7 @@ public void memberReferenceTest() throws CatalogException { Family dummyFamily2 = DummyModelUtils.getDummyFamily(); for (int i = dummyFamily1.getMembers().size() - 1; i >= 0; i--) { - catalogManager.getIndividualManager().create(STUDY, dummyFamily1.getMembers().get(i), QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, dummyFamily1.getMembers().get(i), QueryOptions.empty(), sessionIdUser); } List members = dummyFamily1.getMembers().stream().map(Individual::getId).collect(Collectors.toList()); @@ -1336,7 +1336,7 @@ public void memberReferenceTest() throws CatalogException { dummyFamily2.setMembers(null); catalogManager.getFamilyManager().create(STUDY, dummyFamily2, members, QueryOptions.empty(), sessionIdUser); - OpenCGAResult result = catalogManager.getIndividualManager().get(STUDY, members, QueryOptions.empty(), sessionIdUser); + OpenCGAResult result = catalogManager.getIndividualManager().get(organizationId, STUDY, members, QueryOptions.empty(), sessionIdUser); for (Individual member : result.getResults()) { assertEquals(2, member.getFamilyIds().size()); assertTrue(member.getFamilyIds().containsAll(Arrays.asList(dummyFamily1.getId(), dummyFamily2.getId()))); @@ -1345,15 +1345,15 @@ public void memberReferenceTest() throws CatalogException { // Update family id catalogManager.getFamilyManager().update(STUDY, dummyFamily1.getId(), new FamilyUpdateParams().setId("newId"), QueryOptions.empty(), sessionIdUser); - result = catalogManager.getIndividualManager().get(STUDY, members, QueryOptions.empty(), sessionIdUser); + result = catalogManager.getIndividualManager().get(organizationId, STUDY, members, QueryOptions.empty(), sessionIdUser); for (Individual member : result.getResults()) { assertEquals(2, member.getFamilyIds().size()); assertTrue(member.getFamilyIds().containsAll(Arrays.asList("newId", dummyFamily2.getId()))); } // Delete family1 - catalogManager.getFamilyManager().delete(STUDY, Collections.singletonList("newId"), QueryOptions.empty(), sessionIdUser); - result = catalogManager.getIndividualManager().get(STUDY, members, QueryOptions.empty(), sessionIdUser); + catalogManager.getFamilyManager().delete(organizationId, STUDY, Collections.singletonList("newId"), QueryOptions.empty(), sessionIdUser); + result = catalogManager.getIndividualManager().get(organizationId, STUDY, members, QueryOptions.empty(), sessionIdUser); for (Individual member : result.getResults()) { assertEquals(1, member.getFamilyIds().size()); assertEquals(dummyFamily2.getId(), member.getFamilyIds().get(0)); @@ -1366,7 +1366,7 @@ public void updateInUseInCATest() throws CatalogException { Family family = DummyModelUtils.getDummyCaseFamily("family1"); for (int i = family.getMembers().size() - 1; i >= 0; i--) { - catalogManager.getIndividualManager().create(STUDY, family.getMembers().get(i), QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, family.getMembers().get(i), QueryOptions.empty(), sessionIdUser); } List members = family.getMembers().stream().map(Individual::getId).collect(Collectors.toList()); @@ -1380,17 +1380,17 @@ public void updateInUseInCATest() throws CatalogException { // locked true ClinicalAnalysis case3 = DummyModelUtils.getDummyClinicalAnalysis(family.getMembers().get(0), family, null); - catalogManager.getClinicalAnalysisManager().create(STUDY, case1, QueryOptions.empty(), sessionIdUser); - catalogManager.getClinicalAnalysisManager().create(STUDY, case2, QueryOptions.empty(), sessionIdUser); - catalogManager.getClinicalAnalysisManager().create(STUDY, case3, QueryOptions.empty(), sessionIdUser); - catalogManager.getClinicalAnalysisManager().update(STUDY, case3.getId(), new ClinicalAnalysisUpdateParams().setLocked(true), + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, case1, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, case2, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, case3, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, case3.getId(), new ClinicalAnalysisUpdateParams().setLocked(true), QueryOptions.empty(), sessionIdUser); // Update family id catalogManager.getFamilyManager().update(STUDY, family.getId(), new FamilyUpdateParams().setId("newId"), QueryOptions.empty(), sessionIdUser); - OpenCGAResult result = catalogManager.getClinicalAnalysisManager().get(STUDY, + OpenCGAResult result = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, Arrays.asList(case1.getId(), case2.getId(), case3.getId()), QueryOptions.empty(), sessionIdUser); case1 = result.getResults().get(0); case2 = result.getResults().get(1); @@ -1407,7 +1407,7 @@ public void updateDeleteInUseInCATest() throws CatalogException { Family family = DummyModelUtils.getDummyCaseFamily("family1"); for (int i = family.getMembers().size() - 1; i >= 0; i--) { - catalogManager.getIndividualManager().create(STUDY, family.getMembers().get(i), QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, family.getMembers().get(i), QueryOptions.empty(), sessionIdUser); } List members = family.getMembers().stream().map(Individual::getId).collect(Collectors.toList()); @@ -1421,25 +1421,25 @@ public void updateDeleteInUseInCATest() throws CatalogException { // locked true ClinicalAnalysis case3 = DummyModelUtils.getDummyClinicalAnalysis(family.getMembers().get(0), family, null); - catalogManager.getClinicalAnalysisManager().create(STUDY, case1, QueryOptions.empty(), sessionIdUser); - catalogManager.getClinicalAnalysisManager().create(STUDY, case2, QueryOptions.empty(), sessionIdUser); - catalogManager.getClinicalAnalysisManager().create(STUDY, case3, QueryOptions.empty(), sessionIdUser); - catalogManager.getClinicalAnalysisManager().update(STUDY, case3.getId(), new ClinicalAnalysisUpdateParams().setLocked(true), + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, case1, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, case2, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, case3, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, case3.getId(), new ClinicalAnalysisUpdateParams().setLocked(true), QueryOptions.empty(), sessionIdUser); // Delete family try { - catalogManager.getFamilyManager().delete(STUDY, Collections.singletonList(family.getId()), QueryOptions.empty(), sessionIdUser); + catalogManager.getFamilyManager().delete(organizationId, STUDY, Collections.singletonList(family.getId()), QueryOptions.empty(), sessionIdUser); } catch (CatalogException e) { assertTrue(e.getMessage().contains("in use in Clinical Analyses")); } // unlock case3 - catalogManager.getClinicalAnalysisManager().update(STUDY, case3.getId(), new ClinicalAnalysisUpdateParams().setLocked(false), + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, case3.getId(), new ClinicalAnalysisUpdateParams().setLocked(false), QueryOptions.empty(), sessionIdUser); try { - catalogManager.getFamilyManager().delete(STUDY, Collections.singletonList(family.getId()), QueryOptions.empty(), sessionIdUser); + catalogManager.getFamilyManager().delete(organizationId, STUDY, Collections.singletonList(family.getId()), QueryOptions.empty(), sessionIdUser); } catch (CatalogException e) { assertTrue(e.getMessage().contains("in use in Clinical Analyses")); } @@ -1453,9 +1453,9 @@ public void updateFamilyMembers() throws CatalogException { child.setFather(father); child.setMother(mother); - catalogManager.getIndividualManager().create(STUDY, father, QueryOptions.empty(), sessionIdUser); - catalogManager.getIndividualManager().create(STUDY, mother, QueryOptions.empty(), sessionIdUser); - catalogManager.getIndividualManager().create(STUDY, child, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, father, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, mother, QueryOptions.empty(), sessionIdUser); + catalogManager.getIndividualManager().create(organizationId, STUDY, child, QueryOptions.empty(), sessionIdUser); Family family = DummyModelUtils.getDummyFamily("family"); family.setMembers(null); diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/FileManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/FileManagerTest.java index 77703e0c2ad..91a1de497fe 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/FileManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/FileManagerTest.java @@ -96,7 +96,7 @@ public void testCreateFileFromUnsharedStudy() throws CatalogException { true, sessionIdUser2); fail("The file could be created despite not having the proper permissions."); } catch (CatalogAuthorizationException e) { - assertEquals(0, fileManager.search(studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), + assertEquals(0, fileManager.search(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), "data/test/folder/file.txt"), null, token).getNumResults()); } } @@ -104,7 +104,7 @@ public void testCreateFileFromUnsharedStudy() throws CatalogException { @Test public void testCreateFileFromSharedStudy() throws CatalogException { StudyAclParams aclParams = new StudyAclParams("", "analyst"); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), "user2", aclParams, ParamUtils.AclAction.ADD, token); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), "user2", aclParams, ParamUtils.AclAction.ADD, token); fileManager.create(studyFqn, new FileCreateParams() .setType(File.Type.FILE) @@ -112,19 +112,19 @@ public void testCreateFileFromSharedStudy() throws CatalogException { .setDescription("My description") .setContent("blabla"), true, sessionIdUser2); - assertEquals(1, fileManager.search(studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), + assertEquals(1, fileManager.search(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), "data/test/folder/file.txt"), null, token).getNumResults()); } URI getStudyURI() throws CatalogException { - return catalogManager.getStudyManager().get(studyFqn, + return catalogManager.getStudyManager().get(organizationId, studyFqn, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.URI.key()), token).first().getUri(); } @Test public void testSearchById() throws CatalogException { Query query = new Query(FileDBAdaptor.QueryParams.ID.key(), "~/^data/"); - OpenCGAResult search = catalogManager.getFileManager().search(studyFqn, query, FileManager.INCLUDE_FILE_IDS, token); + OpenCGAResult search = catalogManager.getFileManager().search(organizationId, studyFqn, query, FileManager.INCLUDE_FILE_IDS, token); assertEquals(6, search.getNumResults()); } @@ -146,14 +146,14 @@ public void testLinkCram() throws CatalogException { assertEquals(referenceFile.getId(), link.first().getRelatedFiles().get(0).getFile().getId()); assertEquals(FileRelatedFile.Relation.REFERENCE_GENOME, link.first().getRelatedFiles().get(0).getRelation()); - Sample sample = catalogManager.getSampleManager().get(studyFqn, link.first().getSampleIds().get(0), QueryOptions.empty(), token).first(); + Sample sample = catalogManager.getSampleManager().get(organizationId, studyFqn, link.first().getSampleIds().get(0), QueryOptions.empty(), token).first(); assertEquals("cram_with_crai_index.cram", sample.getFileIds().get(0)); } @Test public void testLinkAnalystUser() throws CatalogException { catalogManager.getUserManager().create("analyst", "analyst", "a@mail.com", TestParamConstants.PASSWORD, "", 200000L, Account.AccountType.GUEST, opencgaToken); - catalogManager.getStudyManager().updateAcl(studyFqn, "analyst", new StudyAclParams("", "analyst"), ParamUtils.AclAction.SET, token); + catalogManager.getStudyManager().updateAcl(organizationId, studyFqn, "analyst", new StudyAclParams("", "analyst"), ParamUtils.AclAction.SET, token); String analystToken = catalogManager.getUserManager().login("analyst", TestParamConstants.PASSWORD).getToken(); String reference = getClass().getResource("/biofiles/cram/hg19mini.fasta").getFile(); @@ -165,7 +165,7 @@ public void testLinkAnalystUser() throws CatalogException { @Test public void testLinkUserWithNoWritePermissions() throws CatalogException { catalogManager.getUserManager().create("view_user", "view_user", "a@mail.com", TestParamConstants.PASSWORD, "", 200000L, Account.AccountType.GUEST, opencgaToken); - catalogManager.getStudyManager().updateAcl(studyFqn, "view_user", new StudyAclParams("", "view_only"), ParamUtils.AclAction.SET, token); + catalogManager.getStudyManager().updateAcl(organizationId, studyFqn, "view_user", new StudyAclParams("", "view_only"), ParamUtils.AclAction.SET, token); String analystToken = catalogManager.getUserManager().login("view_user", TestParamConstants.PASSWORD).getToken(); String reference = getClass().getResource("/biofiles/cram/hg19mini.fasta").getFile(); @@ -244,7 +244,7 @@ public void createWithBase64File2Test() throws CatalogException { assertEquals(params.getSampleIds().size(), file.getSampleIds().size()); assertTrue(file.getSampleIds().containsAll(params.getSampleIds())); - OpenCGAResult sampleResult = catalogManager.getSampleManager().get(studyFqn, params.getSampleIds(), QueryOptions.empty(), + OpenCGAResult sampleResult = catalogManager.getSampleManager().get(organizationId, studyFqn, params.getSampleIds(), QueryOptions.empty(), token); assertEquals(2, sampleResult.getNumResults()); for (Sample sample : sampleResult.getResults()) { @@ -336,7 +336,7 @@ public void testUpdateRelatedFiles() throws CatalogException { .setRelatedFiles(Collections.singletonList(new SmallRelatedFileParams(testFile2, FileRelatedFile.Relation.PRODUCED_FROM))); fileManager.update(studyFqn, testFile1, updateParams, QueryOptions.empty(), token); - File file = fileManager.get(studyFqn, testFile1, QueryOptions.empty(), token).first(); + File file = fileManager.get(organizationId, studyFqn, testFile1, QueryOptions.empty(), token).first(); assertEquals(1, file.getRelatedFiles().size()); assertEquals(testFile2, file.getRelatedFiles().get(0).getFile().getPath()); assertEquals(FileRelatedFile.Relation.PRODUCED_FROM, file.getRelatedFiles().get(0).getRelation()); @@ -347,14 +347,14 @@ public void testUpdateRelatedFiles() throws CatalogException { updateParams = new FileUpdateParams() .setRelatedFiles(Collections.singletonList(new SmallRelatedFileParams(testFile2, FileRelatedFile.Relation.PART_OF_PAIR))); fileManager.update(studyFqn, testFile1, updateParams, new QueryOptions(Constants.ACTIONS, actionMap), token); - file = fileManager.get(studyFqn, testFile1, QueryOptions.empty(), token).first(); + file = fileManager.get(organizationId, studyFqn, testFile1, QueryOptions.empty(), token).first(); assertEquals(1, file.getRelatedFiles().size()); assertEquals(testFile2, file.getRelatedFiles().get(0).getFile().getPath()); assertEquals(FileRelatedFile.Relation.PART_OF_PAIR, file.getRelatedFiles().get(0).getRelation()); actionMap.put(FileDBAdaptor.QueryParams.RELATED_FILES.key(), ParamUtils.BasicUpdateAction.REMOVE.name()); fileManager.update(studyFqn, testFile1, updateParams, new QueryOptions(Constants.ACTIONS, actionMap), token); - file = fileManager.get(studyFqn, testFile1, QueryOptions.empty(), token).first(); + file = fileManager.get(organizationId, studyFqn, testFile1, QueryOptions.empty(), token).first(); assertEquals(0, file.getRelatedFiles().size()); // We add it again @@ -377,7 +377,7 @@ public void testLinkVCFandBAMPair() throws CatalogException { String bamFile = getClass().getResource("/biofiles/NA19600.chrom20.small.bam").getFile(); fileManager.link(studyFqn, new FileLinkParams(bamFile, "", "", "", null, null, null, null, null), false, token); - Sample sample = catalogManager.getSampleManager().get(studyFqn, "NA19600", + Sample sample = catalogManager.getSampleManager().get(organizationId, studyFqn, "NA19600", new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.FILE_IDS.key()), token).first(); assertEquals(2, sample.getFileIds().size()); assertTrue(Arrays.asList("variant-test-file.vcf.gz", "NA19600.chrom20.small.bam").containsAll(sample.getFileIds())); @@ -401,12 +401,12 @@ public void testLinkVirtualExcludeType() throws CatalogException { OpenCGAResult result; - result = fileManager.get(studyFqn, + result = fileManager.get(organizationId, studyFqn, Arrays.asList("variant-test-file.vcf.gz"), new QueryOptions(QueryOptions.INCLUDE, FileDBAdaptor.QueryParams.RELATED_FILES.key()), token); assertEquals(1, result.getNumResults()); - result = fileManager.get(studyFqn, + result = fileManager.get(organizationId, studyFqn, Arrays.asList("variant-test-file.vcf.gz"), new QueryOptions(QueryOptions.EXCLUDE, "type"), token); assertEquals(1, result.getNumResults()); @@ -438,7 +438,7 @@ public void testLinkVirtualOverSampleLinkThreshold() throws CatalogException { } private void checkTestLinkVirtualFile(boolean missingSamples) throws CatalogException { - OpenCGAResult result = fileManager.get(studyFqn, + OpenCGAResult result = fileManager.get(organizationId, studyFqn, Arrays.asList("variant-test-file.vcf.gz", "variant-test-file-copy.vcf.gz", "virtual_file.vcf"), QueryOptions.empty(), token); assertEquals(3, result.getNumResults()); @@ -504,21 +504,21 @@ public void testLinkFolder() throws CatalogException, IOException { // Now we try to create it into a folder that does not exist with parents = true link(uri, "myDirectory", studyFqn, new ObjectMap("parents", true), token); - DataResult folderDataResult = fileManager.search(studyFqn, new Query() + DataResult folderDataResult = fileManager.search(organizationId, studyFqn, new Query() .append(FileDBAdaptor.QueryParams.PATH.key(), "myDirectory/"), null, token); assertEquals(1, folderDataResult.getNumResults()); assertTrue(!folderDataResult.first().isExternal()); - folderDataResult = fileManager.search(studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), + folderDataResult = fileManager.search(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), "myDirectory/A/"), null, token); assertEquals(1, folderDataResult.getNumResults()); assertTrue(folderDataResult.first().isExternal()); - folderDataResult = fileManager.search(studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), + folderDataResult = fileManager.search(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), "myDirectory/A/C/D/"), null, token); assertEquals(1, folderDataResult.getNumResults()); assertTrue(folderDataResult.first().isExternal()); - folderDataResult = fileManager.search(studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), + folderDataResult = fileManager.search(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), "myDirectory/A/B/"), null, token); assertEquals(1, folderDataResult.getNumResults()); assertTrue(folderDataResult.first().isExternal()); @@ -627,7 +627,7 @@ public void testLinkFile() throws CatalogException, IOException, URISyntaxExcept assertEquals(4, link.first().getSampleIds().size()); Query query = new Query(SampleDBAdaptor.QueryParams.ID.key(), link.first().getSampleIds()); - DataResult sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + DataResult sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(4, sampleDataResult.getNumResults()); List sampleNames = sampleDataResult.getResults().stream().map(Sample::getId).collect(Collectors.toList()); @@ -653,72 +653,72 @@ public void testAssociateSamples() throws CatalogException, URISyntaxException { URI uri = getClass().getResource("/biofiles/variant-test-file-dot-names.vcf.gz").toURI(); DataResult link = fileManager.link(studyFqn, uri, ".", new ObjectMap(), token); assertEquals(4, link.first().getSampleIds().size()); - assertThat(catalogManager.getSampleManager().get(studyFqn, "test-name.bam", QueryOptions.empty(), token).first().getFileIds(), + assertThat(catalogManager.getSampleManager().get(organizationId, studyFqn, "test-name.bam", QueryOptions.empty(), token).first().getFileIds(), hasItem(link.first().getId())); - assertThat(catalogManager.getSampleManager().get(studyFqn, "NA19660", QueryOptions.empty(), token).first().getFileIds(), + assertThat(catalogManager.getSampleManager().get(organizationId, studyFqn, "NA19660", QueryOptions.empty(), token).first().getFileIds(), hasItem(link.first().getId())); - assertThat(catalogManager.getSampleManager().get(studyFqn, "NA19661", QueryOptions.empty(), token).first().getFileIds(), + assertThat(catalogManager.getSampleManager().get(organizationId, studyFqn, "NA19661", QueryOptions.empty(), token).first().getFileIds(), hasItem(link.first().getId())); - assertThat(catalogManager.getSampleManager().get(studyFqn, "NA19685", QueryOptions.empty(), token).first().getFileIds(), + assertThat(catalogManager.getSampleManager().get(organizationId, studyFqn, "NA19685", QueryOptions.empty(), token).first().getFileIds(), hasItem(link.first().getId())); Map actionMap = new HashMap<>(); actionMap.put(FileDBAdaptor.QueryParams.SAMPLE_IDS.key(), ParamUtils.BasicUpdateAction.SET.name()); fileManager.update(studyFqn, link.first().getId(), new FileUpdateParams().setSampleIds(Collections.emptyList()), new QueryOptions(Constants.ACTIONS, actionMap), token); - assertThat(catalogManager.getSampleManager().get(studyFqn, "test-name.bam", QueryOptions.empty(), token).first().getFileIds(), + assertThat(catalogManager.getSampleManager().get(organizationId, studyFqn, "test-name.bam", QueryOptions.empty(), token).first().getFileIds(), not(hasItem(link.first().getId()))); - assertThat(catalogManager.getSampleManager().get(studyFqn, "NA19660", QueryOptions.empty(), token).first().getFileIds(), + assertThat(catalogManager.getSampleManager().get(organizationId, studyFqn, "NA19660", QueryOptions.empty(), token).first().getFileIds(), not(hasItem(link.first().getId()))); - assertThat(catalogManager.getSampleManager().get(studyFqn, "NA19661", QueryOptions.empty(), token).first().getFileIds(), + assertThat(catalogManager.getSampleManager().get(organizationId, studyFqn, "NA19661", QueryOptions.empty(), token).first().getFileIds(), not(hasItem(link.first().getId()))); - assertThat(catalogManager.getSampleManager().get(studyFqn, "NA19685", QueryOptions.empty(), token).first().getFileIds(), + assertThat(catalogManager.getSampleManager().get(organizationId, studyFqn, "NA19685", QueryOptions.empty(), token).first().getFileIds(), not(hasItem(link.first().getId()))); - File file = fileManager.get(studyFqn, link.first().getId(), QueryOptions.empty(), token).first(); + File file = fileManager.get(organizationId, studyFqn, link.first().getId(), QueryOptions.empty(), token).first(); assertEquals(0, file.getSampleIds().size()); actionMap.put(FileDBAdaptor.QueryParams.SAMPLE_IDS.key(), ParamUtils.BasicUpdateAction.ADD.name()); fileManager.update(studyFqn, link.first().getId(), new FileUpdateParams().setSampleIds(Arrays.asList("NA19660", "NA19661")), new QueryOptions(Constants.ACTIONS, actionMap), token); - file = fileManager.get(studyFqn, link.first().getId(), QueryOptions.empty(), token).first(); + file = fileManager.get(organizationId, studyFqn, link.first().getId(), QueryOptions.empty(), token).first(); assertEquals(2, file.getSampleIds().size()); - assertThat(catalogManager.getSampleManager().get(studyFqn, "NA19661", QueryOptions.empty(), token).first().getFileIds(), + assertThat(catalogManager.getSampleManager().get(organizationId, studyFqn, "NA19661", QueryOptions.empty(), token).first().getFileIds(), hasItem(file.getId())); - assertThat(catalogManager.getSampleManager().get(studyFqn, "NA19660", QueryOptions.empty(), token).first().getFileIds(), + assertThat(catalogManager.getSampleManager().get(organizationId, studyFqn, "NA19660", QueryOptions.empty(), token).first().getFileIds(), hasItem(file.getId())); actionMap.put(FileDBAdaptor.QueryParams.SAMPLE_IDS.key(), ParamUtils.BasicUpdateAction.REMOVE.name()); fileManager.update(studyFqn, link.first().getId(), new FileUpdateParams().setSampleIds(Arrays.asList("NA19661")), new QueryOptions(Constants.ACTIONS, actionMap), token); - file = fileManager.get(studyFqn, link.first().getId(), QueryOptions.empty(), token).first(); + file = fileManager.get(organizationId, studyFqn, link.first().getId(), QueryOptions.empty(), token).first(); assertEquals(1, file.getSampleIds().size()); assertEquals("NA19660", file.getSampleIds().get(0)); - assertThat(catalogManager.getSampleManager().get(studyFqn, "NA19660", QueryOptions.empty(), token).first().getFileIds(), + assertThat(catalogManager.getSampleManager().get(organizationId, studyFqn, "NA19660", QueryOptions.empty(), token).first().getFileIds(), hasItem(file.getId())); - assertThat(catalogManager.getSampleManager().get(studyFqn, "NA19661", QueryOptions.empty(), token).first().getFileIds(), + assertThat(catalogManager.getSampleManager().get(organizationId, studyFqn, "NA19661", QueryOptions.empty(), token).first().getFileIds(), not(hasItem(file.getId()))); actionMap.put(FileDBAdaptor.QueryParams.SAMPLE_IDS.key(), ParamUtils.BasicUpdateAction.SET); fileManager.update(studyFqn, link.first().getId(), new FileUpdateParams().setSampleIds(Arrays.asList("NA19661")), new QueryOptions(Constants.ACTIONS, actionMap), token); - file = fileManager.get(studyFqn, link.first().getId(), QueryOptions.empty(), token).first(); + file = fileManager.get(organizationId, studyFqn, link.first().getId(), QueryOptions.empty(), token).first(); assertEquals(1, file.getSampleIds().size()); assertEquals("NA19661", file.getSampleIds().get(0)); - assertThat(catalogManager.getSampleManager().get(studyFqn, "NA19660", QueryOptions.empty(), token).first().getFileIds(), + assertThat(catalogManager.getSampleManager().get(organizationId, studyFqn, "NA19660", QueryOptions.empty(), token).first().getFileIds(), not(hasItem(file.getId()))); - assertThat(catalogManager.getSampleManager().get(studyFqn, "NA19661", QueryOptions.empty(), token).first().getFileIds(), + assertThat(catalogManager.getSampleManager().get(organizationId, studyFqn, "NA19661", QueryOptions.empty(), token).first().getFileIds(), hasItem(file.getId())); - file = fileManager.get(studyFqn, link.first().getId(), + file = fileManager.get(organizationId, studyFqn, link.first().getId(), new QueryOptions(QueryOptions.INCLUDE, FileDBAdaptor.QueryParams.SAMPLE_IDS.key()), token).first(); assertEquals(1, file.getSampleIds().size()); assertEquals("NA19661", file.getSampleIds().get(0)); assertNull(file.getCreationDate()); - file = fileManager.get(studyFqn, link.first().getId(), + file = fileManager.get(organizationId, studyFqn, link.first().getId(), new QueryOptions(QueryOptions.EXCLUDE, FileDBAdaptor.QueryParams.SAMPLE_IDS.key()), token).first(); assertTrue(file.getSampleIds().isEmpty()); assertNotNull(file.getCreationDate()); @@ -742,7 +742,7 @@ public void testLinkFileWithDifferentSampleNames() throws CatalogException, URIS assertEquals(4, link.first().getSampleIds().size()); Query query = new Query(SampleDBAdaptor.QueryParams.ID.key(), link.first().getSampleIds()); - DataResult sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + DataResult sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(4, sampleDataResult.getNumResults()); List sampleNames = sampleDataResult.getResults().stream().map(Sample::getId).collect(Collectors.toList()); @@ -768,7 +768,7 @@ public void testLinkFileWithDifferentSampleNamesFromVCFHeader() throws CatalogEx assertEquals(Arrays.asList("TUMOR", "NORMAL", "OTHER"), new ObjectMap(link.first().getAttributes()).getAsStringList("variantFileMetadata.attributes.originalSamples")); Query query = new Query(SampleDBAdaptor.QueryParams.ID.key(), link.first().getSampleIds()); - DataResult sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + DataResult sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(3, sampleDataResult.getNumResults()); List sampleNames = sampleDataResult.getResults().stream().map(Sample::getId).collect(Collectors.toList()); @@ -831,7 +831,7 @@ public void testUnlinkFolder() throws CatalogException, IOException { .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), studyUid) .append(FileDBAdaptor.QueryParams.PATH.key(), "~myDirectory/*") .append(FileDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), FileStatus.READY); - DataResult fileDataResultLinked = fileManager.search(studyFqn, query, null, token); + DataResult fileDataResultLinked = fileManager.search(organizationId, studyFqn, query, null, token); System.out.println("Number of files/folders linked = " + fileDataResultLinked.getNumResults()); @@ -844,14 +844,14 @@ public void testUnlinkFolder() throws CatalogException, IOException { // Now we try to unlink them fileManager.unlink(studyFqn, "myDirectory/A/", token); - fileDataResultLinked = fileManager.search(studyFqn, query, null, token); + fileDataResultLinked = fileManager.search(organizationId, studyFqn, query, null, token); assertEquals(1, fileDataResultLinked.getNumResults()); query = new Query() .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), studyUid) .append(FileDBAdaptor.QueryParams.PATH.key(), "~myDirectory/*") .append(FileDBAdaptor.QueryParams.DELETED.key(), true); - DataResult fileDataResultUnlinked = fileManager.search(studyFqn, query, null, token); + DataResult fileDataResultUnlinked = fileManager.search(organizationId, studyFqn, query, null, token); assertEquals(6, fileDataResultUnlinked.getNumResults()); for (File file : fileDataResultUnlinked.getResults()) { @@ -869,7 +869,7 @@ public void testUnlinkFile() throws CatalogException, IOException { Query query = new Query() .append(FileDBAdaptor.QueryParams.PATH.key(), "~myDirectory/*") .append(FileDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), FileStatus.READY); - DataResult fileDataResultLinked = fileManager.search(studyFqn, query, null, token); + DataResult fileDataResultLinked = fileManager.search(organizationId, studyFqn, query, null, token); int numberLinkedFiles = fileDataResultLinked.getNumResults(); System.out.println("Number of files/folders linked = " + numberLinkedFiles); @@ -880,16 +880,16 @@ public void testUnlinkFile() throws CatalogException, IOException { // Now we try to unlink the file fileManager.unlink(studyFqn, "myDirectory/data/test/folder/test_0.5K.txt", token); - fileDataResultLinked = fileManager.search(studyFqn, unlinkQuery, QueryOptions.empty(), token); + fileDataResultLinked = fileManager.search(organizationId, studyFqn, unlinkQuery, QueryOptions.empty(), token); assertEquals(0, fileDataResultLinked.getNumResults()); unlinkQuery.put(FileDBAdaptor.QueryParams.DELETED.key(), true); - fileDataResultLinked = fileManager.search(studyFqn, unlinkQuery, QueryOptions.empty(), token); + fileDataResultLinked = fileManager.search(organizationId, studyFqn, unlinkQuery, QueryOptions.empty(), token); assertEquals(1, fileDataResultLinked.getNumResults()); assertEquals(FileStatus.REMOVED, fileDataResultLinked.first().getInternal().getStatus().getId()); // Check the other root linked files/folders have not been touched - fileDataResultLinked = fileManager.search(studyFqn, query, QueryOptions.empty(), token); + fileDataResultLinked = fileManager.search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(numberLinkedFiles - 1, fileDataResultLinked.getNumResults()); // We send the unlink command again @@ -929,8 +929,8 @@ public void testCreateFile() throws CatalogException, IOException { @Test public void testCreateFolder() throws Exception { Query query = new Query(StudyDBAdaptor.QueryParams.OWNER.key(), "user2"); - Study study = catalogManager.getStudyManager().search(query, QueryOptions.empty(), sessionIdUser2).first(); - Set paths = fileManager.search(study.getFqn(), new Query("type", File.Type.DIRECTORY), new + Study study = catalogManager.getStudyManager().search(organizationId, query, QueryOptions.empty(), sessionIdUser2).first(); + Set paths = fileManager.search(organizationId, study.getFqn(), new Query("type", File.Type.DIRECTORY), new QueryOptions(), sessionIdUser2) .getResults().stream().map(File::getPath).collect(Collectors.toSet()); assertEquals(2, paths.size()); @@ -945,7 +945,7 @@ public void testCreateFolder() throws Exception { IOManager ioManager = catalogManager.getIoManagerFactory().get(folder.getUri()); assertTrue(!ioManager.exists(folder.getUri())); - paths = fileManager.search(study.getFqn(), new Query(FileDBAdaptor.QueryParams.TYPE.key(), File.Type + paths = fileManager.search(organizationId, study.getFqn(), new Query(FileDBAdaptor.QueryParams.TYPE.key(), File.Type .DIRECTORY), new QueryOptions(), sessionIdUser2).getResults().stream().map(File::getPath).collect(Collectors.toSet()); assertEquals(5, paths.size()); assertTrue(paths.contains("data/new/")); @@ -967,7 +967,7 @@ public void testCreateFolder() throws Exception { @Test public void testCreateFolderAlreadyExists() throws Exception { - Set paths = fileManager.search(studyFqn3, new Query("type", File.Type.DIRECTORY), new QueryOptions(), sessionIdUser2).getResults().stream().map(File::getPath).collect(Collectors.toSet()); + Set paths = fileManager.search(organizationId, studyFqn3, new Query("type", File.Type.DIRECTORY), new QueryOptions(), sessionIdUser2).getResults().stream().map(File::getPath).collect(Collectors.toSet()); assertEquals(2, paths.size()); assertTrue(paths.contains("")); //root // assertTrue(paths.contains("data/")); //data @@ -1001,7 +1001,7 @@ public void testAnnotationWrongEntity() throws CatalogException, JsonProcessingE null, Collections.emptyMap())); variables.add(new Variable("HEIGHT", "", "", Variable.VariableType.DOUBLE, "", false, false, Collections.emptyList(), null, 0, "", "", null, Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); ObjectMap annotations = new ObjectMap() @@ -1026,7 +1026,7 @@ public void testAnnotationForAnyEntity() throws CatalogException, JsonProcessing null, Collections.emptyMap())); variables.add(new Variable("HEIGHT", "", "", Variable.VariableType.DOUBLE, "", false, false, Collections.emptyList(), null, 0, "", "", null, Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, variables, null, token).first(); ObjectMap annotations = new ObjectMap() @@ -1040,7 +1040,7 @@ public void testAnnotationForAnyEntity() throws CatalogException, JsonProcessing DataResult updateResult = fileManager.update(studyFqn, "data/", updateParams, QueryOptions.empty(), token); assertEquals(1, updateResult.getNumUpdated()); - File file = fileManager.get(studyFqn, "data/", QueryOptions.empty(), token).first(); + File file = fileManager.get(organizationId, studyFqn, "data/", QueryOptions.empty(), token).first(); assertEquals(1, file.getAnnotationSets().size()); } @@ -1053,7 +1053,7 @@ public void testAnnotations() throws CatalogException, JsonProcessingException { null, Collections.emptyMap())); variables.add(new Variable("HEIGHT", "", "", Variable.VariableType.DOUBLE, "", false, false, Collections.emptyList(), null, 0, "", "", null, Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.FILE), token).first(); ObjectMap annotations = new ObjectMap() @@ -1067,15 +1067,15 @@ public void testAnnotations() throws CatalogException, JsonProcessingException { DataResult updateResult = fileManager.update(studyFqn, "data/", updateParams, QueryOptions.empty(), token); assertEquals(1, updateResult.getNumUpdated()); - File file = fileManager.get(studyFqn, "data/", QueryOptions.empty(), token).first(); + File file = fileManager.get(organizationId, studyFqn, "data/", QueryOptions.empty(), token).first(); assertEquals(2, file.getAnnotationSets().size()); } @Test public void testUpdateSamples() throws CatalogException { // Update the same sample twice to the file - Sample sample1 = catalogManager.getSampleManager().get(studyFqn, "s_1", QueryOptions.empty(), token).first(); - Sample sample2 = catalogManager.getSampleManager().get(studyFqn, "s_2", QueryOptions.empty(), token).first(); + Sample sample1 = catalogManager.getSampleManager().get(organizationId, studyFqn, "s_1", QueryOptions.empty(), token).first(); + Sample sample2 = catalogManager.getSampleManager().get(organizationId, studyFqn, "s_2", QueryOptions.empty(), token).first(); assertFalse(sample1.getFileIds().contains("data:test:folder:test_1K.txt.gz")); assertFalse(sample2.getFileIds().contains("data:test:folder:test_1K.txt.gz")); @@ -1083,19 +1083,19 @@ public void testUpdateSamples() throws CatalogException { DataResult updateResult = fileManager.update(studyFqn, "test_1K.txt.gz", updateParams, null, token); assertEquals(1, updateResult.getNumUpdated()); - File file = fileManager.get(studyFqn, "test_1K.txt.gz", QueryOptions.empty(), token).first(); + File file = fileManager.get(organizationId, studyFqn, "test_1K.txt.gz", QueryOptions.empty(), token).first(); assertEquals(2, file.getSampleIds().size()); assertTrue(file.getSampleIds().containsAll(Arrays.asList("s_1", "s_2"))); - OpenCGAResult sampleResult = catalogManager.getSampleManager().get(studyFqn, Arrays.asList("s_1", "s_2"), QueryOptions.empty(), token); + OpenCGAResult sampleResult = catalogManager.getSampleManager().get(organizationId, studyFqn, Arrays.asList("s_1", "s_2"), QueryOptions.empty(), token); assertEquals(2, sampleResult.getNumResults()); for (Sample sample : sampleResult.getResults()) { assertTrue(sample.getFileIds().contains(file.getId())); } System.out.println(file.getId()); - sample1 = catalogManager.getSampleManager().get(studyFqn, "s_1", QueryOptions.empty(), token).first(); - sample2 = catalogManager.getSampleManager().get(studyFqn, "s_2", QueryOptions.empty(), token).first(); + sample1 = catalogManager.getSampleManager().get(organizationId, studyFqn, "s_1", QueryOptions.empty(), token).first(); + sample2 = catalogManager.getSampleManager().get(organizationId, studyFqn, "s_2", QueryOptions.empty(), token).first(); assertTrue(sample1.getFileIds().contains(file.getId())); assertTrue(sample2.getFileIds().contains(file.getId())); } @@ -1176,7 +1176,7 @@ public void testCreate() throws Exception { .setContent(createRandomString(200)), true, token); - DataResult fileDataResult = fileManager.get(studyFqn2, fileName, null, token); + DataResult fileDataResult = fileManager.get(organizationId, studyFqn2, fileName, null, token); assertTrue(fileDataResult.first().getSize() > 0); } @@ -1372,7 +1372,7 @@ public void renameFileTest() throws CatalogException { assertEquals(1, queryResult.getNumResults()); fileManager.rename(studyFqn, "data/nested/", "nested2", token); - Set paths = fileManager.search(studyFqn, new Query(), new QueryOptions(), token) + Set paths = fileManager.search(organizationId, studyFqn, new Query(), new QueryOptions(), token) .getResults() .stream().map(File::getPath).collect(Collectors.toSet()); @@ -1383,7 +1383,7 @@ public void renameFileTest() throws CatalogException { assertTrue(paths.contains("data/file.txt")); fileManager.rename(studyFqn, "data/", "Data", token); - paths = fileManager.search(studyFqn, new Query(), new QueryOptions(), token).getResults() + paths = fileManager.search(organizationId, studyFqn, new Query(), new QueryOptions(), token).getResults() .stream().map(File::getPath).collect(Collectors.toSet()); assertTrue(paths.contains("Data/")); @@ -1396,7 +1396,7 @@ public void renameFileTest() throws CatalogException { @Test public void getFileIdByString() throws CatalogException { StudyAclParams aclParams = new StudyAclParams("", "analyst"); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), "user2", aclParams, ParamUtils.AclAction.ADD, token); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), "user2", aclParams, ParamUtils.AclAction.ADD, token); File file = fileManager.create(studyFqn, new FileCreateParams() .setType(File.Type.FILE) @@ -1406,13 +1406,13 @@ public void getFileIdByString() throws CatalogException { .setDescription("My description") .setContent("blabla"), true, sessionIdUser2).first(); - long fileId = fileManager.get(studyFqn, file.getPath(), FileManager.INCLUDE_FILE_IDS, token).first().getUid(); + long fileId = fileManager.get(organizationId, studyFqn, file.getPath(), FileManager.INCLUDE_FILE_IDS, token).first().getUid(); assertEquals(file.getUid(), fileId); - fileId = fileManager.get(studyFqn, file.getPath(), FileManager.INCLUDE_FILE_IDS, token).first().getUid(); + fileId = fileManager.get(organizationId, studyFqn, file.getPath(), FileManager.INCLUDE_FILE_IDS, token).first().getUid(); assertEquals(file.getUid(), fileId); - fileId = fileManager.get(studyFqn, "/", FileManager.INCLUDE_FILE_IDS, token).first().getUid(); + fileId = fileManager.get(organizationId, studyFqn, "/", FileManager.INCLUDE_FILE_IDS, token).first().getUid(); System.out.println(fileId); } @@ -1444,7 +1444,7 @@ public void searchFileTest() throws CatalogException { DataResult result; // Look for a file and folder - DataResult queryResults = fileManager.get(studyFqn, Arrays.asList("data/", "data/test/folder/test_1K.txt.gz"), + DataResult queryResults = fileManager.get(organizationId, studyFqn, Arrays.asList("data/", "data/test/folder/test_1K.txt.gz"), new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(FileDBAdaptor.QueryParams.NAME.key())), token); assertEquals(2, queryResults.getNumResults()); assertTrue("Name not included", queryResults.getResults().stream().map(File::getName) @@ -1452,32 +1452,32 @@ public void searchFileTest() throws CatalogException { .collect(Collectors.toList()).size() == 2); query = new Query(FileDBAdaptor.QueryParams.NAME.key(), "~data"); - result = fileManager.search(studyFqn, query, null, token); + result = fileManager.search(organizationId, studyFqn, query, null, token); assertEquals(1, result.getNumResults()); query = new Query(FileDBAdaptor.QueryParams.NAME.key(), "~txt.gz$"); - result = fileManager.search(studyFqn, query, null, token); + result = fileManager.search(organizationId, studyFqn, query, null, token); assertEquals(1, result.getNumResults()); //Get all files in data query = new Query(FileDBAdaptor.QueryParams.PATH.key(), "~data/[^/]+/?") .append(FileDBAdaptor.QueryParams.TYPE.key(), "FILE"); - result = fileManager.search(studyFqn, query, null, token); + result = fileManager.search(organizationId, studyFqn, query, null, token); assertEquals(3, result.getNumResults()); //Folder "jobs" does not exist query = new Query(FileDBAdaptor.QueryParams.DIRECTORY.key(), "jobs"); - result = fileManager.search(studyFqn, query, null, token); + result = fileManager.search(organizationId, studyFqn, query, null, token); assertEquals(0, result.getNumResults()); //Get all files in data query = new Query(FileDBAdaptor.QueryParams.DIRECTORY.key(), "data/"); - result = fileManager.search(studyFqn, query, null, token); + result = fileManager.search(organizationId, studyFqn, query, null, token); assertEquals(1, result.getNumResults()); //Get all files in data query = new Query(FileDBAdaptor.QueryParams.DIRECTORY.key(), "/data/"); - result = fileManager.search(studyFqn, query, null, token); + result = fileManager.search(organizationId, studyFqn, query, null, token); assertEquals(1, result.getNumResults()); //Get all files in data recursively @@ -1486,48 +1486,48 @@ public void searchFileTest() throws CatalogException { // assertEquals(5, result.getNumResults()); query = new Query(FileDBAdaptor.QueryParams.TYPE.key(), "FILE"); - result = fileManager.search(studyFqn, query, null, token); + result = fileManager.search(organizationId, studyFqn, query, null, token); result.getResults().forEach(f -> assertEquals(File.Type.FILE, f.getType())); int numFiles = result.getNumResults(); assertEquals(3, numFiles); query = new Query(FileDBAdaptor.QueryParams.TYPE.key(), "DIRECTORY"); - result = fileManager.search(studyFqn, query, null, token); + result = fileManager.search(organizationId, studyFqn, query, null, token); result.getResults().forEach(f -> assertEquals(File.Type.DIRECTORY, f.getType())); int numFolders = result.getNumResults(); assertEquals(5, numFolders); query = new Query(FileDBAdaptor.QueryParams.PATH.key(), ""); - result = fileManager.search(studyFqn, query, null, token); + result = fileManager.search(organizationId, studyFqn, query, null, token); assertEquals(1, result.getNumResults()); assertEquals(".", result.first().getName()); query = new Query(FileDBAdaptor.QueryParams.TYPE.key(), "FILE,DIRECTORY"); - result = fileManager.search(studyFqn, query, null, token); + result = fileManager.search(organizationId, studyFqn, query, null, token); assertEquals(8, result.getNumResults()); assertEquals(numFiles + numFolders, result.getNumResults()); query = new Query("type", "FILE"); query.put("size", ">500"); - result = fileManager.search(studyFqn, query, null, token); + result = fileManager.search(organizationId, studyFqn, query, null, token); assertEquals(2, result.getNumResults()); query = new Query("type", "FILE"); query.put("size", "<=500"); - result = fileManager.search(studyFqn, query, null, token); + result = fileManager.search(organizationId, studyFqn, query, null, token); assertEquals(1, result.getNumResults()); - List sampleIds = catalogManager.getSampleManager().search(studyFqn, new Query(SampleDBAdaptor.QueryParams.ID.key(), "s_1,s_3,s_4"), null, token).getResults() + List sampleIds = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.ID.key(), "s_1,s_3,s_4"), null, token).getResults() .stream() .map(Sample::getId) .collect(Collectors.toList()); - result = fileManager.search(studyFqn, new Query(FileDBAdaptor.QueryParams.SAMPLE_IDS.key(), sampleIds), null, token); + result = fileManager.search(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.SAMPLE_IDS.key(), sampleIds), null, token); assertEquals(1, result.getNumResults()); query = new Query(FileDBAdaptor.QueryParams.TYPE.key(), "FILE"); query.put(FileDBAdaptor.QueryParams.FORMAT.key(), "PLAIN"); - result = fileManager.search(studyFqn, query, null, token); + result = fileManager.search(organizationId, studyFqn, query, null, token); assertEquals(2, result.getNumResults()); // String attributes = FileDBAdaptor.QueryParams.ATTRIBUTES.key(); @@ -1653,13 +1653,13 @@ interface Searcher { // assertEquals(1, result.getNumResults()); QueryOptions options = new QueryOptions(QueryOptions.LIMIT, 2).append(QueryOptions.COUNT, true); - result = fileManager.search(studyFqn, new Query(), options, token); + result = fileManager.search(organizationId, studyFqn, new Query(), options, token); assertEquals(2, result.getNumResults()); assertEquals(8, result.getNumMatches()); options = new QueryOptions(QueryOptions.LIMIT, 2) .append(QueryOptions.COUNT, true); - result = fileManager.search(studyFqn, new Query(), options, token); + result = fileManager.search(organizationId, studyFqn, new Query(), options, token); assertEquals(2, result.getNumResults()); assertEquals(8, result.getNumMatches()); @@ -1693,7 +1693,7 @@ interface Searcher { @Test public void testSearchFileFail1() throws CatalogException { thrown.expect(CatalogDBException.class); - fileManager.search(studyFqn, new Query(FileDBAdaptor.QueryParams.NATTRIBUTES.key() + ".numValue", "==NotANumber"), null, + fileManager.search(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.NATTRIBUTES.key() + ".numValue", "==NotANumber"), null, token); } @@ -1702,7 +1702,7 @@ public void testGetFileParents1() throws CatalogException { long fileId; DataResult fileParents; - fileId = fileManager.get(studyFqn, "data/test/folder/", FileManager.INCLUDE_FILE_IDS, token).first().getUid(); + fileId = fileManager.get(organizationId, studyFqn, "data/test/folder/", FileManager.INCLUDE_FILE_IDS, token).first().getUid(); fileParents = fileManager.getParents(fileId, null, token); assertEquals(4, fileParents.getNumResults()); @@ -1717,7 +1717,7 @@ public void testGetFileParents2() throws CatalogException { long fileId; DataResult fileParents; - fileId = fileManager.get(studyFqn, "data/test/folder/test_1K.txt.gz", FileManager.INCLUDE_FILE_IDS, token) + fileId = fileManager.get(organizationId, studyFqn, "data/test/folder/test_1K.txt.gz", FileManager.INCLUDE_FILE_IDS, token) .first().getUid(); fileParents = fileManager.getParents(fileId, null, token); @@ -1734,7 +1734,7 @@ public void testGetFileParents3() throws CatalogException { long fileId; DataResult fileParents; - fileId = fileManager.get(studyFqn, "data/test/", FileManager.INCLUDE_FILE_IDS, token).first().getUid(); + fileId = fileManager.get(organizationId, studyFqn, "data/test/", FileManager.INCLUDE_FILE_IDS, token).first().getUid(); fileParents = fileManager.getParents(fileId, new QueryOptions("include", "projects.studies.files.path," + "projects.studies.files.id"), token); @@ -1753,21 +1753,21 @@ public void testGetFileParents3() throws CatalogException { @Test public void testGetFileWithSamples() throws CatalogException { - DataResult fileDataResult = fileManager.get(studyFqn, "data/test/", QueryOptions.empty(), + DataResult fileDataResult = fileManager.get(organizationId, studyFqn, "data/test/", QueryOptions.empty(), token); assertEquals(1, fileDataResult.getNumResults()); assertEquals(0, fileDataResult.first().getSampleIds().size()); // Create two samples - Sample sample1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("sample1"), INCLUDE_RESULT, token).first(); - Sample sample2 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("sample2"), INCLUDE_RESULT, token).first(); + Sample sample1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("sample1"), INCLUDE_RESULT, token).first(); + Sample sample2 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("sample2"), INCLUDE_RESULT, token).first(); // Associate the two samples to the file fileManager.update(studyFqn, "data/test/", new FileUpdateParams().setSampleIds(Arrays.asList(sample1.getId(), sample2.getId())), QueryOptions.empty(), token); // Fetch the file - fileDataResult = fileManager.get(studyFqn, "data/test/", new QueryOptions( + fileDataResult = fileManager.get(organizationId, studyFqn, "data/test/", new QueryOptions( QueryOptions.INCLUDE, Arrays.asList(FileDBAdaptor.QueryParams.ID.key(), FileDBAdaptor.QueryParams.SAMPLE_IDS.key())), token); assertEquals(1, fileDataResult.getNumResults()); @@ -1784,7 +1784,7 @@ public void testDelete1() throws CatalogException { Query query = new Query() .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), studyUid) .append(FileDBAdaptor.QueryParams.PATH.key(), filePath); - DataResult fileDataResult = fileManager.search(studyFqn, query, null, token); + DataResult fileDataResult = fileManager.search(organizationId, studyFqn, query, null, token); // Change the status to MISSING FileUpdateParams updateParams = new FileUpdateParams() @@ -1792,7 +1792,7 @@ public void testDelete1() throws CatalogException { catalogManager.getFileManager().update(studyFqn, filePath, updateParams, null, token); try { - fileManager.delete(studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), fileDataResult.first().getUid()), null, token); + fileManager.delete(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), fileDataResult.first().getUid()), null, token); fail("Expected fail. It should not be able to delete"); } catch (CatalogException e) { assertTrue(e.getMessage().contains("Cannot delete")); @@ -1803,7 +1803,7 @@ public void testDelete1() throws CatalogException { catalogManager.getFileManager().update(studyFqn, filePath, updateParams, null, token); try { - fileManager.delete(studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), fileDataResult.first().getUid()), null, token); + fileManager.delete(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), fileDataResult.first().getUid()), null, token); fail("Expected fail. It should not be able to delete"); } catch (CatalogException e) { assertTrue(e.getMessage().contains("Cannot delete")); @@ -1813,7 +1813,7 @@ public void testDelete1() throws CatalogException { query = new Query(FileDBAdaptor.QueryParams.PATH.key(), "~^" + filePath + "*"); setToPendingDelete(studyFqn, query); - DataResult deleteResult = fileManager.delete(studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), + DataResult deleteResult = fileManager.delete(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), fileDataResult.first().getUid()), null, token); assertEquals(6, deleteResult.getNumMatches()); assertEquals(6, deleteResult.getNumUpdated()); @@ -1826,24 +1826,24 @@ public void testDelete2() throws CatalogException, IOException { Query query = new Query() .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), studyUid) .append(FileDBAdaptor.QueryParams.PATH.key(), filePath); - File file = fileManager.search(studyFqn, query, null, token).first(); + File file = fileManager.search(organizationId, studyFqn, query, null, token).first(); // We look for all the files and folders that fall within that folder query = new Query() .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), studyUid) .append(FileDBAdaptor.QueryParams.PATH.key(), "~^" + filePath + "*") .append(FileDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), FileStatus.READY); - int numResults = fileManager.search(studyFqn, query, null, token).getNumResults(); + int numResults = fileManager.search(organizationId, studyFqn, query, null, token).getNumResults(); assertEquals(6, numResults); query = new Query(FileDBAdaptor.QueryParams.PATH.key(), "~^" + file.getPath() + "*"); setToPendingDelete(studyFqn, query); // We delete it - fileManager.delete(studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), file.getUid()), null, token); + fileManager.delete(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), file.getUid()), null, token); // The files should have been moved to trashed status - OpenCGAResult search = fileManager.search(studyFqn, query, null, token); + OpenCGAResult search = fileManager.search(organizationId, studyFqn, query, null, token); assertEquals(6, search.getNumResults()); for (File trashedFile : search.getResults()) { assertEquals(FileStatus.TRASHED, trashedFile.getInternal().getStatus().getId()); @@ -1857,56 +1857,56 @@ public void testDelete3() throws CatalogException, IOException { Query query = new Query() .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), studyUid) .append(FileDBAdaptor.QueryParams.PATH.key(), filePath); - File file = fileManager.search(studyFqn, query, null, token).first(); + File file = fileManager.search(organizationId, studyFqn, query, null, token).first(); // We look for all the files and folders that fall within that folder query = new Query() .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), studyUid) .append(FileDBAdaptor.QueryParams.PATH.key(), "~^" + filePath + "*") .append(FileDBAdaptor.QueryParams.INTERNAL_STATUS.key(), FileStatus.READY); - int numResults = fileManager.search(studyFqn, query, null, token).getNumResults(); + int numResults = fileManager.search(organizationId, studyFqn, query, null, token).getNumResults(); assertEquals(6, numResults); setToPendingDelete(studyFqn, query); // We delete it QueryOptions queryOptions = new QueryOptions(Constants.SKIP_TRASH, true); - fileManager.delete(studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), file.getUid()), + fileManager.delete(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), file.getUid()), queryOptions, token); // The files should have been moved to trashed status - numResults = fileManager.search(studyFqn, query, null, token).getNumResults(); + numResults = fileManager.search(organizationId, studyFqn, query, null, token).getNumResults(); assertEquals(0, numResults); query.put(FileDBAdaptor.QueryParams.DELETED.key(), true); query.put(FileDBAdaptor.QueryParams.INTERNAL_STATUS.key(), FileStatus.DELETED); - numResults = fileManager.search(studyFqn, query, null, token).getNumResults(); + numResults = fileManager.search(organizationId, studyFqn, query, null, token).getNumResults(); assertEquals(6, numResults); } @Test public void testDeleteFile() throws CatalogException, IOException { - List result = fileManager.search(studyFqn, new Query(FileDBAdaptor.QueryParams.TYPE.key(), + List result = fileManager.search(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.TYPE.key(), "FILE"), new QueryOptions(), token).getResults(); // 1st we set the status to PENDING DELETE. setToPendingDelete(studyFqn, new Query(FileDBAdaptor.QueryParams.TYPE.key(), "FILE")); for (File file : result) { - fileManager.delete(studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), file.getUid()), null, token); + fileManager.delete(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), file.getUid()), null, token); } // CatalogFileUtils catalogFileUtils = new CatalogFileUtils(catalogManager); - fileManager.search(studyFqn, new Query(FileDBAdaptor.QueryParams.TYPE.key(), "FILE"), new QueryOptions(), token).getResults().forEach(f -> { + fileManager.search(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.TYPE.key(), "FILE"), new QueryOptions(), token).getResults().forEach(f -> { assertEquals(f.getInternal().getStatus().getId(), FileStatus.TRASHED); }); - result = fileManager.search(studyFqn2, new Query(FileDBAdaptor.QueryParams.TYPE.key(), "FILE"), new QueryOptions(), token).getResults(); + result = fileManager.search(organizationId, studyFqn2, new Query(FileDBAdaptor.QueryParams.TYPE.key(), "FILE"), new QueryOptions(), token).getResults(); // 1st we set the status to PENDING DELETE. setToPendingDelete(studyFqn2, new Query(FileDBAdaptor.QueryParams.TYPE.key(), "FILE")); for (File file : result) { - fileManager.delete(studyFqn2, new Query(FileDBAdaptor.QueryParams.UID.key(), file.getUid()), null, token); + fileManager.delete(organizationId, studyFqn2, new Query(FileDBAdaptor.QueryParams.UID.key(), file.getUid()), null, token); } - fileManager.search(studyFqn2, new Query(FileDBAdaptor.QueryParams.TYPE.key(), "FILE"), new QueryOptions(), token).getResults().forEach(f -> { + fileManager.search(organizationId, studyFqn2, new Query(FileDBAdaptor.QueryParams.TYPE.key(), "FILE"), new QueryOptions(), token).getResults().forEach(f -> { assertEquals(f.getInternal().getStatus().getId(), FileStatus.TRASHED); }); } @@ -1914,11 +1914,11 @@ public void testDeleteFile() throws CatalogException, IOException { @Test public void removeFileReferencesFromSamplesOnFileDeleteTest() throws CatalogException { String fileId = "data:test:folder:test_0.1K.png"; - File file = fileManager.get(studyFqn, fileId, QueryOptions.empty(), token).first(); + File file = fileManager.get(organizationId, studyFqn, fileId, QueryOptions.empty(), token).first(); assertFalse(file.getSampleIds().isEmpty()); assertEquals(5, file.getSampleIds().size()); - List samples = catalogManager.getSampleManager().search(studyFqn, + List samples = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), fileId), QueryOptions.empty(), token).getResults(); assertEquals(5, samples.size()); @@ -1929,14 +1929,14 @@ public void removeFileReferencesFromSamplesOnFileDeleteTest() throws CatalogExce // Send to TRASH BIN setToPendingDelete(studyFqn, new Query(FileDBAdaptor.QueryParams.ID.key(), fileId)); - fileManager.delete(studyFqn, Collections.singletonList(fileId), QueryOptions.empty(), token); + fileManager.delete(organizationId, studyFqn, Collections.singletonList(fileId), QueryOptions.empty(), token); - file = fileManager.get(studyFqn, fileId, QueryOptions.empty(), token).first(); + file = fileManager.get(organizationId, studyFqn, fileId, QueryOptions.empty(), token).first(); assertFalse(file.getSampleIds().isEmpty()); assertEquals(5, file.getSampleIds().size()); assertEquals(FileStatus.TRASHED, file.getInternal().getStatus().getId()); - samples = catalogManager.getSampleManager().search(studyFqn, + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), fileId), QueryOptions.empty(), token).getResults(); assertEquals(5, samples.size()); @@ -1947,13 +1947,13 @@ public void removeFileReferencesFromSamplesOnFileDeleteTest() throws CatalogExce // Delete permanently setToPendingDelete(studyFqn, new Query(FileDBAdaptor.QueryParams.ID.key(), fileId)); - fileManager.delete(studyFqn, Collections.singletonList(fileId), new QueryOptions(Constants.SKIP_TRASH, true), token); + fileManager.delete(organizationId, studyFqn, Collections.singletonList(fileId), new QueryOptions(Constants.SKIP_TRASH, true), token); - List noResults = catalogManager.getSampleManager().search(studyFqn, + List noResults = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.FILE_IDS.key(), fileId), QueryOptions.empty(), token).getResults(); assertEquals(0, noResults.size()); - samples = catalogManager.getSampleManager().get(studyFqn, samples.stream().map(Sample::getId).collect(Collectors.toList()), + samples = catalogManager.getSampleManager().get(organizationId, studyFqn, samples.stream().map(Sample::getId).collect(Collectors.toList()), QueryOptions.empty(), token).getResults(); assertEquals(5, samples.size()); @@ -1963,29 +1963,29 @@ public void removeFileReferencesFromSamplesOnFileDeleteTest() throws CatalogExce thrown.expect(CatalogException.class); thrown.expectMessage("Missing"); - fileManager.get(studyFqn, fileId, QueryOptions.empty(), token).first(); + fileManager.get(organizationId, studyFqn, fileId, QueryOptions.empty(), token).first(); } @Test public void testDeleteLeafFolder() throws CatalogException, IOException { - File deletable = fileManager.get(studyFqn, "/data/test/folder/", QueryOptions.empty(), token).first(); + File deletable = fileManager.get(organizationId, studyFqn, "/data/test/folder/", QueryOptions.empty(), token).first(); deleteFolderAndCheck(deletable); } @Test public void testDeleteMiddleFolder() throws CatalogException, IOException { - File deletable = fileManager.get(studyFqn, "/data/", QueryOptions.empty(), token).first(); + File deletable = fileManager.get(organizationId, studyFqn, "/data/", QueryOptions.empty(), token).first(); deleteFolderAndCheck(deletable); } @Test public void testDeleteRootFolder() throws CatalogException { - File deletable = fileManager.get(studyFqn, "/", QueryOptions.empty(), token).first(); + File deletable = fileManager.get(organizationId, studyFqn, "/", QueryOptions.empty(), token).first(); thrown.expect(CatalogException.class); thrown.expectMessage("Root directories cannot be deleted"); - fileManager.delete(studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), deletable.getPath()), null, token); + fileManager.delete(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), deletable.getPath()), null, token); } // Cannot delete staged files @@ -2012,12 +2012,12 @@ public void deleteFolderTest() throws CatalogException, IOException { .append(FileDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), FileStatus.READY); setToPendingDelete(studyFqn, query); - File fileTmp = fileManager.get(studyFqn, folder.getPath(), null, token).first(); + File fileTmp = fileManager.get(organizationId, studyFqn, folder.getPath(), null, token).first(); assertEquals("Folder name should not be modified", folder.getPath(), fileTmp.getPath()); assertTrue(ioManager.exists(fileTmp.getUri())); for (File file : folderFiles) { - fileTmp = fileManager.get(studyFqn, file.getPath(), null, token).first(); + fileTmp = fileManager.get(organizationId, studyFqn, file.getPath(), null, token).first(); assertEquals("File name should not be modified", file.getPath(), fileTmp.getPath()); assertTrue("File uri: " + fileTmp.getUri() + " should exist", ioManager.exists(fileTmp.getUri())); } @@ -2040,11 +2040,11 @@ public void deleteFolderTest2() throws CatalogException, IOException { setToPendingDelete(studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), "~^" + folder.getPath() + "*")); // Now we delete the files - fileManager.delete(studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), folder.getUid()), null, token); + fileManager.delete(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), folder.getUid()), null, token); Query query = new Query() .append(FileDBAdaptor.QueryParams.UID.key(), folder.getUid()); - File fileTmp = fileManager.search(studyFqn, query, QueryOptions.empty(), token).first(); + File fileTmp = fileManager.search(organizationId, studyFqn, query, QueryOptions.empty(), token).first(); assertEquals("Folder name should not be modified", folder.getPath(), fileTmp.getPath()); assertEquals("Status should be to TRASHED", FileStatus.TRASHED, fileTmp.getInternal().getStatus().getId()); @@ -2053,7 +2053,7 @@ public void deleteFolderTest2() throws CatalogException, IOException { for (File file : folderFiles) { query.put(FileDBAdaptor.QueryParams.UID.key(), file.getUid()); - fileTmp = fileManager.search(studyFqn, query, QueryOptions.empty(), token).first(); + fileTmp = fileManager.search(organizationId, studyFqn, query, QueryOptions.empty(), token).first(); assertEquals("Folder name should not be modified", file.getPath(), fileTmp.getPath()); assertEquals("Status should be to TRASHED", FileStatus.TRASHED, fileTmp.getInternal().getStatus().getId()); assertEquals("Name should not have changed", file.getName(), fileTmp.getName()); @@ -2077,7 +2077,7 @@ public void deleteFolderTest3() throws CatalogException, IOException { setToPendingDelete(studyFqn, new Query(FileDBAdaptor.QueryParams.PATH.key(), "~^" + folder.getPath() + "*")); Query query = new Query(FileDBAdaptor.QueryParams.PATH.key(), "~^" + folder.getPath() + "*"); - OpenCGAResult results = fileManager.search(studyFqn, query, + OpenCGAResult results = fileManager.search(organizationId, studyFqn, query, new QueryOptions(QueryOptions.INCLUDE, FileDBAdaptor.QueryParams.INTERNAL_STATUS.key()), token); assertEquals(9, results.getNumResults()); for (File result : results.getResults()) { @@ -2102,12 +2102,12 @@ public void deleteFolderTest4() throws CatalogException, IOException { // Now we delete the files QueryOptions params = new QueryOptions(Constants.SKIP_TRASH, true); - fileManager.delete(studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), folder.getUid()), params, token); + fileManager.delete(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.UID.key(), folder.getUid()), params, token); Query query = new Query() .append(FileDBAdaptor.QueryParams.UID.key(), folder.getUid()) .append(FileDBAdaptor.QueryParams.DELETED.key(), true); - File fileTmp = fileManager.search(studyFqn, query, QueryOptions.empty(), token).first(); + File fileTmp = fileManager.search(organizationId, studyFqn, query, QueryOptions.empty(), token).first(); assertEquals("Folder name should not be modified", folder.getPath(), fileTmp.getPath()); assertEquals("Status should be to DELETED", FileStatus.DELETED, fileTmp.getInternal().getStatus().getId()); @@ -2116,7 +2116,7 @@ public void deleteFolderTest4() throws CatalogException, IOException { for (File file : folderFiles) { query.put(FileDBAdaptor.QueryParams.UID.key(), file.getUid()); - fileTmp = fileManager.search(studyFqn, query, QueryOptions.empty(), token).first(); + fileTmp = fileManager.search(organizationId, studyFqn, query, QueryOptions.empty(), token).first(); assertEquals("Folder name should not be modified", file.getPath(), fileTmp.getPath()); assertEquals("Status should be to DELETED", FileStatus.DELETED, fileTmp.getInternal().getStatus().getId()); assertEquals("Name should not have changed", file.getName(), fileTmp.getName()); @@ -2198,19 +2198,19 @@ private void deleteFolderAndCheck(File deletable) throws CatalogException { Query query = new Query(FileDBAdaptor.QueryParams.PATH.key(), "~^" + deletable.getPath() + "*"); setToPendingDelete(study.getFqn(), query); - fileManager.delete(study.getFqn(), query, null, token); + fileManager.delete(organizationId, study.getFqn(), query, null, token); query = new Query() .append(FileDBAdaptor.QueryParams.PATH.key(), deletable.getPath()) .append(FileDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), FileStatus.TRASHED); QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, FileDBAdaptor.QueryParams.PATH.key()); - DataResult fileDataResult = fileManager.search(study.getFqn(), query, options, token); + DataResult fileDataResult = fileManager.search(organizationId, study.getFqn(), query, options, token); assertEquals(1, fileDataResult.getNumResults()); query = new Query() .append(FileDBAdaptor.QueryParams.DIRECTORY.key(), fileDataResult.first().getPath() + ".*") .append(FileDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), FileStatus.TRASHED); - allFilesInFolder = fileManager.search(study.getFqn(), query, null, token).getResults(); + allFilesInFolder = fileManager.search(organizationId, study.getFqn(), query, null, token).getResults(); for (File subFile : allFilesInFolder) { assertTrue(subFile.getInternal().getStatus().getId().equals(FileStatus.TRASHED)); @@ -2262,7 +2262,7 @@ public void testUpdateIndexStatus() throws CatalogException, URISyntaxException, true, token); fileManager.updateFileInternalVariantIndex(fileResult.first(), FileInternalVariantIndex.init().setStatus(new VariantIndexStatus(VariantIndexStatus.TRANSFORMED, null)), token); - DataResult read = fileManager.get(studyFqn, fileResult.first().getPath(), new QueryOptions(), token); + DataResult read = fileManager.get(organizationId, studyFqn, fileResult.first().getPath(), new QueryOptions(), token); assertEquals(VariantIndexStatus.TRANSFORMED, read.first().getInternal().getVariant().getIndex().getStatus().getId()); } @@ -2277,7 +2277,7 @@ public void testMoveAndRegister() throws URISyntaxException, CatalogException, I catalogManager.getIoManagerFactory().getDefault().deleteDirectory(Paths.get("/tmp/other").toUri()); } - Study study = catalogManager.getStudyManager().resolveId(studyFqn, "user"); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyFqn, "user"); Path studyPath = Paths.get(study.getUri()); // Register in workspace folder @@ -2290,8 +2290,8 @@ public void testMoveAndRegister() throws URISyntaxException, CatalogException, I // We remove the file to start again Query query = new Query(FileDBAdaptor.QueryParams.UID.key(), result.first().getUid()); setToPendingDelete(studyFqn, query); - fileManager.delete(studyFqn, query, new QueryOptions(Constants.SKIP_TRASH, true), token); - assertEquals(0, fileManager.search(studyFqn, query, QueryOptions.empty(), token).getNumResults()); + fileManager.delete(organizationId, studyFqn, query, new QueryOptions(Constants.SKIP_TRASH, true), token); + assertEquals(0, fileManager.search(organizationId, studyFqn, query, QueryOptions.empty(), token).getNumResults()); Files.copy(sourcePath, copy); // Register without passing the path @@ -2303,8 +2303,8 @@ public void testMoveAndRegister() throws URISyntaxException, CatalogException, I // We remove the file to start again query = new Query(FileDBAdaptor.QueryParams.UID.key(), result.first().getUid()); setToPendingDelete(studyFqn, query); - fileManager.delete(studyFqn, query, new QueryOptions(Constants.SKIP_TRASH, true), token); - assertEquals(0, fileManager.search(studyFqn, query, QueryOptions.empty(), token).getNumResults()); + fileManager.delete(organizationId, studyFqn, query, new QueryOptions(Constants.SKIP_TRASH, true), token); + assertEquals(0, fileManager.search(organizationId, studyFqn, query, QueryOptions.empty(), token).getNumResults()); Files.copy(sourcePath, copy); // Register without passing the destiny path @@ -2316,8 +2316,8 @@ public void testMoveAndRegister() throws URISyntaxException, CatalogException, I // We remove the file to start again query = new Query(FileDBAdaptor.QueryParams.UID.key(), result.first().getUid()); setToPendingDelete(studyFqn, query); - fileManager.delete(studyFqn, query, new QueryOptions(Constants.SKIP_TRASH, true), token); - assertEquals(0, fileManager.search(studyFqn, query, QueryOptions.empty(), token).getNumResults()); + fileManager.delete(organizationId, studyFqn, query, new QueryOptions(Constants.SKIP_TRASH, true), token); + assertEquals(0, fileManager.search(organizationId, studyFqn, query, QueryOptions.empty(), token).getNumResults()); Files.copy(sourcePath, copy); // Register to an incorrect path @@ -2330,7 +2330,7 @@ public void testMoveAndRegister() throws URISyntaxException, CatalogException, I } // We grant permissions to user2 to the study - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), "user2", + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), "user2", new StudyAclParams("", "admin"), ParamUtils.AclAction.ADD, token); // Now, instead of moving it to the user's workspace, we will move it to an external path @@ -2342,7 +2342,7 @@ public void testMoveAndRegister() throws URISyntaxException, CatalogException, I } // Now we add user2 to admins group - catalogManager.getStudyManager().updateGroup(studyFqn, "admins", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "admins", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("user2")), token); // and try the same action again diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/IndividualManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/IndividualManagerTest.java index 0ac883fe91a..49cef3dcf40 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/IndividualManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/IndividualManagerTest.java @@ -42,15 +42,15 @@ public class IndividualManagerTest extends AbstractManagerTest { @Test public void testAnnotateIndividual() throws CatalogException { - VariableSet variableSet = catalogManager.getStudyManager().getVariableSet(studyFqn, "vs", null, token).first(); + VariableSet variableSet = catalogManager.getStudyManager().getVariableSet(organizationId, studyFqn, "vs", null, token).first(); - String individualId1 = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("INDIVIDUAL_1") + String individualId1 = catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("INDIVIDUAL_1") .setKaryotypicSex(IndividualProperty.KaryotypicSex.UNKNOWN).setLifeStatus(IndividualProperty.LifeStatus.UNKNOWN), INCLUDE_RESULT, token).first().getId(); - String individualId2 = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("INDIVIDUAL_2") + String individualId2 = catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("INDIVIDUAL_2") .setKaryotypicSex(IndividualProperty.KaryotypicSex.UNKNOWN).setLifeStatus(IndividualProperty.LifeStatus.UNKNOWN), INCLUDE_RESULT, token).first().getId(); - String individualId3 = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("INDIVIDUAL_3") + String individualId3 = catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("INDIVIDUAL_3") .setKaryotypicSex(IndividualProperty.KaryotypicSex.UNKNOWN).setLifeStatus(IndividualProperty.LifeStatus.UNKNOWN), INCLUDE_RESULT, token).first().getId(); @@ -70,17 +70,17 @@ public void testAnnotateIndividual() throws CatalogException { QueryOptions.empty(), token); List individuals; - individuals = catalogManager.getIndividualManager().search(studyFqn, new Query(IndividualDBAdaptor.QueryParams.ANNOTATION.key(), + individuals = catalogManager.getIndividualManager().search(organizationId, studyFqn, new Query(IndividualDBAdaptor.QueryParams.ANNOTATION.key(), variableSet.getId() + ":NAME=~^INDIVIDUAL_"), null, token) .getResults().stream().map(Individual::getName).collect(Collectors.toList()); assertTrue(individuals.containsAll(Arrays.asList("INDIVIDUAL_1", "INDIVIDUAL_2", "INDIVIDUAL_3"))); - individuals = catalogManager.getIndividualManager().search(studyFqn, new Query(IndividualDBAdaptor.QueryParams.ANNOTATION.key(), + individuals = catalogManager.getIndividualManager().search(organizationId, studyFqn, new Query(IndividualDBAdaptor.QueryParams.ANNOTATION.key(), variableSet.getId() + ":AGE>10"), null, token) .getResults().stream().map(Individual::getName).collect(Collectors.toList()); assertTrue(individuals.containsAll(Arrays.asList("INDIVIDUAL_2", "INDIVIDUAL_3"))); - individuals = catalogManager.getIndividualManager().search(studyFqn, new Query(IndividualDBAdaptor.QueryParams.ANNOTATION.key(), + individuals = catalogManager.getIndividualManager().search(organizationId, studyFqn, new Query(IndividualDBAdaptor.QueryParams.ANNOTATION.key(), variableSet.getId() + ":AGE>10;" + variableSet.getId() + ":PHEN=CASE"), null, token) .getResults().stream().map(Individual::getName).collect(Collectors.toList()); assertTrue(individuals.containsAll(Arrays.asList("INDIVIDUAL_3"))); @@ -91,32 +91,32 @@ public void testDistinctDisorders() throws CatalogException { Individual individual = new Individual() .setId("i1") .setDisorders(Collections.singletonList(new Disorder().setId("disorder1").setName(null))); - catalogManager.getIndividualManager().create(studyFqn, individual, null, token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, individual, null, token); individual = new Individual() .setId("i2") .setDisorders(Collections.singletonList(new Disorder().setId("disorder2"))); - catalogManager.getIndividualManager().create(studyFqn, individual, null, token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, individual, null, token); individual = new Individual() .setId("i3") .setDisorders(Collections.singletonList(new Disorder().setId("disorder2"))); - catalogManager.getIndividualManager().create(studyFqn, individual, null, token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, individual, null, token); individual = new Individual() .setId("i4") .setDisorders(Collections.singletonList(new Disorder().setId("adisorder2"))); - catalogManager.getIndividualManager().create(studyFqn, individual, null, token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, individual, null, token); - OpenCGAResult result = catalogManager.getIndividualManager().distinct(studyFqn, + OpenCGAResult result = catalogManager.getIndividualManager().distinct(organizationId, studyFqn, IndividualDBAdaptor.QueryParams.DISORDERS_ID.key(), new Query(), token); assertEquals(3, result.getNumResults()); - result = catalogManager.getIndividualManager().distinct(studyFqn, IndividualDBAdaptor.QueryParams.DISORDERS_ID.key(), + result = catalogManager.getIndividualManager().distinct(organizationId, studyFqn, IndividualDBAdaptor.QueryParams.DISORDERS_ID.key(), new Query(IndividualDBAdaptor.QueryParams.DISORDERS.key(), "~^disor"), token); assertEquals(2, result.getNumResults()); - result = catalogManager.getIndividualManager().distinct(studyFqn, + result = catalogManager.getIndividualManager().distinct(organizationId, studyFqn, Arrays.asList(IndividualDBAdaptor.QueryParams.DISORDERS_ID.key(), IndividualDBAdaptor.QueryParams.DISORDERS_NAME.key()), new Query(), token); assertEquals(4, result.getNumResults()); @@ -128,23 +128,23 @@ public void testSearchDisordersWithCommas() throws CatalogException { Individual individual = new Individual() .setId("i1") .setDisorders(Collections.singletonList(new Disorder().setId("disorder1, description 1"))); - catalogManager.getIndividualManager().create(studyFqn, individual, null, token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, individual, null, token); individual = new Individual() .setId("i2") .setDisorders(Collections.singletonList(new Disorder().setId("disorder2, description 2"))); - catalogManager.getIndividualManager().create(studyFqn, individual, null, token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, individual, null, token); individual = new Individual() .setId("i3") .setDisorders(Collections.singletonList(new Disorder().setId("disorder2"))); - catalogManager.getIndividualManager().create(studyFqn, individual, null, token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, individual, null, token); - OpenCGAResult result = catalogManager.getIndividualManager().distinct(studyFqn, + OpenCGAResult result = catalogManager.getIndividualManager().distinct(organizationId, studyFqn, IndividualDBAdaptor.QueryParams.DISORDERS_ID.key(), new Query(), token); assertEquals(3, result.getNumResults()); - OpenCGAResult search = catalogManager.getIndividualManager().search(studyFqn, + OpenCGAResult search = catalogManager.getIndividualManager().search(organizationId, studyFqn, new Query(IndividualDBAdaptor.QueryParams.DISORDERS.key(), "disorder1, description 1,disorder2, description 2"), IndividualManager.INCLUDE_INDIVIDUAL_IDS, token); assertEquals(2, search.getNumResults()); @@ -154,7 +154,7 @@ public void testSearchDisordersWithCommas() throws CatalogException { @Test public void testUpdatePhenotypes() throws CatalogException { Individual individual = new Individual().setId("i1"); - catalogManager.getIndividualManager().create(studyFqn, individual, null, token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, individual, null, token); List phenotypeList = Arrays.asList( new Phenotype("phenotype0", "phenotypeName0", "SOURCE"), @@ -164,7 +164,7 @@ public void testUpdatePhenotypes() throws CatalogException { IndividualUpdateParams updateParams = new IndividualUpdateParams().setPhenotypes(phenotypeList); catalogManager.getIndividualManager().update(studyFqn, individual.getId(), updateParams, QueryOptions.empty(), token); - individual = catalogManager.getIndividualManager().get(studyFqn, individual.getId(), QueryOptions.empty(), token).first(); + individual = catalogManager.getIndividualManager().get(organizationId, studyFqn, individual.getId(), QueryOptions.empty(), token).first(); assertEquals(3, individual.getPhenotypes().size()); for (int i = 0; i < individual.getPhenotypes().size(); i++) { assertEquals("phenotype" + i, individual.getPhenotypes().get(i).getId()); @@ -177,7 +177,7 @@ public void testUpdatePhenotypes() throws CatalogException { updateParams = new IndividualUpdateParams().setPhenotypes(Arrays.asList( new Phenotype("phenotype0", "phenotypeName0", "SOURCE"), new Phenotype("phenotype2", "phenotypeName2", "SOURCE"))); catalogManager.getIndividualManager().update(studyFqn, individual.getId(), updateParams, options, token); - individual = catalogManager.getIndividualManager().get(studyFqn, individual.getId(), QueryOptions.empty(), token).first(); + individual = catalogManager.getIndividualManager().get(organizationId, studyFqn, individual.getId(), QueryOptions.empty(), token).first(); assertEquals(1, individual.getPhenotypes().size()); assertEquals("phenotype1", individual.getPhenotypes().get(0).getId()); @@ -187,7 +187,7 @@ public void testUpdatePhenotypes() throws CatalogException { updateParams = new IndividualUpdateParams().setPhenotypes(Arrays.asList( new Phenotype("phenotype1", "phenotypeName1", "SOURCE"), new Phenotype("phenotype2", "phenotypeName2", "SOURCE"))); catalogManager.getIndividualManager().update(studyFqn, individual.getId(), updateParams, options, token); - individual = catalogManager.getIndividualManager().get(studyFqn, individual.getId(), QueryOptions.empty(), token).first(); + individual = catalogManager.getIndividualManager().get(organizationId, studyFqn, individual.getId(), QueryOptions.empty(), token).first(); assertEquals(2, individual.getPhenotypes().size()); for (int i = 0; i < individual.getPhenotypes().size(); i++) { assertEquals("phenotype" + (i + 1), individual.getPhenotypes().get(i).getId()); @@ -202,7 +202,7 @@ public void testUpdatePhenotypes() throws CatalogException { ); updateParams = new IndividualUpdateParams().setPhenotypes(phenotypeList); catalogManager.getIndividualManager().update(studyFqn, individual.getId(), updateParams, options, token); - individual = catalogManager.getIndividualManager().get(studyFqn, individual.getId(), QueryOptions.empty(), token).first(); + individual = catalogManager.getIndividualManager().get(organizationId, studyFqn, individual.getId(), QueryOptions.empty(), token).first(); assertEquals(2, individual.getPhenotypes().size()); for (int i = 0; i < individual.getPhenotypes().size(); i++) { assertEquals("phenotype" + (i + 2), individual.getPhenotypes().get(i).getId()); @@ -212,7 +212,7 @@ public void testUpdatePhenotypes() throws CatalogException { @Test public void testUpdateDisorders() throws CatalogException { Individual individual = new Individual().setId("i1"); - catalogManager.getIndividualManager().create(studyFqn, individual, null, token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, individual, null, token); List disorderList = Arrays.asList( new Disorder("disorder0", "disorderName0", "SOURCE", null, "", null), @@ -222,7 +222,7 @@ public void testUpdateDisorders() throws CatalogException { IndividualUpdateParams updateParams = new IndividualUpdateParams().setDisorders(disorderList); catalogManager.getIndividualManager().update(studyFqn, individual.getId(), updateParams, QueryOptions.empty(), token); - individual = catalogManager.getIndividualManager().get(studyFqn, individual.getId(), QueryOptions.empty(), token).first(); + individual = catalogManager.getIndividualManager().get(organizationId, studyFqn, individual.getId(), QueryOptions.empty(), token).first(); assertEquals(3, individual.getDisorders().size()); for (int i = 0; i < individual.getDisorders().size(); i++) { assertEquals("disorder" + i, individual.getDisorders().get(i).getId()); @@ -236,7 +236,7 @@ public void testUpdateDisorders() throws CatalogException { new Disorder("disorder0", "disorderName0", "SOURCE", null, "", null), new Disorder("disorder2", "disorder2", "SOURCE", null, "", null))); catalogManager.getIndividualManager().update(studyFqn, individual.getId(), updateParams, options, token); - individual = catalogManager.getIndividualManager().get(studyFqn, individual.getId(), QueryOptions.empty(), token).first(); + individual = catalogManager.getIndividualManager().get(organizationId, studyFqn, individual.getId(), QueryOptions.empty(), token).first(); assertEquals(1, individual.getDisorders().size()); assertEquals("disorder1", individual.getDisorders().get(0).getId()); @@ -247,7 +247,7 @@ public void testUpdateDisorders() throws CatalogException { new Disorder("disorder1", "disorderName1", "SOURCE", null, "", null), new Disorder("disorder2", "disorderName2", "SOURCE", null, "", null))); catalogManager.getIndividualManager().update(studyFqn, individual.getId(), updateParams, options, token); - individual = catalogManager.getIndividualManager().get(studyFqn, individual.getId(), QueryOptions.empty(), token).first(); + individual = catalogManager.getIndividualManager().get(organizationId, studyFqn, individual.getId(), QueryOptions.empty(), token).first(); assertEquals(2, individual.getDisorders().size()); for (int i = 0; i < individual.getDisorders().size(); i++) { assertEquals("disorder" + (i + 1), individual.getDisorders().get(i).getId()); @@ -262,7 +262,7 @@ public void testUpdateDisorders() throws CatalogException { ); updateParams = new IndividualUpdateParams().setDisorders(disorderList); catalogManager.getIndividualManager().update(studyFqn, individual.getId(), updateParams, options, token); - individual = catalogManager.getIndividualManager().get(studyFqn, individual.getId(), QueryOptions.empty(), token).first(); + individual = catalogManager.getIndividualManager().get(organizationId, studyFqn, individual.getId(), QueryOptions.empty(), token).first(); assertEquals(2, individual.getDisorders().size()); for (int i = 0; i < individual.getDisorders().size(); i++) { assertEquals("disorder" + (i + 2), individual.getDisorders().get(i).getId()); @@ -274,9 +274,9 @@ public void testUpdateIndividualSamples() throws CatalogException { Sample sample = new Sample().setId("sample1"); Sample sample2 = new Sample().setId("sample2"); Sample sample3 = new Sample().setId("sample3"); - catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), token); - catalogManager.getSampleManager().create(studyFqn, sample2, QueryOptions.empty(), token); - catalogManager.getSampleManager().create(studyFqn, sample3, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample2, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample3, QueryOptions.empty(), token); Individual individual = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("individual"), Arrays.asList(sample.getId(), sample2.getId()), INCLUDE_RESULT, token).first(); @@ -299,7 +299,7 @@ public void testUpdateIndividualSamples() throws CatalogException { options, token); assertEquals(1, update.getNumUpdated()); - individual = catalogManager.getIndividualManager().get(studyFqn, individual.getId(), QueryOptions.empty(), token).first(); + individual = catalogManager.getIndividualManager().get(organizationId, studyFqn, individual.getId(), QueryOptions.empty(), token).first(); assertEquals(3, individual.getSamples().size()); assertEquals(3, individual.getSamples().stream().map(Sample::getId) .filter(s -> Arrays.asList(sample.getId(), sample2.getId(), sample3.getId()).contains(s)).count()); @@ -319,7 +319,7 @@ public void testUpdateIndividualSamples() throws CatalogException { update = catalogManager.getIndividualManager().update(studyFqn, individual.getId(), updateParams, options, token); assertEquals(1, update.getNumUpdated()); - individual = catalogManager.getIndividualManager().get(studyFqn, individual.getId(), QueryOptions.empty(), token).first(); + individual = catalogManager.getIndividualManager().get(organizationId, studyFqn, individual.getId(), QueryOptions.empty(), token).first(); assertEquals(2, individual.getSamples().size()); assertEquals(2, individual.getSamples().stream().map(Sample::getId) .filter(s -> Arrays.asList(sample.getId(), sample3.getId()).contains(s)).count()); @@ -333,7 +333,7 @@ public void testUpdateIndividualSamples() throws CatalogException { update = catalogManager.getIndividualManager().update(studyFqn, individual.getId(), updateParams, options, token); assertEquals(1, update.getNumUpdated()); - individual = catalogManager.getIndividualManager().get(studyFqn, individual.getId(), QueryOptions.empty(), token).first(); + individual = catalogManager.getIndividualManager().get(organizationId, studyFqn, individual.getId(), QueryOptions.empty(), token).first(); assertEquals(2, individual.getSamples().size()); assertEquals(2, individual.getSamples().stream().map(Sample::getId) .filter(s -> Arrays.asList(sample.getId(), sample2.getId()).contains(s)).count()); @@ -344,12 +344,12 @@ public void changeIndividualIdTest() throws CatalogException { Sample sample1 = new Sample().setId("sample1"); Sample sample2 = new Sample().setId("sample2"); Sample sample3 = new Sample().setId("sample3"); - catalogManager.getSampleManager().create(studyFqn, sample1, QueryOptions.empty(), token); - catalogManager.getSampleManager().create(studyFqn, sample2, QueryOptions.empty(), token); - catalogManager.getSampleManager().create(studyFqn, sample3, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample1, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample2, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample3, QueryOptions.empty(), token); catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("individual1"), Arrays.asList(sample1.getId(), sample2.getId(), sample3.getId()), QueryOptions.empty(), token); - List samples = catalogManager.getSampleManager().get(studyFqn, + List samples = catalogManager.getSampleManager().get(organizationId, studyFqn, Arrays.asList(sample1.getId(), sample2.getId(), sample3.getId()), QueryOptions.empty(), token).getResults(); for (Sample sample : samples) { assertEquals("individual1", sample.getIndividualId()); @@ -358,13 +358,13 @@ public void changeIndividualIdTest() throws CatalogException { Sample sample4 = new Sample().setId("sample4"); Sample sample5 = new Sample().setId("sample5"); Sample sample6 = new Sample().setId("sample6"); - catalogManager.getSampleManager().create(studyFqn, sample4, QueryOptions.empty(), token); - catalogManager.getSampleManager().create(studyFqn, sample5, QueryOptions.empty(), token); - catalogManager.getSampleManager().create(studyFqn, sample6, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample4, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample5, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample6, QueryOptions.empty(), token); catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("individual2"), Arrays.asList(sample4.getId(), sample5.getId(), sample6.getId()), QueryOptions.empty(), token); - samples = catalogManager.getSampleManager().get(studyFqn, + samples = catalogManager.getSampleManager().get(organizationId, studyFqn, Arrays.asList(sample4.getId(), sample5.getId(), sample6.getId()), QueryOptions.empty(), token).getResults(); for (Sample sample : samples) { assertEquals("individual2", sample.getIndividualId()); @@ -373,13 +373,13 @@ public void changeIndividualIdTest() throws CatalogException { // Update individual id catalogManager.getIndividualManager().update(studyFqn, "individual1", new IndividualUpdateParams().setId("newId1"), QueryOptions.empty(), token); - assertEquals(1, catalogManager.getIndividualManager().get(studyFqn, "newId1", QueryOptions.empty(), token).getNumResults()); + assertEquals(1, catalogManager.getIndividualManager().get(organizationId, studyFqn, "newId1", QueryOptions.empty(), token).getNumResults()); catalogManager.getIndividualManager().update(studyFqn, "individual2", new IndividualUpdateParams().setId("newId2"), QueryOptions.empty(), token); - assertEquals(1, catalogManager.getIndividualManager().get(studyFqn, "newId2", QueryOptions.empty(), token).getNumResults()); + assertEquals(1, catalogManager.getIndividualManager().get(organizationId, studyFqn, "newId2", QueryOptions.empty(), token).getNumResults()); - samples = catalogManager.getSampleManager().get(studyFqn, + samples = catalogManager.getSampleManager().get(organizationId, studyFqn, Arrays.asList(sample1.getId(), sample2.getId(), sample3.getId(), sample4.getId(), sample5.getId(), sample6.getId()), QueryOptions.empty(), token).getResults(); for (Sample sample : samples) { @@ -425,7 +425,7 @@ public void changeIndividualIdTest2() throws CatalogException { // Update child's id catalogManager.getIndividualManager().update(studyFqn, "child", new IndividualUpdateParams().setId("newId1"), QueryOptions.empty(), token); - family = catalogManager.getFamilyManager().get(studyFqn, "family", QueryOptions.empty(), token).first(); + family = catalogManager.getFamilyManager().get(organizationId, studyFqn, "family", QueryOptions.empty(), token).first(); assertTrue(family.getRoles().containsKey("newId1")); for (Map.Entry> entry : family.getRoles().entrySet()) { @@ -438,16 +438,16 @@ public void changeIndividualIdTest2() throws CatalogException { @Test public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { Sample sample = new Sample().setId("sample1"); - catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample, QueryOptions.empty(), token); sample = new Sample().setId("sample2"); - catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample, QueryOptions.empty(), token); sample = new Sample().setId("sample3"); - catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample, QueryOptions.empty(), token); sample = new Sample().setId("sample4"); - catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample, QueryOptions.empty(), token); Individual individual = new Individual() .setId("proband") @@ -475,7 +475,7 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { .setProband(new Individual().setId("proband")) .setFamily(family) .setType(ClinicalAnalysis.Type.FAMILY); - catalogManager.getClinicalAnalysisManager().create(studyFqn, clinicalAnalysis, QueryOptions.empty(), token); + catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, clinicalAnalysis, QueryOptions.empty(), token); // We will create another clinical analysis with the same information. In this test, we will not lock clinical2 clinicalAnalysis = new ClinicalAnalysis() @@ -483,23 +483,23 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { .setProband(new Individual().setId("proband")) .setFamily(family) .setType(ClinicalAnalysis.Type.FAMILY); - catalogManager.getClinicalAnalysisManager().create(studyFqn, clinicalAnalysis, QueryOptions.empty(), token); + catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, clinicalAnalysis, QueryOptions.empty(), token); // Update brother not used in Clinical Analysis catalogManager.getIndividualManager().update(studyFqn, "brother", new IndividualUpdateParams() .setName(RandomStringUtils.random(10)), new QueryOptions(), token); - Individual individualResult = catalogManager.getIndividualManager().get(studyFqn, "brother", QueryOptions.empty(), token).first(); + Individual individualResult = catalogManager.getIndividualManager().get(organizationId, studyFqn, "brother", QueryOptions.empty(), token).first(); assertEquals(3, individualResult.getVersion()); - Family familyResult = catalogManager.getFamilyManager().get(studyFqn, "family", QueryOptions.empty(), token).first(); + Family familyResult = catalogManager.getFamilyManager().get(organizationId, studyFqn, "family", QueryOptions.empty(), token).first(); assertEquals(2, familyResult.getVersion()); assertEquals(3, familyResult.getMembers().size()); assertEquals(2, familyResult.getMembers().get(0).getVersion()); assertEquals(2, familyResult.getMembers().get(1).getVersion()); assertEquals(3, familyResult.getMembers().get(2).getVersion()); - ClinicalAnalysis clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical", QueryOptions.empty(), + ClinicalAnalysis clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical", QueryOptions.empty(), token).first(); assertEquals(2, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample1 version @@ -508,7 +508,7 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { assertEquals(2, clinicalResult.getFamily().getMembers().get(0).getVersion()); // proband version assertEquals(2, clinicalResult.getFamily().getMembers().get(1).getVersion()); // father version - clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical2", QueryOptions.empty(), token).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical2", QueryOptions.empty(), token).first(); assertEquals(2, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample1 version assertEquals(2, clinicalResult.getFamily().getVersion()); @@ -520,17 +520,17 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { catalogManager.getIndividualManager().update(studyFqn, "father", new IndividualUpdateParams() .setName(RandomStringUtils.random(10)), new QueryOptions(), token); - individualResult = catalogManager.getIndividualManager().get(studyFqn, "father", QueryOptions.empty(), token).first(); + individualResult = catalogManager.getIndividualManager().get(organizationId, studyFqn, "father", QueryOptions.empty(), token).first(); assertEquals(3, individualResult.getVersion()); - familyResult = catalogManager.getFamilyManager().get(studyFqn, "family", QueryOptions.empty(), token).first(); + familyResult = catalogManager.getFamilyManager().get(organizationId, studyFqn, "family", QueryOptions.empty(), token).first(); assertEquals(3, familyResult.getVersion()); assertEquals(3, familyResult.getMembers().size()); assertEquals(2, familyResult.getMembers().get(0).getVersion()); assertEquals(3, familyResult.getMembers().get(1).getVersion()); assertEquals(3, familyResult.getMembers().get(2).getVersion()); - clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical", QueryOptions.empty(), token).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical", QueryOptions.empty(), token).first(); assertEquals(2, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample1 version assertEquals(3, clinicalResult.getFamily().getVersion()); @@ -538,7 +538,7 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { assertEquals(2, clinicalResult.getFamily().getMembers().get(0).getVersion()); // proband version assertEquals(3, clinicalResult.getFamily().getMembers().get(1).getVersion()); // father version - clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical2", QueryOptions.empty(), token).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical2", QueryOptions.empty(), token).first(); assertEquals(2, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample1 version assertEquals(3, clinicalResult.getFamily().getVersion()); @@ -547,26 +547,26 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { assertEquals(3, clinicalResult.getFamily().getMembers().get(1).getVersion()); // father version // LOCK CLINICAL ANALYSIS - catalogManager.getClinicalAnalysisManager().update(studyFqn, "clinical", new ClinicalAnalysisUpdateParams().setLocked(true), + catalogManager.getClinicalAnalysisManager().update(organizationId, studyFqn, "clinical", new ClinicalAnalysisUpdateParams().setLocked(true), QueryOptions.empty(), token); - clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical", QueryOptions.empty(), token).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical", QueryOptions.empty(), token).first(); assertTrue(clinicalResult.isLocked()); // Update proband catalogManager.getIndividualManager().update(studyFqn, "proband", new IndividualUpdateParams() .setName(RandomStringUtils.random(10)), new QueryOptions(), token); - individualResult = catalogManager.getIndividualManager().get(studyFqn, "proband", QueryOptions.empty(), token).first(); + individualResult = catalogManager.getIndividualManager().get(organizationId, studyFqn, "proband", QueryOptions.empty(), token).first(); assertEquals(3, individualResult.getVersion()); - familyResult = catalogManager.getFamilyManager().get(studyFqn, "family", QueryOptions.empty(), token).first(); + familyResult = catalogManager.getFamilyManager().get(organizationId, studyFqn, "family", QueryOptions.empty(), token).first(); assertEquals(4, familyResult.getVersion()); assertEquals(3, familyResult.getMembers().size()); assertEquals(3, familyResult.getMembers().get(0).getVersion()); assertEquals(3, familyResult.getMembers().get(1).getVersion()); assertEquals(3, familyResult.getMembers().get(2).getVersion()); - clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical", QueryOptions.empty(), token).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical", QueryOptions.empty(), token).first(); assertEquals(2, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample1 version assertEquals(3, clinicalResult.getFamily().getVersion()); @@ -574,7 +574,7 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { assertEquals(2, clinicalResult.getFamily().getMembers().get(0).getVersion()); // proband version assertEquals(3, clinicalResult.getFamily().getMembers().get(1).getVersion()); // father version - clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical2", QueryOptions.empty(), token).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical2", QueryOptions.empty(), token).first(); assertEquals(3, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample2 version assertEquals(4, clinicalResult.getFamily().getVersion()); @@ -586,17 +586,17 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { catalogManager.getIndividualManager().update(studyFqn, "father", new IndividualUpdateParams() .setName(RandomStringUtils.random(10)), new QueryOptions(), token); - individualResult = catalogManager.getIndividualManager().get(studyFqn, "father", QueryOptions.empty(), token).first(); + individualResult = catalogManager.getIndividualManager().get(organizationId, studyFqn, "father", QueryOptions.empty(), token).first(); assertEquals(4, individualResult.getVersion()); - familyResult = catalogManager.getFamilyManager().get(studyFqn, "family", QueryOptions.empty(), token).first(); + familyResult = catalogManager.getFamilyManager().get(organizationId, studyFqn, "family", QueryOptions.empty(), token).first(); assertEquals(5, familyResult.getVersion()); assertEquals(3, familyResult.getMembers().size()); assertEquals(3, familyResult.getMembers().get(0).getVersion()); assertEquals(4, familyResult.getMembers().get(1).getVersion()); assertEquals(3, familyResult.getMembers().get(2).getVersion()); - clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical", QueryOptions.empty(), token).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical", QueryOptions.empty(), token).first(); assertEquals(2, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample1 version assertEquals(3, clinicalResult.getFamily().getVersion()); @@ -604,7 +604,7 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { assertEquals(2, clinicalResult.getFamily().getMembers().get(0).getVersion()); // proband version assertEquals(3, clinicalResult.getFamily().getMembers().get(1).getVersion()); // father version - clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical2", QueryOptions.empty(), token).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical2", QueryOptions.empty(), token).first(); assertEquals(3, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample2 version assertEquals(5, clinicalResult.getFamily().getVersion()); @@ -616,7 +616,7 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { @Test public void testUpdateIndividualQualityControl() throws CatalogException { IndividualManager individualManager = catalogManager.getIndividualManager(); - DataResult individualDataResult = individualManager.create(studyFqn, new Individual().setId("Test") + DataResult individualDataResult = individualManager.create(organizationId, studyFqn, new Individual().setId("Test") .setDateOfBirth("19870214"), INCLUDE_RESULT, token); IndividualQualityControl qualityControl = new IndividualQualityControl(null, null, null, Collections.emptyList(), @@ -625,7 +625,7 @@ public void testUpdateIndividualQualityControl() throws CatalogException { new IndividualUpdateParams().setQualityControl(qualityControl), QueryOptions.empty(), token); assertEquals(1, update.getNumUpdated()); - Individual individual = individualManager.get(studyFqn, individualDataResult.first().getId(), QueryOptions.empty(), token) + Individual individual = individualManager.get(organizationId, studyFqn, individualDataResult.first().getId(), QueryOptions.empty(), token) .first(); assertEquals(1, individual.getQualityControl().getComments().size()); assertEquals("pfurio", individual.getQualityControl().getComments().get(0).getAuthor()); @@ -637,7 +637,7 @@ public void testUpdateIndividualQualityControl() throws CatalogException { @Test public void testUpdateIndividualInfo() throws CatalogException { IndividualManager individualManager = catalogManager.getIndividualManager(); - DataResult individualDataResult = individualManager.create(studyFqn, new Individual().setId("Test") + DataResult individualDataResult = individualManager.create(organizationId, studyFqn, new Individual().setId("Test") .setDateOfBirth("19870214"), INCLUDE_RESULT, token); assertEquals(1, individualDataResult.getNumResults()); assertEquals("Test", individualDataResult.first().getId()); @@ -647,28 +647,28 @@ public void testUpdateIndividualInfo() throws CatalogException { new IndividualUpdateParams().setDateOfBirth(""), QueryOptions.empty(), token); assertEquals(1, update.getNumUpdated()); - Individual individual = individualManager.get(studyFqn, individualDataResult.first().getId(), QueryOptions.empty(), token) + Individual individual = individualManager.get(organizationId, studyFqn, individualDataResult.first().getId(), QueryOptions.empty(), token) .first(); assertEquals("", individual.getDateOfBirth()); update = individualManager.update(studyFqn, individualDataResult.first().getId(), new IndividualUpdateParams().setDateOfBirth("19870214"), QueryOptions.empty(), token); assertEquals(1, update.getNumUpdated()); - individual = individualManager.get(studyFqn, individualDataResult.first().getId(), QueryOptions.empty(), token) + individual = individualManager.get(organizationId, studyFqn, individualDataResult.first().getId(), QueryOptions.empty(), token) .first(); assertEquals("19870214", individual.getDateOfBirth()); update = individualManager.update(studyFqn, individualDataResult.first().getId(), new IndividualUpdateParams().setAttributes(Collections.singletonMap("key", "value")), QueryOptions.empty(), token); assertEquals(1, update.getNumUpdated()); - individual = individualManager.get(studyFqn, individualDataResult.first().getId(), QueryOptions.empty(), token) + individual = individualManager.get(organizationId, studyFqn, individualDataResult.first().getId(), QueryOptions.empty(), token) .first(); assertEquals("value", individual.getAttributes().get("key")); update = individualManager.update(studyFqn, individualDataResult.first().getId(), new IndividualUpdateParams().setAttributes(Collections.singletonMap("key2", "value2")), QueryOptions.empty(), token); assertEquals(1, update.getNumUpdated()); - individual = individualManager.get(studyFqn, individualDataResult.first().getId(), QueryOptions.empty(), token) + individual = individualManager.get(organizationId, studyFqn, individualDataResult.first().getId(), QueryOptions.empty(), token) .first(); assertEquals("value", individual.getAttributes().get("key")); // Keep "key" assertEquals("value2", individual.getAttributes().get("key2")); // add new "key2" @@ -683,16 +683,16 @@ public void testUpdateIndividualInfo() throws CatalogException { @Test public void testUpdateIndividualParents() throws CatalogException { IndividualManager individualManager = catalogManager.getIndividualManager(); - individualManager.create(studyFqn, new Individual().setId("child"), QueryOptions.empty(), token); - individualManager.create(studyFqn, new Individual().setId("father"), QueryOptions.empty(), token); - individualManager.create(studyFqn, new Individual().setId("mother"), QueryOptions.empty(), token); + individualManager.create(organizationId, studyFqn, new Individual().setId("child"), QueryOptions.empty(), token); + individualManager.create(organizationId, studyFqn, new Individual().setId("father"), QueryOptions.empty(), token); + individualManager.create(organizationId, studyFqn, new Individual().setId("mother"), QueryOptions.empty(), token); DataResult individualDataResult = individualManager.update(studyFqn, "child", new IndividualUpdateParams().setFather(new IndividualReferenceParam("father", "")) .setMother(new IndividualReferenceParam("mother", "")), QueryOptions.empty(), token); assertEquals(1, individualDataResult.getNumUpdated()); - Individual individual = individualManager.get(studyFqn, "child", QueryOptions.empty(), token).first(); + Individual individual = individualManager.get(organizationId, studyFqn, "child", QueryOptions.empty(), token).first(); assertEquals("mother", individual.getMother().getId()); assertEquals(1, individual.getMother().getVersion()); @@ -704,16 +704,16 @@ public void testUpdateIndividualParents() throws CatalogException { @Test public void testRemoveIndividualParents() throws CatalogException { IndividualManager individualManager = catalogManager.getIndividualManager(); - individualManager.create(studyFqn, new Individual().setId("child"), QueryOptions.empty(), token); - individualManager.create(studyFqn, new Individual().setId("father"), QueryOptions.empty(), token); - individualManager.create(studyFqn, new Individual().setId("mother"), QueryOptions.empty(), token); + individualManager.create(organizationId, studyFqn, new Individual().setId("child"), QueryOptions.empty(), token); + individualManager.create(organizationId, studyFqn, new Individual().setId("father"), QueryOptions.empty(), token); + individualManager.create(organizationId, studyFqn, new Individual().setId("mother"), QueryOptions.empty(), token); DataResult individualDataResult = individualManager.update(studyFqn, "child", new IndividualUpdateParams().setFather(new IndividualReferenceParam("father", "")) .setMother(new IndividualReferenceParam("mother", "")), QueryOptions.empty(), token); assertEquals(1, individualDataResult.getNumUpdated()); - Individual individual = individualManager.get(studyFqn, "child", QueryOptions.empty(), token).first(); + Individual individual = individualManager.get(organizationId, studyFqn, "child", QueryOptions.empty(), token).first(); assertEquals("mother", individual.getMother().getId()); assertEquals(1, individual.getMother().getVersion()); @@ -723,7 +723,7 @@ public void testRemoveIndividualParents() throws CatalogException { individualManager.update(studyFqn, "child", new IndividualUpdateParams().setFather(new IndividualReferenceParam("", "")) .setMother(new IndividualReferenceParam("", "")), QueryOptions.empty(), token); - individual = individualManager.get(studyFqn, "child", QueryOptions.empty(), token).first(); + individual = individualManager.get(organizationId, studyFqn, "child", QueryOptions.empty(), token).first(); assertNull(individual.getMother().getId()); assertNull(individual.getFather().getId()); @@ -732,15 +732,15 @@ public void testRemoveIndividualParents() throws CatalogException { @Test public void testIndividualRelatives() throws CatalogException { IndividualManager individualManager = catalogManager.getIndividualManager(); - individualManager.create(studyFqn, new Individual().setId("proband").setSex(SexOntologyTermAnnotation.initMale()), + individualManager.create(organizationId, studyFqn, new Individual().setId("proband").setSex(SexOntologyTermAnnotation.initMale()), QueryOptions.empty(), token); - individualManager.create(studyFqn, new Individual().setId("brother").setSex(SexOntologyTermAnnotation.initMale()), + individualManager.create(organizationId, studyFqn, new Individual().setId("brother").setSex(SexOntologyTermAnnotation.initMale()), QueryOptions.empty(), token); - individualManager.create(studyFqn, new Individual().setId("sister").setSex(SexOntologyTermAnnotation.initFemale()), + individualManager.create(organizationId, studyFqn, new Individual().setId("sister").setSex(SexOntologyTermAnnotation.initFemale()), QueryOptions.empty(), token); - individualManager.create(studyFqn, new Individual().setId("father").setSex(SexOntologyTermAnnotation.initMale()), + individualManager.create(organizationId, studyFqn, new Individual().setId("father").setSex(SexOntologyTermAnnotation.initMale()), QueryOptions.empty(), token); - individualManager.create(studyFqn, new Individual().setId("mother").setSex(SexOntologyTermAnnotation.initFemale()), + individualManager.create(organizationId, studyFqn, new Individual().setId("mother").setSex(SexOntologyTermAnnotation.initFemale()), QueryOptions.empty(), token); individualManager.update(studyFqn, "proband", new IndividualUpdateParams().setFather(new IndividualReferenceParam("father", "")) @@ -763,7 +763,7 @@ public void testIndividualRelatives() throws CatalogException { @Test public void testDeleteIndividualWithFamilies() throws CatalogException { IndividualManager individualManager = catalogManager.getIndividualManager(); - Individual child = individualManager.create(studyFqn, new Individual() + Individual child = individualManager.create(organizationId, studyFqn, new Individual() .setId("child") .setPhenotypes(Collections.singletonList(new Phenotype().setId("phenotype1"))) .setDisorders(Collections.singletonList(new Disorder().setId("disorder1"))), @@ -784,19 +784,19 @@ public void testDeleteIndividualWithFamilies() throws CatalogException { Arrays.asList(father.getId(), child.getId()), QueryOptions.empty(), token); try { - DataResult writeResult = individualManager.delete(studyFqn, new Query(IndividualDBAdaptor.QueryParams.ID.key(), "child"), + DataResult writeResult = individualManager.delete(organizationId, studyFqn, new Query(IndividualDBAdaptor.QueryParams.ID.key(), "child"), new QueryOptions(), token); fail("Expected fail"); } catch (CatalogException e) { assertTrue(e.getMessage().contains("found in the families")); } - DataResult writeResult = individualManager.delete(studyFqn, new Query(IndividualDBAdaptor.QueryParams.ID.key(), "child"), + DataResult writeResult = individualManager.delete(organizationId, studyFqn, new Query(IndividualDBAdaptor.QueryParams.ID.key(), "child"), new QueryOptions(Constants.FORCE, true), token); assertEquals(1, writeResult.getNumDeleted()); - Family family1 = familyManager.get(studyFqn, "family1", QueryOptions.empty(), token).first(); - Family family2 = familyManager.get(studyFqn, "family2", QueryOptions.empty(), token).first(); + Family family1 = familyManager.get(organizationId, studyFqn, "family1", QueryOptions.empty(), token).first(); + Family family2 = familyManager.get(organizationId, studyFqn, "family2", QueryOptions.empty(), token).first(); assertEquals(1, family1.getMembers().size()); assertEquals(0, family1.getMembers().stream().filter(i -> i.getId().equals("child")).count()); @@ -818,16 +818,16 @@ public void testDeleteIndividualWithFamilies() throws CatalogException { @Test public void testGetIndividualWithSamples() throws CatalogException { IndividualManager individualManager = catalogManager.getIndividualManager(); - individualManager.create(studyFqn, new Individual().setId("individual1") + individualManager.create(organizationId, studyFqn, new Individual().setId("individual1") .setSamples(Arrays.asList(new Sample().setId("sample1"), new Sample().setId("sample2"), new Sample().setId( "sample3"))), QueryOptions.empty(), token); - individualManager.create(studyFqn, new Individual().setId("individual2") + individualManager.create(organizationId, studyFqn, new Individual().setId("individual2") .setSamples(Arrays.asList(new Sample().setId("sample4"), new Sample().setId("sample5"), new Sample().setId( "sample6"))), QueryOptions.empty(), token); - DataResult search = individualManager.search(studyFqn, new Query(), QueryOptions.empty(), token); + DataResult search = individualManager.search(organizationId, studyFqn, new Query(), QueryOptions.empty(), token); assertEquals(2, search.getNumResults()); search.getResults().forEach(i -> { assertEquals(3, i.getSamples().size()); @@ -843,7 +843,7 @@ public void testGetIndividualWithSamples() throws CatalogException { } }); - search = individualManager.search(studyFqn, new Query(), new QueryOptions(QueryOptions.EXCLUDE, "samples.creationDate"), + search = individualManager.search(organizationId, studyFqn, new Query(), new QueryOptions(QueryOptions.EXCLUDE, "samples.creationDate"), token); assertEquals(2, search.getNumResults()); search.getResults().forEach(i -> { @@ -860,7 +860,7 @@ public void testGetIndividualWithSamples() throws CatalogException { } }); - search = individualManager.search(studyFqn, new Query(), new QueryOptions(QueryOptions.INCLUDE, "samples.id"), + search = individualManager.search(organizationId, studyFqn, new Query(), new QueryOptions(QueryOptions.INCLUDE, "samples.id"), token); assertEquals(2, search.getNumResults()); search.getResults().forEach(i -> { @@ -877,7 +877,7 @@ public void testGetIndividualWithSamples() throws CatalogException { } }); - search = individualManager.search(studyFqn, new Query(), new QueryOptions(QueryOptions.INCLUDE, "id,creationDate,samples.id"), + search = individualManager.search(organizationId, studyFqn, new Query(), new QueryOptions(QueryOptions.INCLUDE, "id,creationDate,samples.id"), token); assertEquals(2, search.getNumResults()); search.getResults().forEach(i -> { @@ -903,10 +903,10 @@ public void incrementVersionTest() throws CatalogException { Individual dummyIndividual1 = DummyModelUtils.getDummyIndividual(null, null, null, null); Individual dummyIndividual2 = DummyModelUtils.getDummyIndividual(null, null, null, null); - catalogManager.getIndividualManager().create(studyFqn, dummyIndividual1, QueryOptions.empty(), token); - catalogManager.getIndividualManager().create(studyFqn, dummyIndividual2, QueryOptions.empty(), token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, dummyIndividual1, QueryOptions.empty(), token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, dummyIndividual2, QueryOptions.empty(), token); - OpenCGAResult result = catalogManager.getIndividualManager().get(studyFqn, + OpenCGAResult result = catalogManager.getIndividualManager().get(organizationId, studyFqn, Arrays.asList(dummyIndividual1.getId(), dummyIndividual2.getId()), QueryOptions.empty(), token); for (Individual individual : result.getResults()) { assertEquals(1, individual.getVersion()); @@ -914,7 +914,7 @@ public void incrementVersionTest() throws CatalogException { catalogManager.getIndividualManager().update(studyFqn, dummyIndividual1.getId(), new IndividualUpdateParams().setName("name"), QueryOptions.empty(), token); - result = catalogManager.getIndividualManager().get(studyFqn, + result = catalogManager.getIndividualManager().get(organizationId, studyFqn, Arrays.asList(dummyIndividual1.getId(), dummyIndividual2.getId()), QueryOptions.empty(), token); assertEquals(2, result.first().getVersion()); assertEquals("name", result.first().getName()); @@ -924,7 +924,7 @@ public void incrementVersionTest() throws CatalogException { .append(IndividualDBAdaptor.QueryParams.ID.key(), dummyIndividual1.getId()) .append(Constants.ALL_VERSIONS, true); - result = catalogManager.getIndividualManager().search(studyFqn, query, QueryOptions.empty(), token); + result = catalogManager.getIndividualManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(2, result.getNumResults()); assertEquals(dummyIndividual1.getId(), result.getResults().get(0).getName()); assertEquals(1, result.getResults().get(0).getVersion()); @@ -952,13 +952,13 @@ public void memberReferenceTest() throws CatalogException { family.setMembers(null); QueryOptions options = new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true); - individual1 = catalogManager.getIndividualManager().create(studyFqn, individual1, options, token).first(); + individual1 = catalogManager.getIndividualManager().create(organizationId, studyFqn, individual1, options, token).first(); assertEquals(1, individual1.getVersion()); assertEquals(2, individual1.getSamples().size()); assertEquals(2, individual1.getSamples().stream().map(Sample::getVersion).filter(v -> v == 1).count()); assertEquals(2, individual1.getSamples().stream().map(Sample::getIndividualId).filter(i -> i.equals(individualId1)).count()); - individual2 = catalogManager.getIndividualManager().create(studyFqn, individual2, options, token).first(); + individual2 = catalogManager.getIndividualManager().create(organizationId, studyFqn, individual2, options, token).first(); assertEquals(1, individual2.getVersion()); assertEquals(2, individual2.getSamples().size()); assertEquals(2, individual2.getSamples().stream().map(Sample::getVersion).filter(v -> v == 1).count()); @@ -980,7 +980,7 @@ public void memberReferenceTest() throws CatalogException { assertEquals(1, individual2.getFamilyIds().size()); assertEquals(family.getId(), individual2.getFamilyIds().get(0)); - family = catalogManager.getFamilyManager().get(studyFqn, family.getId(), QueryOptions.empty(), token).first(); + family = catalogManager.getFamilyManager().get(organizationId, studyFqn, family.getId(), QueryOptions.empty(), token).first(); assertTrue(family.getRoles().containsKey(individualId1)); assertFalse(family.getRoles().containsKey("blabla")); assertEquals(2, family.getMembers().size()); @@ -1004,13 +1004,13 @@ public void memberReferenceTest() throws CatalogException { assertEquals(1, individual1.getFamilyIds().size()); assertEquals(family.getId(), individual1.getFamilyIds().get(0)); - family = catalogManager.getFamilyManager().get(studyFqn, family.getId(), QueryOptions.empty(), token).first(); + family = catalogManager.getFamilyManager().get(organizationId, studyFqn, family.getId(), QueryOptions.empty(), token).first(); assertEquals(2, family.getMembers().size()); assertEquals(2, family.getMembers().stream().map(Individual::getVersion).filter(v -> v == 3).count()); assertFalse(family.getRoles().containsKey(individualId1)); assertTrue(family.getRoles().containsKey("blabla")); - List samples = catalogManager.getSampleManager().get(studyFqn, Arrays.asList(sample1.getId(), sample2.getId()), + List samples = catalogManager.getSampleManager().get(organizationId, studyFqn, Arrays.asList(sample1.getId(), sample2.getId()), QueryOptions.empty(), token).getResults(); for (Sample sample : samples) { assertEquals("blabla", sample.getIndividualId()); @@ -1025,7 +1025,7 @@ public void updateInUseInCATest() throws CatalogException { Family family = DummyModelUtils.getDummyCaseFamily("family1"); for (int i = family.getMembers().size() - 1; i >= 0; i--) { - catalogManager.getIndividualManager().create(studyFqn, family.getMembers().get(i), QueryOptions.empty(), token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, family.getMembers().get(i), QueryOptions.empty(), token); } List members = family.getMembers().stream().map(Individual::getId).collect(Collectors.toList()); @@ -1040,11 +1040,11 @@ public void updateInUseInCATest() throws CatalogException { ClinicalAnalysis case3 = DummyModelUtils.getDummyClinicalAnalysis(family.getMembers().get(0), family, null) .setLocked(true); - case1 = catalogManager.getClinicalAnalysisManager().create(studyFqn, case1, options, token).first(); + case1 = catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case1, options, token).first(); assertFalse(case1.isLocked()); - case2 = catalogManager.getClinicalAnalysisManager().create(studyFqn, case2, options, token).first(); + case2 = catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case2, options, token).first(); assertFalse(case2.isLocked()); - case3 = catalogManager.getClinicalAnalysisManager().create(studyFqn, case3, options, token).first(); + case3 = catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case3, options, token).first(); assertTrue(case3.isLocked()); String oldProbandId = case3.getProband().getId(); @@ -1055,13 +1055,13 @@ public void updateInUseInCATest() throws CatalogException { assertEquals("blabla", proband.getId()); assertEquals(3, proband.getVersion()); - family = catalogManager.getFamilyManager().get(studyFqn, family.getId(), QueryOptions.empty(), token).first(); + family = catalogManager.getFamilyManager().get(organizationId, studyFqn, family.getId(), QueryOptions.empty(), token).first(); assertEquals(2, family.getVersion()); assertTrue(family.getRoles().containsKey("blabla")); assertEquals(1, family.getMembers().stream().filter(i -> i.getId().equals("blabla")).count()); assertEquals(1, family.getMembers().stream().filter(i -> i.getId().equals("blabla")).filter(i -> i.getVersion() == 3).count()); - OpenCGAResult result = catalogManager.getClinicalAnalysisManager().get(studyFqn, + OpenCGAResult result = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, Arrays.asList(case1.getId(), case2.getId(), case3.getId()), QueryOptions.empty(), token); case1 = result.getResults().get(0); case2 = result.getResults().get(1); @@ -1087,7 +1087,7 @@ public void updateDeleteInUseInCATest() throws CatalogException { Family family = DummyModelUtils.getDummyCaseFamily("family1"); for (int i = family.getMembers().size() - 1; i >= 0; i--) { - catalogManager.getIndividualManager().create(studyFqn, family.getMembers().get(i), QueryOptions.empty(), token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, family.getMembers().get(i), QueryOptions.empty(), token); } List members = family.getMembers().stream().map(Individual::getId).collect(Collectors.toList()); @@ -1102,27 +1102,27 @@ public void updateDeleteInUseInCATest() throws CatalogException { ClinicalAnalysis case3 = DummyModelUtils.getDummyClinicalAnalysis(family.getMembers().get(0), family, null) .setLocked(true); - case1 = catalogManager.getClinicalAnalysisManager().create(studyFqn, case1, options, token).first(); + case1 = catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case1, options, token).first(); assertFalse(case1.isLocked()); - case2 = catalogManager.getClinicalAnalysisManager().create(studyFqn, case2, options, token).first(); + case2 = catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case2, options, token).first(); assertFalse(case2.isLocked()); - case3 = catalogManager.getClinicalAnalysisManager().create(studyFqn, case3, options, token).first(); + case3 = catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case3, options, token).first(); assertTrue(case3.isLocked()); // Delete proband try { - catalogManager.getIndividualManager().delete(studyFqn, Collections.singletonList(case1.getProband().getId()), + catalogManager.getIndividualManager().delete(organizationId, studyFqn, Collections.singletonList(case1.getProband().getId()), new QueryOptions(ParamConstants.FORCE, true), token); } catch (CatalogException e) { assertTrue(e.getMessage().contains("in use in 3 cases")); } // unlock case3 - catalogManager.getClinicalAnalysisManager().update(studyFqn, case3.getId(), new ClinicalAnalysisUpdateParams().setLocked(false), + catalogManager.getClinicalAnalysisManager().update(organizationId, studyFqn, case3.getId(), new ClinicalAnalysisUpdateParams().setLocked(false), QueryOptions.empty(), token); try { - catalogManager.getIndividualManager().delete(studyFqn, Collections.singletonList(case1.getProband().getId()), + catalogManager.getIndividualManager().delete(organizationId, studyFqn, Collections.singletonList(case1.getProband().getId()), new QueryOptions(ParamConstants.FORCE, true), token); } catch (CatalogException e) { assertTrue(e.getMessage().contains("in use in 3 cases")); diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/InterpretationManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/InterpretationManagerTest.java index f3e32569bb0..216bca2005f 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/InterpretationManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/InterpretationManagerTest.java @@ -77,7 +77,7 @@ public void tearDown() throws Exception { private DataResult createDummyFamily() throws CatalogException { Family family = DummyModelUtils.getDummyFamily("family"); - return familyManager.create(STUDY, family, INCLUDE_RESULT, sessionIdUser); + return familyManager.create(organizationId, STUDY, family, INCLUDE_RESULT, sessionIdUser); } private DataResult createDummyEnvironment(boolean createFamily, boolean createDefaultInterpretation) throws CatalogException { @@ -94,7 +94,7 @@ private DataResult createDummyEnvironment(boolean createFamily clinicalAnalysis.setFamily(new Family().setId("family") .setMembers(Arrays.asList(new Individual().setId("child1").setSamples(Arrays.asList(new Sample().setId("sample2")))))); - return catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, !createDefaultInterpretation, + return catalogManager.getClinicalAnalysisManager().create(organizationId, STUDY, clinicalAnalysis, !createDefaultInterpretation, INCLUDE_RESULT, sessionIdUser); } @@ -122,9 +122,9 @@ public void deleteLockedInterpretationTest() throws CatalogException { ClinicalAnalysis ca = createDummyEnvironment(true, false).first(); catalogManager.getInterpretationManager().create(STUDY, ca.getId(), new Interpretation().setLocked(true), ParamUtils.SaveInterpretationAs.PRIMARY, QueryOptions.empty(), sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); - Interpretation interpretation = catalogManager.getInterpretationManager().get(STUDY, ca.getInterpretation().getId(), + Interpretation interpretation = catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getInterpretation().getId(), QueryOptions.empty(), sessionIdUser).first(); assertTrue(interpretation.isLocked()); @@ -140,14 +140,14 @@ public void deleteLockedInterpretationTest() throws CatalogException { // Unlock interpretation catalogManager.getInterpretationManager().update(STUDY, ca.getId(), ca.getInterpretation().getId(), new InterpretationUpdateParams().setLocked(false), null, QueryOptions.empty(), sessionIdUser); - interpretation = catalogManager.getInterpretationManager().get(STUDY, ca.getInterpretation().getId(), + interpretation = catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getInterpretation().getId(), QueryOptions.empty(), sessionIdUser).first(); assertFalse(interpretation.isLocked()); // Delete interpretation catalogManager.getInterpretationManager().delete(STUDY, ca.getId(), Collections.singletonList(ca.getInterpretation().getId()), sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNull(ca.getInterpretation()); } @@ -183,7 +183,7 @@ public void interpretationLockedTest() throws CatalogException { catalogManager.getInterpretationManager().create(STUDY, ca.getId(), new Interpretation(), ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertTrue(ca.getInterpretation().isLocked()); for (Interpretation secondaryInterpretation : ca.getSecondaryInterpretations()) { assertFalse(secondaryInterpretation.isLocked()); @@ -201,14 +201,14 @@ public void interpretationLockedTest() throws CatalogException { // Update interpretation 2 catalogManager.getInterpretationManager().update(STUDY, ca.getId(), ca.getSecondaryInterpretations().get(0).getId(), new InterpretationUpdateParams().setDescription("blabla"), null, QueryOptions.empty(), sessionIdUser); - Interpretation interpretation2 = catalogManager.getInterpretationManager().get(STUDY, + Interpretation interpretation2 = catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getSecondaryInterpretations().get(0).getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals("blabla", interpretation2.getDescription()); assertFalse(interpretation2.isLocked()); catalogManager.getInterpretationManager().update(STUDY, ca.getId(), ca.getSecondaryInterpretations().get(0).getId(), new InterpretationUpdateParams().setDescription("bloblo").setLocked(true), null, QueryOptions.empty(), sessionIdUser); - interpretation2 = catalogManager.getInterpretationManager().get(STUDY, + interpretation2 = catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getSecondaryInterpretations().get(0).getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals("bloblo", interpretation2.getDescription()); assertTrue(interpretation2.isLocked()); @@ -225,7 +225,7 @@ public void interpretationLockedTest() throws CatalogException { // Unlock and update interpretation 2 catalogManager.getInterpretationManager().update(STUDY, ca.getId(), ca.getSecondaryInterpretations().get(0).getId(), new InterpretationUpdateParams().setDescription("blabla").setLocked(false), null, QueryOptions.empty(), sessionIdUser); - interpretation2 = catalogManager.getInterpretationManager().get(STUDY, + interpretation2 = catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getSecondaryInterpretations().get(0).getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals("blabla", interpretation2.getDescription()); assertFalse(interpretation2.isLocked()); @@ -233,15 +233,15 @@ public void interpretationLockedTest() throws CatalogException { // Lock and update interpretation 2 catalogManager.getInterpretationManager().update(STUDY, ca.getId(), ca.getSecondaryInterpretations().get(0).getId(), new InterpretationUpdateParams().setDescription("bloblo").setLocked(true), null, QueryOptions.empty(), sessionIdUser); - interpretation2 = catalogManager.getInterpretationManager().get(STUDY, + interpretation2 = catalogManager.getInterpretationManager().get(organizationId, STUDY, ca.getSecondaryInterpretations().get(0).getId(), QueryOptions.empty(), sessionIdUser).first(); assertEquals("bloblo", interpretation2.getDescription()); assertTrue(interpretation2.isLocked()); // Lock case - catalogManager.getClinicalAnalysisManager().update(STUDY, ca.getId(), new ClinicalAnalysisUpdateParams().setLocked(true), + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, ca.getId(), new ClinicalAnalysisUpdateParams().setLocked(true), QueryOptions.empty(), sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertTrue(ca.isLocked()); assertTrue(ca.getInterpretation().isLocked()); for (Interpretation secondaryInterpretation : ca.getSecondaryInterpretations()) { @@ -258,9 +258,9 @@ public void interpretationLockedTest() throws CatalogException { } // Unlock case - catalogManager.getClinicalAnalysisManager().update(STUDY, ca.getId(), new ClinicalAnalysisUpdateParams().setLocked(false), + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, ca.getId(), new ClinicalAnalysisUpdateParams().setLocked(false), QueryOptions.empty(), sessionIdUser); - ca = catalogManager.getClinicalAnalysisManager().get(STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); + ca = catalogManager.getClinicalAnalysisManager().get(organizationId, STUDY, ca.getId(), QueryOptions.empty(), sessionIdUser).first(); assertFalse(ca.isLocked()); assertTrue(ca.getInterpretation().isLocked()); for (Interpretation secondaryInterpretation : ca.getSecondaryInterpretations()) { @@ -276,17 +276,17 @@ public void createInterpretationWithSubsetOfPanels() throws CatalogException { for (int i = 0; i < 3; i++) { Panel panel = new Panel().setId("panel" + i); panelReferenceParamList.add(new PanelReferenceParam(panel.getId())); - catalogManager.getPanelManager().create(STUDY, panel, QueryOptions.empty(), sessionIdUser); + catalogManager.getPanelManager().create(organizationId, STUDY, panel, QueryOptions.empty(), sessionIdUser); } // Add panels to the case and set panelLock to true ClinicalAnalysisUpdateParams updateParams = new ClinicalAnalysisUpdateParams() .setPanels(panelReferenceParamList); - catalogManager.getClinicalAnalysisManager().update(STUDY, ca.getId(), updateParams, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, ca.getId(), updateParams, QueryOptions.empty(), sessionIdUser); updateParams = new ClinicalAnalysisUpdateParams() .setPanelLock(true); - catalogManager.getClinicalAnalysisManager().update(STUDY, ca.getId(), updateParams, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().update(organizationId, STUDY, ca.getId(), updateParams, QueryOptions.empty(), sessionIdUser); // Create interpretation with just panel1 InterpretationCreateParams interpretationCreateParams = new InterpretationCreateParams() diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/PanelManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/PanelManagerTest.java index a055d368557..ef5c937c56d 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/PanelManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/PanelManagerTest.java @@ -92,7 +92,7 @@ private void setUpCatalogManager(CatalogManager catalogManager) throws IOExcepti public void createTest() throws IOException, CatalogException { Panel panel = Panel.load(getClass().getResource("/disease_panels/panel1.json").openStream()); - DataResult diseasePanelDataResult = panelManager.create(studyFqn, panel, INCLUDE_RESULT, sessionIdUser); + DataResult diseasePanelDataResult = panelManager.create(organizationId, studyFqn, panel, INCLUDE_RESULT, sessionIdUser); assertEquals(1, diseasePanelDataResult.getNumResults()); assertEquals(panel.getId(), diseasePanelDataResult.first().getId()); assertEquals(panel.toString(), diseasePanelDataResult.first().toString()); @@ -124,7 +124,7 @@ public void importFromInvalidSource() throws CatalogException { @Test public void updateTest() throws CatalogException { panelManager.importFromSource(studyFqn, "gene-census", null, sessionIdUser); - Panel panel = panelManager.get(studyFqn, "gene-census", QueryOptions.empty(), sessionIdUser).first(); + Panel panel = panelManager.get(organizationId, studyFqn, "gene-census", QueryOptions.empty(), sessionIdUser).first(); assertEquals(1, panel.getVersion()); assertEquals((int) panel.getStats().get("numberOfRegions"), panel.getVariants().size()); assertEquals((int) panel.getStats().get("numberOfVariants"), panel.getVariants().size()); @@ -149,7 +149,7 @@ public void updateTest() throws CatalogException { DataResult updateResult = panelManager.update(studyFqn, "gene-census", updateParams, null, sessionIdUser); assertEquals(1, updateResult.getNumUpdated()); - Panel updatedPanel = panelManager.get(studyFqn, "gene-census", QueryOptions.empty(), sessionIdUser).first(); + Panel updatedPanel = panelManager.get(organizationId, studyFqn, "gene-census", QueryOptions.empty(), sessionIdUser).first(); assertEquals(2, updatedPanel.getVersion()); assertEquals("author", updatedPanel.getSource().getAuthor()); assertEquals(1, updatedPanel.getRegions().size()); @@ -167,7 +167,7 @@ public void updateTest() throws CatalogException { Query query = new Query() .append(PanelDBAdaptor.QueryParams.VERSION.key(), 1); - panel = panelManager.get(studyFqn, Collections.singletonList("gene-census"), query, QueryOptions.empty(), false, sessionIdUser).first(); + panel = panelManager.get(organizationId, studyFqn, Collections.singletonList("gene-census"), query, QueryOptions.empty(), false, sessionIdUser).first(); assertEquals("gene-census", panel.getId()); assertEquals(1, panel.getVersion()); } @@ -175,25 +175,25 @@ public void updateTest() throws CatalogException { @Test public void deletePanelTest() throws CatalogException { panelManager.importFromSource(studyFqn, "gene-census", null, sessionIdUser); - Panel panel = panelManager.get(studyFqn, "gene-census", QueryOptions.empty(), sessionIdUser).first(); + Panel panel = panelManager.get(organizationId, studyFqn, "gene-census", QueryOptions.empty(), sessionIdUser).first(); assertEquals(1, panel.getVersion()); - OpenCGAResult result = panelManager.delete(studyFqn, Collections.singletonList("gene-census"), QueryOptions.empty(), sessionIdUser); + OpenCGAResult result = panelManager.delete(organizationId, studyFqn, Collections.singletonList("gene-census"), QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumDeleted()); - result = panelManager.get(studyFqn, Collections.singletonList("gene-census"), QueryOptions.empty(), true, sessionIdUser); + result = panelManager.get(organizationId, studyFqn, Collections.singletonList("gene-census"), QueryOptions.empty(), true, sessionIdUser); assertEquals(0, result.getNumResults()); Query query = new Query() .append(ParamConstants.DELETED_PARAM, true); - result = panelManager.get(studyFqn, Collections.singletonList("gene-census"), query, QueryOptions.empty(), false, sessionIdUser); + result = panelManager.get(organizationId, studyFqn, Collections.singletonList("gene-census"), query, QueryOptions.empty(), false, sessionIdUser); assertEquals(1, result.getNumResults()); } @Test public void deletePanelWithVersionsTest() throws CatalogException { panelManager.importFromSource(studyFqn, "gene-census", null, sessionIdUser); - Panel panel = panelManager.get(studyFqn, "gene-census", QueryOptions.empty(), sessionIdUser).first(); + Panel panel = panelManager.get(organizationId, studyFqn, "gene-census", QueryOptions.empty(), sessionIdUser).first(); assertEquals(1, panel.getVersion()); PanelUpdateParams updateParams = new PanelUpdateParams() @@ -202,16 +202,16 @@ public void deletePanelWithVersionsTest() throws CatalogException { DataResult updateResult = panelManager.update(studyFqn, "gene-census", updateParams, null, sessionIdUser); assertEquals(1, updateResult.getNumUpdated()); - OpenCGAResult result = panelManager.delete(studyFqn, Collections.singletonList("gene-census"), QueryOptions.empty(), sessionIdUser); + OpenCGAResult result = panelManager.delete(organizationId, studyFqn, Collections.singletonList("gene-census"), QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumDeleted()); - result = panelManager.get(studyFqn, Collections.singletonList("gene-census"), QueryOptions.empty(), true, sessionIdUser); + result = panelManager.get(organizationId, studyFqn, Collections.singletonList("gene-census"), QueryOptions.empty(), true, sessionIdUser); assertEquals(0, result.getNumResults()); Query query = new Query() .append(Constants.ALL_VERSIONS, true) .append(ParamConstants.DELETED_PARAM, true); - result = panelManager.get(studyFqn, Collections.singletonList("gene-census"), query, QueryOptions.empty(), false, sessionIdUser); + result = panelManager.get(organizationId, studyFqn, Collections.singletonList("gene-census"), query, QueryOptions.empty(), false, sessionIdUser); assertEquals(2, result.getNumResults()); } @@ -249,17 +249,17 @@ public void panelIncrementVersionWithCasesAndInterpretations() throws CatalogExc .setLocked(true); Interpretation interpretation9 = DummyModelUtils.getDummyInterpretation(Collections.singletonList(panel3)); - catalogManager.getPanelManager().create(studyFqn, panel1, QueryOptions.empty(), sessionIdUser); - catalogManager.getPanelManager().create(studyFqn, panel2, QueryOptions.empty(), sessionIdUser); - catalogManager.getPanelManager().create(studyFqn, panel3, QueryOptions.empty(), sessionIdUser); - catalogManager.getPanelManager().create(studyFqn, panel4, QueryOptions.empty(), sessionIdUser); + catalogManager.getPanelManager().create(organizationId, studyFqn, panel1, QueryOptions.empty(), sessionIdUser); + catalogManager.getPanelManager().create(organizationId, studyFqn, panel2, QueryOptions.empty(), sessionIdUser); + catalogManager.getPanelManager().create(organizationId, studyFqn, panel3, QueryOptions.empty(), sessionIdUser); + catalogManager.getPanelManager().create(organizationId, studyFqn, panel4, QueryOptions.empty(), sessionIdUser); - catalogManager.getFamilyManager().create(studyFqn, family1, QueryOptions.empty(), sessionIdUser); + catalogManager.getFamilyManager().create(organizationId, studyFqn, family1, QueryOptions.empty(), sessionIdUser); - catalogManager.getClinicalAnalysisManager().create(studyFqn, case1, QueryOptions.empty(), sessionIdUser); - catalogManager.getClinicalAnalysisManager().create(studyFqn, case2, QueryOptions.empty(), sessionIdUser); - catalogManager.getClinicalAnalysisManager().create(studyFqn, case3, QueryOptions.empty(), sessionIdUser); - catalogManager.getClinicalAnalysisManager().create(studyFqn, case4, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case1, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case2, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case3, QueryOptions.empty(), sessionIdUser); + catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case4, QueryOptions.empty(), sessionIdUser); // case1 catalogManager.getInterpretationManager().create(studyFqn, case1.getId(), interpretation1, @@ -274,7 +274,7 @@ public void panelIncrementVersionWithCasesAndInterpretations() throws CatalogExc ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); catalogManager.getInterpretationManager().create(studyFqn, case2.getId(), interpretation5, ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); - catalogManager.getClinicalAnalysisManager().update(studyFqn, case2.getId(), new ClinicalAnalysisUpdateParams().setPanelLock(true), + catalogManager.getClinicalAnalysisManager().update(organizationId, studyFqn, case2.getId(), new ClinicalAnalysisUpdateParams().setPanelLock(true), QueryOptions.empty(), sessionIdUser); // case 3 @@ -282,7 +282,7 @@ public void panelIncrementVersionWithCasesAndInterpretations() throws CatalogExc ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); catalogManager.getInterpretationManager().create(studyFqn, case3.getId(), interpretation7, ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); - catalogManager.getClinicalAnalysisManager().update(studyFqn, case3.getId(), new ClinicalAnalysisUpdateParams().setLocked(true), + catalogManager.getClinicalAnalysisManager().update(organizationId, studyFqn, case3.getId(), new ClinicalAnalysisUpdateParams().setLocked(true), QueryOptions.empty(), sessionIdUser); // case 4 @@ -290,23 +290,23 @@ public void panelIncrementVersionWithCasesAndInterpretations() throws CatalogExc ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); catalogManager.getInterpretationManager().create(studyFqn, case4.getId(), interpretation9, ParamUtils.SaveInterpretationAs.SECONDARY, QueryOptions.empty(), sessionIdUser); - catalogManager.getClinicalAnalysisManager().update(studyFqn, case4.getId(), new ClinicalAnalysisUpdateParams().setLocked(true), + catalogManager.getClinicalAnalysisManager().update(organizationId, studyFqn, case4.getId(), new ClinicalAnalysisUpdateParams().setLocked(true), QueryOptions.empty(), sessionIdUser); // Update panel1 ... panelManager.update(studyFqn, panel1.getId(), new PanelUpdateParams().setName("name"), QueryOptions.empty(), sessionIdUser); - OpenCGAResult resultPanel = panelManager.get(studyFqn, panel1.getId(), QueryOptions.empty(), sessionIdUser); + OpenCGAResult resultPanel = panelManager.get(organizationId, studyFqn, panel1.getId(), QueryOptions.empty(), sessionIdUser); assertEquals(2, resultPanel.first().getVersion()); assertEquals("name", resultPanel.first().getName()); Query query = new Query() .append(PanelDBAdaptor.QueryParams.ID.key(), panel1.getId()) .append(PanelDBAdaptor.QueryParams.VERSION.key(), 1); - resultPanel = panelManager.search(studyFqn, query, QueryOptions.empty(), sessionIdUser); + resultPanel = panelManager.search(organizationId, studyFqn, query, QueryOptions.empty(), sessionIdUser); assertEquals(1, resultPanel.first().getVersion()); assertNotEquals("name", resultPanel.first().getName()); - OpenCGAResult result = catalogManager.getClinicalAnalysisManager().get(studyFqn, + OpenCGAResult result = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, Arrays.asList(case1.getId(), case2.getId(), case3.getId(), case4.getId()), QueryOptions.empty(), sessionIdUser); case1 = result.getResults().get(0); case2 = result.getResults().get(1); @@ -381,34 +381,34 @@ public void geneIdAndNameQueryTest() throws CatalogException { .setId("panel2") .setGenes(Arrays.asList(createGenePanel("geneId1", "geneName1"), createGenePanel("geneId3", "geneName3"))); - panelManager.create(studyFqn, panel1, QueryOptions.empty(), sessionIdUser); - panelManager.create(studyFqn, panel2, QueryOptions.empty(), sessionIdUser); + panelManager.create(organizationId, studyFqn, panel1, QueryOptions.empty(), sessionIdUser); + panelManager.create(organizationId, studyFqn, panel2, QueryOptions.empty(), sessionIdUser); - OpenCGAResult result = panelManager.search(studyFqn, new Query(PanelDBAdaptor.QueryParams.GENES.key(), "geneName2"), QueryOptions.empty(), sessionIdUser); + OpenCGAResult result = panelManager.search(organizationId, studyFqn, new Query(PanelDBAdaptor.QueryParams.GENES.key(), "geneName2"), QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals("panel1", result.first().getId()); - result = panelManager.search(studyFqn, new Query(PanelDBAdaptor.QueryParams.GENES.key(), "geneId2"), QueryOptions.empty(), sessionIdUser); + result = panelManager.search(organizationId, studyFqn, new Query(PanelDBAdaptor.QueryParams.GENES.key(), "geneId2"), QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals("panel1", result.first().getId()); - result = panelManager.search(studyFqn, new Query(PanelDBAdaptor.QueryParams.GENES.key(), "geneName1"), QueryOptions.empty(), sessionIdUser); + result = panelManager.search(organizationId, studyFqn, new Query(PanelDBAdaptor.QueryParams.GENES.key(), "geneName1"), QueryOptions.empty(), sessionIdUser); assertEquals(2, result.getNumResults()); assertTrue(result.getResults().stream().map(Panel::getId).collect(Collectors.toList()).containsAll(Arrays.asList("panel1", "panel2"))); - result = panelManager.search(studyFqn, new Query(PanelDBAdaptor.QueryParams.GENES.key(), "geneId1"), QueryOptions.empty(), sessionIdUser); + result = panelManager.search(organizationId, studyFqn, new Query(PanelDBAdaptor.QueryParams.GENES.key(), "geneId1"), QueryOptions.empty(), sessionIdUser); assertEquals(2, result.getNumResults()); assertTrue(result.getResults().stream().map(Panel::getId).collect(Collectors.toList()).containsAll(Arrays.asList("panel1", "panel2"))); - result = panelManager.search(studyFqn, new Query(PanelDBAdaptor.QueryParams.GENES.key(), "geneId3"), QueryOptions.empty(), sessionIdUser); + result = panelManager.search(organizationId, studyFqn, new Query(PanelDBAdaptor.QueryParams.GENES.key(), "geneId3"), QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals("panel2", result.first().getId()); - result = panelManager.search(studyFqn, new Query(PanelDBAdaptor.QueryParams.GENES.key(), "geneName3"), QueryOptions.empty(), sessionIdUser); + result = panelManager.search(organizationId, studyFqn, new Query(PanelDBAdaptor.QueryParams.GENES.key(), "geneName3"), QueryOptions.empty(), sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals("panel2", result.first().getId()); - result = panelManager.search(studyFqn, new Query(PanelDBAdaptor.QueryParams.GENES.key(), "geneId4"), QueryOptions.empty(), sessionIdUser); + result = panelManager.search(organizationId, studyFqn, new Query(PanelDBAdaptor.QueryParams.GENES.key(), "geneId4"), QueryOptions.empty(), sessionIdUser); assertEquals(0, result.getNumResults()); } diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/ProjectManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/ProjectManagerTest.java index 2490163b781..548f8d8ac7f 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/ProjectManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/ProjectManagerTest.java @@ -105,14 +105,14 @@ public void setUpCatalogManager(CatalogManager catalogManager) throws IOExceptio @Test public void searchProjectByStudy() throws CatalogException { - OpenCGAResult result = catalogManager.getProjectManager().search(new Query(ProjectDBAdaptor.QueryParams.STUDY.key(), "phase1"), null, sessionIdUser); + OpenCGAResult result = catalogManager.getProjectManager().search(organizationId, new Query(ProjectDBAdaptor.QueryParams.STUDY.key(), "phase1"), null, sessionIdUser); assertEquals(1, result.getNumResults()); assertEquals(project1, result.first().getId()); } @Test public void getOwnProjectNoStudies() throws CatalogException { - DataResult projectDataResult = catalogManager.getProjectManager().get(project3, null, sessionIdUser3); + DataResult projectDataResult = catalogManager.getProjectManager().get(organizationId, project3, null, sessionIdUser3); assertEquals(1, projectDataResult.getNumResults()); } @@ -120,7 +120,7 @@ public void getOwnProjectNoStudies() throws CatalogException { public void getOtherUsersProject() throws CatalogException { thrown.expect(CatalogException.class); thrown.expectMessage("cannot view"); - catalogManager.getProjectManager().get(project1, null, sessionIdUser3); + catalogManager.getProjectManager().get(organizationId, project1, null, sessionIdUser3); } @Test @@ -128,7 +128,7 @@ public void searchSampleNoPermissions() throws CatalogException { // User3 looks for any sample without providing any project or study and he has not been granted permissions anywhere thrown.expect(CatalogAuthorizationException.class); thrown.expectMessage("cannot view any study"); - catalogManager.getSampleManager().search("", new Query(), QueryOptions.empty(), sessionIdUser3); + catalogManager.getSampleManager().search(organizationId, "", new Query(), QueryOptions.empty(), sessionIdUser3); } @Test @@ -136,7 +136,7 @@ public void searchProjects() throws CatalogException { catalogManager.getUserManager().create("userid", "User Name", "mail@ebi.ac.uk", TestParamConstants.PASSWORD, "", null, Account.AccountType.FULL, opencgaToken); String token = catalogManager.getUserManager().login("userid", TestParamConstants.PASSWORD).getToken(); - OpenCGAResult projectOpenCGAResult = catalogManager.getProjectManager().search(new Query(), QueryOptions.empty(), token); + OpenCGAResult projectOpenCGAResult = catalogManager.getProjectManager().search(organizationId, new Query(), QueryOptions.empty(), token); assertTrue(projectOpenCGAResult.getResults().isEmpty()); assertEquals(0, projectOpenCGAResult.getEvents().size()); @@ -144,17 +144,17 @@ public void searchProjects() throws CatalogException { catalogManager.getUserManager().create(otherUser, "User Name", "mail@ebi.ac.uk", TestParamConstants.PASSWORD, "", null, Account.AccountType.FULL, opencgaToken); String otherUsertoken = catalogManager.getUserManager().login(otherUser, TestParamConstants.PASSWORD).getToken(); OpenCGAResult result = catalogManager.getProjectManager() - .search(new Query(), QueryOptions.empty(), otherUsertoken); + .search(organizationId, new Query(), QueryOptions.empty(), otherUsertoken); assertTrue(result.getResults().isEmpty()); assertEquals(0, result.getEvents().size()); // Create a new study in project2 with some dummy permissions for user String s2 = catalogManager.getStudyManager().create(project2, "s2", null, "Study 2", "", null, null, null, null, INCLUDE_RESULT, sessionIdUser2).first().getId(); - catalogManager.getStudyManager().updateGroup(s2, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, s2, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList(otherUser)), sessionIdUser2); result = catalogManager.getProjectManager() - .search(new Query(), QueryOptions.empty(), otherUsertoken); + .search(organizationId, new Query(), QueryOptions.empty(), otherUsertoken); assertEquals(1, result.getNumResults()); assertEquals(project2, result.first().getId()); assertEquals("user2@pmp", result.first().getFqn()); @@ -164,35 +164,35 @@ public void searchProjects() throws CatalogException { @Test public void getSharedProjects() throws CatalogException { try { - OpenCGAResult user = catalogManager.getProjectManager().getSharedProjects("user", null, sessionIdUser); + OpenCGAResult user = catalogManager.getProjectManager().getSharedProjects(organizationId, "user", null, sessionIdUser); } catch (CatalogAuthorizationException e) { // Correct } // Create a new study in project2 with some dummy permissions for user String s2 = catalogManager.getStudyManager().create(project2, "s2", null, "Study 2", "", null, null, null, null, INCLUDE_RESULT, sessionIdUser2).first().getId(); - catalogManager.getStudyManager().updateGroup(s2, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, s2, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("user")), sessionIdUser2); - DataResult queryResult = catalogManager.getProjectManager().getSharedProjects("user", null, sessionIdUser); + DataResult queryResult = catalogManager.getProjectManager().getSharedProjects(organizationId, "user", null, sessionIdUser); assertEquals(1, queryResult.getNumResults()); assertEquals(1, queryResult.first().getStudies().size()); assertEquals("s2", queryResult.first().getStudies().get(0).getId()); // Add permissions to a group were user belongs - catalogManager.getStudyManager().createGroup(studyId3, "@member", Collections.singletonList("user"), sessionIdUser2); + catalogManager.getStudyManager().createGroup(organizationId, studyId3, "@member", Collections.singletonList("user"), sessionIdUser2); - queryResult = catalogManager.getProjectManager().getSharedProjects("user", null, sessionIdUser); + queryResult = catalogManager.getProjectManager().getSharedProjects(organizationId, "user", null, sessionIdUser); assertEquals(1, queryResult.getNumResults()); assertEquals(2, queryResult.first().getStudies().size()); assertEquals("user2@pmp", queryResult.first().getFqn()); // Add permissions to user in a study of user3 String s3 = catalogManager.getStudyManager().create(project3, "s3", null, "StudyProject3", "", null, null, null, null, INCLUDE_RESULT, sessionIdUser3).first().getId(); - catalogManager.getStudyManager().updateGroup(String.valueOf(s3), "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, String.valueOf(s3), "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("user")), sessionIdUser3); - queryResult = catalogManager.getProjectManager().getSharedProjects("user", null, sessionIdUser); + queryResult = catalogManager.getProjectManager().getSharedProjects(organizationId, "user", null, sessionIdUser); assertEquals(2, queryResult.getNumResults()); for (Project project : queryResult.getResults()) { if (project.getId().equals(project2)) { @@ -215,9 +215,9 @@ public void updateOrganismInProject() throws CatalogException { ObjectMap objectMap = new ObjectMap(); objectMap.put(ProjectDBAdaptor.QueryParams.ORGANISM_COMMON_NAME.key(), "common"); - OpenCGAResult update = catalogManager.getProjectManager().update(pr.getId(), objectMap, INCLUDE_RESULT, sessionIdUser); + OpenCGAResult update = catalogManager.getProjectManager().update(organizationId, pr.getId(), objectMap, INCLUDE_RESULT, sessionIdUser); assertEquals(1, update.getNumResults()); - OpenCGAResult queryResult = catalogManager.getProjectManager().get(pr.getId(), null, sessionIdUser); + OpenCGAResult queryResult = catalogManager.getProjectManager().get(organizationId, pr.getId(), null, sessionIdUser); assertEquals("Homo sapiens", queryResult.first().getOrganism().getScientificName()); assertEquals("common", queryResult.first().getOrganism().getCommonName()); @@ -228,13 +228,13 @@ public void updateOrganismInProject() throws CatalogException { thrown.expect(CatalogException.class); thrown.expectMessage("Cannot update organism"); - catalogManager.getProjectManager().update(pr.getId(), objectMap, null, sessionIdUser); + catalogManager.getProjectManager().update(organizationId, pr.getId(), objectMap, null, sessionIdUser); } @Test public void createProjectCheckCellbase() throws CatalogException, JsonProcessingException { Project pr = catalogManager.getProjectManager() - .create(new ProjectCreateParams() + .create(organizationId, new ProjectCreateParams() .setId("Project_1") .setName("Project about some genomes") .setOrganism(new ProjectOrganism("Homo sapiens", "grch38")) @@ -245,7 +245,7 @@ public void createProjectCheckCellbase() throws CatalogException, JsonProcessing assertNull(pr.getCellbase().getDataRelease()); pr = catalogManager.getProjectManager() - .create(new ProjectCreateParams() + .create(organizationId, new ProjectCreateParams() .setId("Project_2") .setName("Project about some genomes") .setOrganism(new ProjectOrganism("Homo sapiens", "grch38")) @@ -256,7 +256,7 @@ public void createProjectCheckCellbase() throws CatalogException, JsonProcessing assertNull(pr.getCellbase().getDataRelease()); pr = catalogManager.getProjectManager() - .create(new ProjectCreateParams() + .create(organizationId, new ProjectCreateParams() .setId("Project_3") .setName("Project about some genomes") .setOrganism(new ProjectOrganism("Homo sapiens", "grch38")) @@ -271,7 +271,7 @@ public void createProjectCheckCellbase() throws CatalogException, JsonProcessing public void createProjectWrongCellbase() throws CatalogException, JsonProcessingException { thrown.expectMessage("DataRelease 'NON_EXISTING_DR' not found on cellbase"); catalogManager.getProjectManager() - .create(new ProjectCreateParams() + .create(organizationId, new ProjectCreateParams() .setId("project2") .setName("Project about some genomes") .setOrganism(new ProjectOrganism("Homo sapiens", "grch38")) @@ -288,17 +288,17 @@ public void updateCellbaseInProject() throws CatalogException, JsonProcessingExc assertEquals(ParamConstants.CELLBASE_VERSION, pr.getCellbase().getVersion()); CellBaseConfiguration cb = new CellBaseConfiguration("https://ws.opencb.org/cellbase", "v3"); - OpenCGAResult update = catalogManager.getProjectManager().setCellbaseConfiguration(pr.getId(), + OpenCGAResult update = catalogManager.getProjectManager().setCellbaseConfiguration(organizationId, pr.getId(), new CellBaseConfiguration("https://ws.opencb.org/cellbase", "v3"), false, sessionIdUser); assertEquals(1, update.getNumUpdated()); - Project project = catalogManager.getProjectManager().get(pr.getId(), QueryOptions.empty(), sessionIdUser).first(); + Project project = catalogManager.getProjectManager().get(organizationId, pr.getId(), QueryOptions.empty(), sessionIdUser).first(); assertNotNull(pr.getCellbase()); assertEquals(cb.getUrl(), project.getCellbase().getUrl()); assertEquals(cb.getVersion(), project.getCellbase().getVersion()); thrown.expectMessage("Unable to access cellbase url"); - catalogManager.getProjectManager().setCellbaseConfiguration(pr.getId(), + catalogManager.getProjectManager().setCellbaseConfiguration(organizationId, pr.getId(), new CellBaseConfiguration("https://ws.opencb.org/cellbase", "v3"), true, sessionIdUser); } } diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/SampleManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/SampleManagerTest.java index 51c78472790..a90642d7e68 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/SampleManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/SampleManagerTest.java @@ -85,22 +85,22 @@ public class SampleManagerTest extends AbstractManagerTest { @Test public void testSampleVersioning() throws CatalogException { Query query = new Query(ProjectDBAdaptor.QueryParams.USER_ID.key(), "user"); - String projectId = catalogManager.getProjectManager().search(query, null, token).first().getId(); + String projectId = catalogManager.getProjectManager().search(organizationId, query, null, token).first().getId(); List descriptions = Arrays.asList(RandomStringUtils.random(5), RandomStringUtils.random(5), RandomStringUtils.random(5)); - catalogManager.getSampleManager().create(studyFqn, + catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("testSample").setDescription("description"), null, token); catalogManager.getSampleManager().update(studyFqn, "testSample", new SampleUpdateParams().setDescription(descriptions.get(0)), new QueryOptions(), token); catalogManager.getSampleManager().update(studyFqn, "testSample", new SampleUpdateParams().setDescription(descriptions.get(1)), new QueryOptions(), token); - catalogManager.getProjectManager().incrementRelease(projectId, token); + catalogManager.getProjectManager().incrementRelease(organizationId, projectId, token); // We create something to have a gap in the release - catalogManager.getSampleManager().create(studyFqn, new Sample().setId("dummy"), null, token); + catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("dummy"), null, token); - catalogManager.getProjectManager().incrementRelease(projectId, token); + catalogManager.getProjectManager().incrementRelease(organizationId, projectId, token); catalogManager.getSampleManager().update(studyFqn, "testSample", new SampleUpdateParams().setDescription(descriptions.get(2)), new QueryOptions(), token); @@ -111,7 +111,7 @@ public void testSampleVersioning() throws CatalogException { query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), "testSample") .append(Constants.ALL_VERSIONS, true); - DataResult sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, null, token); + DataResult sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token); assertEquals(5, sampleDataResult.getNumResults()); assertEquals("description", sampleDataResult.getResults().get(0).getDescription()); assertEquals(descriptions.get(0), sampleDataResult.getResults().get(1).getDescription()); @@ -121,7 +121,7 @@ public void testSampleVersioning() throws CatalogException { query = new Query() .append(SampleDBAdaptor.QueryParams.VERSION.key(), "all"); - sampleDataResult = catalogManager.getSampleManager().get(studyFqn, Collections.singletonList("testSample"), + sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, Collections.singletonList("testSample"), query, null, false, token); assertEquals(5, sampleDataResult.getNumResults()); assertEquals("description", sampleDataResult.getResults().get(0).getDescription()); @@ -134,7 +134,7 @@ public void testSampleVersioning() throws CatalogException { query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), "testSample") .append(SampleDBAdaptor.QueryParams.SNAPSHOT.key(), 1); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, null, token); + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals(3, sampleDataResult.first().getVersion()); @@ -142,14 +142,14 @@ public void testSampleVersioning() throws CatalogException { query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), "testSample") .append(SampleDBAdaptor.QueryParams.SNAPSHOT.key(), 2); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, null, token); + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals(3, sampleDataResult.first().getVersion()); // We want the last version of the sample query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), "testSample"); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, null, token); + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals(5, sampleDataResult.first().getVersion()); @@ -157,7 +157,7 @@ public void testSampleVersioning() throws CatalogException { query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), "testSample") .append(SampleDBAdaptor.QueryParams.VERSION.key(), 2); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, null, token); + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals(2, sampleDataResult.first().getVersion()); @@ -165,33 +165,33 @@ public void testSampleVersioning() throws CatalogException { query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), "testSample") .append(SampleDBAdaptor.QueryParams.VERSION.key(), 1); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, null, token); + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals(1, sampleDataResult.first().getVersion()); DataResult testSample = catalogManager.getSampleManager() - .get(studyFqn, Collections.singletonList("testSample"), new Query(Constants.ALL_VERSIONS, true), null, false, token); + .get(organizationId, studyFqn, Collections.singletonList("testSample"), new Query(Constants.ALL_VERSIONS, true), null, false, token); assertEquals(5, testSample.getResults().size()); } @Test public void testCustomCreationDate() throws CatalogException { - Sample s1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("s1").setCreationDate("20140101120000"), + Sample s1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("s1").setCreationDate("20140101120000"), INCLUDE_RESULT, token).first(); assertEquals("20140101120000", s1.getCreationDate()); - OpenCGAResult search = catalogManager.getSampleManager().search(studyFqn, + OpenCGAResult search = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.CREATION_DATE.key(), "<2015"), QueryOptions.empty(), token); assertEquals(1, search.getNumResults()); assertEquals("s1", search.first().getId()); catalogManager.getSampleManager().update(studyFqn, "s1", new SampleUpdateParams().setCreationDate("20160101120000"), QueryOptions.empty(), token); - search = catalogManager.getSampleManager().search(studyFqn, + search = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.CREATION_DATE.key(), "<2015"), QueryOptions.empty(), token); assertEquals(0, search.getNumResults()); - search = catalogManager.getSampleManager().search(studyFqn, + search = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.CREATION_DATE.key(), "<201602"), QueryOptions.empty(), token); assertEquals(1, search.getNumResults()); assertEquals("s1", search.first().getId()); @@ -201,24 +201,24 @@ public void testCustomCreationDate() throws CatalogException { public void testCustomModificationDate() throws CatalogException { Date date = TimeUtils.toDate(TimeUtils.getTime()); - Sample s1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("s1").setModificationDate("20140101120000"), + Sample s1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("s1").setModificationDate("20140101120000"), INCLUDE_RESULT, token).first(); assertEquals("20140101120000", s1.getModificationDate()); Date date1 = TimeUtils.toDate(s1.getInternal().getLastModified()); assertTrue(date1.after(date) || date1.equals(date)); - OpenCGAResult search = catalogManager.getSampleManager().search(studyFqn, + OpenCGAResult search = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.MODIFICATION_DATE.key(), "<2015"), QueryOptions.empty(), token); assertEquals(1, search.getNumResults()); assertEquals("s1", search.first().getId()); catalogManager.getSampleManager().update(studyFqn, "s1", new SampleUpdateParams().setModificationDate("20160101120000"), QueryOptions.empty(), token); - search = catalogManager.getSampleManager().search(studyFqn, + search = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.MODIFICATION_DATE.key(), "<2015"), QueryOptions.empty(), token); assertEquals(0, search.getNumResults()); - search = catalogManager.getSampleManager().search(studyFqn, + search = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.MODIFICATION_DATE.key(), "<201602"), QueryOptions.empty(), token); assertEquals(1, search.getNumResults()); assertEquals("s1", search.first().getId()); @@ -231,24 +231,24 @@ public void testCustomModificationDate() throws CatalogException { @Test public void testSampleVersioningWithWeirdId() throws CatalogException { Query query = new Query(ProjectDBAdaptor.QueryParams.USER_ID.key(), "user"); - String projectId = catalogManager.getProjectManager().search(query, null, token).first().getId(); + String projectId = catalogManager.getProjectManager().search(organizationId, query, null, token).first().getId(); String sampleId = "test__Sa..mp--le"; List descriptions = Arrays.asList(RandomStringUtils.random(5), RandomStringUtils.random(5), RandomStringUtils.random(5)); - catalogManager.getSampleManager().create(studyFqn, + catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId(sampleId).setDescription("description"), null, token); catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams().setDescription(descriptions.get(0)), new QueryOptions(), token); catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams().setDescription(descriptions.get(1)), new QueryOptions(), token); - catalogManager.getProjectManager().incrementRelease(projectId, token); + catalogManager.getProjectManager().incrementRelease(organizationId, projectId, token); // We create something to have a gap in the release - catalogManager.getSampleManager().create(studyFqn, new Sample().setId("du--m---m..y"), null, token); + catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("du--m---m..y"), null, token); - catalogManager.getProjectManager().incrementRelease(projectId, token); + catalogManager.getProjectManager().incrementRelease(organizationId, projectId, token); catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams().setDescription(descriptions.get(2)), new QueryOptions(), token); @@ -259,7 +259,7 @@ public void testSampleVersioningWithWeirdId() throws CatalogException { query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), sampleId) .append(Constants.ALL_VERSIONS, true); - DataResult sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, null, token); + DataResult sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token); assertEquals(5, sampleDataResult.getNumResults()); assertEquals("description", sampleDataResult.getResults().get(0).getDescription()); assertEquals(descriptions.get(0), sampleDataResult.getResults().get(1).getDescription()); @@ -269,7 +269,7 @@ public void testSampleVersioningWithWeirdId() throws CatalogException { query = new Query() .append(SampleDBAdaptor.QueryParams.VERSION.key(), "all"); - sampleDataResult = catalogManager.getSampleManager().get(studyFqn, Collections.singletonList(sampleId), + sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, Collections.singletonList(sampleId), query, null, false, token); assertEquals(5, sampleDataResult.getNumResults()); assertEquals("description", sampleDataResult.getResults().get(0).getDescription()); @@ -282,7 +282,7 @@ public void testSampleVersioningWithWeirdId() throws CatalogException { query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), sampleId) .append(SampleDBAdaptor.QueryParams.SNAPSHOT.key(), 1); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, null, token); + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals(3, sampleDataResult.first().getVersion()); @@ -290,14 +290,14 @@ public void testSampleVersioningWithWeirdId() throws CatalogException { query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), sampleId) .append(SampleDBAdaptor.QueryParams.SNAPSHOT.key(), 2); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, null, token); + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals(3, sampleDataResult.first().getVersion()); // We want the last version of the sample query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), sampleId); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, null, token); + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals(5, sampleDataResult.first().getVersion()); @@ -305,7 +305,7 @@ public void testSampleVersioningWithWeirdId() throws CatalogException { query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), sampleId) .append(SampleDBAdaptor.QueryParams.VERSION.key(), 2); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, null, token); + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals(2, sampleDataResult.first().getVersion()); @@ -313,12 +313,12 @@ public void testSampleVersioningWithWeirdId() throws CatalogException { query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), sampleId) .append(SampleDBAdaptor.QueryParams.VERSION.key(), 1); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, null, token); + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals(1, sampleDataResult.first().getVersion()); DataResult testSample = catalogManager.getSampleManager() - .get(studyFqn, Collections.singletonList(sampleId), new Query(Constants.ALL_VERSIONS, true), null, false, token); + .get(organizationId, studyFqn, Collections.singletonList(sampleId), new Query(Constants.ALL_VERSIONS, true), null, false, token); assertEquals(5, testSample.getResults().size()); } @@ -329,7 +329,7 @@ public void searchByInternalAnnotationSetTest() throws CatalogException { variables.add(new Variable().setId("a").setType(Variable.VariableType.STRING)); variables.add(new Variable().setId("b").setType(Variable.VariableType.MAP_INTEGER).setAllowedKeys(Arrays.asList("b1", "b2"))); VariableSet variableSet = new VariableSet("myInternalVset", "", false, false, true, "", variables, null, 1, null); - catalogManager.getStudyManager().createVariableSet(studyFqn, variableSet, token); + catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, variableSet, token); Map annotations = new HashMap<>(); annotations.put("a", "hello"); @@ -344,7 +344,7 @@ public void searchByInternalAnnotationSetTest() throws CatalogException { Sample sample = new Sample() .setId("sample") .setAnnotationSets(Arrays.asList(annotationSet, annotationSet2)); - Sample sampleResult = catalogManager.getSampleManager().create(studyFqn, sample, INCLUDE_RESULT, token).first(); + Sample sampleResult = catalogManager.getSampleManager().create(organizationId, studyFqn, sample, INCLUDE_RESULT, token).first(); for (AnnotationSet aSet : sampleResult.getAnnotationSets()) { assertNotEquals(variableSet.getId(), aSet.getVariableSetId()); } @@ -363,30 +363,30 @@ public void searchByInternalAnnotationSetTest() throws CatalogException { Sample sample2 = new Sample() .setId("sample2") .setAnnotationSets(Arrays.asList(annotationSet, annotationSet2)); - sampleResult = catalogManager.getSampleManager().create(studyFqn, sample2, INCLUDE_RESULT, token).first(); + sampleResult = catalogManager.getSampleManager().create(organizationId, studyFqn, sample2, INCLUDE_RESULT, token).first(); for (AnnotationSet aSet : sampleResult.getAnnotationSets()) { assertNotEquals(variableSet.getId(), aSet.getVariableSetId()); } // Query by one of the annotations Query query = new Query(Constants.ANNOTATION, "myInternalVset:a=hello"); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); - assertEquals("sample", catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token).first() + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); + assertEquals("sample", catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token).first() .getId()); query = new Query(Constants.ANNOTATION, "myInternalVset:b.b1=" + (Integer.MAX_VALUE + 1L)); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); - assertEquals("sample", catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token).first() + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); + assertEquals("sample", catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token).first() .getId()); query = new Query(Constants.ANNOTATION, "b.b1=14"); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); - assertEquals("sample2", catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token).first() + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); + assertEquals("sample2", catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token).first() .getId()); query = new Query(Constants.ANNOTATION, "a=goodbye"); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); - assertEquals("sample2", catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token).first() + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); + assertEquals("sample2", catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token).first() .getId()); // Update sample annotation to be exactly the same as sample2 @@ -396,21 +396,21 @@ public void searchByInternalAnnotationSetTest() throws CatalogException { new SampleUpdateParams().setAnnotationSets(Arrays.asList(annotationSet, annotationSet2)), options, token); query = new Query(Constants.ANNOTATION, "myInternalVset:a=hello"); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(Constants.ANNOTATION, "myInternalVset:b.b1=4"); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(Constants.ANNOTATION, "b.b1=14"); - assertEquals(2, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(2, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); assertTrue(Arrays.asList("sample", "sample2") - .containsAll(catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token) + .containsAll(catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token) .getResults().stream().map(Sample::getId).collect(Collectors.toList()))); query = new Query(Constants.ANNOTATION, "a=goodbye"); - assertEquals(2, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(2, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); assertTrue(Arrays.asList("sample", "sample2") - .containsAll(catalogManager.getSampleManager().search(studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token) + .containsAll(catalogManager.getSampleManager().search(organizationId, studyFqn, query, SampleManager.INCLUDE_SAMPLE_IDS, token) .getResults().stream().map(Sample::getId).collect(Collectors.toList()))); } @@ -422,7 +422,7 @@ public void testMultipleUpdate() throws CatalogException { .setSomatic(true) .setQualityControl(new SampleQualityControl()), QueryOptions.empty(), token); - OpenCGAResult result = catalogManager.getSampleManager().get(studyFqn, Arrays.asList("s_1", "s_2", "s_3"), + OpenCGAResult result = catalogManager.getSampleManager().get(organizationId, studyFqn, Arrays.asList("s_1", "s_2", "s_3"), QueryOptions.empty(), token); assertEquals(3, result.getNumResults()); for (Sample sample : result.getResults()) { @@ -436,7 +436,7 @@ public void testMultipleUpdate() throws CatalogException { @Test public void updateQualityControlTest1() throws CatalogException { Sample sample = new Sample().setId("sample"); - catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample, QueryOptions.empty(), token); List sampleQcVariantStats = new ArrayList<>(); SampleVariantStats sampleVariantStats = new SampleVariantStats(); @@ -459,32 +459,32 @@ public void updateQualityControlTest1() throws CatalogException { Query query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_COUNT_PARAM, 20); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v2") .append(ParamConstants.SAMPLE_VARIANT_STATS_COUNT_PARAM, 10); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_COUNT_PARAM, 15); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_TI_TV_RATIO_PARAM, 13.2); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v2") .append(ParamConstants.SAMPLE_VARIANT_STATS_TI_TV_RATIO_PARAM, 15.2); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v2") .append(ParamConstants.SAMPLE_VARIANT_STATS_TI_TV_RATIO_PARAM, 3.5); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); // Change values sampleQcVariantStats = new ArrayList<>(); @@ -504,32 +504,32 @@ public void updateQualityControlTest1() throws CatalogException { query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_COUNT_PARAM, 20); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v2") .append(ParamConstants.SAMPLE_VARIANT_STATS_COUNT_PARAM, 10); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_COUNT_PARAM, 15); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_TI_TV_RATIO_PARAM, 13.2); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_TI_TV_RATIO_PARAM, 15.2); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_TI_TV_RATIO_PARAM, 3.5); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); // Update any other sample field to validate it doesn't affect quality control result = catalogManager.getSampleManager().update(studyFqn, "sample", new SampleUpdateParams().setDescription("my description"), @@ -540,32 +540,32 @@ public void updateQualityControlTest1() throws CatalogException { query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_COUNT_PARAM, 20); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v2") .append(ParamConstants.SAMPLE_VARIANT_STATS_COUNT_PARAM, 10); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_COUNT_PARAM, 15); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_TI_TV_RATIO_PARAM, 13.2); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_TI_TV_RATIO_PARAM, 15.2); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_TI_TV_RATIO_PARAM, 3.5); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); // Remove SampleQcVariantStats values qualityControl = new SampleQualityControl(Arrays.asList("file1", "file2"), null, null); @@ -579,38 +579,38 @@ public void updateQualityControlTest1() throws CatalogException { query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_COUNT_PARAM, 20); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v2") .append(ParamConstants.SAMPLE_VARIANT_STATS_COUNT_PARAM, 10); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_COUNT_PARAM, 15); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_TI_TV_RATIO_PARAM, 13.2); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_TI_TV_RATIO_PARAM, 15.2); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query() .append(ParamConstants.SAMPLE_VARIANT_STATS_ID_PARAM, "v1") .append(ParamConstants.SAMPLE_VARIANT_STATS_TI_TV_RATIO_PARAM, 3.5); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); } @Test public void updateQualityControlTest2() throws CatalogException { Sample sample = new Sample().setId("sample"); - catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample, QueryOptions.empty(), token); List sampleQcVariantStats = new ArrayList<>(); SampleVariantStats sampleVariantStats = new SampleVariantStats(); @@ -631,25 +631,25 @@ public void updateQualityControlTest2() throws CatalogException { assertEquals(1, result.getNumUpdated()); Query query = new Query(Constants.ANNOTATION, "opencga_sample_variant_stats__v1@opencga_sample_variant_stats:variantCount=20"); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(Constants.ANNOTATION, "opencga_sample_variant_stats__v2@opencga_sample_variant_stats:variantCount=20"); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(Constants.ANNOTATION, "opencga_sample_variant_stats__v2@opencga_sample_variant_stats:variantCount=10"); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(Constants.ANNOTATION, "opencga_sample_variant_stats:variantCount=15"); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(Constants.ANNOTATION, "opencga_sample_variant_stats:tiTvRatio=13.2"); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(Constants.ANNOTATION, "opencga_sample_variant_stats:tiTvRatio=15.2"); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(Constants.ANNOTATION, "opencga_sample_variant_stats:tiTvRatio=3.5"); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); // Change values sampleQcVariantStats = new ArrayList<>(); @@ -667,43 +667,43 @@ public void updateQualityControlTest2() throws CatalogException { // Check same values as before but the results should be now different query = new Query(Constants.ANNOTATION, "opencga_sample_variant_stats:variantCount=20"); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(Constants.ANNOTATION, "opencga_sample_variant_stats:variantCount=10"); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(Constants.ANNOTATION, "opencga_sample_variant_stats:variantCount=15"); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(Constants.ANNOTATION, "opencga_sample_variant_stats:tiTvRatio=13.2"); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(Constants.ANNOTATION, "opencga_sample_variant_stats:tiTvRatio=15.2"); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(Constants.ANNOTATION, "opencga_sample_variant_stats:tiTvRatio=3.5"); - assertEquals(1, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(1, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); } @Test public void distinctTest() throws CatalogException { - OpenCGAResult distinct = catalogManager.getSampleManager().distinct(studyFqn, SampleDBAdaptor.QueryParams.ID.key(), null, token); + OpenCGAResult distinct = catalogManager.getSampleManager().distinct(organizationId, studyFqn, SampleDBAdaptor.QueryParams.ID.key(), null, token); assertEquals(String.class.getName(), distinct.getResultType()); assertEquals(9, distinct.getNumResults()); assertEquals(9, distinct.getResults().size()); - distinct = catalogManager.getSampleManager().distinct(studyFqn, Arrays.asList(SampleDBAdaptor.QueryParams.ID.key(), + distinct = catalogManager.getSampleManager().distinct(organizationId, studyFqn, Arrays.asList(SampleDBAdaptor.QueryParams.ID.key(), SampleDBAdaptor.QueryParams.UID.key()), null, token); assertEquals(String.class.getName(), distinct.getResultType()); assertEquals(18, distinct.getNumResults()); assertEquals(18, distinct.getResults().size()); - distinct = catalogManager.getSampleManager().distinct(studyFqn, SampleDBAdaptor.QueryParams.UID.key(), null, token); + distinct = catalogManager.getSampleManager().distinct(organizationId, studyFqn, SampleDBAdaptor.QueryParams.UID.key(), null, token); assertEquals(Long.class.getName(), distinct.getResultType()); assertEquals(9, distinct.getNumResults()); assertEquals(9, distinct.getResults().size()); - distinct = catalogManager.getSampleManager().distinct(studyFqn, SampleDBAdaptor.QueryParams.SOMATIC.key(), null, token); + distinct = catalogManager.getSampleManager().distinct(organizationId, studyFqn, SampleDBAdaptor.QueryParams.SOMATIC.key(), null, token); assertEquals(Boolean.class.getName(), distinct.getResultType()); assertEquals(1, distinct.getNumResults()); assertEquals(1, distinct.getResults().size()); @@ -711,7 +711,7 @@ public void distinctTest() throws CatalogException { @Test public void updateAndReturnResultTest() throws CatalogException { - catalogManager.getSampleManager().create(studyFqn, + catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("testSample").setDescription("description"), null, token); SampleProcessing processing = new SampleProcessing(null, "preparationMethod", "extractionMethod", "labSampleId", "quantity", @@ -737,7 +737,7 @@ public void updateAndReturnResultTest() throws CatalogException { @Test public void updateProcessingField() throws CatalogException { - catalogManager.getSampleManager().create(studyFqn, + catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("testSample").setDescription("description"), null, token); SampleProcessing processing = new SampleProcessing(new OntologyTermAnnotation().setId("product"), @@ -745,7 +745,7 @@ public void updateProcessingField() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, "testSample", new SampleUpdateParams().setProcessing(processing), new QueryOptions(), token); - DataResult testSample = catalogManager.getSampleManager().get(studyFqn, "testSample", new QueryOptions(), token); + DataResult testSample = catalogManager.getSampleManager().get(organizationId, studyFqn, "testSample", new QueryOptions(), token); assertEquals("product", testSample.first().getProcessing().getProduct().getId()); assertEquals("preparationMethod", testSample.first().getProcessing().getPreparationMethod()); assertEquals("extractionMethod", testSample.first().getProcessing().getExtractionMethod()); @@ -757,7 +757,7 @@ public void updateProcessingField() throws CatalogException { @Test public void updateCollectionField() throws CatalogException { - catalogManager.getSampleManager().create(studyFqn, + catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("testSample").setDescription("description"), null, token); SampleCollection collection = new SampleCollection(Collections.singletonList(new OntologyTermAnnotation("id", "name", "desc", @@ -767,7 +767,7 @@ public void updateCollectionField() throws CatalogException { new SampleUpdateParams().setCollection(collection).setStatus(statusParams), new QueryOptions(), token); - DataResult testSample = catalogManager.getSampleManager().get(studyFqn, "testSample", new QueryOptions(), token); + DataResult testSample = catalogManager.getSampleManager().get(organizationId, studyFqn, "testSample", new QueryOptions(), token); assertEquals(1, testSample.first().getCollection().getFrom().size()); assertEquals("id", testSample.first().getCollection().getFrom().get(0).getId()); assertEquals("name", testSample.first().getCollection().getFrom().get(0).getName()); @@ -787,7 +787,7 @@ public void updateCollectionField() throws CatalogException { public void testCreateSample() throws CatalogException { String time = TimeUtils.getTime(); - DataResult sampleDataResult = catalogManager.getSampleManager().create(studyFqn, + DataResult sampleDataResult = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample() .setId("HG007") .setStatus(new Status("stat1", "stat1", "my description", time)), @@ -815,16 +815,16 @@ public void testCreateSample() throws CatalogException { @Test public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { Sample sample = new Sample().setId("sample1"); - catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample, QueryOptions.empty(), token); sample = new Sample().setId("sample2"); - catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample, QueryOptions.empty(), token); sample = new Sample().setId("sample3"); - catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample, QueryOptions.empty(), token); sample = new Sample().setId("sample4"); - catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample, QueryOptions.empty(), token); Individual individual = new Individual() .setId("proband") @@ -850,7 +850,7 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { .setFamily(family) .setLocked(true) .setType(ClinicalAnalysis.Type.FAMILY); - catalogManager.getClinicalAnalysisManager().create(studyFqn, clinicalAnalysis, QueryOptions.empty(), token); + catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, clinicalAnalysis, QueryOptions.empty(), token); // We will create another clinical analysis with the same information. In this test, we will not lock clinical2 clinicalAnalysis = new ClinicalAnalysis() @@ -858,28 +858,28 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { .setProband(new Individual().setId("proband")) .setFamily(family) .setType(ClinicalAnalysis.Type.FAMILY); - catalogManager.getClinicalAnalysisManager().create(studyFqn, clinicalAnalysis, new QueryOptions(), token); + catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, clinicalAnalysis, new QueryOptions(), token); // Update sample1 from proband not used in Clinical Analysis catalogManager.getSampleManager().update(studyFqn, "sample1", new SampleUpdateParams().setDescription("a"), new QueryOptions(), token); - Sample sampleResult = catalogManager.getSampleManager().get(studyFqn, "sample1", QueryOptions.empty(), token).first(); + Sample sampleResult = catalogManager.getSampleManager().get(organizationId, studyFqn, "sample1", QueryOptions.empty(), token).first(); assertEquals(3, sampleResult.getVersion()); - Individual individualResult = catalogManager.getIndividualManager().get(studyFqn, "proband", QueryOptions.empty(), token).first(); + Individual individualResult = catalogManager.getIndividualManager().get(organizationId, studyFqn, "proband", QueryOptions.empty(), token).first(); assertEquals(3, individualResult.getVersion()); assertEquals(2, individualResult.getSamples().size()); assertEquals(3, individualResult.getSamples().get(0).getVersion()); assertEquals(2, individualResult.getSamples().get(1).getVersion()); - Family familyResult = catalogManager.getFamilyManager().get(studyFqn, "family", QueryOptions.empty(), token).first(); + Family familyResult = catalogManager.getFamilyManager().get(organizationId, studyFqn, "family", QueryOptions.empty(), token).first(); assertEquals(2, familyResult.getVersion()); assertEquals(2, familyResult.getMembers().size()); assertEquals(3, familyResult.getMembers().get(0).getVersion()); assertEquals(2, familyResult.getMembers().get(1).getVersion()); - ClinicalAnalysis clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical", QueryOptions.empty(), + ClinicalAnalysis clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical", QueryOptions.empty(), token).first(); assertEquals(2, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample2 version @@ -887,7 +887,7 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { assertEquals(2, clinicalResult.getFamily().getMembers().get(0).getVersion()); // proband version assertEquals(2, clinicalResult.getFamily().getMembers().get(1).getVersion()); // father version - clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical2", QueryOptions.empty(), token).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical2", QueryOptions.empty(), token).first(); assertEquals(3, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample2 version assertEquals(2, clinicalResult.getFamily().getVersion()); @@ -898,22 +898,22 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, "sample3", new SampleUpdateParams().setDescription("asd"), new QueryOptions(), token); - sampleResult = catalogManager.getSampleManager().get(studyFqn, "sample3", QueryOptions.empty(), token).first(); + sampleResult = catalogManager.getSampleManager().get(organizationId, studyFqn, "sample3", QueryOptions.empty(), token).first(); assertEquals(3, sampleResult.getVersion()); - individualResult = catalogManager.getIndividualManager().get(studyFqn, "father", QueryOptions.empty(), token).first(); + individualResult = catalogManager.getIndividualManager().get(organizationId, studyFqn, "father", QueryOptions.empty(), token).first(); assertEquals(3, individualResult.getVersion()); assertEquals(2, individualResult.getSamples().size()); assertEquals(3, individualResult.getSamples().get(0).getVersion()); assertEquals(2, individualResult.getSamples().get(1).getVersion()); - familyResult = catalogManager.getFamilyManager().get(studyFqn, "family", QueryOptions.empty(), token).first(); + familyResult = catalogManager.getFamilyManager().get(organizationId, studyFqn, "family", QueryOptions.empty(), token).first(); assertEquals(3, familyResult.getVersion()); assertEquals(2, familyResult.getMembers().size()); assertEquals(3, familyResult.getMembers().get(0).getVersion()); assertEquals(3, familyResult.getMembers().get(1).getVersion()); - clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical", QueryOptions.empty(), token).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical", QueryOptions.empty(), token).first(); assertEquals(2, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample2 version assertEquals(1, clinicalResult.getFamily().getVersion()); @@ -921,7 +921,7 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { assertEquals(2, clinicalResult.getFamily().getMembers().get(1).getVersion()); // father version assertEquals(2, clinicalResult.getFamily().getMembers().get(1).getSamples().get(0).getVersion()); // father sample3 version - clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical2", QueryOptions.empty(), token).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical2", QueryOptions.empty(), token).first(); assertEquals(3, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample2 version assertEquals(3, clinicalResult.getFamily().getVersion()); @@ -930,7 +930,7 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { assertEquals(3, clinicalResult.getFamily().getMembers().get(1).getSamples().get(0).getVersion()); // father sample3 version catalogManager.getSampleManager().updateSampleInternalVariantSecondarySampleIndex( - catalogManager.getSampleManager().get(studyFqn, "sample3", null, token).first(), + catalogManager.getSampleManager().get(organizationId, studyFqn, "sample3", null, token).first(), new SampleInternalVariantSecondarySampleIndex( new IndexStatus(IndexStatus.READY, "This should be doable!"), new IndexStatus(IndexStatus.READY, "This should be doable!"), @@ -941,22 +941,22 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, "sample2", new SampleUpdateParams().setDescription("asda"), new QueryOptions(), token); - sampleResult = catalogManager.getSampleManager().get(studyFqn, "sample2", QueryOptions.empty(), token).first(); + sampleResult = catalogManager.getSampleManager().get(organizationId, studyFqn, "sample2", QueryOptions.empty(), token).first(); assertEquals(3, sampleResult.getVersion()); - individualResult = catalogManager.getIndividualManager().get(studyFqn, "proband", QueryOptions.empty(), token).first(); + individualResult = catalogManager.getIndividualManager().get(organizationId, studyFqn, "proband", QueryOptions.empty(), token).first(); assertEquals(4, individualResult.getVersion()); assertEquals(2, individualResult.getSamples().size()); assertEquals(3, individualResult.getSamples().get(0).getVersion()); assertEquals(3, individualResult.getSamples().get(1).getVersion()); - familyResult = catalogManager.getFamilyManager().get(studyFqn, "family", QueryOptions.empty(), token).first(); + familyResult = catalogManager.getFamilyManager().get(organizationId, studyFqn, "family", QueryOptions.empty(), token).first(); assertEquals(5, familyResult.getVersion()); assertEquals(2, familyResult.getMembers().size()); assertEquals(4, familyResult.getMembers().get(0).getVersion()); assertEquals(4, familyResult.getMembers().get(1).getVersion()); - clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical", QueryOptions.empty(), token).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical", QueryOptions.empty(), token).first(); assertEquals(2, clinicalResult.getProband().getVersion()); assertEquals(2, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample2 version assertEquals(1, clinicalResult.getFamily().getVersion()); @@ -964,7 +964,7 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { assertEquals(2, clinicalResult.getFamily().getMembers().get(1).getVersion()); // father version assertEquals(2, clinicalResult.getFamily().getMembers().get(1).getSamples().get(0).getVersion()); // father sample3 version - clinicalResult = catalogManager.getClinicalAnalysisManager().get(studyFqn, "clinical2", QueryOptions.empty(), token).first(); + clinicalResult = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, "clinical2", QueryOptions.empty(), token).first(); assertEquals(4, clinicalResult.getProband().getVersion()); assertEquals(3, clinicalResult.getProband().getSamples().get(0).getVersion()); // sample2 version assertEquals(5, clinicalResult.getFamily().getVersion()); @@ -977,7 +977,7 @@ public void testUpdateWithLockedClinicalAnalysis() throws CatalogException { @Test public void testCreateSampleWithDotInName() throws CatalogException { String name = "HG007.sample"; - DataResult sampleDataResult = catalogManager.getSampleManager().create(studyFqn, new Sample().setId(name), INCLUDE_RESULT, + DataResult sampleDataResult = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId(name), INCLUDE_RESULT, token); assertEquals(name, sampleDataResult.first().getId()); } @@ -993,7 +993,7 @@ public void testAnnotate() throws CatalogException { "", null, Collections.emptyMap())); variables.add(new Variable("MAP", "", Variable.VariableType.OBJECT, new HashMap<>(), false, false, Collections.emptyList(), null, 0, "", "", null, Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); HashMap annotations = new HashMap<>(); @@ -1006,7 +1006,7 @@ public void testAnnotate() throws CatalogException { .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation1", vs1.getId(), annotations))), QueryOptions.empty(), token); - DataResult sampleDataResult = catalogManager.getSampleManager().get(studyFqn, s_1, + DataResult sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, s_1, new QueryOptions(QueryOptions.INCLUDE, Constants.ANNOTATION_SET_NAME + ".annotation1"), token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals(1, sampleDataResult.first().getAnnotationSets().size()); @@ -1051,7 +1051,7 @@ public void testDynamicAnnotationsCreation() throws CatalogException, IOExceptio "", Collections.emptySet(), Collections.emptyMap()))), Collections.emptyMap()))), Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); InputStream inputStream = this.getClass().getClassLoader().getResource("annotation_sets/complete_annotation.json").openStream(); @@ -1062,7 +1062,7 @@ public void testDynamicAnnotationsCreation() throws CatalogException, IOExceptio .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation1", vs1.getId(), annotations))), QueryOptions.empty(), token); - DataResult sampleDataResult = catalogManager.getSampleManager().get(studyFqn, s_1, + DataResult sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, s_1, new QueryOptions(QueryOptions.INCLUDE, Constants.ANNOTATION_SET_NAME + ".annotation1"), token); assertEquals(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(annotations), @@ -1087,7 +1087,7 @@ public void testWrongAnnotation() throws CatalogException { Collections.emptySet(), Collections.emptyMap())); variables.add(new Variable("b", "b", "", Variable.VariableType.STRING, null, true, false, null, null, 0, "", "", Collections.emptySet(), Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); ObjectMap annotation = new ObjectMap() @@ -1157,7 +1157,7 @@ public void testVariableAllowedKeys() throws CatalogException, IOException { "", Collections.emptySet(), Collections.emptyMap()))), Collections.emptyMap()))), Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); InputStream inputStream = this.getClass().getClassLoader().getResource("annotation_sets/complete_annotation.json").openStream(); @@ -1197,7 +1197,7 @@ public void testVariableAllowedKeys() throws CatalogException, IOException { "", Collections.emptySet(), Collections.emptyMap()))), Collections.emptyMap()))), Collections.emptyMap())); - VariableSet vs2 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs2", "vs2", false, false, "", null, variables, + VariableSet vs2 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs2", "vs2", false, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); thrown.expect(CatalogException.class); @@ -1235,7 +1235,7 @@ public void testDynamicAnnotationsSearch() throws CatalogException, IOException Collections.emptyMap())); variables.add(new Variable("a4", "a4", "", Variable.VariableType.MAP_INTEGER, null, true, false, null, null, 0, "", "", Collections.emptySet(), Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); InputStream inputStream = this.getClass().getClassLoader().getResource("annotation_sets/complete_annotation.json").openStream(); @@ -1258,39 +1258,39 @@ public void testDynamicAnnotationsSearch() throws CatalogException, IOException Query query = new Query(Constants.ANNOTATION, "a3.b.c.z=z2;a2.b.c.z=z3"); QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, "annotationSet.annotation1"); - assertEquals(0, catalogManager.getSampleManager().count(studyFqn, query, token).getNumMatches()); + assertEquals(0, catalogManager.getSampleManager().count(organizationId, studyFqn, query, token).getNumMatches()); query = new Query(Constants.ANNOTATION, "a3.b.c.z=z2;a2.b.c.z=z"); - OpenCGAResult result = catalogManager.getSampleManager().search(studyFqn, query, options, token); + OpenCGAResult result = catalogManager.getSampleManager().search(organizationId, studyFqn, query, options, token); assertEquals(1, result.getNumResults()); assertEquals(s_1, result.first().getId()); assertEquals(7, ((Map) result.first().getAnnotationSets().get(0).getAnnotations().get("a4")).size()); options = new QueryOptions(ParamConstants.FLATTEN_ANNOTATIONS, true); - result = catalogManager.getSampleManager().search(studyFqn, query, options, token); + result = catalogManager.getSampleManager().search(organizationId, studyFqn, query, options, token); assertEquals(1, result.getNumResults()); assertEquals(s_1, result.first().getId()); query = new Query(Constants.ANNOTATION, "a4..=3"); - result = catalogManager.getSampleManager().search(studyFqn, query, options, token); + result = catalogManager.getSampleManager().search(organizationId, studyFqn, query, options, token); assertEquals(1, result.getNumResults()); query = new Query(Constants.ANNOTATION, "a4..=2"); - result = catalogManager.getSampleManager().search(studyFqn, query, options, token); + result = catalogManager.getSampleManager().search(organizationId, studyFqn, query, options, token); assertEquals(0, result.getNumResults()); } @Test public void searchSamples() throws CatalogException { - catalogManager.getStudyManager().createGroup(studyFqn, "myGroup", Arrays.asList("user2", "user3"), token); - catalogManager.getStudyManager().createGroup(studyFqn, "myGroup2", Arrays.asList("user2", "user3"), token); - catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), "@myGroup", + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, "myGroup", Arrays.asList("user2", "user3"), token); + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, "myGroup2", Arrays.asList("user2", "user3"), token); + catalogManager.getStudyManager().updateAcl(organizationId, Arrays.asList(studyFqn), "@myGroup", new StudyAclParams("", null), SET, token); catalogManager.getSampleManager().updateAcl(studyFqn, Arrays.asList("s_1"), "@myGroup", new SampleAclParams(null, null, null, null, "VIEW"), SET, token); - DataResult search = catalogManager.getSampleManager().search(studyFqn, new Query(), new QueryOptions(), + DataResult search = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(), new QueryOptions(), sessionIdUser2); assertEquals(1, search.getNumResults()); } @@ -1304,7 +1304,7 @@ public void testDeleteAnnotationset() throws CatalogException, JsonProcessingExc null, Collections.emptyMap())); variables.add(new Variable("HEIGHT", "", "", Variable.VariableType.DOUBLE, "", false, false, Collections.emptyList(), null, 0, "", "", null, Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); ObjectMap annotations = new ObjectMap() @@ -1318,7 +1318,7 @@ public void testDeleteAnnotationset() throws CatalogException, JsonProcessingExc .setAnnotationSets(Arrays.asList(annotationSet, annotationSet1)), QueryOptions.empty(), token); assertEquals(1, update.getNumUpdated()); - Sample sample = catalogManager.getSampleManager().get(studyFqn, s_1, QueryOptions.empty(), token).first(); + Sample sample = catalogManager.getSampleManager().get(organizationId, studyFqn, s_1, QueryOptions.empty(), token).first(); assertEquals(3, sample.getAnnotationSets().size()); catalogManager.getSampleManager().removeAnnotationSet(studyFqn, s_1, "annotation1", QueryOptions.empty(), token); @@ -1326,7 +1326,7 @@ public void testDeleteAnnotationset() throws CatalogException, JsonProcessingExc .removeAnnotationSet(studyFqn, s_1, "annotation2", QueryOptions.empty(), token); assertEquals(1, update.getNumUpdated()); - sample = catalogManager.getSampleManager().get(studyFqn, s_1, QueryOptions.empty(), token).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, s_1, QueryOptions.empty(), token).first(); assertEquals(1, sample.getAnnotationSets().size()); thrown.expect(CatalogDBException.class); @@ -1345,7 +1345,7 @@ public void testSearchAnnotation() throws CatalogException, JsonProcessingExcept "", null, Collections.emptyMap())); variables.add(new Variable("OTHER", "", "", Variable.VariableType.OBJECT, null, false, false, null, null, 1, "", "", null, Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); ObjectMap annotations = new ObjectMap() @@ -1358,45 +1358,45 @@ public void testSearchAnnotation() throws CatalogException, JsonProcessingExcept .setAnnotationSets(Collections.singletonList(annotationSet)), QueryOptions.empty(), token); Query query = new Query(Constants.ANNOTATION, "var_name=Joe;" + vs1.getId() + ":AGE=25"); - DataResult annotDataResult = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), + DataResult annotDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(1, annotDataResult.getNumResults()); query.put(Constants.ANNOTATION, "var_name=Joe;" + vs1.getId() + ":AGE=23"); - annotDataResult = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + annotDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(0, annotDataResult.getNumResults()); query.put(Constants.ANNOTATION, "var_name=Joe;" + vs1.getId() + ":AGE=25;variableSet!=" + vs1.getId()); - annotDataResult = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + annotDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(1, annotDataResult.getNumResults()); query.put(Constants.ANNOTATION, "var_name=Joe;" + vs1.getId() + ":AGE=25;variableSet!==" + vs1.getId()); - annotDataResult = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + annotDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(0, annotDataResult.getNumResults()); query.put(Constants.ANNOTATION, "var_name=Joe;" + vs1.getId() + ":AGE=25;variableSet==" + vs1.getId()); - annotDataResult = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + annotDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(1, annotDataResult.getNumResults()); query.put(Constants.ANNOTATION, "var_name=Joe;" + vs1.getId() + ":AGE=25;variableSet===" + vs1.getId()); - annotDataResult = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + annotDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(0, annotDataResult.getNumResults()); - VariableSet vs = catalogManager.getStudyManager().getVariableSet(studyFqn, "vs", null, token).first(); + VariableSet vs = catalogManager.getStudyManager().getVariableSet(organizationId, studyFqn, "vs", null, token).first(); query.put(Constants.ANNOTATION, "variableSet===" + vs.getId()); - annotDataResult = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + annotDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(7, annotDataResult.getNumResults()); query.put(Constants.ANNOTATION, "variableSet!=" + vs1.getId()); - annotDataResult = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + annotDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(9, annotDataResult.getNumResults()); query.put(Constants.ANNOTATION, "variableSet!==" + vs1.getId()); - annotDataResult = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + annotDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(8, annotDataResult.getNumResults()); query.put(Constants.ANNOTATION, "variableSet=" + vs1.getId()); - annotDataResult = catalogManager.getSampleManager().search(studyFqn, query, + annotDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, new QueryOptions(QueryOptions.INCLUDE, Constants.VARIABLE_SET + "." + vs1.getId()), token); assertEquals(1, annotDataResult.getNumResults()); assertEquals(1, annotDataResult.first().getAnnotationSets().size()); @@ -1405,11 +1405,11 @@ public void testSearchAnnotation() throws CatalogException, JsonProcessingExcept @Test public void testProjections() throws CatalogException { - VariableSet variableSet = catalogManager.getStudyManager().getVariableSet("1000G:phase1", "vs", null, token).first(); + VariableSet variableSet = catalogManager.getStudyManager().getVariableSet(organizationId, "1000G:phase1", "vs", null, token).first(); Query query = new Query(Constants.ANNOTATION, "variableSet===" + variableSet.getId()); QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, "annotationSets"); - DataResult annotDataResult = catalogManager.getSampleManager().search(studyFqn, query, options, + DataResult annotDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, options, token); assertEquals(8, annotDataResult.getNumResults()); @@ -1421,13 +1421,13 @@ public void testProjections() throws CatalogException { @Test public void testAnnotateMulti() throws CatalogException { - String sampleId = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, + String sampleId = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first().getId(); List variables = new ArrayList<>(); variables.add(new Variable("NAME", "NAME", "", Variable.VariableType.STRING, "", true, false, Collections.emptyList(), null, 0, "", "", null, Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); @@ -1437,7 +1437,7 @@ public void testAnnotateMulti() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation1", vs1.getId(), annotations))), QueryOptions.empty(), token); - DataResult sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId, + DataResult sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(1, sampleDataResult.first().getAnnotationSets().size()); @@ -1446,7 +1446,7 @@ public void testAnnotateMulti() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation2", vs1.getId(), annotations))), QueryOptions.empty(), token); - sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId, + sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(2, sampleDataResult.first().getAnnotationSets().size()); @@ -1456,13 +1456,13 @@ public void testAnnotateMulti() throws CatalogException { @Test public void testAnnotateUnique() throws CatalogException { - String sampleId = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, + String sampleId = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first().getId(); List variables = new ArrayList<>(); variables.add(new Variable("NAME", "NAME", "", Variable.VariableType.STRING, "", true, false, Collections.emptyList(), null, 0, "", "", null, Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", true, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", true, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); @@ -1472,7 +1472,7 @@ public void testAnnotateUnique() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation1", vs1.getId(), annotations))), QueryOptions.empty(), token); - DataResult sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId, + DataResult sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(1, sampleDataResult.first().getAnnotationSets().size()); @@ -1486,13 +1486,13 @@ public void testAnnotateUnique() throws CatalogException { @Test public void testAnnotateIndividualUnique() throws CatalogException { - String individualId = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("INDIVIDUAL_1"), + String individualId = catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("INDIVIDUAL_1"), INCLUDE_RESULT, token).first().getId(); List variables = new ArrayList<>(); variables.add(new Variable("NAME", "NAME", "", Variable.VariableType.STRING, "", true, false, Collections.emptyList(), null, 0, "", "", null, Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", true, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", true, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.INDIVIDUAL), token).first(); @@ -1501,7 +1501,7 @@ public void testAnnotateIndividualUnique() throws CatalogException { catalogManager.getIndividualManager().update(studyFqn, individualId, new IndividualUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation1", vs1.getId(), annotations))), QueryOptions.empty(), token); - DataResult individualDataResult = catalogManager.getIndividualManager().get(studyFqn, individualId, + DataResult individualDataResult = catalogManager.getIndividualManager().get(organizationId, studyFqn, individualId, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(1, individualDataResult.first().getAnnotationSets().size()); @@ -1515,13 +1515,13 @@ public void testAnnotateIndividualUnique() throws CatalogException { @Test public void testAnnotateIncorrectType() throws CatalogException { - String sampleId = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, + String sampleId = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first().getId(); List variables = new ArrayList<>(); variables.add(new Variable("NUM", "NUM", "", Variable.VariableType.DOUBLE, "", true, false, null, null, 0, "", "", null, Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); @@ -1530,7 +1530,7 @@ public void testAnnotateIncorrectType() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation1", vs1.getId(), annotations))), QueryOptions.empty(), token); - DataResult sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId, + DataResult sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(1, sampleDataResult.first().getAnnotationSets().size()); @@ -1538,7 +1538,7 @@ public void testAnnotateIncorrectType() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation2", vs1.getId(), annotations))), QueryOptions.empty(), token); - sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId, + sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(2, sampleDataResult.first().getAnnotationSets().size()); @@ -1551,13 +1551,13 @@ public void testAnnotateIncorrectType() throws CatalogException { @Test public void testAnnotateRange() throws CatalogException { - String sampleId = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, + String sampleId = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first().getId(); List variables = new ArrayList<>(); variables.add(new Variable("RANGE_NUM", "RANGE_NUM", "", Variable.VariableType.DOUBLE, "", true, false, Arrays.asList("1:14", "16:22", "50:"), null, 0, "", "", null, Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); HashMap annotations = new HashMap<>(); @@ -1565,7 +1565,7 @@ public void testAnnotateRange() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation1", vs1.getId(), annotations))), QueryOptions.empty(), token); - DataResult sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId, + DataResult sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(1, sampleDataResult.first().getAnnotationSets().size()); @@ -1573,7 +1573,7 @@ public void testAnnotateRange() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation2", vs1.getId(), annotations))), QueryOptions.empty(), token); - sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId, + sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(2, sampleDataResult.first().getAnnotationSets().size()); @@ -1581,7 +1581,7 @@ public void testAnnotateRange() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation3", vs1.getId(), annotations))), QueryOptions.empty(), token); - sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId, + sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(3, sampleDataResult.first().getAnnotationSets().size()); @@ -1589,7 +1589,7 @@ public void testAnnotateRange() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation4", vs1.getId(), annotations))), QueryOptions.empty(), token); - sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId, + sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(4, sampleDataResult.first().getAnnotationSets().size()); @@ -1602,13 +1602,13 @@ public void testAnnotateRange() throws CatalogException { @Test public void testAnnotateCategorical() throws CatalogException { - String sampleId = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, + String sampleId = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first().getId(); List variables = new ArrayList<>(); variables.add(new Variable("COOL_NAME", "COOL_NAME", "", Variable.VariableType.CATEGORICAL, "", true, false, Arrays.asList("LUKE", "LEIA", "VADER", "YODA"), null, 0, "", "", null, Collections.emptyMap())); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, variables, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, variables, Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); Map actionMap = new HashMap<>(); @@ -1620,7 +1620,7 @@ public void testAnnotateCategorical() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation1", vs1.getId(), annotations))), options, token); - DataResult sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId, + DataResult sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(1, sampleDataResult.first().getAnnotationSets().size()); @@ -1628,7 +1628,7 @@ public void testAnnotateCategorical() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation2", vs1.getId(), annotations))), options, token); - sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId, + sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(2, sampleDataResult.first().getAnnotationSets().size()); @@ -1636,7 +1636,7 @@ public void testAnnotateCategorical() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation3", vs1.getId(), annotations))), options, token); - sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId, + sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(3, sampleDataResult.first().getAnnotationSets().size()); @@ -1644,7 +1644,7 @@ public void testAnnotateCategorical() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation4", vs1.getId(), annotations))), options, token); - sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId, + sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(4, sampleDataResult.first().getAnnotationSets().size()); @@ -1657,12 +1657,12 @@ public void testAnnotateCategorical() throws CatalogException { @Test public void testAnnotateNested() throws CatalogException { - String sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), + String sampleId1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first().getId(); - String sampleId2 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_2"), + String sampleId2 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_2"), INCLUDE_RESULT, token).first().getId(); - VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", false, false, "", null, + VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, "vs1", "vs1", false, false, "", null, Collections.singletonList(CatalogAnnotationsValidatorTest.nestedObject), Collections.singletonList(VariableSet.AnnotableDataModels.SAMPLE), token).first(); @@ -1675,7 +1675,7 @@ public void testAnnotateNested() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId1, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation1", vs1.getId(), annotations))), QueryOptions.empty(), token); - DataResult sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId1, + DataResult sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId1, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(1, sampleDataResult.first().getAnnotationSets().size()); @@ -1687,66 +1687,66 @@ public void testAnnotateNested() throws CatalogException { catalogManager.getSampleManager().update(studyFqn, sampleId2, new SampleUpdateParams() .setAnnotationSets(Collections.singletonList(new AnnotationSet("annotation1", vs1.getId(), annotations))), QueryOptions.empty(), token); - sampleDataResult = catalogManager.getSampleManager().get(studyFqn, sampleId2, + sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId2, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(1, sampleDataResult.first().getAnnotationSets().size()); List samples; Query query = new Query(SampleDBAdaptor.QueryParams.ANNOTATION.key(), vs1.getId() + ":nestedObject.stringList=li"); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(1, samples.size()); query.put(SampleDBAdaptor.QueryParams.ANNOTATION.key(), vs1.getId() + ":nestedObject.stringList=lo"); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(1, samples.size()); query.put(SampleDBAdaptor.QueryParams.ANNOTATION.key(), vs1.getId() + ":nestedObject.stringList=LL"); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(0, samples.size()); query.put(SampleDBAdaptor.QueryParams.ANNOTATION.key(), vs1.getId() + ":nestedObject.stringList=lo,li,LL"); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(2, samples.size()); query.put(SampleDBAdaptor.QueryParams.ANNOTATION.key(), vs1.getId() + ":nestedObject.object.string=my value"); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(1, samples.size()); query.put(SampleDBAdaptor.QueryParams.ANNOTATION.key(), vs1.getId() + ":nestedObject.stringList=lo,lu,LL;" + vs1.getId() + ":nestedObject.object.string=my value"); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(1, samples.size()); query.put(SampleDBAdaptor.QueryParams.ANNOTATION.key(), vs1.getId() + ":nestedObject.stringList=lo,lu,LL;" + vs1.getId() + ":nestedObject.object.numberList=7"); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(0, samples.size()); query.put(SampleDBAdaptor.QueryParams.ANNOTATION.key(), vs1.getId() + ":nestedObject.stringList=lo,lu,LL;" + vs1.getId() + ":nestedObject.object.numberList=3"); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(2, samples.size()); query.put(SampleDBAdaptor.QueryParams.ANNOTATION.key(), vs1.getId() + ":nestedObject.stringList=lo,lu,LL;" + vs1.getId() + ":nestedObject.object.numberList=5;" + vs1.getId() + ":nestedObject.object.string=stringValue"); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(1, samples.size()); query.put(SampleDBAdaptor.QueryParams.ANNOTATION.key(), vs1.getId() + ":nestedObject.stringList=lo,lu,LL;" + vs1.getId() + ":nestedObject.object.numberList=2,5"); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(2, samples.size()); query.put(SampleDBAdaptor.QueryParams.ANNOTATION.key(), vs1.getId() + ":nestedObject.stringList=lo,lu,LL;" + vs1.getId() + ":nestedObject.object.numberList=0"); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(0, samples.size()); query.put(SampleDBAdaptor.QueryParams.ANNOTATION.key(), vs1.getId() + ":unexisting=lo,lu,LL"); thrown.expect(CatalogException.class); thrown.expectMessage("does not exist"); - catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); } // @Test @@ -1772,9 +1772,9 @@ public void testAnnotateNested() throws CatalogException { @Test public void testGroupByAnnotations() throws Exception { - AbstractManager.MyResourceId vs1 = catalogManager.getStudyManager().getVariableSetId("vs", studyFqn, token); + AbstractManager.MyResourceId vs1 = catalogManager.getStudyManager().getVariableSetId(organizationId, "vs", studyFqn, token); - DataResult queryResult = catalogManager.getSampleManager().groupBy(studyFqn, new Query(), + DataResult queryResult = catalogManager.getSampleManager().groupBy(organizationId, studyFqn, new Query(), Collections.singletonList(Constants.ANNOTATION + ":" + vs1.getResourceId() + ":annot1:PHEN"), QueryOptions.empty(), token); @@ -1804,7 +1804,7 @@ public void testGroupByAnnotations() throws Exception { public void testIteratorSamples() throws CatalogException { Query query = new Query(); - DBIterator iterator = catalogManager.getSampleManager().iterator(studyFqn, query, null, token); + DBIterator iterator = catalogManager.getSampleManager().iterator(organizationId, studyFqn, query, null, token); int count = 0; while (iterator.hasNext()) { iterator.next(); @@ -1815,41 +1815,41 @@ public void testIteratorSamples() throws CatalogException { @Test public void testQuerySamples() throws CatalogException { - VariableSet variableSet = catalogManager.getStudyManager().getVariableSet(studyFqn, "vs", QueryOptions.empty(), token).first(); + VariableSet variableSet = catalogManager.getStudyManager().getVariableSet(organizationId, studyFqn, "vs", QueryOptions.empty(), token).first(); List samples; Query query = new Query(); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(9, samples.size()); query = new Query(ANNOTATION.key(), Constants.VARIABLE_SET + "=" + variableSet.getId()); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(8, samples.size()); query = new Query(ANNOTATION.key(), Constants.ANNOTATION_SET_NAME + "=annot2"); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(3, samples.size()); query = new Query(ANNOTATION.key(), Constants.ANNOTATION_SET_NAME + "=noExist"); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(0, samples.size()); query = new Query(ANNOTATION.key(), variableSet.getId() + ":NAME=s_1,s_2,s_3"); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(3, samples.size()); query = new Query(ANNOTATION.key(), variableSet.getId() + ":AGE>30;" + Constants.VARIABLE_SET + "=" + variableSet.getId()); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(3, samples.size()); query = new Query(ANNOTATION.key(), variableSet.getId() + ":AGE>30;" + Constants.VARIABLE_SET + "=" + variableSet.getId()); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(3, samples.size()); query = new Query(ANNOTATION.key(), variableSet.getId() + ":AGE>30;" + variableSet.getId() + ":ALIVE=true;" + Constants.VARIABLE_SET + "=" + variableSet.getId()); - samples = catalogManager.getSampleManager().search(studyFqn, query, null, token).getResults(); + samples = catalogManager.getSampleManager().search(organizationId, studyFqn, query, null, token).getResults(); assertEquals(2, samples.size()); } @@ -1862,14 +1862,14 @@ public void testUpdateSampleId() throws CatalogException { @Test public void testUpdateAnnotation() throws CatalogException { - Sample sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, token).first(); + Sample sample = catalogManager.getSampleManager().get(organizationId, studyFqn, s_1, null, token).first(); AnnotationSet annotationSet = sample.getAnnotationSets().get(0); Individual ind = new Individual() .setId("INDIVIDUAL_1") .setSex(SexOntologyTermAnnotation.initUnknown()); ind.setAnnotationSets(Collections.singletonList(annotationSet)); - ind = catalogManager.getIndividualManager().create(studyFqn, ind, INCLUDE_RESULT, token).first(); + ind = catalogManager.getIndividualManager().create(organizationId, studyFqn, ind, INCLUDE_RESULT, token).first(); // First update annotationSet.getAnnotations().put("NAME", "SAMPLE1"); @@ -1893,8 +1893,8 @@ public void testUpdateAnnotation() throws CatalogException { assertEquals("extra", auxAnnotations.get("EXTRA")); }; - sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, token).first(); - ind = catalogManager.getIndividualManager().get(studyFqn, ind.getId(), null, token).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, s_1, null, token).first(); + ind = catalogManager.getIndividualManager().get(organizationId, studyFqn, ind.getId(), null, token).first(); check.accept(sample.getAnnotationSets().get(0)); check.accept(ind.getAnnotationSets().get(0)); @@ -1922,8 +1922,8 @@ public void testUpdateAnnotation() throws CatalogException { assertEquals(false, auxAnnotations.containsKey("EXTRA")); }; - sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, token).first(); - ind = catalogManager.getIndividualManager().get(studyFqn, ind.getId(), null, token).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, s_1, null, token).first(); + ind = catalogManager.getIndividualManager().get(organizationId, studyFqn, ind.getId(), null, token).first(); check.accept(sample.getAnnotationSets().get(0)); check.accept(ind.getAnnotationSets().get(0)); @@ -1943,8 +1943,8 @@ public void testUpdateAnnotation() throws CatalogException { assertEquals("extra", auxAnnotations.get("EXTRA")); }; - sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, token).first(); - ind = catalogManager.getIndividualManager().get(studyFqn, ind.getId(), null, token).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, s_1, null, token).first(); + ind = catalogManager.getIndividualManager().get(organizationId, studyFqn, ind.getId(), null, token).first(); check.accept(sample.getAnnotationSets().get(0)); check.accept(ind.getAnnotationSets().get(0)); @@ -1964,8 +1964,8 @@ public void testUpdateAnnotation() throws CatalogException { assertEquals("extraa", auxAnnotations.get("EXTRA")); }; - sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, token).first(); - ind = catalogManager.getIndividualManager().get(studyFqn, ind.getId(), null, token).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, s_1, null, token).first(); + ind = catalogManager.getIndividualManager().get(organizationId, studyFqn, ind.getId(), null, token).first(); check.accept(sample.getAnnotationSets().get(0)); check.accept(ind.getAnnotationSets().get(0)); @@ -1977,7 +1977,7 @@ public void testUpdateAnnotation() throws CatalogException { @Test public void testUpdatePhenotypes() throws CatalogException { - Sample sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, token).first(); + Sample sample = catalogManager.getSampleManager().get(organizationId, studyFqn, s_1, null, token).first(); List phenotypeList = Arrays.asList( new Phenotype("phenotype0", "phenotypeName0", "SOURCE"), @@ -1987,7 +1987,7 @@ public void testUpdatePhenotypes() throws CatalogException { SampleUpdateParams updateParams = new SampleUpdateParams().setPhenotypes(phenotypeList); catalogManager.getSampleManager().update(studyFqn, sample.getId(), updateParams, QueryOptions.empty(), token); - sample = catalogManager.getSampleManager().get(studyFqn, sample.getId(), QueryOptions.empty(), token).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, sample.getId(), QueryOptions.empty(), token).first(); assertEquals(3, sample.getPhenotypes().size()); for (int i = 0; i < sample.getPhenotypes().size(); i++) { assertEquals("phenotype" + i, sample.getPhenotypes().get(i).getId()); @@ -2000,7 +2000,7 @@ public void testUpdatePhenotypes() throws CatalogException { updateParams = new SampleUpdateParams().setPhenotypes(Arrays.asList( new Phenotype("phenotype0", "phenotypeName0", "SOURCE"), new Phenotype("phenotype2", "phenotypeName2", "SOURCE"))); catalogManager.getSampleManager().update(studyFqn, sample.getId(), updateParams, options, token); - sample = catalogManager.getSampleManager().get(studyFqn, sample.getId(), QueryOptions.empty(), token).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, sample.getId(), QueryOptions.empty(), token).first(); assertEquals(1, sample.getPhenotypes().size()); assertEquals("phenotype1", sample.getPhenotypes().get(0).getId()); @@ -2010,7 +2010,7 @@ public void testUpdatePhenotypes() throws CatalogException { updateParams = new SampleUpdateParams().setPhenotypes(Arrays.asList( new Phenotype("phenotype1", "phenotypeName1", "SOURCE"), new Phenotype("phenotype2", "phenotypeName2", "SOURCE"))); catalogManager.getSampleManager().update(studyFqn, sample.getId(), updateParams, options, token); - sample = catalogManager.getSampleManager().get(studyFqn, sample.getId(), QueryOptions.empty(), token).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, sample.getId(), QueryOptions.empty(), token).first(); assertEquals(2, sample.getPhenotypes().size()); for (int i = 0; i < sample.getPhenotypes().size(); i++) { assertEquals("phenotype" + (i + 1), sample.getPhenotypes().get(i).getId()); @@ -2025,7 +2025,7 @@ public void testUpdatePhenotypes() throws CatalogException { ); updateParams = new SampleUpdateParams().setPhenotypes(phenotypeList); catalogManager.getSampleManager().update(studyFqn, sample.getId(), updateParams, options, token); - sample = catalogManager.getSampleManager().get(studyFqn, sample.getId(), QueryOptions.empty(), token).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, sample.getId(), QueryOptions.empty(), token).first(); assertEquals(2, sample.getPhenotypes().size()); for (int i = 0; i < sample.getPhenotypes().size(); i++) { assertEquals("phenotype" + (i + 2), sample.getPhenotypes().get(i).getId()); @@ -2034,7 +2034,7 @@ public void testUpdatePhenotypes() throws CatalogException { @Test public void testUpdateAnnotationFail() throws CatalogException { - Sample sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, token).first(); + Sample sample = catalogManager.getSampleManager().get(organizationId, studyFqn, s_1, null, token).first(); AnnotationSet annotationSet = sample.getAnnotationSets().get(0); thrown.expect(CatalogException.class); //Can not delete required fields @@ -2051,7 +2051,7 @@ public void testDeleteAnnotation() throws CatalogException { catalogManager.getSampleManager().updateAnnotations(studyFqn, s_1, "annot1", new ObjectMap("EXTRA", "extra"), ParamUtils.CompleteUpdateAction.ADD, QueryOptions.empty(), token); - Sample sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, token).first(); + Sample sample = catalogManager.getSampleManager().get(organizationId, studyFqn, s_1, null, token).first(); AnnotationSet annotationSet = sample.getAnnotationSets().get(0); assertEquals("extra", annotationSet.getAnnotations().get("EXTRA")); @@ -2059,7 +2059,7 @@ public void testDeleteAnnotation() throws CatalogException { catalogManager.getSampleManager().removeAnnotations(studyFqn, s_1, annotationSet.getId(), Collections.singletonList("EXTRA"), QueryOptions.empty(), token); - sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, token).first(); + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, s_1, null, token).first(); annotationSet = sample.getAnnotationSets().get(0); assertTrue(!annotationSet.getAnnotations().containsKey("EXTRA")); @@ -2074,17 +2074,17 @@ public void testDeleteAnnotation() throws CatalogException { public void testDeleteAnnotationSet() throws CatalogException { catalogManager.getSampleManager().removeAnnotationSet(studyFqn, s_1, "annot1", QueryOptions.empty(), token); - DataResult sampleDataResult = catalogManager.getSampleManager().get(studyFqn, s_1, + DataResult sampleDataResult = catalogManager.getSampleManager().get(organizationId, studyFqn, s_1, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), token); assertEquals(0, sampleDataResult.first().getAnnotationSets().size()); } @Test public void getVariableSetSummary() throws CatalogException { - VariableSet variableSet = catalogManager.getStudyManager().getVariableSet(studyFqn, "vs", null, token).first(); + VariableSet variableSet = catalogManager.getStudyManager().getVariableSet(organizationId, studyFqn, "vs", null, token).first(); DataResult variableSetSummary = catalogManager.getStudyManager() - .getVariableSetSummary(studyFqn, variableSet.getId(), token); + .getVariableSetSummary(organizationId, studyFqn, variableSet.getId(), token); assertEquals(1, variableSetSummary.getNumResults()); VariableSetSummary summary = variableSetSummary.first(); @@ -2123,22 +2123,22 @@ public void getVariableSetSummary() throws CatalogException { @Test public void testModifySample() throws CatalogException { String sampleId1 = catalogManager.getSampleManager() - .create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first().getId(); - String individualId = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1"), + .create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first().getId(); + String individualId = catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("Individual1"), INCLUDE_RESULT, token).first().getId(); DataResult updateResult = catalogManager.getSampleManager() .update(studyFqn, sampleId1, new SampleUpdateParams().setIndividualId(individualId), null, token); assertEquals(1, updateResult.getNumUpdated()); - Sample sample = catalogManager.getSampleManager().get(studyFqn, sampleId1, QueryOptions.empty(), token).first(); + Sample sample = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId1, QueryOptions.empty(), token).first(); assertEquals(individualId, sample.getIndividualId()); - sample = catalogManager.getSampleManager().get(studyFqn, sampleId1, new QueryOptions(QueryOptions.INCLUDE, + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId1, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key()), token).first(); assertNull(sample.getAttributes()); - sample = catalogManager.getSampleManager().get(studyFqn, sampleId1, new QueryOptions() + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId1, new QueryOptions() .append(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key()) .append(SAMPLE_INCLUDE_INDIVIDUAL_PARAM, true), token).first(); assertNotNull(sample.getAttributes()); @@ -2149,19 +2149,19 @@ public void associateSameSampleAndIndividualInDifferentStudies() throws CatalogE String id = "myUniqueId"; for (String studyId : Arrays.asList("st1", "st2")) { System.out.println("Study " + studyId); - catalogManager.getStudyManager().create(project1, new Study().setId(studyId), QueryOptions.empty(), token); + catalogManager.getStudyManager().create(organizationId, project1, new Study().setId(studyId), QueryOptions.empty(), token); - catalogManager.getSampleManager().create(studyId, new Sample().setId(id), QueryOptions.empty(), token); - catalogManager.getIndividualManager().create(studyId, new Individual().setId(id), QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId(id), QueryOptions.empty(), token); + catalogManager.getIndividualManager().create(organizationId, studyId, new Individual().setId(id), QueryOptions.empty(), token); catalogManager.getSampleManager().update(studyId, id, new SampleUpdateParams().setIndividualId(id), QueryOptions.empty(), token); - OpenCGAResult sampleResult = catalogManager.getSampleManager().get(studyId, id, QueryOptions.empty(), token); + OpenCGAResult sampleResult = catalogManager.getSampleManager().get(organizationId, studyId, id, QueryOptions.empty(), token); assertEquals(1, sampleResult.getNumResults()); assertEquals(id, sampleResult.first().getIndividualId()); assertEquals(2, sampleResult.first().getVersion()); - OpenCGAResult individualResult = catalogManager.getIndividualManager().get(studyId, id, QueryOptions.empty(), + OpenCGAResult individualResult = catalogManager.getIndividualManager().get(organizationId, studyId, id, QueryOptions.empty(), token); assertEquals(1, individualResult.getNumResults()); assertEquals(2, individualResult.first().getVersion()); @@ -2175,32 +2175,32 @@ public void associateSameSampleAndIndividualInDifferentStudies() throws CatalogE @Test public void testGetSampleAndIndividualWithPermissionsChecked() throws CatalogException { String sampleId1 = catalogManager.getSampleManager() - .create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first().getId(); - String individualId = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1"), + .create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first().getId(); + String individualId = catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("Individual1"), INCLUDE_RESULT, token).first().getId(); DataResult updateResult = catalogManager.getSampleManager() .update(studyFqn, sampleId1, new SampleUpdateParams().setIndividualId(individualId), null, token); assertEquals(1, updateResult.getNumUpdated()); - Sample sample = catalogManager.getSampleManager().get(studyFqn, sampleId1, QueryOptions.empty(), token).first(); + Sample sample = catalogManager.getSampleManager().get(organizationId, studyFqn, sampleId1, QueryOptions.empty(), token).first(); assertEquals(individualId, sample.getIndividualId()); catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList("SAMPLE_1"), "user2", new SampleAclParams(null, null, null, null, SamplePermissions.VIEW.name()), SET, token); - sample = catalogManager.getSampleManager().get(studyFqn, "SAMPLE_1", new QueryOptions(SAMPLE_INCLUDE_INDIVIDUAL_PARAM, true), + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, "SAMPLE_1", new QueryOptions(SAMPLE_INCLUDE_INDIVIDUAL_PARAM, true), sessionIdUser2).first(); assertEquals(null, sample.getAttributes().get("OPENCGA_INDIVIDUAL")); catalogManager.getIndividualManager().updateAcl(studyFqn, Collections.emptyList(), "user2", new IndividualAclParams(sampleId1, IndividualPermissions.VIEW.name()), SET, false, token); - sample = catalogManager.getSampleManager().get(studyFqn, "SAMPLE_1", new QueryOptions(SAMPLE_INCLUDE_INDIVIDUAL_PARAM, true), + sample = catalogManager.getSampleManager().get(organizationId, studyFqn, "SAMPLE_1", new QueryOptions(SAMPLE_INCLUDE_INDIVIDUAL_PARAM, true), sessionIdUser2).first(); assertEquals(individualId, ((Individual) sample.getAttributes().get("OPENCGA_INDIVIDUAL")).getId()); assertEquals(sampleId1, sample.getId()); - sample = catalogManager.getSampleManager().search(studyFqn, new Query(SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key(), + sample = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key(), "Individual1"), new QueryOptions(SAMPLE_INCLUDE_INDIVIDUAL_PARAM, true), sessionIdUser2).first(); assertEquals(individualId, ((Individual) sample.getAttributes().get("OPENCGA_INDIVIDUAL")).getId()); assertEquals(sampleId1, sample.getId()); @@ -2208,50 +2208,50 @@ public void testGetSampleAndIndividualWithPermissionsChecked() throws CatalogExc @Test public void searchSamplesByIndividual() throws CatalogException { - catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1") + catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("Individual1") .setSamples(Arrays.asList(new Sample().setId("sample1"), new Sample().setId("sample2"))), new QueryOptions(), token); - DataResult sampleDataResult = catalogManager.getSampleManager().search(studyFqn, + DataResult sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key(), "Individual1"), QueryOptions.empty(), token); assertEquals(2, sampleDataResult.getNumResults()); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query().append(SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key(), "Individual1") .append(SampleDBAdaptor.QueryParams.ID.key(), "sample1"), QueryOptions.empty(), token); assertEquals(1, sampleDataResult.getNumResults()); - catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual2"), new QueryOptions(), token); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, + catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("Individual2"), new QueryOptions(), token); + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query().append(SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key(), "Individual2"), QueryOptions.empty(), token); assertEquals(0, sampleDataResult.getNumResults()); } @Test public void searchIndividualsBySample() throws CatalogException { - catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1") + catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("Individual1") .setSamples(Arrays.asList(new Sample().setId("sample1"), new Sample().setId("sample2"))), new QueryOptions(), token); - Individual individual = catalogManager.getIndividualManager().search(studyFqn, + Individual individual = catalogManager.getIndividualManager().search(organizationId, studyFqn, new Query(IndividualDBAdaptor.QueryParams.SAMPLES.key(), "sample1"), QueryOptions.empty(), token).first(); assertEquals("Individual1", individual.getId()); } @Test public void searchIndividualsBySampleWithNoSamples() throws CatalogException { - catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1") + catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("Individual1") .setSamples(Arrays.asList(new Sample().setId("sample1"), new Sample().setId("sample2"))), new QueryOptions(), token); - OpenCGAResult search = catalogManager.getIndividualManager().search(studyFqn, + OpenCGAResult search = catalogManager.getIndividualManager().search(organizationId, studyFqn, new Query(IndividualDBAdaptor.QueryParams.SAMPLES.key(), ""), QueryOptions.empty(), token); assertEquals(1, search.getNumResults()); } @Test public void searchSamplesDifferentVersions() throws CatalogException { - catalogManager.getSampleManager().create(studyFqn, new Sample().setId("sample1"), QueryOptions.empty(), token); - catalogManager.getSampleManager().create(studyFqn, new Sample().setId("sample2"), QueryOptions.empty(), token); - catalogManager.getSampleManager().create(studyFqn, new Sample().setId("sample3"), QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("sample1"), QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("sample2"), QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("sample3"), QueryOptions.empty(), token); // Generate 4 versions of sample1 catalogManager.getSampleManager().update(studyFqn, "sample1", new SampleUpdateParams().setDescription(RandomStringUtils.random(5)), @@ -2274,7 +2274,7 @@ public void searchSamplesDifferentVersions() throws CatalogException { Query query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), "sample1,sample2,sample3") .append(SampleDBAdaptor.QueryParams.VERSION.key(), "3,2,1"); - DataResult sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + DataResult sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(3, sampleDataResult.getNumResults()); for (Sample sample : sampleDataResult.getResults()) { switch (sample.getId()) { @@ -2293,7 +2293,7 @@ public void searchSamplesDifferentVersions() throws CatalogException { } query.put(SampleDBAdaptor.QueryParams.VERSION.key(), "2"); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(3, sampleDataResult.getNumResults()); sampleDataResult.getResults().forEach( s -> assertEquals(2, s.getVersion()) @@ -2302,39 +2302,39 @@ public void searchSamplesDifferentVersions() throws CatalogException { query.put(SampleDBAdaptor.QueryParams.VERSION.key(), "1,2"); thrown.expect(CatalogException.class); thrown.expectMessage("size of the array"); - catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); } @Test public void updateIndividualFromSample() throws CatalogException { - catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1"), new QueryOptions(), token); - catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual2"), new QueryOptions(), token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("Individual1"), new QueryOptions(), token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("Individual2"), new QueryOptions(), token); catalogManager.getSampleManager().update(studyFqn, "s_1", new SampleUpdateParams().setIndividualId("Individual1"), QueryOptions.empty(), token); - DataResult sampleDataResult = catalogManager.getSampleManager().search(studyFqn, + DataResult sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key(), "Individual1"), QueryOptions.empty(), token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals("s_1", sampleDataResult.first().getId()); catalogManager.getSampleManager().update(studyFqn, "s_1", new SampleUpdateParams().setIndividualId("Individual2"), QueryOptions.empty(), token); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key(), "Individual1"), QueryOptions.empty(), token); assertEquals(0, sampleDataResult.getNumResults()); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key(), "Individual2"), QueryOptions.empty(), token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals("s_1", sampleDataResult.first().getId()); - catalogManager.getIndividualManager().delete(studyFqn, Arrays.asList("Individual1", "Individual2"), QueryOptions.empty(), token); - catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1"), new QueryOptions(), token); - catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual2"), new QueryOptions(), token); + catalogManager.getIndividualManager().delete(organizationId, studyFqn, Arrays.asList("Individual1", "Individual2"), QueryOptions.empty(), token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("Individual1"), new QueryOptions(), token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("Individual2"), new QueryOptions(), token); catalogManager.getSampleManager().update(studyFqn, "s_1", new SampleUpdateParams().setIndividualId("Individual2"), QueryOptions.empty(), token); - sampleDataResult = catalogManager.getSampleManager().search(studyFqn, + sampleDataResult = catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(SampleDBAdaptor.QueryParams.INDIVIDUAL_ID.key(), "Individual2"), QueryOptions.empty(), token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals("s_1", sampleDataResult.first().getId()); @@ -2344,24 +2344,24 @@ public void updateIndividualFromSample() throws CatalogException { public void getSharedProject() throws CatalogException, IOException { catalogManager.getUserManager().create("dummy", "dummy", "asd@asd.asd", TestParamConstants.PASSWORD, "", 50000L, Account.AccountType.GUEST, opencgaToken); - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("dummy")), token); String token = catalogManager.getUserManager().login("dummy", TestParamConstants.PASSWORD).getToken(); - DataResult queryResult = catalogManager.getProjectManager().getSharedProjects("dummy", QueryOptions.empty(), token); + DataResult queryResult = catalogManager.getProjectManager().getSharedProjects(organizationId, "dummy", QueryOptions.empty(), token); assertEquals(1, queryResult.getNumResults()); - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("*")), this.token); - queryResult = catalogManager.getProjectManager().getSharedProjects("*", QueryOptions.empty(), null); + queryResult = catalogManager.getProjectManager().getSharedProjects(organizationId, "*", QueryOptions.empty(), null); assertEquals(1, queryResult.getNumResults()); } @Test public void smartResolutorStudyAliasFromAnonymousUser() throws CatalogException { - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("*")), token); - Study study = catalogManager.getStudyManager().resolveId(studyFqn, "*"); + Study study = catalogManager.getStudyManager().resolveId(organizationId, studyFqn, "*"); assertTrue(study != null); } @@ -2371,12 +2371,12 @@ public void checkRegisteredUserPermissions() throws CatalogException { Account.AccountType.GUEST, opencgaToken); String token = catalogManager.getUserManager().login("dummy", TestParamConstants.PASSWORD).getToken(); - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList(ParamConstants.REGISTERED_USERS)), this.token); - OpenCGAResult studyResult = catalogManager.getStudyManager().get(studyFqn, QueryOptions.empty(), token); + OpenCGAResult studyResult = catalogManager.getStudyManager().get(organizationId, studyFqn, QueryOptions.empty(), token); assertEquals(1, studyResult.getNumResults()); - assertEquals(0, catalogManager.getSampleManager().search(studyFqn, new Query(), new QueryOptions(), token).getNumResults()); + assertEquals(0, catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(), new QueryOptions(), token).getNumResults()); } @Test @@ -2385,80 +2385,80 @@ public void checkRegisteredUserPermissions2() throws CatalogException { Account.AccountType.GUEST, opencgaToken); String token = catalogManager.getUserManager().login("dummy", TestParamConstants.PASSWORD).getToken(); - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList(ParamConstants.REGISTERED_USERS)), this.token); - catalogManager.getStudyManager().updateAcl(studyFqn, "@members", new StudyAclParams("", AuthorizationManager.ROLE_VIEW_ONLY), + catalogManager.getStudyManager().updateAcl(organizationId, studyFqn, "@members", new StudyAclParams("", AuthorizationManager.ROLE_VIEW_ONLY), ParamUtils.AclAction.ADD, this.token); - OpenCGAResult studyResult = catalogManager.getStudyManager().get(studyFqn, QueryOptions.empty(), token); + OpenCGAResult studyResult = catalogManager.getStudyManager().get(organizationId, studyFqn, QueryOptions.empty(), token); assertEquals(1, studyResult.getNumResults()); - assertTrue(catalogManager.getSampleManager().search(studyFqn, new Query(), new QueryOptions(), token).getNumResults() > 0); - assertTrue(catalogManager.getFileManager().search(studyFqn, new Query(), new QueryOptions(), token).getNumResults() > 0); + assertTrue(catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(), new QueryOptions(), token).getNumResults() > 0); + assertTrue(catalogManager.getFileManager().search(organizationId, studyFqn, new Query(), new QueryOptions(), token).getNumResults() > 0); } @Test public void checkAnonymousUserWithNoPermissions() throws CatalogException { - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList(ParamConstants.REGISTERED_USERS)), this.token); - catalogManager.getStudyManager().updateAcl(studyFqn, "@members", new StudyAclParams("", AuthorizationManager.ROLE_VIEW_ONLY), + catalogManager.getStudyManager().updateAcl(organizationId, studyFqn, "@members", new StudyAclParams("", AuthorizationManager.ROLE_VIEW_ONLY), ParamUtils.AclAction.ADD, this.token); thrown.expect(CatalogException.class); thrown.expectMessage("view any study"); - catalogManager.getStudyManager().get(studyFqn, QueryOptions.empty(), ""); + catalogManager.getStudyManager().get(organizationId, studyFqn, QueryOptions.empty(), ""); } @Test public void checkAnonymousUserPermissions() throws CatalogException { - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList(ParamConstants.ANONYMOUS_USER_ID)), this.token); - OpenCGAResult studyResult = catalogManager.getStudyManager().get(studyFqn, QueryOptions.empty(), ""); + OpenCGAResult studyResult = catalogManager.getStudyManager().get(organizationId, studyFqn, QueryOptions.empty(), ""); assertEquals(1, studyResult.getNumResults()); - assertEquals(0, catalogManager.getSampleManager().search(studyFqn, new Query(), new QueryOptions(), "").getNumResults()); + assertEquals(0, catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(), new QueryOptions(), "").getNumResults()); } @Test public void checkAnonymousUserPermissions2() throws CatalogException { - catalogManager.getStudyManager().updateGroup(studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList(ParamConstants.ANONYMOUS_USER_ID)), this.token); - catalogManager.getStudyManager().updateAcl(studyFqn, "@members", new StudyAclParams("", AuthorizationManager.ROLE_VIEW_ONLY), + catalogManager.getStudyManager().updateAcl(organizationId, studyFqn, "@members", new StudyAclParams("", AuthorizationManager.ROLE_VIEW_ONLY), ParamUtils.AclAction.ADD, this.token); - OpenCGAResult studyResult = catalogManager.getStudyManager().get(studyFqn, QueryOptions.empty(), ""); + OpenCGAResult studyResult = catalogManager.getStudyManager().get(organizationId, studyFqn, QueryOptions.empty(), ""); assertEquals(1, studyResult.getNumResults()); - assertTrue(catalogManager.getSampleManager().search(studyFqn, new Query(), new QueryOptions(), "").getNumResults() > 0); - assertTrue(catalogManager.getFileManager().search(studyFqn, new Query(), new QueryOptions(), "").getNumResults() > 0); + assertTrue(catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(), new QueryOptions(), "").getNumResults() > 0); + assertTrue(catalogManager.getFileManager().search(organizationId, studyFqn, new Query(), new QueryOptions(), "").getNumResults() > 0); catalogManager.getUserManager().create("dummy", "dummy", "asd@asd.asd", TestParamConstants.PASSWORD, "", 50000L, Account.AccountType.GUEST, opencgaToken); String token = catalogManager.getUserManager().login("dummy", TestParamConstants.PASSWORD).getToken(); - studyResult = catalogManager.getStudyManager().get(studyFqn, QueryOptions.empty(), token); + studyResult = catalogManager.getStudyManager().get(organizationId, studyFqn, QueryOptions.empty(), token); assertEquals(1, studyResult.getNumResults()); - assertTrue(catalogManager.getSampleManager().search(studyFqn, new Query(), new QueryOptions(), token).getNumResults() > 0); - assertTrue(catalogManager.getFileManager().search(studyFqn, new Query(), new QueryOptions(), token).getNumResults() > 0); + assertTrue(catalogManager.getSampleManager().search(organizationId, studyFqn, new Query(), new QueryOptions(), token).getNumResults() > 0); + assertTrue(catalogManager.getFileManager().search(organizationId, studyFqn, new Query(), new QueryOptions(), token).getNumResults() > 0); } @Test public void testCreateSampleWithIndividual() throws CatalogException { - String individualId = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1"), + String individualId = catalogManager.getIndividualManager().create(organizationId, studyFqn, new Individual().setId("Individual1"), INCLUDE_RESULT, token).first().getId(); - String sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample() + String sampleId1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample() .setId("SAMPLE_1") .setIndividualId(individualId), INCLUDE_RESULT, token).first().getId(); - DataResult individualDataResult = catalogManager.getIndividualManager().get(studyFqn, individualId, + DataResult individualDataResult = catalogManager.getIndividualManager().get(organizationId, studyFqn, individualId, QueryOptions.empty(), token); assertEquals(sampleId1, individualDataResult.first().getSamples().get(0).getId()); // Create sample linking to individual based on the individual name - String sampleId2 = catalogManager.getSampleManager().create(studyFqn, new Sample() + String sampleId2 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample() .setId("SAMPLE_2") .setIndividualId("Individual1"), INCLUDE_RESULT, token).first().getId(); - individualDataResult = catalogManager.getIndividualManager().get(studyFqn, individualId, QueryOptions.empty(), token); + individualDataResult = catalogManager.getIndividualManager().get(organizationId, studyFqn, individualId, QueryOptions.empty(), token); assertEquals(2, individualDataResult.first().getSamples().size()); assertTrue(individualDataResult.first().getSamples().stream().map(Sample::getId).collect(Collectors.toSet()).containsAll( Arrays.asList(sampleId1, sampleId2) @@ -2467,7 +2467,7 @@ public void testCreateSampleWithIndividual() throws CatalogException { @Test public void testModifySampleBadIndividual() throws CatalogException { - String sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, + String sampleId1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first().getId(); thrown.expect(CatalogException.class); @@ -2477,29 +2477,29 @@ public void testModifySampleBadIndividual() throws CatalogException { @Test public void testDeleteSample() throws CatalogException { - long sampleUid = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, + long sampleUid = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("SAMPLE_1"), INCLUDE_RESULT, token).first().getUid(); Query query = new Query(SampleDBAdaptor.QueryParams.ID.key(), "SAMPLE_1"); - DataResult sampleDataResult = catalogManager.getSampleManager().search("1000G:phase1", query, new QueryOptions(), token); + DataResult sampleDataResult = catalogManager.getSampleManager().search(organizationId, "1000G:phase1", query, new QueryOptions(), token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals("SAMPLE_1", sampleDataResult.first().getId()); query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), "SAMPLE_1") .append(SampleDBAdaptor.QueryParams.DELETED.key(), false); - sampleDataResult = catalogManager.getSampleManager().search("1000G:phase1", query, new QueryOptions(), token); + sampleDataResult = catalogManager.getSampleManager().search(organizationId, "1000G:phase1", query, new QueryOptions(), token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals("SAMPLE_1", sampleDataResult.first().getId()); - DataResult delete = catalogManager.getSampleManager().delete("1000G:phase1", query, null, token); + DataResult delete = catalogManager.getSampleManager().delete(organizationId, "1000G:phase1", query, null, token); assertEquals(1, delete.getNumDeleted()); query = new Query() .append(SampleDBAdaptor.QueryParams.UID.key(), sampleUid) .append(SampleDBAdaptor.QueryParams.DELETED.key(), true); - sampleDataResult = catalogManager.getSampleManager().search("1000G:phase1", query, new QueryOptions(), token); + sampleDataResult = catalogManager.getSampleManager().search(organizationId, "1000G:phase1", query, new QueryOptions(), token); assertEquals(1, sampleDataResult.getNumResults()); assertEquals(InternalStatus.DELETED, sampleDataResult.first().getInternal().getStatus().getId()); } @@ -2507,7 +2507,7 @@ public void testDeleteSample() throws CatalogException { @Test public void testAssignPermissions() throws CatalogException { Sample sample = new Sample().setId("sample"); - catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample, QueryOptions.empty(), token); OpenCGAResult> dataResult = catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList("sample"), "user2", new SampleAclParams(null, null, null, null, "VIEW"), SET, token); @@ -2520,10 +2520,10 @@ public void testAssignPermissions() throws CatalogException { @Test public void testAssignPermissionsByFamily() throws CatalogException { Sample sample = new Sample().setId("sample1"); - catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample, QueryOptions.empty(), token); Sample sample2 = new Sample().setId("sample2"); - catalogManager.getSampleManager().create(studyFqn, sample2, QueryOptions.empty(), token); + catalogManager.getSampleManager().create(organizationId, studyFqn, sample2, QueryOptions.empty(), token); Individual individual = new Individual().setId("individual"); catalogManager.getIndividualManager().create(studyFqn, individual, Collections.singletonList(sample.getId()), @@ -2574,8 +2574,8 @@ public void incrementVersionTest() throws CatalogException { Sample dummySample1 = DummyModelUtils.getDummySample(); Sample dummySample2 = DummyModelUtils.getDummySample(); - dummySample1 = catalogManager.getSampleManager().create(studyFqn, dummySample1, options, token).first(); - dummySample2 = catalogManager.getSampleManager().create(studyFqn, dummySample2, options, token).first(); + dummySample1 = catalogManager.getSampleManager().create(organizationId, studyFqn, dummySample1, options, token).first(); + dummySample2 = catalogManager.getSampleManager().create(organizationId, studyFqn, dummySample2, options, token).first(); String oldDescription = dummySample1.getDescription(); @@ -2587,14 +2587,14 @@ public void incrementVersionTest() throws CatalogException { assertEquals(2, dummySample1.getVersion()); assertEquals("name", dummySample1.getDescription()); - dummySample2 = catalogManager.getSampleManager().get(studyFqn, dummySample2.getId(), QueryOptions.empty(), token).first(); + dummySample2 = catalogManager.getSampleManager().get(organizationId, studyFqn, dummySample2.getId(), QueryOptions.empty(), token).first(); assertEquals(1, dummySample2.getVersion()); Query query = new Query() .append(SampleDBAdaptor.QueryParams.ID.key(), dummySample1.getId()) .append(Constants.ALL_VERSIONS, true); - OpenCGAResult result = catalogManager.getSampleManager().search(studyFqn, query, QueryOptions.empty(), token); + OpenCGAResult result = catalogManager.getSampleManager().search(organizationId, studyFqn, query, QueryOptions.empty(), token); assertEquals(2, result.getNumResults()); assertEquals(oldDescription, result.getResults().get(0).getDescription()); assertEquals(1, result.getResults().get(0).getVersion()); @@ -2623,13 +2623,13 @@ public void memberReferenceTest() throws CatalogException { family.setMembers(null); QueryOptions options = new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true); - individual1 = catalogManager.getIndividualManager().create(studyFqn, individual1, options, token).first(); + individual1 = catalogManager.getIndividualManager().create(organizationId, studyFqn, individual1, options, token).first(); assertEquals(1, individual1.getVersion()); assertEquals(2, individual1.getSamples().size()); assertEquals(2, individual1.getSamples().stream().map(Sample::getVersion).filter(v -> v == 1).count()); assertEquals(2, individual1.getSamples().stream().map(Sample::getIndividualId).filter(i -> i.equals(individualId1)).count()); - individual2 = catalogManager.getIndividualManager().create(studyFqn, individual2, options, token).first(); + individual2 = catalogManager.getIndividualManager().create(organizationId, studyFqn, individual2, options, token).first(); assertEquals(1, individual2.getVersion()); assertEquals(2, individual2.getSamples().size()); assertEquals(2, individual2.getSamples().stream().map(Sample::getVersion).filter(v -> v == 1).count()); @@ -2644,7 +2644,7 @@ public void memberReferenceTest() throws CatalogException { // Update sample1 sample1 = catalogManager.getSampleManager().update(studyFqn, sample1.getId(), new SampleUpdateParams().setDescription("blabla"), options, token).first(); - individual1 = catalogManager.getIndividualManager().get(studyFqn, individualId1, QueryOptions.empty(), token).first(); + individual1 = catalogManager.getIndividualManager().get(organizationId, studyFqn, individualId1, QueryOptions.empty(), token).first(); assertEquals(2, sample1.getVersion()); assertEquals(2, individual1.getSamples().size()); @@ -2656,7 +2656,7 @@ public void memberReferenceTest() throws CatalogException { assertEquals(1, individual1.getFamilyIds().size()); assertEquals(family.getId(), individual1.getFamilyIds().get(0)); - family = catalogManager.getFamilyManager().get(studyFqn, family.getId(), QueryOptions.empty(), token).first(); + family = catalogManager.getFamilyManager().get(organizationId, studyFqn, family.getId(), QueryOptions.empty(), token).first(); assertEquals(2, family.getMembers().size()); for (Individual member : family.getMembers()) { if (member.getId().equals(individualId1)) { @@ -2676,7 +2676,7 @@ public void updateInUseInCATest() throws CatalogException { Family family = DummyModelUtils.getDummyCaseFamily("family1"); for (int i = family.getMembers().size() - 1; i >= 0; i--) { - catalogManager.getIndividualManager().create(studyFqn, family.getMembers().get(i), QueryOptions.empty(), token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, family.getMembers().get(i), QueryOptions.empty(), token); } List members = family.getMembers().stream().map(Individual::getId).collect(Collectors.toList()); @@ -2691,11 +2691,11 @@ public void updateInUseInCATest() throws CatalogException { ClinicalAnalysis case3 = DummyModelUtils.getDummyClinicalAnalysis(family.getMembers().get(0), family, null) .setLocked(true); - case1 = catalogManager.getClinicalAnalysisManager().create(studyFqn, case1, options, token).first(); + case1 = catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case1, options, token).first(); assertFalse(case1.isLocked()); - case2 = catalogManager.getClinicalAnalysisManager().create(studyFqn, case2, options, token).first(); + case2 = catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case2, options, token).first(); assertFalse(case2.isLocked()); - case3 = catalogManager.getClinicalAnalysisManager().create(studyFqn, case3, options, token).first(); + case3 = catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case3, options, token).first(); assertTrue(case3.isLocked()); String probandId = case3.getProband().getId(); @@ -2706,17 +2706,17 @@ public void updateInUseInCATest() throws CatalogException { new SampleUpdateParams().setDescription("blabla"), options, token).first(); assertEquals(2, sample.getVersion()); - Individual proband = catalogManager.getIndividualManager().get(studyFqn, probandId, QueryOptions.empty(), token).first(); + Individual proband = catalogManager.getIndividualManager().get(organizationId, studyFqn, probandId, QueryOptions.empty(), token).first(); assertEquals(3, proband.getVersion()); assertEquals(2, proband.getSamples().get(0).getVersion()); assertEquals("blabla", proband.getSamples().get(0).getDescription()); - family = catalogManager.getFamilyManager().get(studyFqn, family.getId(), QueryOptions.empty(), token).first(); + family = catalogManager.getFamilyManager().get(organizationId, studyFqn, family.getId(), QueryOptions.empty(), token).first(); assertEquals(2, family.getVersion()); assertEquals(1, family.getMembers().stream().filter(i -> i.getId().equals(probandId)).count()); assertEquals(1, family.getMembers().stream().filter(i -> i.getId().equals(probandId)).filter(i -> i.getVersion() == 3).count()); - OpenCGAResult result = catalogManager.getClinicalAnalysisManager().get(studyFqn, + OpenCGAResult result = catalogManager.getClinicalAnalysisManager().get(organizationId, studyFqn, Arrays.asList(case1.getId(), case2.getId(), case3.getId()), QueryOptions.empty(), token); case1 = result.getResults().get(0); case2 = result.getResults().get(1); @@ -2750,7 +2750,7 @@ public void deleteInUseInCATest() throws CatalogException { Family family = DummyModelUtils.getDummyCaseFamily("family1"); for (int i = family.getMembers().size() - 1; i >= 0; i--) { - catalogManager.getIndividualManager().create(studyFqn, family.getMembers().get(i), QueryOptions.empty(), token); + catalogManager.getIndividualManager().create(organizationId, studyFqn, family.getMembers().get(i), QueryOptions.empty(), token); } List members = family.getMembers().stream().map(Individual::getId).collect(Collectors.toList()); @@ -2765,27 +2765,27 @@ public void deleteInUseInCATest() throws CatalogException { ClinicalAnalysis case3 = DummyModelUtils.getDummyClinicalAnalysis(family.getMembers().get(0), family, null) .setLocked(true); - case1 = catalogManager.getClinicalAnalysisManager().create(studyFqn, case1, options, token).first(); + case1 = catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case1, options, token).first(); assertFalse(case1.isLocked()); - case2 = catalogManager.getClinicalAnalysisManager().create(studyFqn, case2, options, token).first(); + case2 = catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case2, options, token).first(); assertFalse(case2.isLocked()); - case3 = catalogManager.getClinicalAnalysisManager().create(studyFqn, case3, options, token).first(); + case3 = catalogManager.getClinicalAnalysisManager().create(organizationId, studyFqn, case3, options, token).first(); assertTrue(case3.isLocked()); // Delete sample from proband try { - catalogManager.getSampleManager().delete(studyFqn, Collections.singletonList(case1.getProband().getSamples().get(0).getId()), + catalogManager.getSampleManager().delete(organizationId, studyFqn, Collections.singletonList(case1.getProband().getSamples().get(0).getId()), new QueryOptions(ParamConstants.FORCE, true), token); } catch (CatalogException e) { assertTrue(e.getMessage().contains("in use in 3 cases")); } // unlock case3 - catalogManager.getClinicalAnalysisManager().update(studyFqn, case3.getId(), new ClinicalAnalysisUpdateParams().setLocked(false), + catalogManager.getClinicalAnalysisManager().update(organizationId, studyFqn, case3.getId(), new ClinicalAnalysisUpdateParams().setLocked(false), QueryOptions.empty(), token); try { - catalogManager.getSampleManager().delete(studyFqn, Collections.singletonList(case1.getProband().getSamples().get(0).getId()), + catalogManager.getSampleManager().delete(organizationId, studyFqn, Collections.singletonList(case1.getProband().getSamples().get(0).getId()), new QueryOptions(ParamConstants.FORCE, true), token); } catch (CatalogException e) { assertTrue(e.getMessage().contains("in use in 3 cases")); diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/StudyManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/StudyManagerTest.java index 203dbf336ac..884bef86394 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/StudyManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/managers/StudyManagerTest.java @@ -54,7 +54,7 @@ public void testDefaultVariableSets() throws Exception { String fqn = catalogManager.getStudyManager().create(project1, "newStudy", "newStudy", "newStudy", null, null, null, null, null, new QueryOptions(), token).first().getFqn(); - Study study = catalogManager.getStudyManager().get(fqn, null, token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, fqn, null, token).first(); Set s = new Reflections(new ResourcesScanner(), "variablesets/").getResources(Pattern.compile(".*\\.json")); @@ -104,18 +104,18 @@ public void cleanVariable(Variable variable) { @Test public void testCreateDuplicatedVariableSets() throws Exception { - Study study = catalogManager.getStudyManager().get(studyFqn, null, token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyFqn, null, token).first(); // Create a new variable set changing the id study.getVariableSets().get(0).setId("newId"); - catalogManager.getStudyManager().createVariableSet(studyFqn, study.getVariableSets().get(0), token); - Study study2 = catalogManager.getStudyManager().get(studyFqn, null, token).first(); + catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, study.getVariableSets().get(0), token); + Study study2 = catalogManager.getStudyManager().get(organizationId, studyFqn, null, token).first(); assertEquals(study.getVariableSets().size() + 1, study2.getVariableSets().size()); // Replicate the first of the variable sets for creation thrown.expect(CatalogException.class); thrown.expectMessage("already exists"); - catalogManager.getStudyManager().createVariableSet(studyFqn, study.getVariableSets().get(0), token); + catalogManager.getStudyManager().createVariableSet(organizationId, studyFqn, study.getVariableSets().get(0), token); } @Test @@ -128,13 +128,13 @@ public void internalVariableSetTest() throws CatalogException { variables.add(new Variable().setId("b").setType(Variable.VariableType.MAP_INTEGER).setAllowedKeys(Arrays.asList("b1", "b2"))); VariableSet variableSet = new VariableSet("myInternalVset", "", false, false, true, "", variables, null, 1, null); - OpenCGAResult result = catalogManager.getStudyManager().createVariableSet(study.getId(), variableSet, token); + OpenCGAResult result = catalogManager.getStudyManager().createVariableSet(organizationId, study.getId(), variableSet, token); assertEquals(1, result.getNumUpdated()); assertEquals(1, result.getNumResults()); assertEquals(1, result.getResults().size()); // An internal variable set should never be returned - study = catalogManager.getStudyManager().get("newStudy", QueryOptions.empty(), token).first(); + study = catalogManager.getStudyManager().get(organizationId, "newStudy", QueryOptions.empty(), token).first(); for (VariableSet vset : study.getVariableSets()) { assertNotEquals(variableSet.getId(), vset.getId()); assertFalse(vset.isInternal()); @@ -143,7 +143,7 @@ public void internalVariableSetTest() throws CatalogException { // But if I try to create another one with the same id, it should fail thrown.expect(CatalogException.class); thrown.expectMessage("exists"); - catalogManager.getStudyManager().createVariableSet(study.getId(), variableSet, token); + catalogManager.getStudyManager().createVariableSet(organizationId, study.getId(), variableSet, token); } @Test @@ -153,19 +153,19 @@ public void updateInternalRecessiveGene() throws CatalogException { assertEquals(RecessiveGeneSummaryIndex.Status.NOT_INDEXED, study.getInternal().getIndex().getRecessiveGene().getStatus()); String date = TimeUtils.getTime(); - catalogManager.getStudyManager().updateSummaryIndex("newStudy", + catalogManager.getStudyManager().updateSummaryIndex(organizationId, "newStudy", new RecessiveGeneSummaryIndex(RecessiveGeneSummaryIndex.Status.INDEXED, date), token); - study = catalogManager.getStudyManager().get("newStudy", QueryOptions.empty(), token).first(); + study = catalogManager.getStudyManager().get(organizationId, "newStudy", QueryOptions.empty(), token).first(); assertEquals(RecessiveGeneSummaryIndex.Status.INDEXED, study.getInternal().getIndex().getRecessiveGene().getStatus()); assertEquals(date, study.getInternal().getIndex().getRecessiveGene().getModificationDate()); - catalogManager.getStudyManager().updateGroup("newStudy", "members", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, "newStudy", "members", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("user2")), token); thrown.expect(CatalogAuthorizationException.class); thrown.expectMessage("admin"); - catalogManager.getStudyManager().updateSummaryIndex("newStudy", + catalogManager.getStudyManager().updateSummaryIndex(organizationId, "newStudy", new RecessiveGeneSummaryIndex(RecessiveGeneSummaryIndex.Status.INDEXED, date), sessionIdUser2); } @@ -180,9 +180,9 @@ public void updateClinicalConfiguration() throws CatalogException { assertFalse(study.getInternal().getConfiguration().getClinical().getStatus().isEmpty()); study.getInternal().getConfiguration().getClinical().setPriorities(Collections.singletonList(new ClinicalPriorityValue("bla", "bla", 1, true))); - catalogManager.getClinicalAnalysisManager().configureStudy("newStudy", study.getInternal().getConfiguration().getClinical(), token); + catalogManager.getClinicalAnalysisManager().configureStudy(organizationId, "newStudy", study.getInternal().getConfiguration().getClinical(), token); - study = catalogManager.getStudyManager().get("newStudy", QueryOptions.empty(), token).first(); + study = catalogManager.getStudyManager().get(organizationId, "newStudy", QueryOptions.empty(), token).first(); assertNotNull(study.getInternal().getConfiguration()); assertNotNull(study.getInternal().getConfiguration().getClinical()); assertFalse(study.getInternal().getConfiguration().getClinical().getPriorities().isEmpty()); @@ -191,9 +191,9 @@ public void updateClinicalConfiguration() throws CatalogException { assertFalse(study.getInternal().getConfiguration().getClinical().getFlags().isEmpty()); assertFalse(study.getInternal().getConfiguration().getClinical().getStatus().isEmpty()); - catalogManager.getClinicalAnalysisManager().configureStudy("newStudy", ClinicalAnalysisStudyConfiguration.defaultConfiguration(), token); + catalogManager.getClinicalAnalysisManager().configureStudy(organizationId, "newStudy", ClinicalAnalysisStudyConfiguration.defaultConfiguration(), token); - study = catalogManager.getStudyManager().get("newStudy", QueryOptions.empty(), token).first(); + study = catalogManager.getStudyManager().get(organizationId, "newStudy", QueryOptions.empty(), token).first(); assertNotNull(study.getInternal().getConfiguration()); assertNotNull(study.getInternal().getConfiguration().getClinical()); assertFalse(study.getInternal().getConfiguration().getClinical().getPriorities().isEmpty()); @@ -205,26 +205,26 @@ public void updateClinicalConfiguration() throws CatalogException { @Test public void testSetVariantEngineConfiguration() throws CatalogException { - Study study = catalogManager.getStudyManager().get(studyFqn, null, token).first(); + Study study = catalogManager.getStudyManager().get(organizationId, studyFqn, null, token).first(); System.out.println("getVariantEngineConfiguration() = " + study.getInternal().getConfiguration().getVariantEngine()); - catalogManager.getStudyManager().setVariantEngineConfigurationOptions(studyFqn, new ObjectMap("k1", "v1"), token); - study = catalogManager.getStudyManager().get(studyFqn, null, token).first(); + catalogManager.getStudyManager().setVariantEngineConfigurationOptions(organizationId, studyFqn, new ObjectMap("k1", "v1"), token); + study = catalogManager.getStudyManager().get(organizationId, studyFqn, null, token).first(); System.out.println("getVariantEngineConfiguration() = " + study.getInternal().getConfiguration().getVariantEngine()); assertEquals(new ObjectMap("k1", "v1"), study.getInternal().getConfiguration().getVariantEngine().getOptions()); - catalogManager.getStudyManager().setVariantEngineConfigurationOptions(studyFqn, new ObjectMap("k2", "v2"), token); - study = catalogManager.getStudyManager().get(studyFqn, null, token).first(); + catalogManager.getStudyManager().setVariantEngineConfigurationOptions(organizationId, studyFqn, new ObjectMap("k2", "v2"), token); + study = catalogManager.getStudyManager().get(organizationId, studyFqn, null, token).first(); System.out.println("getVariantEngineConfiguration() = " + study.getInternal().getConfiguration().getVariantEngine()); assertEquals(new ObjectMap("k2", "v2"), study.getInternal().getConfiguration().getVariantEngine().getOptions()); SampleIndexConfiguration sampleIndexConfiguration = SampleIndexConfiguration.defaultConfiguration(); catalogManager.getStudyManager() - .setVariantEngineConfigurationSampleIndex(studyFqn, sampleIndexConfiguration, token); - study = catalogManager.getStudyManager().get(studyFqn, null, token).first(); + .setVariantEngineConfigurationSampleIndex(organizationId, studyFqn, sampleIndexConfiguration, token); + study = catalogManager.getStudyManager().get(organizationId, studyFqn, null, token).first(); System.out.println("getVariantEngineConfiguration() = " + study.getInternal().getConfiguration().getVariantEngine()); assertEquals(sampleIndexConfiguration, study.getInternal().getConfiguration().getVariantEngine().getSampleIndex()); @@ -234,41 +234,41 @@ public void testSetVariantEngineConfiguration() throws CatalogException { @Test public void uploadTemplates() throws IOException, CatalogException { InputStream inputStream = getClass().getResource("/template.zip").openStream(); - OpenCGAResult result = catalogManager.getStudyManager().uploadTemplate(studyFqn, "template.zip", inputStream, token); + OpenCGAResult result = catalogManager.getStudyManager().uploadTemplate(organizationId, studyFqn, "template.zip", inputStream, token); assertFalse(StringUtils.isEmpty(result.first())); System.out.println(result.first()); inputStream = getClass().getResource("/template.zip").openStream(); - result = catalogManager.getStudyManager().uploadTemplate(studyFqn, "template.zip", inputStream, token); + result = catalogManager.getStudyManager().uploadTemplate(organizationId, studyFqn, "template.zip", inputStream, token); System.out.println(result.first()); } @Test public void deleteTemplates() throws IOException, CatalogException { InputStream inputStream = getClass().getResource("/template.zip").openStream(); - String templateId = catalogManager.getStudyManager().uploadTemplate(studyFqn, "template.zip", inputStream, token).first(); + String templateId = catalogManager.getStudyManager().uploadTemplate(organizationId, studyFqn, "template.zip", inputStream, token).first(); - Boolean deleted = catalogManager.getStudyManager().deleteTemplate(studyFqn, templateId, token).first(); + Boolean deleted = catalogManager.getStudyManager().deleteTemplate(organizationId, studyFqn, templateId, token).first(); assertTrue(deleted); thrown.expectMessage("doesn't exist"); thrown.expect(CatalogException.class); - catalogManager.getStudyManager().deleteTemplate(studyFqn, templateId, token); + catalogManager.getStudyManager().deleteTemplate(organizationId, studyFqn, templateId, token); } @Test public void emptyGroupTest() throws CatalogException { // In the list of users we add it as null to test it properly - catalogManager.getStudyManager().createGroup(studyFqn, "@test", null, token); - Group first = catalogManager.getStudyManager().getGroup(studyFqn, "@test", token).first(); + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, "@test", null, token); + Group first = catalogManager.getStudyManager().getGroup(organizationId, studyFqn, "@test", token).first(); assertNotNull(first.getUserIds()); catalogManager.getUserManager().create("dummy", "dummy", "dummy@mail.com", TestParamConstants.PASSWORD, "", 0L, Account.AccountType.GUEST, opencgaToken); - catalogManager.getStudyManager().createGroup(studyFqn, "@test2", Collections.singletonList("dummy"), token); - catalogManager.getStudyManager().updateAcl(studyFqn, "@test2", new StudyAclParams("", "view_only"), ParamUtils.AclAction.ADD, token); + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, "@test2", Collections.singletonList("dummy"), token); + catalogManager.getStudyManager().updateAcl(organizationId, studyFqn, "@test2", new StudyAclParams("", "view_only"), ParamUtils.AclAction.ADD, token); String dummyToken = catalogManager.getUserManager().login("dummy", TestParamConstants.PASSWORD).getToken(); - OpenCGAResult search = catalogManager.getFileManager().search(studyFqn, new Query(), new QueryOptions(), dummyToken); + OpenCGAResult search = catalogManager.getFileManager().search(organizationId, studyFqn, new Query(), new QueryOptions(), dummyToken); assertTrue(search.getNumResults() > 0); } } diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/migration/MigrationManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/migration/MigrationManagerTest.java index e28a7774895..4e9db79b64f 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/migration/MigrationManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/migration/MigrationManagerTest.java @@ -121,7 +121,7 @@ protected void run() throws MigrationException { public static class MigrationWithJobs extends MigrationTool { @Override protected void run() throws Exception { - String fqn = catalogManager.getProjectManager().search(new Query(), new QueryOptions(), token).first().getFqn(); + String fqn = catalogManager.getProjectManager().search(organizationId, new Query(), new QueryOptions(), token).first().getFqn(); getMigrationRun().getJobs().clear(); getMigrationRun().addJob(catalogManager.getJobManager().submitProject(fqn, "my-tool", null, Collections.emptyMap(), null, null, null, null, token).first()); @@ -248,7 +248,7 @@ public void testMigrationsWithJobs() throws CatalogException, IOException { assertEquals(j, migrationRun.getJobs().get(0)); // Update job with ERROR. Migration gets updated to ERROR. - Job job = catalogManager.getJobManager().get(j.getStudyId(), j.getId(), new QueryOptions(), token).first(); + Job job = catalogManager.getJobManager().get(organizationId, j.getStudyId(), j.getId(), new QueryOptions(), token).first(); Enums.ExecutionStatus status = new Enums.ExecutionStatus(Enums.ExecutionStatus.ERROR, "Failed"); catalogManager.getJobManager().update(job.getStudy().getId(), job.getId(), new ObjectMap(JobDBAdaptor.QueryParams.INTERNAL_STATUS.key(), status), new QueryOptions(), token); @@ -265,7 +265,7 @@ public void testMigrationsWithJobs() throws CatalogException, IOException { // Update job with DONE. Migration gets updated to DONE. j = migrationRun.getJobs().get(0); - job = catalogManager.getJobManager().get(j.getStudyId(), j.getId(), new QueryOptions(), token).first(); + job = catalogManager.getJobManager().get(organizationId, j.getStudyId(), j.getId(), new QueryOptions(), token).first(); status = new Enums.ExecutionStatus(Enums.ExecutionStatus.DONE, "Done"); catalogManager.getJobManager().update(job.getStudy().getId(), job.getId(), new ObjectMap(JobDBAdaptor.QueryParams.INTERNAL_STATUS.key(), status), new QueryOptions(), token); diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/stats/solr/AbstractSolrManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/stats/solr/AbstractSolrManagerTest.java index 488925c504b..530d748c630 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/stats/solr/AbstractSolrManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/stats/solr/AbstractSolrManagerTest.java @@ -101,22 +101,22 @@ public void setUpCatalogManager(CatalogManager catalogManager) throws IOExceptio studyFqn = catalogManager.getStudyManager().create(project.getFqn(), "phase1", null, "Phase 1", "Done", null, null, null, null, INCLUDE_RESULT, sessionIdOwner).first().getFqn(); - catalogManager.getStudyManager().updateGroup(studyFqn, "@admins", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@admins", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("admin1")), sessionIdOwner); - catalogManager.getStudyManager().createGroup(studyFqn, "@study_allow", Collections.singletonList("user1"), sessionIdAdmin); - catalogManager.getStudyManager().createGroup(studyFqn, "@study_deny", Collections.singletonList("user2"), sessionIdAdmin); + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, "@study_allow", Collections.singletonList("user1"), sessionIdAdmin); + catalogManager.getStudyManager().createGroup(organizationId, studyFqn, "@study_deny", Collections.singletonList("user2"), sessionIdAdmin); - catalogManager.getStudyManager().updateAcl(Collections.singletonList(studyFqn), "@study_allow", + catalogManager.getStudyManager().updateAcl(organizationId, Collections.singletonList(studyFqn), "@study_allow", new StudyAclParams(null, "view_only"), ParamUtils.AclAction.ADD, sessionIdAdmin); - study = catalogManager.getStudyManager().get("phase1", new QueryOptions(DBAdaptor.INCLUDE_ACLS, true), sessionIdOwner).first(); + study = catalogManager.getStudyManager().get(organizationId, "phase1", new QueryOptions(DBAdaptor.INCLUDE_ACLS, true), sessionIdOwner).first(); // Samples - Sample sample1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("sample1"), INCLUDE_RESULT, + Sample sample1 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("sample1"), INCLUDE_RESULT, sessionIdAdmin).first(); - Sample sample2 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("sample2"), INCLUDE_RESULT, + Sample sample2 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("sample2"), INCLUDE_RESULT, sessionIdAdmin).first(); - Sample sample3 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("sample3"), INCLUDE_RESULT, + Sample sample3 = catalogManager.getSampleManager().create(organizationId, studyFqn, new Sample().setId("sample3"), INCLUDE_RESULT, sessionIdAdmin).first(); catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList("sample1"), "@study_deny,user3", @@ -125,11 +125,11 @@ public void setUpCatalogManager(CatalogManager catalogManager) throws IOExceptio new SampleAclParams(null, null, null, null, ""), ParamUtils.AclAction.SET, sessionIdAdmin); // Cohorts - catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("cohort1").setSamples(Arrays.asList(sample1, sample2, sample3)), + catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("cohort1").setSamples(Arrays.asList(sample1, sample2, sample3)), QueryOptions.empty(), sessionIdAdmin); - catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("cohort2").setSamples(Arrays.asList(sample1, sample2)), + catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("cohort2").setSamples(Arrays.asList(sample1, sample2)), QueryOptions.empty(), sessionIdAdmin); - catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("cohort3").setSamples(Arrays.asList(sample2, sample3)), + catalogManager.getCohortManager().create(organizationId, studyFqn, new Cohort().setId("cohort3").setSamples(Arrays.asList(sample2, sample3)), QueryOptions.empty(), sessionIdAdmin); catalogManager.getCohortManager().updateAcl(studyFqn, Collections.singletonList("cohort1"), "@study_deny,user3", diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogFileUtilsTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogFileUtilsTest.java index 6d31de83b9e..38af7e2fed9 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogFileUtilsTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogFileUtilsTest.java @@ -129,7 +129,7 @@ public void checkFileTest() throws CatalogException, IOException { assertEquals(FileStatus.MISSING, returnedFile.getInternal().getStatus().getId()); /** Check MISSING file still missing **/ - file = catalogManager.getFileManager().get(studyFqn, file.getPath(), null, userSessionId).first(); + file = catalogManager.getFileManager().get(organizationId, studyFqn, file.getPath(), null, userSessionId).first(); returnedFile = catalogFileUtils.checkFile(studyFqn, file, true, userSessionId); assertEquals("Should not modify the still MISSING file, so should return the same file.", file.getInternal().getStatus().getId(), diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoaderTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoaderTest.java index 336d60295c5..788777492d8 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoaderTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoaderTest.java @@ -129,19 +129,19 @@ public void testLoadPedigreeCatalog() throws Exception { .append(QueryOptions.LIMIT, 0) .append(QueryOptions.COUNT, true); - DataResult allSamples = catalogManager.getSampleManager().search(studyId, query, options, sessionId); + DataResult allSamples = catalogManager.getSampleManager().search(organizationId, studyId, query, options, sessionId); Assert.assertNotEquals(0, allSamples.getNumMatches()); query = new Query(Constants.ANNOTATION, variableSetId + ":sex=2;" + variableSetId + ":Population=ITU"); - DataResult femaleIta = catalogManager.getSampleManager().search(studyId, query, options, sessionId); + DataResult femaleIta = catalogManager.getSampleManager().search(organizationId, studyId, query, options, sessionId); Assert.assertNotEquals(0, femaleIta.getNumMatches()); query = new Query(Constants.ANNOTATION, variableSetId + ":sex=1;" + variableSetId + ":Population=ITU"); - DataResult maleIta = catalogManager.getSampleManager().search(studyId, query, options, sessionId); + DataResult maleIta = catalogManager.getSampleManager().search(organizationId, studyId, query, options, sessionId); Assert.assertNotEquals(0, maleIta.getNumMatches()); query = new Query(Constants.ANNOTATION, variableSetId + ":Population=ITU"); - DataResult ita = catalogManager.getSampleManager().search(studyId, query, options, sessionId); + DataResult ita = catalogManager.getSampleManager().search(organizationId, studyId, query, options, sessionId); Assert.assertNotEquals(0, ita.getNumMatches()); Assert.assertEquals("Fail sample query", ita.getNumMatches(), maleIta.getNumMatches() + femaleIta.getNumMatches()); diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/FileMetadataReaderTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/FileMetadataReaderTest.java index 8813e517553..a3679a370e0 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/FileMetadataReaderTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/FileMetadataReaderTest.java @@ -153,7 +153,7 @@ public void testGetMetadataFromVcf() throws CatalogException, IOException { public void testGetMetadataFromVcfWithAlreadyExistingSamples() throws CatalogException, IOException { //Create the samples in the same order than in the file for (String sampleName : expectedSampleNames) { - catalogManager.getSampleManager().create(study.getFqn(), new Sample().setId(sampleName), new QueryOptions(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, study.getFqn(), new Sample().setId(sampleName), new QueryOptions(), sessionIdUser); } testGetMetadataFromVcf(); } @@ -161,20 +161,20 @@ public void testGetMetadataFromVcfWithAlreadyExistingSamples() throws CatalogExc @Test public void testGetMetadataFromVcfWithAlreadyExistingSamplesUnsorted() throws CatalogException, IOException { //Create samples in a different order than the file order - catalogManager.getSampleManager().create(study.getFqn(), new Sample().setId(expectedSampleNames.get(2)), new QueryOptions(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, study.getFqn(), new Sample().setId(expectedSampleNames.get(2)), new QueryOptions(), sessionIdUser); - catalogManager.getSampleManager().create(study.getFqn(), new Sample().setId(expectedSampleNames.get(0)), new QueryOptions(), sessionIdUser); - catalogManager.getSampleManager().create(study.getFqn(), new Sample().setId(expectedSampleNames.get(3)), new QueryOptions(), sessionIdUser); - catalogManager.getSampleManager().create(study.getFqn(), new Sample().setId(expectedSampleNames.get(1)), new QueryOptions(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, study.getFqn(), new Sample().setId(expectedSampleNames.get(0)), new QueryOptions(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, study.getFqn(), new Sample().setId(expectedSampleNames.get(3)), new QueryOptions(), sessionIdUser); + catalogManager.getSampleManager().create(organizationId, study.getFqn(), new Sample().setId(expectedSampleNames.get(1)), new QueryOptions(), sessionIdUser); testGetMetadataFromVcf(); } @Test public void testGetMetadataFromVcfWithSomeExistingSamples() throws CatalogException, IOException { - catalogManager.getSampleManager().create(study.getFqn(), new Sample().setId(expectedSampleNames.get(2)), new QueryOptions(), + catalogManager.getSampleManager().create(organizationId, study.getFqn(), new Sample().setId(expectedSampleNames.get(2)), new QueryOptions(), sessionIdUser); - catalogManager.getSampleManager().create(study.getFqn(), new Sample().setId(expectedSampleNames.get(0)), new QueryOptions(), + catalogManager.getSampleManager().create(organizationId, study.getFqn(), new Sample().setId(expectedSampleNames.get(0)), new QueryOptions(), sessionIdUser); testGetMetadataFromVcf(); @@ -194,12 +194,12 @@ public void testDoNotOverwriteSampleIds() throws CatalogException, IOException { assertEquals(4, file.getSampleIds().size()); //Add a sampleId - String sampleId = catalogManager.getSampleManager().create(study.getFqn(), new Sample().setId("Bad_Sample"), INCLUDE_RESULT, sessionIdUser) + String sampleId = catalogManager.getSampleManager().create(organizationId, study.getFqn(), new Sample().setId("Bad_Sample"), INCLUDE_RESULT, sessionIdUser) .first().getId(); catalogManager.getFileManager().update(study.getFqn(), file.getPath(), new FileUpdateParams().setSampleIds(Collections.singletonList(sampleId)), new QueryOptions(), sessionIdUser); - file = catalogManager.getFileManager().get(study.getFqn(), file.getPath(), null, sessionIdUser).first(); + file = catalogManager.getFileManager().get(organizationId, study.getFqn(), file.getPath(), null, sessionIdUser).first(); assertEquals(5, file.getSampleIds().size()); assertEquals(sampleId, file.getSampleIds().get(4)); } diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/FileScannerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/FileScannerTest.java index b09c365b86d..49734d9e23c 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/FileScannerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/FileScannerTest.java @@ -136,7 +136,7 @@ public File getDeletedFile(long id) throws CatalogException { Query query = new Query() .append(FileDBAdaptor.QueryParams.UID.key(), id) .append(FileDBAdaptor.QueryParams.DELETED.key(), true); - return catalogManager.getFileManager().search(study.getFqn(), query, null, sessionIdUser).first(); + return catalogManager.getFileManager().search(organizationId, study.getFqn(), query, null, sessionIdUser).first(); } @Test @@ -160,7 +160,7 @@ public void testReplaceExisting() throws IOException, CatalogException { FileScanner fileScanner = new FileScanner(catalogManager); fileScanner.scan(folder, directory.toUri(), FileScanner.FileScannerPolicy.REPLACE, true, true, sessionIdUser); - File replacedFile = catalogManager.getFileManager().get(study.getFqn(), file.getPath(), null, sessionIdUser).first(); + File replacedFile = catalogManager.getFileManager().get(organizationId, study.getFqn(), file.getPath(), null, sessionIdUser).first(); assertEquals(FileStatus.READY, replacedFile.getInternal().getStatus().getId()); assertEquals(file.getUid(), replacedFile.getUid()); assertNotEquals(replacedFile.getChecksum(), file.getChecksum()); @@ -209,7 +209,7 @@ public void testScanStudyURI() throws IOException, CatalogException { Path studyUriPath = Paths.get(study.getUri()); CatalogManagerTest.createDebugFile(studyUriPath.resolve("data/test/folder/").resolve("file2.txt").toString()); - File root = catalogManager.getFileManager().search(study.getFqn(), new Query("name", "."), null, sessionIdUser).first(); + File root = catalogManager.getFileManager().search(organizationId, study.getFqn(), new Query("name", "."), null, sessionIdUser).first(); files = fileScanner.scan(root, studyUriPath.toUri(), FileScanner.FileScannerPolicy.REPLACE, true, true, sessionIdUser); assertEquals(1, files.size()); diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/templates/TemplateManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/templates/TemplateManagerTest.java index 3edb612f992..165cae66267 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/templates/TemplateManagerTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/templates/TemplateManagerTest.java @@ -50,7 +50,7 @@ public void test() throws Exception { String token = catalogManager.getUserManager().login("user1", TestParamConstants.PASSWORD).getToken(); catalogManager.getProjectManager().create("project", "Project", "", "hsapiens", "common", "GRCh38", QueryOptions.empty(), token); - catalogManager.getStudyManager().create("project", new Study().setId("study"), QueryOptions.empty(), token); + catalogManager.getStudyManager().create(organizationId, "project", new Study().setId("study"), QueryOptions.empty(), token); URI resource = catalogManagerResource.getResourceUri("templates/manifest.yml"); catalogManagerResource.getResourceUri("templates/families.members.txt"); @@ -81,7 +81,7 @@ public void test_yaml() throws Exception { String token = catalogManager.getUserManager().login("user1", TestParamConstants.PASSWORD).getToken(); catalogManager.getProjectManager().create("project", "Project", "", "hsapiens", "common", "GRCh38", QueryOptions.empty(), token); - catalogManager.getStudyManager().create("project", new Study().setId("study"), QueryOptions.empty(), token); + catalogManager.getStudyManager().create(organizationId, "project", new Study().setId("study"), QueryOptions.empty(), token); URI resource = catalogManagerResource.getResourceUri("templates_yaml/manifest.yml"); catalogManagerResource.getResourceUri("templates_yaml/families.members.txt"); diff --git a/opencga-master/src/main/java/org/opencb/opencga/master/monitor/daemons/ExecutionDaemon.java b/opencga-master/src/main/java/org/opencb/opencga/master/monitor/daemons/ExecutionDaemon.java index e7920c53303..5a7e67fa30d 100644 --- a/opencga-master/src/main/java/org/opencb/opencga/master/monitor/daemons/ExecutionDaemon.java +++ b/opencga-master/src/main/java/org/opencb/opencga/master/monitor/daemons/ExecutionDaemon.java @@ -500,7 +500,7 @@ protected int checkPendingJob(Job job) { if (tool.scope() == Tool.Scope.PROJECT) { String projectFqn = job.getStudy().getId().substring(0, job.getStudy().getId().indexOf(ParamConstants.PROJECT_STUDY_SEPARATOR)); try { - List studyFqnSet = catalogManager.getStudyManager().search(projectFqn, new Query(), + List studyFqnSet = catalogManager.getStudyManager().search(organizationId, projectFqn, new Query(), new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(StudyDBAdaptor.QueryParams.GROUPS.key(), StudyDBAdaptor.QueryParams.FQN.key())), token) .getResults() @@ -629,11 +629,11 @@ protected void checkToolExecutionPermission(Job job) throws Exception { if (tool.scope() == Tool.Scope.PROJECT) { String projectFqn = job.getStudy().getId() .substring(0, job.getStudy().getId().indexOf(ParamConstants.PROJECT_STUDY_SEPARATOR)); - studiesToValidate = catalogManager.getStudyManager().search(projectFqn, new Query(), + studiesToValidate = catalogManager.getStudyManager().search(organizationId, projectFqn, new Query(), new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(StudyDBAdaptor.QueryParams.GROUPS.key(), StudyDBAdaptor.QueryParams.FQN.key())), token).getResults(); } else { - studiesToValidate = catalogManager.getStudyManager().get(job.getStudy().getId(), + studiesToValidate = catalogManager.getStudyManager().get(organizationId, job.getStudy().getId(), new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(StudyDBAdaptor.QueryParams.GROUPS.key(), StudyDBAdaptor.QueryParams.FQN.key())), token).getResults(); } @@ -687,7 +687,7 @@ private File getValidInternalOutDir(String study, Job job, String outDirPath, St } File outDir; try { - outDir = fileManager.get(study, outDirPath, FileManager.INCLUDE_FILE_URI_PATH, token).first(); + outDir = fileManager.get(organizationId, study, outDirPath, FileManager.INCLUDE_FILE_URI_PATH, token).first(); } catch (CatalogException e) { // Directory not found. Will try to create using user's token boolean parents = (boolean) job.getAttributes().getOrDefault(Job.OPENCGA_PARENTS, false); @@ -1012,7 +1012,7 @@ private int processFinishedJob(Job job, Enums.ExecutionStatus status) { for (URI externalFile : execution.getExternalFiles()) { Query query = new Query(FileDBAdaptor.QueryParams.URI.key(), externalFile); try { - OpenCGAResult search = fileManager.search(job.getStudy().getId(), query, FileManager.INCLUDE_FILE_URI_PATH, + OpenCGAResult search = fileManager.search(organizationId, job.getStudy().getId(), query, FileManager.INCLUDE_FILE_URI_PATH, token); if (search.getNumResults() == 0) { throw new CatalogException("File not found"); @@ -1079,7 +1079,7 @@ private void copyJobResultsInTemplateFolder(Job job, Path outDirPath) { String templateId = String.valueOf(job.getParams().get("id")); // We obtain the basic studyPath where we will upload the file temporarily - Study study = catalogManager.getStudyManager().get(job.getStudy().getId(), + Study study = catalogManager.getStudyManager().get(organizationId, job.getStudy().getId(), new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.URI.key()), token).first(); java.nio.file.Path studyPath = Paths.get(study.getUri()); diff --git a/opencga-master/src/test/java/org/opencb/opencga/master/monitor/daemons/ExecutionDaemonTest.java b/opencga-master/src/test/java/org/opencb/opencga/master/monitor/daemons/ExecutionDaemonTest.java index e04aee848ae..c0d7221b01b 100644 --- a/opencga-master/src/test/java/org/opencb/opencga/master/monitor/daemons/ExecutionDaemonTest.java +++ b/opencga-master/src/test/java/org/opencb/opencga/master/monitor/daemons/ExecutionDaemonTest.java @@ -143,7 +143,7 @@ public void testCreateDefaultOutDir() throws Exception { @Test public void testWebhookNotification() throws Exception { - catalogManager.getStudyManager().update(studyFqn, new StudyUpdateParams() + catalogManager.getStudyManager().update(organizationId, studyFqn, new StudyUpdateParams() .setNotification(new StudyNotification(new URL("https://ptsv2.com/t/dgogf-1581523512/post"))), null, token); HashMap params = new HashMap<>(); @@ -199,7 +199,7 @@ public void testNotEmptyOutDir() throws Exception { daemon.checkPendingJobs(); - OpenCGAResult jobOpenCGAResult = catalogManager.getJobManager().get(studyFqn, jobId, QueryOptions.empty(), token); + OpenCGAResult jobOpenCGAResult = catalogManager.getJobManager().get(organizationId, studyFqn, jobId, QueryOptions.empty(), token); assertEquals(1, jobOpenCGAResult.getNumResults()); checkStatus(getJob(jobId), Enums.ExecutionStatus.ABORTED); checkStatus(jobOpenCGAResult.first(), Enums.ExecutionStatus.ABORTED); @@ -209,13 +209,13 @@ public void testNotEmptyOutDir() throws Exception { @Test public void testProjectScopeTask() throws Exception { // User 2 to admins group in study1 but not in study2 - catalogManager.getStudyManager().updateGroup(studyFqn, "@admins", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@admins", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("user2")), token); // User 3 to admins group in both study1 and study2 - catalogManager.getStudyManager().updateGroup(studyFqn, "@admins", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn, "@admins", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("user3")), token); - catalogManager.getStudyManager().updateGroup(studyFqn2, "@admins", ParamUtils.BasicUpdateAction.ADD, + catalogManager.getStudyManager().updateGroup(organizationId, studyFqn2, "@admins", ParamUtils.BasicUpdateAction.ADD, new GroupUpdateParams(Collections.singletonList("user3")), token); HashMap params = new HashMap<>(); @@ -229,26 +229,26 @@ public void testProjectScopeTask() throws Exception { daemon.checkPendingJobs(); // Job sent by the owner - OpenCGAResult jobOpenCGAResult = catalogManager.getJobManager().get(studyFqn, jobId, QueryOptions.empty(), token); + OpenCGAResult jobOpenCGAResult = catalogManager.getJobManager().get(organizationId, studyFqn, jobId, QueryOptions.empty(), token); assertEquals(1, jobOpenCGAResult.getNumResults()); checkStatus(jobOpenCGAResult.first(), Enums.ExecutionStatus.QUEUED); // Job sent by user2 (admin from study1 but not from study2) - jobOpenCGAResult = catalogManager.getJobManager().get(studyFqn, jobId2, QueryOptions.empty(), token); + jobOpenCGAResult = catalogManager.getJobManager().get(organizationId, studyFqn, jobId2, QueryOptions.empty(), token); assertEquals(1, jobOpenCGAResult.getNumResults()); checkStatus(jobOpenCGAResult.first(), Enums.ExecutionStatus.ABORTED); assertTrue(jobOpenCGAResult.first().getInternal().getStatus().getDescription() .contains("can only be executed by the project owners or members of " + ParamConstants.ADMINS_GROUP)); // Job sent by user3 (admin from study1 and study2) - jobOpenCGAResult = catalogManager.getJobManager().get(studyFqn, jobId3, QueryOptions.empty(), token); + jobOpenCGAResult = catalogManager.getJobManager().get(organizationId, studyFqn, jobId3, QueryOptions.empty(), token); assertEquals(1, jobOpenCGAResult.getNumResults()); checkStatus(jobOpenCGAResult.first(), Enums.ExecutionStatus.QUEUED); - jobOpenCGAResult = catalogManager.getJobManager().search(studyFqn2, new Query(), QueryOptions.empty(), token); + jobOpenCGAResult = catalogManager.getJobManager().search(organizationId, studyFqn2, new Query(), QueryOptions.empty(), token); assertEquals(0, jobOpenCGAResult.getNumResults()); - jobOpenCGAResult = catalogManager.getJobManager().search(studyFqn2, new Query(), + jobOpenCGAResult = catalogManager.getJobManager().search(organizationId, studyFqn2, new Query(), new QueryOptions(ParamConstants.OTHER_STUDIES_FLAG, true), token); assertEquals(2, jobOpenCGAResult.getNumResults()); } @@ -262,11 +262,11 @@ public void testDependsOnJobs() throws Exception { daemon.checkPendingJobs(); - OpenCGAResult jobOpenCGAResult = catalogManager.getJobManager().get(studyFqn, job1, QueryOptions.empty(), token); + OpenCGAResult jobOpenCGAResult = catalogManager.getJobManager().get(organizationId, studyFqn, job1, QueryOptions.empty(), token); assertEquals(1, jobOpenCGAResult.getNumResults()); checkStatus(jobOpenCGAResult.first(), Enums.ExecutionStatus.QUEUED); - jobOpenCGAResult = catalogManager.getJobManager().get(studyFqn, job2, QueryOptions.empty(), token); + jobOpenCGAResult = catalogManager.getJobManager().get(organizationId, studyFqn, job2, QueryOptions.empty(), token); assertEquals(1, jobOpenCGAResult.getNumResults()); checkStatus(jobOpenCGAResult.first(), Enums.ExecutionStatus.PENDING); @@ -276,7 +276,7 @@ public void testDependsOnJobs() throws Exception { // The job that depended on job1 should be ABORTED because job1 execution "failed" daemon.checkPendingJobs(); - jobOpenCGAResult = catalogManager.getJobManager().get(studyFqn, job2, QueryOptions.empty(), token); + jobOpenCGAResult = catalogManager.getJobManager().get(organizationId, studyFqn, job2, QueryOptions.empty(), token); assertEquals(1, jobOpenCGAResult.getNumResults()); checkStatus(jobOpenCGAResult.first(), Enums.ExecutionStatus.ABORTED); assertTrue(jobOpenCGAResult.first().getInternal().getStatus().getDescription().contains("depended on did not finish successfully")); @@ -290,7 +290,7 @@ public void testDependsOnJobs() throws Exception { Collections.singletonList(job1), null, token).first().getId(); daemon.checkPendingJobs(); - jobOpenCGAResult = catalogManager.getJobManager().get(studyFqn, job3, QueryOptions.empty(), token); + jobOpenCGAResult = catalogManager.getJobManager().get(organizationId, studyFqn, job3, QueryOptions.empty(), token); assertEquals(1, jobOpenCGAResult.getNumResults()); checkStatus(jobOpenCGAResult.first(), Enums.ExecutionStatus.QUEUED); } @@ -305,7 +305,7 @@ public void testDependsOnMultiStudy() throws Exception { assertEquals(firstJob.getId(), job.getDependsOn().get(0).getId()); assertEquals(firstJob.getUuid(), job.getDependsOn().get(0).getUuid()); - job = catalogManager.getJobManager().get(studyFqn2, job.getId(), QueryOptions.empty(), token).first(); + job = catalogManager.getJobManager().get(organizationId, studyFqn2, job.getId(), QueryOptions.empty(), token).first(); assertEquals(1, job.getDependsOn().size()); assertEquals(firstJob.getId(), job.getDependsOn().get(0).getId()); assertEquals(firstJob.getUuid(), job.getDependsOn().get(0).getUuid()); @@ -315,7 +315,7 @@ public void testDependsOnMultiStudy() throws Exception { public void testRunJob() throws Exception { HashMap params = new HashMap<>(); params.put(ExecutionDaemon.OUTDIR_PARAM, "outDir"); - org.opencb.opencga.core.models.file.File inputFile = catalogManager.getFileManager().get(studyFqn, testFile1, null, token).first(); + org.opencb.opencga.core.models.file.File inputFile = catalogManager.getFileManager().get(organizationId, studyFqn, testFile1, null, token).first(); params.put("myFile", inputFile.getPath()); Job job = catalogManager.getJobManager().submit(studyFqn, "variant-index", Enums.Priority.MEDIUM, params, token).first(); String jobId = job.getId(); @@ -345,7 +345,7 @@ public void testRunJob() throws Exception { public void testCheckLogs() throws Exception { HashMap params = new HashMap<>(); params.put(ExecutionDaemon.OUTDIR_PARAM, "outDir"); - org.opencb.opencga.core.models.file.File inputFile = catalogManager.getFileManager().get(studyFqn, testFile1, null, token).first(); + org.opencb.opencga.core.models.file.File inputFile = catalogManager.getFileManager().get(organizationId, studyFqn, testFile1, null, token).first(); params.put("myFile", inputFile.getPath()); Job job = catalogManager.getJobManager().submit(studyFqn, "variant-index", Enums.Priority.MEDIUM, params, token).first(); String jobId = job.getId(); @@ -360,7 +360,7 @@ public void testCheckLogs() throws Exception { checkStatus(getJob(jobId), Enums.ExecutionStatus.QUEUED); executor.jobStatus.put(jobId, Enums.ExecutionStatus.RUNNING); - job = catalogManager.getJobManager().get(studyFqn, jobId, null, token).first(); + job = catalogManager.getJobManager().get(organizationId, studyFqn, jobId, null, token).first(); daemon.checkJobs(); checkStatus(getJob(jobId), Enums.ExecutionStatus.RUNNING); @@ -380,7 +380,7 @@ public void testCheckLogs() throws Exception { public void testCheckLogsNoPermissions() throws Exception { HashMap params = new HashMap<>(); params.put(ExecutionDaemon.OUTDIR_PARAM, "outDir"); - org.opencb.opencga.core.models.file.File inputFile = catalogManager.getFileManager().get(studyFqn, testFile1, null, token).first(); + org.opencb.opencga.core.models.file.File inputFile = catalogManager.getFileManager().get(organizationId, studyFqn, testFile1, null, token).first(); params.put("myFile", inputFile.getPath()); Job job = catalogManager.getJobManager().submit(studyFqn, "variant-index", Enums.Priority.MEDIUM, params, token).first(); String jobId = job.getId(); @@ -398,7 +398,7 @@ public void testCheckLogsNoPermissions() throws Exception { checkStatus(getJob(jobId), Enums.ExecutionStatus.QUEUED); executor.jobStatus.put(jobId, Enums.ExecutionStatus.RUNNING); - job = catalogManager.getJobManager().get(studyFqn, jobId, null, token).first(); + job = catalogManager.getJobManager().get(organizationId, studyFqn, jobId, null, token).first(); daemon.checkJobs(); checkStatus(getJob(jobId), Enums.ExecutionStatus.RUNNING); @@ -415,7 +415,7 @@ public void testCheckLogsNoPermissions() throws Exception { public void testRegisterFilesSuccessfully() throws Exception { HashMap params = new HashMap<>(); // params.put(ExecutionDaemon.OUTDIR_PARAM, "outDir"); - org.opencb.opencga.core.models.file.File inputFile = catalogManager.getFileManager().get(studyFqn, testFile1, null, token).first(); + org.opencb.opencga.core.models.file.File inputFile = catalogManager.getFileManager().get(organizationId, studyFqn, testFile1, null, token).first(); params.put("myFile", inputFile.getPath()); Job job = catalogManager.getJobManager().submit(studyFqn, "variant-index", Enums.Priority.MEDIUM, params, token).first(); String jobId = job.getId(); @@ -436,7 +436,7 @@ public void testRegisterFilesSuccessfully() throws Exception { createAnalysisResult(jobId, "myTest", false); executor.jobStatus.put(jobId, Enums.ExecutionStatus.READY); - job = catalogManager.getJobManager().get(studyFqn, job.getId(), QueryOptions.empty(), token).first(); + job = catalogManager.getJobManager().get(organizationId, studyFqn, job.getId(), QueryOptions.empty(), token).first(); Files.createFile(Paths.get(job.getOutDir().getUri()).resolve("file1.txt")); Files.createFile(Paths.get(job.getOutDir().getUri()).resolve("file2.txt")); Files.createDirectory(Paths.get(job.getOutDir().getUri()).resolve("A")); @@ -449,7 +449,7 @@ public void testRegisterFilesSuccessfully() throws Exception { checkStatus(getJob(jobId), Enums.ExecutionStatus.DONE); - job = catalogManager.getJobManager().get(studyFqn, job.getId(), QueryOptions.empty(), token).first(); + job = catalogManager.getJobManager().get(organizationId, studyFqn, job.getId(), QueryOptions.empty(), token).first(); String outDir = job.getOutDir().getPath(); @@ -465,7 +465,7 @@ public void testRegisterFilesSuccessfully() throws Exception { assertEquals(job.getId() + ".err", job.getStderr().getName()); // Check jobId is properly populated - OpenCGAResult files = catalogManager.getFileManager().search(studyFqn, + OpenCGAResult files = catalogManager.getFileManager().search(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.JOB_ID.key(), job.getId()), FileManager.INCLUDE_FILE_URI_PATH, token); List expectedFiles = Arrays.asList( outDir, @@ -485,9 +485,9 @@ public void testRegisterFilesSuccessfully() throws Exception { } } - files = catalogManager.getFileManager().count(studyFqn, new Query(FileDBAdaptor.QueryParams.JOB_ID.key(), ""), token); + files = catalogManager.getFileManager().count(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.JOB_ID.key(), ""), token); assertEquals(10, files.getNumMatches()); - files = catalogManager.getFileManager().count(studyFqn, new Query(FileDBAdaptor.QueryParams.JOB_ID.key(), "NonE"), token); + files = catalogManager.getFileManager().count(organizationId, studyFqn, new Query(FileDBAdaptor.QueryParams.JOB_ID.key(), "NonE"), token); assertEquals(10, files.getNumMatches()); } @@ -544,7 +544,7 @@ private void checkStatus(Job job, String status) { } private Job getJob(String jobId) throws CatalogException { - return catalogManager.getJobManager().get(studyFqn, jobId, new QueryOptions(), token).first(); + return catalogManager.getJobManager().get(organizationId, studyFqn, jobId, new QueryOptions(), token).first(); } private void createAnalysisResult(String jobId, String analysisId, boolean error) throws CatalogException, ToolException { diff --git a/opencga-master/src/test/java/org/opencb/opencga/master/monitor/models/PrivateJobUpdateParamsTest.java b/opencga-master/src/test/java/org/opencb/opencga/master/monitor/models/PrivateJobUpdateParamsTest.java index 8ab9f740c71..99352c5fd3e 100644 --- a/opencga-master/src/test/java/org/opencb/opencga/master/monitor/models/PrivateJobUpdateParamsTest.java +++ b/opencga-master/src/test/java/org/opencb/opencga/master/monitor/models/PrivateJobUpdateParamsTest.java @@ -71,7 +71,7 @@ public void updateJobInformation() throws CatalogException { PrivateJobUpdateParams updateParams = new PrivateJobUpdateParams().setCommandLine("myCommandLine"); catalogManager.getJobManager().update(studyFqn, jobResult.first().getId(), updateParams, QueryOptions.empty(), token); - jobResult = catalogManager.getJobManager().get(studyFqn, jobResult.first().getId(), QueryOptions.empty(), token); + jobResult = catalogManager.getJobManager().get(organizationId, studyFqn, jobResult.first().getId(), QueryOptions.empty(), token); assertEquals("myCommandLine", jobResult.first().getCommandLine()); @@ -81,7 +81,7 @@ public void updateJobInformation() throws CatalogException { .setId("myJobId")) .setStudy(new JobStudyParam(studyFqn, Arrays.asList(studyFqn2, studyFqn3))); catalogManager.getJobManager().update(studyFqn, jobResult.first().getId(), updateParams, QueryOptions.empty(), token); - jobResult = catalogManager.getJobManager().get(studyFqn, jobResult.first().getId(), QueryOptions.empty(), token); + jobResult = catalogManager.getJobManager().get(organizationId, studyFqn, jobResult.first().getId(), QueryOptions.empty(), token); assertEquals(2, jobResult.first().getStudy().getOthers().size()); System.out.println(jobResult); diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/CohortWSServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/CohortWSServer.java index 82815df680f..c815b1dc8c5 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/CohortWSServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/CohortWSServer.java @@ -140,7 +140,7 @@ public Response infoSample( query.remove(ParamConstants.STUDY_PARAM); List cohortList = getIdList(cohortsStr); - DataResult cohortQueryResult = cohortManager.get(studyStr, cohortList, new Query("deleted", deleted), queryOptions, true, token); + DataResult cohortQueryResult = cohortManager.get(organizationId, studyStr, cohortList, new Query("deleted", deleted), queryOptions, true, token); return createOkResponse(cohortQueryResult); } catch (Exception e) { return createErrorResponse(e); @@ -179,7 +179,7 @@ public Response searchCohorts( @ApiParam(value = ParamConstants.COHORT_RELEASE_DESCRIPTION) @QueryParam(ParamConstants.COHORT_RELEASE_PARAM) String release) { try { query.remove(ParamConstants.STUDY_PARAM); - return createOkResponse(catalogManager.getCohortManager().search(studyStr, query, queryOptions, token)); + return createOkResponse(catalogManager.getCohortManager().search(organizationId, studyStr, query, queryOptions, token)); } catch (CatalogException e) { return createErrorResponse(e); } @@ -209,7 +209,7 @@ public Response distinct( query.remove(ParamConstants.STUDY_PARAM); query.remove(ParamConstants.DISTINCT_FIELD_PARAM); List fields = split(field, ParamConstants.DISTINCT_FIELD_PARAM, true); - return createOkResponse(cohortManager.distinct(studyStr, fields, query, token)); + return createOkResponse(cohortManager.distinct(organizationId, studyStr, fields, query, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -352,7 +352,7 @@ public Response deleteList( @ApiParam(value = "Comma separated list of cohort ids") @PathParam("cohorts") String cohorts) { try { List cohortIds = getIdList(cohorts); - return createOkResponse(cohortManager.delete(studyStr, cohortIds, queryOptions, token)); + return createOkResponse(cohortManager.delete(organizationId, studyStr, cohortIds, queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); } diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/FamilyWSServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/FamilyWSServer.java index 621342e3753..761689ea5da 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/FamilyWSServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/FamilyWSServer.java @@ -16,19 +16,12 @@ package org.opencb.opencga.server.rest; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.ObjectUtils; -import org.apache.commons.lang3.time.StopWatch; import org.opencb.commons.datastore.core.DataResult; import org.opencb.commons.datastore.core.FacetField; import org.opencb.commons.datastore.core.ObjectMap; import org.opencb.commons.datastore.core.QueryOptions; import org.opencb.opencga.analysis.family.FamilyTsvAnnotationLoader; -import org.opencb.opencga.analysis.family.PedigreeGraphAnalysis; -import org.opencb.opencga.analysis.tools.ToolRunner; -import org.opencb.opencga.analysis.variant.circos.CircosAnalysis; -import org.opencb.opencga.analysis.variant.manager.VariantStorageManager; -import org.opencb.opencga.analysis.variant.mutationalSignature.MutationalSignatureAnalysis; import org.opencb.opencga.catalog.db.api.FamilyDBAdaptor; import org.opencb.opencga.catalog.managers.FamilyManager; import org.opencb.opencga.catalog.utils.Constants; @@ -38,19 +31,12 @@ import org.opencb.opencga.core.models.common.TsvAnnotationParams; import org.opencb.opencga.core.models.family.*; import org.opencb.opencga.core.models.job.Job; -import org.opencb.opencga.core.models.variant.MutationalSignatureAnalysisParams; -import org.opencb.opencga.core.response.OpenCGAResult; import org.opencb.opencga.core.tools.annotations.*; -import org.opencb.opencga.storage.core.StorageEngineFactory; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.*; import javax.ws.rs.core.*; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Paths; import java.util.*; /** @@ -88,7 +74,7 @@ public Response infoFamily( query.remove("families"); List familyList = getIdList(familyStr); - DataResult familyQueryResult = familyManager.get(studyStr, familyList, query, queryOptions, true, token); + DataResult familyQueryResult = familyManager.get(organizationId, studyStr, familyList, query, queryOptions, true, token); return createOkResponse(familyQueryResult); } catch (Exception e) { return createErrorResponse(e); @@ -128,7 +114,7 @@ public Response search( @ApiParam(value = ParamConstants.FAMILY_SNAPSHOT_DESCRIPTION) @QueryParam(ParamConstants.FAMILY_SNAPSHOT_PARAM) Integer snapshot) { try { query.remove(ParamConstants.STUDY_PARAM); - return createOkResponse(familyManager.search(studyStr, query, queryOptions, token)); + return createOkResponse(familyManager.search(organizationId, studyStr, query, queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -161,7 +147,7 @@ public Response distinct( query.remove(ParamConstants.STUDY_PARAM); query.remove(ParamConstants.DISTINCT_FIELD_PARAM); List fields = split(field, ParamConstants.DISTINCT_FIELD_PARAM, true); - return createOkResponse(familyManager.distinct(studyStr, fields, query, token)); + return createOkResponse(familyManager.distinct(organizationId, studyStr, fields, query, token)); } catch (Exception e) { return createErrorResponse(e); } diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/FileWSServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/FileWSServer.java index 3c030b9ce64..3e0a840fcfb 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/FileWSServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/FileWSServer.java @@ -123,7 +123,7 @@ public Response info( query.remove("files"); List idList = getIdList(fileStr.replaceAll(":", "/")); - DataResult fileQueryResult = fileManager.get(studyStr, idList, new Query("deleted", deleted), queryOptions, true, token); + DataResult fileQueryResult = fileManager.get(organizationId, studyStr, idList, new Query("deleted", deleted), queryOptions, true, token); return createOkResponse(fileQueryResult); } catch (Exception e) { return createErrorResponse(e); @@ -334,7 +334,7 @@ public Response search( @ApiParam(value = ParamConstants.RELEASE_DESCRIPTION) @QueryParam("release") String release) { try { query.remove(ParamConstants.STUDY_PARAM); - return createOkResponse(fileManager.search(studyStr, query, queryOptions, token)); + return createOkResponse(fileManager.search(organizationId, studyStr, query, queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -375,7 +375,7 @@ public Response distinct( query.remove(ParamConstants.STUDY_PARAM); query.remove(ParamConstants.DISTINCT_FIELD_PARAM); List fields = split(field, ParamConstants.DISTINCT_FIELD_PARAM, true); - return createOkResponse(fileManager.distinct(studyStr, fields, query, token)); + return createOkResponse(fileManager.distinct(organizationId, studyStr, fields, query, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -846,7 +846,7 @@ public Response refresh( @ApiParam(value = ParamConstants.STUDY_DESCRIPTION) @QueryParam(ParamConstants.STUDY_PARAM) String studyStr) { try { ParamUtils.checkIsSingleID(fileIdStr); - File file = fileManager.get(studyStr, fileIdStr, null, token).first(); + File file = fileManager.get(organizationId, studyStr, fileIdStr, null, token).first(); List files; FileUtils catalogFileUtils = new FileUtils(catalogManager); diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/IndividualWSServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/IndividualWSServer.java index ac061670b52..85793f3785a 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/IndividualWSServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/IndividualWSServer.java @@ -100,7 +100,7 @@ public Response infoIndividual( query.remove("individuals"); List individualList = getIdList(individualStr); - DataResult individualQueryResult = individualManager.get(studyStr, individualList, query, queryOptions, true, token); + DataResult individualQueryResult = individualManager.get(organizationId, studyStr, individualList, query, queryOptions, true, token); return createOkResponse(individualQueryResult); } catch (Exception e) { return createErrorResponse(e); @@ -174,7 +174,7 @@ public Response searchIndividuals( @ApiParam(value = ParamConstants.INDIVIDUAL_SNAPSHOT_DESCRIPTION) @QueryParam(ParamConstants.INDIVIDUAL_SNAPSHOT_PARAM) int snapshot) { try { query.remove(ParamConstants.STUDY_PARAM); - return createOkResponse(individualManager.search(studyStr, query, queryOptions, token)); + return createOkResponse(individualManager.search(organizationId, studyStr, query, queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -215,7 +215,7 @@ public Response distinct( query.remove(ParamConstants.STUDY_PARAM); query.remove(ParamConstants.DISTINCT_FIELD_PARAM); List fields = split(field, ParamConstants.DISTINCT_FIELD_PARAM, true); - return createOkResponse(individualManager.distinct(studyStr, fields, query, token)); + return createOkResponse(individualManager.distinct(organizationId, studyStr, fields, query, token)); } catch (Exception e) { return createErrorResponse(e); } diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/JobWSServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/JobWSServer.java index 113be86571a..5d7a7f0090d 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/JobWSServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/JobWSServer.java @@ -67,7 +67,7 @@ public Response createJobPOST( @ApiParam(value = ParamConstants.STUDY_DESCRIPTION) @QueryParam(ParamConstants.STUDY_PARAM) String studyStr, @ApiParam(value = "job", required = true) JobCreateParams inputJob) { try { - OpenCGAResult result = catalogManager.getJobManager().create(studyStr, inputJob.toJob(), queryOptions, token); + OpenCGAResult result = catalogManager.getJobManager().create(organizationId, studyStr, inputJob.toJob(), queryOptions, token); return createOkResponse(result); } catch (Exception e) { return createErrorResponse(e); @@ -124,7 +124,7 @@ public Response info( @ApiParam(value = "Boolean to retrieve deleted jobs", defaultValue = "false") @QueryParam("deleted") boolean deleted) { try { List idList = getIdList(jobIds); - return createOkResponse(catalogManager.getJobManager().get(studyStr, idList, new Query("deleted", deleted), queryOptions, + return createOkResponse(catalogManager.getJobManager().get(organizationId, studyStr, idList, new Query("deleted", deleted), queryOptions, true, token)); } catch (Exception e) { return createErrorResponse(e); @@ -202,7 +202,7 @@ public Response search( @ApiParam(value = ParamConstants.DELETED_DESCRIPTION, defaultValue = "false") @QueryParam("deleted") boolean deleted) { try { query.remove(ParamConstants.STUDY_PARAM); - return createOkResponse(catalogManager.getJobManager().search(studyStr, query, queryOptions, token)); + return createOkResponse(catalogManager.getJobManager().search(organizationId, studyStr, query, queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -236,7 +236,7 @@ public Response distinct( query.remove(ParamConstants.STUDY_PARAM); query.remove(ParamConstants.DISTINCT_FIELD_PARAM); List fields = split(field, ParamConstants.DISTINCT_FIELD_PARAM, true); - return createOkResponse(jobManager.distinct(studyStr, fields, query, token)); + return createOkResponse(jobManager.distinct(organizationId, studyStr, fields, query, token)); } catch (Exception e) { return createErrorResponse(e); } diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/OpenCGAWSServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/OpenCGAWSServer.java index 03a39102d9e..81a1d7c8809 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/OpenCGAWSServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/OpenCGAWSServer.java @@ -888,7 +888,7 @@ protected DataResult submitJobRaw(String toolId, String project, String stu QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.FQN.key()); // Peek any study. The ExecutionDaemon will take care of filling up the rest of studies. List studies = catalogManager.getStudyManager() - .search(project, new Query(), options, token) + .search(organizationId, project, new Query(), options, token) .getResults() .stream() .map(Study::getFqn) diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/PanelWSServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/PanelWSServer.java index 2ec062bb84f..eab640e9b26 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/PanelWSServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/PanelWSServer.java @@ -66,7 +66,7 @@ public Response createPanel( @ApiParam(value = ParamConstants.INCLUDE_RESULT_DESCRIPTION, defaultValue = "false") @QueryParam(ParamConstants.INCLUDE_RESULT_PARAM) boolean includeResult, @ApiParam(name = "body", value = "Panel parameters") PanelCreateParams params) { try { - return createOkResponse(panelManager.create(studyStr, params.toPanel(), queryOptions, token)); + return createOkResponse(panelManager.create(organizationId, studyStr, params.toPanel(), queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -156,7 +156,7 @@ public Response info( query.remove(ParamConstants.STUDY_PARAM); List idList = getIdList(panelStr); - DataResult panelQueryResult = panelManager.get(studyStr, idList, query, queryOptions, true, token); + DataResult panelQueryResult = panelManager.get(organizationId, studyStr, idList, query, queryOptions, true, token); return createOkResponse(panelQueryResult); } catch (Exception e) { return createErrorResponse(e); @@ -198,7 +198,7 @@ public Response search( @ApiParam(value = ParamConstants.PANEL_SNAPSHOT_DESCRIPTION) @QueryParam(ParamConstants.PANEL_SNAPSHOT_PARAM) int snapshot) { try { query.remove(ParamConstants.STUDY_PARAM); - return createOkResponse(panelManager.search(studyStr, query, queryOptions, token)); + return createOkResponse(panelManager.search(organizationId, studyStr, query, queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -232,7 +232,7 @@ public Response distinct( query.remove(ParamConstants.STUDY_PARAM); query.remove(ParamConstants.DISTINCT_FIELD_PARAM); List fields = split(field, ParamConstants.DISTINCT_FIELD_PARAM, true); - return createOkResponse(panelManager.distinct(studyStr, fields, query, token)); + return createOkResponse(panelManager.distinct(organizationId, studyStr, fields, query, token)); } catch (Exception e) { return createErrorResponse(e); } diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/ProjectWSServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/ProjectWSServer.java index 2d8a7d24c7e..db981c36fd4 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/ProjectWSServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/ProjectWSServer.java @@ -67,7 +67,7 @@ public Response createProjectPOST( try { ObjectUtils.defaultIfNull(project, new ProjectCreateParams()); - OpenCGAResult queryResult = catalogManager.getProjectManager().create(project, queryOptions, token); + OpenCGAResult queryResult = catalogManager.getProjectManager().create(organizationId, project, queryOptions, token); return createOkResponse(queryResult); } catch (CatalogException e) { e.printStackTrace(); @@ -89,7 +89,7 @@ public Response info( try { List idList = getIdList(projects); - return createOkResponse(catalogManager.getProjectManager().get(idList, queryOptions, true, token)); + return createOkResponse(catalogManager.getProjectManager().get(organizationId, idList, queryOptions, true, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -126,7 +126,7 @@ public Response searchProjects( query.put(ProjectDBAdaptor.QueryParams.USER_ID.key(), owner); } - DataResult queryResult = catalogManager.getProjectManager().search(query, queryOptions, token); + DataResult queryResult = catalogManager.getProjectManager().search(organizationId, query, queryOptions, token); return createOkResponse(queryResult); } catch (Exception e) { return createErrorResponse(e); @@ -158,7 +158,7 @@ public Response getAggregationStats( List idList = getIdList(projects); Map result = new HashMap<>(); for (String project : idList) { - result.put(project, catalogManager.getProjectManager().facet(project, fileFields, sampleFields, individualFields, + result.put(project, catalogManager.getProjectManager().facet(organizationId, project, fileFields, sampleFields, individualFields, cohortFields, familyFields, jobFields, defaultStats, token)); } return createOkResponse(result); @@ -174,7 +174,7 @@ public Response incrementRelease( @ApiParam(value = ParamConstants.PROJECT_DESCRIPTION, required = true) @PathParam(ParamConstants.PROJECT_PARAM) String projectStr) { try { ParamUtils.checkIsSingleID(projectStr); - return createOkResponse(catalogManager.getProjectManager().incrementRelease(projectStr, token)); + return createOkResponse(catalogManager.getProjectManager().incrementRelease(organizationId, projectStr, token)); } catch (CatalogException e) { e.printStackTrace(); return createErrorResponse(e); @@ -195,7 +195,7 @@ public Response incrementRelease( public Response getAllStudies( @ApiParam(value = ParamConstants.PROJECT_DESCRIPTION, required = true) @PathParam(ParamConstants.PROJECT_PARAM) String project) { try { - return createOkResponse(catalogManager.getStudyManager().search(project, new Query(), queryOptions, token)); + return createOkResponse(catalogManager.getStudyManager().search(organizationId, project, new Query(), queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -234,7 +234,7 @@ public Response updateByPost( params.remove("organism"); } - DataResult result = catalogManager.getProjectManager().update(projectStr, params, queryOptions, token); + DataResult result = catalogManager.getProjectManager().update(organizationId, projectStr, params, queryOptions, token); return createOkResponse(result); } catch (Exception e) { return createErrorResponse(e); diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/SampleWSServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/SampleWSServer.java index 5ab2cc91491..9202b22a048 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/SampleWSServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/SampleWSServer.java @@ -82,7 +82,7 @@ public Response infoSample( query.remove("samples"); List sampleList = getIdList(samplesStr); - DataResult sampleQueryResult = sampleManager.get(studyStr, sampleList, query, queryOptions, true, token); + DataResult sampleQueryResult = sampleManager.get(organizationId, studyStr, sampleList, query, queryOptions, true, token); return createOkResponse(sampleQueryResult); } catch (Exception e) { return createErrorResponse(e); @@ -107,7 +107,7 @@ public Response createSamplePOST( Sample sample = params.toSample(); - return createOkResponse(sampleManager.create(studyStr, sample, queryOptions, token)); + return createOkResponse(sampleManager.create(organizationId, studyStr, sample, queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -121,7 +121,7 @@ public Response loadSamples( @ApiParam(value = "file", required = true) @QueryParam("file") String fileStr, @ApiParam(value = "variableSet", required = false) @QueryParam("variableSet") String variableSet) { try { - File pedigreeFile = catalogManager.getFileManager().get(studyStr, fileStr, null, token).first(); + File pedigreeFile = catalogManager.getFileManager().get(organizationId, studyStr, fileStr, null, token).first(); CatalogSampleAnnotationsLoader loader = new CatalogSampleAnnotationsLoader(catalogManager); DataResult sampleQueryResult = loader.loadSampleAnnotations(pedigreeFile, variableSet, token); return createOkResponse(sampleQueryResult); @@ -192,7 +192,7 @@ public Response search( @ApiParam(value = ParamConstants.SAMPLE_VARIANT_STATS_CONSEQUENCE_TYPE_COUNT_DESCRIPTION) @QueryParam(ParamConstants.SAMPLE_VARIANT_STATS_CONSEQUENCE_TYPE_COUNT_PARAM) String consequenceTypeCount) { try { query.remove(ParamConstants.STUDY_PARAM); - return createOkResponse(sampleManager.search(studyStr, query, queryOptions, token)); + return createOkResponse(sampleManager.search(organizationId, studyStr, query, queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -247,7 +247,7 @@ public Response distinct( query.remove(ParamConstants.STUDY_PARAM); query.remove(ParamConstants.DISTINCT_FIELD_PARAM); List fields = split(field, ParamConstants.DISTINCT_FIELD_PARAM, true); - return createOkResponse(sampleManager.distinct(studyStr, fields, query, token)); + return createOkResponse(sampleManager.distinct(organizationId, studyStr, fields, query, token)); } catch (Exception e) { return createErrorResponse(e); } diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/StudyWSServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/StudyWSServer.java index 0db3fae08ad..46013e02ebf 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/StudyWSServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/StudyWSServer.java @@ -77,7 +77,7 @@ public Response createStudyPOST( @ApiParam(value = ParamConstants.INCLUDE_RESULT_DESCRIPTION, defaultValue = "false") @QueryParam(ParamConstants.INCLUDE_RESULT_PARAM) boolean includeResult, @ApiParam(value = ParamConstants.STUDY_PARAM, required = true) StudyCreateParams study) { try { - return createOkResponse(catalogManager.getStudyManager().create(project, study != null ? study.toStudy() : new Study(), + return createOkResponse(catalogManager.getStudyManager().create(organizationId, project, study != null ? study.toStudy() : new Study(), queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); @@ -121,7 +121,7 @@ public Response getAllStudies( } query.remove(ParamConstants.PROJECT_PARAM); - DataResult queryResult = catalogManager.getStudyManager().search(projectStr, query, queryOptions, token); + DataResult queryResult = catalogManager.getStudyManager().search(organizationId, projectStr, query, queryOptions, token); return createOkResponse(queryResult); } catch (Exception e) { return createErrorResponse(e); @@ -144,7 +144,7 @@ public Response updateByPost( @ApiParam(value = "JSON containing the params to be updated.", required = true) StudyUpdateParams updateParams) { try { ObjectUtils.defaultIfNull(updateParams, new StudyUpdateParams()); - DataResult queryResult = catalogManager.getStudyManager().update(studyStr, updateParams, queryOptions, token); + DataResult queryResult = catalogManager.getStudyManager().update(organizationId, studyStr, updateParams, queryOptions, token); return createOkResponse(queryResult); } catch (Exception e) { return createErrorResponse(e); @@ -165,7 +165,7 @@ public Response info( required = true) @PathParam(ParamConstants.STUDIES_PARAM) String studies) { try { List idList = getIdList(studies); - return createOkResponse(studyManager.get(idList, queryOptions, true, token)); + return createOkResponse(studyManager.get(organizationId, idList, queryOptions, true, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -195,7 +195,7 @@ public Response getGroups( @ApiParam(value = "Group id. If provided, it will only fetch information for the provided group.") @QueryParam("id") String groupId, @ApiParam(value = ParamConstants.SILENT_DESCRIPTION, defaultValue = "false") @QueryParam(Constants.SILENT) boolean silent) { try { - return createOkResponse(catalogManager.getStudyManager().getCustomGroups(studyStr, groupId, token)); + return createOkResponse(catalogManager.getStudyManager().getCustomGroups(organizationId, studyStr, groupId, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -215,9 +215,9 @@ public Response updateGroupPOST( } OpenCGAResult group; if (action == ParamUtils.AddRemoveAction.ADD) { - group = catalogManager.getStudyManager().createGroup(studyStr, params.getId(), params.getUsers(), token); + group = catalogManager.getStudyManager().createGroup(organizationId, studyStr, params.getId(), params.getUsers(), token); } else { - group = catalogManager.getStudyManager().deleteGroup(studyStr, params.getId(), token); + group = catalogManager.getStudyManager().deleteGroup(organizationId, studyStr, params.getId(), token); } return createOkResponse(group); } catch (Exception e) { @@ -239,7 +239,7 @@ public Response updateUsersFromGroupPOST( action = ParamUtils.BasicUpdateAction.ADD; } - return createOkResponse(catalogManager.getStudyManager().updateGroup(studyStr, groupId, action, updateParams, token)); + return createOkResponse(catalogManager.getStudyManager().updateGroup(organizationId, studyStr, groupId, action, updateParams, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -254,7 +254,7 @@ public Response getPermissionRules( @QueryParam("entity") Enums.Entity entity) { try { ParamUtils.checkIsSingleID(studyStr); - return createOkResponse(catalogManager.getStudyManager().getPermissionRules(studyStr, entity, token)); + return createOkResponse(catalogManager.getStudyManager().getPermissionRules(organizationId, studyStr, entity, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -279,7 +279,7 @@ public Response updatePermissionRules( action = Enums.PermissionRuleAction.ADD; } if (action == Enums.PermissionRuleAction.ADD) { - return createOkResponse(catalogManager.getStudyManager().createPermissionRule(studyStr, entity, params, token)); + return createOkResponse(catalogManager.getStudyManager().createPermissionRule(organizationId, studyStr, entity, params, token)); } else { PermissionRule.DeleteAction deleteAction; switch (action) { @@ -294,7 +294,7 @@ public Response updatePermissionRules( deleteAction = PermissionRule.DeleteAction.REMOVE; break; } - catalogManager.getStudyManager().markDeletedPermissionRule(studyStr, entity, params.getId(), deleteAction, token); + catalogManager.getStudyManager().markDeletedPermissionRule(organizationId, studyStr, entity, params.getId(), deleteAction, token); return createOkResponse(DataResult.empty()); } } catch (Exception e) { @@ -313,7 +313,7 @@ public Response getAcls( return run(() -> { List idList = getIdList(studiesStr); - return studyManager.getAcls(idList, member, silent, token); + return studyManager.getAcls(organizationId, idList, member, silent, token); }); } @@ -329,7 +329,7 @@ public Response updateAcl( ObjectUtils.defaultIfNull(params, new StudyAclUpdateParams()); StudyAclParams aclParams = new StudyAclParams(params.getPermissions(), params.getTemplate()); List idList = getIdList(params.getStudy(), false); - return createOkResponse(studyManager.updateAcl(idList, memberId, aclParams, action, token)); + return createOkResponse(studyManager.updateAcl(organizationId, idList, memberId, aclParams, action, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -347,7 +347,7 @@ public Response getVariableSets( DataResult queryResult; if (StringUtils.isEmpty(variableSetId)) { QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key()); - DataResult studyQueryResult = catalogManager.getStudyManager().get(studyStr, options, token); + DataResult studyQueryResult = catalogManager.getStudyManager().get(organizationId, studyStr, options, token); if (studyQueryResult.getNumResults() == 1) { queryResult = new DataResult<>(studyQueryResult.getTime(), studyQueryResult.getEvents(), @@ -357,7 +357,7 @@ public Response getVariableSets( queryResult = DataResult.empty(); } } else { - queryResult = catalogManager.getStudyManager().getVariableSet(studyStr, variableSetId, queryOptions, token); + queryResult = catalogManager.getStudyManager().getVariableSet(organizationId, studyStr, variableSetId, queryOptions, token); } return createOkResponse(queryResult); } catch (Exception e) { @@ -391,7 +391,7 @@ public Response getAggregationStats( List idList = getIdList(studies); Map result = new HashMap<>(); for (String study : idList) { - result.put(study, catalogManager.getStudyManager().facet(study, fileFields, sampleFields, individualFields, cohortFields, + result.put(study, catalogManager.getStudyManager().facet(organizationId, study, fileFields, sampleFields, individualFields, cohortFields, familyFields, jobFields, defaultStats, token)); } return createOkResponse(result); @@ -423,12 +423,12 @@ public Response createOrRemoveVariableSets( fixVariable(variable); } - queryResult = catalogManager.getStudyManager().createVariableSet(studyStr, params.getId(), params.getName(), + queryResult = catalogManager.getStudyManager().createVariableSet(organizationId, studyStr, params.getId(), params.getName(), params.getUnique(), params.getConfidential(), params.getDescription(), null, params.getVariables(), params.getEntities(), token); } else { boolean force = ParamUtils.AddRemoveForceRemoveAction.FORCE_REMOVE.equals(action); - queryResult = catalogManager.getStudyManager().deleteVariableSet(studyStr, params.getId(), force, token); + queryResult = catalogManager.getStudyManager().deleteVariableSet(organizationId, studyStr, params.getId(), force, token); } return createOkResponse(queryResult); } catch (Exception e) { @@ -465,9 +465,9 @@ public Response updateVariablesFromVariableSet( DataResult queryResult; if (action == ParamUtils.AddRemoveAction.ADD) { - queryResult = catalogManager.getStudyManager().addFieldToVariableSet(studyStr, variableSetId, variable, token); + queryResult = catalogManager.getStudyManager().addFieldToVariableSet(organizationId, studyStr, variableSetId, variable, token); } else { - queryResult = catalogManager.getStudyManager().removeFieldFromVariableSet(studyStr, variableSetId, variable.getId(), + queryResult = catalogManager.getStudyManager().removeFieldFromVariableSet(organizationId, studyStr, variableSetId, variable.getId(), token); } return createOkResponse(queryResult); @@ -520,7 +520,7 @@ public Response upload( @FormDataParam("file") FormDataContentDisposition fileMetaData, @ApiParam(value = ParamConstants.STUDY_DESCRIPTION) @PathParam(ParamConstants.STUDY_PARAM) String studyStr) { try { - return createOkResponse(studyManager.uploadTemplate(studyStr, fileMetaData.getFileName(), fileInputStream, token)); + return createOkResponse(studyManager.uploadTemplate(organizationId, studyStr, fileMetaData.getFileName(), fileInputStream, token)); } catch (Exception e) { return createErrorResponse("Upload template file", e.getMessage()); } @@ -533,7 +533,7 @@ public Response delete( @ApiParam(value = ParamConstants.STUDY_DESCRIPTION) @QueryParam(ParamConstants.STUDY_PARAM) String studyStr, @ApiParam(value = "Template id") @PathParam("templateId") String templateId) { try { - return createOkResponse(studyManager.deleteTemplate(studyStr, templateId, token)); + return createOkResponse(studyManager.deleteTemplate(organizationId, studyStr, templateId, token)); } catch (Exception e) { return createErrorResponse(e); } diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/UserWSServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/UserWSServer.java index 8b8850b3ebd..b330d115a98 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/UserWSServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/UserWSServer.java @@ -204,7 +204,7 @@ public Response getAllProjects(@ApiParam(value = ParamConstants.USER_DESCRIPTION ParamUtils.checkIsSingleID(userId); query.remove("user"); query.put(ProjectDBAdaptor.QueryParams.USER_ID.key(), userId); - return createOkResponse(catalogManager.getProjectManager().search(query, queryOptions, token)); + return createOkResponse(catalogManager.getProjectManager().search(organizationId, query, queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); } diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/analysis/ClinicalWebService.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/analysis/ClinicalWebService.java index 7906588ad23..84787101eac 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/analysis/ClinicalWebService.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/analysis/ClinicalWebService.java @@ -129,7 +129,7 @@ private VariantStorageManager getVariantStorageManager() { public Response clinicalConfigure( @ApiParam(value = ParamConstants.STUDY_DESCRIPTION) @QueryParam(ParamConstants.STUDY_PARAM) String study, @ApiParam(value = "Configuration params to update") ClinicalAnalysisStudyConfiguration params) { - return run(() -> clinicalManager.configureStudy(study, params, token)); + return run(() -> clinicalManager.configureStudy(organizationId, study, params, token)); } @POST @@ -150,7 +150,7 @@ public Response create( @ApiParam(name = "body", value = "JSON containing clinical analysis information", required = true) ClinicalAnalysisCreateParams params) { try { - return createOkResponse(clinicalManager.create(studyStr, params.toClinicalAnalysis(), skipCreateInterpretation, queryOptions, + return createOkResponse(clinicalManager.create(organizationId, studyStr, params.toClinicalAnalysis(), skipCreateInterpretation, queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); @@ -185,7 +185,7 @@ public Response update( ClinicalAnalysisUpdateParams params) { try { query.remove(ParamConstants.STUDY_PARAM); - return createOkResponse(clinicalManager.update(studyStr, query, params, true, queryOptions, token)); + return createOkResponse(clinicalManager.update(organizationId, studyStr, query, params, true, queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -235,7 +235,7 @@ public Response update( actionMap.put(ClinicalAnalysisDBAdaptor.QueryParams.PANELS.key(), panelsAction); queryOptions.put(Constants.ACTIONS, actionMap); - return createOkResponse(clinicalManager.update(studyStr, getIdList(clinicalAnalysisStr), params, true, queryOptions, token)); + return createOkResponse(clinicalManager.update(organizationId, studyStr, getIdList(clinicalAnalysisStr), params, true, queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -249,7 +249,7 @@ public Response delete( @ApiParam(value = "Force deletion if the ClinicalAnalysis contains interpretations or is locked", defaultValue = "false") @QueryParam(Constants.FORCE) boolean force, @ApiParam(value = ParamConstants.CLINICAL_ANALYSES_DESCRIPTION) @PathParam(ParamConstants.CLINICAL_ANALYSES_PARAM) String clinicalAnalyses) { try { - return createOkResponse(clinicalManager.delete(studyStr, getIdList(clinicalAnalyses), queryOptions, true, token)); + return createOkResponse(clinicalManager.delete(organizationId, studyStr, getIdList(clinicalAnalyses), queryOptions, true, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -274,7 +274,7 @@ public Response info( query.remove("clinicalAnalysis"); List analysisList = getIdList(clinicalAnalysisStr); - DataResult analysisResult = clinicalManager.get(studyStr, analysisList, queryOptions, true, token); + DataResult analysisResult = clinicalManager.get(organizationId, studyStr, analysisList, queryOptions, true, token); return createOkResponse(analysisResult); } catch (Exception e) { return createErrorResponse(e); @@ -320,7 +320,7 @@ public Response search( @ApiParam(value = ParamConstants.DELETED_DESCRIPTION) @QueryParam(ParamConstants.DELETED_PARAM) boolean deleted) { try { query.remove(ParamConstants.STUDY_PARAM); - DataResult queryResult = clinicalManager.search(studyStr, query, queryOptions, token); + DataResult queryResult = clinicalManager.search(organizationId, studyStr, query, queryOptions, token); return createOkResponse(queryResult); } catch (Exception e) { return createErrorResponse(e); @@ -362,7 +362,7 @@ public Response distinct( query.remove(ParamConstants.STUDY_PARAM); query.remove(ParamConstants.DISTINCT_FIELD_PARAM); List fields = split(field, ParamConstants.DISTINCT_FIELD_PARAM, true); - return createOkResponse(clinicalManager.distinct(studyStr, fields, query, token)); + return createOkResponse(clinicalManager.distinct(organizationId, studyStr, fields, query, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -381,7 +381,7 @@ public Response getAcls( defaultValue = "false") @QueryParam(Constants.SILENT) boolean silent) { try { List idList = getIdList(clinicalAnalysis); - return createOkResponse(clinicalManager.getAcls(studyStr, idList, member, silent, token)); + return createOkResponse(clinicalManager.getAcls(organizationId, studyStr, idList, member, silent, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -400,7 +400,7 @@ public Response updateAcl( params = ObjectUtils.defaultIfNull(params, new ClinicalAnalysisAclUpdateParams()); AclParams clinicalAclParams = new AclParams(params.getPermissions()); List idList = getIdList(params.getClinicalAnalysis()); - return createOkResponse(clinicalManager.updateAcl(studyStr, idList, memberId, clinicalAclParams, action, propagate, token)); + return createOkResponse(clinicalManager.updateAcl(organizationId, studyStr, idList, memberId, clinicalAclParams, action, propagate, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -609,7 +609,7 @@ public Response interpretationInfo( query.remove("interpretations"); List interpretationList = getIdList(interpretations); - DataResult interpretationOpenCGAResult = catalogInterpretationManager.get(studyStr, interpretationList, query, queryOptions, true, token); + DataResult interpretationOpenCGAResult = catalogInterpretationManager.get(organizationId, studyStr, interpretationList, query, queryOptions, true, token); return createOkResponse(interpretationOpenCGAResult); } catch (Exception e) { return createErrorResponse(e); @@ -650,7 +650,7 @@ public Response interpretationSearch( query.putIfNotEmpty(ParamConstants.INTERPRETATION_METHOD_NAME_PARAM, clinicalAnalyst); query.remove("analyst"); query.remove("methods"); - return createOkResponse(catalogInterpretationManager.search(studyStr, query, queryOptions, token)); + return createOkResponse(catalogInterpretationManager.search(organizationId, studyStr, query, queryOptions, token)); } catch (Exception e) { return createErrorResponse(e); } @@ -688,7 +688,7 @@ public Response interpretationDistinct( query.remove("methods"); List fields = split(field, ParamConstants.DISTINCT_FIELD_PARAM, true); - return createOkResponse(catalogInterpretationManager.distinct(studyStr, fields, query, token)); + return createOkResponse(catalogInterpretationManager.distinct(organizationId, studyStr, fields, query, token)); } catch (Exception e) { return createErrorResponse(e); } diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/analysis/VariantWebService.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/analysis/VariantWebService.java index 6ac26bbb92e..2d0e475d2e1 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/analysis/VariantWebService.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/analysis/VariantWebService.java @@ -27,7 +27,6 @@ import org.opencb.biodata.models.variant.metadata.SampleVariantStats; import org.opencb.biodata.models.variant.metadata.VariantMetadata; import org.opencb.biodata.models.variant.metadata.VariantSetStats; -import org.opencb.commons.annotations.DataField; import org.opencb.commons.datastore.core.*; import org.opencb.opencga.analysis.AnalysisUtils; import org.opencb.opencga.analysis.family.qc.FamilyQcAnalysis; @@ -750,7 +749,7 @@ public Response cohortStatsQuery(@ApiParam(value = ParamConstants.STUDY_PARAM) @ ParamUtils.checkParameter(cohort, "cohort"); ParamUtils.checkParameter(studyStr, ParamConstants.STUDY_PARAM); OpenCGAResult result = catalogManager.getCohortManager() - .get(studyStr, getIdList(cohort), new QueryOptions(), token); + .get(organizationId, studyStr, getIdList(cohort), new QueryOptions(), token); List stats = new ArrayList<>(result.getNumResults()); for (Cohort c : result.getResults()) { @@ -1156,14 +1155,14 @@ public Response individualQcRun( OpenCGAResult fileResult; Query query = new Query(FileDBAdaptor.QueryParams.ID.key(), catalogBamFile.getId() + ".bw"); - fileResult = catalogManager.getFileManager().search(study, query, QueryOptions.empty(), token); + fileResult = catalogManager.getFileManager().search(organizationId, study, query, QueryOptions.empty(), token); Job deeptoolsJob = null; if (fileResult.getNumResults() == 0) { // Coverage file does not exit, a job must be submitted to create the .bw file // but first, check if .bai (bam index file) exist query = new Query(FileDBAdaptor.QueryParams.ID.key(), catalogBamFile.getId() + ".bai"); - fileResult = catalogManager.getFileManager().search(study, query, QueryOptions.empty(), token); + fileResult = catalogManager.getFileManager().search(organizationId, study, query, QueryOptions.empty(), token); Job samtoolsJob = null; if (fileResult.getNumResults() == 0) { diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/fileupload/FileUploadServlet.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/fileupload/FileUploadServlet.java index 2aefadef49b..aedfae2e2e7 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/fileupload/FileUploadServlet.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/fileupload/FileUploadServlet.java @@ -84,7 +84,7 @@ protected void doPost(HttpServletRequest request, String path = request.getHeader("relativeFilePath"); logger.info("Trying to update file for study " + studyId); CatalogManager catalogManager = new CatalogManager(OpenCGAWSServer.getConfiguration()); - catalogManager.getStudyManager().get(studyId, QueryOptions.empty(), token); + catalogManager.getStudyManager().get(organizationId, studyId, QueryOptions.empty(), token); // Temporal folder Path temp = Files.createTempDirectory("temp"); diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/ga4gh/Ga4ghWSServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/ga4gh/Ga4ghWSServer.java index fe91a804817..c8f4b2533df 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/ga4gh/Ga4ghWSServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/ga4gh/Ga4ghWSServer.java @@ -190,12 +190,12 @@ public Response getHtsget( @ApiParam(value = "The end position of the range on the reference, 0-based, exclusive.") @QueryParam("end") int end, @ApiParam(value = "Reference genome.") @QueryParam("referenceGenome") String referenceGenome) { try { - File file = catalogManager.getFileManager().get(studyStr, fileIdStr, FileManager.EXCLUDE_FILE_ATTRIBUTES, token).first(); + File file = catalogManager.getFileManager().get(organizationId, studyStr, fileIdStr, FileManager.EXCLUDE_FILE_ATTRIBUTES, token).first(); java.nio.file.Path referencePath = null; if (file.getFormat() == File.Format.CRAM) { if (org.apache.commons.lang3.StringUtils.isNotEmpty(referenceGenome)) { - referencePath = Paths.get(catalogManager.getFileManager().get(studyStr, referenceGenome, FileManager.INCLUDE_FILE_URI_PATH, token).first().getUri().getPath()); + referencePath = Paths.get(catalogManager.getFileManager().get(organizationId, studyStr, referenceGenome, FileManager.INCLUDE_FILE_URI_PATH, token).first().getUri().getPath()); } else if (ListUtils.isNotEmpty(file.getRelatedFiles())) { for (FileRelatedFile relatedFile : file.getRelatedFiles()) { if (relatedFile.getRelation() == FileRelatedFile.Relation.REFERENCE_GENOME) { @@ -207,7 +207,7 @@ public Response getHtsget( if (referencePath == null) { // Look for a reference genome in the study Query referenceQuery = new Query(FileDBAdaptor.QueryParams.BIOFORMAT.key(), File.Bioformat.REFERENCE_GENOME); - DataResult fileDataResult = catalogManager.getFileManager().search(studyStr, referenceQuery, FileManager.INCLUDE_FILE_URI_PATH, token); + DataResult fileDataResult = catalogManager.getFileManager().search(organizationId, studyStr, referenceQuery, FileManager.INCLUDE_FILE_URI_PATH, token); if (fileDataResult.getNumResults() == 0 || fileDataResult.getNumResults() > 1) { throw new CatalogException("Missing referenceGenome field for CRAM file"); } diff --git a/opencga-server/src/main/java/org/opencb/opencga/server/rest/utils/FileRangesWSServer.java b/opencga-server/src/main/java/org/opencb/opencga/server/rest/utils/FileRangesWSServer.java index 4f62e142dff..c5f402d7f38 100644 --- a/opencga-server/src/main/java/org/opencb/opencga/server/rest/utils/FileRangesWSServer.java +++ b/opencga-server/src/main/java/org/opencb/opencga/server/rest/utils/FileRangesWSServer.java @@ -56,7 +56,7 @@ public Response getRanges(@Context HttpHeaders headers, @QueryParam(ParamConstants.STUDY_PARAM) String studyStr) { try { - DataResult queryResult = catalogManager.getFileManager().get(studyStr, fileIdStr, this.queryOptions, token); + DataResult queryResult = catalogManager.getFileManager().get(organizationId, studyStr, fileIdStr, this.queryOptions, token); File file = queryResult.getResults().get(0); List rangeList = headers.getRequestHeader("range"); diff --git a/opencga-server/src/test/java/org/opencb/opencga/server/rest/FileWSServerTest.java b/opencga-server/src/test/java/org/opencb/opencga/server/rest/FileWSServerTest.java index f061eae49d1..3b21429f7f3 100644 --- a/opencga-server/src/test/java/org/opencb/opencga/server/rest/FileWSServerTest.java +++ b/opencga-server/src/test/java/org/opencb/opencga/server/rest/FileWSServerTest.java @@ -174,7 +174,7 @@ public void linkFileTest2() throws IOException { @Test public void updateFilePOST() throws Exception { - File file = OpenCGAWSServer.catalogManager.getFileManager().search(String.valueOf(studyId), new Query(FileDBAdaptor.QueryParams.TYPE + File file = OpenCGAWSServer.catalogManager.getFileManager().search(organizationId, String.valueOf(studyId), new Query(FileDBAdaptor.QueryParams.TYPE .key(), "FILE"), new QueryOptions(), sessionId).first(); ObjectMap params = new ObjectMap(FileDBAdaptor.QueryParams.DESCRIPTION.key(), "Change description"); diff --git a/opencga-server/src/test/java/org/opencb/opencga/server/rest/IndividualWSServerTest.java b/opencga-server/src/test/java/org/opencb/opencga/server/rest/IndividualWSServerTest.java index 499d68b5e62..cddb58fe1be 100644 --- a/opencga-server/src/test/java/org/opencb/opencga/server/rest/IndividualWSServerTest.java +++ b/opencga-server/src/test/java/org/opencb/opencga/server/rest/IndividualWSServerTest.java @@ -94,13 +94,13 @@ static public void shutdownServer() throws Exception { public void init() throws Exception { webTarget = serverTestUtils.getWebTarget(); sessionId = OpenCGAWSServer.catalogManager.getUserManager().login("user", TestParamConstants.PASSWORD).getToken(); - in1 = OpenCGAWSServer.catalogManager.getIndividualManager().create(studyId, new Individual().setId("in1"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), + in1 = OpenCGAWSServer.catalogManager.getIndividualManager().create(organizationId, studyId, new Individual().setId("in1"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first().getId(); - in2 = OpenCGAWSServer.catalogManager.getIndividualManager().create(studyId, new Individual().setId("in2"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first() + in2 = OpenCGAWSServer.catalogManager.getIndividualManager().create(organizationId, studyId, new Individual().setId("in2"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first() .getId(); - in3 = OpenCGAWSServer.catalogManager.getIndividualManager().create(studyId, new Individual().setId("in3"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first() + in3 = OpenCGAWSServer.catalogManager.getIndividualManager().create(organizationId, studyId, new Individual().setId("in3"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first() .getId(); - in4 = OpenCGAWSServer.catalogManager.getIndividualManager().create(studyId, new Individual().setId("in4"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first() + in4 = OpenCGAWSServer.catalogManager.getIndividualManager().create(organizationId, studyId, new Individual().setId("in4"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first() .getId(); } @@ -222,10 +222,10 @@ public void updateIndividualSamplesTest() throws IOException, CatalogException { new Sample().setId("sample1"), new Sample().setId("sample2") )); - OpenCGAWSServer.catalogManager.getIndividualManager().create(String.valueOf(studyId), individual, null, sessionId); + OpenCGAWSServer.catalogManager.getIndividualManager().create(organizationId, String.valueOf(studyId), individual, null, sessionId); Sample sample = new Sample().setId("sample3"); - OpenCGAWSServer.catalogManager.getSampleManager().create(String.valueOf(studyId), sample, null, sessionId); + OpenCGAWSServer.catalogManager.getSampleManager().create(organizationId, String.valueOf(studyId), sample, null, sessionId); // Update the individual information to contain a third sample as well ObjectMap params = new ObjectMap() @@ -258,7 +258,7 @@ public void deleteIndividualTest() throws IOException, CatalogException { // FIXME: This will have to return an exception once we improve the delete behaviour // thrown.expect(CatalogException.class); - OpenCGAWSServer.catalogManager.getIndividualManager().get(null, String.valueOf((Long) individual.getUid()), null, sessionId); + OpenCGAWSServer.catalogManager.getIndividualManager().get(organizationId, null, String.valueOf((Long) individual.getUid()), null, sessionId); } diff --git a/opencga-server/src/test/java/org/opencb/opencga/server/rest/SampleWSServerTest.java b/opencga-server/src/test/java/org/opencb/opencga/server/rest/SampleWSServerTest.java index 1e70b03aff1..05abaf4a28e 100644 --- a/opencga-server/src/test/java/org/opencb/opencga/server/rest/SampleWSServerTest.java +++ b/opencga-server/src/test/java/org/opencb/opencga/server/rest/SampleWSServerTest.java @@ -24,8 +24,6 @@ import org.opencb.opencga.TestParamConstants; import org.opencb.opencga.catalog.db.api.SampleDBAdaptor; import org.opencb.opencga.core.api.ParamConstants; -import org.opencb.opencga.core.models.cohort.Cohort; -import org.opencb.opencga.core.models.common.Enums; import org.opencb.opencga.core.models.individual.Individual; import org.opencb.opencga.core.models.sample.Sample; import org.opencb.opencga.core.testclassification.duration.MediumTests; @@ -68,12 +66,12 @@ public void init() throws Exception { // serverTestUtils.setUp(); webTarget = serverTestUtils.getWebTarget(); sessionId = OpenCGAWSServer.catalogManager.getUserManager().login("user", TestParamConstants.PASSWORD).getToken(); - in1 = OpenCGAWSServer.catalogManager.getIndividualManager().create(studyId, new Individual().setId("in1"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), + in1 = OpenCGAWSServer.catalogManager.getIndividualManager().create(organizationId, studyId, new Individual().setId("in1"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first().getUid(); - s1 = OpenCGAWSServer.catalogManager.getSampleManager().create(studyId, new Sample().setId("s1"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first().getUid(); - s2 = OpenCGAWSServer.catalogManager.getSampleManager().create(studyId, new Sample().setId("s2"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first().getUid(); - s3 = OpenCGAWSServer.catalogManager.getSampleManager().create(studyId, new Sample().setId("s3"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first().getUid(); - s4 = OpenCGAWSServer.catalogManager.getSampleManager().create(studyId, new Sample().setId("s4"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first().getUid(); + s1 = OpenCGAWSServer.catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("s1"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first().getUid(); + s2 = OpenCGAWSServer.catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("s2"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first().getUid(); + s3 = OpenCGAWSServer.catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("s3"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first().getUid(); + s4 = OpenCGAWSServer.catalogManager.getSampleManager().create(organizationId, studyId, new Sample().setId("s4"), new QueryOptions(ParamConstants.INCLUDE_RESULT_PARAM, true), sessionId).first().getUid(); } @After diff --git a/opencga-server/src/test/java/org/opencb/opencga/server/rest/VariableSetWSServerTest.java b/opencga-server/src/test/java/org/opencb/opencga/server/rest/VariableSetWSServerTest.java index 177a529004a..cfc35c0e49f 100644 --- a/opencga-server/src/test/java/org/opencb/opencga/server/rest/VariableSetWSServerTest.java +++ b/opencga-server/src/test/java/org/opencb/opencga/server/rest/VariableSetWSServerTest.java @@ -74,7 +74,7 @@ static public void shutdownServer() throws Exception { public void init() throws Exception { // serverTestUtils.setUp(); webTarget = serverTestUtils.getWebTarget(); - variableSetId = OpenCGAWSServer.catalogManager.getStudyManager().searchVariableSets(studyId, null,null, sessionId) + variableSetId = OpenCGAWSServer.catalogManager.getStudyManager().searchVariableSets(organizationId, studyId, null,null, sessionId) .first().getUid(); }