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;
}
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);
}
}
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);
}
}
Aggregations