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()); }
@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); }
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); } }
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 static String getMostSimilarProperty(Box box, String search) { List<String> properties = new ArrayList<>(Arrays.asList(box.getAlias(), box.getName())); if (box.getIdentificationBarcode() != null) { properties.add(box.getIdentificationBarcode()); } return properties.stream().map(String::toLowerCase).filter(p -> p.indexOf(search) >= 0) .min(Comparator.comparingInt(p -> p.indexOf(search))).orElse(""); }
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 { box.setChangeDetails(authorizationManager.getCurrentUser()); if (box.getStorageLocation() != null) { box.setStorageLocation(storageLocationService.get(box.getStorageLocation().getId())); } else { box.setStorageLocation(null); if (!box.isSaved()) { return saveNewBox(box); } else { Box managed = boxStore.get(box.getId()); authorizationManager.throwIfNotWritable(managed); logStorageChange(box, managed); 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(); if (oldOccupant.getBoxId().longValue() == box.getId()) { managed.getAlias(), managed.getName())); message.append(String.format("Moved %s (%s) from %s (%s) to %s", oldOccupant.getAlias(), oldOccupant.getName(), oldOccupant.getBoxAlias(), oldOccupant.getBoxName(), entry.getKey())); for (Map.Entry<String, BoxPosition> entry : managed.getBoxPositions().entrySet()) {
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 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())); } } }
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; }
v.setPreMigrationId(dilution.getPreMigrationId()); if (dilution.getBox() != null) { v.setBoxName(dilution.getBox().getName()); v.setBoxAlias(dilution.getBox().getAlias()); v.setBoxIdentificationBarcode(dilution.getBox().getIdentificationBarcode()); v.setBoxLocationBarcode(dilution.getBox().getLocationBarcode());
@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"); } }
List<ValidationError> errors = new ArrayList<>(); if (isStringEmptyOrNull(box.getAlias())) { errors.add(new ValidationError("alias", "Alias cannot be blank")); } 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")); 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"));
@Override public void beforeDelete(Box object) throws IOException { object.getBoxPositions().clear(); save(object); }
return; if ((boxable.getBox() != null && managedOriginal.getBox() != null && boxable.getBox().getId() == managedOriginal.getBox().getId() && boxable.getBoxPosition().equals(managedOriginal.getBoxPosition()))) { BoxPosition temp = managedOriginal.getBox().getBoxPositions().get(managedOriginal.getBoxPosition()); if (temp != null && temp.getBoxableId().equals(boxableId)) { return; Box box = get(managedOriginal.getBox().getId()); box.getBoxPositions().remove(managedOriginal.getBoxPosition()); addBoxContentsChangeLog(managedOriginal.getBox(), String.format("Removed %s (%s)", managedOriginal.getAlias(), managedOriginal.getName())); box.setChangeDetails(authorizationManager.getCurrentUser()); boxStore.save(box); Box managedNew = boxStore.get(boxable.getBox().getId()); 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()); boxStore.save(managedNew);
@Override public void processInput(BoxPositionProgressStep step) { if (isLocationFree(step.getInput())) { boxPositionStep = step; } else if (!box.isValidPosition(step.getInput())) { error = String.format("The Box '%s' does not have a position '%s'", box.getAlias(), step.getInput()); } else if (!box.isFreePosition(step.getInput())) { error = String.format("The position '%s' is already occupied", step.getInput()); } }
public String getAlias() { return boxStep.getInput().getAlias(); }
public static String makeLocationLabel(Boxable boxable) { return makeLocationLabel(boxable.isDiscarded(), boxable.getLocationBarcode(), boxable.getBox() == null ? null : boxable.getBox().getAlias(), boxable.getBoxPosition(), boxable.getBox() == null ? null : boxable.getBox().getLocationBarcode()); }
@Override public void processInput(BoxProgressStep step) { if (step.getInput().getFreeCount() >= 1) { boxStep = step; } else { error = String.format("Box '%s' is full", step.getInput().getAlias()); } }
@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(); } }