Search in sources :

Example 1 with BatchResult

use of org.activityinfo.shared.command.result.BatchResult in project activityinfo by bedatadriven.

the class ImporterWizard method submitSites.

private void submitSites(List<LocationDTO> results, final AsyncCallback<Void> callback) {
    int numColums = model.getData().getNumColumns();
    ColumnBinding[] bindings = bindingsArray();
    KeyGenerator keyGenerator = new KeyGenerator();
    // do a first pass to match the location
    List<Command> siteBatch = Lists.newArrayList();
    int rowIndex = 0;
    for (ImportRowModel row : model.getData().getRowStore().getModels()) {
        LocationDTO location = results.get(rowIndex);
        if (location.isNew()) {
            siteBatch.add(new CreateLocation(location));
        }
        SiteDTO site = new SiteDTO();
        site.setId(keyGenerator.generateInt());
        site.setReportingPeriodId(keyGenerator.generateInt());
        site.setActivityId(model.getActivity().getId());
        site.setLocationId(location.getId());
        site.setPartner(model.getActivity().getDatabase().getPartners().get(0));
        for (int i = 0; i != numColums; ++i) {
            bindings[i].bindSite(row.get(i), site);
        }
        siteBatch.add(new CreateSite(site));
        rowIndex++;
    }
    dispatcher.execute(new BatchCommand(siteBatch), new AsyncCallback<BatchResult>() {

        @Override
        public void onFailure(Throwable caught) {
            MessageBox.alert("Import failed", "Exception: " + caught.getMessage(), null);
            callback.onFailure(null);
        }

        @Override
        public void onSuccess(BatchResult result) {
            MessageBox.alert("Import succeeded!", "Refresh the data grid to see your new sites", null);
            callback.onSuccess(null);
        }
    });
}
Also used : CreateLocation(org.activityinfo.shared.command.CreateLocation) ColumnBinding(org.activityinfo.client.importer.column.ColumnBinding) BatchResult(org.activityinfo.shared.command.result.BatchResult) CreateSite(org.activityinfo.shared.command.CreateSite) Command(org.activityinfo.shared.command.Command) BatchCommand(org.activityinfo.shared.command.BatchCommand) BatchCommand(org.activityinfo.shared.command.BatchCommand) SiteDTO(org.activityinfo.shared.dto.SiteDTO) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator) LocationDTO(org.activityinfo.shared.dto.LocationDTO)

Example 2 with BatchResult

use of org.activityinfo.shared.command.result.BatchResult in project activityinfo by bedatadriven.

the class ShareReportDialog method show.

public void show(ReportMetadataDTO metadata) {
    super.show();
    BatchCommand batch = new BatchCommand();
    batch.add(new GetReportModel(metadata.getId()));
    batch.add(new GetSchema());
    batch.add(new GetReportVisibility(metadata.getId()));
    dispatcher.execute(batch, new MaskingAsyncMonitor(grid, I18N.CONSTANTS.loading()), new AsyncCallback<BatchResult>() {

        @Override
        public void onFailure(Throwable caught) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onSuccess(BatchResult batch) {
            currentReport = ((ReportDTO) batch.getResult(0)).getReport();
            populateGrid((SchemaDTO) batch.getResult(1), (ReportVisibilityResult) batch.getResult(2));
        }
    });
}
Also used : ReportVisibilityResult(org.activityinfo.shared.command.result.ReportVisibilityResult) GetReportVisibility(org.activityinfo.shared.command.GetReportVisibility) GetReportModel(org.activityinfo.shared.command.GetReportModel) MaskingAsyncMonitor(org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor) ReportDTO(org.activityinfo.shared.dto.ReportDTO) BatchCommand(org.activityinfo.shared.command.BatchCommand) BatchResult(org.activityinfo.shared.command.result.BatchResult) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Example 3 with BatchResult

use of org.activityinfo.shared.command.result.BatchResult in project activityinfo by bedatadriven.

the class ShareReportDialog method show.

public void show(final Report report) {
    super.show();
    this.currentReport = report;
    // we need to combine the databases which already have visiblity with
    // those
    // that could potentially be added
    BatchCommand batch = new BatchCommand();
    batch.add(new GetSchema());
    batch.add(new GetReportVisibility(currentReport.getId()));
    dispatcher.execute(batch, new MaskingAsyncMonitor(grid, I18N.CONSTANTS.loading()), new AsyncCallback<BatchResult>() {

        @Override
        public void onFailure(Throwable caught) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onSuccess(BatchResult batch) {
            populateGrid((SchemaDTO) batch.getResult(0), (ReportVisibilityResult) batch.getResult(1));
        }
    });
}
Also used : ReportVisibilityResult(org.activityinfo.shared.command.result.ReportVisibilityResult) GetReportVisibility(org.activityinfo.shared.command.GetReportVisibility) MaskingAsyncMonitor(org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor) BatchCommand(org.activityinfo.shared.command.BatchCommand) BatchResult(org.activityinfo.shared.command.result.BatchResult) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Example 4 with BatchResult

use of org.activityinfo.shared.command.result.BatchResult in project activityinfo by bedatadriven.

the class BatchCommandHandler method execute.

@Override
public void execute(BatchCommand batch, ExecutionContext context, final AsyncCallback<BatchResult> callback) {
    if (batch.getCommands().isEmpty()) {
        LOGGER.warning("Received empty batch command");
        callback.onSuccess(new BatchResult(Lists.<CommandResult>newArrayList()));
    } else {
        final ArrayList<CommandResult> results = new ArrayList<CommandResult>();
        for (Command command : batch.getCommands()) {
            results.add(null);
        }
        final boolean[] finished = new boolean[batch.getCommands().size()];
        final List<Throwable> exceptions = Lists.newArrayList();
        for (int i = 0; i != batch.getCommands().size(); ++i) {
            final int commandIndex = i;
            context.execute(batch.getCommands().get(i), new AsyncCallback<CommandResult>() {

                @Override
                public void onFailure(Throwable caught) {
                    if (exceptions.isEmpty()) {
                        exceptions.add(caught);
                        callback.onFailure(caught);
                    }
                }

                @Override
                public void onSuccess(CommandResult result) {
                    results.set(commandIndex, result);
                    finished[commandIndex] = true;
                    if (all(finished)) {
                        callback.onSuccess(new BatchResult(results));
                    }
                }
            });
        }
    }
}
Also used : BatchCommand(org.activityinfo.shared.command.BatchCommand) Command(org.activityinfo.shared.command.Command) ArrayList(java.util.ArrayList) BatchResult(org.activityinfo.shared.command.result.BatchResult) CommandResult(org.activityinfo.shared.command.result.CommandResult)

Example 5 with BatchResult

use of org.activityinfo.shared.command.result.BatchResult in project activityinfo by bedatadriven.

the class DispatcherStub method execute.

@Override
public <T extends CommandResult> void execute(Command<T> command, AsyncCallback<T> callback) {
    if (command instanceof BatchCommand) {
        BatchCommand batch = (BatchCommand) command;
        List<CommandResult> results = new ArrayList<CommandResult>();
        for (Command batchCmd : batch.getCommands()) {
            results.add(findResult(batchCmd));
        }
        callback.onSuccess((T) new BatchResult(results));
    } else {
        callback.onSuccess((T) findResult(command));
    }
}
Also used : BatchCommand(org.activityinfo.shared.command.BatchCommand) Command(org.activityinfo.shared.command.Command) ArrayList(java.util.ArrayList) BatchCommand(org.activityinfo.shared.command.BatchCommand) BatchResult(org.activityinfo.shared.command.result.BatchResult) CommandResult(org.activityinfo.shared.command.result.CommandResult)

Aggregations

BatchCommand (org.activityinfo.shared.command.BatchCommand)7 BatchResult (org.activityinfo.shared.command.result.BatchResult)7 Command (org.activityinfo.shared.command.Command)4 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)3 ArrayList (java.util.ArrayList)2 ColumnBinding (org.activityinfo.client.importer.column.ColumnBinding)2 KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)2 GetReportVisibility (org.activityinfo.shared.command.GetReportVisibility)2 GetSchema (org.activityinfo.shared.command.GetSchema)2 CommandResult (org.activityinfo.shared.command.result.CommandResult)2 ReportVisibilityResult (org.activityinfo.shared.command.result.ReportVisibilityResult)2 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)2 Record (com.extjs.gxt.ui.client.store.Record)1 List (java.util.List)1 CreateLocation (org.activityinfo.shared.command.CreateLocation)1 CreateSite (org.activityinfo.shared.command.CreateSite)1 GetReportModel (org.activityinfo.shared.command.GetReportModel)1 MatchLocation (org.activityinfo.shared.command.MatchLocation)1 UpdateUserPermissions (org.activityinfo.shared.command.UpdateUserPermissions)1 LocationDTO (org.activityinfo.shared.dto.LocationDTO)1