Search in sources :

Example 16 with CommandException

use of org.activityinfo.legacy.shared.exception.CommandException in project activityinfo by bedatadriven.

the class GetSitesHandler method execute.

@Override
public SiteResult execute(GetSites cmd, User user) {
    if (useLegacyMethod(cmd, user)) {
        return dispatcher.execute(new OldGetSites(cmd));
    }
    LOGGER.info("Entering execute()");
    aggregateTime.start();
    try {
        initialiseHandler(cmd, user);
        fetchActivityMetadata(cmd.getFilter());
        queryFormTrees();
        constructActivityLinks();
        buildQueries();
        batchQueries();
        executeBatch();
        mergeMonthlyRootSites();
        setSitesLinkedStatus();
        sort();
    } catch (CommandException excp) {
        // old method at any point of execution and elongate the return time
        return dispatcher.execute(new OldGetSites(cmd));
    }
    aggregateTime.stop();
    printTimes();
    SiteResult result = new SiteResult(siteList);
    result.setOffset(cmd.getOffset());
    result.setTotalLength(totalResultLength);
    LOGGER.info("Exiting execute()");
    return result;
}
Also used : OldGetSites(org.activityinfo.legacy.shared.command.OldGetSites) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) CommandException(org.activityinfo.legacy.shared.exception.CommandException)

Example 17 with CommandException

use of org.activityinfo.legacy.shared.exception.CommandException in project activityinfo by bedatadriven.

the class GetSyncRegionUpdatesHandler method execute.

@Override
public CommandResult execute(GetSyncRegionUpdates cmd, User user) throws CommandException {
    Log.info("Fetching updates for " + cmd.getRegionPath() + ", localVersion = " + cmd.getLocalVersion());
    UpdateBuilder builder;
    if (cmd.getRegionType().equals(DbUpdateBuilder.REGION_TYPE)) {
        builder = injector.getInstance(DbUpdateBuilder.class);
    } else if (cmd.getRegionType().equals(AdminUpdateBuilder.REGION_TYPE)) {
        builder = injector.getInstance(AdminUpdateBuilder.class);
    } else if (cmd.getRegionType().equals(LocationUpdateBuilder.REGION_TYPE)) {
        builder = injector.getInstance(LocationUpdateBuilder.class);
    } else if (cmd.getRegionType().equals(SiteUpdateBuilder.REGION_TYPE)) {
        builder = injector.getInstance(SiteUpdateBuilder.class);
    } else if (cmd.getRegionType().equals(TableDefinitionUpdateBuilder.REGION_TYPE)) {
        builder = injector.getInstance(TableDefinitionUpdateBuilder.class);
    } else if (cmd.getRegionType().equals(CountryUpdateBuilder.REGION_TYPE)) {
        builder = injector.getInstance(CountryUpdateBuilder.class);
    } else {
        throw new CommandException("Unknown sync region: " + cmd.getRegionPath());
    }
    TraceContext traceContext = Trace.startSpan("/ai/cmd/sync/" + prefix(cmd.getRegionPath()));
    try {
        return builder.build(user, cmd);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
        throw new RuntimeException(e);
    } finally {
        Trace.endSpan(traceContext);
    }
}
Also used : TraceContext(com.google.cloud.trace.core.TraceContext) CommandException(org.activityinfo.legacy.shared.exception.CommandException) CommandException(org.activityinfo.legacy.shared.exception.CommandException)

Example 18 with CommandException

use of org.activityinfo.legacy.shared.exception.CommandException in project activityinfo by bedatadriven.

the class CommandServlet method handleCommand.

protected CommandResult handleCommand(Command command) throws CommandException {
    RemoteExecutionContext context = null;
    try {
        context = new RemoteExecutionContext(injector);
        CommandResult result = context.startExecute(command);
        if (result instanceof CommandException) {
            LOGGER.log(Level.SEVERE, "Exception executing " + command.getClass().getSimpleName(), (CommandException) result);
        }
        return result;
    } catch (CommandException e) {
        throw e;
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Exception executing " + command.getClass().getSimpleName(), e);
        throw new CommandException(command, context, e);
    }
}
Also used : CommandException(org.activityinfo.legacy.shared.exception.CommandException) InvalidAuthTokenException(org.activityinfo.legacy.shared.exception.InvalidAuthTokenException) CommandException(org.activityinfo.legacy.shared.exception.CommandException) CommandResult(org.activityinfo.legacy.shared.command.result.CommandResult)

Aggregations

CommandException (org.activityinfo.legacy.shared.exception.CommandException)18 TraceContext (com.google.cloud.trace.core.TraceContext)3 Filter (org.activityinfo.legacy.shared.command.Filter)3 IllegalAccessCommandException (org.activityinfo.legacy.shared.exception.IllegalAccessCommandException)3 SQLException (java.sql.SQLException)2 Date (java.util.Date)2 CommandResult (org.activityinfo.legacy.shared.command.result.CommandResult)2 DateRange (org.activityinfo.legacy.shared.reports.model.DateRange)2 PropertyMap (org.activityinfo.server.command.handler.crud.PropertyMap)2 User (org.activityinfo.server.database.hibernate.entity.User)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 StringWriter (java.io.StringWriter)1 Calendar (java.util.Calendar)1 CreateLocation (org.activityinfo.legacy.shared.command.CreateLocation)1 CreateLockedPeriod (org.activityinfo.legacy.shared.command.CreateLockedPeriod)1 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)1 OldGetSites (org.activityinfo.legacy.shared.command.OldGetSites)1 UpdateMonthlyReports (org.activityinfo.legacy.shared.command.UpdateMonthlyReports)1