public List<QueryResult<Study>> get(List<String> projectList, Query query, QueryOptions options, boolean silent, String sessionId) throws CatalogException { List<QueryResult<Study>> results = new ArrayList<>(projectList.size()); for (String project : projectList) { try { QueryResult<Study> studyObj = get(project, query, options, sessionId); results.add(studyObj); } catch (CatalogException e) { if (silent) { results.add(new QueryResult<>(project, 0, 0, 0, "", e.toString(), new ArrayList<>(0))); } else { throw e; } } } return results; }
public List<QueryResult<Study>> get(List<String> studyList, QueryOptions queryOptions, boolean silent, String sessionId) throws CatalogException { List<QueryResult<Study>> results = new ArrayList<>(studyList.size()); for (String study : studyList) { try { QueryResult<Study> studyObj = get(study, queryOptions, sessionId); results.add(studyObj); } catch (CatalogException e) { if (silent) { results.add(new QueryResult<>(study, 0, 0, 0, "", e.toString(), new ArrayList<>(0))); } else { throw e; } } } return results; }
@Deprecated private Path getWorkspace(long studyId, String sessionId) throws CatalogException, IOException { // Obtain the study uri QueryOptions studyOptions = new QueryOptions(QueryOptions.INCLUDE, FileDBAdaptor.QueryParams.URI.key()); QueryResult<Study> studyQueryResult = catalogManager.getStudyManager().get(String.valueOf((Long) studyId), studyOptions, sessionId); if (studyQueryResult .getNumResults() != 1) { logger.error("Critical error: Study {} not found in catalog.", studyId); throw new CatalogException("Critical error: Study " + studyId + " not found in catalog"); } Path workspace = Paths.get(studyQueryResult.first().getUri().getRawPath()).resolve(".opencga").resolve("alignments"); if (!workspace.toFile().exists()) { Files.createDirectories(workspace); } return workspace; }
@Override protected List<String> validate(String defaultStudyStr, List<String> values, Integer release, VariantQueryParam param, String sessionId) throws CatalogException { if (release == null) { String userId = catalogManager.getUserManager().getUserId(sessionId); List<Study> studies = catalogManager.getStudyManager().resolveIds(values, userId); return studies.stream().map(Study::getFqn).collect(Collectors.toList()); } else { List<String> validatedValues = new ArrayList<>(values.size()); List<QueryResult<Study>> queryResults = catalogManager.getStudyManager().get(values, RELEASE_OPTIONS, false, sessionId); for (QueryResult<Study> queryResult : queryResults) { Study study = queryResult.first(); validatedValues.add(study.getFqn()); checkRelease(release, study.getRelease(), param, study.getFqn()); } return validatedValues; } } }
public static DataStore getDataStore(CatalogManager catalogManager, String studyStr, File.Bioformat bioformat, String sessionId) throws CatalogException { Study study = catalogManager.getStudyManager().get(studyStr, new QueryOptions(), sessionId).first(); return getDataStore(catalogManager, study, bioformat, sessionId); }
private Map<String, Group> getGroupMap() throws CatalogException { return catalogManager.getStudyManager().get(studyFqn, null, ownerSessionId).first().getGroups() .stream() .collect(Collectors.toMap(Group::getName, f -> f)); }
private void fillStudy(String studyId, VariantStudyMetadata studyMetadata) throws CatalogException { QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.DESCRIPTION.key()); // Just add file description Study study = catalogManager.getStudyManager().get(studyId, options, sessionId).first(); studyMetadata.setDescription(study.getDescription()); }
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; }
@Test public void testCreateRepeatedVariableSet() throws CatalogException { Study study = catalogManager.getStudyManager().get("user@1000G:phase1", null, sessionIdUser).first(); List<Variable> variables = Arrays.asList( new Variable("NAME", "", Variable.VariableType.TEXT, "", true, false, Collections.<String>emptyList(), 0, "", "", null, Collections.<String, Object>emptyMap()), new Variable("NAME", "", Variable.VariableType.BOOLEAN, "", true, false, Collections.<String>emptyList(), 3, "", "", null, Collections.<String, Object>emptyMap()), new Variable("AGE", "", Variable.VariableType.DOUBLE, null, true, false, Collections.singletonList("0:99"), 1, "", "", null, Collections.<String, Object>emptyMap()), new Variable("HEIGHT", "", Variable.VariableType.DOUBLE, "1.5", false, false, Collections.singletonList("0:"), 2, "", "", null, Collections.<String, Object>emptyMap()), new Variable("PHEN", "", Variable.VariableType.CATEGORICAL, "", true, false, Arrays.asList("CASE", "CONTROL"), 4, "", "", null, Collections.<String, Object>emptyMap()) ); thrown.expect(CatalogException.class); catalogManager.getStudyManager().createVariableSet(study.getFqn(), "vs1", "vs1", true, false, "", null, variables, sessionIdUser); }
@Test public void readStudy() throws CatalogException { QueryResult<Study> study = catalogManager.getStudyManager().get(studyFqn, null, ownerSessionId); assertEquals(1, study.getNumResults()); study = catalogManager.getStudyManager().get(studyFqn, null, memberSessionId); assertEquals(1, study.getNumResults()); }
/** * VariableSet methods * *************************** */ @Test public void testCreateVariableSet() throws CatalogException { Study study = catalogManager.getStudyManager().get("user@1000G:phase1", null, sessionIdUser).first(); long variableSetNum = study.getVariableSets().size(); List<Variable> variables = new ArrayList<>(); variables.addAll(Arrays.asList( new Variable("NAME", "", Variable.VariableType.TEXT, "", true, false, Collections.<String>emptyList(), 0, "", "", null, Collections.<String, Object>emptyMap()), new Variable("AGE", "", Variable.VariableType.DOUBLE, null, true, false, Collections.singletonList("0:99"), 1, "", "", null, Collections.<String, Object>emptyMap()), new Variable("HEIGHT", "", Variable.VariableType.DOUBLE, "1.5", false, false, Collections.singletonList("0:"), 2, "", "", null, Collections.<String, Object>emptyMap()), new Variable("ALIVE", "", Variable.VariableType.BOOLEAN, "", true, false, Collections.<String>emptyList(), 3, "", "", null, Collections.<String, Object>emptyMap()), new Variable("PHEN", "", Variable.VariableType.CATEGORICAL, "", true, false, Arrays.asList("CASE", "CONTROL"), 4, "", "", null, Collections.<String, Object>emptyMap()) )); QueryResult<VariableSet> queryResult = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", true, false, "", null, variables, sessionIdUser); assertEquals(1, queryResult.getResult().size()); study = catalogManager.getStudyManager().get(study.getId(), null, sessionIdUser).first(); assertEquals(variableSetNum + 1, study.getVariableSets().size()); }
@Test public void readStudyDeny() throws CatalogException { catalogManager.getStudyManager().updateGroup(String.valueOf(studyFqn), "@members", new GroupParams(externalUser, GroupParams.Action.REMOVE), ownerSessionId); thrown.expect(CatalogAuthorizationException.class); catalogManager.getStudyManager().get(studyFqn, null, externalSessionId); }
URI getStudyURI() throws CatalogException { return catalogManager.getStudyManager().get(studyFqn, new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.URI.key()), sessionIdUser).first().getUri(); }
@Test public void testCalculateAggregatedStatsNonAggregatedStudy() throws Exception { beforeAggregated("variant-test-aggregated-file.vcf.gz", null); calculateAggregatedStats(new QueryOptions(VariantStorageEngine.Options.AGGREGATED_TYPE.key(), Aggregation.BASIC)); Study study = catalogManager.getStudyManager().get(studyId, null, sessionId).first(); String agg = study.getAttributes().get(VariantStorageEngine.Options.AGGREGATED_TYPE.key()).toString(); assertNotNull(agg); assertEquals(Aggregation.BASIC.toString(), agg); }
@Test public void testAssignPermissions() throws CatalogException, IOException { catalogManager.getUserManager().create("test", "test", "test@mail.com", "test", null, 100L, "guest", null, null); catalogManager.getStudyManager().createGroup("user@1000G:phase1", "group_cancer_some_thing_else", "test", sessionIdUser); List<QueryResult<StudyAclEntry>> permissions = catalogManager.getStudyManager().updateAcl( Collections.singletonList("user@1000G:phase1"), "@group_cancer_some_thing_else", new Study.StudyAclParams("", AclParams.Action.SET, "view_only"), sessionIdUser); assertEquals("@group_cancer_some_thing_else", permissions.get(0).first().getMember()); String token = catalogManager.getUserManager().login("test", "test"); QueryResult<Study> studyQueryResult = catalogManager.getStudyManager().get("user@1000G:phase1", QueryOptions.empty(), token); assertEquals(1, studyQueryResult.getNumResults()); assertTrue(studyQueryResult.first().getAttributes().isEmpty()); studyQueryResult = catalogManager.getStudyManager().get("user@1000G:phase1", new QueryOptions(DBAdaptor.INCLUDE_ACLS, true), token); assertEquals(1, studyQueryResult.getNumResults()); assertTrue(!studyQueryResult.first().getAttributes().isEmpty()); assertTrue(studyQueryResult.first().getAttributes().containsKey("OPENCGA_ACL")); List<Map<String, Object>> acls = (List<Map<String, Object>>) studyQueryResult.first().getAttributes().get("OPENCGA_ACL"); assertEquals(1, acls.size()); assertEquals("@group_cancer_some_thing_else", acls.get(0).get("member")); assertTrue(!((List) acls.get(0).get("permissions")).isEmpty()); }
@Ignore @Test public void loginNotRegisteredUsers() throws CatalogException, NamingException, IOException { // Action only for admins catalogManager.getStudyManager().createGroup(studyFqn, "ldap", "", sessionIdUser); catalogManager.getStudyManager().syncGroupWith(studyFqn, "ldap", new Group.Sync("ldap", "bio"), sessionIdUser); catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), "@ldap", new Study.StudyAclParams("", AclParams.Action.SET, "view_only"), sessionIdUser); String token = catalogManager.getUserManager().login("user", "password"); QueryResult<Study> studyQueryResult = catalogManager.getStudyManager().get(String.valueOf((Long) studyUid), QueryOptions.empty(), token); assertEquals(1, studyQueryResult.getNumResults()); // We remove the permissions for group ldap catalogManager.getStudyManager().updateAcl(Arrays.asList(studyFqn), "@ldap", new Study.StudyAclParams("", AclParams.Action.RESET, ""), sessionIdUser); thrown.expect(CatalogAuthorizationException.class); catalogManager.getStudyManager().get(String.valueOf((Long) studyUid), QueryOptions.empty(), token); }
/** * 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()); } }
@Test public void testProjections() throws CatalogException { Study study = catalogManager.getStudyManager().get("1000G:phase1", null, sessionIdUser).first(); Query query = new Query(Constants.ANNOTATION, "variableSet===" + study.getVariableSets().get(0).getId()); QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, "annotationSets"); QueryResult<Sample> annotQueryResult = catalogManager.getSampleManager().search(studyFqn, query, options, sessionIdUser); assertEquals(8, annotQueryResult.getNumResults()); for (Sample sample : annotQueryResult.getResult()) { assertEquals(null, sample.getId()); assertTrue(!sample.getAnnotationSets().isEmpty()); } }
@Before public void setUp() throws Exception { scm = new StudyConfigurationManager(new DummyProjectMetadataAdaptor(), new DummyStudyConfigurationAdaptor(), new DummyVariantFileMetadataDBAdaptor()); Study study = catalogManager.getStudyManager().get(studyId, null, sessionId).first(); StudyConfiguration studyConfigurationToReturn = new StudyConfiguration((int) study.getUid(), "user@p1:s1"); studyConfigurationToReturn.setIndexedFiles(indexedFiles); for (File file : files) { if (indexedFiles.contains(((int) file.getUid()))) { studyConfigurationToReturn.getFileIds().put(file.getName(), ((int) file.getUid())); } } scm.updateStudyConfiguration(studyConfigurationToReturn, null); // checkStudyConfiguration(study, studyConfigurationToReturn); }
@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()); }