private StorageLocation getFreezer(Box box) { if (box.getStorageLocation() == null) { throw new IllegalArgumentException(String.format("%s (%s) does not have a storage location", box.getAlias(), box.getName())); } StorageLocation location = box.getStorageLocation().getFreezerLocation(); if (location == null) { throw new IllegalArgumentException(String.format("Location %s does not have a parent freezer", box.getStorageLocation().getAlias())); } return location; }
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); } } }
private void loadChildEntities(Box box) throws IOException { if (box.getSize() != null) { box.setSize(getSize(box.getSize().getId())); } box.setUse(getUse(box.getUse().getId())); if (box.getStorageLocation() != null) { if (box.getStorageLocation().getId() > 0L) { box.setStorageLocation(storageLocationService.get(box.getStorageLocation().getId())); } else if (!LimsUtils.isStringEmptyOrNull(box.getStorageLocation().getIdentificationBarcode())) { box.setStorageLocation(storageLocationService.getByBarcode(box.getStorageLocation().getIdentificationBarcode())); } } }
if (box.getStorageLocation() != null) { if (box.getStorageLocation().getLocationUnit().getBoxStorageAmount() == BoxStorageAmount.NONE) { errors.add(new ValidationError("storageLocation", "Invalid box location")); } else if (box.getStorageLocation().getLocationUnit().getBoxStorageAmount() == BoxStorageAmount.SINGLE) { if (beforeChange == null || beforeChange.getStorageLocation() == null || beforeChange.getStorageLocation().getId() != box.getStorageLocation().getId()) { box.getStorageLocation().getBoxes().forEach(b -> { if (b.getId() != box.getId()) { errors.add(new ValidationError("storageLocation", "Location already occupied"));
/** * 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); }
@Override public long save(Box box) throws IOException { box.setChangeDetails(authorizationManager.getCurrentUser()); if (box.getStorageLocation() != null) { box.setStorageLocation(storageLocationService.get(box.getStorageLocation().getId())); } else { box.setStorageLocation(null);
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; }
private void applyChanges(Box from, Box to) throws IOException { to.setAlias(from.getAlias()); to.setDescription(from.getDescription()); to.setIdentificationBarcode(LimsUtils.nullifyStringIfBlank(from.getIdentificationBarcode())); to.setLocationBarcode(from.getLocationBarcode()); to.setUse(boxStore.getUseById(from.getUse().getId())); to.setStorageLocation(from.getStorageLocation()); }
public static Box to(@Nonnull BoxDto from) { Box to = new BoxImpl(); if (from.getId() != null) to.setId(from.getId()); to.setAlias(from.getAlias()); to.setDescription(from.getDescription()); to.setIdentificationBarcode(from.getIdentificationBarcode()); to.setLocationBarcode(from.getLocationBarcode() == null ? "" : from.getLocationBarcode()); if (from.getUseId() != null) { BoxUse use = new BoxUse(); use.setId(from.getUseId()); to.setUse(use); } if (from.getSizeId() != null) { BoxSize size = new BoxSize(); size.setId(from.getSizeId()); to.setSize(size); } if (from.getStorageLocationId() != null) { to.setStorageLocation(new StorageLocation()); to.getStorageLocation().setId(from.getStorageLocationId()); } if (!isStringEmptyOrNull(from.getStorageLocationBarcode())) { if (to.getStorageLocation() == null) { to.setStorageLocation(new StorageLocation()); } to.getStorageLocation().setIdentificationBarcode(from.getStorageLocationBarcode()); } return to; }
private long saveNewBox(Box box) throws IOException { authorizationManager.throwIfNotWritable(box); try { box.setName(generateTemporaryName()); box.setSecurityProfile(securityProfileStore.get(securityProfileStore.save(box.getSecurityProfile()))); box.setChangeDetails(authorizationManager.getCurrentUser()); box.setIdentificationBarcode(LimsUtils.nullifyStringIfBlank(box.getIdentificationBarcode())); validateChange(box, null); boxStore.save(box); if (autoGenerateIdBarcodes) { box.setIdentificationBarcode(box.getName() + "::" + box.getAlias()); } box.setName(namingScheme.generateNameFor(box)); validateNameOrThrow(box, namingScheme); if (box.getStorageLocation() != null) { addStorageChangeLog(getFreezer(box), box, true); } return boxStore.save(box); } catch (MisoNamingException e) { throw new IOException("Invalid name for box", e); } }