default boolean exists(long interpretationId) throws CatalogDBException { return count(new Query(QueryParams.UID.key(), interpretationId)).first() > 0; }
default void checkId(long interpretationId) throws CatalogDBException { if (interpretationId < 0) { throw CatalogDBException.newInstance("Interpretation id '{}' is not valid: ", interpretationId); } if (!exists(interpretationId)) { throw CatalogDBException.newInstance("Interpretation id '{}' does not exist", interpretationId); } }
@Override public QueryResult<Interpretation> get(String studyStr, Query query, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); String userId = catalogManager.getUserManager().getUserId(sessionId); Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); query.append(InterpretationDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); QueryResult<Interpretation> queryResult = interpretationDBAdaptor.get(query, options, userId); List<Interpretation> results = new ArrayList<>(queryResult.getResult().size()); for (Interpretation interpretation : queryResult.getResult()) { if (StringUtils.isNotEmpty(interpretation.getInterpretation().getClinicalAnalysisId())) { try { catalogManager.getClinicalAnalysisManager().smartResolutor(study.getUid(), interpretation.getInterpretation().getClinicalAnalysisId(), userId); results.add(interpretation); } catch (CatalogException e) { logger.debug("Removing interpretation " + interpretation.getUuid() + " from results. User " + userId + " does not have " + "proper permissions"); } } } queryResult.setResult(results); queryResult.setNumTotalResults(results.size()); queryResult.setNumResults(results.size()); return queryResult; }
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; }
QueryResult<Interpretation> queryResult = interpretationDBAdaptor.update(resource.getResource().getUid(), parameters, options); auditManager.recordUpdate(AuditRecord.Resource.interpretation, resource.getResource().getUid(), resource.getUser(), parameters, null, null);
InterpretationDBAdaptor.QueryParams.UID.key(), InterpretationDBAdaptor.QueryParams.STUDY_UID.key(), InterpretationDBAdaptor.QueryParams.ID.key(), InterpretationDBAdaptor.QueryParams.STATUS.key())); QueryResult<Interpretation> interpretationQueryResult = interpretationDBAdaptor.get(query, options, user); if (interpretationQueryResult.getNumResults() == 0) { interpretationQueryResult = interpretationDBAdaptor.get(query, options); if (interpretationQueryResult.getNumResults() == 0) { throw new CatalogException("Interpretation " + entry + " not found");