public CohortAclEntry(String member, ObjectMap permissions) { super(member, EnumSet.noneOf(CohortPermissions.class)); EnumSet<CohortPermissions> aux = EnumSet.allOf(CohortPermissions.class); for (CohortPermissions permission : aux) { if (permissions.containsKey(permission.name()) && permissions.getBoolean(permission.name())) { this.permissions.add(permission); } } }
.map(StudyAclEntry.StudyPermissions::toString) .collect(Collectors.toList())); this.fullPermissionsMap.put(Entity.COHORT, Arrays.stream(CohortAclEntry.CohortPermissions.values()) .map(CohortAclEntry.CohortPermissions::toString) .collect(Collectors.toList()));
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(); }
@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_COHORT_ANNOTATIONS.name(), CohortAclEntry.CohortPermissions.VIEW_ANNOTATIONS.name(), Entity.COHORT.name()); } else { queryForAuthorisedEntries = getQueryForAuthorisedEntries(studyDocument, user, StudyAclEntry.StudyPermissions.VIEW_COHORTS.name(), CohortAclEntry.CohortPermissions.VIEW.name(), Entity.COHORT.name()); } filterOutDeleted(query); Bson bsonQuery = parseQuery(query, false, queryForAuthorisedEntries); return groupBy(cohortCollection, bsonQuery, fields, QueryParams.ID.key(), options); }
@Override public QueryResult groupBy(Query query, String field, QueryOptions options, String user) throws CatalogDBException, CatalogAuthorizationException { Document studyDocument = getStudyDocument(query); Document queryForAuthorisedEntries; if (containsAnnotationQuery(query)) { queryForAuthorisedEntries = getQueryForAuthorisedEntries(studyDocument, user, StudyAclEntry.StudyPermissions.VIEW_COHORT_ANNOTATIONS.name(), CohortAclEntry.CohortPermissions.VIEW_ANNOTATIONS.name(), Entity.COHORT.name()); } else { queryForAuthorisedEntries = getQueryForAuthorisedEntries(studyDocument, user, StudyAclEntry.StudyPermissions.VIEW_COHORTS.name(), CohortAclEntry.CohortPermissions.VIEW.name(), Entity.COHORT.name()); } filterOutDeleted(query); Bson bsonQuery = parseQuery(query, false, queryForAuthorisedEntries); return groupBy(cohortCollection, bsonQuery, field, QueryParams.ID.key(), options); }
@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); }
@Override public DBIterator nativeIterator(Query query, QueryOptions options, String user) throws CatalogDBException, CatalogAuthorizationException { QueryOptions queryOptions = options != null ? new QueryOptions(options) : new QueryOptions(); queryOptions.put(NATIVE_QUERY, true); Document studyDocument = getStudyDocument(query); MongoCursor<Document> mongoCursor = getMongoCursor(query, queryOptions, studyDocument, user); Function<Document, Document> iteratorFilter = (d) -> filterAnnotationSets(studyDocument, d, user, StudyAclEntry.StudyPermissions.VIEW_COHORT_ANNOTATIONS.name(), CohortAclEntry.CohortPermissions.VIEW_ANNOTATIONS.name()); return new CohortMongoDBIterator(mongoCursor, null, iteratorFilter, dbAdaptorFactory.getCatalogSampleDBAdaptor(), query.getLong(PRIVATE_STUDY_ID), user, options); }
@Override public DBIterator<Cohort> iterator(Query query, QueryOptions options, String user) throws CatalogDBException, CatalogAuthorizationException { Document studyDocument = getStudyDocument(query); MongoCursor<Document> mongoCursor = getMongoCursor(query, options, studyDocument, user); Function<Document, Document> iteratorFilter = (d) -> filterAnnotationSets(studyDocument, d, user, StudyAclEntry.StudyPermissions.VIEW_COHORT_ANNOTATIONS.name(), CohortAclEntry.CohortPermissions.VIEW_ANNOTATIONS.name()); return new CohortMongoDBIterator<>(mongoCursor, cohortConverter, iteratorFilter, dbAdaptorFactory.getCatalogSampleDBAdaptor(), query.getLong(PRIVATE_STUDY_ID), user, options); }
public CohortAclEntry.CohortPermissions getCohortPermission() { if (this.type == COHORT) { return CohortAclEntry.CohortPermissions.valueOf(this.permission); } return null; }