use of org.activityinfo.legacy.shared.command.result.VoidResult in project activityinfo by bedatadriven.
the class ReportGridPanel method onDashboardClicked.
private void onDashboardClicked(final ReportMetadataDTO model) {
model.setDashboard(!model.isDashboard());
store.update(model);
UpdateReportSubscription update = new UpdateReportSubscription();
update.setReportId(model.getId());
update.setPinnedToDashboard(model.isDashboard());
dispatcher.execute(update, new AsyncCallback<VoidResult>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
@Override
public void onSuccess(VoidResult result) {
Info.displayText(I18N.CONSTANTS.saved(), model.isDashboard() ? I18N.MESSAGES.addedToDashboard(model.getTitle()) : I18N.MESSAGES.removedFromDashboard(model.getTitle()));
}
});
}
use of org.activityinfo.legacy.shared.command.result.VoidResult in project activityinfo by bedatadriven.
the class EmailDialog method onButtonPressed.
@Override
protected void onButtonPressed(Button button) {
if (button.getItemId().equals(OK)) {
final UpdateReportSubscription update = new UpdateReportSubscription();
update.setReportId(reportMetadata.getId());
if (weekly.getValue()) {
update.setEmailDelivery(EmailDelivery.WEEKLY);
update.setEmailDay(dayOfWeek.getMappedValue());
} else if (monthly.getValue()) {
update.setEmailDelivery(EmailDelivery.MONTHLY);
update.setEmailDay(dayOfMonth.getMappedValue());
} else {
update.setEmailDelivery(EmailDelivery.NONE);
}
dispatcher.execute(update, new MaskingAsyncMonitor(this, I18N.CONSTANTS.saving()), new AsyncCallback<VoidResult>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(VoidResult result) {
hide();
reportMetadata.setEmailDelivery(update.getEmailDelivery());
reportMetadata.setDay(update.getEmailDay());
callback.onUpdated();
}
});
} else if (button.getItemId().equals(CANCEL)) {
hide();
}
}
use of org.activityinfo.legacy.shared.command.result.VoidResult in project activityinfo by bedatadriven.
the class CreateSiteAttachmentHandler method execute.
@Override
public void execute(CreateSiteAttachment command, ExecutionContext context, AsyncCallback<VoidResult> callback) {
SqlInsert.insertInto("siteattachment").value("siteid", command.getSiteId()).value("blobid", command.getBlobId()).value("filename", command.getFileName()).value("uploadedby", context.getUser().getUserId()).value("blobsize", command.getBlobSize()).value("contenttype", command.getContentType()).execute(context.getTransaction());
callback.onSuccess(new VoidResult());
}
use of org.activityinfo.legacy.shared.command.result.VoidResult in project activityinfo by bedatadriven.
the class RequestChangeHandler method execute.
@Override
public CommandResult execute(RequestChange cmd, User user) throws CommandException {
ChangeRequestBuilder request = new ChangeRequestBuilder().setChangeType(ChangeType.valueOf(cmd.getChangeType())).setEntityId(cmd.getEntityId()).setEntityType(cmd.getEntityType()).setUser(user);
if (cmd.getPropertyMap() != null) {
request.setProperties(cmd.getPropertyMap().getTransientMap());
}
changeHandler.execute(request);
return new VoidResult();
}
use of org.activityinfo.legacy.shared.command.result.VoidResult in project activityinfo by bedatadriven.
the class UpdateMonthlyReportsHandler method execute.
@Override
public CommandResult execute(UpdateMonthlyReports cmd, User user) throws CommandException {
// Phantom Row issue occurs when attempting to update Monthly ReportingPeriods concurrently.
// To prevent this, we introduce a locking mechanism to prevent simultaneous insertions into table which result
// in duplicate reporting periods on the given site.
// Once we have acquired a lock, we can then safely execute the command
acquireLock(cmd.getSiteId());
try {
Site site = em.find(Site.class, cmd.getSiteId());
if (site == null) {
throw new CommandException(cmd, "site " + cmd.getSiteId() + " not found for user " + user.getEmail());
}
if (!permissionOracle.isEditAllowed(site, user)) {
throw new IllegalAccessCommandException("Not authorized to modify sites");
}
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()) {
if (!periods.containsKey(change.getMonth())) {
ReportingPeriod 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);
}
}
for (UpdateMonthlyReports.Change change : cmd.getChanges()) {
updateIndicatorValue(em, periods.get(change.getMonth()), change.getIndicatorId(), change.getValue(), false);
siteHistoryChangeMap.put(getPropertyName(change.getIndicatorId(), change.getMonth()), change.getValue());
}
// update the timestamp on the site entity so changes get picked up
// by the synchro mechanism
site.setVersion(site.getActivity().incrementSiteVersion());
siteHistoryProcessor.persistHistory(site, user, ChangeType.UPDATE, siteHistoryChangeMap);
} finally {
releaseLock(cmd.getSiteId());
}
return new VoidResult();
}
Aggregations