use of org.activityinfo.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.shared.command.result.CommandResult in project activityinfo by bedatadriven.
the class CommandServlet method handleCommands.
/**
* Publicly visible for testing *
*/
@LogException
public List<CommandResult> handleCommands(List<Command> commands) {
applyUserFilters();
List<CommandResult> results = new ArrayList<CommandResult>();
for (Command command : commands) {
LOGGER.log(Level.INFO, authProvider.get().getEmail() + ": " + command.getClass().getSimpleName());
try {
results.add(handleCommand(command));
} catch (CommandException e) {
results.add(e);
}
}
return results;
}
use of org.activityinfo.shared.command.result.CommandResult in project activityinfo by bedatadriven.
the class CommandServlet method handleCommand.
@LogException(emailAlert = true)
protected CommandResult handleCommand(Command command) throws CommandException {
RemoteExecutionContext context = null;
try {
long timeStart = System.currentTimeMillis();
context = new RemoteExecutionContext(injector);
CommandResult result = context.startExecute(command);
long timeElapsed = System.currentTimeMillis() - timeStart;
if (timeElapsed > 1000) {
LOGGER.warning("Command " + command.toString() + " completed in " + timeElapsed + "ms");
}
return result;
} catch (Exception e) {
throw new CommandException(command, context, e);
}
}
Aggregations