@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);
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");
}
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);
}