use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.
the class DimensionTree method onModelChanged.
private void onModelChanged() {
if (needToReloadDimensions(model)) {
clearIndicatorSpecificDimensions();
dispatcher.execute(new GetSchema(), new MaskingAsyncMonitor(treePanel, I18N.CONSTANTS.loading()), new AsyncCallback<SchemaDTO>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(SchemaDTO result) {
populateIndicatorSpecificDimensions(result);
applyModelState(result);
}
});
}
}
use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.
the class ExportSitesServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Set<Integer> activities = new HashSet<Integer>();
if (req.getParameterValues("a") != null) {
for (String activity : req.getParameterValues("a")) {
activities.add(Integer.parseInt(activity));
}
}
Filter filter = FilterUrlSerializer.fromQueryParameter(req.getParameter("filter"));
SchemaDTO schema = dispatcher.execute(new GetSchema());
SiteExporter export = new SiteExporter(dispatcher);
for (UserDatabaseDTO db : schema.getDatabases()) {
for (ActivityDTO activity : db.getActivities()) {
if (!filter.isRestricted(DimensionType.Activity) || filter.getRestrictions(DimensionType.Activity).contains(activity.getId())) {
export.export(activity, filter);
}
}
}
export.done();
resp.setContentType("application/vnd.ms-excel");
if (req.getHeader("User-Agent").indexOf("MSIE") != -1) {
resp.addHeader("Content-Disposition", "attachment; filename=ActivityInfo.xls");
} else {
resp.addHeader("Content-Disposition", "attachment; filename=" + ("ActivityInfo Export " + new Date().toString() + ".xls").replace(" ", "_"));
}
OutputStream os = resp.getOutputStream();
export.getBook().write(os);
}
use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.
the class SiteChangeServlet method sendNotifications.
@VisibleForTesting
void sendNotifications(int editorUserId, int siteId, ChangeType type) {
User user = entityManager.get().find(User.class, editorUserId);
/*
* For our purposes, the user who initiated the change will be
* considered the authenticated user for this thread
*/
authProvider.set(user);
SiteResult siteResult = dispatcher.execute(GetSites.byId(siteId));
SiteDTO siteDTO = siteResult.getData().get(0);
SchemaDTO schemaDTO = dispatcher.execute(new GetSchema());
ActivityDTO activityDTO = schemaDTO.getActivityById(siteDTO.getActivityId());
UserDatabaseDTO userDatabaseDTO = activityDTO.getDatabase();
Date date = new Date();
List<User> recipients = findRecipients(userDatabaseDTO.getId());
for (User recipient : recipients) {
try {
// themselves!
if (recipient.getId() != editorUserId) {
LOGGER.info("sending sitechange notification email to " + recipient.getEmail());
UpdateMessageBuilder message = new UpdateMessageBuilder();
message.setDate(date);
message.setEditor(user);
message.setRecipient(recipient);
message.setUserDatabaseDTO(userDatabaseDTO);
message.setSiteDTO(siteDTO);
message.setActivityDTO(activityDTO);
message.setChangeType(type);
mailSender.get().send(message.build());
}
} catch (Throwable t) {
LOGGER.warning("failed sending notification email to " + recipient.getName() + " <" + recipient.getEmail() + ">: " + t.getMessage());
t.printStackTrace();
}
}
}
use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.
the class RemoteDispatcherTest method commandShouldBeSentToServerIfThereAreNoProxiesAndNoPendingCommands.
@Test
public void commandShouldBeSentToServerIfThereAreNoProxiesAndNoPendingCommands() {
// define our expectations
expectRemoteCall(new GetSchema());
replay(service);
// trigger a call
dispatcher.execute(new GetSchema(), makeNullCallback());
processPendingCommands();
// verify that the command was dispatched to the server
verify(service);
}
use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.
the class RemoteDispatcherTest method commandsUnsuccessfullyExecutedThroughProxiesShouldBeSentToServer.
@Test
public void commandsUnsuccessfullyExecutedThroughProxiesShouldBeSentToServer() {
GetSchema command = new GetSchema();
expect(proxy.maybeExecute(eq(command))).andReturn(CacheResult.couldNotExecute());
replay(proxy);
expectRemoteCall(command);
andCallbackWihSuccess(new SchemaDTO());
replay(service);
AsyncCallback callback = makeCallbackThatExpectsNonNullSuccess();
proxyManager.registerProxy(GetSchema.class, proxy);
dispatcher.execute(new GetSchema(), callback);
processPendingCommands();
verify(proxy, service, callback);
}
Aggregations