Return local Sones from core and web interface.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 2 Dec 2014 21:01:05 +0000 (22:01 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 2 Dec 2014 21:01:05 +0000 (22:01 +0100)
24 files changed:
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/database/SoneProvider.java
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java
src/main/java/net/pterodactylus/sone/web/CreatePostPage.java
src/main/java/net/pterodactylus/sone/web/CreateReplyPage.java
src/main/java/net/pterodactylus/sone/web/KnownSonesPage.java
src/main/java/net/pterodactylus/sone/web/LockSonePage.java
src/main/java/net/pterodactylus/sone/web/LoginPage.java
src/main/java/net/pterodactylus/sone/web/OptionsPage.java
src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java
src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetNotificationsAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/JsonPage.java
src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java
src/test/java/net/pterodactylus/sone/fcp/LockSoneCommandTest.java
src/test/java/net/pterodactylus/sone/fcp/UnlockSoneCommandTest.java
src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java

index 71dd349..b485445 100644 (file)
@@ -55,6 +55,7 @@ import net.pterodactylus.sone.core.event.SoneRemovedEvent;
 import net.pterodactylus.sone.core.event.SoneUnlockedEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Image;
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Reply;
@@ -326,27 +327,13 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                return database.getSone(id);
        }
 
-       /**
-        * {@inheritDocs}
-        */
        @Override
-       public Collection<Sone> getLocalSones() {
+       public Collection<LocalSone> getLocalSones() {
                return database.getLocalSones();
        }
 
-       /**
-        * Returns the local Sone with the given ID, optionally creating a new Sone.
-        *
-        * @param id
-        *            The ID of the Sone
-        * @return The Sone with the given ID, or {@code null}
-        */
-       public Sone getLocalSone(String id) {
-               Optional<Sone> sone = database.getSone(id);
-               if (sone.isPresent() && sone.get().isLocal()) {
-                       return sone.get();
-               }
-               return null;
+       public Optional<LocalSone> getLocalSone(String id) {
+               return database.getLocalSone(id);
        }
 
        /**
index 73467a2..fd35d7b 100644 (file)
@@ -20,6 +20,7 @@ package net.pterodactylus.sone.database;
 import java.util.Collection;
 
 import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Sone;
 
 import com.google.common.base.Function;
@@ -58,7 +59,7 @@ public interface SoneProvider {
         *
         * @return All local Sones
         */
-       public Collection<Sone> getLocalSones();
+       public Collection<LocalSone> getLocalSones();
 
        /**
         * Returns all remote Sones.
index 12ef439..128a4bd 100644 (file)
@@ -583,10 +583,16 @@ public class MemoryDatabase extends AbstractService implements Database {
        }
 
        @Override
-       public Collection<Sone> getLocalSones() {
+       public Collection<LocalSone> getLocalSones() {
                lock.readLock().lock();
                try {
-                       return from(allSones.values()).filter(LOCAL_SONE_FILTER).toSet();
+                       return from(allSones.values()).filter(LOCAL_SONE_FILTER).transform(new Function<Sone, LocalSone>() {
+                               @Override
+                               public LocalSone apply(Sone sone) {
+                                       // FIXME – Sones will not always implement LocalSone
+                                       return (LocalSone) sone;
+                               }
+                       }).toSet();
                } finally {
                        lock.readLock().unlock();
                }
index 0590f72..d66690e 100644 (file)
@@ -19,6 +19,7 @@ package net.pterodactylus.sone.web;
 
 import com.google.common.base.Optional;
 
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.text.TextFilter;
@@ -62,14 +63,13 @@ public class CreatePostPage extends SoneTemplatePage {
                        if (text.length() != 0) {
                                String senderId = request.getHttpRequest().getPartAsStringFailsafe("sender", 43);
                                String recipientId = request.getHttpRequest().getPartAsStringFailsafe("recipient", 43);
-                               Sone currentSone = getCurrentSone(request.getToadletContext()).get();
-                               Sone sender = webInterface.getCore().getLocalSone(senderId);
-                               if (sender == null) {
-                                       sender = currentSone;
-                               }
                                Optional<Sone> recipient = webInterface.getCore().getSone(recipientId);
+                               Optional<LocalSone> sender = webInterface.getCore().getLocalSone(senderId);
+                               if (!sender.isPresent()) {
+                                       sender = getCurrentSone(request.getToadletContext());
+                               }
                                text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text);
-                               webInterface.getCore().createPost(sender, recipient, text);
+                               webInterface.getCore().createPost(sender.get(), recipient, text);
                                throw new RedirectException(returnPage);
                        }
                        templateContext.set("errorTextEmpty", true);
index 4158313..3ec13f6 100644 (file)
@@ -19,8 +19,8 @@ package net.pterodactylus.sone.web;
 
 import com.google.common.base.Optional;
 
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.text.TextFilter;
 import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.util.template.Template;
@@ -66,12 +66,12 @@ public class CreateReplyPage extends SoneTemplatePage {
                        }
                        if (text.length() > 0) {
                                String senderId = request.getHttpRequest().getPartAsStringFailsafe("sender", 43);
-                               Sone sender = webInterface.getCore().getLocalSone(senderId);
-                               if (sender == null) {
-                                       sender = getCurrentSone(request.getToadletContext()).get();
+                               Optional<LocalSone> sender = webInterface.getCore().getLocalSone(senderId);
+                               if (!sender.isPresent()) {
+                                       sender = getCurrentSone(request.getToadletContext());
                                }
                                text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text);
-                               webInterface.getCore().createReply(sender, post.get(), text);
+                               webInterface.getCore().createReply(sender.get(), post.get(), text);
                                throw new RedirectException(returnPage);
                        }
                        templateContext.set("errorTextEmpty", true);
index a741322..6a3c537 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.util.collection.Pagination;
@@ -74,7 +75,7 @@ public class KnownSonesPage extends SoneTemplatePage {
                templateContext.set("sort", sortField);
                templateContext.set("order", sortOrder);
                templateContext.set("filter", filter);
-               final Optional<Sone> currentSone = getCurrentSone(request.getToadletContext(), false);
+               final Optional<LocalSone> currentSone = getCurrentSone(request.getToadletContext(), false);
                Collection<Sone> knownSones = Collections2.filter(webInterface.getCore().getSones(), Sone.EMPTY_SONE_FILTER);
                if (currentSone.isPresent() && "followed".equals(filter)) {
                        knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {
index f72252f..cf33d05 100644 (file)
 
 package net.pterodactylus.sone.web;
 
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
 
+import com.google.common.base.Optional;
+
 /**
  * This page lets the user lock a {@link Sone} to prevent it from being
  * inserted.
@@ -53,9 +56,9 @@ public class LockSonePage extends SoneTemplatePage {
        protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
                super.processTemplate(request, templateContext);
                String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
-               Sone sone = webInterface.getCore().getLocalSone(soneId);
-               if (sone != null) {
-                       webInterface.getCore().lockSone(sone);
+               Optional<LocalSone> sone = webInterface.getCore().getLocalSone(soneId);
+               if (sone.isPresent()) {
+                       webInterface.getCore().lockSone(sone.get());
                }
                String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
                throw new RedirectException(returnPage);
index 8d269dd..5934497 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.logging.Logger;
 
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.freenet.wot.OwnIdentity;
 import net.pterodactylus.sone.web.page.FreenetRequest;
@@ -32,6 +33,8 @@ import net.pterodactylus.util.template.TemplateContext;
 import net.pterodactylus.util.web.Method;
 import freenet.clients.http.ToadletContext;
 
+import com.google.common.base.Optional;
+
 /**
  * The login page manages logging the user in.
  *
@@ -71,9 +74,9 @@ public class LoginPage extends SoneTemplatePage {
                templateContext.set("sones", localSones);
                if (request.getMethod() == Method.POST) {
                        String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone-id", 100);
-                       Sone selectedSone = webInterface.getCore().getLocalSone(soneId);
-                       if (selectedSone != null) {
-                               setCurrentSone(request.getToadletContext(), selectedSone);
+                       Optional<LocalSone> selectedSone = webInterface.getCore().getLocalSone(soneId);
+                       if (selectedSone.isPresent()) {
+                               setCurrentSone(request.getToadletContext(), selectedSone.get());
                                String target = request.getHttpRequest().getParam("target");
                                if ((target == null) || (target.length() == 0)) {
                                        target = "index.html";
index cbc9686..4b8ef00 100644 (file)
@@ -23,7 +23,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import net.pterodactylus.sone.core.Preferences;
-import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Sone.ShowCustomAvatars;
 import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
 import net.pterodactylus.sone.web.page.FreenetRequest;
@@ -63,7 +63,7 @@ public class OptionsPage extends SoneTemplatePage {
        protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
                super.processTemplate(request, templateContext);
                Preferences preferences = webInterface.getCore().getPreferences();
-               Optional<Sone> currentSone = webInterface.getCurrentSone(request.getToadletContext(), false);
+               Optional<LocalSone> currentSone = webInterface.getCurrentSone(request.getToadletContext(), false);
                if (request.getMethod() == Method.POST) {
                        List<String> fieldErrors = new ArrayList<String>();
                        if (currentSone.isPresent()) {
index fa2798e..506fc15 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.main.SonePlugin;
 import net.pterodactylus.sone.notify.ListNotificationFilters;
@@ -138,7 +139,7 @@ public class SoneTemplatePage extends FreenetTemplatePage {
         * @return The currently logged in Sone, or {@code null} if no Sone is
         *         currently logged in
         */
-       protected Optional<Sone> getCurrentSone(ToadletContext toadletContext) {
+       protected Optional<LocalSone> getCurrentSone(ToadletContext toadletContext) {
                return webInterface.getCurrentSone(toadletContext);
        }
 
@@ -153,7 +154,7 @@ public class SoneTemplatePage extends FreenetTemplatePage {
         * @return The currently logged in Sone, or {@code null} if no Sone is
         *         currently logged in
         */
-       protected Optional<Sone> getCurrentSone(ToadletContext toadletContext, boolean create) {
+       protected Optional<LocalSone> getCurrentSone(ToadletContext toadletContext, boolean create) {
                return webInterface.getCurrentSone(toadletContext, create);
        }
 
@@ -224,7 +225,7 @@ public class SoneTemplatePage extends FreenetTemplatePage {
        @Override
        protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
                super.processTemplate(request, templateContext);
-               Optional<Sone> currentSone = getCurrentSone(request.getToadletContext(), false);
+               Optional<LocalSone> currentSone = getCurrentSone(request.getToadletContext(), false);
                templateContext.set("core", webInterface.getCore());
                templateContext.set("currentSone", currentSone.orNull());
                templateContext.set("localSones", webInterface.getCore().getLocalSones());
index 8491163..56ee2b7 100644 (file)
 
 package net.pterodactylus.sone.web;
 
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
 
+import com.google.common.base.Optional;
+
 /**
  * This page lets the user unlock a {@link Sone} to allow its insertion.
  *
@@ -52,9 +55,9 @@ public class UnlockSonePage extends SoneTemplatePage {
        protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
                super.processTemplate(request, templateContext);
                String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
-               Sone sone = webInterface.getCore().getLocalSone(soneId);
-               if (sone != null) {
-                       webInterface.getCore().unlockSone(sone);
+               Optional<LocalSone> localSone = webInterface.getCore().getLocalSone(soneId);
+               if (localSone.isPresent()) {
+                       webInterface.getCore().unlockSone(localSone.get());
                }
                String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
                throw new RedirectException(returnPage);
index 258669a..e245b6a 100644 (file)
@@ -64,6 +64,7 @@ import net.pterodactylus.sone.core.event.SoneUnlockedEvent;
 import net.pterodactylus.sone.core.event.UpdateFoundEvent;
 import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Image;
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Profile;
@@ -381,7 +382,7 @@ public class WebInterface {
         * @return The currently logged in Sone, or {@code null} if no Sone is
         *         currently logged in
         */
-       public Optional<Sone> getCurrentSone(ToadletContext toadletContext) {
+       public Optional<LocalSone> getCurrentSone(ToadletContext toadletContext) {
                return getCurrentSone(toadletContext, true);
        }
 
@@ -396,8 +397,8 @@ public class WebInterface {
         * @return The currently logged in Sone, or {@code null} if no Sone is
         *         currently logged in
         */
-       public Optional<Sone> getCurrentSone(ToadletContext toadletContext, boolean createSession) {
-               Collection<Sone> localSones = getCore().getLocalSones();
+       public Optional<LocalSone> getCurrentSone(ToadletContext toadletContext, boolean createSession) {
+               Collection<LocalSone> localSones = getCore().getLocalSones();
                if (localSones.size() == 1) {
                        return Optional.of(localSones.iterator().next());
                }
@@ -412,7 +413,7 @@ public class WebInterface {
         * @return The currently logged in Sone, or {@code null} if no Sone is
         *         currently logged in
         */
-       public Optional<Sone> getCurrentSone(Optional<Session> session) {
+       public Optional<LocalSone> getCurrentSone(Optional<Session> session) {
                if (!session.isPresent()) {
                        return Optional.absent();
                }
@@ -420,7 +421,7 @@ public class WebInterface {
                if (soneId == null) {
                        return Optional.absent();
                }
-               return Optional.fromNullable(getCore().getLocalSone(soneId));
+               return getCore().getLocalSone(soneId);
        }
 
        /**
index 71a76a6..50bf221 100644 (file)
@@ -17,6 +17,7 @@
 
 package net.pterodactylus.sone.web.ajax;
 
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.text.TextFilter;
@@ -47,21 +48,21 @@ public class CreatePostAjaxPage extends JsonPage {
         */
        @Override
        protected JsonReturnObject createJsonObject(FreenetRequest request) {
-               Sone sone = getCurrentSone(request.getToadletContext()).get();
+               LocalSone sone = getCurrentSone(request.getToadletContext()).get();
                String recipientId = request.getHttpRequest().getParam("recipient");
                Optional<Sone> recipient = webInterface.getCore().getSone(recipientId);
                String senderId = request.getHttpRequest().getParam("sender");
-               Sone sender = webInterface.getCore().getLocalSone(senderId);
-               if (sender == null) {
-                       sender = sone;
+               Optional<LocalSone> sender = webInterface.getCore().getLocalSone(senderId);
+               if (!sender.isPresent()) {
+                       sender = Optional.of(sone);
                }
                String text = request.getHttpRequest().getParam("text");
                if ((text == null) || (text.trim().length() == 0)) {
                        return createErrorJsonObject("text-required");
                }
                text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text);
-               Post newPost = webInterface.getCore().createPost(sender, recipient, text);
-               return createSuccessJsonObject().put("postId", newPost.getId()).put("sone", sender.getId()).put("recipient", newPost.getRecipientId().orNull());
+               Post newPost = webInterface.getCore().createPost(sender.get(), recipient, text);
+               return createSuccessJsonObject().put("postId", newPost.getId()).put("sone", sender.get().getId()).put("recipient", newPost.getRecipientId().orNull());
        }
 
 }
index 8c0387e..0056156 100644 (file)
@@ -19,9 +19,9 @@ package net.pterodactylus.sone.web.ajax;
 
 import com.google.common.base.Optional;
 
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.text.TextFilter;
 import net.pterodactylus.sone.web.WebInterface;
 import net.pterodactylus.sone.web.page.FreenetRequest;
@@ -55,17 +55,17 @@ public class CreateReplyAjaxPage extends JsonPage {
                String postId = request.getHttpRequest().getParam("post");
                String text = request.getHttpRequest().getParam("text").trim();
                String senderId = request.getHttpRequest().getParam("sender");
-               Sone sender = webInterface.getCore().getLocalSone(senderId);
-               if (sender == null) {
-                       sender = getCurrentSone(request.getToadletContext()).get();
+               Optional<LocalSone> sender = webInterface.getCore().getLocalSone(senderId);
+               if (!sender.isPresent()) {
+                       sender = getCurrentSone(request.getToadletContext());
                }
                Optional<Post> post = webInterface.getCore().getPost(postId);
                if (!post.isPresent()) {
                        return createErrorJsonObject("invalid-post-id");
                }
                text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text);
-               PostReply reply = webInterface.getCore().createReply(sender, post.get(), text);
-               return createSuccessJsonObject().put("reply", reply.getId()).put("sone", sender.getId());
+               PostReply reply = webInterface.getCore().createReply(sender.get(), post.get(), text);
+               return createSuccessJsonObject().put("reply", reply.getId()).put("sone", sender.get().getId());
        }
 
 }
index d86e5a8..e6a6a9f 100644 (file)
@@ -25,7 +25,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
-import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.main.SonePlugin;
 import net.pterodactylus.sone.notify.ListNotificationFilters;
 import net.pterodactylus.sone.web.WebInterface;
@@ -81,7 +81,7 @@ public class GetNotificationsAjaxPage extends JsonPage {
         */
        @Override
        protected JsonReturnObject createJsonObject(FreenetRequest request) {
-               Optional<Sone> currentSone = getCurrentSone(request.getToadletContext(), false);
+               Optional<LocalSone> currentSone = getCurrentSone(request.getToadletContext(), false);
                Collection<Notification> notifications = webInterface.getNotifications().getNotifications();
                List<Notification> filteredNotifications = ListNotificationFilters.filterNotifications(notifications, currentSone.orNull());
                Collections.sort(filteredNotifications, Notification.CREATED_TIME_SORTER);
@@ -145,7 +145,7 @@ public class GetNotificationsAjaxPage extends JsonPage {
         *            The current Sone (may be {@code null})
         * @return The current options
         */
-       private static JsonNode createJsonOptions(Optional<Sone> currentSone) {
+       private static JsonNode createJsonOptions(Optional<LocalSone> currentSone) {
                ObjectNode options = new ObjectNode(instance);
                if (currentSone.isPresent()) {
                        options.put("ShowNotification/NewSones", currentSone.get().getOptions().isShowNewSoneNotifications());
index 51ab3ee..bb1e416 100644 (file)
@@ -22,8 +22,8 @@ import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance;
 
 import com.google.common.base.Optional;
 
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.WebInterface;
 import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.util.io.Closer;
@@ -95,7 +95,7 @@ public class GetPostAjaxPage extends JsonPage {
         *            The currently logged in Sone (to store in the template)
         * @return The JSON representation of the post
         */
-       private JsonNode createJsonPost(FreenetRequest request, Post post, Optional<Sone> currentSone) {
+       private JsonNode createJsonPost(FreenetRequest request, Post post, Optional<LocalSone> currentSone) {
                ObjectNode jsonPost = new ObjectNode(instance);
                jsonPost.put("id", post.getId());
                jsonPost.put("sone", post.getSone().getId());
index d0b79ac..14d96ee 100644 (file)
@@ -22,8 +22,8 @@ import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance;
 
 import com.google.common.base.Optional;
 
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.WebInterface;
 import net.pterodactylus.sone.web.page.FreenetRequest;
 import net.pterodactylus.util.io.Closer;
@@ -97,7 +97,7 @@ public class GetReplyAjaxPage extends JsonPage {
         *            The currently logged in Sone (to store in the template)
         * @return The JSON representation of the reply
         */
-       private JsonNode createJsonReply(FreenetRequest request, PostReply reply, Optional<Sone> currentSone) {
+       private JsonNode createJsonReply(FreenetRequest request, PostReply reply, Optional<LocalSone> currentSone) {
                ObjectNode jsonReply = new ObjectNode(instance);
                jsonReply.put("id", reply.getId());
                jsonReply.put("postId", reply.getPostId());
index bb59a8d..84c96dd 100644 (file)
@@ -29,6 +29,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Sone;
@@ -73,7 +74,7 @@ public class GetStatusAjaxPage extends JsonPage {
         */
        @Override
        protected JsonReturnObject createJsonObject(FreenetRequest request) {
-               final Optional<Sone> currentSone = getCurrentSone(request.getToadletContext(), false);
+               final Optional<LocalSone> currentSone = getCurrentSone(request.getToadletContext(), false);
                /* load Sones. always return the status of the current Sone. */
                Set<Sone> sones = new HashSet<Sone>(currentSone.asSet());
                String loadSoneIds = request.getHttpRequest().getParam("soneIds");
@@ -191,7 +192,7 @@ public class GetStatusAjaxPage extends JsonPage {
         *            The current Sone (may be {@code null})
         * @return The current options
         */
-       private static JsonNode createJsonOptions(Optional<Sone> currentSone) {
+       private static JsonNode createJsonOptions(Optional<LocalSone> currentSone) {
                ObjectNode options = new ObjectNode(instance);
                if (currentSone.isPresent()) {
                        options.put("ShowNotification/NewSones", currentSone.get().getOptions().isShowNewSoneNotifications());
index ada501a..e181a4e 100644 (file)
@@ -27,7 +27,7 @@ import java.net.URI;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.web.WebInterface;
 import net.pterodactylus.sone.web.page.FreenetPage;
 import net.pterodactylus.sone.web.page.FreenetRequest;
@@ -77,11 +77,11 @@ public abstract class JsonPage implements FreenetPage {
        // ACCESSORS
        //
 
-       protected Optional<Sone> getCurrentSone(ToadletContext toadletContext) {
+       protected Optional<LocalSone> getCurrentSone(ToadletContext toadletContext) {
                return webInterface.getCurrentSone(toadletContext);
        }
 
-       protected Optional<Sone> getCurrentSone(ToadletContext toadletContext, boolean createSession) {
+       protected Optional<LocalSone> getCurrentSone(ToadletContext toadletContext, boolean createSession) {
                return webInterface.getCurrentSone(toadletContext, createSession);
        }
 
index cc04338..516db2d 100644 (file)
 package net.pterodactylus.sone.web.ajax;
 
 import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.WebInterface;
 import net.pterodactylus.sone.web.page.FreenetRequest;
 
+import com.google.common.base.Optional;
+
 /**
  * Lets the user {@link Core#lockSone(Sone) lock} a {@link Sone}.
  *
@@ -45,11 +48,11 @@ public class LockSoneAjaxPage extends JsonPage {
        @Override
        protected JsonReturnObject createJsonObject(FreenetRequest request) {
                String soneId = request.getHttpRequest().getParam("sone");
-               Sone sone = webInterface.getCore().getLocalSone(soneId);
-               if (sone == null) {
+               Optional<LocalSone> sone = webInterface.getCore().getLocalSone(soneId);
+               if (!sone.isPresent()) {
                        return createErrorJsonObject("invalid-sone-id");
                }
-               webInterface.getCore().lockSone(sone);
+               webInterface.getCore().lockSone(sone.get());
                return createSuccessJsonObject();
        }
 
index 3a91f81..8384e85 100644 (file)
 package net.pterodactylus.sone.web.ajax;
 
 import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.web.WebInterface;
 import net.pterodactylus.sone.web.page.FreenetRequest;
 
+import com.google.common.base.Optional;
+
 /**
  * Lets the user {@link Core#unlockSone(Sone) unlock} a {@link Sone}.
  *
@@ -45,11 +48,11 @@ public class UnlockSoneAjaxPage extends JsonPage {
        @Override
        protected JsonReturnObject createJsonObject(FreenetRequest request) {
                String soneId = request.getHttpRequest().getParam("sone");
-               Sone sone = webInterface.getCore().getLocalSone(soneId);
-               if (sone == null) {
+               Optional<LocalSone> localSone = webInterface.getCore().getLocalSone(soneId);
+               if (!localSone.isPresent()) {
                        return createErrorJsonObject("invalid-sone-id");
                }
-               webInterface.getCore().unlockSone(sone);
+               webInterface.getCore().unlockSone(localSone.get());
                return createSuccessJsonObject();
        }
 
index 2306931..383b52a 100644 (file)
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
 import net.pterodactylus.sone.freenet.fcp.Command.Response;
@@ -45,12 +46,12 @@ public class LockSoneCommandTest {
 
        @Test
        public void testLockingALocalSone() throws FcpException {
-               Sone localSone = mock(Sone.class);
+               LocalSone localSone = mock(LocalSone.class);
                when(localSone.getId()).thenReturn("LocalSone");
                when(localSone.isLocal()).thenReturn(true);
                Core core = mock(Core.class);
-               when(core.getSone(eq("LocalSone"))).thenReturn(Optional.of(localSone));
-               when(core.getLocalSone(eq("LocalSone"))).thenReturn(localSone);
+               when(core.getSone(eq("LocalSone"))).thenReturn(Optional.<Sone>of(localSone));
+               when(core.getLocalSone(eq("LocalSone"))).thenReturn(Optional.of(localSone));
                SimpleFieldSet fields = new SimpleFieldSetBuilder().put("Sone", "LocalSone").get();
 
                LockSoneCommand lockSoneCommand = new LockSoneCommand(core);
index ca615ee..48f5aa1 100644 (file)
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
 import net.pterodactylus.sone.freenet.fcp.Command.Response;
@@ -45,12 +46,12 @@ public class UnlockSoneCommandTest {
 
        @Test
        public void testUnlockingALocalSone() throws FcpException {
-               Sone localSone = mock(Sone.class);
+               LocalSone localSone = mock(LocalSone.class);
                when(localSone.getId()).thenReturn("LocalSone");
                when(localSone.isLocal()).thenReturn(true);
                Core core = mock(Core.class);
-               when(core.getSone(eq("LocalSone"))).thenReturn(Optional.of(localSone));
-               when(core.getLocalSone(eq("LocalSone"))).thenReturn(localSone);
+               when(core.getSone(eq("LocalSone"))).thenReturn(Optional.<Sone>of(localSone));
+               when(core.getLocalSone(eq("LocalSone"))).thenReturn(Optional.of(localSone));
                SimpleFieldSet fields = new SimpleFieldSetBuilder().put("Sone", "LocalSone").get();
 
                UnlockSoneCommand unlockSoneCommand = new UnlockSoneCommand(core);
index 2ac6db7..ff4ec15 100644 (file)
@@ -22,6 +22,7 @@ import java.io.StringReader;
 import java.util.Arrays;
 import java.util.Collection;
 
+import net.pterodactylus.sone.data.LocalSone;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.impl.IdOnlySone;
 import net.pterodactylus.sone.database.SoneProvider;
@@ -212,7 +213,7 @@ public class SoneTextParserTest extends TestCase {
                 * {@inheritDocs}
                 */
                @Override
-               public Collection<Sone> getLocalSones() {
+               public Collection<LocalSone> getLocalSones() {
                        return null;
                }