Search in sources :

Example 21 with VoidResult

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);
                    }
                });
            }
        }
    });
}
Also used : MessageBoxEvent(com.extjs.gxt.ui.client.event.MessageBoxEvent) VoidResult(org.activityinfo.shared.command.result.VoidResult) MaskingAsyncMonitor(org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) DeleteReport(org.activityinfo.shared.command.DeleteReport) ReportMetadataDTO(org.activityinfo.shared.dto.ReportMetadataDTO)

Example 22 with VoidResult

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();
}
Also used : TargetValue(org.activityinfo.server.database.hibernate.entity.TargetValue) UpdateTargetValue(org.activityinfo.shared.command.UpdateTargetValue) Target(org.activityinfo.server.database.hibernate.entity.Target) PropertyMap(org.activityinfo.server.command.handler.crud.PropertyMap) VoidResult(org.activityinfo.shared.command.result.VoidResult) TargetValueId(org.activityinfo.server.database.hibernate.entity.TargetValueId) CommandException(org.activityinfo.shared.exception.CommandException) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator)

Example 23 with 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());
}
Also used : VoidResult(org.activityinfo.shared.command.result.VoidResult)

Example 24 with 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());
}
Also used : VoidResult(org.activityinfo.shared.command.result.VoidResult) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction)

Example 25 with 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"));
}
Also used : TreeStore(com.extjs.gxt.ui.client.store.TreeStore) VoidResult(org.activityinfo.shared.command.result.VoidResult) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) MockEventBus(org.activityinfo.client.MockEventBus) DispatcherStub(org.activityinfo.client.dispatch.DispatcherStub) Record(com.extjs.gxt.ui.client.store.Record) UIConstants(org.activityinfo.client.i18n.UIConstants) StateManagerStub(org.activityinfo.client.mock.StateManagerStub) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) Test(org.junit.Test)

Aggregations

VoidResult (org.activityinfo.shared.command.result.VoidResult)26 Record (com.extjs.gxt.ui.client.store.Record)4 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)4 MockEventBus (org.activityinfo.client.MockEventBus)4 DispatcherStub (org.activityinfo.client.dispatch.DispatcherStub)4 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)4 UIConstants (org.activityinfo.client.i18n.UIConstants)4 StateManagerStub (org.activityinfo.client.mock.StateManagerStub)4 UpdateEntity (org.activityinfo.shared.command.UpdateEntity)4 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)4 Test (org.junit.Test)4 FormDialogCallback (org.activityinfo.client.page.common.dialog.FormDialogCallback)3 TreeStore (com.extjs.gxt.ui.client.store.TreeStore)2 FormDialogImpl (org.activityinfo.client.page.common.dialog.FormDialogImpl)2 Delete (org.activityinfo.shared.command.Delete)2 UpdateMonthlyReports (org.activityinfo.shared.command.UpdateMonthlyReports)2 UpdateReportSubscription (org.activityinfo.shared.command.UpdateReportSubscription)2 UpdateUserPermissions (org.activityinfo.shared.command.UpdateUserPermissions)2 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)2 CommandException (org.activityinfo.shared.exception.CommandException)2