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