Remove possibility to create Sones from sone provider interface.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 22 Jan 2013 10:27:11 +0000 (11:27 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 22 Jan 2013 10:27:11 +0000 (11:27 +0100)
23 files changed:
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/SoneProvider.java
src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java
src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java
src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java
src/main/java/net/pterodactylus/sone/template/ParserFilter.java
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
src/main/java/net/pterodactylus/sone/web/CreatePostPage.java
src/main/java/net/pterodactylus/sone/web/DistrustPage.java
src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java
src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java
src/main/java/net/pterodactylus/sone/web/SearchPage.java
src/main/java/net/pterodactylus/sone/web/TrustPage.java
src/main/java/net/pterodactylus/sone/web/UntrustPage.java
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java
src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java

index 862cc78..582a5fd 100644 (file)
@@ -357,30 +357,9 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
         * @return The Sone with the given ID, or {@code null} if there is no such
         *         Sone
         */
-       public Sone getSone(String id) {
-               return getSone(id, true);
-       }
-
-       /**
-        * Returns the Sone with the given ID, regardless whether it’s local or
-        * remote.
-        *
-        * @param id
-        *            The ID of the Sone to get
-        * @param create
-        *            {@code true} to create a new Sone if none exists,
-        *            {@code false} to return {@code null} if a Sone with the given
-        *            ID does not exist
-        * @return The Sone with the given ID, or {@code null} if there is no such
-        *         Sone
-        */
        @Override
-       public Sone getSone(String id, boolean create) {
+       public Sone getSone(String id) {
                synchronized (sones) {
-                       if (!sones.containsKey(id) && create) {
-                               Sone sone = new Sone(id, false);
-                               sones.put(id, sone);
-                       }
                        return sones.get(id);
                }
        }
@@ -2359,7 +2338,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                        /* some local identity still trusts this identity, don’t remove. */
                        return;
                }
-               Sone sone = getSone(identity.getId(), false);
+               Sone sone = getSone(identity.getId());
                if (sone == null) {
                        /* TODO - we don’t have the Sone anymore. should this happen? */
                        return;
index 73edd0b..6b479df 100644 (file)
@@ -27,17 +27,12 @@ import net.pterodactylus.sone.data.Sone;
 public interface SoneProvider {
 
        /**
-        * Returns the Sone with the given ID, if it exists. If it does not exist
-        * and {@code create} is {@code false}, {@code null} is returned; otherwise,
-        * a new Sone with the given ID is created and returned.
+        * Returns the Sone with the given ID, if it exists.
         *
         * @param soneId
         *            The ID of the Sone to return
-        * @param create
-        *            {@code true} to create a new Sone if no Sone with the given ID
-        *            exists, {@code false} to return {@code null} instead
         * @return The Sone with the given ID, or {@code null}
         */
-       public Sone getSone(String soneId, boolean create);
+       public Sone getSone(String soneId);
 
 }
index bb8a4df..d422cba 100644 (file)
@@ -94,7 +94,7 @@ public class PostImpl implements Post {
         */
        @Override
        public Sone getSone() {
-               return soneProvider.getSone(soneId, false);
+               return soneProvider.getSone(soneId);
        }
 
        /**
@@ -102,7 +102,7 @@ public class PostImpl implements Post {
         */
        @Override
        public Sone getRecipient() {
-               return soneProvider.getSone(recipientId, false);
+               return soneProvider.getSone(recipientId);
        }
 
        /**
index 5590c7e..5ede070 100644 (file)
@@ -83,7 +83,7 @@ public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
         */
        @Override
        public Sone getSone() {
-               return soneProvider.getSone(soneId, false);
+               return soneProvider.getSone(soneId);
        }
 
        /**
index 80802ad..036e451 100644 (file)
@@ -162,7 +162,7 @@ public abstract class AbstractSoneCommand extends AbstractCommand {
                if (mandatory && (soneId == null)) {
                        throw new FcpException("Could not load Sone ID from “" + parameterName + "”.");
                }
-               Sone sone = localOnly ? core.getLocalSone(soneId, false) : core.getSone(soneId, false);
+               Sone sone = localOnly ? core.getLocalSone(soneId, false) : core.getSone(soneId);
                if (mandatory && (sone == null)) {
                        throw new FcpException("Could not load Sone from “" + soneId + "”.");
                }
index 5f2fd14..f842ac4 100644 (file)
@@ -66,7 +66,7 @@ public class GetPostFeedCommand extends AbstractSoneCommand {
                        if (!getCore().hasSone(friendSoneId)) {
                                continue;
                        }
-                       allPosts.addAll(getCore().getSone(friendSoneId, false).getPosts());
+                       allPosts.addAll(getCore().getSone(friendSoneId).getPosts());
                }
                allPosts.addAll(getCore().getDirectedPosts(sone));
                allPosts = Collections2.filter(allPosts, Post.FUTURE_POSTS_FILTER);
index d2f2619..8833a2d 100644 (file)
@@ -94,7 +94,7 @@ public class ParserFilter implements Filter {
                int cutOffLength = Numbers.safeParseInteger(parameters.get("cut-off-length"), Numbers.safeParseInteger(templateContext.get(String.valueOf(parameters.get("cut-off-length"))), length));
                Object sone = parameters.get("sone");
                if (sone instanceof String) {
-                       sone = core.getSone((String) sone, false);
+                       sone = core.getSone((String) sone);
                }
                FreenetRequest request = (FreenetRequest) templateContext.get("request");
                SoneTextParserContext context = new SoneTextParserContext(request, (Sone) sone);
index a093e46..8e3c023 100644 (file)
@@ -239,7 +239,7 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
                                        if (linkType == LinkType.SONE) {
                                                if (line.length() >= (7 + 43)) {
                                                        String soneId = line.substring(7, 50);
-                                                       Sone sone = soneProvider.getSone(soneId, false);
+                                                       Sone sone = soneProvider.getSone(soneId);
                                                        if (sone == null) {
                                                                /*
                                                                 * don’t use create=true above, we don’t want
index 087a5ad..e77e55a 100644 (file)
@@ -65,7 +65,7 @@ public class CreatePostPage extends SoneTemplatePage {
                                if (sender == null) {
                                        sender = currentSone;
                                }
-                               Sone recipient = webInterface.getCore().getSone(recipientId, false);
+                               Sone recipient = webInterface.getCore().getSone(recipientId);
                                text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text);
                                webInterface.getCore().createPost(sender, recipient, System.currentTimeMillis(), text);
                                throw new RedirectException(returnPage);
index 60c174d..262d602 100644 (file)
@@ -59,7 +59,7 @@ public class DistrustPage extends SoneTemplatePage {
                        String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
                        String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
                        Sone currentSone = getCurrentSone(request.getToadletContext());
-                       Sone sone = webInterface.getCore().getSone(identity, false);
+                       Sone sone = webInterface.getCore().getSone(identity);
                        if (sone != null) {
                                webInterface.getCore().distrustSone(currentSone, sone);
                        }
index 4a9548e..d0a446f 100644 (file)
@@ -77,7 +77,7 @@ public class ImageBrowserPage extends SoneTemplatePage {
                }
                String soneId = request.getHttpRequest().getParam("sone", null);
                if (soneId != null) {
-                       Sone sone = webInterface.getCore().getSone(soneId, false);
+                       Sone sone = webInterface.getCore().getSone(soneId);
                        templateContext.set("soneRequested", true);
                        templateContext.set("sone", sone);
                        return;
index 0bf5285..a923386 100644 (file)
@@ -77,7 +77,7 @@ public class MarkAsKnownPage extends SoneTemplatePage {
                                }
                                webInterface.getCore().markReplyKnown(reply);
                        } else if (type.equals("sone")) {
-                               Sone sone = webInterface.getCore().getSone(id, false);
+                               Sone sone = webInterface.getCore().getSone(id);
                                if (sone == null) {
                                        continue;
                                }
index 337918d..c037baf 100644 (file)
@@ -309,7 +309,7 @@ public class SearchPage extends SoneTemplatePage {
         */
        private String getSoneId(String phrase) {
                String soneId = phrase.startsWith("sone://") ? phrase.substring(7) : phrase;
-               return (webInterface.getCore().getSone(soneId, false) != null) ? soneId : null;
+               return (webInterface.getCore().getSone(soneId) != null) ? soneId : null;
        }
 
        /**
index ef5463b..5d62399 100644 (file)
@@ -59,7 +59,7 @@ public class TrustPage extends SoneTemplatePage {
                        String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
                        String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
                        Sone currentSone = getCurrentSone(request.getToadletContext());
-                       Sone sone = webInterface.getCore().getSone(identity, false);
+                       Sone sone = webInterface.getCore().getSone(identity);
                        if (sone != null) {
                                webInterface.getCore().trustSone(currentSone, sone);
                        }
index e43740e..1ee4f8e 100644 (file)
@@ -59,7 +59,7 @@ public class UntrustPage extends SoneTemplatePage {
                        String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
                        String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
                        Sone currentSone = getCurrentSone(request.getToadletContext());
-                       Sone sone = webInterface.getCore().getSone(identity, false);
+                       Sone sone = webInterface.getCore().getSone(identity);
                        if (sone != null) {
                                webInterface.getCore().untrustSone(currentSone, sone);
                        }
index dec4fe2..ddc0231 100644 (file)
@@ -65,7 +65,7 @@ public class ViewSonePage extends SoneTemplatePage {
        @Override
        protected String getPageTitle(FreenetRequest request) {
                String soneId = request.getHttpRequest().getParam("sone");
-               Sone sone = webInterface.getCore().getSone(soneId, false);
+               Sone sone = webInterface.getCore().getSone(soneId);
                if ((sone != null) && (sone.getTime() > 0)) {
                        String soneName = SoneAccessor.getNiceName(sone);
                        return soneName + " - " + webInterface.getL10n().getString("Page.ViewSone.Title");
@@ -80,7 +80,7 @@ public class ViewSonePage extends SoneTemplatePage {
        protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
                super.processTemplate(request, templateContext);
                String soneId = request.getHttpRequest().getParam("sone");
-               Sone sone = webInterface.getCore().getSone(soneId, false);
+               Sone sone = webInterface.getCore().getSone(soneId);
                templateContext.set("sone", sone);
                templateContext.set("soneId", soneId);
                if (sone == null) {
index 4750794..32ebfc9 100644 (file)
@@ -51,7 +51,7 @@ public class CreatePostAjaxPage extends JsonPage {
                        return createErrorJsonObject("auth-required");
                }
                String recipientId = request.getHttpRequest().getParam("recipient");
-               Sone recipient = webInterface.getCore().getSone(recipientId, false);
+               Sone recipient = webInterface.getCore().getSone(recipientId);
                String senderId = request.getHttpRequest().getParam("sender");
                Sone sender = webInterface.getCore().getLocalSone(senderId, false);
                if (sender == null) {
index 25de182..b86055d 100644 (file)
@@ -51,7 +51,7 @@ public class DistrustAjaxPage extends JsonPage {
                        return createErrorJsonObject("auth-required");
                }
                String soneId = request.getHttpRequest().getParam("sone");
-               Sone sone = webInterface.getCore().getSone(soneId, false);
+               Sone sone = webInterface.getCore().getSone(soneId);
                if (sone == null) {
                        return createErrorJsonObject("invalid-sone-id");
                }
index 8657a6a..384261c 100644 (file)
@@ -74,7 +74,7 @@ public class GetStatusAjaxPage extends JsonPage {
                        String[] soneIds = loadSoneIds.split(",");
                        for (String soneId : soneIds) {
                                /* just add it, we skip null further down. */
-                               sones.add(webInterface.getCore().getSone(soneId, false));
+                               sones.add(webInterface.getCore().getSone(soneId));
                        }
                }
                JsonArray jsonSones = new JsonArray();
index e9c582a..55ae553 100644 (file)
@@ -69,7 +69,7 @@ public class MarkAsKnownAjaxPage extends JsonPage {
                                }
                                core.markReplyKnown(reply);
                        } else if (type.equals("sone")) {
-                               Sone sone = core.getSone(id, false);
+                               Sone sone = core.getSone(id);
                                if (sone == null) {
                                        continue;
                                }
index 756cee7..9329c1b 100644 (file)
@@ -51,7 +51,7 @@ public class TrustAjaxPage extends JsonPage {
                        return createErrorJsonObject("auth-required");
                }
                String soneId = request.getHttpRequest().getParam("sone");
-               Sone sone = webInterface.getCore().getSone(soneId, false);
+               Sone sone = webInterface.getCore().getSone(soneId);
                if (sone == null) {
                        return createErrorJsonObject("invalid-sone-id");
                }
index 227b580..70e1448 100644 (file)
@@ -51,7 +51,7 @@ public class UntrustAjaxPage extends JsonPage {
                        return createErrorJsonObject("auth-required");
                }
                String soneId = request.getHttpRequest().getParam("sone");
-               Sone sone = webInterface.getCore().getSone(soneId, false);
+               Sone sone = webInterface.getCore().getSone(soneId);
                if (sone == null) {
                        return createErrorJsonObject("invalid-sone-id");
                }
index cd05acb..53c52dd 100644 (file)
@@ -181,7 +181,7 @@ public class SoneTextParserTest extends TestCase {
                 * {@inheritDoc}
                 */
                @Override
-               public Sone getSone(final String soneId, boolean create) {
+               public Sone getSone(final String soneId) {
                        return new Sone(soneId, false) {
 
                                /**