@Override public Long getId() { return box.getId(); }
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; }
@Override public long save(Box box) throws IOException { if (!box.isSaved()) { return (long) currentSession().save(box); } else { currentSession().update(box); // flush required to avoid constraint violation incase removed items are 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(); return box.getId(); } }
@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 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); }
} else if (beforeChange == null || !box.getAlias().equals(beforeChange.getAlias())) { Box existing = boxStore.getBoxByAlias(box.getAlias()); if (existing != null && existing.getId() != box.getId()) { errors.add(new ValidationError("alias", "There is already a box with this alias")); || beforeChange.getStorageLocation().getId() != box.getStorageLocation().getId()) { box.getStorageLocation().getBoxes().forEach(b -> { if (b.getId() != box.getId()) { errors.add(new ValidationError("storageLocation", "Location already occupied"));
@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"); } }
return; if ((boxable.getBox() != null && managedOriginal.getBox() != null && boxable.getBox().getId() == managedOriginal.getBox().getId() && boxable.getBoxPosition().equals(managedOriginal.getBoxPosition()))) { Box box = get(managedOriginal.getBox().getId()); box.getBoxPositions().remove(managedOriginal.getBoxPosition()); addBoxContentsChangeLog(managedOriginal.getBox(), Box managedNew = boxStore.get(boxable.getBox().getId()); addBoxContentsChangeLog(managedNew, String.format("Added %s (%s) to %s", boxable.getAlias(), boxable.getName(), boxable.getBoxPosition()));
public static BoxableView fromBoxable(Boxable boxable) { BoxableView v = new BoxableView(); v.setId(new BoxableId(boxable.getEntityType(), boxable.getId())); v.setName(boxable.getName()); v.setAlias(boxable.getAlias()); v.setIdentificationBarcode(boxable.getIdentificationBarcode()); v.setLocationBarcode(boxable.getLocationBarcode()); v.setVolume(boxable.getVolume()); v.setDiscarded(boxable.isDiscarded()); Box box = boxable.getBox(); if (box != null) { v.setBoxId(box.getId()); v.setBoxName(box.getName()); v.setBoxAlias(box.getAlias()); v.setBoxPosition(boxable.getBoxPosition()); v.setBoxLocationBarcode(box.getLocationBarcode()); } v.setPreMigrationId(boxable.getPreMigrationId()); return v; }