/** * Add a changelog entry to record a Box added to or removed from a StorageLocation * * @param location the StorageLocation that box was added to or removed from * @param box the Box that was added or removed * @param addition true for addition; false for removal * @throws IOException */ private void addStorageChangeLog(StorageLocation location, Box box, boolean addition) throws IOException { if (location.getLocationUnit() != LocationUnit.FREEZER) { throw new IllegalArgumentException(String.format("%s is not a freezer", location.getAlias())); } String message = addition ? String.format("Added %s (%s) to %s", box.getAlias(), box.getName(), box.getStorageLocation().getFreezerDisplayLocation()) : (String.format("Removed %s (%s)", box.getAlias(), box.getName())); ChangeLog change = location.createChangeLog(message, "", authorizationManager.getCurrentUser()); changeLogService.create(change); }
public String getFreezerDisplayLocation() { return ((getParentLocation() == null || getParentLocation().getLocationUnit() == LocationUnit.FREEZER || getParentLocation().getLocationUnit() == LocationUnit.ROOM) ? "" : getParentLocation().getFreezerDisplayLocation() + ", ") + getDisplayLocation(); }
private void logStorageChange(Box box, Box original) throws IOException { if (original.getStorageLocation() == null && box.getStorageLocation() != null) { addStorageChangeLog(getFreezer(box), box, true); } else if (original.getStorageLocation() != null && box.getStorageLocation() == null) { addStorageChangeLog(getFreezer(original), box, false); } else if (original.getStorageLocation() != null && box.getStorageLocation() != null) { if (getFreezer(original).getId() != getFreezer(box).getId()) { addStorageChangeLog(getFreezer(original), box, false); addStorageChangeLog(getFreezer(box), box, true); } else if (original.getStorageLocation().getId() != box.getStorageLocation().getId()) { String message = String.format("Relocated %s (%s) from %s to %s", box.getAlias(), box.getName(), original.getStorageLocation().getFreezerDisplayLocation(), box.getStorageLocation().getFreezerDisplayLocation()); ChangeLog change = getFreezer(box).createChangeLog(message, "", authorizationManager.getCurrentUser()); changeLogService.create(change); } } }
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; }