use of uk.ac.bbsrc.tgac.miso.core.data.BoxPosition in project miso-lims by miso-lims.
the class BoxPageIT method testMoveItemWithinBox.
@Test
public void testMoveItemWithinBox() {
final String initialPosition = "F10";
final String finalPosition = "F12";
Library lib = (Library) getSession().get(LibraryImpl.class, 505L);
assertNotNull(lib);
BoxableId libBoxableId = new BoxableId(lib.getEntityType(), lib.getId());
// confirm positions pre-move
Box initial = (Box) getSession().get(BoxImpl.class, 500L);
BoxPosition itemAtInitialPosition = initial.getBoxPositions().get(initialPosition);
assertNotNull(itemAtInitialPosition);
assertNull(initial.getBoxPositions().get(finalPosition));
assertEquals(libBoxableId, itemAtInitialPosition.getBoxableId());
BoxPage page = getBoxPage(500L);
BoxVisualization visualization = page.getVisualization();
assertFalse("checking that library is in position F10", visualization.isEmptyPosition(initialPosition));
assertTrue("checking which library is in position F10", visualization.getPositionTitle(initialPosition).contains(lib.getAlias()));
assertTrue("checking that no tube is in position F12", visualization.isEmptyPosition(finalPosition));
visualization.selectPosition(finalPosition);
visualization.searchBoxables(lib.getIdentificationBarcode());
visualization.updatePosition(false);
// confirm positions post-move
Box updated = (Box) getSession().get(BoxImpl.class, 500L);
assertNull(updated.getBoxPositions().get(initialPosition));
BoxPosition updatedAtFinalPosition = updated.getBoxPositions().get(finalPosition);
assertNotNull(updatedAtFinalPosition);
assertEquals(libBoxableId, updatedAtFinalPosition.getBoxableId());
BoxPage afterSave = getBoxPage(500L);
BoxVisualization afterVisualization = afterSave.getVisualization();
assertTrue("checking that no tube is in position F10", afterVisualization.isEmptyPosition(initialPosition));
assertFalse("checking that library is in position F12", afterVisualization.isEmptyPosition(finalPosition));
assertTrue("checking which library is in position F12", afterVisualization.getPositionTitle(finalPosition).contains(lib.getAlias()));
}
use of uk.ac.bbsrc.tgac.miso.core.data.BoxPosition 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);
}
use of uk.ac.bbsrc.tgac.miso.core.data.BoxPosition in project miso-lims by miso-lims.
the class BoxRestController method bulkUpdatePositions.
@PostMapping(value = "/{boxId}/bulk-update")
@ResponseBody
public BoxDto bulkUpdatePositions(@PathVariable long boxId, @RequestBody List<BulkUpdateRequestItem> items) throws IOException {
Box box = boxService.get(boxId);
if (box == null) {
throw new RestException("Box " + boxId + " not found", Status.NOT_FOUND);
}
ValidationResult validation = new ValidationResult();
Map<String, BoxableView> updates = new HashMap<>();
for (BulkUpdateRequestItem item : items) {
if (!box.isValidPosition(item.getPosition())) {
validation.addError(new ValidationError("Invalid position given: " + item.getPosition()));
}
if (item.getSearchString() == null) {
box.getBoxPositions().remove(item.getPosition());
continue;
}
List<BoxableView> searchResults = boxService.getBoxableViewsBySearch(item.getSearchString());
if (searchResults == null || searchResults.isEmpty()) {
validation.addError(new ValidationError("No item found by searching '" + item.getSearchString() + "' for position " + item.getPosition()));
} else if (searchResults.size() > 1) {
validation.addError(new ValidationError("Multiple items matched search '" + item.getSearchString() + "' for position " + item.getPosition()));
} else {
BoxableView boxable = searchResults.get(0);
// if the selected item is already in the box, remove it here and add it to the correct position in next step
if (Long.valueOf(box.getId()).equals(boxable.getBoxId())) {
box.getBoxPositions().remove(boxable.getBoxPosition());
}
updates.put(item.getPosition(), boxable);
}
}
for (Entry<String, BoxableView> entry : updates.entrySet()) {
// if an item already exists at this position, its location will be set to unknown.
BoxableId id = new BoxableId(entry.getValue().getEntityType(), entry.getValue().getId());
BoxPosition bp = new BoxPosition(box, entry.getKey(), id);
box.getBoxPositions().put(entry.getKey(), bp);
}
validation.throwIfInvalid();
boxService.save(box);
Box updated = boxService.get(boxId);
List<BoxableView> updatedContents = boxService.getBoxContents(boxId);
return Dtos.asDtoWithBoxables(updated, updatedContents);
}
use of uk.ac.bbsrc.tgac.miso.core.data.BoxPosition 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.BoxPosition 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);
}
Aggregations