.getProjectManager() .get(studyInfo.getProjectId(), new QueryOptions(QueryOptions.INCLUDE, ProjectDBAdaptor.QueryParams.CURRENT_RELEASE.key()), sessionId); int release = projectQueryResult.first().getCurrentRelease();
fixComplexQueryParam(QueryParams.ATTRIBUTES.key(), query); fixComplexQueryParam(QueryParams.BATTRIBUTES.key(), query); fixComplexQueryParam(QueryParams.NATTRIBUTES.key(), query); QueryParams queryParam = QueryParams.getParam(entry.getKey()) != null ? QueryParams.getParam(entry.getKey()) : QueryParams.getParam(key); if (queryParam == null) { throw new CatalogDBException("Unexpected parameter " + entry.getKey() + ". The parameter does not exist or cannot be " switch (queryParam) { case UID: addAutoOrQuery("projects." + queryParam.key(), queryParam.key(), query, queryParam.type(), andBsonList); break; case USER_ID: addAutoOrQuery(PRIVATE_ID, queryParam.key(), query, queryParam.type(), andBsonList); break; case ATTRIBUTES: addAutoOrQuery("projects." + entry.getKey(), entry.getKey(), query, queryParam.type(), andBsonList); break; case BATTRIBUTES: String mongoKey = "projects." + entry.getKey().replace(QueryParams.BATTRIBUTES.key(), QueryParams.ATTRIBUTES.key()); addAutoOrQuery(mongoKey, entry.getKey(), query, queryParam.type(), andBsonList); break; case NATTRIBUTES: mongoKey = "projects." + entry.getKey().replace(QueryParams.NATTRIBUTES.key(), QueryParams.ATTRIBUTES.key()); addAutoOrQuery(mongoKey, entry.getKey(), query, queryParam.type(), andBsonList); break; case CREATION_DATE: addAutoOrQuery(PRIVATE_CREATION_DATE, queryParam.key(), query, queryParam.type(), andBsonList);
project.put(ProjectDBAdaptor.QueryParams.UID.key(), ParamUtils.getAsLong(project.get(ProjectDBAdaptor.QueryParams.UID.key()))); project.put(ProjectDBAdaptor.QueryParams.SIZE.key(), ParamUtils.getAsLong(project.get(ProjectDBAdaptor.QueryParams.SIZE.key()))); if (projectDBAdaptor.exists((Long) project.get(ProjectDBAdaptor.QueryParams.UID.key()))) { throw new CatalogException("The database is not empty. Project " + project.get(ProjectDBAdaptor.QueryParams.NAME.key()) + " already exists");
ProjectDBAdaptor.QueryParams.UID.key(), ProjectDBAdaptor.QueryParams.CURRENT_RELEASE.key() )) .append(QueryOptions.EXCLUDE, "studies"); Query query = new Query(ProjectDBAdaptor.QueryParams.UID.key(), projectId); DBIterator dbIterator = projectDBAdaptor.nativeIterator(query, QueryOptions.empty()); exportToFile(dbIterator, outputDir.resolve("projects.json").toFile(), objectMapper, "project");
ProjectDBAdaptor.QueryParams.UID.key(), ProjectDBAdaptor.QueryParams.UUID.key(), ProjectDBAdaptor.QueryParams.ID.key(), ProjectDBAdaptor.QueryParams.FQN.key(), ProjectDBAdaptor.QueryParams.CURRENT_RELEASE.key())); Query query = new Query(ProjectDBAdaptor.QueryParams.USER_ID.key(), userId); if (isUuid) { query.putIfNotEmpty(ProjectDBAdaptor.QueryParams.UUID.key(), projectStr); } else { query.putIfNotEmpty(ProjectDBAdaptor.QueryParams.ID.key(), auxProject); query = new Query(ProjectDBAdaptor.QueryParams.FQN.key(), projectFqnSet); return projectDBAdaptor.get(query, projectOptions).first(); } else {
@Test public void testSampleVersioning() throws CatalogException { Query query = new Query(ProjectDBAdaptor.QueryParams.USER_ID.key(), "user"); String projectId = catalogManager.getProjectManager().get(query, null, sessionIdUser).first().getId();
if (parameters.containsKey(ProjectDBAdaptor.QueryParams.ID.key())) { editId(project, parameters.getString(ProjectDBAdaptor.QueryParams.ID.key()), sessionId); parameters.remove(ProjectDBAdaptor.QueryParams.ID.key()); if (parameters.containsKey(ProjectDBAdaptor.QueryParams.ORGANISM_SCIENTIFIC_NAME.key()) || parameters.containsKey(ProjectDBAdaptor.QueryParams.ORGANISM_COMMON_NAME.key()) || parameters.containsKey(ProjectDBAdaptor.QueryParams.ORGANISM_TAXONOMY_CODE.key()) || parameters.containsKey(ProjectDBAdaptor.QueryParams.ORGANISM_ASSEMBLY.key())) { QueryResult<Project> projectQR = projectDBAdaptor .get(projectId, new QueryOptions(QueryOptions.INCLUDE, ProjectDBAdaptor.QueryParams.ORGANISM.key())); if (projectQR.getNumResults() == 0) { throw new CatalogException("Project " + projectId + " not found"); if (parameters.containsKey(ProjectDBAdaptor.QueryParams.ORGANISM_SCIENTIFIC_NAME.key()) && StringUtils.isEmpty(projectQR.first().getOrganism().getScientificName())) { objectMap.put(ProjectDBAdaptor.QueryParams.ORGANISM_SCIENTIFIC_NAME.key(), parameters.getString(ProjectDBAdaptor.QueryParams.ORGANISM_SCIENTIFIC_NAME.key())); parameters.remove(ProjectDBAdaptor.QueryParams.ORGANISM_SCIENTIFIC_NAME.key()); if (parameters.containsKey(ProjectDBAdaptor.QueryParams.ORGANISM_COMMON_NAME.key()) && StringUtils.isEmpty(projectQR.first().getOrganism().getCommonName())) { objectMap.put(ProjectDBAdaptor.QueryParams.ORGANISM_COMMON_NAME.key(), parameters.getString(ProjectDBAdaptor.QueryParams.ORGANISM_COMMON_NAME.key())); parameters.remove(ProjectDBAdaptor.QueryParams.ORGANISM_COMMON_NAME.key()); if (parameters.containsKey(ProjectDBAdaptor.QueryParams.ORGANISM_TAXONOMY_CODE.key()) && projectQR.first().getOrganism().getTaxonomyCode() <= 0) { objectMap.put(ProjectDBAdaptor.QueryParams.ORGANISM_TAXONOMY_CODE.key(),
List<Long> projectUids = query.getAsLongList(QueryParams.UID.key()); Query studyQuery = new Query(); if (projectUids != null && projectUids.size() > 0) { studyQuery.append(StudyDBAdaptor.QueryParams.PROJECT_UID.key(), projectUids); List<String> projectIds = query.getAsStringList(QueryParams.ID.key()); if (projectIds != null && projectIds.size() > 0) { studyQuery.append(StudyDBAdaptor.QueryParams.PROJECT_ID.key(), projectIds); studyQuery.putIfNotEmpty(StudyDBAdaptor.QueryParams.UID.key(), query.getString(QueryParams.STUDY_UID.key())); studyQuery.putIfNotEmpty(StudyDBAdaptor.QueryParams.ID.key(), query.getString(QueryParams.STUDY_ID.key())); studyQuery.putIfNotEmpty(StudyDBAdaptor.QueryParams.OWNER.key(), query.getString(QueryParams.USER_ID.key())); QueryResult<Document> queryResult = dbAdaptorFactory.getCatalogStudyDBAdaptor().nativeGet(studyQuery, new QueryOptions(), user); query.remove(QueryParams.STUDY_UID.key()); query.remove(QueryParams.STUDY_ID.key()); if (!StringUtils.isEmpty(query.getString(QueryParams.USER_ID.key())) && !user.equals(query.getString(QueryParams.USER_ID.key()))) { query.put(QueryParams.USER_ID.key(), user); } else { query.put(QueryParams.UID.key(), projectUids);
String[] acceptedParams = {QueryParams.NAME.key(), QueryParams.CREATION_DATE.key(), QueryParams.DESCRIPTION.key(), QueryParams.ORGANIZATION.key(), QueryParams.LAST_MODIFIED.key(), QueryParams.ORGANISM_SCIENTIFIC_NAME.key(), QueryParams.ORGANISM_COMMON_NAME.key(), QueryParams.ORGANISM_ASSEMBLY.key(), }; for (String s : acceptedParams) { if (parameters.containsKey(s)) { String[] acceptedIntParams = {QueryParams.SIZE.key(), QueryParams.ORGANISM_TAXONOMY_CODE.key(), }; for (String s : acceptedIntParams) { if (parameters.containsKey(s)) { Map<String, Object> attributes = parameters.getMap(QueryParams.ATTRIBUTES.key()); if (attributes != null) { for (Map.Entry<String, Object> entry : attributes.entrySet()) { if (parameters.containsKey(QueryParams.STATUS_NAME.key())) { projectParameters.put("projects.$." + QueryParams.STATUS_NAME.key(), parameters.get(QueryParams.STATUS_NAME.key())); projectParameters.put("projects.$." + QueryParams.STATUS_DATE.key(), TimeUtils.getTime()); projectParameters.put(QueryParams.MODIFICATION_DATE.key(), time); projectParameters.put(PRIVATE_MODIFICATION_DATE, date);
Project project = catalogManager.getProjectManager().get(new Query(ProjectDBAdaptor.QueryParams.FQN.key(), projectFqn), new QueryOptions(), sessionId).first(); studyInfo.setProjectUid(project.getUid());
throws CatalogException { ParamUtils.checkParameter(name, ProjectDBAdaptor.QueryParams.NAME.key()); ParamUtils.checkParameter(scientificName, ProjectDBAdaptor.QueryParams.ORGANISM_SCIENTIFIC_NAME.key()); ParamUtils.checkParameter(assembly, ProjectDBAdaptor.QueryParams.ORGANISM_ASSEMBLY.key()); ParamUtils.checkAlias(id, ProjectDBAdaptor.QueryParams.ID.key()); ParamUtils.checkParameter(sessionId, "token");
private MongoCursor<Document> getMongoCursor(Query query, QueryOptions options) throws CatalogDBException { if (!query.containsKey(QueryParams.STATUS_NAME.key())) { query.append(QueryParams.STATUS_NAME.key(), "!=" + Status.DELETED); List<String> optionsAsStringList = options.getAsStringList(QueryOptions.INCLUDE); includeList.addAll(optionsAsStringList.stream().collect(Collectors.toList())); if (!includeList.contains(QueryParams.UID.key())) { includeList.add(QueryParams.UID.key());
objectMap.put(ProjectDBAdaptor.QueryParams.ORGANISM_TAXONOMY_CODE.key(), 55); QueryResult<Project> update = catalogManager.getProjectManager().update(pr.getId(), objectMap, null, sessionIdUser); objectMap.put(ProjectDBAdaptor.QueryParams.ORGANISM_COMMON_NAME.key(), "common"); objectMap.put(ProjectDBAdaptor.QueryParams.ORGANISM_ASSEMBLY.key(), "assembly");
@Test public void testGetAllStudies() throws CatalogException { Query query = new Query(ProjectDBAdaptor.QueryParams.USER_ID.key(), "user"); String projectId = catalogManager.getProjectManager().get(query, null, sessionIdUser).first().getId(); catalogManager.getStudyManager().create(projectId, "study_1", null, "study_1", Study.Type.CASE_CONTROL, "creationDate",
if (StringUtils.isNotEmpty(query.getString(ProjectDBAdaptor.QueryParams.STUDY.key()))) { List<String> studyList = query.getAsStringList(ProjectDBAdaptor.QueryParams.STUDY.key()); List<Long> idList = new ArrayList<>(); List<String> aliasList = new ArrayList<>(); query.remove(ProjectDBAdaptor.QueryParams.STUDY.key()); if (CollectionUtils.isNotEmpty(idList)) { query.put(ProjectDBAdaptor.QueryParams.STUDY_UID.key(), StringUtils.join(idList, ",")); query.put(ProjectDBAdaptor.QueryParams.STUDY_ID.key(), StringUtils.join(aliasList, ","));
@Deprecated @Override public QueryResult<Project> delete(long id, QueryOptions queryOptions) throws CatalogDBException { long startTime = startQuery(); checkId(id); // Check the project is active Query query = new Query(QueryParams.UID.key(), id).append(QueryParams.STATUS_NAME.key(), Status.READY); if (count(query).first() == 0) { query.put(QueryParams.STATUS_NAME.key(), Status.DELETED); QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, QueryParams.STATUS_NAME.key()); Project project = get(query, options).first(); throw new CatalogDBException("The project {" + id + "} was already " + project.getStatus().getName()); } // If we don't find the force parameter, we check first if the user does not have an active project. if (!queryOptions.containsKey(FORCE) || !queryOptions.getBoolean(FORCE)) { checkCanDelete(id); } if (queryOptions.containsKey(FORCE) && queryOptions.getBoolean(FORCE)) { // Delete the active studies (if any) query = new Query(StudyDBAdaptor.QueryParams.PROJECT_ID.key(), id); dbAdaptorFactory.getCatalogStudyDBAdaptor().delete(query, queryOptions); } // Change the status of the project to deleted setStatus(id, Status.DELETED); query = new Query(QueryParams.UID.key(), id) .append(QueryParams.STATUS_NAME.key(), Status.DELETED); return endQuery("Delete project", startTime, get(query, queryOptions)); }
@Test public void testModifyProject() throws CatalogException { String newProjectName = "ProjectName " + StringUtils.randomString(10); String projectId = catalogManager.getUserManager().get("user", null, new QueryOptions(), sessionIdUser).first().getProjects().get(0) .getId(); ObjectMap options = new ObjectMap(); options.put("name", newProjectName); ObjectMap attributes = new ObjectMap("myBoolean", true); attributes.put("value", 6); attributes.put("object", new ObjectMap("id", 1234)); options.put("attributes", attributes); catalogManager.getProjectManager().update(projectId, options, null, sessionIdUser); QueryResult<Project> result = catalogManager.getProjectManager().get(projectId, null, sessionIdUser); Project project = result.first(); System.out.println(result); assertEquals(newProjectName, project.getName()); for (Map.Entry<String, Object> entry : attributes.entrySet()) { assertEquals(project.getAttributes().get(entry.getKey()), entry.getValue()); } options = new ObjectMap(); options.put(ProjectDBAdaptor.QueryParams.ID.key(), "newProjectId"); catalogManager.getProjectManager().update(projectId, options, null, sessionIdUser); thrown.expect(CatalogException.class); thrown.expectMessage("not found"); catalogManager.getProjectManager().update(projectId, options, null, sessionIdUser); }
/** * At the moment it does not clean external references to itself. */ // @Override // public QueryResult<Integer> deleteProject(int projectId) throws CatalogDBException { // long startTime = startQuery(); // DBObject query = new BasicDBObject(UserDBAdaptor.QueryParams.PROJECTS_UID.key(), projectId); // DBObject pull = new BasicDBObject("$pull", // new BasicDBObject("projects", // new BasicDBObject(UserDBAdaptor.QueryParams.ID.key(), projectId))); // // QueryResult<WriteResult> update = userCollection.update(query, pull, null); // List<Integer> deletes = new LinkedList<>(); // if (update.getResult().get(0).getN() == 0) { // throw CatalogDBException.idNotFound("Project", projectId); // } else { // deletes.add(update.getResult().get(0).getN()); // return endQuery("delete project", startTime, deletes); // } // } @Override public QueryResult<Project> get(String userId, QueryOptions options) throws CatalogDBException { long startTime = startQuery(); Query query = new Query(QueryParams.USER_ID.key(), userId); return endQuery("User projects list", startTime, get(query, options).getResult()); }
public QueryResult<User> delete(String id, QueryOptions queryOptions) throws CatalogDBException { long startTime = startQuery(); checkId(id); // Check the user is active or banned Query query = new Query(QueryParams.ID.key(), id) .append(QueryParams.STATUS_NAME.key(), User.UserStatus.READY + "," + User.UserStatus.BANNED); if (count(query).first() == 0) { query.put(QueryParams.STATUS_NAME.key(), User.UserStatus.DELETED); QueryOptions options = new QueryOptions(MongoDBCollection.INCLUDE, QueryParams.STATUS_NAME.key()); User user = get(query, options).first(); throw new CatalogDBException("The user {" + id + "} was already " + user.getStatus().getName()); } // If we don't find the force parameter, we check first if the user does not have an active project. if (!queryOptions.containsKey(FORCE) || !queryOptions.getBoolean(FORCE)) { checkCanDelete(id); } if (queryOptions.containsKey(FORCE) && queryOptions.getBoolean(FORCE)) { // Delete the active projects (if any) query = new Query(ProjectDBAdaptor.QueryParams.USER_ID.key(), id); dbAdaptorFactory.getCatalogProjectDbAdaptor().delete(query, queryOptions); } // Change the status of the user to deleted setStatus(id, User.UserStatus.DELETED); query = new Query(QueryParams.ID.key(), id) .append(QueryParams.STATUS_NAME.key(), User.UserStatus.DELETED); return endQuery("Delete user", startTime, get(query, queryOptions)); }
@Override public QueryResult nativeGet(Query query, QueryOptions options) throws CatalogDBException { if (!query.containsKey(QueryParams.STATUS_NAME.key())) { query.append(QueryParams.STATUS_NAME.key(), "!=" + Status.DELETED); } Bson bson = parseQuery(query); QueryResult<Document> queryResult = userCollection.find(bson, options); for (Document user : queryResult.getResult()) { ArrayList<Document> projects = (ArrayList<Document>) user.get("projects"); if (projects.size() > 0) { List<Document> projectsTmp = new ArrayList<>(projects.size()); for (Document project : projects) { Query query1 = new Query(ProjectDBAdaptor.QueryParams.UID.key(), project.get(ProjectDBAdaptor .QueryParams.UID.key())); QueryResult<Document> queryResult1 = dbAdaptorFactory.getCatalogProjectDbAdaptor().nativeGet(query1, options); projectsTmp.add(queryResult1.first()); } user.remove("projects"); user.append("projects", projectsTmp); } } return queryResult; }