@Override public void beforeDelete(Box object) throws IOException { object.getBoxPositions().clear(); save(object); }
@Override public void discardAllContents(Box box) throws IOException { Box managed = get(box.getId()); authorizationManager.throwIfNotWritable(managed); 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); }
@Override public void removeBoxableFromBox(Boxable boxable) throws IOException { if (boxable.getBox() != null) { boxable.getBox().getBoxPositions().remove(boxable.getBoxPosition()); currentSession().save(boxable.getBox()); } }
@Override public void discardSingleItem(Box box, String position) throws IOException { Box managed = boxStore.get(box.getId()); authorizationManager.throwIfNotWritable(managed); 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)", target.getAlias(), target.getName())); discardBoxable(bp.getBoxableId()); managed.getBoxPositions().remove(position); boxStore.save(managed); }
@Override public void removeBoxableFromBox(BoxableView boxable) throws IOException { if (boxable.getBoxId() == null) { return; } Box box = get(boxable.getBoxId()); box.getBoxPositions().remove(boxable.getBoxPosition()); currentSession().update(box); // flush required to avoid constraint violation incase item is immediately added to another box or the same one // NOTE: this flush will cause ALL Hibernate-managed items to be saved to the db in their current state, even if their `save` method // hasn't explicitly been called yet currentSession().flush(); }
@Override public void beforeDelete(Pool object) throws IOException { Set<PoolOrder> orders = poolOrderService.getByPool(object.getId()); poolOrderService.bulkDelete(orders); Box box = object.getBox(); if (box != null) { box.getBoxPositions().remove(object.getBoxPosition()); boxService.save(box); } }
List<BoxableId> ids = box.getBoxPositions().values() .stream() .map(BoxPosition::getBoxableId) for (Map.Entry<String, BoxPosition> entry : box.getBoxPositions().entrySet()) { BoxPosition managedPos = managed.getBoxPositions().get(entry.getKey()); BoxPosition newPos = entry.getValue(); for (Map.Entry<String, BoxPosition> entry : managed.getBoxPositions().entrySet()) { if (box.getBoxPositions().keySet().contains(entry.getKey()) && box.getBoxPositions().get(entry.getKey()).getBoxableId().equals(entry.getValue().getBoxableId())) { movedWithinBox.forEach(bp -> managed.getBoxPositions().remove(bp.getPosition())); removed.forEach(boxable -> managed.getBoxPositions().remove(boxable.getBoxPosition())); if (!movedWithinBox.isEmpty() || !removed.isEmpty()) { boxStore.save(managed); for (String pos : box.getBoxPositions().keySet()) { if (!managed.getBoxPositions().containsKey(pos) || !managed.getBoxPositions().get(pos).getBoxableId().equals(box.getBoxPositions().get(pos).getBoxableId())) { managed.getBoxPositions().put(pos, new BoxPosition(managed, pos, box.getBoxPositions().get(pos).getBoxableId()));
@Override public void beforeDelete(Sample object) throws IOException { List<Workset> worksets = worksetService.listBySample(object.getId()); for (Workset workset : worksets) { workset.getSamples().removeIf(sam -> sam.getId() == object.getId()); worksetService.save(workset); } Box box = object.getBox(); if (box != null) { box.getBoxPositions().remove(object.getBoxPosition()); boxService.save(box); } }
@Override public void beforeDelete(Library object) throws IOException { List<Workset> worksets = worksetService.listByLibrary(object.getId()); for (Workset workset : worksets) { workset.getLibraries().removeIf(lib -> lib.getId() == object.getId()); worksetService.save(workset); } Box box = object.getBox(); if (box != null) { box.getBoxPositions().remove(object.getBoxPosition()); boxService.save(box); } }
@Override public void beforeDelete(LibraryDilution object) throws IOException { List<Workset> worksets = worksetService.listByDilution(object.getId()); for (Workset workset : worksets) { workset.getDilutions().removeIf(ldi -> ldi.getId() == object.getId()); worksetService.save(workset); } Box box = object.getBox(); if (box != null) { box.getBoxPositions().remove(object.getBoxPosition()); boxService.save(box); } }
@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 IllegalArgumentException("Box position '" + boxable.getBoxPosition() + "' in box '" + box.getAlias() + "' is not empty"); } }
stockBox.getBoxPositions().put(stockBoxPositionStep.getPosition(), stockBp); String aliquotPos = ((AliquotBoxPositionStep) aliquotHandlingSteps.get(3 * i)).getPosition(); BoxPosition aliquotBp = new BoxPosition(aliquotBox, aliquotPos, aliquot.getEntityType(), aliquot.getId()); aliquotBox.getBoxPositions().put(aliquotPos, aliquotBp);
BoxPosition temp = managedOriginal.getBox().getBoxPositions().get(managedOriginal.getBoxPosition()); if (temp != null && temp.getBoxableId().equals(boxableId)) { return; box.getBoxPositions().remove(managedOriginal.getBoxPosition()); addBoxContentsChangeLog(managedOriginal.getBox(), String.format("Removed %s (%s)", managedOriginal.getAlias(), managedOriginal.getName())); addBoxContentsChangeLog(managedNew, String.format("Added %s (%s) to %s", boxable.getAlias(), boxable.getName(), boxable.getBoxPosition())); managedNew.getBoxPositions().put(boxable.getBoxPosition(), new BoxPosition(managedNew, boxable.getBoxPosition(), boxable.getEntityType(), boxable.getId())); managedNew.setChangeDetails(authorizationManager.getCurrentUser());
public static BoxDto asDto(@Nonnull Box from, boolean includePositions) { BoxDto dto = new BoxDto(); dto.setId(from.getId()); dto.setName(from.getName()); dto.setAlias(from.getAlias()); dto.setDescription(from.getDescription()); dto.setIdentificationBarcode(from.getIdentificationBarcode()); dto.setLocationBarcode(from.getLocationBarcode()); if (from.getUse() != null) { dto.setUseId(from.getUse().getId()); dto.setUseAlias(from.getUse().getAlias()); } if (from.getSize() != null) { dto.setSizeId(from.getSize().getId()); dto.setRows(from.getSize().getRows()); dto.setCols(from.getSize().getColumns()); dto.setScannable(from.getSize().getScannable()); } if (includePositions) { dto.setItems(from.getBoxPositions().values().stream().map(Dtos::asDto).collect(Collectors.toList())); } if (from.getStorageLocation() != null) { dto.setStorageLocationId(from.getStorageLocation().getId()); dto.setStorageLocationBarcode(from.getStorageLocation().getIdentificationBarcode()); dto.setFreezerDisplayLocation(from.getStorageLocation().getFreezerDisplayLocation()); dto.setStorageDisplayLocation(from.getStorageLocation().getFullDisplayLocation()); } dto.setTubeCount(from.getTubeCount()); return dto; }