Skip to content

Commit

Permalink
organizations: start removal of organization from public api, TASK-4389
Browse files Browse the repository at this point in the history
  • Loading branch information
pfurio committed Sep 20, 2023
1 parent 0bff62f commit 9844259
Show file tree
Hide file tree
Showing 136 changed files with 3,093 additions and 2,572 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,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(organizationId, studyId, query, QueryOptions.empty(), token);
fileQueryResult = fileManager.search(studyId, query, QueryOptions.empty(), token);
} catch (CatalogException e) {
throw new ToolException(e);
}
Expand All @@ -55,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(organizationId, studyId, query, queryOptions, token);
fileQueryResult = fileManager.search(studyId, query, queryOptions, token);
} catch (CatalogException e) {
throw new ToolException(e);
}
Expand All @@ -81,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(organizationId, studyId, query, QueryOptions.empty(), token);
fileQueryResult = fileManager.search(studyId, query, QueryOptions.empty(), token);

// Sanity check
if (fileQueryResult.getNumResults() == 0) {
Expand Down Expand Up @@ -124,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(organizationId, study, query, QueryOptions.empty(), token);
OpenCGAResult<Job> result = jobManager.search(study, query, QueryOptions.empty(), token);
Job job = result.first();
String status = job.getInternal().getStatus().getId();

Expand All @@ -134,7 +134,7 @@ public static boolean waitFor(String jobId, String study, JobManager jobManager,
try {
// Sleep for 30 seconds
Thread.sleep(30000);
result = jobManager.search(organizationId, study, query, QueryOptions.empty(), token);
result = jobManager.search(study, query, QueryOptions.empty(), token);
job = result.first();
} catch (CatalogException | InterruptedException e) {
new ToolException("Error waiting for job '" + jobId + "': " + e.getMessage());
Expand All @@ -146,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(organizationId, study, query, QueryOptions.empty(), token);
OpenCGAResult<Job> result = jobManager.search(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 @@ -67,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(organizationId, getStudy(), query, QueryOptions.empty(), token);
OpenCGAResult<File> fileResult = catalogManager.getFileManager().search(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 @@ -72,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(organizationId, getStudy(), query, QueryOptions.empty(), token);
OpenCGAResult<File> fileResult = catalogManager.getFileManager().search(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 @@ -240,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(organizationId, study, query, QueryOptions.empty(), token);
result = catalogManager.getJobManager().search(study, query, QueryOptions.empty(), token);
} catch (CatalogException e) {
new ToolException("Error waiting for job '" + jobId + "': " + e.getMessage());
}
Expand All @@ -253,7 +253,7 @@ private boolean waitFor(String jobId) throws ToolException {
// Sleep for 1 minute
try {
Thread.sleep(60000);
result = catalogManager.getJobManager().search(organizationId, study, query, QueryOptions.empty(), token);
result = catalogManager.getJobManager().search(study, query, QueryOptions.empty(), token);
job = result.first();
} catch (CatalogException | InterruptedException e) {
new ToolException("Error waiting for job '" + jobId + "': " + e.getMessage());
Expand All @@ -268,7 +268,7 @@ private Job getJob(String jobId) {
Job job = null;
try {
Query query = new Query("id", jobId);
OpenCGAResult<Job> result = catalogManager.getJobManager().search(organizationId, study, query, QueryOptions.empty(), token);
OpenCGAResult<Job> result = catalogManager.getJobManager().search(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 @@ -73,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(organizationId, getStudy(), query, QueryOptions.empty(), token);
OpenCGAResult<File> fileResult = catalogManager.getFileManager().search(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 @@ -165,7 +165,7 @@ public DataResult<ClinicalVariant> index(String token) {

public DataResult<ClinicalVariant> index(String study, String token) throws IOException, ClinicalVariantException, CatalogException {
DBIterator<ClinicalAnalysis> clinicalAnalysisDBIterator =
clinicalAnalysisManager.iterator(organizationId, study, new Query(), QueryOptions.empty(), token);
clinicalAnalysisManager.iterator(study, new Query(), QueryOptions.empty(), token);

while (clinicalAnalysisDBIterator.hasNext()) {
ClinicalAnalysis clinicalAnalysis = clinicalAnalysisDBIterator.next();
Expand Down Expand Up @@ -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<ClinicalAnalysis> clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager()
.search(organizationId, studyIds.get(0), query, QueryOptions.empty(), token);
.search(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");
Expand Down Expand Up @@ -953,7 +953,7 @@ private void checkInterpretationPermissions(String study, long interpretationId,
// This checks that the user has permission to this interpretation
Query query = new Query(ClinicalAnalysisDBAdaptor.QueryParams.INTERPRETATION_ID.key(), interpretationId);
DataResult<ClinicalAnalysis> clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager()
.search(organizationId, studyId, query, QueryOptions.empty(), token);
.search(studyId, query, QueryOptions.empty(), token);

if (clinicalAnalysisQueryResult.getResults().isEmpty()) {
throw new ClinicalVariantException("Either the interpretation ID (" + interpretationId + ") does not exist or the user does"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(organizationId, study.getFqn(), query,
catalogSolrManager.insertCatalogCollection(catalogManager.getCohortManager().iterator(study.getFqn(), query,
cohortQueryOptions, token), new CatalogCohortToSolrCohortConverter(study), CatalogSolrManager.COHORT_SOLR_COLLECTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class CohortTsvAnnotationLoader extends TsvAnnotationLoader {

@Override
public int count(Query query) throws CatalogException {
return catalogManager.getCohortManager().count(organizationId, study, query, token).getNumResults();
return catalogManager.getCohortManager().count(study, query, token).getNumResults();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(organizationId, study.getFqn(), query,
catalogSolrManager.insertCatalogCollection(catalogManager.getFamilyManager().iterator(study.getFqn(), query,
familyQueryOptions, token), new CatalogFamilyToSolrFamilyConverter(study), CatalogSolrManager.FAMILY_SOLR_COLLECTION);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class FamilyTsvAnnotationLoader extends TsvAnnotationLoader {

@Override
public int count(Query query) throws CatalogException {
return catalogManager.getFamilyManager().count(organizationId, study, query, token).getNumResults();
return catalogManager.getFamilyManager().count(study, query, token).getNumResults();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Family> results = catalogManager.getFamilyManager().search(organizationId, study, new Query(), queryOptions, token);
OpenCGAResult<Family> results = catalogManager.getFamilyManager().search(study, new Query(), queryOptions, token);

// Get families to update by filtering
List<Family> familiesToUpdate = results.getResults().stream().filter(family -> PedigreeGraphUtils.hasMinTwoGenerations(family)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected void check() throws Exception {
try {
Study study = catalogManager.getStudyManager().get(organizationId, studyId, QueryOptions.empty(), token).first();
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
catalogManager.getAuthorizationManager().checkStudyPermission(study.getUid(), userId, WRITE_FAMILIES);
catalogManager.getAuthorizationManager().checkStudyPermission(organizationId, study.getUid(), userId, WRITE_FAMILIES);
} catch (CatalogException e) {
throw new ToolException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void runRelatedness() throws ToolException {

List<String> sampleIds = new ArrayList<>();
try {
OpenCGAResult<Individual> individualResult = catalogManager.getIndividualManager().search(organizationId, getStudyId(), query, queryOptions,
OpenCGAResult<Individual> individualResult = catalogManager.getIndividualManager().search(getStudyId(), query, queryOptions,
getToken());
for (Individual individual : individualResult.getResults()) {
if (CollectionUtils.isNotEmpty(individual.getSamples())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected void check() throws Exception {
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
// Check write permissions over the path
catalogManager.getAuthorizationManager()
.checkFilePermission(study.getUid(), parents.first().getUid(), userId, FilePermissions.WRITE);
.checkFilePermission(organizationId, study.getUid(), parents.first().getUid(), userId, FilePermissions.WRITE);
} catch (CatalogException e) {
throw new ToolException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<File> iterator = fileManager.iterator(organizationId, studyFqn, query, FileManager.EXCLUDE_FILE_ATTRIBUTES, token)) {
try (DBIterator<File> iterator = fileManager.iterator(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(organizationId, studyFqn, Collections.singletonList(file.getUuid()), params, token);
fileManager.delete(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());
Expand Down Expand Up @@ -172,7 +172,7 @@ private void recoverFromFatalCrash() {
query.put(FileDBAdaptor.QueryParams.INTERNAL_STATUS_ID.key(), FileStatus.DELETING);
OpenCGAResult<File> fileResult = null;
try {
fileResult = catalogManager.getFileManager().search(organizationId, studyFqn, query, FileManager.EXCLUDE_FILE_ATTRIBUTES,
fileResult = catalogManager.getFileManager().search(studyFqn, query, FileManager.EXCLUDE_FILE_ATTRIBUTES,
token);
} catch (CatalogException e) {
logger.error("Critical: Could not check if there are any inconsistent files", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(organizationId, study.getFqn(), query,
catalogSolrManager.insertCatalogCollection(catalogManager.getFileManager().iterator(study.getFqn(), query,
fileQueryOptions, token), new CatalogFileToSolrFileConverter(study), CatalogSolrManager.FILE_SOLR_COLLECTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class FileTsvAnnotationLoader extends TsvAnnotationLoader {

@Override
public int count(Query query) throws CatalogException {
return catalogManager.getFileManager().count(organizationId, study, query, token).getNumResults();
return catalogManager.getFileManager().count(study, query, token).getNumResults();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<File> iterator = fileManager.iterator(organizationId, studyFqn, query, FileManager.EXCLUDE_FILE_ATTRIBUTES, token)) {
try (DBIterator<File> iterator = fileManager.iterator(studyFqn, query, FileManager.EXCLUDE_FILE_ATTRIBUTES, token)) {
while (iterator.hasNext()) {
File file = iterator.next();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected void run() throws Exception {
OpenCGAResult<File> fileResult;
if (files == null) {
// We need to associate all non-associated files
fileResult = catalogManager.getFileManager().search(organizationId, study, fileQuery, options, token);
fileResult = catalogManager.getFileManager().search(study, fileQuery, options, token);
if (fileResult.getNumResults() == 0) {
break;
}
Expand Down Expand Up @@ -126,7 +126,7 @@ protected void run() throws Exception {
if (!sampleExists(sampleId)) {
try {
// Sample still doesn't exist, so we create it
OpenCGAResult<Sample> sampleResult = catalogManager.getSampleManager().create(organizationId, study, new Sample().setId(sampleId),
OpenCGAResult<Sample> sampleResult = catalogManager.getSampleManager().create(study, new Sample().setId(sampleId),
QueryOptions.empty(), token);
if (sampleResult.getNumResults() != 1) {
throw new CatalogException("Could not create sample '" + sampleId + "'");
Expand Down Expand Up @@ -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<Sample> sampleResult = catalogManager.getSampleManager().search(organizationId, study, sampleQuery,
OpenCGAResult<Sample> sampleResult = catalogManager.getSampleManager().search(study, sampleQuery,
SampleManager.INCLUDE_SAMPLE_IDS, token);

return sampleResult.getNumResults() == 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(organizationId, study.getFqn(), query,
catalogSolrManager.insertCatalogCollection(catalogManager.getIndividualManager().iterator(study.getFqn(), query,
individualQueryOptions, token), new CatalogIndividualToSolrIndividualConverter(study),
CatalogSolrManager.INDIVIDUAL_SOLR_COLLECTION);
}
Expand Down
Loading

0 comments on commit 9844259

Please sign in to comment.