private void loadChildEntities(StorageLocation storage) { if (storage.getParentLocation() != null && storage.getParentLocation().isSaved()) { storage.setParentLocation(get(storage.getParentLocation().getId())); } }
private void applyChanges(StorageLocation from, StorageLocation to) { to.setAlias(from.getAlias()); to.setIdentificationBarcode(from.getIdentificationBarcode()); to.setParentLocation(from.getParentLocation()); to.setMapUrl(from.getMapUrl()); to.setProbeId(from.getProbeId()); }
public String getFreezerDisplayLocation() { return ((getParentLocation() == null || getParentLocation().getLocationUnit() == LocationUnit.FREEZER || getParentLocation().getLocationUnit() == LocationUnit.ROOM) ? "" : getParentLocation().getFreezerDisplayLocation() + ", ") + getDisplayLocation(); }
public StorageLocation getFreezerLocation() { if (locationUnit == LocationUnit.FREEZER) { return this; } else if (getParentLocation() == null || locationUnit == LocationUnit.ROOM) { return null; } return getParentLocation().getFreezerLocation(); }
public static StorageLocationDto asDto(@Nonnull StorageLocation from, boolean includeChildLocations, boolean recursive) { StorageLocationDto dto = new StorageLocationDto(); dto.setId(from.getId()); if (from.getParentLocation() != null) { dto.setParentLocationId(from.getParentLocation().getId()); dto.setLocationUnit(from.getLocationUnit().name()); switch (from.getLocationUnit().getBoxStorageAmount()) { case NONE: dto.setAvailableStorage(false); break; case SINGLE: dto.setAvailableStorage(from.getBoxes().isEmpty()); break; case MULTIPLE: dto.setAlias(from.getAlias()); dto.setIdentificationBarcode(from.getIdentificationBarcode()); dto.setDisplayLocation(from.getDisplayLocation()); dto.setFullDisplayLocation(from.getFullDisplayLocation()); dto.setMapUrl(from.getMapUrl()); dto.setProbeId(from.getProbeId()); if (includeChildLocations) { dto.setChildLocations(from.getChildLocations().stream() .map(child -> Dtos.asDto(child, recursive, recursive)) .collect(Collectors.toList())); dto.setBoxes(from.getBoxes().stream().map(box -> asDto(box, true)).collect(Collectors.toSet())); return dto;
public static StorageLocation to(@Nonnull StorageLocationDto from) { StorageLocation location = new StorageLocation(); location.setId(from.getId()); location.setAlias(from.getAlias()); if (!LimsUtils.isStringEmptyOrNull(from.getIdentificationBarcode())) { location.setIdentificationBarcode(from.getIdentificationBarcode()); } if (!LimsUtils.isStringEmptyOrNull(from.getMapUrl())) { location.setMapUrl(from.getMapUrl()); } if (from.getParentLocationId() != null) { location.setParentLocation(new StorageLocation()); location.getParentLocation().setId(from.getParentLocationId()); } location.setLocationUnit(LocationUnit.valueOf(from.getLocationUnit())); location.setProbeId(from.getProbeId()); return location; }
private long create(StorageLocation location) throws IOException { location.setParentLocation(storageLocationStore.get(location.getParentLocation().getId())); validateChange(location, null); createParentIfNecessary(location); location.setChangeDetails(authorizationManager.getCurrentUser()); return storageLocationStore.save(location); }
/** * 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 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 createParentIfNecessary(StorageLocation freezer) throws IOException { if (freezer.getParentLocation() != null && !freezer.getParentLocation().isSaved()) { freezer.getParentLocation().setChangeDetails(authorizationManager.getCurrentUser()); long parentId = storageLocationStore.save(freezer.getParentLocation()); freezer.setParentLocation(storageLocationStore.get(parentId)); } }
private void validateLocationUnitRelationships(StorageLocation storage, List<ValidationError> errors) { if (storage.getParentLocation() != null && !storage.getLocationUnit().getAcceptableParents().contains(storage.getParentLocation().getLocationUnit())) { errors.add(new ValidationError(String.format("%s is not an appropriate container for %s", storage.getParentLocation().getLocationUnit().getDisplayName(), storage.getLocationUnit().getDisplayName()))); for (StorageLocation child : storage.getChildLocations()) { validateLocationUnitRelationships(child, errors); } } }
@Override public long createRoom(StorageLocation room) throws IOException { if (room.getLocationUnit() != LocationUnit.ROOM) { throw new IllegalArgumentException("Location is not a room"); } room.setChangeDetails(authorizationManager.getCurrentUser()); if (room.getId() == StorageLocation.UNSAVED_ID) { return storageLocationStore.save(room); } else { throw new IllegalArgumentException("Can not yet update rooms"); } }
public String getFullDisplayLocation() { return (getParentLocation() == null ? "" : getParentLocation().getFullDisplayLocation() + ", ") + getDisplayLocation(); }
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"));
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); } } }
@Override public long saveFreezer(StorageLocation freezer) throws IOException { if (freezer.getLocationUnit() != LocationUnit.FREEZER) { throw new IllegalArgumentException("Location is not a freezer"); } loadChildEntities(freezer); if (freezer.getId() == StorageLocation.UNSAVED_ID) { return create(freezer); } else { return update(freezer); } }
@Override public StorageLocation getFreezerForBarcodedStorageLocation(String barcode) { for (StorageLocation current = getByBarcode(barcode); current != null; current = current.getParentLocation()) { if (current.getLocationUnit() == LocationUnit.FREEZER) { return current; } } return null; }
public String getDisplayLocation() { return getLocationUnit().getDisplayName() + " " + getAlias(); }
@Override public boolean isSaved() { return getId() != UNSAVED_ID; }