use of uk.ac.bbsrc.tgac.miso.core.data.Box in project miso-lims by miso-lims.
the class DefaultBoxService method discardAllContents.
@Override
public void discardAllContents(Box box) throws IOException {
Box managed = get(box.getId());
addBoxContentsChangeLog(managed, String.format("Discarded all box contents (%d items)", managed.getBoxPositions().size()));
for (BoxPosition bp : managed.getBoxPositions().values()) {
discardBoxable(bp.getBoxableId());
}
managed.getBoxPositions().clear();
boxStore.save(managed);
}
use of uk.ac.bbsrc.tgac.miso.core.data.Box in project miso-lims by miso-lims.
the class DefaultBoxService method discardSingleItem.
@Override
public void discardSingleItem(Box box, String position) throws IOException {
Box managed = boxStore.get(box.getId());
BoxPosition bp = managed.getBoxPositions().get(position);
if (bp == null) {
throw new IllegalArgumentException("No item in the specified box position");
}
Boxable target = boxStore.getBoxable(bp.getBoxableId());
addBoxContentsChangeLog(managed, String.format("Discarded %s (%s) from %s", target.getAlias(), target.getName(), target.getBoxPosition()));
discardBoxable(bp.getBoxableId());
managed.getBoxPositions().remove(position);
boxStore.save(managed);
}
use of uk.ac.bbsrc.tgac.miso.core.data.Box in project miso-lims by miso-lims.
the class DefaultBoxService method throwIfBoxPositionIsFilled.
@Override
public void throwIfBoxPositionIsFilled(Boxable boxable) throws IOException {
if (boxable.getBox() == null || boxable.getBoxPosition() == null)
return;
Box box = get(boxable.getBox().getId());
BoxPosition bp = box.getBoxPositions().get(boxable.getBoxPosition());
if (bp == null)
return;
if (!bp.getBoxableId().equals(new BoxableId(boxable.getEntityType(), boxable.getId()))) {
throw new ValidationException(new ValidationError("boxPosition", "Position is not available"));
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.Box in project miso-lims by miso-lims.
the class BoxRestController method toBoxWithOriginalContents.
private Box toBoxWithOriginalContents(BoxDto dto) throws IOException {
Box original = getBox(dto.getId());
Box box = Dtos.to(dto);
// reset contents in-case they were changed while the box was being edited
box.setBoxPositions(original.getBoxPositions());
return box;
}
use of uk.ac.bbsrc.tgac.miso.core.data.Box in project miso-lims by miso-lims.
the class BoxRestController method recreateBoxFromPrefix.
@PostMapping("/{boxId}/positions/fill-by-pattern")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void recreateBoxFromPrefix(@PathVariable long boxId, @RequestParam(name = "prefix", required = true) String prefix, @RequestParam(name = "suffix", required = true) String suffix) throws IOException {
Box box = getBox(boxId);
if (!SUFFIXES.containsKey(suffix)) {
throw new RestException("Invalid suffix", Status.BAD_REQUEST);
}
BiFunction<Integer, Integer, String> suffixGenerator = SUFFIXES.get(suffix).apply(box.getSize());
Map<String, String> positionToBarcode = new HashMap<>();
for (int row = 0; row < box.getSize().getRows(); row++) {
for (int column = 0; column < box.getSize().getColumns(); column++) {
positionToBarcode.put(BoxUtils.getPositionString(row, column), prefix + suffixGenerator.apply(row, column));
}
}
Map<String, BoxableView> barcodesToBoxables = boxService.getViewsFromBarcodeList(positionToBarcode.values()).stream().collect(Collectors.toMap(BoxableView::getIdentificationBarcode, Function.identity()));
box.setBoxPositions(positionToBarcode.entrySet().stream().filter(entry -> barcodesToBoxables.containsKey(entry.getValue())).collect(Collectors.toMap(Map.Entry::getKey, entry -> {
BoxableView boxable = barcodesToBoxables.get(entry.getValue());
BoxableId id = new BoxableId(boxable.getEntityType(), boxable.getId());
return new BoxPosition(box, entry.getKey(), id);
})));
boxService.save(box);
}
Aggregations