use of org.activityinfo.legacy.shared.command.result.CommandResult in project activityinfo by bedatadriven.
the class BatchCommandHandlerAsync method execute.
@Override
public void execute(BatchCommand batch, ExecutionContext context, final AsyncCallback<BatchResult> callback) {
if (batch.getCommands().isEmpty()) {
LOGGER.warning("Received empty batch command");
callback.onSuccess(new BatchResult(Lists.<CommandResult>newArrayList()));
} else {
final ArrayList<CommandResult> results = new ArrayList<>();
for (Command command : batch.getCommands()) {
results.add(null);
}
final boolean[] finished = new boolean[batch.getCommands().size()];
final List<Throwable> exceptions = Lists.newArrayList();
for (int i = 0; i != batch.getCommands().size(); ++i) {
final int commandIndex = i;
context.execute(batch.getCommands().get(i), new AsyncCallback<CommandResult>() {
@Override
public void onFailure(Throwable caught) {
if (exceptions.isEmpty()) {
exceptions.add(caught);
callback.onFailure(caught);
}
}
@Override
public void onSuccess(CommandResult result) {
results.set(commandIndex, result);
finished[commandIndex] = true;
if (all(finished)) {
callback.onSuccess(new BatchResult(results));
}
}
});
}
}
}
use of org.activityinfo.legacy.shared.command.result.CommandResult in project activityinfo by bedatadriven.
the class JsonRpcServlet method execute.
@POST
public Response execute(String json) {
// All RPC Commands require authentication
if (user.get().isAnonymous()) {
return Response.status(Response.Status.UNAUTHORIZED).build();
}
Command command = deserialize(json);
CommandResult result = execute(command);
return serializeResult(result);
}
use of org.activityinfo.legacy.shared.command.result.CommandResult in project activityinfo by bedatadriven.
the class CommandTestCase method execute.
protected <T extends CommandResult> T execute(Command<T> command) throws CommandException {
User user = em.find(User.class, AuthenticationModuleStub.getCurrentUser().getUserId());
assert user != null : "cannot find user id " + AuthenticationModuleStub.getCurrentUser().getUserId() + " in the database, have you " + " called execute() without a @OnDataset annotation?";
Locale.setDefault(Locale.ENGLISH);
List<CommandResult> results = servlet.handleCommands(Collections.<Command>singletonList(command));
// normally each request and so each handleCommand() gets its own
// EntityManager, but here successive requests in the same test
// will share an EntityManager, which can be bad if there are
// collections
// still living in the first-level cache
//
// I think these command tests should ultimately become real end-to-end
// tests and so would go through the actual servlet process, but for the
// moment,
// we'll just add this work aroudn that clears the cache after each
// command.
em.clear();
CommandResult result = results.get(0);
if (result instanceof CommandException) {
throw (CommandException) result;
}
return (T) result;
}
use of org.activityinfo.legacy.shared.command.result.CommandResult in project activityinfo by bedatadriven.
the class DispatcherStub method execute.
@Override
public <T extends CommandResult> void execute(Command<T> command, AsyncCallback<T> callback) {
if (command instanceof BatchCommand) {
BatchCommand batch = (BatchCommand) command;
List<CommandResult> results = new ArrayList<CommandResult>();
for (Command batchCmd : batch.getCommands()) {
results.add(findResult(batchCmd));
}
callback.onSuccess((T) new BatchResult(results));
} else {
callback.onSuccess((T) findResult(command));
}
}
use of org.activityinfo.legacy.shared.command.result.CommandResult in project activityinfo by bedatadriven.
the class MockRemoteCommandService method execute.
@Override
public void execute(String authToken, String locale, List<Command> cmds, AsyncCallback<List<CommandResult>> callback) {
List<CommandResult> results = new ArrayList<CommandResult>();
for (Command cmd : cmds) {
Integer count = commandCounts.get(cmd.getClass());
commandCounts.put(cmd.getClass(), count == null ? 1 : count + 1);
if (schema != null && cmd instanceof GetSchema) {
results.add(schema);
} else {
results.add(mockExecute(cmd));
}
}
callback.onSuccess(results);
}
Aggregations