@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"); } }
@Override public long addFreezerStorage(StorageLocation storage) throws IOException { validateChange(storage, null); loadChildEntities(storage); storage.setChangeDetails(authorizationManager.getCurrentUser()); long savedId = storageLocationStore.save(storage); StorageLocation[] childLocations = storage.getChildLocations().toArray(new StorageLocation[storage.getChildLocations().size()]); for (StorageLocation child : childLocations) { addFreezerStorage(child); } return savedId; }
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); }
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 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); }