Remove the concept of the album image, always use a random image
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 23 Jun 2016 18:39:29 +0000 (20:39 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 23 Jun 2016 18:46:02 +0000 (20:46 +0200)
15 files changed:
src/main/java/net/pterodactylus/sone/core/ConfigurationSoneParser.java
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/SoneParser.java
src/main/java/net/pterodactylus/sone/data/Album.java
src/main/java/net/pterodactylus/sone/data/impl/AlbumImpl.java
src/main/java/net/pterodactylus/sone/template/AlbumAccessor.java
src/main/java/net/pterodactylus/sone/web/EditAlbumPage.java
src/main/resources/templates/imageBrowser.html
src/main/resources/templates/include/browseAlbums.html
src/test/java/net/pterodactylus/sone/Matchers.java
src/test/java/net/pterodactylus/sone/TestAlbumBuilder.java
src/test/java/net/pterodactylus/sone/core/ConfigurationSoneParserTest.java
src/test/java/net/pterodactylus/sone/core/SoneParserTest.java
src/test/java/net/pterodactylus/sone/database/memory/MemoryDatabaseTest.java
src/test/java/net/pterodactylus/sone/template/AlbumAccessorTest.java

index a29856b..37e0ed5 100644 (file)
@@ -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);
index 5a95810..8df8f95 100644 (file)
@@ -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);
 
index ae1e2a5..fdbd9ae 100644 (file)
@@ -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();
                        }
                }
 
index 698206d..0f12068 100644 (file)
@@ -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 { }
index 41668ab..123fe75 100644 (file)
@@ -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<String> description = absent();
 
-                       private Optional<String> 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(");
index 5093442..b0799e4 100644 (file)
@@ -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<Image> images = album.getImages();
                        return images.isEmpty() ? null : images.get(random.nextInt(images.size()));
                }
index 5244bc5..5573656 100644 (file)
@@ -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 {
index c49c633..7dd4c29 100644 (file)
                                                <%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>
index a22505f..9aacad3 100644 (file)
@@ -8,7 +8,7 @@
                                <%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>
index faf2633..a4a5179 100644 (file)
@@ -109,8 +109,7 @@ public class Matchers {
 
        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,
@@ -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);
-                               }
                        }
                };
        }
index 9890a70..a499019 100644 (file)
@@ -46,17 +46,6 @@ public class TestAlbumBuilder implements AlbumBuilder {
                                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>() {
@@ -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;
                        }
index 7bbfae8..ec42a8c 100644 (file)
@@ -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());
        }
index dc19195..2d8a5a0 100644 (file)
@@ -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<Void>() {
                        @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;
                        }
                };
index 5ee498c..5332425 100644 (file)
@@ -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",
index b31eabf..aace929 100644 (file)
@@ -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.<Image>emptyList());
-               assertThat(albumAccessor.get(null, album, "randomImage"), nullValue());
+               assertThat(albumAccessor.get(null, album, "albumImage"), nullValue());
        }
 
 }