use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.
the class CreateEntityHandler method execute.
@Override
public CommandResult execute(CreateEntity cmd, User user) throws CommandException {
Map<String, Object> properties = cmd.getProperties().getTransientMap();
PropertyMap propertyMap = new PropertyMap(cmd.getProperties().getTransientMap());
if ("UserDatabase".equals(cmd.getEntityName())) {
UserDatabasePolicy policy = injector.getInstance(UserDatabasePolicy.class);
return new CreateResult((Integer) policy.create(user, propertyMap));
} else if ("Activity".equals(cmd.getEntityName())) {
ActivityPolicy policy = injector.getInstance(ActivityPolicy.class);
return new CreateResult((Integer) policy.create(user, propertyMap));
} else if ("AttributeGroup".equals(cmd.getEntityName())) {
return createAttributeGroup(cmd, properties);
} else if ("Attribute".equals(cmd.getEntityName())) {
return createAttribute(cmd, properties);
} else if ("Indicator".equals(cmd.getEntityName())) {
return createIndicator(user, cmd, properties);
} else {
throw new CommandException("Invalid entity class " + cmd.getEntityName());
}
}
use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.
the class RenderReportHtmlHandler method execute.
@Override
@LogException
public CommandResult execute(RenderReportHtml cmd, User user) throws CommandException {
ReportElement model = cmd.getModel();
LOGGER.fine("Model: " + model);
// don't show the title: it will be rendered by the container
model.setTitle(null);
generator.generateElement(user, model, new Filter(), new DateRange());
StringWriter writer = new StringWriter();
try {
renderer.render(model, writer);
} catch (IOException e) {
throw new CommandException(e);
}
return new HtmlResult(writer.toString());
}
use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.
the class UpdateMonthlyReportsHandler method execute.
@Override
public CommandResult execute(UpdateMonthlyReports cmd, User user) throws CommandException {
Site site = em.find(Site.class, cmd.getSiteId());
if (site == null) {
throw new CommandException(cmd, "site " + cmd.getSiteId() + " not found for user " + user.getEmail());
}
Map<Month, ReportingPeriod> periods = Maps.newHashMap();
Map<String, Object> siteHistoryChangeMap = createChangeMap();
for (ReportingPeriod period : site.getReportingPeriods()) {
periods.put(HandlerUtil.monthFromRange(period.getDate1(), period.getDate2()), period);
}
for (UpdateMonthlyReports.Change change : cmd.getChanges()) {
ReportingPeriod period = periods.get(change.getMonth());
if (period == null) {
period = new ReportingPeriod(site);
period.setId(keyGenerator.generateInt());
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, change.getMonth().getYear());
calendar.set(Calendar.MONTH, change.getMonth().getMonth() - 1);
calendar.set(Calendar.DATE, 1);
period.setDate1(calendar.getTime());
calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
period.setDate2(calendar.getTime());
em.persist(period);
periods.put(change.getMonth(), period);
}
updateIndicatorValue(em, period, change.getIndicatorId(), change.getValue(), false);
siteHistoryChangeMap.put(IndicatorDTO.getPropertyName(change.getIndicatorId(), change.getMonth()), change.getValue());
}
siteHistoryProcessor.persistHistory(site, user, ChangeType.UPDATE, siteHistoryChangeMap);
return new VoidResult();
}
use of org.activityinfo.shared.exception.CommandException in project activityinfo by bedatadriven.
the class KmlDataServlet method doGet.
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
res.getWriter();
int activityId = Integer.valueOf(req.getParameter("activityId"));
// Get Authorization header
String auth = req.getHeader("Authorization");
// Do we allow that user?
User user = authenticator.doAuthentication(auth);
if (user == null) {
// Not allowed, or no password provided so report unauthorized
res.setHeader("WWW-Authenticate", "BASIC realm=\"Utilisateurs authorises\"");
res.sendError(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
res.setContentType("application/vnd.google-earth.kml+xml");
try {
writeDocument(user, res.getWriter(), activityId);
} catch (TransformerConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (CommandException e) {
e.printStackTrace();
}
}
use of org.activityinfo.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