If no current Sone exists, return an error.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ajax / GetPostAjaxPage.java
index 8eeedc9..1221f1a 100644 (file)
 
 package net.pterodactylus.sone.web.ajax;
 
-import java.io.StringWriter;
+import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance;
 
-import com.google.common.base.Optional;
+import java.io.StringWriter;
 
 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;
-import net.pterodactylus.util.json.JsonObject;
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
 import net.pterodactylus.util.template.TemplateException;
 
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.base.Optional;
+
 /**
  * This AJAX handler retrieves information and rendered representation of a
  * {@link Post}.
@@ -55,22 +58,16 @@ public class GetPostAjaxPage extends JsonPage {
                this.postTemplate = postTemplate;
        }
 
-       /**
-        * {@inheritDoc}
-        */
        @Override
-       protected JsonObject createJsonObject(FreenetRequest request) {
+       protected JsonReturnObject createJsonObject(FreenetRequest request) {
                String postId = request.getHttpRequest().getParam("post");
-               Optional<Post> post = webInterface.getCore().getPost(postId);
+               Optional<Post> post = webInterface.getCore().getDatabase().getPost(postId);
                if (!post.isPresent()) {
                        return createErrorJsonObject("invalid-post-id");
                }
                return createSuccessJsonObject().put("post", createJsonPost(request, post.get(), getCurrentSone(request.getToadletContext())));
        }
 
-       /**
-        * {@inheritDoc}
-        */
        @Override
        protected boolean needsFormPassword() {
                return false;
@@ -92,8 +89,8 @@ public class GetPostAjaxPage extends JsonPage {
         *            The currently logged in Sone (to store in the template)
         * @return The JSON representation of the post
         */
-       private JsonObject createJsonPost(FreenetRequest request, Post post, Sone currentSone) {
-               JsonObject jsonPost = new JsonObject();
+       private JsonNode createJsonPost(FreenetRequest request, Post post, Sone currentSone) {
+               ObjectNode jsonPost = new ObjectNode(instance);
                jsonPost.put("id", post.getId());
                jsonPost.put("sone", post.getSone().getId());
                jsonPost.put("recipient", post.getRecipientId().orNull());