Search in sources :

Example 6 with CommandResult

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;
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) CommandException(org.activityinfo.shared.exception.CommandException) CommandResult(org.activityinfo.shared.command.result.CommandResult)

Example 7 with CommandResult

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;
}
Also used : Command(org.activityinfo.shared.command.Command) ArrayList(java.util.ArrayList) CommandException(org.activityinfo.shared.exception.CommandException) CommandResult(org.activityinfo.shared.command.result.CommandResult) LogException(org.activityinfo.server.util.logging.LogException)

Example 8 with CommandResult

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);
    }
}
Also used : CommandException(org.activityinfo.shared.exception.CommandException) LogException(org.activityinfo.server.util.logging.LogException) InvalidAuthTokenException(org.activityinfo.shared.exception.InvalidAuthTokenException) CommandException(org.activityinfo.shared.exception.CommandException) CommandResult(org.activityinfo.shared.command.result.CommandResult) LogException(org.activityinfo.server.util.logging.LogException)

Aggregations

CommandResult (org.activityinfo.shared.command.result.CommandResult)8 Command (org.activityinfo.shared.command.Command)5 ArrayList (java.util.ArrayList)4 CommandException (org.activityinfo.shared.exception.CommandException)3 LogException (org.activityinfo.server.util.logging.LogException)2 BatchCommand (org.activityinfo.shared.command.BatchCommand)2 BatchResult (org.activityinfo.shared.command.result.BatchResult)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 User (org.activityinfo.server.database.hibernate.entity.User)1 GetSchema (org.activityinfo.shared.command.GetSchema)1 InvalidAuthTokenException (org.activityinfo.shared.exception.InvalidAuthTokenException)1