From 037659e129ca0a398a436db695a64b4596763a6b Mon Sep 17 00:00:00 2001 From: Philip Cheung Date: Sat, 13 May 2023 12:20:10 -0700 Subject: [PATCH] Added conservative option to Protocol.findProtocolByProtocolName whcih allows for uselike -- updated most calls to false) --- .../labseer/api/ApiExperimentController.java | 2 +- .../labseer/api/ApiProtocolController.java | 15 +++++++++++++-- .../com/labsynch/labseer/domain/Protocol.java | 10 ++++++++-- .../labseer/service/ProtocolServiceTest.java | 2 +- 4 files changed, 23 insertions(+), 6 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..fcb07a560 100755 --- a/src/main/java/com/labsynch/labseer/api/ApiExperimentController.java +++ b/src/main/java/com/labsynch/labseer/api/ApiExperimentController.java @@ -245,7 +245,7 @@ public ResponseEntity listJson( } } } else if (protocolKind == null && protocolName != null) { - List protocols = Protocol.findProtocolByProtocolName(protocolName); + List protocols = Protocol.findProtocolByProtocolName(protocolName, false); for (Protocol protocol : protocols) { List experiments = Experiment.findExperimentsByProtocol(protocol).getResultList(); for (Experiment experiment : experiments) { diff --git a/src/main/java/com/labsynch/labseer/api/ApiProtocolController.java b/src/main/java/com/labsynch/labseer/api/ApiProtocolController.java index a668811e5..d93f78107 100644 --- a/src/main/java/com/labsynch/labseer/api/ApiProtocolController.java +++ b/src/main/java/com/labsynch/labseer/api/ApiProtocolController.java @@ -371,7 +371,7 @@ public ResponseEntity jsonFindProtocolsByProtocolNameEqualsRou String protocolName = restOfTheUrl.split("protocolname\\/")[1].replaceAll("/$", ""); HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "application/json; charset=utf-8"); - return new ResponseEntity(Protocol.toJsonArray(Protocol.findProtocolByProtocolName(protocolName)), + return new ResponseEntity(Protocol.toJsonArray(Protocol.findProtocolByProtocolName(protocolName, false)), headers, HttpStatus.OK); } @@ -382,7 +382,18 @@ public ResponseEntity jsonFindProtocolsByProtocolNameEqualsGet @RequestParam("protocolName") String protocolName) { HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "application/json; charset=utf-8"); - return new ResponseEntity(Protocol.toJsonArray(Protocol.findProtocolByProtocolName(protocolName)), + return new ResponseEntity(Protocol.toJsonArray(Protocol.findProtocolByProtocolName(protocolName, false)), + headers, HttpStatus.OK); + } + + @Transactional + @RequestMapping(params = "FindByProtocolNameLike", method = RequestMethod.GET, headers = "Accept=application/json") + @ResponseBody + public ResponseEntity jsonFindProtocolsByProtocolNameLikeGet( + @RequestParam("protocolName") String protocolName) { + HttpHeaders headers = new HttpHeaders(); + headers.add("Content-Type", "application/json; charset=utf-8"); + return new ResponseEntity(Protocol.toJsonArray(Protocol.findProtocolByProtocolName(protocolName, true)), headers, HttpStatus.OK); } diff --git a/src/main/java/com/labsynch/labseer/domain/Protocol.java b/src/main/java/com/labsynch/labseer/domain/Protocol.java index 8daf15bba..8492a1615 100755 --- a/src/main/java/com/labsynch/labseer/domain/Protocol.java +++ b/src/main/java/com/labsynch/labseer/domain/Protocol.java @@ -129,8 +129,14 @@ public static com.labsynch.labseer.domain.Protocol update(com.labsynch.labseer.d return updatedProtocol; } - public static List findProtocolByProtocolName(String protocolName) { - List foundProtocolLabels = ProtocolLabel.findProtocolLabelsByName(protocolName).getResultList(); + public static List findProtocolByProtocolName(String protocolName, boolean useLike) { + List foundProtocolLabels; + if (useLike) { + foundProtocolLabels = ProtocolLabel.findProtocolLabelsByName(protocolName).getResultList(); + } else { + foundProtocolLabels = ProtocolLabel.findProtocolLabelsByNameLike(protocolName).getResultList(); + } + List protocolList = new ArrayList(); for (ProtocolLabel protocolLabel : foundProtocolLabels) { Protocol protocol = Protocol.findProtocol(protocolLabel.getProtocol().getId()); diff --git a/src/test/java/com/labsynch/labseer/service/ProtocolServiceTest.java b/src/test/java/com/labsynch/labseer/service/ProtocolServiceTest.java index a3fb87f73..e6de4421c 100755 --- a/src/test/java/com/labsynch/labseer/service/ProtocolServiceTest.java +++ b/src/test/java/com/labsynch/labseer/service/ProtocolServiceTest.java @@ -46,7 +46,7 @@ public class ProtocolServiceTest { // @Test public void FindProtocolByName_Test10() { - List protocols = Protocol.findProtocolByProtocolName("test"); + List protocols = Protocol.findProtocolByProtocolName("test", false); logger.info("Found number of protocols: " + protocols.size()); for (Protocol protocol : protocols) { logger.info(protocol.toJson());