List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get
public JsonNode get(String paramString)
From source file:com.pros.jsontransform.expression.FunctionRandomUUID.java
public static JsonNode evaluate(final JsonNode argsNode, final JsonNode valueNode, final ObjectTransformer transformer) throws ObjectTransformerException { ObjectNode resultNode = (ObjectNode) argsNode; resultNode.put("returnValue", UUID.randomUUID().toString()); return resultNode.get("returnValue"); }
From source file:com.pros.jsontransform.plugin.expression.FunctionAvgChildrenAge.java
public static JsonNode evaluate(final JsonNode argsNode, final JsonNode resultNode, final ObjectTransformer transformer) throws ObjectTransformerException { double avg = 0.0; // argument $value indicates children array in source node context if (argsNode.get("$value") != null) { // transformer resolves $value to corresponding node JsonNode childrenArray = transformer.transformValueNode(transformer.getSourceNode(), argsNode); if (childrenArray.isArray()) { for (JsonNode child : childrenArray) { avg += child.path("age").asDouble(); }/*from w ww . j av a2 s .co m*/ avg = avg / childrenArray.size(); } } // use argsNode to hold temporary return value node ObjectNode holderNode = (ObjectNode) argsNode; holderNode.put("returnValue", avg); return holderNode.get("returnValue"); }
From source file:com.redhat.lightblue.query.ArrayContainsExpression.java
/** * Parses an ArrayContainsExpression from a JSON object node. */// w w w. j av a 2 s .com public static ArrayContainsExpression fromJson(ObjectNode node) { JsonNode x = node.get("array"); if (x != null) { Path field = new Path(x.asText()); x = node.get("contains"); if (x != null) { ContainsOperator op = ContainsOperator.fromString(x.asText()); if (op != null) { x = node.get("values"); if (x instanceof ArrayNode) { ArrayList<Value> values = new ArrayList<>(((ArrayNode) x).size()); for (Iterator<JsonNode> itr = ((ArrayNode) x).elements(); itr.hasNext();) { values.add(Value.fromJson(itr.next())); } return new ArrayContainsExpression(field, op, values); } } } } throw Error.get(QueryConstants.ERR_INVALID_ARRAY_COMPARISON_EXPRESSION, node.toString()); }
From source file:com.redhat.lightblue.query.NaryFieldRelationalExpression.java
/** * Parses an n-ary relational expression from the given json object *//*from w ww . j a v a2 s . c o m*/ public static NaryFieldRelationalExpression fromJson(ObjectNode node) { if (node.size() == 3) { JsonNode x = node.get("op"); if (x != null) { NaryRelationalOperator op = NaryRelationalOperator.fromString(x.asText()); if (op != null) { x = node.get("field"); if (x != null) { Path field = new Path(x.asText()); x = node.get("rfield"); if (x != null) { return new NaryFieldRelationalExpression(field, op, new Path(x.asText())); } } } } } throw Error.get(QueryConstants.ERR_INVALID_COMPARISON_EXPRESSION, node.toString()); }
From source file:com.redhat.lightblue.query.BasicProjection.java
/** * Parses a field or array projection from the given json object *///from w w w.ja v a 2 s.c o m public static BasicProjection fromJson(ObjectNode node) { String field = node.get("field").asText(); if (field == null) { throw Error.get(QueryConstants.ERR_INVALID_PROJECTION, "field"); } Path path = getNonRelativePath(new Path(field)); // Processing of optional elements. We decide on the type of // the final object based on what fields this object has JsonNode x = node.get("include"); boolean include; if (x == null) { include = true; } else { include = x.asBoolean(); } Projection projection; x = node.get("project"); if (x != null) { projection = Projection.fromJson(x); } else { projection = null; } x = node.get("sort"); Sort sort; if (x != null) { sort = Sort.fromJson(x); } else { sort = null; } x = node.get("range"); if (x != null) { if (x instanceof ArrayNode && ((ArrayNode) x).size() == 2) { int from = ((ArrayNode) x).get(0).asInt(); int to = ((ArrayNode) x).get(1).asInt(); return new ArrayRangeProjection(path, include, projection, sort, from, to); } else { throw Error.get(QueryConstants.ERR_INVALID_ARRAY_RANGE_PROJECTION, node.toString()); } } x = node.get("match"); if (x != null) { return new ArrayQueryMatchProjection(path, include, projection, sort, QueryExpression.fromJson(x)); } x = node.get("recursive"); return new FieldProjection(path, include, x == null ? false : x.asBoolean()); }
From source file:com.pros.jsontransform.expression.FunctionSum.java
public static JsonNode evaluate(final JsonNode argsNode, final JsonNode valueNode, final ObjectTransformer transformer) throws ObjectTransformerException { Double sum = 0.0;//from ww w .j a v a2s . c om JsonNode sumValuesArray = argsNode.path(ARGUMENT_WHAT); if (sumValuesArray.isArray()) { for (JsonNode sumValue : sumValuesArray) { JsonNode value = transformer.transformValueNode(transformer.getSourceNode(), sumValue); if (value.isNumber()) { sum += value.asDouble(); } } } // add start value if any if (valueNode.isNumber()) { sum += valueNode.asDouble(); } ObjectNode resultNode = (ObjectNode) argsNode; resultNode.put("returnValue", sum); return resultNode.get("returnValue"); }
From source file:com.redhat.lightblue.crud.DeleteRequest.java
/** * Parses an object node and populates a DeleteRequest. It is up to the * caller to make sure that the node is actually a DeleteRequest. Any * unrecignized elements are ignored.// w ww. ja v a 2 s . c o m */ public static DeleteRequest fromJson(ObjectNode node) { DeleteRequest req = new DeleteRequest(); req.parse(node); JsonNode x = node.get("query"); if (x != null) { req.query = QueryExpression.fromJson(x); } return req; }
From source file:com.redhat.lightblue.query.RegexMatchExpression.java
public static RegexMatchExpression fromJson(ObjectNode node) { JsonNode x = node.get("field"); if (x != null) { Path field = new Path(x.asText()); x = node.get("regex"); if (x != null) { String regex = x.asText(); return new RegexMatchExpression(field, regex, asBoolean(node.get("caseInsensitive")), asBoolean(node.get("multiline")), asBoolean(node.get("extended")), asBoolean(node.get("dotall"))); }//from ww w . ja v a2s . co m } throw Error.get(QueryConstants.ERR_INVALID_REGEX_EXPRESSION, node.toString()); }
From source file:com.redhat.lightblue.ExecutionOptions.java
/** * Parses execution options from a json object. Unrecognized elements are * ignored./*from w w w. ja v a 2s . c om*/ */ public static ExecutionOptions fromJson(ObjectNode node) { ExecutionOptions ret = new ExecutionOptions(); JsonNode x = node.get("timeLimit"); if (x != null) { ret.timeLimit = x.asLong(); } x = node.get("asynchronous"); if (x != null) { ret.asynchronous = x.asLong(); } return ret; }
From source file:com.pros.jsontransform.expression.FunctionSet.java
public static JsonNode evaluate(final JsonNode argsNode, final JsonNode valueNode, final ObjectTransformer transformer) throws ObjectTransformerException { ObjectNode resultNode = (ObjectNode) argsNode; resultNode.put("returnValue", transformArgument(argsNode.path(ARGUMENT_WITH), transformer)); return resultNode.get("returnValue"); }