From c790f9aa38bad01a0facca55c846b10a9ecde2c1 Mon Sep 17 00:00:00 2001 From: michaelkain Date: Fri, 3 Nov 2023 09:44:51 +0100 Subject: [PATCH] ShUp: adds find acquisition equipment by serial number to shup client --- .../AcquisitionEquipmentRepository.java | 2 +- .../AcquisitionEquipmentServiceImpl.java | 2 +- .../service/RabbitMqCenterService.java | 2 +- .../rest/ShanoirUploaderServiceClient.java | 21 ++++++++++++++++++- .../test/importer/CenterAndEquipmentTest.java | 10 ++++++--- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/shanoir-ng-studies/src/main/java/org/shanoir/ng/acquisitionequipment/repository/AcquisitionEquipmentRepository.java b/shanoir-ng-studies/src/main/java/org/shanoir/ng/acquisitionequipment/repository/AcquisitionEquipmentRepository.java index 8f2aa5f0fa..cd33ed60d4 100644 --- a/shanoir-ng-studies/src/main/java/org/shanoir/ng/acquisitionequipment/repository/AcquisitionEquipmentRepository.java +++ b/shanoir-ng-studies/src/main/java/org/shanoir/ng/acquisitionequipment/repository/AcquisitionEquipmentRepository.java @@ -30,7 +30,7 @@ public interface AcquisitionEquipmentRepository extends CrudRepository findByCenterStudyCenterListStudyId(Long studyId); - List findBySerialNumber(String serialNumber); + List findBySerialNumberContaining(String serialNumber); List findByManufacturerModelId(Long manufacturerModelId); diff --git a/shanoir-ng-studies/src/main/java/org/shanoir/ng/acquisitionequipment/service/AcquisitionEquipmentServiceImpl.java b/shanoir-ng-studies/src/main/java/org/shanoir/ng/acquisitionequipment/service/AcquisitionEquipmentServiceImpl.java index 1f1945d10e..4c2f5d61b2 100644 --- a/shanoir-ng-studies/src/main/java/org/shanoir/ng/acquisitionequipment/service/AcquisitionEquipmentServiceImpl.java +++ b/shanoir-ng-studies/src/main/java/org/shanoir/ng/acquisitionequipment/service/AcquisitionEquipmentServiceImpl.java @@ -79,7 +79,7 @@ public List findAllByStudyId(Long studyId) { } public List findAllBySerialNumber(String serialNumber) { - return this.repository.findBySerialNumber(serialNumber); + return this.repository.findBySerialNumberContaining(serialNumber); } public AcquisitionEquipment create(AcquisitionEquipment entity) { diff --git a/shanoir-ng-studies/src/main/java/org/shanoir/ng/acquisitionequipment/service/RabbitMqCenterService.java b/shanoir-ng-studies/src/main/java/org/shanoir/ng/acquisitionequipment/service/RabbitMqCenterService.java index b95ae9d1ea..9659e3248d 100644 --- a/shanoir-ng-studies/src/main/java/org/shanoir/ng/acquisitionequipment/service/RabbitMqCenterService.java +++ b/shanoir-ng-studies/src/main/java/org/shanoir/ng/acquisitionequipment/service/RabbitMqCenterService.java @@ -84,7 +84,7 @@ public String findAcquisitionEquipments(String message) { @Transactional public Long getEquipmentFromCode(String message) { try { - List equipList = acquisitionEquipmentService.findBySerialNumber(message); + List equipList = acquisitionEquipmentService.findBySerialNumberContaining(message); if (equipList == null || equipList.isEmpty()) { return null; } diff --git a/shanoir-uploader/src/main/java/org/shanoir/uploader/service/rest/ShanoirUploaderServiceClient.java b/shanoir-uploader/src/main/java/org/shanoir/uploader/service/rest/ShanoirUploaderServiceClient.java index 3f5f17f920..4d01f0f96b 100644 --- a/shanoir-uploader/src/main/java/org/shanoir/uploader/service/rest/ShanoirUploaderServiceClient.java +++ b/shanoir-uploader/src/main/java/org/shanoir/uploader/service/rest/ShanoirUploaderServiceClient.java @@ -458,6 +458,25 @@ public List findAcquisitionEquipments() throws Exception { return null; } + public List findAcquisitionEquipmentsBySerialNumber(String serialNumber) throws Exception { + long startTime = System.currentTimeMillis(); + try (CloseableHttpResponse response = httpService.get(this.serviceURLAcquisitionEquipmentsBySerialNumber)) { + long stopTime = System.currentTimeMillis(); + long elapsedTime = stopTime - startTime; + logger.info("findAcquisitionEquipmentsBySerialNumber: " + elapsedTime + "ms"); + int code = response.getCode(); + if (code == HttpStatus.SC_OK) { + List acquisitionEquipments = Util.getMappedList(response, + AcquisitionEquipment.class); + return acquisitionEquipments; + } else { + logger.error("Could not find acquisition equipments by serial number (status code: " + code + ", message: " + + apiResponseMessages.getOrDefault(code, "unknown status code") + ")"); + } + } + return null; + } + public void uploadFile(String tempDirId, File file) throws Exception { try (CloseableHttpResponse response = httpService.postFile(this.serviceURLImporterCreateTempDir, tempDirId, file)) { @@ -467,7 +486,7 @@ public void uploadFile(String tempDirId, File file) throws Exception { logger.error("Error in uploadFile: with tempDirId " + tempDirId + " with file (path: " + file.getAbsolutePath() + ", size in bytes: " + Files.size(file.toPath()) + "), status code: " + code + ", message: " + apiResponseMessages.getOrDefault(code, "unknown status code")); - throw new Exception("Error in uploadFile"); + throw new Exception("Error in uploadFile."); } } } diff --git a/shanoir-uploader/src/test/java/org/shanoir/uploader/test/importer/CenterAndEquipmentTest.java b/shanoir-uploader/src/test/java/org/shanoir/uploader/test/importer/CenterAndEquipmentTest.java index b962b6d0ec..7f52f08589 100644 --- a/shanoir-uploader/src/test/java/org/shanoir/uploader/test/importer/CenterAndEquipmentTest.java +++ b/shanoir-uploader/src/test/java/org/shanoir/uploader/test/importer/CenterAndEquipmentTest.java @@ -1,5 +1,6 @@ package org.shanoir.uploader.test.importer; +import java.util.List; import java.util.UUID; import org.apache.log4j.Logger; @@ -25,7 +26,7 @@ public void createCenter() throws Exception { } @Test - public void createEquipment() throws Exception { + public void createEquipmentAndFindIt() throws Exception { Center center = new Center(); center.setName("Center-Name-" + UUID.randomUUID().toString()); Center createdCenter = shUpClient.createCenter(center); @@ -42,11 +43,14 @@ public void createEquipment() throws Exception { ManufacturerModel createdManufacturerModel = shUpClient.createManufacturerModel(manufacturerModel); Assertions.assertNotNull(createdManufacturerModel); AcquisitionEquipment equipment = new AcquisitionEquipment(); - equipment.setSerialNumber("Serial-Number-" + UUID.randomUUID().toString()); + String serialNumberRandom = UUID.randomUUID().toString(); + equipment.setSerialNumber("Serial-Number-" + serialNumberRandom); equipment.setCenter(new IdName(createdCenter.getId(), createdCenter.getName())); equipment.setManufacturerModel(createdManufacturerModel); AcquisitionEquipment createdEquipment = shUpClient.createEquipment(equipment); Assertions.assertNotNull(createdEquipment); + List equipments = shUpClient.findAcquisitionEquipmentsBySerialNumber(serialNumberRandom); + Assertions.assertNotNull(equipments); } - + }