Remove possibility to create new posts from post provider interface.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 18 Jan 2013 10:01:30 +0000 (11:01 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 18 Jan 2013 10:01:30 +0000 (11:01 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/PostProvider.java
src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
src/main/java/net/pterodactylus/sone/text/SoneTextParser.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/ViewPostPage.java
src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetTimesAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java

index a51247e..1ebdcc8 100644 (file)
@@ -522,24 +522,12 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
        }
 
        /**
-        * Returns the post with the given ID, optionally creating a new post.
-        *
-        * @param postId
-        *            The ID of the post to get
-        * @param create
-        *            {@code true} it create a new post if no post with the given ID
-        *            exists, {@code false} to return {@code null}
-        * @return The post, or {@code null} if there is no such post
+        * {@inheritDoc}
         */
        @Override
-       public Post getPost(String postId, boolean create) {
+       public Post getPost(String postId) {
                synchronized (posts) {
-                       Post post = posts.get(postId);
-                       if ((post == null) && create) {
-                               post = new PostImpl(postId);
-                               posts.put(postId, post);
-                       }
-                       return post;
+                       return posts.get(postId);
                }
        }
 
@@ -677,7 +665,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider
                Set<Post> posts = new HashSet<Post>();
                synchronized (bookmarkedPosts) {
                        for (String bookmarkedPostId : bookmarkedPosts) {
-                               Post post = getPost(bookmarkedPostId, false);
+                               Post post = getPost(bookmarkedPostId);
                                if (post != null) {
                                        posts.add(post);
                                }
index c73ad65..e7167cd 100644 (file)
@@ -27,17 +27,12 @@ import net.pterodactylus.sone.data.Post;
 public interface PostProvider {
 
        /**
-        * Returns the post 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 post with the given ID is created and returned.
+        * Returns the post with the given ID.
         *
         * @param postId
         *            The ID of the post to return
-        * @param create
-        *            {@code true} to create a new post if no post with the given ID
-        *            exists, {@code false} to return {@code null} instead
         * @return The post with the given ID, or {@code null}
         */
-       public Post getPost(String postId, boolean create);
+       public Post getPost(String postId);
 
 }
index a483b01..b9ff03c 100644 (file)
@@ -185,7 +185,7 @@ public abstract class AbstractSoneCommand extends AbstractCommand {
        protected Post getPost(SimpleFieldSet simpleFieldSet, String parameterName) throws FcpException {
                try {
                        String postId = simpleFieldSet.getString(parameterName);
-                       Post post = core.getPost(postId, false);
+                       Post post = core.getPost(postId);
                        if (post == null) {
                                throw new FcpException("Could not load post from “" + postId + "”.");
                        }
index 5c59912..a093e46 100644 (file)
@@ -258,7 +258,7 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
                                        if (linkType == LinkType.POST) {
                                                if (line.length() >= (7 + 36)) {
                                                        String postId = line.substring(7, 43);
-                                                       Post post = postProvider.getPost(postId, false);
+                                                       Post post = postProvider.getPost(postId);
                                                        if ((post != null) && (post.getSone() != null)) {
                                                                parts.add(new PostPart(post));
                                                        } else {
index d552b91..fe50509 100644 (file)
@@ -65,7 +65,7 @@ public class MarkAsKnownPage extends SoneTemplatePage {
                for (StringTokenizer idTokenizer = new StringTokenizer(ids); idTokenizer.hasMoreTokens();) {
                        String id = idTokenizer.nextToken();
                        if (type.equals("post")) {
-                               Post post = webInterface.getCore().getPost(id, false);
+                               Post post = webInterface.getCore().getPost(id);
                                if (post == null) {
                                        continue;
                                }
index 1bca8cd..7352bab 100644 (file)
@@ -322,7 +322,7 @@ public class SearchPage extends SoneTemplatePage {
         */
        private String getPostId(String phrase) {
                String postId = phrase.startsWith("post://") ? phrase.substring(7) : phrase;
-               return (webInterface.getCore().getPost(postId, false) != null) ? postId : null;
+               return (webInterface.getCore().getPost(postId) != null) ? postId : null;
        }
 
        /**
index aaf013d..ca78d99 100644 (file)
@@ -54,7 +54,7 @@ public class ViewPostPage extends SoneTemplatePage {
        @Override
        protected String getPageTitle(FreenetRequest request) {
                String postId = request.getHttpRequest().getParam("post");
-               Post post = webInterface.getCore().getPost(postId, false);
+               Post post = webInterface.getCore().getPost(postId);
                String title = "";
                if ((post != null) && (post.getSone() != null)) {
                        title = post.getText().substring(0, Math.min(20, post.getText().length())) + "…";
index a8c36d5..3beb85d 100644 (file)
@@ -49,7 +49,7 @@ public class DeletePostAjaxPage extends JsonPage {
        @Override
        protected JsonObject createJsonObject(FreenetRequest request) {
                String postId = request.getHttpRequest().getParam("post");
-               Post post = webInterface.getCore().getPost(postId, false);
+               Post post = webInterface.getCore().getPost(postId);
                if ((post == null) || (post.getSone() == null)) {
                        return createErrorJsonObject("invalid-post-id");
                }
index ae813ee..0c2311e 100644 (file)
@@ -59,7 +59,7 @@ public class GetPostAjaxPage extends JsonPage {
        @Override
        protected JsonObject createJsonObject(FreenetRequest request) {
                String postId = request.getHttpRequest().getParam("post");
-               Post post = webInterface.getCore().getPost(postId, false);
+               Post post = webInterface.getCore().getPost(postId);
                if (post == null) {
                        return createErrorJsonObject("invalid-post-id");
                }
index a7f02c9..03bf8c5 100644 (file)
@@ -58,7 +58,7 @@ public class GetTimesAjaxPage extends JsonPage {
                if (allIds.length() > 0) {
                        String[] ids = allIds.split(",");
                        for (String id : ids) {
-                               Post post = webInterface.getCore().getPost(id, false);
+                               Post post = webInterface.getCore().getPost(id);
                                if (post == null) {
                                        continue;
                                }
index a193d75..18450b1 100644 (file)
@@ -57,7 +57,7 @@ public class MarkAsKnownAjaxPage extends JsonPage {
                Core core = webInterface.getCore();
                for (String id : ids) {
                        if (type.equals("post")) {
-                               Post post = core.getPost(id, false);
+                               Post post = core.getPost(id);
                                if (post == null) {
                                        continue;
                                }