public static DataStore getDataStoreByProjectId(CatalogManager catalogManager, String projectStr, File.Bioformat bioformat, String sessionId) throws CatalogException { DataStore dataStore; QueryOptions queryOptions = new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(ProjectDBAdaptor.QueryParams.ID.key(), ProjectDBAdaptor.QueryParams.DATASTORES.key())); Project project = catalogManager.getProjectManager().get(projectStr, queryOptions, sessionId).first(); if (project.getDataStores() != null && project.getDataStores().containsKey(bioformat)) { dataStore = project.getDataStores().get(bioformat); } else { //get default datastore //Must use the UserByStudyId instead of the file owner. String userId = catalogManager.getProjectManager().getOwner(project.getUid()); // Replace possible dots at the userId. Usually a special character in almost all databases. See #532 userId = userId.replace('.', '_'); String databasePrefix = catalogManager.getConfiguration().getDatabasePrefix(); String dbName = buildDatabaseName(databasePrefix, userId, project.getId()); dataStore = new DataStore(StorageEngineFactory.get().getDefaultStorageEngineId(), dbName); } return dataStore; }
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); }
@Before public void setUp() throws IOException, CatalogException, URISyntaxException { catalogManager = catalogManagerExternalResource.getCatalogManager(); catalogManager.getUserManager().create("user", "User Name", "mail@ebi.ac.uk", PASSWORD, "", null, Account.FULL, null, null); sessionIdUser = catalogManager.getUserManager().login("user", PASSWORD); project = catalogManager.getProjectManager().create("1000G", "Project about some genomes", "", "ACME", "Homo sapiens", null, null, "GRCh38", new QueryOptions(), sessionIdUser).first(); study = catalogManager.getStudyManager().create(project.getId(), "phase1", null, "Phase 1", Study.Type.TRIO, null, "Done", null, null, null, null, null, null, null, null, sessionIdUser).first(); folder = catalogManager.getFileManager().createFolder(study.getId(), Paths.get("data/vcf/").toString(), null, true, null, QueryOptions.empty(), sessionIdUser).first(); Path vcfPath = catalogManagerExternalResource.getOpencgaHome().resolve(VCF_FILE_NAME); Files.copy(this.getClass().getClassLoader().getResourceAsStream("biofiles/" + VCF_FILE_NAME), vcfPath, StandardCopyOption.REPLACE_EXISTING); vcfFileUri = vcfPath.toUri(); Path bamPath = catalogManagerExternalResource.getOpencgaHome().resolve(BAM_FILE_NAME); Files.copy(this.getClass().getClassLoader().getResourceAsStream("biofiles/" + BAM_FILE_NAME), bamPath, StandardCopyOption.REPLACE_EXISTING); bamFileUri = bamPath.toUri(); }
@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); }
@Test public void getProjectIdTest() throws CatalogDBException { assertTrue(catalogProjectDBAdaptor.getId(user3.getId(), user3.getProjects().get(0).getId()) != -1); assertTrue(catalogProjectDBAdaptor.getId(user3.getId(), "nonExistingProject") == -1); }
@Before public void setUp() throws IOException, CatalogException { catalogManager = catalogManagerExternalResource.getCatalogManager(); catalogManager.getUserManager().create("user", "User Name", "mail@ebi.ac.uk", PASSWORD, "", null, Account.FULL, null, null); sessionIdUser = catalogManager.getUserManager().login("user", PASSWORD); project = catalogManager.getProjectManager().create("1000G", "Project about some genomes", "", "ACME", "Homo sapiens", null, null, "GRCh38", new QueryOptions(), sessionIdUser).first(); study = catalogManager.getStudyManager().create(project.getId(), "phase1", null, "Phase 1", Study.Type.TRIO, null, "Done", null, null, null, null, null, null, null, null, sessionIdUser).first(); folder = catalogManager.getFileManager().createFolder(study.getId(), Paths.get("data/test/folder/").toString(), null, true, null, QueryOptions.empty(), sessionIdUser).first(); directory = catalogManagerExternalResource.getOpencgaHome().resolve("catalog_scan_test_folder").toAbsolutePath(); if (directory.toFile().exists()) { IOUtils.deleteDirectory(directory); } Files.createDirectory(directory); }
@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", "description", new Status(), null, null, null, null, null, null, null, sessionIdUser);
@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()); }
public void setUpCatalogManager(CatalogManager catalogManager) throws IOException, CatalogException { catalogManager.getUserManager().create("user", "User Name", "mail@ebi.ac.uk", PASSWORD, "", null, Account.FULL, null, null); sessionIdUser = catalogManager.getUserManager().login("user", PASSWORD); String projectId = catalogManager.getProjectManager().create("1000G", "Project about some genomes", "", "ACME", "Homo sapiens", null, null, "GRCh38", new QueryOptions(), sessionIdUser).first().getId(); catalogManager.getStudyManager().create(projectId, "phase1", null, "Phase 1", Study.Type.TRIO, null, "Done", null, null, null, null, null, null, null, null, sessionIdUser); }
public void setUpCatalogManager(CatalogManager catalogManager) throws IOException, CatalogException { catalogManager.getUserManager().create("user", "User Name", "mail@ebi.ac.uk", PASSWORD, "", null, Account.FULL, null, null); sessionIdUser = catalogManager.getUserManager().login("user", PASSWORD); String projectId = catalogManager.getProjectManager().create("1000G", "Project about some genomes", "", "ACME", "Homo sapiens", null, null, "GRCh38", new QueryOptions(), sessionIdUser).first().getId(); catalogManager.getStudyManager().create(projectId, "phase1", null, "Phase 1", Study.Type.TRIO, null, "Done", null, null, null, null, null, null, null, null, sessionIdUser); }
String projectErrorMsg = dbAdaptorFactory.getCatalogProjectDbAdaptor().insert(p, user.getId(), options).getErrorMsg(); if (projectErrorMsg != null && !projectErrorMsg.isEmpty()) { errorMsg += ", " + p.getId() + ":" + projectErrorMsg;
private void setUpCatalogManager(CatalogManager catalogManager) throws IOException, CatalogException { catalogManager.getUserManager().create("user", "User Name", "mail@ebi.ac.uk", PASSWORD, "", null, Account.FULL, null, null); sessionIdUser = catalogManager.getUserManager().login("user", PASSWORD); String projectId = catalogManager.getProjectManager().create("1000G", "Project about some genomes", "", "ACME", "Homo sapiens", null, null, "GRCh38", new QueryOptions(), sessionIdUser).first().getId(); catalogManager.getStudyManager().create(projectId, "phase1", null, "Phase 1", Study.Type.TRIO, null, "Done", null, null, null, null, null, null, null, null, sessionIdUser); }
null, null, "GRCh38", new QueryOptions(), userSessionId).getResult().get(0).getId(); Study study = catalogManager.getStudyManager().create(projectId, "std", "std", "std", Study.Type.CONTROL_SET, null, "", null, null, null, null, null, null, null, null, userSessionId).getResult().get(0);
null, null, "GRCh38", new QueryOptions(), sessionId).first().getId(); Study study = catalogManager.getStudyManager().create(projectId, "s1", null, "s1", Study.Type.CASE_CONTROL, null, "Study " + "1", null, null, null, null, Collections.singletonMap(File.Bioformat.VARIANT, new DataStore("mongodb", DB_NAME)), null,
public void setUpCatalogManager(CatalogManager catalogManager) throws IOException, CatalogException { catalogManager.getUserManager().create("user", "User Name", "mail@ebi.ac.uk", PASSWORD, "", null, Account.FULL, null, null); catalogManager.getUserManager().create("user2", "User2 Name", "mail2@ebi.ac.uk", PASSWORD, "", null, Account.FULL, null, null); catalogManager.getUserManager().create("user3", "User3 Name", "user.2@e.mail", PASSWORD, "ACME", null, Account.FULL, null, null); sessionIdUser = catalogManager.getUserManager().login("user", PASSWORD); sessionIdUser2 = catalogManager.getUserManager().login("user2", PASSWORD); sessionIdUser3 = catalogManager.getUserManager().login("user3", PASSWORD); project1 = catalogManager.getProjectManager().create("1000G", "Project about some genomes", "", "ACME", "Homo sapiens", null, null, "GRCh38", new QueryOptions(), sessionIdUser).first().getId(); project2 = catalogManager.getProjectManager().create("pmp", "Project Management Project", "life art intelligent system", "myorg", "Homo sapiens", null, null, "GRCh38", new QueryOptions(), sessionIdUser2).first().getId(); project3 = catalogManager.getProjectManager().create("p1", "project 1", "", "", "Homo sapiens", null, null, "GRCh38", new QueryOptions(), sessionIdUser3).first().getId(); studyId = catalogManager.getStudyManager().create(project1, "phase1", null, "Phase 1", Study.Type.TRIO, null, "Done", null, null, null, null, null, null, null, null, sessionIdUser).first().getFqn(); studyId2 = catalogManager.getStudyManager().create(project1, "phase3", null, "Phase 3", Study.Type.CASE_CONTROL, null, "d", null, null, null, null, null, null, null, null, sessionIdUser).first().getFqn(); studyId3 = catalogManager.getStudyManager().create(project2, "s1", null, "Study 1", Study.Type.CONTROL_SET, null, "", null, null, null, null, null, null, null, null, sessionIdUser2).first().getFqn(); }
@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); }
projectAlias = "p1"; projectId = catalogManager.getProjectManager().create(projectAlias, projectAlias, "Project 1", "ACME", "Homo sapiens", null, null, "GRCh38", new QueryOptions(), sessionId).first().getId(); Study study = catalogManager.getStudyManager().create(projectId, "s1", "s1", "s1", Study.Type.CASE_CONTROL, null, "Study 1", null, null, null, null, Collections.singletonMap(File.Bioformat.VARIANT, new DataStore(getStorageEngine(), dbName)), null, Collections.singletonMap(VariantStorageEngine.Options.AGGREGATED_TYPE.key(), getAggregation()), null, sessionId)
/** * 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); } }
assertEquals(2, queryResult.getNumResults()); for (Project project : queryResult.getResult()) { if (project.getId().equals(project2)) { assertEquals(2, project.getStudies().size()); } else {
QueryResult<Project> update = catalogManager.getProjectManager().update(pr.getId(), objectMap, null, sessionIdUser); objectMap.put(ProjectDBAdaptor.QueryParams.ORGANISM_COMMON_NAME.key(), "common"); update = catalogManager.getProjectManager().update(pr.getId(), objectMap, null, sessionIdUser); catalogManager.getProjectManager().update(pr.getId(), objectMap, null, sessionIdUser);