String albumDescription =
getString(albumPrefix + "/Description", null);
String albumParentId = getString(albumPrefix + "/Parent", null);
- String albumImageId =
- getString(albumPrefix + "/AlbumImage", null);
if ((albumTitle == null) || (albumDescription == null)) {
throw new InvalidAlbumFound();
}
.modify()
.setTitle(albumTitle)
.setDescription(albumDescription)
- .setAlbumImage(albumImageId)
.update();
if (albumParentId != null) {
Album parentAlbum = albums.get(albumParentId);
configuration.getStringValue(albumPrefix + "/Title").setValue(album.getTitle());
configuration.getStringValue(albumPrefix + "/Description").setValue(album.getDescription());
configuration.getStringValue(albumPrefix + "/Parent").setValue(album.getParent().equals(sone.getRootAlbum()) ? null : album.getParent().getId());
- configuration.getStringValue(albumPrefix + "/AlbumImage").setValue(album.getAlbumImage() == null ? null : album.getAlbumImage().getId());
}
configuration.getStringValue(sonePrefix + "/Albums/" + albumCounter + "/ID").setValue(null);
String parentId = albumXml.getValue("parent", null);
String title = albumXml.getValue("title", null);
String description = albumXml.getValue("description", "");
- String albumImageId = albumXml.getValue("album-image", null);
if ((id == null) || (title == null)) {
logger.log(Level.WARNING, String.format("Downloaded Sone %s contains invalid album!", sone));
return null;
allImages.put(imageId, image);
}
}
- album.modify().setAlbumImage(albumImageId).update();
}
}
Image moveImageDown(Image image);
/**
- * Returns the album image of this album, or {@code null} if no album image has
- * been set.
- *
- * @return The image to show when this album is listed
- */
- Image getAlbumImage();
-
- /**
* Returns whether this album contains any other albums or images.
*
* @return {@code true} if this album is empty, {@code false} otherwise
Modifier setDescription(String description);
- Modifier setAlbumImage(String imageId);
-
Album update() throws IllegalStateException;
class AlbumTitleMustNotBeEmpty extends IllegalStateException { }
/** The description of this album. */
private String description;
- /** The ID of the album picture. */
- private String albumImage;
-
/** Creates a new album with a random ID. */
public AlbumImpl(Sone sone) {
this(sone, UUID.randomUUID().toString());
image.getAlbum().removeImage(image);
}
image.setAlbum(this);
- if (imageIds.isEmpty() && (albumImage == null)) {
- albumImage = image.getId();
- }
if (!imageIds.contains(image.getId())) {
imageIds.add(image.getId());
images.put(image.getId(), image);
checkArgument(image.getSone().equals(sone), "image must belong to the same Sone as this album");
imageIds.remove(image.getId());
images.remove(image.getId());
- if (image.getId().equals(albumImage)) {
- if (images.isEmpty()) {
- albumImage = null;
- } else {
- albumImage = images.values().iterator().next().getId();
- }
- }
}
@Override
}
@Override
- public Image getAlbumImage() {
- if (albumImage == null) {
- return null;
- }
- return Optional.fromNullable(images.get(albumImage)).or(images.values().iterator().next());
- }
-
- @Override
public boolean isEmpty() {
return albums.isEmpty() && images.isEmpty();
}
private Optional<String> description = absent();
- private Optional<String> albumImage = absent();
-
@Override
public Modifier setTitle(String title) {
this.title = fromNullable(title);
}
@Override
- public Modifier setAlbumImage(String imageId) {
- this.albumImage = fromNullable(imageId);
- return this;
- }
-
- @Override
public Album update() throws IllegalStateException {
if (title.isPresent() && title.get().trim().isEmpty()) {
throw new AlbumTitleMustNotBeEmpty();
if (description.isPresent()) {
AlbumImpl.this.description = description.get();
}
- if (albumImage.isPresent()) {
- AlbumImpl.this.albumImage = albumImage.get();
- }
return AlbumImpl.this;
}
};
hash.putString("ID(").putString(id).putString(")");
hash.putString("Title(").putString(title).putString(")");
hash.putString("Description(").putString(description).putString(")");
- if (albumImage != null) {
- hash.putString("AlbumImage(").putString(albumImage).putString(")");
- }
/* add nested albums. */
hash.putString("Albums(");
}
backlinks.add(0, new Link("imageBrowser.html?sone=" + album.getSone().getId(), SoneAccessor.getNiceName(album.getSone())));
return backlinks;
- } else if ("randomImage".equals(member)) {
+ } else if ("albumImage".equals(member)) {
List<Image> images = album.getImages();
return images.isEmpty() ? null : images.get(random.nextInt(images.size()));
}
webInterface.getCore().touchConfiguration();
throw new RedirectException("imageBrowser.html?album=" + album.getParent().getId());
}
- String albumImageId = request.getHttpRequest().getPartAsStringFailsafe("album-image", 36);
- if (webInterface.getCore().getImage(albumImageId, false) == null) {
- albumImageId = null;
- }
- album.modify().setAlbumImage(albumImageId).update();
String title = request.getHttpRequest().getPartAsStringFailsafe("title", 100).trim();
String description = request.getHttpRequest().getPartAsStringFailsafe("description", 1000).trim();
try {
<%ifnull album.albumImage>
<img src="images/unknown-image-0.png" width="333" height="250" alt="<% album.title|html> (<%album.sone.niceName|html>)" title="<% album.title|html> (<%album.sone.niceName|html>)" style="position: relative; top: 0px; left: -41px;" />
<%else><!-- TODO -->
- <% album.randomImage|image-link max-width==250 max-height==250 mode==enlarge title=album.title>
+ <% album.albumImage|image-link max-width==250 max-height==250 mode==enlarge title=album.title>
<%/if>
</a>
</div>
<%ifnull album.albumImage>
<img src="images/unknown-image-0.png" width="333" height="250" alt="<% album.title|html>" title="<% album.title|html>" style="position: relative; top: 0px; left: -41px;" />
<%else><!-- TODO -->
- <% album.randomImage|image-link max-width==250 max-height==250 mode==enlarge title=album.title>
+ <% album.albumImage|image-link max-width==250 max-height==250 mode==enlarge title=album.title>
<%/if>
</a>
</div>
public static Matcher<Album> isAlbum(final String albumId,
final String parentAlbumId,
- final String title, final String albumDescription,
- final String imageId) {
+ final String title, final String albumDescription) {
return new TypeSafeDiagnosingMatcher<Album>() {
@Override
protected boolean matchesSafely(Album album,
.appendValue(album.getDescription());
return false;
}
- if (imageId == null) {
- if (album.getAlbumImage() != null) {
- mismatchDescription.appendText("has album image");
- return false;
- }
- } else {
- if (album.getAlbumImage() == null) {
- mismatchDescription.appendText("has no album image");
- return false;
- }
- if (!album.getAlbumImage().getId().equals(imageId)) {
- mismatchDescription.appendText("has album image ")
- .appendValue(album.getAlbumImage().getId());
- return false;
- }
- }
return true;
}
description.appendText(", has title ").appendValue(title);
description.appendText(", has description ")
.appendValue(albumDescription);
- if (imageId == null) {
- description.appendText(", has no album image");
- } else {
- description.appendText(", has album image ")
- .appendValue(imageId);
- }
}
};
}
return description;
}
});
- when(album.getAlbumImage()).thenAnswer(new Answer<Image>() {
- @Override
- public Image answer(InvocationOnMock invocation) {
- if (imageId == null) {
- return null;
- }
- Image image = mock(Image.class);
- when(image.getId()).thenReturn(imageId);
- return image;
- }
- });
when(album.getAlbums()).thenReturn(albums);
when(album.getImages()).thenReturn(images);
doAnswer(new Answer<Void>() {
}
@Override
- public Modifier setAlbumImage(String imageId) {
- TestAlbumBuilder.this.imageId = imageId;
- return this;
- }
-
- @Override
public Album update() throws IllegalStateException {
return album;
}
albumBuilderFactory);
assertThat(topLevelAlbums, hasSize(2));
Album firstAlbum = topLevelAlbums.get(0);
- assertThat(firstAlbum, isAlbum("A1", null, "T1", "D1", "I1"));
+ assertThat(firstAlbum, isAlbum("A1", null, "T1", "D1"));
assertThat(firstAlbum.getAlbums(), emptyIterable());
assertThat(firstAlbum.getImages(), emptyIterable());
Album secondAlbum = topLevelAlbums.get(1);
- assertThat(secondAlbum, isAlbum("A2", null, "T2", "D2", null));
+ assertThat(secondAlbum, isAlbum("A2", null, "T2", "D2"));
assertThat(secondAlbum.getAlbums(), hasSize(1));
assertThat(secondAlbum.getImages(), emptyIterable());
Album thirdAlbum = secondAlbum.getAlbums().get(0);
- assertThat(thirdAlbum, isAlbum("A3", "A2", "T3", "D3", "I3"));
+ assertThat(thirdAlbum, isAlbum("A3", "A2", "T3", "D3"));
assertThat(thirdAlbum.getAlbums(), emptyIterable());
assertThat(thirdAlbum.getImages(), emptyIterable());
}
@Before
public void setupAlbum() {
final Album album = SoneParserTest.this.album;
- when(album.getAlbumImage()).thenReturn(mock(Image.class));
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
final Modifier albumModifier = new Modifier() {
private String title = album.getTitle();
private String description = album.getDescription();
- private String imageId = album.getAlbumImage().getId();
@Override
public Modifier setTitle(String title) {
}
@Override
- public Modifier setAlbumImage(String imageId) {
- this.imageId = imageId;
- return this;
- }
-
- @Override
public Album update() throws IllegalStateException {
when(album.getTitle()).thenReturn(title);
when(album.getDescription()).thenReturn(description);
- Image image = mock(Image.class);
- when(image.getId()).thenReturn(imageId);
- when(album.getAlbumImage()).thenReturn(image);
return album;
}
};
.update();
Album secondAlbum = new TestAlbumBuilder().withId("album2").by(
sone).build().modify().setTitle("album2").setDescription(
- "album-description2").setAlbumImage("image1").update();
+ "album-description2").update();
Album thirdAlbum = new TestAlbumBuilder().withId("album3").by(
sone).build().modify().setTitle("album3").setDescription(
"album-description3").update();
assertThat(memoryDatabase.getPostReply("reply4").isPresent(),
is(false));
assertThat(memoryDatabase.getAlbum("album1").get(),
- isAlbum("album1", null, "album1", "album-description1",
- null));
+ isAlbum("album1", null, "album1", "album-description1"));
assertThat(memoryDatabase.getAlbum("album2").get(),
- isAlbum("album2", null, "album2", "album-description2",
- "image1"));
+ isAlbum("album2", null, "album2", "album-description2"));
assertThat(memoryDatabase.getAlbum("album3").get(),
- isAlbum("album3", "album1", "album3", "album-description3",
- null));
+ isAlbum("album3", "album1", "album3", "album-description3"));
assertThat(memoryDatabase.getAlbum("album4").isPresent(), is(false));
assertThat(memoryDatabase.getImage("image1").get(),
isImage("image1", 1000L, "KSK@image1", "image1",
when(album.getImages()).thenReturn(albumImages);
int matchedImage = 0;
for (int i = 0; i < 1000; i++) {
- Image randomImage = (Image) albumAccessor.get(null, album, "randomImage");
+ Image randomImage = (Image) albumAccessor.get(null, album, "albumImage");
if (randomImage == image) {
matchedImage++;
}
@Test
public void albumImageIsNullIfThereAreNoImagesInAnAlbum() {
when(album.getImages()).thenReturn(Collections.<Image>emptyList());
- assertThat(albumAccessor.get(null, album, "randomImage"), nullValue());
+ assertThat(albumAccessor.get(null, album, "albumImage"), nullValue());
}
}