package net.pterodactylus.sone.web;
+import static com.google.common.collect.FluentIterable.from;
+import static net.pterodactylus.sone.data.Album.FLATTENER;
+import static net.pterodactylus.sone.data.Album.NOT_EMPTY;
+import static net.pterodactylus.sone.data.Album.TITLE_COMPARATOR;
+
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import com.google.common.base.Optional;
-
import net.pterodactylus.sone.data.Album;
import net.pterodactylus.sone.data.Image;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
+import com.google.common.base.Optional;
+
/**
* The image browser page is the entry page for the image management.
*
// SONETEMPLATEPAGE METHODS
//
- /**
- * {@inheritDoc}
- */
@Override
protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
super.processTemplate(request, templateContext);
String albumId = request.getHttpRequest().getParam("album", null);
if (albumId != null) {
- Album album = webInterface.getCore().getAlbum(albumId, false);
+ Optional<Album> album = webInterface.getCore().getAlbum(albumId);
templateContext.set("albumRequested", true);
- templateContext.set("album", album);
+ templateContext.set("album", album.orNull());
templateContext.set("page", request.getHttpRequest().getParam("page"));
return;
}
String imageId = request.getHttpRequest().getParam("image", null);
if (imageId != null) {
- Image image = webInterface.getCore().getImage(imageId, false);
+ Optional<Image> image = webInterface.getCore().getImage(imageId);
templateContext.set("imageRequested", true);
- templateContext.set("image", image);
+ templateContext.set("image", image.orNull());
return;
}
String soneId = request.getHttpRequest().getParam("sone", null);
templateContext.set("galleryRequested", true);
List<Album> albums = new ArrayList<Album>();
for (Sone sone : webInterface.getCore().getSones()) {
- albums.addAll(sone.getAllAlbums());
+ albums.addAll(from(sone.getRootAlbum().getAlbums()).transformAndConcat(FLATTENER).filter(NOT_EMPTY).toList());
}
- Collections.sort(albums, Album.TITLE_COMPARATOR);
+ Collections.sort(albums, TITLE_COMPARATOR);
Pagination<Album> albumPagination = new Pagination<Album>(albums, 12).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
templateContext.set("albumPagination", albumPagination);
templateContext.set("albums", albumPagination.getItems());
templateContext.set("sone", sone);
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean isLinkExcepted(URI link) {
return true;