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