/** * Reads a project from Catalog given a project id or alias. * * @param projectStr Project id or alias. * @param options Read options * @param sessionId sessionId * @return The specified object * @throws CatalogException CatalogException */ @Deprecated public QueryResult<Project> get(String projectStr, QueryOptions options, String sessionId) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(sessionId); Project project = resolveId(projectStr, userId); return projectDBAdaptor.get(project.getUid(), options); }
default boolean exists(long projectId) throws CatalogDBException { return count(new Query(QueryParams.UID.key(), projectId)).first() > 0; }
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.nativeInsert(project, owner);
@Test public void incrementCurrentRelease() throws CatalogDBException { long projectId = catalogProjectDBAdaptor.getId(user3.getId(), user3.getProjects().get(0).getId()); QueryResult<Project> projectQueryResult = catalogProjectDBAdaptor.get(projectId, new QueryOptions(QueryOptions.INCLUDE, ProjectDBAdaptor.QueryParams.CURRENT_RELEASE.key())); assertEquals(1, projectQueryResult.first().getCurrentRelease()); assertEquals(2, catalogProjectDBAdaptor.incrementCurrentRelease(projectId).first().intValue()); assertEquals(3, catalogProjectDBAdaptor.incrementCurrentRelease(projectId).first().intValue()); }
@Test public void deleteProjectTest() throws CatalogException { Project p = new Project("2000G", "Project about some more genomes", null, "Cool", new Status(), "", 3000, "", null, 1); QueryResult<Project> result = catalogProjectDBAdaptor.insert(p, user1.getId(), null); System.out.println(result.first().getStatus()); p = result.first(); QueryResult<Project> queryResult = catalogProjectDBAdaptor.delete(p.getUid(), new QueryOptions()); System.out.println(queryResult.first().getStatus()); assertTrue(queryResult.getNumResults() == 1); //thrown.expect(CatalogDBException.class); //catalogProjectDBAdaptor.delete(p.getId()); thrown.expect(CatalogDBException.class); //Expected "Project not found" exception catalogProjectDBAdaptor.delete(-1, new QueryOptions()); }
/** * cases: * ok: correct projectId, correct newName * error: non-existent projectId * error: newName already used * error: newName == oldName * * @throws CatalogDBException */ @Test public void renameProjectTest() throws CatalogException { Project p1 = catalogProjectDBAdaptor.insert(new Project("p1", "project1", null, "Cool", new Status(), "", 3000, "", null, 1), user1.getId(), null).first(); Project p2 = catalogProjectDBAdaptor.insert(new Project("p2", "project2", null, "Cool", new Status(), "", 3000, "", null, 1), user1.getId(), null).first(); catalogProjectDBAdaptor.editId(user1.getId(), p1.getUid(), "p1", "newpmp"); try { catalogProjectDBAdaptor.editId(user1.getId(), -1, "", "falseProject"); fail("renamed project with projectId=-1"); } catch (CatalogDBException e) { System.out.println("correct exception: " + e); } try { catalogProjectDBAdaptor.editId(user1.getId(), p1.getUid(), "newpmp", p2.getId()); fail("renamed project with name collision"); } catch (CatalogDBException e) { System.out.println("correct exception: " + e); } }
@Test public void getProjectTest() throws CatalogDBException { long projectId = catalogProjectDBAdaptor.getId(user3.getId(), user3.getProjects().get(0).getId()); System.out.println("projectId = " + projectId); QueryResult<Project> project = catalogProjectDBAdaptor.get(projectId, null); System.out.println(project); assertNotNull(project.first()); thrown.expect(CatalogDBException.class); //"Expected \"bad id\" exception" catalogProjectDBAdaptor.get(-100, null); }
|| 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"); queryResult = projectDBAdaptor.update(projectId, objectMap, QueryOptions.empty()); } else { throw new CatalogException("Cannot update organism information that is already filled in"); queryResult = projectDBAdaptor.update(projectId, parameters, QueryOptions.empty());
@Test public void createProjectTest() throws CatalogException, JsonProcessingException { Project p = new Project("1000G", "Project about some genomes", "Today", "Cool", new Status(), "", 1000, "", null, 1); System.out.println(catalogProjectDBAdaptor.insert(p, user1.getId(), null)); p = new Project("2000G", "Project about some more genomes", "Tomorrow", "Cool", new Status(), "", 3000, "", null, 1); System.out.println(catalogProjectDBAdaptor.insert(p, user1.getId(), null)); p = new Project("pmp", "Project management project", "yesterday", "it is a system", new Status(), "", 2000, "", null, 1); System.out.println(catalogProjectDBAdaptor.insert(p, user2.getId(), null)); System.out.println(catalogProjectDBAdaptor.insert(p, user1.getId(), null)); try { System.out.println(catalogProjectDBAdaptor.insert(p, user1.getId(), null)); fail("Expected \"projectAlias already exists\" exception"); } catch (CatalogDBException e) { System.out.println(e); } }
void editId(Project project, String newProjectId, String sessionId) throws CatalogException { ParamUtils.checkAlias(newProjectId, "new project id"); ParamUtils.checkParameter(sessionId, "sessionId"); String userId = this.catalogManager.getUserManager().getUserId(sessionId); authorizationManager.checkCanEditProject(project.getUid(), userId); String owner = project.getFqn().split("@")[0]; if (StringUtils.isEmpty(owner)) { throw new CatalogException("Internal error. Project fqn required"); } userDBAdaptor.updateUserLastModified(userId); projectDBAdaptor.editId(owner, project.getUid(), project.getId(), newProjectId); auditManager.recordUpdate(AuditRecord.Resource.project, project.getUid(), userId, new ObjectMap(ProjectDBAdaptor.QueryParams.ID.key(), newProjectId), null, null); }
public QueryResult<Integer> incrementRelease(String projectStr, String sessionId) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(sessionId); Project project = resolveId(projectStr, userId); long projectId = project.getUid(); authorizationManager.checkCanEditProject(projectId, userId); // Obtain the current release number int currentRelease = project.getCurrentRelease(); // Check current release has been used at least in one study or file or cohort or individual... List<Study> allStudiesInProject = project.getStudies(); if (allStudiesInProject.isEmpty()) { throw new CatalogException("Cannot increment current release number. No studies found for release " + currentRelease); } if (checkCurrentReleaseInUse(allStudiesInProject, currentRelease)) { // Increment current project release QueryResult<Integer> integerQueryResult = projectDBAdaptor.incrementCurrentRelease(projectId); // Upgrade release in sample, family and individuals for (Study study : allStudiesInProject) { sampleDBAdaptor.updateProjectRelease(study.getUid(), integerQueryResult.first()); individualDBAdaptor.updateProjectRelease(study.getUid(), integerQueryResult.first()); familyDBAdaptor.updateProjectRelease(study.getUid(), integerQueryResult.first()); panelDBAdaptor.updateProjectRelease(study.getUid(), integerQueryResult.first()); } return integerQueryResult; } else { throw new CatalogException("Cannot increment current release number. The current release " + currentRelease + " has not yet " + "been used in any entry"); } }
public String getOwner(long projectId) throws CatalogException { return projectDBAdaptor.getOwnerId(projectId); }
public QueryResult groupBy(String userId, Query query, String field, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); ParamUtils.checkObj(field, "field"); ParamUtils.checkObj(userId, "userId"); ParamUtils.checkObj(sessionId, "sessionId"); String userOfQuery = this.catalogManager.getUserManager().getUserId(sessionId); if (!userOfQuery.equals(userId)) { // The user cannot read projects of other users. throw CatalogAuthorizationException.cantRead(userOfQuery, "Project", -1, userId); } // TODO: In next release, we will have to check the count parameter from the queryOptions object. boolean count = true; QueryResult queryResult = null; if (count) { // We do not need to check for permissions when we show the count of files queryResult = projectDBAdaptor.groupBy(query, field, options); } return ParamUtils.defaultObject(queryResult, QueryResult::new); }
default void checkId(long projectId) throws CatalogDBException { if (projectId < 0) { throw CatalogDBException.newInstance("Project id '{}' is not valid: ", projectId); } if (!exists(projectId)) { throw CatalogDBException.newInstance("Project id '{}' does not exist", projectId); } }
QueryResult<Project> queryResult = projectDBAdaptor.insert(project, userId, options); project = queryResult.getResult().get(0); } catch (CatalogIOException e) { try { projectDBAdaptor.delete(project.getUid()); } catch (Exception e1) { logger.error("Error deleting project from catalog after failing creating the folder in the filesystem", e1);
@Override public void checkCanEditProject(long projectId, String userId) throws CatalogException { if (projectDBAdaptor.getOwnerId(projectId).equals(userId)) { return; } throw new CatalogAuthorizationException("Permission denied: Only the owner of the project can update it."); }
public QueryResult groupBy(String userId, Query query, List<String> fields, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); ParamUtils.checkObj(fields, "fields"); ParamUtils.checkObj(userId, "userId"); ParamUtils.checkObj(sessionId, "sessionId"); String userOfQuery = this.catalogManager.getUserManager().getUserId(sessionId); if (!userOfQuery.equals(userId)) { // The user cannot read projects of other users. throw CatalogAuthorizationException.cantRead(userOfQuery, "Project", -1, userId); } // TODO: In next release, we will have to check the count parameter from the queryOptions object. boolean count = true; QueryResult queryResult = null; if (count) { // We do not need to check for permissions when we show the count of files queryResult = projectDBAdaptor.groupBy(query, fields, options); } return ParamUtils.defaultObject(queryResult, QueryResult::new); }
private int getProjectCurrentRelease(long projectId) throws CatalogException { QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, ProjectDBAdaptor.QueryParams.CURRENT_RELEASE.key()); QueryResult<Project> projectQueryResult = projectDBAdaptor.get(projectId, options); if (projectQueryResult.getNumResults() == 0) { throw new CatalogException("Internal error. Cannot retrieve current release from project"); } return projectQueryResult.first().getCurrentRelease(); }
@Override public void checkCanViewProject(long projectId, String userId) throws CatalogException { if (userId.equals(ADMIN)) { return; } if (projectDBAdaptor.getOwnerId(projectId).equals(userId)) { return; } // Only members of any study belonging to the project can view the project final Query query = new Query() .append(StudyDBAdaptor.QueryParams.PROJECT_ID.key(), projectId) .append(StudyDBAdaptor.QueryParams.GROUP_USER_IDS.key(), userId); if (studyDBAdaptor.count(query).first() > 0) { return; } throw CatalogAuthorizationException.deny(userId, "view", "Project", projectId, null); }