static CatalogException unableToCalculateCohortReady(Cohort cohort) { return new CatalogException("Unable to calculate stats for cohort " + "{ uid: " + cohort.getUid() + " id: \"" + cohort.getId() + "\" }" + " with status \"" + cohort.getStatus().getName() + "\". " + "Resume or update stats for continue calculation"); }
static CatalogException unableToCalculateCohortCalculating(Cohort cohort) { return new CatalogException("Unable to calculate stats for cohort " + "{ uid: " + cohort.getUid() + " id: \"" + cohort.getId() + "\" }" + " with status \"" + cohort.getStatus().getName() + "\". " + "Resume for continue calculation."); }
public List<QueryResult<CohortAclEntry>> getAcls(String studyStr, List<String> cohortList, String member, boolean silent, String sessionId) throws CatalogException { List<QueryResult<CohortAclEntry>> cohortAclList = new ArrayList<>(cohortList.size()); for (String cohort : cohortList) { try { MyResource<Cohort> resource = getUid(cohort, studyStr, sessionId); QueryResult<CohortAclEntry> allCohortAcls; if (StringUtils.isNotEmpty(member)) { allCohortAcls = authorizationManager.getCohortAcl(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), member); } else { allCohortAcls = authorizationManager.getAllCohortAcls(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser()); } allCohortAcls.setId(cohort); cohortAclList.add(allCohortAcls); } catch (CatalogException e) { if (silent) { cohortAclList.add(new QueryResult<>(cohort, 0, 0, 0, "", e.toString(), new ArrayList<>(0))); } else { throw e; } } } return cohortAclList; }
@Deprecated public void checkInUse(long sampleId) throws CatalogDBException { long studyId = getStudyId(sampleId); Query query = new Query(FileDBAdaptor.QueryParams.SAMPLE_UIDS.key(), sampleId); QueryOptions queryOptions = new QueryOptions(MongoDBCollection.INCLUDE, Arrays.asList(FILTER_ROUTE_FILES + FileDBAdaptor .QueryParams.UID.key(), FILTER_ROUTE_FILES + FileDBAdaptor.QueryParams.PATH.key())); QueryResult<File> fileQueryResult = dbAdaptorFactory.getCatalogFileDBAdaptor().get(query, queryOptions); if (fileQueryResult.getNumResults() != 0) { String msg = "Can't delete Sample " + sampleId + ", still in use in \"sampleId\" array of files : " + fileQueryResult.getResult().stream() .map(file -> "{ id: " + file.getUid() + ", path: \"" + file.getPath() + "\" }") .collect(Collectors.joining(", ", "[", "]")); throw new CatalogDBException(msg); } queryOptions = new QueryOptions(CohortDBAdaptor.QueryParams.SAMPLES.key(), sampleId) .append(MongoDBCollection.INCLUDE, Arrays.asList(FILTER_ROUTE_COHORTS + CohortDBAdaptor.QueryParams.UID.key(), FILTER_ROUTE_COHORTS + CohortDBAdaptor.QueryParams.ID.key())); QueryResult<Cohort> cohortQueryResult = dbAdaptorFactory.getCatalogCohortDBAdaptor().getAllInStudy(studyId, queryOptions); if (cohortQueryResult.getNumResults() != 0) { String msg = "Can't delete Sample " + sampleId + ", still in use in cohorts : " + cohortQueryResult.getResult().stream() .map(cohort -> "{ id: " + cohort.getUid() + ", name: \"" + cohort.getId() + "\" }") .collect(Collectors.joining(", ", "[", "]")); throw new CatalogDBException(msg); } }
@Override public Document convertToStorageType(Cohort object, List<VariableSet> variableSetList) { Document document = super.convertToStorageType(object, variableSetList); document.remove(CohortDBAdaptor.QueryParams.ANNOTATION_SETS.key()); document.put("uid", object.getUid()); document.put("studyUid", object.getStudyUid()); document.put("samples", convertSamplesToDocument(object.getSamples())); return document; }
CohortSolrModel cohortSolrModel = new CohortSolrModel(); cohortSolrModel.setUid(cohort.getUid()); cohortSolrModel.setStudyId(study.getFqn().replace(":", "__")); cohortSolrModel.setType(cohort.getType().name());
public QueryResult<Cohort> update(String studyStr, String entryStr, ObjectMap parameters, boolean allowModifyCohortAll, QueryOptions options, String sessionId) throws CatalogException { ParamUtils.checkObj(parameters, "Update parameters"); options = ParamUtils.defaultObject(options, QueryOptions::new); parameters = new ObjectMap(parameters); MyResource<Cohort> resource = getUid(entryStr, studyStr, sessionId); // Check permissions... // Only check write annotation permissions if the user wants to update the annotation sets if (parameters.containsKey(CohortDBAdaptor.QueryParams.ANNOTATION_SETS.key())) { authorizationManager.checkCohortPermission(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), CohortAclEntry.CohortPermissions.WRITE_ANNOTATIONS); } // Only check update permissions if the user wants to update anything apart from the annotation sets if ((parameters.size() == 1 && !parameters.containsKey(CohortDBAdaptor.QueryParams.ANNOTATION_SETS.key())) || parameters.size() > 1) { authorizationManager.checkCohortPermission(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), CohortAclEntry.CohortPermissions.UPDATE); } Cohort cohort = cohortDBAdaptor.get(resource.getResource().getUid(), QueryOptions.empty()).first(); return unsafeUpdate(resource.getStudy(), cohort, parameters, allowModifyCohortAll, options, resource.getUser()); }
authorizationManager.checkCohortPermission(study.getUid(), cohort.getUid(), userId, CohortAclEntry.CohortPermissions.DELETE); .append(CohortDBAdaptor.QueryParams.UID.key(), cohort.getUid()) .append(CohortDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); ObjectMap updateParams = new ObjectMap() if (update.first() > 0) { numModified += 1; auditManager.recordDeletion(AuditRecord.Resource.cohort, cohort.getUid(), userId, null, updateParams, null, null); } else { failedList.add(new WriteResult.Fail(cohort.getId(), "Unknown reason"));
@Test public void testDeleteCohort() throws CatalogException, IOException { String studyId = "user@1000G:phase1"; Sample sampleId1 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_1"), new QueryOptions(), sessionIdUser).first(); Sample sampleId2 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_2"), new QueryOptions(), sessionIdUser).first(); Sample sampleId3 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_3"), new QueryOptions(), sessionIdUser).first(); Cohort myCohort = catalogManager.getCohortManager().create(studyId, new Cohort().setId("MyCohort").setType(Study.Type.FAMILY) .setSamples(Arrays.asList(sampleId1, sampleId2, sampleId3)), null, sessionIdUser).first(); assertEquals("MyCohort", myCohort.getId()); assertEquals(3, myCohort.getSamples().size()); assertTrue(myCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId1.getUid())); assertTrue(myCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId2.getUid())); assertTrue(myCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId3.getUid())); WriteResult deleteResult = catalogManager.getCohortManager().delete(studyId, new Query(CohortDBAdaptor.QueryParams.UID.key(), myCohort.getUid()), null, sessionIdUser); assertEquals(1, deleteResult.getNumModified()); Query query = new Query() .append(CohortDBAdaptor.QueryParams.UID.key(), myCohort.getUid()) .append(CohortDBAdaptor.QueryParams.STATUS_NAME.key(), "!=" + Cohort.CohortStatus.READY); Cohort cohort = catalogManager.getCohortManager().get(studyId, query, null, sessionIdUser).first(); assertEquals(Status.DELETED, cohort.getStatus().getName()); }
Query query = new Query() .append(CohortDBAdaptor.QueryParams.STUDY_UID.key(), resource.getStudy().getUid()) .append(CohortDBAdaptor.QueryParams.UID.key(), resource.getResource().getUid()); QueryResult<Cohort> cohortQueryResult = cohortDBAdaptor.get(query, new QueryOptions(QueryOptions.INCLUDE, CohortDBAdaptor.QueryParams.SAMPLES.key()));
CohortSolrModel cohortSolrModel = new CatalogCohortToSolrCohortConverter(study).convertToStorageType(cohort); assertEquals(cohortSolrModel.getUid(), cohort.getUid()); assertEquals(cohortSolrModel.getStatus(), cohort.getStatus().getName());
Query cohortQuery = new Query(CohortDBAdaptor.QueryParams.UID.key(), cohort.getUid()); WriteResult delete = catalogManager.getCohortManager().delete(studyStr, cohortQuery, new ObjectMap(), sessionId); if (delete.getWarning() != null || delete.getError() != null) {
auditManager.recordCreation(AuditRecord.Resource.cohort, queryResult.first().getUid(), userId, queryResult.first(), null, null); return queryResult;
Cohort cohort = catalogManager.getCohortManager().create(studyId, cohortName, null, null, Collections.emptyList(), null, null, sessionId).first(); cohortId = cohort.getId(); cohortUid = cohort.getUid(); files.add(create("platinum/1K.end.platinum-genomes-vcf-NA12877_S1.genome.vcf.gz")); files.add(create("platinum/1K.end.platinum-genomes-vcf-NA12878_S1.genome.vcf.gz", true));
String msg = "Can't delete VariableSetId, still in use as \"variableSetId\" of cohorts : ["; for (Cohort cohort : cohorts.getResult()) { msg += " { id: " + cohort.getUid() + ", name: \"" + cohort.getId() + "\" },";