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}.
* {@inheritDoc}
*/
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
+ public Response execute(SimpleFieldSet parameters) throws FcpException {
Sone sone = getSone(parameters, "Sone", true);
String text = getString(parameters, "Text");
Sone recipient = null;
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 Reply}.
* {@inheritDoc}
*/
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
+ public Response execute(SimpleFieldSet parameters) throws FcpException {
Sone sone = getSone(parameters, "Sone", true);
Post post = getPost(parameters, "Post");
String text = getString(parameters, "Text");
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 deletes a {@link Post}.
* {@inheritDoc}
*/
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
+ public Response execute(SimpleFieldSet parameters) throws FcpException {
Post post = getPost(parameters, "Post");
if (!post.getSone().isLocal()) {
return new ErrorResponse(401, "Not allowed.");
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 deletes a {@link PostReply}.
* {@inheritDoc}
*/
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
+ public Response execute(SimpleFieldSet parameters) throws FcpException {
PostReply reply = getReply(parameters, "Reply");
if (!reply.getSone().isLocal()) {
return new ErrorResponse(401, "Not allowed.");
return;
}
try {
- Response response = command.execute(parameters, data, AccessType.values()[accessType]);
+ Response response = command.execute(parameters);
sendReply(pluginReplySender, identifier, response);
} catch (Exception e1) {
logger.log(Level.WARNING, "Could not process FCP command “%s”.", command);
import net.pterodactylus.sone.core.Core;
import freenet.support.SimpleFieldSet;
-import freenet.support.api.Bucket;
/**
* Implements the “GetLocalSones” FCP command that returns the list of local
* {@inheritDoc}
*/
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) {
+ public Response execute(SimpleFieldSet parameters) {
return new Response("ListLocalSones", encodeSones(getCore().getLocalSones(), "LocalSones."));
}
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.freenet.fcp.FcpException;
import freenet.support.SimpleFieldSet;
-import freenet.support.api.Bucket;
/**
* The “GetPost” FCP command returns a single {@link Post} to an FCP client.
* {@inheritDoc}
*/
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
+ public Response execute(SimpleFieldSet parameters) throws FcpException {
Post post = getPost(parameters, "Post");
boolean includeReplies = getBoolean(parameters, "IncludeReplies", true);
import com.google.common.collect.Collections2;
import freenet.support.SimpleFieldSet;
-import freenet.support.api.Bucket;
/**
* Implementation of an FCP interface for other clients or plugins to
* {@inheritDoc}
*/
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
+ public Response execute(SimpleFieldSet parameters) throws FcpException {
Sone sone = getSone(parameters, "Sone", true);
int startPost = getInt(parameters, "StartPost", 0);
int maxPosts = getInt(parameters, "MaxPosts", -1);
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.freenet.fcp.FcpException;
import freenet.support.SimpleFieldSet;
-import freenet.support.api.Bucket;
/**
* Implements the “GetPosts” FCP command that returns the list of posts a Sone
* {@inheritDoc}
*/
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
+ public Response execute(SimpleFieldSet parameters) throws FcpException {
Sone sone = getSone(parameters, "Sone", false);
int startPost = getInt(parameters, "StartPost", 0);
int maxPosts = getInt(parameters, "MaxPosts", -1);
import com.google.common.base.Optional;
import freenet.support.SimpleFieldSet;
-import freenet.support.api.Bucket;
/**
* Implements the “GetSone“ FCP command which returns {@link Profile}
* {@inheritDoc}
*/
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
+ public Response execute(SimpleFieldSet parameters) throws FcpException {
Sone sone = getSone(parameters, "Sone", false);
Optional<Sone> localSone = getSone(parameters, "LocalSone", false, false);
return new Response("Sone", encodeSone(sone, "", localSone));
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Sone;
import freenet.support.SimpleFieldSet;
-import freenet.support.api.Bucket;
/**
* Implements the “GetSones” FCP command that returns the list of known Sones.
* {@inheritDoc}
*/
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) {
+ public Response execute(SimpleFieldSet parameters) {
int startSone = getInt(parameters, "StartSone", 0);
int maxSones = getInt(parameters, "MaxSones", -1);
List<Sone> sones = new ArrayList<Sone>(getCore().getSones());
import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import net.pterodactylus.sone.freenet.fcp.FcpException;
import freenet.support.SimpleFieldSet;
-import freenet.support.api.Bucket;
/**
* Implements the “LikePost” FCP command which allows the user to like a post.
* {@inheritDoc}
*/
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
+ public Response execute(SimpleFieldSet parameters) throws FcpException {
Post post = getPost(parameters, "Post");
Sone sone = getSone(parameters, "Sone", true);
sone.addLikedPostId(post.getId());
import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import net.pterodactylus.sone.freenet.fcp.FcpException;
import freenet.support.SimpleFieldSet;
-import freenet.support.api.Bucket;
/**
* Implements the “LikeReply” FCP command which allows the user to like a reply.
* {@inheritDoc}
*/
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
+ public Response execute(SimpleFieldSet parameters) throws FcpException {
PostReply reply = getReply(parameters, "Reply");
Sone sone = getSone(parameters, "Sone", true);
sone.addLikedReplyId(reply.getId());
import net.pterodactylus.sone.freenet.fcp.FcpException;
import freenet.support.SimpleFieldSet;
-import freenet.support.api.Bucket;
import com.google.common.base.Optional;
//
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
+ public Response execute(SimpleFieldSet parameters) throws FcpException {
Optional<Sone> sone = getSone(parameters, "Sone", true, true);
getCore().lockSone(sone.get());
return new Response("SoneLocked", new SimpleFieldSetBuilder().put("Sone", sone.get().getId()).get());
import net.pterodactylus.sone.freenet.fcp.FcpException;
import freenet.support.SimpleFieldSet;
-import freenet.support.api.Bucket;
import com.google.common.base.Optional;
//
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException {
+ public Response execute(SimpleFieldSet parameters) throws FcpException {
Optional<Sone> sone = getSone(parameters, "Sone", true, true);
getCore().unlockSone(sone.get());
return new Response("SoneUnlocked", new SimpleFieldSetBuilder().put("Sone", sone.get().getId()).get());
import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import net.pterodactylus.sone.main.SonePlugin;
import freenet.support.SimpleFieldSet;
-import freenet.support.api.Bucket;
/**
* Returns version information about the Sone plugin.
* {@inheritDoc}
*/
@Override
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) {
+ public Response execute(SimpleFieldSet parameters) {
return new Response("Version", new SimpleFieldSetBuilder().put("Version", SonePlugin.getPluginVersion()).put("ProtocolVersion", 1).get());
}
import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import freenet.support.SimpleFieldSet;
-import freenet.support.api.Bucket;
/**
* Implementation of an FCP interface for other clients or plugins to
*
* @param parameters
* The parameters of the comand
- * @param data
- * The data of the command (may be {@code null})
- * @param accessType
- * The access type
* @return A reply to send back to the plugin
* @throws FcpException
* if an error processing the parameters occurs
*/
- public Response execute(SimpleFieldSet parameters, Bucket data, AccessType accessType) throws FcpException;
+ public Response execute(SimpleFieldSet parameters) throws FcpException;
/**
* The access type of the request.
private val core = mock<Core>()
private val workingCommand = mock<AbstractSoneCommand>().apply {
- whenever(execute(any(), any(), any())).thenReturn(Response("Working", SimpleFieldSet(true).apply {
+ whenever(execute(any())).thenReturn(Response("Working", SimpleFieldSet(true).apply {
putSingle("ReallyWorking", "true")
}))
}
private val brokenCommand = mock<AbstractSoneCommand>().apply {
- whenever(execute(any(), any(), any())).thenThrow(RuntimeException::class.java)
+ whenever(execute(any())).thenThrow(RuntimeException::class.java)
}
private val commandSupplier = object : CommandSupplier() {
override fun supplyCommands(core: Core): Map<String, AbstractSoneCommand> {
SimpleFieldSet fields = new SimpleFieldSetBuilder().put("Sone", "LocalSone").get();
LockSoneCommand lockSoneCommand = new LockSoneCommand(core);
- Response response = lockSoneCommand.execute(fields, null, null);
+ Response response = lockSoneCommand.execute(fields);
verify(core).lockSone(eq(localSone));
assertThat(response, notNullValue());
SimpleFieldSet fields = new SimpleFieldSetBuilder().put("Sone", "RemoteSone").get();
LockSoneCommand lockSoneCommand = new LockSoneCommand(core);
- lockSoneCommand.execute(fields, null, null);
+ lockSoneCommand.execute(fields);
}
@Test(expected = FcpException.class)
SimpleFieldSet fields = new SimpleFieldSetBuilder().get();
LockSoneCommand lockSoneCommand = new LockSoneCommand(core);
- lockSoneCommand.execute(fields, null, null);
+ lockSoneCommand.execute(fields);
}
}
SimpleFieldSet fields = new SimpleFieldSetBuilder().put("Sone", "LocalSone").get();
UnlockSoneCommand unlockSoneCommand = new UnlockSoneCommand(core);
- Response response = unlockSoneCommand.execute(fields, null, null);
+ Response response = unlockSoneCommand.execute(fields);
verify(core).unlockSone(eq(localSone));
assertThat(response, notNullValue());
SimpleFieldSet fields = new SimpleFieldSetBuilder().put("Sone", "RemoteSone").get();
UnlockSoneCommand unlockSoneCommand = new UnlockSoneCommand(core);
- unlockSoneCommand.execute(fields, null, null);
+ unlockSoneCommand.execute(fields);
}
@Test(expected = FcpException.class)
SimpleFieldSet fields = new SimpleFieldSetBuilder().get();
UnlockSoneCommand unlockSoneCommand = new UnlockSoneCommand(core);
- unlockSoneCommand.execute(fields, null, null);
+ unlockSoneCommand.execute(fields);
}
}
whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
val post = mock<Post>().apply { whenever(id).thenReturn("PostId") }
whenever(core.createPost(localSone, absent(), "Test")).thenReturn(post)
- val response = command.execute(parameters, null, null)
+ val response = command.execute(parameters)
assertThat(response.replyParameters.get("Message"), equalTo("PostCreated"))
assertThat(response.replyParameters.get("Post"), equalTo("PostId"))
}
parameters.putSingle("Text", "Test")
parameters.putSingle("Recipient", "LocalSoneId")
whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
- val response = command.execute(parameters, null, null)
+ val response = command.execute(parameters)
assertThat(response.replyParameters["Message"], equalTo("Error"))
assertThat(response.replyParameters["ErrorMessage"], notNullValue())
}
whenever(core.getSone("RemoteSoneId")).thenReturn(of(remoteSone))
val post = mock<Post>().apply { whenever(id).thenReturn("PostId") }
whenever(core.createPost(localSone, of(remoteSone), "Test")).thenReturn(post)
- val response = command.execute(parameters, null, null)
+ val response = command.execute(parameters)
assertThat(response.replyParameters.get("Message"), equalTo("PostCreated"))
assertThat(response.replyParameters.get("Post"), equalTo("PostId"))
}
parameters.putSingle("Text", "Test")
val postReply = mock<PostReply>().apply { whenever(id).thenReturn("ReplyId") }
whenever(core.createReply(localSone, post, "Test")).thenReturn(postReply)
- val response = command.execute(parameters, null, null)
+ val response = command.execute(parameters)
assertThat(response.replyParameters["Message"], equalTo("ReplyCreated"))
assertThat(response.replyParameters["Reply"], equalTo("ReplyId"))
}
fun `request with post from remote sone returns error response`() {
parameters.putSingle("Post", "RemotePostId")
whenever(core.getPost("RemotePostId")).thenReturn(of(postFromRemoteSone))
- val response = command.execute(parameters, null, null)
+ val response = command.execute(parameters)
assertThat(response.replyParameters["Message"], equalTo("Error"))
assertThat(response.replyParameters["ErrorCode"], equalTo("401"))
}
fun `request with post from local sone deletes posts`() {
parameters.putSingle("Post", "LocalPostId")
whenever(core.getPost("LocalPostId")).thenReturn(of(postFromLocalSone))
- val response = command.execute(parameters, null, null)
+ val response = command.execute(parameters)
assertThat(response.replyParameters["Message"], equalTo("PostDeleted"))
verify(core).deletePost(postFromLocalSone)
}
fun `request with remote post reply parameter results in error response`() {
parameters.putSingle("Reply", "RemoteReplyId")
whenever(core.getPostReply("RemoteReplyId")).thenReturn(of(remotePostReply))
- val response = command.execute(parameters, null, null)
+ val response = command.execute(parameters)
assertThat(response.replyParameters["Message"], equalTo("Error"))
assertThat(response.replyParameters["ErrorCode"], equalTo("401"))
}
fun `request with local post reply parameter deletes reply`() {
parameters.putSingle("Reply", "RemoteReplyId")
whenever(core.getPostReply("RemoteReplyId")).thenReturn(of(localPostReply))
- val response = command.execute(parameters, null, null)
+ val response = command.execute(parameters)
assertThat(response.replyParameters["Message"], equalTo("ReplyDeleted"))
verify(core).deleteReply(localPostReply)
}
protected fun executeCommandAndExpectFcpException() {
expectedException.expect(FcpException::class.java)
- command.execute(parameters, null, null)
+ command.execute(parameters)
}
protected fun requestWithoutAnyParameterResultsInFcpException() {
expectedException.expect(FcpException::class.java)
- command.execute(parameters, null, null)
+ command.execute(parameters)
}
protected fun requestWithEmptySoneParameterResultsInFcpException() {