use of org.activityinfo.shared.command.result.VoidResult in project activityinfo by bedatadriven.
the class ReportGridPanel method delete.
private void delete() {
final ReportMetadataDTO report = grid.getSelectionModel().getSelectedItem();
MessageBox.confirm(I18N.CONSTANTS.delete(), I18N.MESSAGES.confirmDeleteReport(report.getTitle()), new Listener<MessageBoxEvent>() {
@Override
public void handleEvent(MessageBoxEvent be) {
if (be.getButtonClicked().getItemId().equals(Dialog.YES)) {
dispatcher.execute(new DeleteReport(report.getId()), new MaskingAsyncMonitor(ReportGridPanel.this, I18N.CONSTANTS.delete()), new AsyncCallback<VoidResult>() {
@Override
public void onFailure(Throwable caught) {
// handled by monitor
}
@Override
public void onSuccess(VoidResult result) {
grid.getStore().remove(report);
}
});
}
}
});
}
use of org.activityinfo.shared.command.result.VoidResult 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.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.shared.command.result.VoidResult in project activityinfo by bedatadriven.
the class UpdateSiteHandler method execute.
@Override
public void execute(final UpdateSite command, ExecutionContext context, final AsyncCallback<VoidResult> callback) {
final Map<String, Object> changes = command.getChanges().getTransientMap();
SqlTransaction tx = context.getTransaction();
updateSiteProperties(tx, command, changes);
updateAttributeValues(tx, command.getSiteId(), changes);
// updateLocation(tx, command.getSiteId(), changes);
updateReportingPeriod(tx, command.getSiteId(), changes);
callback.onSuccess(new VoidResult());
}
use of org.activityinfo.shared.command.result.VoidResult in project activityinfo by bedatadriven.
the class DesignTest method testSave.
@Test
public void testSave() {
// 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);
// Localisation resources
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.onUIAction(UIActions.SAVE);
UpdateEntity cmd = service.getLastExecuted(UpdateEntity.class);
Assert.assertTrue(cmd.getChanges().containsKey("name"));
Assert.assertEquals("New Name", cmd.getChanges().get("name"));
}
Aggregations