use of org.activityinfo.legacy.shared.exception.CommandException in project activityinfo by bedatadriven.
the class UserDatabasePolicy method findCountry.
private Country findCountry(PropertyMap properties) {
int countryId;
if (properties.containsKey("countryId")) {
countryId = properties.get("countryId");
} else {
// this was the default
countryId = 1;
}
Country country = countryDAO.findById(countryId);
if (country == null) {
throw new CommandException(String.format("No country exists with id %d", countryId));
}
return country;
}
use of org.activityinfo.legacy.shared.exception.CommandException in project activityinfo by bedatadriven.
the class UpdateUserPermissionsHandler method createNewUser.
private User createNewUser(User executingUser, UserPermissionDTO dto) {
if (executingUser.getId() == 0) {
throw new AssertionError("executingUser.id == 0!");
}
if (executingUser.getName() == null) {
throw new AssertionError("executingUser.name == null!");
}
User user = UserDAOImpl.createNewUser(dto.getEmail(), dto.getName(), executingUser.getLocale());
user.setInvitedBy(executingUser);
userDAO.persist(user);
try {
Message message = mailSender.createMessage(new InvitationMessage(user, executingUser));
message.replyTo(executingUser.getEmail(), executingUser.getName());
mailSender.send(message);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Could not send invitation mail", e);
throw new CommandException("Failed to send invitation email");
}
return user;
}
use of org.activityinfo.legacy.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.legacy.shared.exception.CommandException in project activityinfo by bedatadriven.
the class PivotSitesHandlerTest method execute.
private void execute(int userId) {
setUser(userId);
try {
PivotSites pivot = new PivotSites(dimensions, filter);
pivot.setValueType(valueType);
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);
}
System.out.println("\n }");
}
System.out.print("]\n");
}
use of org.activityinfo.legacy.shared.exception.CommandException in project activityinfo by bedatadriven.
the class RemoteDispatcherTest method commandExceptionsShouldBeCalledBackWithFailure.
@Test
public void commandExceptionsShouldBeCalledBackWithFailure() {
expectRemoteCall(new GetSchema());
// remote call succeeded,
andCallbackWihSuccess(new CommandException());
// command failed
replay(service);
AsyncCallback callback = makeCallbackThatExpectsFailure();
dispatcher.execute(new GetSchema(), callback);
processPendingCommands();
verify(service, callback);
}
Aggregations