Search in sources :

Example 6 with Command

use of org.activityinfo.shared.command.Command in project activityinfo by bedatadriven.

the class ImporterWizard method finish.

@Override
public void finish(final AsyncCallback<Void> callback) {
    final KeyGenerator keyGenerator = new KeyGenerator();
    int numColums = model.getData().getNumColumns();
    ColumnBinding[] bindings = bindingsArray();
    // do a first pass to match the location
    List<Command> matchBatch = Lists.newArrayList();
    for (ImportRowModel row : model.getData().getRowStore().getModels()) {
        MatchLocation location = new MatchLocation();
        location.setLocationType(model.getActivity().getLocationTypeId());
        for (int i = 0; i != numColums; ++i) {
            bindings[i].bindLocation(row.get(i), location);
        }
        matchBatch.add(location);
    }
    dispatcher.execute(new BatchCommand(matchBatch), new AsyncCallback<BatchResult>() {

        @Override
        public void onFailure(Throwable caught) {
            MessageBox.alert("Match locations failed", "Exception", null);
        }

        @Override
        public void onSuccess(BatchResult result) {
            submitSites((List) result.getResults(), callback);
        }
    });
}
Also used : ColumnBinding(org.activityinfo.client.importer.column.ColumnBinding) BatchResult(org.activityinfo.shared.command.result.BatchResult) MatchLocation(org.activityinfo.shared.command.MatchLocation) Command(org.activityinfo.shared.command.Command) BatchCommand(org.activityinfo.shared.command.BatchCommand) BatchCommand(org.activityinfo.shared.command.BatchCommand) List(java.util.List) KeyGenerator(org.activityinfo.client.local.command.handler.KeyGenerator)

Example 7 with Command

use of org.activityinfo.shared.command.Command in project activityinfo by bedatadriven.

the class CommandServlet method handleCommands.

/**
 * Publicly visible for testing *
 */
@LogException
public List<CommandResult> handleCommands(List<Command> commands) {
    applyUserFilters();
    List<CommandResult> results = new ArrayList<CommandResult>();
    for (Command command : commands) {
        LOGGER.log(Level.INFO, authProvider.get().getEmail() + ": " + command.getClass().getSimpleName());
        try {
            results.add(handleCommand(command));
        } catch (CommandException e) {
            results.add(e);
        }
    }
    return results;
}
Also used : Command(org.activityinfo.shared.command.Command) ArrayList(java.util.ArrayList) CommandException(org.activityinfo.shared.exception.CommandException) CommandResult(org.activityinfo.shared.command.result.CommandResult) LogException(org.activityinfo.server.util.logging.LogException)

Example 8 with Command

use of org.activityinfo.shared.command.Command in project activityinfo by bedatadriven.

the class CommandDeserializer method deserialize.

@Override
public Command deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    ObjectNode root = (ObjectNode) mapper.readTree(jp);
    String typeName = root.path("type").asText();
    Class commandClass = lookupCommandClass(typeName);
    return (Command) mapper.readValue(root.path("command"), commandClass);
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) Command(org.activityinfo.shared.command.Command) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

Command (org.activityinfo.shared.command.Command)8 CommandResult (org.activityinfo.shared.command.result.CommandResult)5 ArrayList (java.util.ArrayList)4 BatchCommand (org.activityinfo.shared.command.BatchCommand)4 BatchResult (org.activityinfo.shared.command.result.BatchResult)4 ColumnBinding (org.activityinfo.client.importer.column.ColumnBinding)2 KeyGenerator (org.activityinfo.client.local.command.handler.KeyGenerator)2 IOException (java.io.IOException)1 List (java.util.List)1 ServletException (javax.servlet.ServletException)1 LogException (org.activityinfo.server.util.logging.LogException)1 CreateLocation (org.activityinfo.shared.command.CreateLocation)1 CreateSite (org.activityinfo.shared.command.CreateSite)1 GetSchema (org.activityinfo.shared.command.GetSchema)1 MatchLocation (org.activityinfo.shared.command.MatchLocation)1 LocationDTO (org.activityinfo.shared.dto.LocationDTO)1 SiteDTO (org.activityinfo.shared.dto.SiteDTO)1 CommandException (org.activityinfo.shared.exception.CommandException)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 ObjectNode (org.codehaus.jackson.node.ObjectNode)1