From 439a3fdc96c9ee6cdd35c4f50e11e9e302a3cb64 Mon Sep 17 00:00:00 2001 From: Brian Bolt Date: Mon, 14 Aug 2023 17:19:37 -0700 Subject: [PATCH 1/2] ACAS-699: Accept projects list to filter /api/experiments/protocolCodename/:code on from from nodejs --- .../labseer/api/ApiExperimentController.java | 18 ++++----- .../labseer/service/ExperimentService.java | 4 ++ .../service/ExperimentServiceImpl.java | 39 +++++++++++++++++++ 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/labsynch/labseer/api/ApiExperimentController.java b/src/main/java/com/labsynch/labseer/api/ApiExperimentController.java index d6bfd2857..6107a51ba 100755 --- a/src/main/java/com/labsynch/labseer/api/ApiExperimentController.java +++ b/src/main/java/com/labsynch/labseer/api/ApiExperimentController.java @@ -44,6 +44,7 @@ import com.labsynch.labseer.dto.TsvLoaderResponseDTO; import com.labsynch.labseer.exceptions.ErrorMessage; import com.labsynch.labseer.exceptions.NotFoundException; +import com.labsynch.labseer.exceptions.TooManyResultsException; import com.labsynch.labseer.exceptions.UniqueNameException; import com.labsynch.labseer.service.AnalysisGroupService; import com.labsynch.labseer.service.AnalysisGroupValueService; @@ -1634,20 +1635,19 @@ public ResponseEntity jsonFindExperimentByNameGet(@RequestPara @RequestMapping(value = "/protocol/{codeName}", method = RequestMethod.GET, headers = "Accept=application/json") @ResponseBody public ResponseEntity jsonFindExperimentsByProtocolCodeName( - @PathVariable("codeName") String codeName, @RequestParam(value = "with", required = false) String with) { + @PathVariable("codeName") String codeName, @RequestParam(value = "projects", required = false) List projects, @RequestParam(value = "with", required = false) String with) { HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "application/json; charset=utf-8"); - List protocols = Protocol.findProtocolsByCodeNameEqualsAndIgnoredNot(codeName, true).getResultList(); - if (protocols.size() == 1) { + try { + Collection experiments = experimentService.findExperimentsByProtocolCodeName(codeName, projects); return new ResponseEntity( - Experiment.toJsonArrayStub(Experiment.findExperimentsByProtocol(protocols.get(0)).getResultList()), + Experiment.toJsonArrayStub(experiments), headers, HttpStatus.OK); - } else if (protocols.size() > 1) { - logger.error("ERROR: multiple protocols found with the same code name"); - return new ResponseEntity("[ ]", headers, HttpStatus.CONFLICT); - } else { - logger.warn("WARN: no protocols found with the query code name"); + } catch (NoResultException e) { return new ResponseEntity("[ ]", headers, HttpStatus.NOT_FOUND); + + } catch (TooManyResultsException e) { + return new ResponseEntity("[ ]", headers, HttpStatus.CONFLICT); } } diff --git a/src/main/java/com/labsynch/labseer/service/ExperimentService.java b/src/main/java/com/labsynch/labseer/service/ExperimentService.java index 4725ad0b7..bb7fc3bad 100755 --- a/src/main/java/com/labsynch/labseer/service/ExperimentService.java +++ b/src/main/java/com/labsynch/labseer/service/ExperimentService.java @@ -51,6 +51,10 @@ public Collection getExperimentNodesByProtocolTree( public Collection findExperimentsByMetadataJson( List metaDataList); + + public Collection findExperimentsByProtocolCodeName(String query, List projects) + throws TooManyResultsException; + public Collection findExperimentsByGenericMetaDataSearch(String query, String userName, Boolean includeDeleted) throws TooManyResultsException; diff --git a/src/main/java/com/labsynch/labseer/service/ExperimentServiceImpl.java b/src/main/java/com/labsynch/labseer/service/ExperimentServiceImpl.java index 87c4b5101..a65f08caf 100755 --- a/src/main/java/com/labsynch/labseer/service/ExperimentServiceImpl.java +++ b/src/main/java/com/labsynch/labseer/service/ExperimentServiceImpl.java @@ -1118,6 +1118,45 @@ public Collection findExperimentsByGenericMetaDataSearch(String quer } + public Collection findExperimentsByProtocolCodeName(String codeName, List projects) + throws TooManyResultsException, NoResultException { + List protocols = Protocol.findProtocolsByCodeNameEqualsAndIgnoredNot(codeName, true).getResultList(); + + if (protocols.size() > 1) { + logger.error("ERROR: multiple protocols found with the same code name"); + throw new RuntimeException("ERROR: multiple protocols found with the same code name"); + } else if (protocols.size() < 1) { + logger.warn("WARN: no protocols found with the query code name"); + throw new NoResultException("WARN: no protocols found with the query code name"); + } + + Collection rawResults = Experiment.findExperimentsByProtocol(protocols.get(0)).getResultList(); + if (propertiesUtilService.getRestrictExperiments()) { + projects.add("unassigned"); + Collection results = new HashSet(); + for (Experiment rawResult : rawResults) { + String experimentProject = null; + for (ExperimentState state : rawResult.getLsStates()) { + if (!state.isIgnored() && !state.isDeleted()) { + for (ExperimentValue value : state.getLsValues()) { + if (value.getLsKind().equals("project") && !value.getDeleted() && !value.getIgnored()) { + experimentProject = value.getCodeValue(); + break; + } + } + } + } + if (projects.contains(experimentProject)) { + results.add(rawResult); + } + } + return results; + } else { + return rawResults; + } + + } + @Override public Collection findExperimentsByGenericMetaDataSearch(String queryString, List projects, Boolean includeDeleted) throws TooManyResultsException { From f94a2dbedc8f1f9462627a75d97bf723e1a43d3b Mon Sep 17 00:00:00 2001 From: Brian Bolt Date: Wed, 16 Aug 2023 17:03:13 -0700 Subject: [PATCH 2/2] Throw TooManyResultsException instead --- .../com/labsynch/labseer/service/ExperimentServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/labsynch/labseer/service/ExperimentServiceImpl.java b/src/main/java/com/labsynch/labseer/service/ExperimentServiceImpl.java index a65f08caf..cc0ef0159 100755 --- a/src/main/java/com/labsynch/labseer/service/ExperimentServiceImpl.java +++ b/src/main/java/com/labsynch/labseer/service/ExperimentServiceImpl.java @@ -1124,7 +1124,7 @@ public Collection findExperimentsByProtocolCodeName(String codeName, if (protocols.size() > 1) { logger.error("ERROR: multiple protocols found with the same code name"); - throw new RuntimeException("ERROR: multiple protocols found with the same code name"); + throw new TooManyResultsException("ERROR: multiple protocols found with the same code name"); } else if (protocols.size() < 1) { logger.warn("WARN: no protocols found with the query code name"); throw new NoResultException("WARN: no protocols found with the query code name");