Iterate over IDs and load Sones correctly.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 2 Dec 2014 20:34:59 +0000 (21:34 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 2 Dec 2014 20:34:59 +0000 (21:34 +0100)
src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java

index 89a3858..bb59a8d 100644 (file)
@@ -21,6 +21,7 @@ import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance;
 
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
@@ -33,6 +34,7 @@ import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.notify.ListNotificationFilters;
 import net.pterodactylus.sone.template.SoneAccessor;
+import net.pterodactylus.sone.utils.Optionals;
 import net.pterodactylus.sone.web.WebInterface;
 import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.util.notify.Notification;
@@ -43,6 +45,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicate;
 import com.google.common.collect.Collections2;
+import com.google.common.collect.FluentIterable;
 
 /**
  * The “get status” AJAX handler returns all information that is necessary to
@@ -76,16 +79,14 @@ public class GetStatusAjaxPage extends JsonPage {
                String loadSoneIds = request.getHttpRequest().getParam("soneIds");
                if (loadSoneIds.length() > 0) {
                        String[] soneIds = loadSoneIds.split(",");
-                       for (String soneId : soneIds) {
-                               /* just add it, we skip null further down. */
-                               sones.add(webInterface.getCore().getSone(soneId).orNull());
-                       }
+                       FluentIterable.from(Arrays.asList(soneIds))
+                                       .transform(webInterface.getCore().soneLoader())
+                                       .filter(Optionals.isPresent())
+                                       .transform(Optionals.<Sone>get())
+                                       .copyInto(sones);
                }
                ArrayNode jsonSones = new ArrayNode(instance);
                for (Sone sone : sones) {
-                       if (sone == null) {
-                               continue;
-                       }
                        jsonSones.add(createJsonSone(sone));
                }
                /* load notifications. */