@Override public boolean isSaved() { return getId() != UNSAVED_ID; }
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())); } } }
@Override public Long getId() { return storageLocation.getId(); }
@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 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 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 long save(StorageLocation location) { if (!location.isSaved()) { return (long) currentSession().save(location); } else { currentSession().update(location); return location.getId(); } }
private long update(StorageLocation location) throws IOException { StorageLocation managed = get(location.getId()); location.setParentLocation(storageLocationStore.get(location.getParentLocation().getId())); validateChange(location, managed); createParentIfNecessary(location); applyChanges(location, managed); managed.setChangeDetails(authorizationManager.getCurrentUser()); return storageLocationStore.save(managed); }
private void loadChildEntities(StorageLocation storage) { if (storage.getParentLocation() != null && storage.getParentLocation().isSaved()) { storage.setParentLocation(get(storage.getParentLocation().getId())); } }
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 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); }
box.setChangeDetails(authorizationManager.getCurrentUser()); if (box.getStorageLocation() != null) { box.setStorageLocation(storageLocationService.get(box.getStorageLocation().getId())); } else { box.setStorageLocation(null);
} 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()) {