Skip to content

Commit

Permalink
ShUp: adds find acquisition equipment by serial number to shup client
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkain committed Nov 3, 2023
1 parent 0936dfa commit c790f9a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface AcquisitionEquipmentRepository extends CrudRepository<Acquisiti

List<AcquisitionEquipment> findByCenterStudyCenterListStudyId(Long studyId);

List<AcquisitionEquipment> findBySerialNumber(String serialNumber);
List<AcquisitionEquipment> findBySerialNumberContaining(String serialNumber);

List<AcquisitionEquipment> findByManufacturerModelId(Long manufacturerModelId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public List<AcquisitionEquipment> findAllByStudyId(Long studyId) {
}

public List<AcquisitionEquipment> findAllBySerialNumber(String serialNumber) {
return this.repository.findBySerialNumber(serialNumber);
return this.repository.findBySerialNumberContaining(serialNumber);
}

public AcquisitionEquipment create(AcquisitionEquipment entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public String findAcquisitionEquipments(String message) {
@Transactional
public Long getEquipmentFromCode(String message) {
try {
List<AcquisitionEquipment> equipList = acquisitionEquipmentService.findBySerialNumber(message);
List<AcquisitionEquipment> equipList = acquisitionEquipmentService.findBySerialNumberContaining(message);
if (equipList == null || equipList.isEmpty()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,25 @@ public List<AcquisitionEquipment> findAcquisitionEquipments() throws Exception {
return null;
}

public List<AcquisitionEquipment> 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<AcquisitionEquipment> 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)) {
Expand All @@ -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.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.shanoir.uploader.test.importer;

import java.util.List;
import java.util.UUID;

import org.apache.log4j.Logger;
Expand All @@ -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);
Expand All @@ -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<AcquisitionEquipment> equipments = shUpClient.findAcquisitionEquipmentsBySerialNumber(serialNumberRandom);
Assertions.assertNotNull(equipments);
}

}

0 comments on commit c790f9a

Please sign in to comment.