From: David ‘Bombe’ Roden Date: Thu, 23 Jun 2016 18:39:29 +0000 (+0200) Subject: Remove the concept of the album image, always use a random image X-Git-Tag: 0.9.5^2~26 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=91b8268946412b35bcce5b4406106ecd4cb58e3c;p=Sone.git Remove the concept of the album image, always use a random image --- diff --git a/src/main/java/net/pterodactylus/sone/core/ConfigurationSoneParser.java b/src/main/java/net/pterodactylus/sone/core/ConfigurationSoneParser.java index a29856b..37e0ed5 100644 --- a/src/main/java/net/pterodactylus/sone/core/ConfigurationSoneParser.java +++ b/src/main/java/net/pterodactylus/sone/core/ConfigurationSoneParser.java @@ -201,8 +201,6 @@ public class ConfigurationSoneParser { 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(); } @@ -213,7 +211,6 @@ public class ConfigurationSoneParser { .modify() .setTitle(albumTitle) .setDescription(albumDescription) - .setAlbumImage(albumImageId) .update(); if (albumParentId != null) { Album parentAlbum = albums.get(albumParentId); diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 5a95810..8df8f95 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -1518,7 +1518,6 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, 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); diff --git a/src/main/java/net/pterodactylus/sone/core/SoneParser.java b/src/main/java/net/pterodactylus/sone/core/SoneParser.java index ae1e2a5..fdbd9ae 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneParser.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneParser.java @@ -261,7 +261,6 @@ public class SoneParser { 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; @@ -315,7 +314,6 @@ public class SoneParser { allImages.put(imageId, image); } } - album.modify().setAlbumImage(albumImageId).update(); } } diff --git a/src/main/java/net/pterodactylus/sone/data/Album.java b/src/main/java/net/pterodactylus/sone/data/Album.java index 698206d..0f12068 100644 --- a/src/main/java/net/pterodactylus/sone/data/Album.java +++ b/src/main/java/net/pterodactylus/sone/data/Album.java @@ -206,14 +206,6 @@ public interface Album extends Identified, Fingerprintable { 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 @@ -288,8 +280,6 @@ public interface Album extends Identified, Fingerprintable { Modifier setDescription(String description); - Modifier setAlbumImage(String imageId); - Album update() throws IllegalStateException; class AlbumTitleMustNotBeEmpty extends IllegalStateException { } diff --git a/src/main/java/net/pterodactylus/sone/data/impl/AlbumImpl.java b/src/main/java/net/pterodactylus/sone/data/impl/AlbumImpl.java index 41668ab..123fe75 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/AlbumImpl.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/AlbumImpl.java @@ -70,9 +70,6 @@ public class AlbumImpl implements Album { /** 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()); @@ -176,9 +173,6 @@ public class AlbumImpl implements Album { 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); @@ -192,13 +186,6 @@ public class AlbumImpl implements Album { 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 @@ -232,14 +219,6 @@ public class AlbumImpl implements Album { } @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(); } @@ -284,8 +263,6 @@ public class AlbumImpl implements Album { private Optional description = absent(); - private Optional albumImage = absent(); - @Override public Modifier setTitle(String title) { this.title = fromNullable(title); @@ -299,12 +276,6 @@ public class AlbumImpl implements Album { } @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(); @@ -315,9 +286,6 @@ public class AlbumImpl implements Album { if (description.isPresent()) { AlbumImpl.this.description = description.get(); } - if (albumImage.isPresent()) { - AlbumImpl.this.albumImage = albumImage.get(); - } return AlbumImpl.this; } }; @@ -334,9 +302,6 @@ public class AlbumImpl implements Album { 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("); diff --git a/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java b/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java index 5093442..b0799e4 100644 --- a/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java +++ b/src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java @@ -53,7 +53,7 @@ public class AlbumAccessor extends ReflectionAccessor { } 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 images = album.getImages(); return images.isEmpty() ? null : images.get(random.nextInt(images.size())); } diff --git a/src/main/java/net/pterodactylus/sone/web/EditAlbumPage.java b/src/main/java/net/pterodactylus/sone/web/EditAlbumPage.java index 5244bc5..5573656 100644 --- a/src/main/java/net/pterodactylus/sone/web/EditAlbumPage.java +++ b/src/main/java/net/pterodactylus/sone/web/EditAlbumPage.java @@ -68,11 +68,6 @@ public class EditAlbumPage extends SoneTemplatePage { 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 { diff --git a/src/main/resources/templates/imageBrowser.html b/src/main/resources/templates/imageBrowser.html index c49c633..7dd4c29 100644 --- a/src/main/resources/templates/imageBrowser.html +++ b/src/main/resources/templates/imageBrowser.html @@ -623,7 +623,7 @@ <%ifnull album.albumImage> <% album.title|html> (<%album.sone.niceName|html>) <%else> - <% 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> diff --git a/src/main/resources/templates/include/browseAlbums.html b/src/main/resources/templates/include/browseAlbums.html index a22505f..9aacad3 100644 --- a/src/main/resources/templates/include/browseAlbums.html +++ b/src/main/resources/templates/include/browseAlbums.html @@ -8,7 +8,7 @@ <%ifnull album.albumImage> <% album.title|html> <%else> - <% 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> diff --git a/src/test/java/net/pterodactylus/sone/Matchers.java b/src/test/java/net/pterodactylus/sone/Matchers.java index faf2633..a4a5179 100644 --- a/src/test/java/net/pterodactylus/sone/Matchers.java +++ b/src/test/java/net/pterodactylus/sone/Matchers.java @@ -109,8 +109,7 @@ public class Matchers { public static Matcher 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() { @Override protected boolean matchesSafely(Album album, @@ -146,22 +145,6 @@ public class Matchers { .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; } @@ -177,12 +160,6 @@ public class Matchers { 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); - } } }; } diff --git a/src/test/java/net/pterodactylus/sone/TestAlbumBuilder.java b/src/test/java/net/pterodactylus/sone/TestAlbumBuilder.java index 9890a70..a499019 100644 --- a/src/test/java/net/pterodactylus/sone/TestAlbumBuilder.java +++ b/src/test/java/net/pterodactylus/sone/TestAlbumBuilder.java @@ -46,17 +46,6 @@ public class TestAlbumBuilder implements AlbumBuilder { return description; } }); - when(album.getAlbumImage()).thenAnswer(new Answer() { - @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() { @@ -101,12 +90,6 @@ public class TestAlbumBuilder implements AlbumBuilder { } @Override - public Modifier setAlbumImage(String imageId) { - TestAlbumBuilder.this.imageId = imageId; - return this; - } - - @Override public Album update() throws IllegalStateException { return album; } diff --git a/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java b/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java index 7bbfae8..ec42a8c 100644 --- a/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java +++ b/src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java @@ -333,15 +333,15 @@ public class ConfigurationSoneParserTest { 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()); } diff --git a/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java b/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java index dc19195..2d8a5a0 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneParserTest.java @@ -243,7 +243,6 @@ public class SoneParserTest { @Before public void setupAlbum() { final Album album = SoneParserTest.this.album; - when(album.getAlbumImage()).thenReturn(mock(Image.class)); doAnswer(new Answer() { @Override public Void answer(InvocationOnMock invocation) { @@ -273,7 +272,6 @@ public class SoneParserTest { 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) { @@ -288,18 +286,9 @@ public class SoneParserTest { } @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; } }; diff --git a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java index 5ee498c..5332425 100644 --- a/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java +++ b/src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java @@ -131,7 +131,7 @@ public class MemoryDatabaseTest { .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(); @@ -192,14 +192,11 @@ public class MemoryDatabaseTest { 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", diff --git a/src/test/java/net/pterodactylus/sone/template/AlbumAccessorTest.java b/src/test/java/net/pterodactylus/sone/template/AlbumAccessorTest.java index b31eabf..aace929 100644 --- a/src/test/java/net/pterodactylus/sone/template/AlbumAccessorTest.java +++ b/src/test/java/net/pterodactylus/sone/template/AlbumAccessorTest.java @@ -104,7 +104,7 @@ public class AlbumAccessorTest { 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++; } @@ -115,7 +115,7 @@ public class AlbumAccessorTest { @Test public void albumImageIsNullIfThereAreNoImagesInAnAlbum() { when(album.getImages()).thenReturn(Collections.emptyList()); - assertThat(albumAccessor.get(null, album, "randomImage"), nullValue()); + assertThat(albumAccessor.get(null, album, "albumImage"), nullValue()); } }