Search in sources :

Example 6 with CommandException

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

Example 7 with CommandException

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

Example 8 with CommandException

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

Example 9 with CommandException

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");
}
Also used : Bucket(org.activityinfo.legacy.shared.command.result.Bucket) CommandException(org.activityinfo.legacy.shared.exception.CommandException)

Example 10 with CommandException

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);
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) CommandException(org.activityinfo.legacy.shared.exception.CommandException) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) Test(org.junit.Test)

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