Skip to content

Commit

Permalink
organizations: work in progress #TASK-4389
Browse files Browse the repository at this point in the history
  • Loading branch information
pfurio committed Sep 8, 2023
1 parent c7866c4 commit 8028603
Show file tree
Hide file tree
Showing 103 changed files with 2,256 additions and 2,082 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ protected StorageManager(CatalogManager catalogManager, CacheManager cacheManage


public void clearCache(String sessionId) throws CatalogException {
String userId = catalogManager.getUserManager().getUserId(sessionId);
String userId = catalogManager.getUserManager().getUserId(organizationId, sessionId);

}


public void clearCache(String studyId, String sessionId) throws CatalogException {
String userId = catalogManager.getUserManager().getUserId(sessionId);
String userId = catalogManager.getUserManager().getUserId(organizationId, sessionId);

}

Expand All @@ -99,7 +99,7 @@ protected StudyInfo getStudyInfo(@Nullable String studyIdStr, List<String> fileI
throws CatalogException {
StudyInfo studyInfo = new StudyInfo().setSessionId(sessionId);

String userId = catalogManager.getUserManager().getUserId(sessionId);
String userId = catalogManager.getUserManager().getUserId(organizationId, sessionId);
Study study = catalogManager.getStudyManager().get(organizationId, studyIdStr, QueryOptions.empty(), sessionId).first();

List<File> files;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void setStudy(String study) {

@Override
protected void check() throws Exception {
String userId = catalogManager.getUserManager().getUserId(token);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);

OpenCGAResult<File> fileResult = catalogManager.getFileManager().get(organizationId, study, path, FileManager.INCLUDE_FILE_URI_PATH, token);
if (fileResult.getNumResults() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,8 @@ public List<ClinicalVariant> getPrimaryFindings(String clinicalAnalysisId, Query

public ClinicalAnalyst getAnalyst(String token) throws ToolException {
try {
String userId = catalogManager.getUserManager().getUserId(token);
OpenCGAResult<User> userQueryResult = catalogManager.getUserManager().get(userId, new QueryOptions(QueryOptions.INCLUDE,
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
OpenCGAResult<User> userQueryResult = catalogManager.getUserManager().get(organizationId, userId, new QueryOptions(QueryOptions.INCLUDE,
Arrays.asList(UserDBAdaptor.QueryParams.EMAIL.key(), UserDBAdaptor.QueryParams.ORGANIZATION.key())), token);
User user = userQueryResult.first();
return new ClinicalAnalyst(userId, user.getName(), user.getEmail(), "", "");
Expand Down Expand Up @@ -877,7 +877,7 @@ private Query checkQueryPermissions(Query query, String token) throws ClinicalVa
}

// Get userId from token and Study numeric IDs from the query
String userId = catalogManager.getUserManager().getUserId(token);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
List<String> studyIds = getStudyIds(userId, query);

// If one specific clinical analysis, sample or individual is provided we expect a single valid study as well
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected void check() throws Exception {
// Check permissions
try {
Study study = catalogManager.getStudyManager().get(organizationId, studyId, QueryOptions.empty(), token).first();
String userId = catalogManager.getUserManager().getUserId(token);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
catalogManager.getAuthorizationManager().checkStudyPermission(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 @@ protected void check() throws Exception {
throw new CatalogException("Parent path " + parents.first().getPath() + " is external. Cannot download to mounted folders");
}

String userId = catalogManager.getUserManager().getUserId(token);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
// Check write permissions over the path
catalogManager.getAuthorizationManager()
.checkFilePermission(study.getUid(), parents.first().getUid(), userId, FilePermissions.WRITE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected void check() throws Exception {
// Check permissions
try {
Study study = catalogManager.getStudyManager().get(organizationId, studyId, QueryOptions.empty(), token).first();
String userId = catalogManager.getUserManager().getUserId(token);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
catalogManager.getAuthorizationManager().checkStudyPermission(study.getUid(), userId, WRITE_INDIVIDUALS);
} catch (CatalogException e) {
throw new ToolException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected void check() throws Exception {

@Override
protected void run() throws Exception {
step(() -> catalogManager.getPanelManager().importFromSource(studyFqn, params.getSource(), params.getId(), token));
step(() -> catalogManager.getPanelManager().importFromSource(organizationId, studyFqn, params.getSource(), params.getId(), token));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,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);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
Study studyObject = catalogManager.getStudyManager().get(organizationId, study, QueryOptions.empty(), token).first();
try {
catalogManager.getAuthorizationManager().isOwnerOrAdmin(studyObject.getUid(), userId);
Expand Down Expand Up @@ -225,7 +225,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);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first();
try {
catalogManager.getAuthorizationManager().isOwnerOrAdmin(study.getUid(), userId);
Expand Down Expand Up @@ -433,7 +433,7 @@ private AuxiliarRgaDataModel getAuxiliarRgaDataModel(String mainCollection, Stri
private OpenCGAResult<Long> updateRgaInternalIndexStatus(String studyStr, List<String> sampleIds, RgaIndex.Status status,
String token) throws CatalogException, RgaException {
Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first();
String userId = catalogManager.getUserManager().getUserId(token);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
String collection = getMainCollectionName(study.getFqn());

catalogManager.getAuthorizationManager().checkIsOwnerOrAdmin(study.getUid(), userId);
Expand All @@ -454,7 +454,7 @@ private OpenCGAResult<Long> updateRgaInternalIndexStatus(String studyStr, List<S
for (String sampleId : sampleIds) {
tmpSampleIds.add(sampleId);
if (tmpSampleIds.size() == 100) {
OpenCGAResult<Sample> update = catalogManager.getSampleManager().updateRgaIndexes(study.getFqn(), tmpSampleIds, rgaIndex,
OpenCGAResult<Sample> update = catalogManager.getSampleManager().updateRgaIndexes(organizationId, study.getFqn(), tmpSampleIds, rgaIndex,
token);
updatedSamples += update.getNumUpdated();

Expand All @@ -464,7 +464,7 @@ private OpenCGAResult<Long> updateRgaInternalIndexStatus(String studyStr, List<S

if (!tmpSampleIds.isEmpty()) {
// Update last batch
OpenCGAResult<Sample> update = catalogManager.getSampleManager().updateRgaIndexes(study.getFqn(), tmpSampleIds, rgaIndex,
OpenCGAResult<Sample> update = catalogManager.getSampleManager().updateRgaIndexes(organizationId, study.getFqn(), tmpSampleIds, rgaIndex,
token);
updatedSamples += update.getNumUpdated();
}
Expand All @@ -476,7 +476,7 @@ private OpenCGAResult<Long> updateRgaInternalIndexStatus(String studyStr, List<S
private OpenCGAResult<Long> updateRgaInternalIndexStatus(String studyStr, String token)
throws CatalogException, IOException, RgaException {
Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first();
String userId = catalogManager.getUserManager().getUserId(token);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
String collection = getMainCollectionName(study.getFqn());

catalogManager.getAuthorizationManager().checkIsOwnerOrAdmin(study.getUid(), userId);
Expand All @@ -497,7 +497,7 @@ private OpenCGAResult<Long> updateRgaInternalIndexStatus(String studyStr, String
int updatedSamples = 0;

// Before doing anything, we first reset all the sample rga indexes
OpenCGAResult<Sample> resetResult = catalogManager.getSampleManager().resetRgaIndexes(studyStr, token);
OpenCGAResult<Sample> resetResult = catalogManager.getSampleManager().resetRgaIndexes(organizationId, studyStr, token);
logger.debug("Resetting RGA indexes for " + resetResult.getNumMatches() + " samples took " + resetResult.getTime() + " ms.");

// Update samples in batches of 100
Expand All @@ -507,7 +507,7 @@ private OpenCGAResult<Long> updateRgaInternalIndexStatus(String studyStr, String
for (FacetField.Bucket bucket : result.first().getBuckets()) {
sampleIds.add(bucket.getValue());
if (sampleIds.size() == 100) {
OpenCGAResult<Sample> update = catalogManager.getSampleManager().updateRgaIndexes(study.getFqn(), sampleIds, rgaIndex,
OpenCGAResult<Sample> update = catalogManager.getSampleManager().updateRgaIndexes(organizationId, study.getFqn(), sampleIds, rgaIndex,
token);
updatedSamples += update.getNumUpdated();

Expand All @@ -517,7 +517,7 @@ private OpenCGAResult<Long> updateRgaInternalIndexStatus(String studyStr, String

if (!sampleIds.isEmpty()) {
// Update last batch
OpenCGAResult<Sample> update = catalogManager.getSampleManager().updateRgaIndexes(study.getFqn(), sampleIds, rgaIndex, token);
OpenCGAResult<Sample> update = catalogManager.getSampleManager().updateRgaIndexes(organizationId, study.getFqn(), sampleIds, rgaIndex, token);
updatedSamples += update.getNumUpdated();
}

Expand Down Expand Up @@ -619,7 +619,7 @@ public OpenCGAResult<RgaKnockoutByGene> geneQuery(String studyStr, Query query,
}

Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first();
String userId = catalogManager.getUserManager().getUserId(token);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
String collection = getMainCollectionName(study.getFqn());
if (!rgaEngine.isAlive(collection)) {
throw new RgaException("Missing RGA indexes for study '" + study.getFqn() + "' or solr server not alive");
Expand Down Expand Up @@ -753,7 +753,7 @@ public OpenCGAResult<KnockoutByVariant> variantQuery(String studyStr, Query quer
}

Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first();
String userId = catalogManager.getUserManager().getUserId(token);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
String collection = getMainCollectionName(study.getFqn());
String auxCollection = getAuxCollectionName(study.getFqn());
if (!rgaEngine.isAlive(collection)) {
Expand Down Expand Up @@ -1048,7 +1048,7 @@ public OpenCGAResult<KnockoutByGeneSummary> geneSummary(String studyStr, Query q
}

Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first();
String userId = catalogManager.getUserManager().getUserId(token);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
String collection = getMainCollectionName(study.getFqn());
if (!rgaEngine.isAlive(collection)) {
throw new RgaException("Missing RGA indexes for study '" + study.getFqn() + "' or solr server not alive");
Expand Down Expand Up @@ -1132,7 +1132,7 @@ public OpenCGAResult<KnockoutByVariantSummary> variantSummary(String studyStr, Q
}

Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first();
String userId = catalogManager.getUserManager().getUserId(token);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
String collection = getMainCollectionName(study.getFqn());
String auxCollection = getAuxCollectionName(study.getFqn());
if (!rgaEngine.isAlive(collection)) {
Expand Down Expand Up @@ -1238,7 +1238,7 @@ public OpenCGAResult<KnockoutByVariantSummary> variantSummary(String studyStr, Q
public OpenCGAResult<FacetField> aggregationStats(String studyStr, Query query, QueryOptions options, String fields, String token)
throws CatalogException, IOException, RgaException {
Study study = catalogManager.getStudyManager().get(organizationId, studyStr, QueryOptions.empty(), token).first();
String userId = catalogManager.getUserManager().getUserId(token);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);

catalogManager.getAuthorizationManager().checkCanViewStudy(study.getUid(), userId);

Expand Down Expand Up @@ -1720,7 +1720,7 @@ private Set<String> getAuthorisedSamples(String study, Set<String> sampleIds, Li
private Preprocess individualQueryPreprocess(Study study, Query query, QueryOptions options, String token)
throws RgaException, CatalogException, IOException {

String userId = catalogManager.getUserManager().getUserId(token);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
String collection = getMainCollectionName(study.getFqn());
if (!rgaEngine.isAlive(collection)) {
throw new RgaException("Missing RGA indexes for study '" + study.getFqn() + "' or solr server not alive");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public int count(Query query) throws CatalogException {

@Override
public void addAnnotationSet(String entryId, AnnotationSet annotationSet, QueryOptions options) throws CatalogException {
catalogManager.getSampleManager().addAnnotationSet(study, entryId, annotationSet, options, token);
catalogManager.getSampleManager().addAnnotationSet(organizationId, study, entryId, annotationSet, options, token);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected void check() throws Exception {
// Check permissions
try {
long studyUid = catalogManager.getStudyManager().get(organizationId, getStudy(), QueryOptions.empty(), token).first().getUid();
String userId = catalogManager.getUserManager().getUserId(token);
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
catalogManager.getAuthorizationManager().checkStudyPermission(studyUid, userId, WRITE_SAMPLES);
} catch (CatalogException e) {
throw new ToolException(e);
Expand Down Expand Up @@ -350,7 +350,7 @@ protected void run() throws ToolException {
if (genomePlot != null) {
qc.getVariant().setGenomePlot(genomePlot);

catalogManager.getSampleManager().update(getStudy(), sample.getId(), new SampleUpdateParams().setQualityControl(qc),
catalogManager.getSampleManager().update(organizationId, getStudy(), sample.getId(), new SampleUpdateParams().setQualityControl(qc),
QueryOptions.empty(), getToken());
logger.info("Quality control saved for sample {}", sample.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected void run() throws ToolException {
}
qc.getVariant().setGenomePlot(genomePlot);

catalogManager.getSampleManager().update(getStudy(), sample.getId(), new SampleUpdateParams().setQualityControl(qc),
catalogManager.getSampleManager().update(organizationId, getStudy(), sample.getId(), new SampleUpdateParams().setQualityControl(qc),
QueryOptions.empty(), getToken());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected void run() throws ToolException {
qc.getVariant().setHrDetects(new ArrayList<>());
}
qc.getVariant().getHrDetects().add(hrDetect);
catalogManager.getSampleManager().update(getStudy(), sample.getId(), new SampleUpdateParams().setQualityControl(qc),
catalogManager.getSampleManager().update(organizationId, getStudy(), sample.getId(), new SampleUpdateParams().setQualityControl(qc),
QueryOptions.empty(), getToken());
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ protected void check() throws Exception {
String project = getParams().getString(ParamConstants.PROJECT_PARAM);

if (StringUtils.isEmpty(project)) {
String userId = getCatalogManager().getUserManager().getUserId(getToken());
User user = catalogManager.getUserManager().get(userId, null, getToken()).first();
String userId = getCatalogManager().getUserManager().getUserId(organizationId, getToken());
User user = catalogManager.getUserManager().get(organizationId, userId, null, getToken()).first();
if (CollectionUtils.isEmpty(user.getProjects()) || user.getProjects().size() > 1) {
throw new CatalogException("Missing '" + ParamConstants.PROJECT_PARAM + "' parameter");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ public Query parseQuery(Query query, QueryOptions queryOptions, CellBaseUtils ce

if (isValidParam(query, SAVED_FILTER)) {
String savedFilter = query.getString(SAVED_FILTER.key());
String userId = catalogManager.getUserManager().getUserId(token);
UserFilter userFilter = catalogManager.getUserManager().getFilter(userId, savedFilter, token).first();
String userId = catalogManager.getUserManager().getUserId(organizationId, token);
UserFilter userFilter = catalogManager.getUserManager().getFilter(organizationId, userId, savedFilter, token).first();
if (!userFilter.getResource().equals(Enums.Resource.VARIANT)) {
throw VariantQueryException.malformedParam(SAVED_FILTER, savedFilter,
"The selected saved filter is not a filter for '" + Enums.Resource.VARIANT + "'. "
Expand Down Expand Up @@ -1610,7 +1610,7 @@ protected List<String> getValuesToValidate(List<String> rawValues) {
protected List<String> validate(String defaultStudyStr, List<String> values, Integer release, VariantQueryParam param,
String sessionId) throws CatalogException {
if (release == null) {
String userId = catalogManager.getUserManager().getUserId(sessionId);
String userId = catalogManager.getUserManager().getUserId(organizationId, sessionId);
// DataResult<Sample> samples = catalogManager.getSampleManager().get(defaultStudyStr, values,
// SampleManager.INCLUDE_SAMPLE_IDS, sessionId);
long numMatches = catalogManager.getSampleManager()
Expand Down
Loading

0 comments on commit 8028603

Please sign in to comment.