use of org.activityinfo.shared.exception.CommandException 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.exception.CommandException in project activityinfo by bedatadriven.
the class PivotSitesHandlerTest method execute.
private void execute() {
setUser(OWNER_USER_ID);
try {
PivotSites pivot = new PivotSites(dimensions, filter);
pivot.setValueType(valueType);
pivot.setPointRequested(pointsRequested);
buckets = execute(pivot).getBuckets();
} catch (CommandException e) {
throw new RuntimeException(e);
}
System.out.println("Buckets = [");
for (Bucket bucket : buckets) {
System.out.print(" { Value: " + bucket.doubleValue());
for (Dimension dim : bucket.dimensions()) {
DimensionCategory cat = bucket.getCategory(dim);
System.out.print("\n " + dim.toString() + ": ");
System.out.print(cat.toString());
}
System.out.println("\n }");
}
System.out.print("]\n");
}
use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.
the class PivotSitesHandlerLocalTest method execute.
private void execute() {
setUser(OWNER_USER_ID);
try {
PivotSites pivot = new PivotSites(dimensions, filter);
pivot.setValueType(valueType);
buckets = executeLocally(pivot).getBuckets();
} catch (CommandException e) {
throw new RuntimeException(e);
}
System.out.println("Buckets = [");
for (Bucket bucket : buckets) {
System.out.print(bucket.toString());
}
System.out.print("]\n");
}
use of org.activityinfo.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.getRegionId() + ", localVersion = " + cmd.getLocalVersion());
UpdateBuilder builder;
if (cmd.getRegionId().equals("schema")) {
builder = injector.getInstance(SchemaUpdateBuilder.class);
} else if (cmd.getRegionId().startsWith("admin/")) {
builder = injector.getInstance(AdminUpdateBuilder.class);
} else if (cmd.getRegionId().startsWith("location/")) {
builder = injector.getInstance(LocationUpdateBuilder.class);
} else if (cmd.getRegionId().startsWith("site/")) {
builder = injector.getInstance(SiteUpdateBuilder.class);
} else if (cmd.getRegionId().equals("site-tables")) {
builder = injector.getInstance(SiteTableUpdateBuilder.class);
} else {
throw new CommandException("Unknown sync region: " + cmd.getRegionId());
}
try {
return builder.build(user, cmd);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.
the class CreateLockedPeriodHandler method execute.
@Override
public CommandResult execute(CreateLockedPeriod cmd, User user) throws CommandException {
Activity activity = null;
UserDatabase database = null;
Project project = null;
LockedPeriod lockedPeriod = new LockedPeriod();
LockedPeriodDTO lockedPeriodDTO = cmd.getLockedPeriod();
lockedPeriod.setFromDate(lockedPeriodDTO.getFromDate().atMidnightInMyTimezone());
lockedPeriod.setToDate(lockedPeriodDTO.getToDate().atMidnightInMyTimezone());
lockedPeriod.setName(lockedPeriodDTO.getName());
lockedPeriod.setEnabled(lockedPeriodDTO.isEnabled());
int databaseId;
if (cmd.getUserDatabseId() != 0) {
database = em.find(UserDatabase.class, cmd.getUserDatabseId());
lockedPeriod.setUserDatabase(database);
databaseId = database.getId();
} else if (cmd.getProjectId() != 0) {
project = em.find(Project.class, cmd.getProjectId());
lockedPeriod.setProject(project);
databaseId = project.getUserDatabase().getId();
} else if (cmd.getActivityId() != 0) {
activity = em.find(Activity.class, cmd.getActivityId());
lockedPeriod.setActivity(activity);
databaseId = activity.getDatabase().getId();
} else {
throw new CommandException("One of the following must be provdied: userDatabaseId, projectId, activityId");
}
UserDatabase db = em.find(UserDatabase.class, databaseId);
em.persist(lockedPeriod);
db.setLastSchemaUpdate(new Date());
em.persist(db);
if (database != null) {
database.getLockedPeriods().add(lockedPeriod);
}
if (project != null) {
project.getLockedPeriods().add(lockedPeriod);
}
if (activity != null) {
activity.getLockedPeriods().add(lockedPeriod);
}
return new CreateResult(lockedPeriod.getId());
}
Aggregations