@Override public void deleteGroup(long studyId, String groupId) throws CatalogDBException { Bson queryBson = new Document() .append(PRIVATE_UID, studyId) .append(QueryParams.GROUP_NAME.key(), groupId) .append("$isolated", 1); Document pull = new Document("$pull", new Document("groups", new Document("name", groupId))); QueryResult<UpdateResult> update = studyCollection.update(queryBson, pull, null); if (update.first().getModifiedCount() != 1) { throw new CatalogDBException("Could not remove the group " + groupId); } }
public static List<String> getAdminUsers(Document study) { List<Document> groupDocumentList = study.get(StudyDBAdaptor.QueryParams.GROUPS.key(), ArrayList.class); if (groupDocumentList != null && !groupDocumentList.isEmpty()) { for (Document group : groupDocumentList) { if ((ADMINS).equals(group.getString("name"))) { return (List<String>) group.get("userIds", ArrayList.class); } } } return Collections.emptyList(); }
@Override public void syncGroup(long studyId, String groupId, Group.Sync syncedFrom) throws CatalogDBException { Document mongoDBDocument = getMongoDBDocument(syncedFrom, "Group.Sync"); Document query = new Document() .append(PRIVATE_UID, studyId) .append(QueryParams.GROUP_NAME.key(), groupId) .append("$isolated", 1); Document updates = new Document("$set", new Document("groups.$.syncedFrom", mongoDBDocument)); studyCollection.update(query, updates, null); }
URI getStudyURI() throws CatalogException { return catalogManager.getStudyManager().get(studyFqn, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.URI.key()), sessionIdUser).first().getUri(); }
@Override public long getId(long projectId, String studyAlias) throws CatalogDBException { Query query1 = new Query(QueryParams.PROJECT_ID.key(), projectId).append(QueryParams.ID.key(), studyAlias); QueryOptions queryOptions = new QueryOptions(MongoDBCollection.INCLUDE, QueryParams.UID.key()); QueryResult<Study> studyQueryResult = get(query1, queryOptions); List<Study> studies = studyQueryResult.getResult(); return studies == null || studies.isEmpty() ? -1 : studies.get(0).getUid(); }
@Override public boolean hasStudyPermission(long studyId, String user, StudyAclEntry.StudyPermissions permission) throws CatalogDBException { Query query = new Query(QueryParams.UID.key(), studyId); QueryResult queryResult = nativeGet(query, QueryOptions.empty()); if (queryResult.getNumResults() == 0) { throw new CatalogDBException("Study " + studyId + " not found"); } return checkStudyPermission((Document) queryResult.first(), user, permission.name()); }
private Document getStudyDocument(Query query) throws CatalogDBException { // Get the study document Query studyQuery = new Query() .append(StudyDBAdaptor.QueryParams.UID.key(), query.getLong(FamilyDBAdaptor.QueryParams.STUDY_UID.key())); QueryResult<Document> queryResult = dbAdaptorFactory.getCatalogStudyDBAdaptor().nativeGet(studyQuery, QueryOptions.empty()); if (queryResult.getNumResults() == 0) { throw new CatalogDBException("Study " + query.getLong(FamilyDBAdaptor.QueryParams.STUDY_UID.key()) + " not found"); } return queryResult.first(); } }
@Override public QueryResult<Long> delete(Query query, QueryOptions queryOptions) throws CatalogDBException { long startTime = startQuery(); query.append(QueryParams.STATUS_NAME.key(), Status.READY); QueryResult<Study> studyQueryResult = get(query, new QueryOptions(MongoDBCollection.INCLUDE, QueryParams.UID.key())); for (Study study : studyQueryResult.getResult()) { delete(study.getUid(), queryOptions); } return endQuery("Delete study", startTime, Collections.singletonList(studyQueryResult.getNumTotalResults())); }
@Override public QueryResult<Study> update(long id, ObjectMap parameters, QueryOptions queryOptions) throws CatalogDBException { long startTime = startQuery(); QueryResult<Long> update = update(new Query(QueryParams.UID.key(), id), parameters, QueryOptions.empty()); if (update.getNumTotalResults() != 1) { throw new CatalogDBException("Could not update study with id " + id); } return endQuery("Update study", startTime, get(id, null)); }
private Document getStudyDocument(Query query) throws CatalogDBException { // Get the study document Query studyQuery = new Query(StudyDBAdaptor.QueryParams.UID.key(), query.getLong(QueryParams.STUDY_UID.key())); QueryResult<Document> queryResult = dbAdaptorFactory.getCatalogStudyDBAdaptor().nativeGet(studyQuery, QueryOptions.empty()); if (queryResult.getNumResults() == 0) { throw new CatalogDBException("Study " + query.getLong(QueryParams.STUDY_UID.key()) + " not found"); } return queryResult.first(); }
private Document getStudyDocument(Query query) throws CatalogDBException { // Get the study document Query studyQuery = new Query(StudyDBAdaptor.QueryParams.UID.key(), query.getLong(QueryParams.STUDY_UID.key())); QueryResult<Document> queryResult = dbAdaptorFactory.getCatalogStudyDBAdaptor().nativeGet(studyQuery, QueryOptions.empty()); if (queryResult.getNumResults() == 0) { throw new CatalogDBException("Study " + query.getLong(QueryParams.STUDY_UID.key()) + " not found"); } return queryResult.first(); }
private Document getStudyDocument(Query query) throws CatalogDBException { // Get the study document Query studyQuery = new Query(StudyDBAdaptor.QueryParams.UID.key(), query.getLong(QueryParams.STUDY_UID.key())); QueryResult<Document> queryResult = dbAdaptorFactory.getCatalogStudyDBAdaptor().nativeGet(studyQuery, QueryOptions.empty()); if (queryResult.getNumResults() == 0) { throw new CatalogDBException("Study " + query.getLong(QueryParams.STUDY_UID.key()) + " not found"); } return queryResult.first(); }
@Test public void testGetAllJobs() throws CatalogException { Query query = new Query(StudyDBAdaptor.QueryParams.OWNER.key(), "user"); String studyId = catalogManager.getStudyManager().get(query, null, sessionIdUser).first().getId(); catalogManager.getJobManager().create(studyId, new Job().setId("myErrorJob").setToolId("samtools"), null, sessionIdUser); QueryResult<Job> allJobs = catalogManager.getJobManager().get(studyId, (Query) null, null, sessionIdUser); assertEquals(1, allJobs.getNumTotalResults()); assertEquals(1, allJobs.getNumResults()); }
@Override public void delete(long id) throws CatalogDBException { Query query = new Query(QueryParams.UID.key(), id); delete(query); }
private Document getStudyDocument(Query query) throws CatalogDBException { // Get the study document Query studyQuery = new Query(StudyDBAdaptor.QueryParams.UID.key(), query.getLong(QueryParams.STUDY_UID.key())); QueryResult<Document> queryResult = dbAdaptorFactory.getCatalogStudyDBAdaptor().nativeGet(studyQuery, QueryOptions.empty()); if (queryResult.getNumResults() == 0) { throw new CatalogDBException("Study " + query.getLong(QueryParams.STUDY_UID.key()) + " not found"); } return queryResult.first(); }
@Override public QueryResult<Long> restore(Query query, QueryOptions queryOptions) throws CatalogDBException { long startTime = startQuery(); query.put(QueryParams.STATUS_NAME.key(), Status.DELETED); return endQuery("Restore studies", startTime, setStatus(query, Status.READY)); }
private Document getStudyDocument(Query query) throws CatalogDBException { // Get the study document Query studyQuery = new Query(StudyDBAdaptor.QueryParams.UID.key(), query.getLong(QueryParams.STUDY_UID.key())); QueryResult<Document> queryResult = dbAdaptorFactory.getCatalogStudyDBAdaptor().nativeGet(studyQuery, QueryOptions.empty()); if (queryResult.getNumResults() == 0) { throw new CatalogDBException("Study " + query.getLong(QueryParams.STUDY_UID.key()) + " not found"); } return queryResult.first(); }