use of uk.ac.bbsrc.tgac.miso.dto.Dtos in project miso-lims by miso-lims.
the class ChangeLogTag method doStartTagInternal.
@Override
protected int doStartTagInternal() throws Exception {
ChangeLoggable item = (ChangeLoggable) this.item;
if (item.getChangeLog().isEmpty()) {
return SKIP_BODY;
}
ObjectMapper mapper = new ObjectMapper();
pageContext.getOut().append(String.format("<br/><h1>Changes</h1><table id='changelog' class='display no-border ui-widget-content'></table><script type='text/javascript'>jQuery(document).ready(function () { ListUtils.createStaticTable('changelog', ListTarget.changelog, {}, %1$s);});</script>", mapper.writeValueAsString(item.getChangeLog().stream().map(Dtos::asDto).collect(Collectors.toList()))));
return SKIP_BODY;
}
use of uk.ac.bbsrc.tgac.miso.dto.Dtos in project miso-lims by miso-lims.
the class BoxRestController method getBoxScan.
/**
* Gets the Box Scanner scan results (map of box positions and barcodes)
*
* @param boxId
* @param requestData
* @return a serialized box object containing the Boxable items
* linked with each barcode at each position indicated by the scan results. Any errors are returned with a message containing the
* type of
* error (unable to read at certain positions; multiple items associated with a single barcode; unable to find box scanner), a
* message
* about the error, the positions that were successfully read (if applicable) and the positions at which the error was triggered
* (if
* applicable)
*/
@PostMapping(value = "/{boxId}/scan")
@ResponseBody
public ScanResultsDto getBoxScan(@PathVariable(required = true) int boxId, @RequestBody(required = true) ScanRequest requestData) {
try {
BoxScanner boxScanner = boxScanners.get(requestData.getScannerName());
if (boxScanner == null) {
throw new RestException("Invalid scanner specified", Status.BAD_REQUEST);
}
BoxScan scan = boxScanner.getScan();
if (scan == null) {
throw new RestException("The scanner did not detect a box!", Status.CONFLICT);
}
Map<String, String> barcodesByPosition = scan.getBarcodesMap();
// Extract the valid barcodes and build a barcode to item map
Set<String> validBarcodes = barcodesByPosition.values().stream().filter(barcode -> isRealBarcode(scan, barcode)).collect(Collectors.toSet());
Map<String, BoxableView> boxablesByBarcode = boxService.getViewsFromBarcodeList(validBarcodes).stream().collect(Collectors.toMap(BoxableView::getIdentificationBarcode, Function.identity()));
// For all the valid barcodes, build a list of DTOs with the updated positions
List<BoxableDto> items = barcodesByPosition.entrySet().stream().filter(entry -> isRealBarcode(scan, entry.getValue()) && boxablesByBarcode.containsKey(entry.getValue())).map(entry -> {
BoxableDto dto = Dtos.asDto(boxablesByBarcode.get(entry.getValue()));
dto.setCoordinates(entry.getKey());
return dto;
}).collect(Collectors.toList());
// Collect all the errors
List<ErrorMessage> errors = new ArrayList<>();
// If there's a barcode that wasn't found in the DB, create an error.
barcodesByPosition.entrySet().stream().filter(entry -> isRealBarcode(scan, entry.getValue()) && !boxablesByBarcode.containsKey(entry.getValue())).map(entry -> {
ErrorMessage dto = new ErrorMessage();
dto.setCoordinates(entry.getKey());
dto.setMessage("Barcode " + entry.getValue() + " not found.");
return dto;
}).forEachOrdered(errors::add);
// If there was a read error, produce an error.
scan.getReadErrorPositions().stream().map(position -> {
ErrorMessage dto = new ErrorMessage();
dto.setCoordinates(position);
dto.setMessage("Cannot read tube.");
return dto;
}).forEachOrdered(errors::add);
long totalBarcodes = barcodesByPosition.values().stream().filter(barcode -> isRealBarcode(scan, barcode)).count();
if (validBarcodes.size() != totalBarcodes) {
ErrorMessage dto = new ErrorMessage();
dto.message = "Duplicate barcodes detected!";
errors.add(dto);
}
// Build the diffs for this box
List<DiffMessage> diffs = new ArrayList<>();
Box box;
Map<String, BoxableView> boxables;
try {
box = boxService.get(boxId);
boxables = boxService.getBoxContents(boxId).stream().collect(Collectors.toMap(BoxableView::getBoxPosition, Function.identity()));
} catch (IOException e) {
throw new RestException("Cannot get the Box: " + e.getMessage(), Status.INTERNAL_SERVER_ERROR);
}
if (box.getSize().getRows() != scan.getRowCount() || box.getSize().getColumns() != scan.getColumnCount())
throw new RestException(String.format("Box is %d×%d, but scanner detected %d×%d.", box.getSize().getRows(), box.getSize().getColumns(), scan.getRowCount(), scan.getColumnCount()), Status.BAD_REQUEST);
box.getSize().positionStream().map(position -> {
BoxableView originalItem = boxables.containsKey(position) ? boxables.get(position) : null;
BoxableView newItem = barcodesByPosition.containsKey(position) && boxablesByBarcode.containsKey(barcodesByPosition.get(position)) ? boxablesByBarcode.get(barcodesByPosition.get(position)) : null;
if (originalItem != null && newItem != null && !newItem.getIdentificationBarcode().equals(originalItem.getIdentificationBarcode())) {
DiffMessage dto = new DiffMessage();
dto.action = "changed";
dto.modified = Dtos.asDto(newItem);
dto.original = Dtos.asDto(originalItem);
return dto;
} else if (originalItem != null && newItem == null) {
DiffMessage dto = new DiffMessage();
dto.action = "removed";
dto.original = Dtos.asDto(originalItem);
return dto;
} else if (originalItem == null && newItem != null) {
DiffMessage dto = new DiffMessage();
dto.action = "added";
dto.modified = Dtos.asDto(newItem);
return dto;
} else {
return null;
}
}).filter(Objects::nonNull);
ScanResultsDto scanResults = new ScanResultsDto();
scanResults.setEmptyPositions(//
barcodesByPosition.entrySet().stream().filter(//
entry -> !isRealBarcode(scan, entry.getValue())).map(//
Entry::getKey).collect(Collectors.toList()));
scanResults.setItems(items);
scanResults.setErrors(errors);
scanResults.setDiffs(diffs);
scanResults.setRows(scan.getRowCount());
scanResults.setColumns(scan.getColumnCount());
return scanResults;
} catch (IntegrationException | IOException e) {
throw new RestException("Error scanning box: " + e.getMessage(), Status.INTERNAL_SERVER_ERROR);
}
}
use of uk.ac.bbsrc.tgac.miso.dto.Dtos in project miso-lims by miso-lims.
the class LabRestController method updateLab.
@PutMapping(value = "/{id}", headers = { "Content-type=application/json" })
@ResponseBody
public LabDto updateLab(@PathVariable("id") Long id, @RequestBody LabDto labDto, UriComponentsBuilder uriBuilder) throws IOException {
LabDto updated = RestUtils.updateObject("Lab", id, labDto, Dtos::to, labService, Dtos::asDto);
constantsController.refreshConstants();
return updated;
}
use of uk.ac.bbsrc.tgac.miso.dto.Dtos in project miso-lims by miso-lims.
the class RunRestController method getPotentialExperiments.
@GetMapping("/{runId}/potentialExperiments")
@ResponseBody
public List<StudiesForExperiment> getPotentialExperiments(@PathVariable long runId) throws IOException {
Run run = getRun(runId);
RunDto runDto = Dtos.asDto(run);
InstrumentModelDto instrumentModelDto = Dtos.asDto(run.getSequencer().getInstrumentModel());
Map<Library, List<Partition>> libraryGroups = getLibraryGroups(run);
return libraryGroups.entrySet().stream().map(group -> new Pair<>(group.getKey(), group.getValue().stream().map(partition -> Dtos.asDto(partition, indexChecker)).map(partitionDto -> new RunPartitionDto(runDto, partitionDto)).collect(Collectors.toList()))).map(group -> {
StudiesForExperiment result = new StudiesForExperiment();
result.experiment = new ExperimentDto();
result.experiment.setLibrary(Dtos.asDto(group.getKey(), false));
result.experiment.setInstrumentModel(instrumentModelDto);
result.experiment.setPartitions(group.getValue());
result.studies = group.getKey().getSample().getProject().getStudies().stream().map(Dtos::asDto).collect(Collectors.toList());
return result;
}).collect(Collectors.toList());
}
use of uk.ac.bbsrc.tgac.miso.dto.Dtos in project miso-lims by miso-lims.
the class SampleClassRestController method createSampleClass.
@PostMapping(headers = { "Content-type=application/json" })
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public SampleClassDto createSampleClass(@RequestBody SampleClassDto sampleClassDto) throws IOException {
return RestUtils.createObject("Sample Class", sampleClassDto, Dtos::to, sampleClassService, sampleClass -> {
SampleClassDto dto = Dtos.asDto(sampleClass);
constantsController.refreshConstants();
return dto;
});
}
Aggregations