Search in sources :

Example 6 with BatchResult

use of org.activityinfo.legacy.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 : Command(org.activityinfo.legacy.shared.command.Command) BatchCommand(org.activityinfo.legacy.shared.command.BatchCommand) ArrayList(java.util.ArrayList) BatchCommand(org.activityinfo.legacy.shared.command.BatchCommand) BatchResult(org.activityinfo.legacy.shared.command.result.BatchResult) CommandResult(org.activityinfo.legacy.shared.command.result.CommandResult)

Example 7 with BatchResult

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

the class SchemaImporterV2 method persistBatch.

private void persistBatch(final Iterator<List<? extends EntityDTO>> batchIterator) {
    BatchCommand batchCommand = new BatchCommand();
    final List<? extends EntityDTO> batch = batchIterator.next();
    for (EntityDTO entity : batch) {
        batchCommand.add(create(entity));
    }
    listener.submittingBatch(batchNumber++, batchCount);
    dispatcher.execute(batchCommand, new AsyncCallback<BatchResult>() {

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }

        @Override
        public void onSuccess(BatchResult result) {
            for (int i = 0; i != result.getResults().size(); ++i) {
                CreateResult createResult = result.getResult(i);
                batch.get(i).set("id", createResult.getNewId());
            }
            if (batchIterator.hasNext()) {
                persistBatch(batchIterator);
            } else {
                callback.onSuccess(null);
            }
        }
    });
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) BatchCommand(org.activityinfo.legacy.shared.command.BatchCommand) BatchResult(org.activityinfo.legacy.shared.command.result.BatchResult)

Aggregations

BatchResult (org.activityinfo.legacy.shared.command.result.BatchResult)7 BatchCommand (org.activityinfo.legacy.shared.command.BatchCommand)4 MaskingAsyncMonitor (org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor)3 ArrayList (java.util.ArrayList)2 Command (org.activityinfo.legacy.shared.command.Command)2 CommandResult (org.activityinfo.legacy.shared.command.result.CommandResult)2 Record (com.extjs.gxt.ui.client.store.Record)1 UpdateUserPermissions (org.activityinfo.legacy.shared.command.UpdateUserPermissions)1 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)1 IndicatorResult (org.activityinfo.legacy.shared.command.result.IndicatorResult)1 ReportVisibilityResult (org.activityinfo.legacy.shared.command.result.ReportVisibilityResult)1 UserPermissionDTO (org.activityinfo.legacy.shared.model.UserPermissionDTO)1 AsyncMonitor (org.activityinfo.ui.client.dispatch.AsyncMonitor)1 SuccessCallback (org.activityinfo.ui.client.dispatch.callback.SuccessCallback)1 SaveChangesCallback (org.activityinfo.ui.client.page.common.dialog.SaveChangesCallback)1 SavePromptMessageBox (org.activityinfo.ui.client.page.common.dialog.SavePromptMessageBox)1