Skip to content

Commit

Permalink
catalog: add organizationId to some managers, #TASK-4389
Browse files Browse the repository at this point in the history
  • Loading branch information
pfurio committed Aug 28, 2023
1 parent 91b5aed commit 1de04f2
Show file tree
Hide file tree
Showing 174 changed files with 3,185 additions and 3,143 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -127,7 +124,7 @@ public static Map<String, Map<String, Float>> 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<Job> result = jobManager.search(study, query, QueryOptions.empty(), token);
OpenCGAResult<Job> result = jobManager.search(organizationId, study, query, QueryOptions.empty(), token);
Job job = result.first();
String status = job.getInternal().getStatus().getId();

Expand All @@ -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());
Expand All @@ -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<Job> result = jobManager.search(study, query, QueryOptions.empty(), token);
OpenCGAResult<Job> 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 + "'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ protected StudyInfo getStudyInfo(@Nullable String studyIdStr, List<String> 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<File> files;
if (fileIdStrs.isEmpty()) {
files = Collections.emptyList();
} else {
DataResult<File> queryResult = catalogManager.getFileManager().get(studyIdStr, fileIdStrs, null, sessionId);
DataResult<File> queryResult = catalogManager.getFileManager().get(organizationId, studyIdStr, fileIdStrs, null, sessionId);
files = queryResult.getResults();
}
List<FileInfo> fileInfos = new ArrayList<>(fileIdStrs.size());
Expand All @@ -130,12 +130,12 @@ protected StudyInfo getStudyInfo(@Nullable String studyIdStr, List<String> 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<File.Bioformat, DataStore> dataStores = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected void check() throws Exception {
OpenCGAResult<File> 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);
}
Expand Down Expand Up @@ -143,7 +143,7 @@ protected void run() throws Exception {
Path outputCatalogPath = Paths.get(bamCatalogFile.getPath()).getParent().resolve(outputPath.getFileName());
OpenCGAResult<File> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected void check() throws Exception {

OpenCGAResult<File> 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);
}
Expand Down Expand Up @@ -96,7 +96,7 @@ protected void run() throws Exception {
Path outputCatalogPath = Paths.get(inputCatalogFile.getPath()).getParent().resolve(outputPath.getFileName());
OpenCGAResult<File> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public OpenCGAResult<GeneCoverageStats> coverageStats(String studyIdStr, String

// Get species and assembly from catalog
OpenCGAResult<Project> 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) {
Expand Down Expand Up @@ -439,7 +439,7 @@ public List<Region> mergeRegions(List<Region> regions, List<String> genes, boole

// Get species and assembly from catalog
OpenCGAResult<Project> 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);
Expand Down Expand Up @@ -537,7 +537,7 @@ public Map<String, List<Region>> getExonRegionsPerTranscript(String geneName, Ce
}

private File extractAlignmentOrCoverageFile(String studyIdStr, String fileIdStr, String sessionId) throws CatalogException {
OpenCGAResult<File> fileResult = catalogManager.getFileManager().get(studyIdStr, fileIdStr, QueryOptions.empty(), sessionId);
OpenCGAResult<File> fileResult = catalogManager.getFileManager().get(organizationId, studyIdStr, fileIdStr, QueryOptions.empty(), sessionId);
if (fileResult.getNumResults() == 0) {
throw new CatalogException("File " + fileIdStr + " not found");
}
Expand Down Expand Up @@ -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<Study> studyResult = catalogManager.getStudyManager().get(String.valueOf((Long) studyId), studyOptions, sessionId);
OpenCGAResult<Study> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<File> fileResult = catalogManager.getFileManager().search(getStudy(), query, QueryOptions.empty(), token);
OpenCGAResult<File> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<File> fileResult = catalogManager.getFileManager().search(getStudy(), query, QueryOptions.empty(), token);
OpenCGAResult<File> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -241,7 +240,7 @@ private boolean waitFor(String jobId) throws ToolException {
Query query = new Query("id", jobId);
OpenCGAResult<Job> 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());
}
Expand All @@ -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());
Expand All @@ -269,7 +268,7 @@ private Job getJob(String jobId) {
Job job = null;
try {
Query query = new Query("id", jobId);
OpenCGAResult<Job> result = catalogManager.getJobManager().search(study, query, QueryOptions.empty(), token);
OpenCGAResult<Job> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<File> fileResult = catalogManager.getFileManager().search(getStudy(), query, QueryOptions.empty(), token);
OpenCGAResult<File> 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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ public void setStudy(String study) {
protected void check() throws Exception {
String userId = catalogManager.getUserManager().getUserId(token);

OpenCGAResult<File> fileResult = catalogManager.getFileManager().get(study, path, FileManager.INCLUDE_FILE_URI_PATH, token);
OpenCGAResult<File> 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<VariableSet> variableSetResult = catalogManager.getStudyManager().getVariableSet(study, variableSetId,
OpenCGAResult<VariableSet> variableSetResult = catalogManager.getStudyManager().getVariableSet(organizationId, study, variableSetId,
QueryOptions.empty(), token);
if (variableSetResult.getNumResults() == 0) {
throw new ToolException("Variable set '" + variableSetId + "' not found");
Expand Down
Loading

0 comments on commit 1de04f2

Please sign in to comment.