Search in sources :

Example 1 with BatchCommand

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

the class DbUserEditorActions method save.

public void save(final NavigationCallback callback) {
    BatchCommand batch = new BatchCommand();
    for (Record record : store.getModifiedRecords()) {
        batch.add(new UpdateUserPermissions(db.getId(), (UserPermissionDTO) record.getModel()));
    }
    dispatcher.execute(batch, new MaskingAsyncMonitor(panel, I18N.CONSTANTS.saving()), new AsyncCallback<BatchResult>() {

        @Override
        public void onFailure(Throwable caught) {
            // handled by monitor
            if (callback != null) {
                callback.onDecided(false);
            }
        }

        @Override
        public void onSuccess(BatchResult result) {
            store.commitChanges();
            panel.setModified(false);
            if (callback != null) {
                callback.onDecided(true);
            }
        }
    });
}
Also used : UpdateUserPermissions(org.activityinfo.legacy.shared.command.UpdateUserPermissions) MaskingAsyncMonitor(org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor) BatchCommand(org.activityinfo.legacy.shared.command.BatchCommand) Record(com.extjs.gxt.ui.client.store.Record) BatchResult(org.activityinfo.legacy.shared.command.result.BatchResult) UserPermissionDTO(org.activityinfo.legacy.shared.model.UserPermissionDTO)

Example 2 with BatchCommand

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

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

Example 3 with BatchCommand

use of org.activityinfo.legacy.shared.command.BatchCommand 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 4 with BatchCommand

use of org.activityinfo.legacy.shared.command.BatchCommand 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

BatchCommand (org.activityinfo.legacy.shared.command.BatchCommand)4 BatchResult (org.activityinfo.legacy.shared.command.result.BatchResult)4 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 UserPermissionDTO (org.activityinfo.legacy.shared.model.UserPermissionDTO)1 MaskingAsyncMonitor (org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor)1