StudyAclEntry.StudyPermissions.VIEW_SAMPLES.name(), SampleAclEntry.SamplePermissions.VIEW.name(), Entity.SAMPLE.name());
@Override public QueryResult<Long> count(final Query query, final String user, final StudyAclEntry.StudyPermissions studyPermissions) throws CatalogDBException, CatalogAuthorizationException { filterOutDeleted(query); StudyAclEntry.StudyPermissions studyPermission = (studyPermissions == null ? StudyAclEntry.StudyPermissions.VIEW_COHORTS : studyPermissions); // Get the study document Document studyDocument = getStudyDocument(query); // Get the document query needed to check the permissions as well Document queryForAuthorisedEntries = getQueryForAuthorisedEntries(studyDocument, user, studyPermission.name(), studyPermission.getCohortPermission().name(), Entity.COHORT.name()); Bson bson = parseQuery(query, false, queryForAuthorisedEntries); logger.debug("Cohort count: query : {}, dbTime: {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); return cohortCollection.count(bson); }
studyPermission.name(), studyPermission.getSamplePermission().name(), Entity.SAMPLE.name()); Bson bson = parseQuery(finalQuery, false, queryForAuthorisedEntries);
uniquePermissions.add(studyPermission.toString());
checkStudyPermission(study, user, StudyAclEntry.StudyPermissions.CONFIDENTIAL_VARIABLE_SET_ACCESS.toString()); if (!confidential) {
StudyAclEntry.StudyPermissions.CONFIDENTIAL_VARIABLE_SET_ACCESS.toString()); List<VariableSet> variableSets = new ArrayList<>(); for (Document studyDocument : queryResult.getResult()) {
@Override public QueryResult<VariableSet> getVariableSet(long variableSetId, QueryOptions options, String user) throws CatalogDBException, CatalogAuthorizationException { long startTime = startQuery(); Bson query = new Document("variableSets", new Document("$elemMatch", new Document(PRIVATE_UID, variableSetId))); QueryOptions qOptions = new QueryOptions(QueryOptions.INCLUDE, "variableSets.$,_ownerId,groups,_acl"); QueryResult<Document> studyQueryResult = studyCollection.find(query, qOptions); if (studyQueryResult.getNumResults() == 0) { throw new CatalogDBException("Variable set not found."); } if (!checkCanViewStudy(studyQueryResult.first(), user)) { throw CatalogAuthorizationException.deny(user, "view", "VariableSet", variableSetId, ""); } Study study = studyConverter.convertToDataModelType(studyQueryResult.first()); if (study.getVariableSets() == null || study.getVariableSets().isEmpty()) { throw new CatalogDBException("Variable set not found."); } // Check if it is confidential if (study.getVariableSets().get(0).isConfidential()) { if (!checkStudyPermission(studyQueryResult.first(), user, StudyAclEntry.StudyPermissions.CONFIDENTIAL_VARIABLE_SET_ACCESS.toString())) { throw CatalogAuthorizationException.deny(user, StudyAclEntry.StudyPermissions.CONFIDENTIAL_VARIABLE_SET_ACCESS.toString(), "VariableSet", variableSetId, ""); } } return endQuery("", startTime, study.getVariableSets()); }
private MongoCursor<Document> getMongoCursor(Query query, QueryOptions options, Document studyDocument, String user) throws CatalogDBException, CatalogAuthorizationException { Document queryForAuthorisedEntries = null; if (studyDocument != null && user != null) { // Get the document query needed to check the permissions as well queryForAuthorisedEntries = getQueryForAuthorisedEntries(studyDocument, user, StudyAclEntry.StudyPermissions.VIEW_INDIVIDUALS.name(), IndividualAclEntry.IndividualPermissions.VIEW.name(), Entity.INDIVIDUAL.name()); } filterOutDeleted(query); Bson bson = parseQuery(query, false, queryForAuthorisedEntries); QueryOptions qOptions; if (options != null) { qOptions = new QueryOptions(options); } else { qOptions = new QueryOptions(); } qOptions = removeInnerProjections(qOptions, QueryParams.SAMPLES.key()); qOptions = removeAnnotationProjectionOptions(qOptions); // FIXME we should be able to remove this now safely qOptions = filterOptions(qOptions, FILTER_ROUTE_INDIVIDUALS); logger.debug("Individual get: query : {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); return individualCollection.nativeQuery().find(bson, qOptions).iterator(); }
private MongoCursor<Document> getMongoCursor(Query query, QueryOptions options, Document studyDocument, String user) throws CatalogDBException, CatalogAuthorizationException { Document queryForAuthorisedEntries = null; if (studyDocument != null && user != null) { // Get the document query needed to check the permissions as well queryForAuthorisedEntries = getQueryForAuthorisedEntries(studyDocument, user, StudyAclEntry.StudyPermissions.VIEW_COHORTS.name(), CohortAclEntry.CohortPermissions.VIEW.name(), Entity.COHORT.name()); } filterOutDeleted(query); Bson bson = parseQuery(query, false, queryForAuthorisedEntries); QueryOptions qOptions; if (options != null) { qOptions = new QueryOptions(options); } else { qOptions = new QueryOptions(); } qOptions = removeInnerProjections(qOptions, QueryParams.SAMPLES.key()); qOptions = removeAnnotationProjectionOptions(qOptions); qOptions = filterOptions(qOptions, FILTER_ROUTE_COHORTS); logger.debug("Cohort query : {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); return cohortCollection.nativeQuery().find(bson, qOptions).iterator(); }
private MongoCursor<Document> getMongoCursor(Query query, QueryOptions options, Document studyDocument, String user) throws CatalogDBException, CatalogAuthorizationException { Document queryForAuthorisedEntries = null; if (studyDocument != null && user != null) { // Get the document query needed to check the permissions as well queryForAuthorisedEntries = getQueryForAuthorisedEntries(studyDocument, user, StudyAclEntry.StudyPermissions.VIEW_FILES.name(), FileAclEntry.FilePermissions.VIEW.name(), Entity.FILE.name()); } filterOutDeleted(query); Bson bson = parseQuery(query, false, queryForAuthorisedEntries); QueryOptions qOptions; if (options != null) { qOptions = new QueryOptions(options); } else { qOptions = new QueryOptions(); } qOptions = removeInnerProjections(qOptions, QueryParams.SAMPLES.key()); qOptions = removeAnnotationProjectionOptions(qOptions); qOptions = filterOptions(qOptions, FILTER_ROUTE_FILES); logger.debug("File query: {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); return fileCollection.nativeQuery().find(bson, qOptions).iterator(); }
private MongoCursor<Document> getMongoCursor(Query query, QueryOptions options, Document studyDocument, String user) throws CatalogDBException, CatalogAuthorizationException { Document queryForAuthorisedEntries = null; if (studyDocument != null && user != null) { // Get the document query needed to check the permissions as well queryForAuthorisedEntries = getQueryForAuthorisedEntries(studyDocument, user, StudyAclEntry.StudyPermissions.VIEW_CLINICAL_ANALYSIS.name(), ClinicalAnalysisAclEntry.ClinicalAnalysisPermissions.VIEW.name(), Entity.CLINICAL_ANALYSIS.name()); } filterOutDeleted(query); Bson bson = parseQuery(query, false, queryForAuthorisedEntries); QueryOptions qOptions; if (options != null) { qOptions = new QueryOptions(options); } else { qOptions = new QueryOptions(); } qOptions = removeInnerProjections(qOptions, QueryParams.PROBAND.key()); qOptions = removeInnerProjections(qOptions, QueryParams.FAMILY.key()); logger.debug("Clinical analysis query : {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); return clinicalCollection.nativeQuery().find(bson, qOptions).iterator(); }
private MongoCursor<Document> getMongoCursor(Query query, QueryOptions options, Document studyDocument, String user) throws CatalogDBException, CatalogAuthorizationException { Document queryForAuthorisedEntries = null; if (studyDocument != null && user != null) { // Get the document query needed to check the permissions as well queryForAuthorisedEntries = getQueryForAuthorisedEntries(studyDocument, user, StudyAclEntry.StudyPermissions.VIEW_FAMILIES.name(), FamilyAclEntry.FamilyPermissions.VIEW.name(), Entity.FAMILY.name()); } filterOutDeleted(query); Bson bson = parseQuery(query, false, queryForAuthorisedEntries); QueryOptions qOptions; if (options != null) { qOptions = new QueryOptions(options); } else { qOptions = new QueryOptions(); } qOptions = removeInnerProjections(qOptions, QueryParams.MEMBERS.key()); qOptions = removeAnnotationProjectionOptions(qOptions); logger.debug("Family query : {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); return familyCollection.nativeQuery().find(bson, qOptions).iterator(); }
private MongoCursor<Document> getMongoCursor(Query query, QueryOptions options, Document studyDocument, String user) throws CatalogDBException, CatalogAuthorizationException { Document queryForAuthorisedEntries = null; if (studyDocument != null && user != null) { // Get the document query needed to check the permissions as well queryForAuthorisedEntries = getQueryForAuthorisedEntries(studyDocument, user, StudyAclEntry.StudyPermissions.VIEW_JOBS.name(), JobAclEntry.JobPermissions.VIEW.name(), Entity.JOB.name()); } filterOutDeleted(query); Bson bson = parseQuery(query, false, queryForAuthorisedEntries); QueryOptions qOptions; if (options != null) { qOptions = new QueryOptions(options); } else { qOptions = new QueryOptions(); } qOptions = filterOptions(qOptions, FILTER_ROUTE_JOBS); logger.debug("Job get: query : {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); return jobCollection.nativeQuery().find(bson, qOptions).iterator(); }
@Override public QueryResult<Long> count(final Query query, final String user, final StudyAclEntry.StudyPermissions studyPermissions) throws CatalogDBException, CatalogAuthorizationException { filterOutDeleted(query); StudyAclEntry.StudyPermissions studyPermission = studyPermissions; if (studyPermission == null) { studyPermission = StudyAclEntry.StudyPermissions.VIEW_CLINICAL_ANALYSIS; } // Get the study document Query studyQuery = new Query(StudyDBAdaptor.QueryParams.UID.key(), query.getLong(QueryParams.STUDY_UID.key())); QueryResult queryResult = dbAdaptorFactory.getCatalogStudyDBAdaptor().nativeGet(studyQuery, QueryOptions.empty()); if (queryResult.getNumResults() == 0) { throw new CatalogDBException("Study " + query.getLong(QueryParams.STUDY_UID.key()) + " not found"); } // Get the document query needed to check the permissions as well Document queryForAuthorisedEntries = getQueryForAuthorisedEntries((Document) queryResult.first(), user, studyPermission.name(), studyPermission.getClinicalAnalysisPermission().name(), Entity.CLINICAL_ANALYSIS.name()); Bson bson = parseQuery(query, false, queryForAuthorisedEntries); logger.debug("Clinical count: query : {}, dbTime: {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); return clinicalCollection.count(bson); }
private MongoCursor<Document> getMongoCursor(Query query, QueryOptions options, Document studyDocument, String user) throws CatalogDBException, CatalogAuthorizationException { Document queryForAuthorisedEntries = null; if (studyDocument != null && user != null) { // Get the document query needed to check the permissions as well queryForAuthorisedEntries = getQueryForAuthorisedEntries(studyDocument, user, StudyAclEntry.StudyPermissions.VIEW_PANELS.name(), PanelAclEntry.PanelPermissions.VIEW.name(), Entity.PANEL.name()); } Query finalQuery = new Query(query); filterOutDeleted(finalQuery); QueryOptions qOptions; if (options != null) { qOptions = new QueryOptions(options); } else { qOptions = new QueryOptions(); } Bson bson = parseQuery(finalQuery, false, queryForAuthorisedEntries); logger.debug("Panel query: {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); return panelCollection.nativeQuery().find(bson, qOptions).iterator(); }
@Override public QueryResult<Long> count(final Query query, final String user, final StudyAclEntry.StudyPermissions studyPermissions) throws CatalogDBException, CatalogAuthorizationException { filterOutDeleted(query); StudyAclEntry.StudyPermissions studyPermission = (studyPermissions == null ? StudyAclEntry.StudyPermissions.VIEW_FAMILIES : studyPermissions); // Get the study document Query studyQuery = new Query(StudyDBAdaptor.QueryParams.UID.key(), query.getLong(QueryParams.STUDY_UID.key())); QueryResult queryResult = dbAdaptorFactory.getCatalogStudyDBAdaptor().nativeGet(studyQuery, QueryOptions.empty()); if (queryResult.getNumResults() == 0) { throw new CatalogDBException("Study " + query.getLong(QueryParams.STUDY_UID.key()) + " not found"); } // Get the document query needed to check the permissions as well Document queryForAuthorisedEntries = getQueryForAuthorisedEntries((Document) queryResult.first(), user, studyPermission.name(), studyPermission.getFamilyPermission().name(), Entity.FAMILY.name()); Bson bson = parseQuery(query, false, queryForAuthorisedEntries); logger.debug("Family count: query : {}, dbTime: {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); return familyCollection.count(bson); }
@Override public QueryResult<Long> count(final Query query, final String user, final StudyAclEntry.StudyPermissions studyPermissions) throws CatalogDBException, CatalogAuthorizationException { filterOutDeleted(query); StudyAclEntry.StudyPermissions studyPermission = (studyPermissions == null ? StudyAclEntry.StudyPermissions.VIEW_FILES : studyPermissions); // Get the study document Query studyQuery = new Query(StudyDBAdaptor.QueryParams.UID.key(), query.getLong(QueryParams.STUDY_UID.key())); QueryResult queryResult = dbAdaptorFactory.getCatalogStudyDBAdaptor().nativeGet(studyQuery, QueryOptions.empty()); if (queryResult.getNumResults() == 0) { throw new CatalogDBException("Study " + query.getLong(QueryParams.STUDY_UID.key()) + " not found"); } // Get the document query needed to check the permissions as well Document queryForAuthorisedEntries = getQueryForAuthorisedEntries((Document) queryResult.first(), user, studyPermission.name(), studyPermission.getFilePermission().name(), Entity.FILE.name()); Bson bson = parseQuery(query, false, queryForAuthorisedEntries); logger.debug("File count: query : {}, dbTime: {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); return fileCollection.count(bson); }
@Override public QueryResult<Long> count(Query query, String user, StudyAclEntry.StudyPermissions studyPermissions) throws CatalogDBException, CatalogAuthorizationException { filterOutDeleted(query); StudyAclEntry.StudyPermissions studyPermission = (studyPermissions == null ? StudyAclEntry.StudyPermissions.VIEW_JOBS : studyPermissions); // Get the study document Query studyQuery = new Query(StudyDBAdaptor.QueryParams.UID.key(), query.getLong(QueryParams.STUDY_UID.key())); QueryResult queryResult = dbAdaptorFactory.getCatalogStudyDBAdaptor().nativeGet(studyQuery, QueryOptions.empty()); if (queryResult.getNumResults() == 0) { throw new CatalogDBException("Study " + query.getLong(QueryParams.STUDY_UID.key()) + " not found"); } // Get the document query needed to check the permissions as well Document queryForAuthorisedEntries = getQueryForAuthorisedEntries((Document) queryResult.first(), user, studyPermission.name(), studyPermission.getJobPermission().name(), Entity.JOB.name()); Bson bson = parseQuery(query, false, queryForAuthorisedEntries); logger.debug("Job count: query : {}, dbTime: {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); return jobCollection.count(bson); }
@Override public QueryResult<Long> count(Query query, String user, StudyAclEntry.StudyPermissions studyPermissions) throws CatalogDBException, CatalogAuthorizationException { filterOutDeleted(query); StudyAclEntry.StudyPermissions studyPermission = (studyPermissions == null ? StudyAclEntry.StudyPermissions.VIEW_INDIVIDUALS : studyPermissions); // Get the study document Query studyQuery = new Query(StudyDBAdaptor.QueryParams.UID.key(), query.getLong(QueryParams.STUDY_UID.key())); QueryResult queryResult = dbAdaptorFactory.getCatalogStudyDBAdaptor().nativeGet(studyQuery, QueryOptions.empty()); if (queryResult.getNumResults() == 0) { throw new CatalogDBException("Study " + query.getLong(QueryParams.STUDY_UID.key()) + " not found"); } // Get the document query needed to check the permissions as well Document queryForAuthorisedEntries = getQueryForAuthorisedEntries((Document) queryResult.first(), user, studyPermission.name(), studyPermission.getIndividualPermission().name(), Entity.INDIVIDUAL.name()); Bson bson = parseQuery(query, false, queryForAuthorisedEntries); logger.debug("Individual count: query : {}, dbTime: {}", bson.toBsonDocument(Document.class, MongoClient.getDefaultCodecRegistry())); return individualCollection.count(bson); }
@Override public QueryResult groupBy(Query query, List<String> fields, QueryOptions options, String user) throws CatalogDBException, CatalogAuthorizationException { Document studyDocument = getStudyDocument(query); Document queryForAuthorisedEntries; if (containsAnnotationQuery(query)) { queryForAuthorisedEntries = getQueryForAuthorisedEntries(studyDocument, user, StudyAclEntry.StudyPermissions.VIEW_FAMILY_ANNOTATIONS.name(), FamilyAclEntry.FamilyPermissions.VIEW_ANNOTATIONS.name(), Entity.FAMILY.name()); } else { queryForAuthorisedEntries = getQueryForAuthorisedEntries(studyDocument, user, StudyAclEntry.StudyPermissions.VIEW_FAMILIES.name(), FamilyAclEntry.FamilyPermissions.VIEW.name(), Entity.FAMILY.name()); } filterOutDeleted(query); Bson bsonQuery = parseQuery(query, false, queryForAuthorisedEntries); return groupBy(familyCollection, bsonQuery, fields, QueryParams.ID.key(), options); }