public String getStudyFQN() { return study != null ? study.getFqn() : null; }
.setAlias(study.getId()) .setAttributes(study.getAttributes()) .setCipher(study.getCipher()) .setCreationDate(study.getCreationDate()) .setDatasets(study.getDatasets().size()) .setDescription(study.getDescription()) .setDiskUsage(study.getSize()) .setExperiments(study.getExperiments()) .setGroups(study.getGroups()) .setName(study.getName()) .setStats(study.getStats()) .setStatus(study.getStatus()) .setType(study.getType()) .setVariableSets(study.getVariableSets()); new Query(FileDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()) .append(FileDBAdaptor.QueryParams.TYPE.key(), File.Type.FILE) .append(FileDBAdaptor.QueryParams.STATUS_NAME.key(), "!=" + File.FileStatus.TRASHED + ";!=" new Query(SampleDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()) .append(SampleDBAdaptor.QueryParams.STATUS_NAME.key(), "!=" + File.FileStatus.TRASHED + ";!=" + File.FileStatus.DELETED)) new Query(JobDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()) .append(JobDBAdaptor.QueryParams.STATUS_NAME.key(), "!=" + File.FileStatus.TRASHED + ";!=" + File.FileStatus.DELETED)) new Query(CohortDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()) .append(CohortDBAdaptor.QueryParams.STATUS_NAME.key(), "!=" + File.FileStatus.TRASHED + ";!="
private static DataStore getDataStore(CatalogManager catalogManager, Study study, File.Bioformat bioformat, String sessionId) throws CatalogException { DataStore dataStore; if (study.getDataStores() != null && study.getDataStores().containsKey(bioformat)) { dataStore = study.getDataStores().get(bioformat); } else { String projectId = catalogManager.getStudyManager().getProjectFqn(study.getFqn()); dataStore = getDataStoreByProjectId(catalogManager, projectId, bioformat, sessionId); } return dataStore; }
private void applyPermissionRules(Study study) { if (study.getPermissionRules().isEmpty()) { return; logger.info("Analysing study {} ({})", study.getId(), study.getUid()); for (Map.Entry<Study.Entity, List<PermissionRule>> myMap : study.getPermissionRules().entrySet()) { Study.Entity entry = myMap.getKey(); for (PermissionRule permissionRule : myMap.getValue()) { authorizationManager.applyPermissionRule(study.getUid(), permissionRule, entry); } else { logger.info("Removing permission rule {}", permissionRule.getId().split(INTERNAL_DELIMITER)[0], entry); authorizationManager.removePermissionRule(study.getUid(), permissionRule.getId(), entry); break; case REVERT:
if (studyIdExists(project.getUid(), study.getId())) { throw new CatalogDBException("Study {id:\"" + study.getId() + "\"} already exists"); study.setUid(newId); if (StringUtils.isEmpty(study.getUuid())) { study.setUuid(UUIDUtils.generateOpenCGAUUID(UUIDUtils.Entity.STUDY)); List<File> files = study.getFiles(); study.setFiles(Collections.emptyList()); List<Job> jobs = study.getJobs(); study.setJobs(Collections.emptyList()); List<Cohort> cohorts = study.getCohorts(); study.setCohorts(Collections.emptyList()); List<Dataset> datasets = study.getDatasets(); study.setDatasets(Collections.emptyList()); List<Panel> panels = study.getPanels(); study.setPanels(Collections.emptyList()); study.setFqn(project.getFqn() + ":" + study.getId()); if (StringUtils.isNotEmpty(study.getCreationDate())) { studyObject.put(PRIVATE_CREATION_DATE, TimeUtils.toDate(study.getCreationDate())); } else { studyObject.put(PRIVATE_CREATION_DATE, TimeUtils.getDate());
cohortSolrModel.setStudyId(study.getFqn().replace(":", "__")); cohortSolrModel.setType(cohort.getType().name()); SolrConverterUtil.parseInternalOpenCGAAcls((List<Map<String, Object>>) cohort.getAttributes().get("OPENCGA_ACL")); List<String> effectivePermissions = SolrConverterUtil.getEffectivePermissions((Map<String, Set<String>>) study.getAttributes().get("OPENCGA_ACL"), cohortAcl, "COHORT"); cohortSolrModel.setAcl(effectivePermissions);
public QueryResult<Group> getGroup(String studyStr, String groupId, String sessionId) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(sessionId); Study study = resolveId(studyStr, userId); authorizationManager.checkCanViewStudy(study.getUid(), userId); // Fix the groupId if (groupId != null && !groupId.startsWith("@")) { groupId = "@" + groupId; } return studyDBAdaptor.getGroup(study.getUid(), groupId, Collections.emptyList()); }
QueryOptions queryOptionsCopy = queryOptions == null ? new QueryOptions() : new QueryOptions(queryOptions); queryCopy.put(CatalogSolrQueryParser.QueryParams.STUDY.key(), study.getFqn()); if (!catalogManager.getAuthorizationManager().checkIsOwnerOrAdmin(study.getUid(), userId)) { study.getGroups().forEach(group -> { if (group.getUserIds().contains(userId)) { groups.add(group.getName()); SolrQuery solrQuery = catalogSolrQueryParser.parse(queryCopy, queryOptionsCopy, study.getVariableSets());
public Map<String, Object> facet(String projectStr, String fileFields, String sampleFields, String individualFields, String cohortFields, String familyFields, boolean defaultStats, String sessionId) throws CatalogException, IOException { String userId = catalogManager.getUserManager().getUserId(sessionId); Project project = resolveId(projectStr, userId); Query query = new Query(StudyDBAdaptor.QueryParams.PROJECT_UID.key(), project.getUid()); QueryResult<Study> studyQueryResult = catalogManager.getStudyManager().get(query, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(StudyDBAdaptor.QueryParams.FQN.key(), StudyDBAdaptor.QueryParams.ID.key())), sessionId); Map<String, Object> result = new HashMap<>(); for (Study study : studyQueryResult.getResult()) { result.put(study.getId(), catalogManager.getStudyManager().facet(study.getFqn(), fileFields, sampleFields, individualFields, cohortFields, familyFields, defaultStats, sessionId)); } return result; }
/** * Study methods * *************************** */ @Test public void testModifyStudy() throws Exception { Query query = new Query(StudyDBAdaptor.QueryParams.OWNER.key(), "user"); String studyId = catalogManager.getStudyManager().get(query, null, sessionIdUser).first().getId(); String newName = "Phase 1 " + StringUtils.randomString(20); String newDescription = StringUtils.randomString(500); ObjectMap parameters = new ObjectMap(); parameters.put("name", newName); parameters.put("description", newDescription); BasicDBObject attributes = new BasicDBObject("key", "value"); parameters.put("attributes", attributes); catalogManager.getStudyManager().update(studyId, parameters, null, sessionIdUser); QueryResult<Study> result = catalogManager.getStudyManager().get(studyId, null, sessionIdUser); System.out.println(result); Study study = result.first(); assertEquals(study.getName(), newName); assertEquals(study.getDescription(), newDescription); for (Map.Entry<String, Object> entry : attributes.entrySet()) { assertEquals(study.getAttributes().get(entry.getKey()), entry.getValue()); } }
private Cohort createDefaultCohort(Study study, String sessionId) throws CatalogException { return catalogManager.getCohortManager().create(study.getId(), StudyEntry.DEFAULT_COHORT, Study.Type.COLLECTION, DEFAULT_COHORT_DESCRIPTION, Collections.emptyList(), null, null, sessionId).first(); }
authorizationManager.checkStudyPermission(study.getUid(), userId, StudyAclEntry.StudyPermissions.WRITE_FILES); .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()) .append(FileDBAdaptor.QueryParams.STATUS_NAME.key(), "!=" + File.FileStatus.TRASHED + ";!=" + Status.DELETED + ";!=" + File.FileStatus.REMOVED) .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()) .append(FileDBAdaptor.QueryParams.STATUS_NAME.key(), "!=" + File.FileStatus.TRASHED + ";!=" + Status.DELETED + ";!=" + File.FileStatus.REMOVED) .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()) .append(FileDBAdaptor.QueryParams.STATUS_NAME.key(), "!=" + File.FileStatus.TRASHED + ";!=" + Status.DELETED + ";!=" + File.FileStatus.REMOVED) authorizationManager.checkStudyPermission(study.getUid(), userId, StudyAclEntry.StudyPermissions.WRITE_FILES); } else { .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()) .append(FileDBAdaptor.QueryParams.PATH.key(), pathDestiny); if (fileDBAdaptor.count(query).first() == 0) { if (parents) { URI studyURI = study.getUri(); createParents(study, userId, studyURI, catalogPath, true); long fileId = fileDBAdaptor.getId(study.getUid(), pathDestiny); authorizationManager.checkFilePermission(study.getUid(), fileId, userId, FileAclEntry.FilePermissions.WRITE); .append(FileDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid())
SolrConverterUtil.parseInternalOpenCGAAcls((List<Map<String, Object>>) study.getAttributes().get("OPENCGA_ACL")); study.getAttributes().put("OPENCGA_ACL", studyAcls); new Query(CohortDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()), queryOptions); catalogSolrManager.insertCatalogCollection(cohortDBIterator, new CatalogCohortToSolrCohortConverter(study), CatalogSolrManager.COHORT_SOLR_COLLECTION);
@Test public void FamilyToSolrTest() { Study study = new Study().setFqn("user@project:study").setAttributes(new HashMap<>()); Family family = new Family("id", "family", null, null, Arrays.asList(new Individual().setId("I1"), new Individual().setId("I2")), "test", 1000, AnnotationHelper.createAnnotation(), null); family.setUid(100).setStatus(new Family.FamilyStatus("READY")).setRelease(1).setVersion(2); FamilySolrModel familySolrModel = new CatalogFamilyToSolrFamilyConverter(study).convertToStorageType(family); assertEquals(familySolrModel.getUid(), family.getUid()); assertEquals(familySolrModel.getStatus(), family.getStatus().getName()); assertEquals(familySolrModel.getNumMembers(), family.getMembers().size()); assertEquals(familySolrModel.getRelease(), family.getRelease()); assertEquals(familySolrModel.getVersion(), family.getVersion()); assertEquals(familySolrModel.getPhenotypes().size(), 0); assertEquals(familySolrModel.getAnnotations().get("annotations__o__annotName.vsId.a.ab2.ab2c1.ab2c1d1"), Arrays.asList(1, 2, 3, 4, 11, 12, 13, 14, 21)); assertEquals(familySolrModel.getAnnotations().get("annotations__o__annotName.vsId.a.ab1.ab1c1"), Arrays.asList(true, false, false)); assertEquals(familySolrModel.getAnnotations().get("annotations__s__annotName.vsId.a.ab1.ab1c2"), "hello world"); assertEquals(familySolrModel.getAnnotations().get("annotations__o__annotName.vsId.a.ab2.ab2c1.ab2c1d2"), Arrays.asList("hello ab2c1d2 1", "hello ab2c1d2 2")); assertEquals(familySolrModel.getAnnotations().get("annotations__o__annotName.vsId.a.ab3.ab3c1.ab3c1d1"), Arrays.asList(Arrays.asList("hello"), Arrays.asList("hello2", "bye2"), Arrays.asList("byeee2", "hellooo2"))); assertEquals(familySolrModel.getAnnotations().get("annotations__o__annotName.vsId.a.ab3.ab3c1.ab3c1d2"), Arrays.asList(2.0, 4.0, 24.0)); assertNull(familySolrModel.getAnnotations().get("nothing")); assertEquals(familySolrModel.getAnnotations().keySet().size(), 6); } }
@Test public void getAllFilesTest() throws CatalogDBException { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); QueryResult<File> allFiles = catalogFileDBAdaptor.getAllInStudy(studyId, null); List<File> files = allFiles.getResult(); List<File> expectedFiles = user3.getProjects().get(0).getStudies().get(0).getFiles(); assertEquals(expectedFiles.size(), files.size()); for (File expectedFile : expectedFiles) { boolean found = false; for (File fileResult : allFiles.getResult()) { if (fileResult.getUid() == expectedFile.getUid()) found = true; } if (!found) { throw new CatalogDBException("The file " + expectedFile.getName() + " could not be found."); } } }
@Test public void testScanStudyURI() throws IOException, CatalogException { CatalogManagerTest.createDebugFile(directory.resolve("file1.txt").toString()); FileScanner fileScanner = new FileScanner(catalogManager); List<File> files = fileScanner.scan(folder, directory.toUri(), FileScanner.FileScannerPolicy.REPLACE, true, true, sessionIdUser); assertEquals(1, files.size()); URI studyUri = study.getUri(); CatalogManagerTest.createDebugFile(studyUri.resolve("data/test/folder/").resolve("file2.txt").getPath()); File root = catalogManager.getFileManager().get(study.getFqn(), new Query("name", "."), null, sessionIdUser).first(); files = fileScanner.scan(root, studyUri, FileScanner.FileScannerPolicy.REPLACE, true, true, sessionIdUser); assertEquals(1, files.size()); files.forEach((f) -> assertTrue(f.getSize() > 0)); files.forEach((f) -> assertEquals(f.getStatus().getName(), File.FileStatus.READY)); files.forEach((f) -> assertTrue(StringUtils.isNotEmpty(f.getChecksum()))); }
for (Study study : studyQueryResult.getResult()) { Map<String, Set<String>> studyAcls = SolrConverterUtil.parseInternalOpenCGAAcls((List<Map<String, Object>>) study.getAttributes().get("OPENCGA_ACL")); study.getAttributes().put("OPENCGA_ACL", studyAcls);
Study study = new Study(id, name, alias, type, creationDate, description, status, TimeUtils.getTime(), 0, cipher, Arrays.asList(new Group(MEMBERS, Collections.emptyList()), new Group(ADMINS, Collections.emptyList())), experiments, files, jobs, new LinkedList<>(), new LinkedList<>(), new LinkedList<>(), new LinkedList<>(), study.setUuid(UUIDUtils.generateOpenCGAUUID(UUIDUtils.Entity.STUDY)); QueryResult<Study> result = studyDBAdaptor.insert(project, study, options); study = result.getResult().get(0); uri = catalogIOManager.createStudy(userId, Long.toString(projectId), Long.toString(study.getUid())); } catch (CatalogIOException e) { try { studyDBAdaptor.delete(study.getUid()); } catch (Exception e1) { logger.error("Can't delete study after failure creating study", e1); study = studyDBAdaptor.update(study.getUid(), new ObjectMap("uri", uri), QueryOptions.empty()).first(); auditManager.recordCreation(AuditRecord.Resource.study, study.getUid(), userId, study, null, null); long rootFileId = fileDBAdaptor.getId(study.getUid(), ""); //Set studyUri to the root folder too rootFile = fileDBAdaptor.update(rootFileId, new ObjectMap("uri", uri), QueryOptions.empty()).first(); auditManager.recordCreation(AuditRecord.Resource.file, rootFile.getUid(), userId, rootFile, null, null);