QueryResult<Study> studyQueryResult = studyDBAdaptor.get(resource.getStudy().getUid(), new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); if (studyQueryResult.getNumResults() == 0) { throw new CatalogException("Internal error: Study " + resource.getStudy().getFqn() + " not found. Update could not be performed."); dbAdaptor.getAnnotationSet(resource.getResource().getUid(), null); authorizationManager.checkStudyPermission(resource.getStudy().getUid(), resource.getUser(), StudyAclEntry.StudyPermissions.CONFIDENTIAL_VARIABLE_SET_ACCESS, ""); confidentialPermissionsChecked = true; QueryResult<Study> studyQueryResult = studyDBAdaptor.get(resource.getStudy().getUid(), new QueryOptions(QueryOptions.INCLUDE, StudyDBAdaptor.QueryParams.VARIABLE_SET.key())); throw new CatalogException("Internal error: Study " + resource.getStudy().getFqn() + " not found. Update could not be performed."); QueryResult<AnnotationSet> annotationSetQueryResult = dbAdaptor.getAnnotationSet(resource.getResource().getUid(), annotationSet.getId()); if (annotationSetQueryResult.getNumResults() == 0) {
MyResource<Cohort> resource = new MyResource<>(user, study, cohort); auditManager.recordUpdate(AuditRecord.Resource.cohort, cohort.getUid(), resource.getUser(), parameters, null, null); return queryResult;
String userId = resource.getUser(); long studyId = resource.getStudy().getUid(); long individualId = resource.getResource().getUid(); MyResource tmpResource = getUid((String) map.get(IndividualDBAdaptor.QueryParams.ID.key()), studyStr, sessionId); parameters.remove(IndividualDBAdaptor.QueryParams.FATHER.key()); parameters.put(IndividualDBAdaptor.QueryParams.FATHER_UID.key(), tmpResource.getResource().getUid()); } else { throw new CatalogException("Cannot update father parameter. Father name or id not passed"); MyResource tmpResource = getUid((String) map.get(IndividualDBAdaptor.QueryParams.ID.key()), studyStr, sessionId); parameters.remove(IndividualDBAdaptor.QueryParams.MOTHER.key()); parameters.put(IndividualDBAdaptor.QueryParams.MOTHER_UID.key(), tmpResource.getResource().getUid()); } else { throw new CatalogException("Cannot update mother parameter. Mother name or id not passed"); return unsafeUpdate(resource.getStudy(), resource.getResource(), parameters, options, userId);
authorizationManager.checkSamplePermission(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), SampleAclEntry.SamplePermissions.WRITE_ANNOTATIONS); authorizationManager.checkSamplePermission(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), SampleAclEntry.SamplePermissions.UPDATE); .append(IndividualDBAdaptor.QueryParams.SAMPLE_UIDS.key(), resource.getResource().getUid()) .append(IndividualDBAdaptor.QueryParams.STUDY_UID.key(), resource.getStudy().getUid()); QueryOptions indOptions = new QueryOptions(QueryOptions.INCLUDE, Arrays.asList( IndividualDBAdaptor.QueryParams.UID.key(), IndividualDBAdaptor.QueryParams.SAMPLES.key())); authorizationManager.checkIndividualPermission(resource.getStudy().getUid(), individual.getUid(), resource.getUser(), IndividualAclEntry.IndividualPermissions.UPDATE); if (sample.getUid() != resource.getResource().getUid()) { sampleList.add(sample); authorizationManager.checkIndividualPermission(resource.getStudy().getUid(), individual.getUid(), resource.getUser(), IndividualAclEntry.IndividualPermissions.UPDATE); sampleList.add(resource.getResource()); options.put(Constants.CURRENT_RELEASE, studyManager.getCurrentRelease(resource.getStudy(), resource.getUser())); QueryResult<Sample> queryResult = sampleDBAdaptor.update(resource.getResource().getUid(), parameters, variableSetList, options); auditManager.recordUpdate(AuditRecord.Resource.sample, resource.getResource().getUid(), resource.getUser(), parameters, null, null); return queryResult;
try { MyResource<Sample> resource = catalogManager.getSampleManager().getUid(sample.getId(), studyStr, sessionId); existingSampleIds.add(resource.getResource().getUid()); } catch (CatalogException e) { individual.setFather(fatherResource.getResource()); individual.setMother(motherResource.getResource());
long familyId = resource.getResource().getUid(); authorizationManager.checkFamilyPermission(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), FamilyAclEntry.FamilyPermissions.WRITE_ANNOTATIONS); authorizationManager.checkFamilyPermission(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), FamilyAclEntry.FamilyPermissions.UPDATE); .append(FamilyDBAdaptor.QueryParams.STUDY_UID.key(), resource.getStudy().getUid()); QueryResult<Family> familyQueryResult = familyDBAdaptor.get(query, new QueryOptions()); if (familyQueryResult.getNumResults() == 0) { } else { autoCompleteFamilyMembers(family, resource.getStudy(), sessionId); options.put(Constants.CURRENT_RELEASE, studyManager.getCurrentRelease(resource.getStudy(), resource.getUser())); auditManager.recordUpdate(AuditRecord.Resource.family, familyId, resource.getUser(), parameters, null, null);
String sessionId) throws CatalogException { MyResource<ClinicalAnalysis> resource = getUid(entryStr, studyStr, sessionId); authorizationManager.checkClinicalAnalysisPermission(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), ClinicalAnalysisAclEntry.ClinicalAnalysisPermissions.UPDATE); MyResource<File> fileResource = catalogManager.getFileManager().getUid(String.valueOf(fileMap.get("path")), studyStr, sessionId); fileMap.put(FileDBAdaptor.QueryParams.UID.key(), fileResource.getResource().getUid()); Query query = new Query(ClinicalAnalysisDBAdaptor.QueryParams.UID.key(), resource.getResource().getUid()); QueryResult<ClinicalAnalysis> clinicalAnalysisQueryResult = get(studyStr, query, new QueryOptions(), sessionId); ClinicalAnalysis clinicalAnalysis = clinicalAnalysisQueryResult.first(); family = getFullValidatedFamily(family, resource.getStudy(), sessionId); clinicalAnalysis.setFamily(family); parameters.put(ClinicalAnalysisDBAdaptor.QueryParams.FAMILY.key(), family); proband = getFullValidatedMember(proband, resource.getStudy(), sessionId); clinicalAnalysis.setProband(proband); parameters.put(ClinicalAnalysisDBAdaptor.QueryParams.PROBAND.key(), proband); validateClinicalAnalysisFields(clinicalAnalysis, resource.getStudy(), sessionId); if (parameters.containsKey(ClinicalAnalysisDBAdaptor.QueryParams.FILES.key())) { parameters.put(ClinicalAnalysisDBAdaptor.QueryParams.FILES.key(), clinicalAnalysis.getFiles()); return clinicalDBAdaptor.update(resource.getResource().getUid(), parameters, QueryOptions.empty());
query.put(FileDBAdaptor.QueryParams.STUDY_UID.key(), resource.getStudy().getUid()); .append(QueryOptions.INCLUDE, Arrays.asList(FileDBAdaptor.QueryParams.PATH.key(), FileDBAdaptor.QueryParams.NAME.key(), FileDBAdaptor.QueryParams.UID.key(), FileDBAdaptor.QueryParams.TYPE.key())); QueryResult<File> fileQueryResult = fileDBAdaptor.get(resource.getResource().getUid(), qOptions); if (fileQueryResult == null || fileQueryResult.getNumResults() != 1) { throw new CatalogException("An error occurred with the database."); FileTree fileTree = getTree(fileQueryResult.first(), query, queryOptions, maxDepth, resource.getStudy().getUid(), resource.getUser());
public QueryResult<File> rename(String studyStr, String fileStr, String newName, String sessionId) throws CatalogException { ParamUtils.checkFileName(newName, "name"); MyResource<File> resource = getUid(fileStr, studyStr, sessionId); String userId = resource.getUser(); Study study = resource.getStudy(); String ownerId = StringUtils.split(study.getFqn(), "@")[0]; File file = resource.getResource();
String userId = resource.getUser(); long fileId = resource.getResource().getUid(); long studyUid = resource.getStudy().getUid(); File file = resource.getResource(); MyResources<File> fileResource = new MyResources<>(userId, resource.getStudy(), fileList); try { removeJobReferences(fileResource);
File file = resource.getResource(); authorizationManager.checkFilePermission(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), FileAclEntry.FilePermissions.WRITE_ANNOTATIONS); authorizationManager.checkFilePermission(resource.getStudy().getUid(), file.getUid(), userId, FileAclEntry.FilePermissions.WRITE); return unsafeUpdate(resource.getStudy(), file, parameters, options, userId);
.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()));
Collections.emptyList()); } else { Query query = new Query("uid", resource.getResource().getUid()); QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, Constants.ANNOTATION_SET_NAME + "." + annotationSetName);
MyResource<Family> familyResource = catalogManager.getFamilyManager() .getUid(query.getString(ClinicalAnalysisDBAdaptor.QueryParams.FAMILY.key()), study.getFqn(), sessionId); query.put(ClinicalAnalysisDBAdaptor.QueryParams.FAMILY_UID.key(), familyResource.getResource().getUid()); query.remove(ClinicalAnalysisDBAdaptor.QueryParams.FAMILY.key()); MyResource<Sample> sampleResource = catalogManager.getSampleManager().getUid(query.getString("sample"), study.getFqn(), sessionId); query.put(ClinicalAnalysisDBAdaptor.QueryParams.SAMPLE_UID.key(), sampleResource.getResource().getUid()); query.remove("sample"); MyResource<Individual> probandResource = catalogManager.getIndividualManager() .getUid(query.getString(ClinicalAnalysisDBAdaptor.QueryParams.PROBAND.key()), study.getFqn(), sessionId); query.put(ClinicalAnalysisDBAdaptor.QueryParams.PROBAND_UID.key(), probandResource.getResource().getUid()); query.remove(ClinicalAnalysisDBAdaptor.QueryParams.PROBAND.key()); MyResource<File> resource = catalogManager.getFileManager() .getUid(query.getString(ClinicalAnalysisDBAdaptor.QueryParams.GERMLINE.key()), study.getFqn(), sessionId); query.put(ClinicalAnalysisDBAdaptor.QueryParams.GERMLINE_UID.key(), resource.getResource().getUid()); query.remove(ClinicalAnalysisDBAdaptor.QueryParams.GERMLINE.key()); MyResource<File> resource = catalogManager.getFileManager() .getUid(query.getString(ClinicalAnalysisDBAdaptor.QueryParams.SOMATIC.key()), study.getFqn(), sessionId); query.put(ClinicalAnalysisDBAdaptor.QueryParams.SOMATIC_UID.key(), resource.getResource().getUid()); query.remove(ClinicalAnalysisDBAdaptor.QueryParams.SOMATIC.key());
.getUid(resource.getResource().getInterpretation().getClinicalAnalysisId(), studyStr, sessionId); authorizationManager.checkClinicalAnalysisPermission(resource.getStudy().getUid(), clinicalAnalysisResource.getResource().getUid(), resource.getUser(), ClinicalAnalysisAclEntry.ClinicalAnalysisPermissions.UPDATE); if (ListUtils.isNotEmpty(resource.getResource().getInterpretation().getReportedVariants()) && (parameters.size() > 1 || !parameters.containsKey(InterpretationDBAdaptor.UpdateParams.REPORTED_VARIANTS.key()))) { throw new CatalogException("Interpretation already has reported variants. Only array of reported variants can be updated."); QueryResult<Interpretation> queryResult = interpretationDBAdaptor.update(resource.getResource().getUid(), parameters, options); auditManager.recordUpdate(AuditRecord.Resource.interpretation, resource.getResource().getUid(), resource.getUser(), parameters, null, null);
proband.setUid(resource.getResource().getUid());
@Override public QueryResult groupBy(@Nullable String studyStr, Query query, List<String> fields, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); if (fields == null || fields.size() == 0) { throw new CatalogException("Empty fields parameter."); } String userId = userManager.getUserId(sessionId); Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); // Fix query if it contains any annotation AnnotationUtils.fixQueryAnnotationSearch(study, userId, query, authorizationManager); AnnotationUtils.fixQueryOptionAnnotation(options); // Add study id to the query query.put(SampleDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); if (StringUtils.isNotEmpty(query.getString(SampleDBAdaptor.QueryParams.INDIVIDUAL.key()))) { String individualStr = query.getString(SampleDBAdaptor.QueryParams.INDIVIDUAL.key()); if (NumberUtils.isCreatable(individualStr) && Long.parseLong(individualStr) <= 0) { query.put(SampleDBAdaptor.QueryParams.INDIVIDUAL_UID.key(), -1); } else { MyResource resource = catalogManager.getIndividualManager().getUid(individualStr, studyStr, sessionId); query.put(SampleDBAdaptor.QueryParams.INDIVIDUAL_UID.key(), resource.getResource().getUid()); } query.remove(SampleDBAdaptor.QueryParams.INDIVIDUAL.key()); } QueryResult queryResult = sampleDBAdaptor.groupBy(query, fields, options, userId); return ParamUtils.defaultObject(queryResult, QueryResult::new); }
@Override public QueryResult<Panel> update(String studyStr, String panelId, ObjectMap parameters, QueryOptions options, String sessionId) throws CatalogException { ParamUtils.checkObj(parameters, "parameters"); parameters = new ObjectMap(parameters); options = ParamUtils.defaultObject(options, QueryOptions::new); MyResource<Panel> resource = getUid(panelId, studyStr, sessionId); // Check update permissions authorizationManager.checkPanelPermission(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), PanelAclEntry.PanelPermissions.UPDATE); try { ParamUtils.checkAllParametersExist(parameters.keySet().iterator(), (a) -> PanelDBAdaptor.UpdateParams.getParam(a) != null); } catch (CatalogParameterException e) { throw new CatalogException("Could not update: " + e.getMessage(), e); } if (parameters.containsKey(PanelDBAdaptor.UpdateParams.ID.key())) { ParamUtils.checkAlias(parameters.getString(PanelDBAdaptor.UpdateParams.ID.key()), PanelDBAdaptor.UpdateParams.ID.key()); } if (options.getBoolean(Constants.INCREMENT_VERSION)) { // We do need to get the current release to properly create a new version options.put(Constants.CURRENT_RELEASE, studyManager.getCurrentRelease(resource.getStudy(), resource.getUser())); } QueryResult<Panel> queryResult = panelDBAdaptor.update(resource.getResource().getUid(), parameters, options); auditManager.recordUpdate(AuditRecord.Resource.panel, resource.getResource().getUid(), resource.getUser(), parameters, null, null); return queryResult; }
public List<QueryResult<PanelAclEntry>> getAcls(String studyStr, List<String> panelList, String member, boolean silent, String sessionId) throws CatalogException { List<QueryResult<PanelAclEntry>> panelAclList = new ArrayList<>(panelList.size()); for (String panel : panelList) { try { MyResource<Panel> resource = getUid(panel, studyStr, sessionId); QueryResult<PanelAclEntry> allPanelAcls; if (StringUtils.isNotEmpty(member)) { allPanelAcls = authorizationManager.getPanelAcl(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), member); } else { allPanelAcls = authorizationManager.getAllPanelAcls(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser()); } allPanelAcls.setId(panel); panelAclList.add(allPanelAcls); } catch (CatalogException e) { if (silent) { panelAclList.add(new QueryResult<>(panel, 0, 0, 0, "", e.toString(), new ArrayList<>(0))); } else { throw e; } } } return panelAclList; }
public QueryResult<Interpretation> create(String studyStr, String clinicalAnalysisStr, Interpretation interpretation, QueryOptions options, String sessionId) throws CatalogException { // We check if the user can create interpretations in the clinical analysis MyResource<ClinicalAnalysis> resource = catalogManager.getClinicalAnalysisManager() .getUid(clinicalAnalysisStr, studyStr, sessionId); authorizationManager.checkClinicalAnalysisPermission(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), ClinicalAnalysisAclEntry.ClinicalAnalysisPermissions.UPDATE); options = ParamUtils.defaultObject(options, QueryOptions::new); ParamUtils.checkObj(interpretation, "clinicalAnalysis"); ParamUtils.checkAlias(interpretation.getInterpretation().getId(), "id"); interpretation.getInterpretation().setCreationDate(TimeUtils.getTime()); interpretation.getInterpretation().setDescription( ParamUtils.defaultString(interpretation.getInterpretation().getDescription(), "")); interpretation.getInterpretation().setStatus(Status.READY); interpretation.getInterpretation().setAttributes( ParamUtils.defaultObject(interpretation.getInterpretation().getAttributes(), Collections.emptyMap())); interpretation.setUuid(UUIDUtils.generateOpenCGAUUID(UUIDUtils.Entity.INTERPRETATION)); QueryResult<Interpretation> queryResult = interpretationDBAdaptor.insert(resource.getStudy().getUid(), interpretation, options); // Now, we add the interpretation to the clinical analysis ObjectMap parameters = new ObjectMap(); parameters.put(ClinicalAnalysisDBAdaptor.QueryParams.INTERPRETATIONS.key(), Arrays.asList(interpretation)); Map<String, Object> actionMap = new HashMap<>(); actionMap.put(ClinicalAnalysisDBAdaptor.QueryParams.INTERPRETATIONS.key(), ParamUtils.UpdateAction.ADD.name()); parameters.put(Constants.ACTIONS, actionMap); catalogManager.getClinicalAnalysisManager().update(resource.getStudy().getFqn(), clinicalAnalysisStr, parameters, null, sessionId); return queryResult; }