use of org.activityinfo.shared.command.result.VoidResult in project activityinfo by bedatadriven.
the class DeleteSiteAttachmentHandler method execute.
@Override
public void execute(DeleteSiteAttachment command, ExecutionContext context, AsyncCallback<VoidResult> callback) {
attachmentService.delete(command.getBlobId());
SqlUpdate.delete(Tables.SITE_ATTACHMENT).where("blobid", command.getBlobId()).execute(context.getTransaction());
callback.onSuccess(new VoidResult());
}
use of org.activityinfo.shared.command.result.VoidResult 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.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.shared.command.result.VoidResult in project activityinfo by bedatadriven.
the class UpdateUserProfileHandler method execute.
@Override
public void execute(final UpdateUserProfile command, ExecutionContext context, final AsyncCallback<VoidResult> callback) {
UserProfileDTO model = command.getModel();
SqlUpdate.update("userlogin").where("userId", model.getUserId()).value("name", model.getName()).value("organization", model.getOrganization()).value("jobtitle", model.getJobtitle()).value("emailNotification", model.isEmailNotification()).execute(context.getTransaction());
callback.onSuccess(new VoidResult());
}
use of org.activityinfo.shared.command.result.VoidResult in project activityinfo by bedatadriven.
the class DesignTest method testSaveOnNavigateAway.
@Test
public void testSaveOnNavigateAway() {
// Dummy Data
SchemaDTO schema = DTOs.pear();
// Collaborator
MockEventBus eventBus = new MockEventBus();
// Collaborator
DispatcherStub service = new DispatcherStub();
service.setResult(GetSchema.class, schema);
service.setResult(UpdateEntity.class, new VoidResult());
// Collaborator
DesignPresenter.View view = createNiceMock(DesignPresenter.View.class);
replay(view);
// Collaborator
UIConstants constants = createNiceMock(UIConstants.class);
replay(constants);
DesignPresenter designer = new DesignPresenter(eventBus, service, new StateManagerStub(), view, constants);
designer.go(schema.getDatabaseById(1));
// Verify that following a change to the record, a save call
// triggers an update command
ActivityDTO activity = (ActivityDTO) ((TreeStore) designer.getStore()).getRootItems().get(0);
Record record = designer.getStore().getRecord(activity);
record.set("name", "New Name");
designer.requestToNavigateAway(new DataEntryPlace(), new NavigationCallback() {
@Override
public void onDecided(boolean allowed) {
}
});
UpdateEntity cmd = service.getLastExecuted(UpdateEntity.class);
Assert.assertTrue(cmd.getChanges().containsKey("name"));
Assert.assertEquals("New Name", cmd.getChanges().get("name"));
}
Aggregations