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);
}
}
});
}
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));
}
}
});
}
}
}
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));
}
}
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);
}
}
});
}
Aggregations