Example usage for com.fasterxml.jackson.databind.node ObjectNode get

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ObjectNode get.

Prototype

public JsonNode get(String paramString) 

Source Link

Usage

From source file:com.joyent.manta.client.multipart.ServerSideMultipartManagerTest.java

public void canCreateMpuRequestBodyJson() throws IOException {
    final String path = "/user/stor/object";

    final byte[] json = ServerSideMultipartManager.createMpuRequestBody(path, null, null);

    ObjectNode jsonObject = mapper.readValue(json, ObjectNode.class);

    Assert.assertEquals(jsonObject.get("objectPath").textValue(), path);
}

From source file:com.ikanow.aleph2.graph.titan.utils.TitanGraphBuildingUtils.java

/** Quick/fast validation of user chosen elements from the merge list
 * @param o/*from  w w  w. j  av  a  2s.  c om*/
 * @return
 */
public static Validation<BasicMessageBean, ObjectNode> validateMergedElement(final ObjectNode o,
        GraphSchemaBean config) {
    // Some basic validation: 
    // - is "type" either edge or vertex
    // - "label" is set
    // - properties are valid 
    // - (for edges _don't_ to validate inV/outV because all that's already been chosen and can't be chosen at this point .. ditto vertices and ids)

    // Type is set to one of edge/vertex
    {
        final JsonNode type = o.get(GraphAnnotationBean.type);
        if (null == type) {
            return Validation
                    .fail(ErrorUtils.buildErrorMessage("GraphBuilderEnrichmentService", "system.onObjectBatch",
                            ErrorUtils.MISSING_OR_BADLY_FORMED_FIELD, GraphAnnotationBean.type, "missing"));
        } else if (!type.isTextual()) {
            return Validation
                    .fail(ErrorUtils.buildErrorMessage("GraphBuilderEnrichmentService", "system.onObjectBatch",
                            ErrorUtils.MISSING_OR_BADLY_FORMED_FIELD, GraphAnnotationBean.type, "not_text"));
        } else if (!GraphAnnotationBean.ElementType.edge.toString().equals(type.asText())
                && !GraphAnnotationBean.ElementType.vertex.toString().equals(type.asText())) {
            return Validation.fail(ErrorUtils.buildErrorMessage("GraphBuilderEnrichmentService",
                    "system.onObjectBatch", ErrorUtils.MISSING_OR_BADLY_FORMED_FIELD, GraphAnnotationBean.type,
                    "not_edge_or_vertex"));
        }
    }
    // Label is set
    {
        final JsonNode label = o.get(GraphAnnotationBean.label);
        if (null == label) {
            return Validation
                    .fail(ErrorUtils.buildErrorMessage("GraphBuilderEnrichmentService", "system.onObjectBatch",
                            ErrorUtils.MISSING_OR_BADLY_FORMED_FIELD, GraphAnnotationBean.label, "missing"));
        } else if (!label.isTextual()) {
            return Validation
                    .fail(ErrorUtils.buildErrorMessage("GraphBuilderEnrichmentService", "system.onObjectBatch",
                            ErrorUtils.MISSING_OR_BADLY_FORMED_FIELD, GraphAnnotationBean.label, "not_text"));
        }
    }
    // Sort out properties

    final JsonNode properties = o.get(GraphAnnotationBean.properties);
    if (null != properties) { // (properties is optional)
        //TODO (ALEPH-15): sort out properties later (TODO including permissions, or does that happen elsewhere?)
        // - Check if is an object
        // - Loop over fields:
        //   - check each value is an array or an object (replace with a nested array if an object)
        //     - (if it's atomic, convert into an object of the right sort?)
        //   - for each value in the array, check it's an object (see above mutation step)
        //   - check it's value is one of the supported types
        //   - if it has a properties field, check it is an object of string/string
        //   - (Will just discard _b so can ignore): TODO: sort out setting it elsewhere

        if (!properties.isObject()) {
            return Validation.fail(ErrorUtils.buildErrorMessage("GraphBuilderEnrichmentService",
                    "system.onObjectBatch", ErrorUtils.MISSING_OR_BADLY_FORMED_FIELD,
                    GraphAnnotationBean.properties, "not_object"));
        }
    }

    return Validation.success(o);
}

From source file:org.gitana.platform.client.plan.PlanImpl.java

private BigDecimal _getBigDecimal(String objectFieldId, String fieldId) {
    BigDecimal big = null;/*from   www  . j av a2s. c o m*/

    ObjectNode object = getObject(objectFieldId);
    if (object != null && object.has(fieldId)) {
        Object value = object.get(fieldId);
        if (value != null) {
            if (value instanceof NumericNode) {
                big = ((NumericNode) value).decimalValue();
            }
        }
    }

    return big;
}

From source file:org.flowable.admin.service.engine.ProcessInstanceService.java

public List<String> getCompletedActivityInstancesAndProcessDefinitionId(ServerConfig serverConfig,
        String processInstanceId) {
    URIBuilder builder = clientUtil.createUriBuilder(HISTORIC_ACTIVITY_INSTANCE_LIST_URL);
    builder.addParameter("processInstanceId", processInstanceId);
    // builder.addParameter("finished", "true");
    builder.addParameter("sort", "startTime");
    builder.addParameter("order", "asc");
    builder.addParameter("size", DEFAULT_ACTIVITY_SIZE);

    HttpGet get = new HttpGet(clientUtil.getServerUrl(serverConfig, builder));
    JsonNode node = clientUtil.executeRequest(get, serverConfig);

    List<String> result = new ArrayList<String>();
    if (node.has("data") && node.get("data").isArray()) {
        ArrayNode data = (ArrayNode) node.get("data");
        ObjectNode activity = null;
        for (int i = 0; i < data.size(); i++) {
            activity = (ObjectNode) data.get(i);
            if (activity.has("activityType")) {
                result.add(activity.get("activityId").asText());
            }/*from   ww w  . j  a  v  a2  s . com*/
        }
    }

    return result;
}

From source file:com.github.reinert.jjschema.HyperSchemaGeneratorV4.java

@Override
public <T> ObjectNode generateSchema(Class<T> type) throws TypeException {
    ObjectNode hyperSchema = null;/*from w  ww  . ja va  2 s . c o  m*/
    Annotation path = type.getAnnotation(Path.class);
    if (path != null) {
        hyperSchema = generateHyperSchemaFromResource(type);
    } else {
        ObjectNode jsonSchema = (ObjectNode) jsonSchemaGenerator.generateSchema(type);
        if (jsonSchema != null) {
            if ("array".equals(jsonSchema.get("type").asText())) {
                if (!Collection.class.isAssignableFrom(type)) {
                    ObjectNode items = (ObjectNode) jsonSchema.get("items");
                    // NOTE: Customized Iterable Class must declare the Collection object at first
                    Field field = type.getDeclaredFields()[0];
                    ParameterizedType genericType = (ParameterizedType) field.getGenericType();
                    Class<?> genericClass = (Class<?>) genericType.getActualTypeArguments()[0];
                    ObjectNode hyperItems = transformJsonToHyperSchema(genericClass, (ObjectNode) items);
                    jsonSchema.put("items", hyperItems);
                }
                hyperSchema = jsonSchema;
            } else if (jsonSchema.has("properties")) {
                hyperSchema = transformJsonToHyperSchema(type, jsonSchema);
            } else {
                hyperSchema = jsonSchema;
            }
        }
    }

    //TODO: When available by SchemaVersion, put the $schema attribute as the correct HyperSchema ref.

    return hyperSchema;
}

From source file:org.agatom.springatom.cmp.action.DefaultActionsModelReader.java

private void setCssRule(final ObjectNode node, final AbstractAction action) {
    if (node.has("iconClass")) {
        action.setIconClass(node.get("iconClass").textValue());
    }// w w w .j a va2  s .  c o  m
    if (node.has("btnClass")) {
        action.setBtnClass(node.get("btnClass").textValue());
    }
}

From source file:com.almende.eve.rpc.jsonrpc.JSONResponse.java

/**
 * Inits the.//from   w ww  .j  av  a  2 s. c  o  m
 *
 * @param response the response
 * @throws JSONRPCException the jSONRPC exception
 */
private void init(final ObjectNode response) throws JSONRPCException {
    if (response == null || response.isNull()) {
        throw new JSONRPCException(JSONRPCException.CODE.INVALID_REQUEST, "Response is null");
    }
    if (response.has(JSONRPC) && response.get(JSONRPC).isTextual()
            && !response.get(JSONRPC).asText().equals(VERSION)) {
        throw new JSONRPCException(JSONRPCException.CODE.INVALID_REQUEST,
                "Value of member 'jsonrpc' must be '2.0'");
    }
    final boolean hasError = response.has(ERROR) && !response.get(ERROR).isNull();
    if (hasError && !(response.get(ERROR).isObject())) {
        throw new JSONRPCException(JSONRPCException.CODE.INVALID_REQUEST, "Member 'error' is no ObjectNode");
    }

    final JsonNode id = response.get(ID);
    final Object result = response.get(RESULT);
    JSONRPCException error = null;
    if (hasError) {
        error = new JSONRPCException((ObjectNode) response.get(ERROR));
    }

    init(id, result, error);
}

From source file:controllers.Rules.java

@Security.Authenticated(Secured.class)
@BodyParser.Of(BodyParser.Json.class)
public static Promise<Result> updateName(final String name) {
    final ObjectNode newProps = (ObjectNode) request().body().asJson();
    newProps.retain("uuid", "name", "description");
    Promise<Boolean> nameTaken = Rule.nodes.exists(newProps);
    Promise<Boolean> updated = nameTaken.flatMap(new Function<Boolean, Promise<Boolean>>() {
        public Promise<Boolean> apply(Boolean nameTaken) {
            if (nameTaken) {
                return Promise.pure(false);
            }/*from  ww  w .j  av  a 2s .c om*/
            ObjectNode oldProps = Json.newObject();
            oldProps.put("name", name);
            return Rule.nodes.update(oldProps, newProps);
        }
    });
    return updated.map(new Function<Boolean, Result>() {
        ObjectNode result = Json.newObject();

        public Result apply(Boolean updated) {
            if (updated) {
                result.put("id", newProps.get("name").asText());
                result.put("message", "Name successfully updated.");
                return ok(result);
            }
            result.put("message", "Name not updated.");
            return badRequest(result);
        }
    });
}

From source file:br.com.ingenieux.mojo.simpledb.cmd.PutAttributesCommand.java

private void putAttribute(PutAttributesContext ctx, ObjectNode objectNode) {
    PutAttributesRequest request = new PutAttributesRequest();

    request.setDomainName(ctx.getDomain());

    Iterator<String> itFieldName = objectNode.fieldNames();

    while (itFieldName.hasNext()) {
        String key = itFieldName.next();

        if ("name".equals(key)) {
            String value = objectNode.get("name").textValue();

            request.setItemName(value);/*  www  .j a  v a2 s  . c om*/
        } else if ("append".equals(key) || "replace".equals(key)) {
            boolean replaceP = "replace".equals(key);

            ArrayNode attributesNode = (ArrayNode) objectNode.get(key);

            Collection<ReplaceableAttribute> value = getAttributesFrom(attributesNode, replaceP);

            request.getAttributes().addAll(value);
        } else if ("expect".equals(key)) {
            ObjectNode expectNode = (ObjectNode) objectNode.get("expect");

            request.setExpected(getUpdateCondition(expectNode));
        }
    }

    service.putAttributes(request);
}

From source file:com.almende.eve.algorithms.TrickleRPC.java

/**
 * Instantiates a new trickle rpc./*from w w w .j ava2  s .  c  om*/
 *
 * @param config
 *            the config
 * @param scheduler
 *            the scheduler
 * @param onInterval
 *            the on interval
 * @param onSend
 *            the on send
 */
public TrickleRPC(final ObjectNode config, Scheduler scheduler, Runnable onInterval, Runnable onSend) {
    this.scheduler = scheduler;
    this.onInterval = onInterval;
    this.onSend = onSend;

    int intervalMin = 100;
    int intervalFactor = 16;
    int redundancyFactor = 1;

    if (config.has("intervalMin")) {
        intervalMin = config.get("intervalMin").asInt();
    }
    if (config.has("intervalFactor")) {
        intervalFactor = config.get("intervalFactor").asInt();
    }
    if (config.has("redundancyFactor")) {
        redundancyFactor = config.get("redundancyFactor").asInt();
    }
    if (config.has("namespace")) {
        namespace = config.get("namespace").asText() + namespace;
    }
    requests.put(namespace + "send", new JSONRequest(namespace + "send", null));
    requests.put(namespace + "nextInterval", new JSONRequest(namespace + "nextInterval", null));
    trickle = new Trickle(intervalMin, intervalFactor, redundancyFactor);
    reschedule(trickle.next());
}