/*
- * Sone - CreatePostCommand.java - Copyright © 2011 David Roden
+ * Sone - CreatePostCommand.java - Copyright © 2011–2013 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
package net.pterodactylus.sone.fcp;
+import static com.google.common.base.Optional.fromNullable;
+import static net.pterodactylus.sone.data.Identified.GET_ID;
+
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import net.pterodactylus.sone.freenet.fcp.FcpException;
+
import freenet.support.SimpleFieldSet;
import freenet.support.api.Bucket;
/**
* FCP command that creates a new {@link Post}.
*
- * @see Core#createPost(Sone, Sone, String)
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
public class CreatePostCommand extends AbstractSoneCommand {
* The Sone core
*/
public CreatePostCommand(Core core) {
- super(core);
+ super(core, true);
}
- /**
- * {@inheritDoc}
- */
@Override
public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
- Sone sone = getSone(parameters, "Sone", true);
+ Sone sone = getMandatoryLocalSone(parameters, "Sone");
String text = getString(parameters, "Text");
Sone recipient = null;
if (parameters.get("Recipient") != null) {
- recipient = getSone(parameters, "Recipient", false);
+ recipient = getMandatorySone(parameters, "Recipient");
}
if (sone.equals(recipient)) {
return new ErrorResponse("Sone and Recipient must not be the same.");
}
- Post post = getCore().createPost(sone, recipient, text);
+ Post post = sone.newPostBuilder().to(fromNullable(recipient).transform(GET_ID)).withText(text).build(getCore().postCreated());
return new Response("PostCreated", new SimpleFieldSetBuilder().put("Post", post.getId()).get());
}