Search in sources :

Example 11 with CommandException

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

the class UpdateUserPermissionsHandler method createNewUser.

private User createNewUser(User executingUser, UserPermissionDTO dto, String host) throws CommandException {
    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.shared.exception.IllegalAccessCommandException) CommandException(org.activityinfo.shared.exception.CommandException) IllegalAccessCommandException(org.activityinfo.shared.exception.IllegalAccessCommandException) CommandException(org.activityinfo.shared.exception.CommandException)

Example 12 with CommandException

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

the class RenderElementHandler method execute.

@Override
public CommandResult execute(RenderElement cmd, User user) throws CommandException {
    try {
        Renderer renderer = rendererFactory.get(cmd.getFormat());
        TempStorage storage = storageProvider.allocateTemporaryFile(renderer.getMimeType(), cmd.getFilename() + renderer.getFileSuffix());
        LOGGER.fine("Rendering element: " + cmd + "\nURL: " + storage.getUrl());
        try {
            generator.generateElement(user, cmd.getElement(), new Filter(), new DateRange());
            renderer.render(cmd.getElement(), storage.getOutputStream());
        } finally {
            try {
                storage.getOutputStream().close();
            } catch (Exception e) {
                LOGGER.log(Level.WARNING, "Exception while closing storage: " + e.getMessage(), e);
            }
        }
        return new UrlResult(storage.getUrl());
    } catch (Exception e) {
        throw new RuntimeException("Exception generating export", e);
    }
}
Also used : DateRange(org.activityinfo.shared.report.model.DateRange) TempStorage(org.activityinfo.server.report.output.TempStorage) Filter(org.activityinfo.shared.command.Filter) Renderer(org.activityinfo.server.report.renderer.Renderer) CommandException(org.activityinfo.shared.exception.CommandException) UrlResult(org.activityinfo.shared.command.result.UrlResult)

Example 13 with CommandException

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

the class UpdateTargetValueHandler method execute.

@Override
public CommandResult execute(UpdateTargetValue cmd, User user) throws CommandException {
    LOG.fine("[execute] Update command for entity: TargetValue");
    Map<String, Object> changes = cmd.getChanges().getTransientMap();
    new PropertyMap(changes);
    try {
        TargetValue targetValue = entityManager().find(TargetValue.class, new TargetValueId(cmd.getTargetId(), cmd.getIndicatorId()));
        if (cmd.getChanges().get("value") != null) {
            targetValue.setValue((Double.valueOf((String) cmd.getChanges().get("value"))));
            entityManager().persist(targetValue);
            return new VoidResult();
        }
        entityManager().remove(targetValue);
        return new VoidResult();
    } catch (Exception e) {
    // ignore
    }
    Target target = entityManager().find(Target.class, cmd.getTargetId());
    Indicator indicator = entityManager().find(Indicator.class, cmd.getIndicatorId());
    TargetValue targetValue = new TargetValue();
    targetValue.setId(new TargetValueId(cmd.getTargetId(), cmd.getIndicatorId()));
    targetValue.setValue((Double.valueOf((String) cmd.getChanges().get("value"))));
    targetValue.setTarget(target);
    targetValue.setIndicator(indicator);
    entityManager().persist(targetValue);
    return new VoidResult();
}
Also used : TargetValue(org.activityinfo.server.database.hibernate.entity.TargetValue) UpdateTargetValue(org.activityinfo.shared.command.UpdateTargetValue) Target(org.activityinfo.server.database.hibernate.entity.Target) PropertyMap(org.activityinfo.server.command.handler.crud.PropertyMap) VoidResult(org.activityinfo.shared.command.result.VoidResult) TargetValueId(org.activityinfo.server.database.hibernate.entity.TargetValueId) CommandException(org.activityinfo.shared.exception.CommandException) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator)

Example 14 with CommandException

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

the class CommandServlet method handleCommands.

/**
 * Publicly visible for testing *
 */
@LogException
public List<CommandResult> handleCommands(List<Command> commands) {
    applyUserFilters();
    List<CommandResult> results = new ArrayList<CommandResult>();
    for (Command command : commands) {
        LOGGER.log(Level.INFO, authProvider.get().getEmail() + ": " + command.getClass().getSimpleName());
        try {
            results.add(handleCommand(command));
        } catch (CommandException e) {
            results.add(e);
        }
    }
    return results;
}
Also used : Command(org.activityinfo.shared.command.Command) ArrayList(java.util.ArrayList) CommandException(org.activityinfo.shared.exception.CommandException) CommandResult(org.activityinfo.shared.command.result.CommandResult) LogException(org.activityinfo.server.util.logging.LogException)

Example 15 with CommandException

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

the class CommandServlet method handleCommand.

@LogException(emailAlert = true)
protected CommandResult handleCommand(Command command) throws CommandException {
    RemoteExecutionContext context = null;
    try {
        long timeStart = System.currentTimeMillis();
        context = new RemoteExecutionContext(injector);
        CommandResult result = context.startExecute(command);
        long timeElapsed = System.currentTimeMillis() - timeStart;
        if (timeElapsed > 1000) {
            LOGGER.warning("Command " + command.toString() + " completed in " + timeElapsed + "ms");
        }
        return result;
    } catch (Exception e) {
        throw new CommandException(command, context, e);
    }
}
Also used : CommandException(org.activityinfo.shared.exception.CommandException) LogException(org.activityinfo.server.util.logging.LogException) InvalidAuthTokenException(org.activityinfo.shared.exception.InvalidAuthTokenException) CommandException(org.activityinfo.shared.exception.CommandException) CommandResult(org.activityinfo.shared.command.result.CommandResult) LogException(org.activityinfo.server.util.logging.LogException)

Aggregations

CommandException (org.activityinfo.shared.exception.CommandException)15 User (org.activityinfo.server.database.hibernate.entity.User)3 LogException (org.activityinfo.server.util.logging.LogException)3 CommandResult (org.activityinfo.shared.command.result.CommandResult)3 PropertyMap (org.activityinfo.server.command.handler.crud.PropertyMap)2 Filter (org.activityinfo.shared.command.Filter)2 Bucket (org.activityinfo.shared.command.result.Bucket)2 CreateResult (org.activityinfo.shared.command.result.CreateResult)2 VoidResult (org.activityinfo.shared.command.result.VoidResult)2 IllegalAccessCommandException (org.activityinfo.shared.exception.IllegalAccessCommandException)2 DateRange (org.activityinfo.shared.report.model.DateRange)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 ActivityPolicy (org.activityinfo.server.command.handler.crud.ActivityPolicy)1 UserDatabasePolicy (org.activityinfo.server.command.handler.crud.UserDatabasePolicy)1