Search in sources :

Example 6 with Command

use of org.activityinfo.legacy.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();
    if (Strings.isNullOrEmpty(typeName)) {
        throw new BadRpcRequest("Expected 'type' property on root object. You must specify a command type.");
    }
    Class commandClass;
    try {
        commandClass = lookupCommandClass(typeName);
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Failed to find command class for " + typeName, e);
        throw new BadRpcRequest("Invalid command type '%s'", typeName);
    }
    JsonNode command = root.path("command");
    if (!command.isObject()) {
        throw new BadRpcRequest("Expected 'command' root object property.");
    }
    try {
        return (Command) mapper.readValue(command, commandClass);
    } catch (UnrecognizedPropertyException e) {
        throw new BadRpcRequest("Unexpected property '%s'", formatPath(e.getPath()));
    }
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) Command(org.activityinfo.legacy.shared.command.Command) UnrecognizedPropertyException(org.codehaus.jackson.map.exc.UnrecognizedPropertyException) JsonNode(org.codehaus.jackson.JsonNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) UnrecognizedPropertyException(org.codehaus.jackson.map.exc.UnrecognizedPropertyException) IOException(java.io.IOException) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException)

Aggregations

Command (org.activityinfo.legacy.shared.command.Command)6 CommandResult (org.activityinfo.legacy.shared.command.result.CommandResult)4 ArrayList (java.util.ArrayList)3 BatchCommand (org.activityinfo.legacy.shared.command.BatchCommand)2 BatchResult (org.activityinfo.legacy.shared.command.result.BatchResult)2 IOException (java.io.IOException)1 POST (javax.ws.rs.POST)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)1 CommandException (org.activityinfo.legacy.shared.exception.CommandException)1 IllegalAccessCommandException (org.activityinfo.legacy.shared.exception.IllegalAccessCommandException)1 JsonNode (org.codehaus.jackson.JsonNode)1 JsonProcessingException (org.codehaus.jackson.JsonProcessingException)1 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 UnrecognizedPropertyException (org.codehaus.jackson.map.exc.UnrecognizedPropertyException)1 ObjectNode (org.codehaus.jackson.node.ObjectNode)1