/** {@inheritDoc} */ @Override public Object get(TemplateContext templateContext, Object object, String member) { Image image = (Image) object; if ("next".equals(member)) { Album album = image.getAlbum(); int imagePosition = album.getImages().indexOf(image); if (imagePosition < album.getImages().size() - 1) { return album.getImages().get(imagePosition + 1); } return null; } else if ("previous".equals(member)) { Album album = image.getAlbum(); int imagePosition = album.getImages().indexOf(image); if (imagePosition > 0) { return album.getImages().get(imagePosition - 1); } return null; } return super.get(templateContext, object, member); }
public void parseImages(ImageBuilderFactory imageBuilderFactory) { int imageCounter = 0; while (true) { String imagePrefix = "/Images/" + imageCounter++; String imageId = getString(imagePrefix + "/ID", null); if (imageId == null) { break; } String albumId = getString(imagePrefix + "/Album", null); String key = getString(imagePrefix + "/Key", null); String title = getString(imagePrefix + "/Title", null); String description = getString(imagePrefix + "/Description", null); Long creationTime = getLong(imagePrefix + "/CreationTime", null); Integer width = getInt(imagePrefix + "/Width", null); Integer height = getInt(imagePrefix + "/Height", null); if (albumAttributesAreInvalid( albumId, key, title, description, creationTime, width, height)) { throw new InvalidImageFound(); } Album album = albums.get(albumId); if (album == null) { throw new InvalidParentAlbumFound(albumId); } Image image = imageBuilderFactory .newImageBuilder() .withId(imageId) .build() .modify() .setSone(sone) .setCreationTime(creationTime) .setKey(key) .setTitle(title) .setDescription(description) .setWidth(width) .setHeight(height) .update(); album.addImage(image); images.put(image.getId(), image); } }
@Test(expected = ImageTitleMustNotBeEmpty.class) public void modifierDoesNotAllowTitleDoBeEmpty() { image.modify().setTitle("").update(); }