@Test public void testFromJson() throws IOException { ObjectNode node = (ObjectNode) JsonUtils.json("{\"$append\":{\"\":{\"$valueof\":\"\"}}}"); List<RValueExpression> l = new ArrayList<>(); ArrayAddExpression expResult = new ArrayAddExpression(Path.EMPTY, UpdateOperator._append, l); l.add(new RValueExpression(Path.EMPTY)); ArrayAddExpression result = ArrayAddExpression.fromJson(node); assertEquals(expResult, result); }
public static ArrayAddExpression fromJson(ObjectNode node) { if (node.size() == 1) { UpdateOperator op = UpdateOperator._append; JsonNode arg = node.get(UpdateOperator._append.toString()); if (arg == null) { arg = node.get(UpdateOperator._insert.toString()); op = UpdateOperator._insert; } if (arg instanceof ObjectNode) { ObjectNode objArg = (ObjectNode) arg; if (objArg.size() == 1) { Map.Entry<String, JsonNode> item = objArg.fields().next(); Path field = new Path(item.getKey()); JsonNode valueNode = item.getValue(); List<RValueExpression> rvalues = new ArrayList<>(); if (valueNode instanceof ArrayNode) { for (Iterator<JsonNode> itr = ((ArrayNode) valueNode).elements(); itr.hasNext();) { rvalues.add(RValueExpression.fromJson(itr.next())); } } else { rvalues.add(RValueExpression.fromJson(valueNode)); } return new ArrayAddExpression(field, op, rvalues); } } } throw Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString()); }
ArrayAddExpression extends ArrayUpdateExpression { public static ArrayAddExpression fromJson(ObjectNode node) { if (node.size() == 1) { UpdateOperator op = UpdateOperator._append; JsonNode arg = node.get(UpdateOperator._append.toString()); if (arg == null) { arg = node.get(UpdateOperator._insert.toString()); op = UpdateOperator._insert; } if (arg instanceof ObjectNode) { ObjectNode objArg = (ObjectNode) arg; if (objArg.size() == 1) { Map.Entry<String, JsonNode> item = objArg.fields().next(); Path field = new Path(item.getKey()); JsonNode valueNode = item.getValue(); List<RValueExpression> rvalues = new ArrayList<>(); if (valueNode instanceof ArrayNode) { for (Iterator<JsonNode> itr = ((ArrayNode) valueNode).elements(); itr.hasNext();) { rvalues.add(RValueExpression.fromJson(itr.next())); } } else { rvalues.add(RValueExpression.fromJson(valueNode)); } return new ArrayAddExpression(field, op, rvalues); } } } throw Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString()); } }
ArrayAddExpression extends ArrayUpdateExpression { public static ArrayAddExpression fromJson(ObjectNode node) { if (node.size() == 1) { UpdateOperator op = UpdateOperator._append; JsonNode arg = node.get(UpdateOperator._append.toString()); if (arg == null) { arg = node.get(UpdateOperator._insert.toString()); op = UpdateOperator._insert; } if (arg instanceof ObjectNode) { ObjectNode objArg = (ObjectNode) arg; if (objArg.size() == 1) { Map.Entry<String, JsonNode> item = objArg.fields().next(); Path field = new Path(item.getKey()); JsonNode valueNode = item.getValue(); List<RValueExpression> rvalues = new ArrayList<>(); if (valueNode instanceof ArrayNode) { for (Iterator<JsonNode> itr = ((ArrayNode) valueNode).elements(); itr.hasNext();) { rvalues.add(RValueExpression.fromJson(itr.next())); } } else { rvalues.add(RValueExpression.fromJson(valueNode)); } return new ArrayAddExpression(field, op, rvalues); } } } throw Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString()); } ArrayAddExpression(Path field, UpdateOperator op, List<RValueExpression> list); }
ArrayAddExpression extends ArrayUpdateExpression { public static ArrayAddExpression fromJson(ObjectNode node) { if (node.size() == 1) { UpdateOperator op = UpdateOperator._append; JsonNode arg = node.get(UpdateOperator._append.toString()); if (arg == null) { arg = node.get(UpdateOperator._insert.toString()); op = UpdateOperator._insert; } if (arg instanceof ObjectNode) { ObjectNode objArg = (ObjectNode) arg; if (objArg.size() == 1) { Map.Entry<String, JsonNode> item = objArg.fields().next(); Path field = new Path(item.getKey()); JsonNode valueNode = item.getValue(); List<RValueExpression> rvalues = new ArrayList<>(); if (valueNode instanceof ArrayNode) { for (Iterator<JsonNode> itr = ((ArrayNode) valueNode).elements(); itr.hasNext();) { rvalues.add(RValueExpression.fromJson(itr.next())); } } else { rvalues.add(RValueExpression.fromJson(valueNode)); } return new ArrayAddExpression(field, op, rvalues); } } } throw Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString()); } ArrayAddExpression(Path field, UpdateOperator op, List<RValueExpression> list); Path getField(); List<RValueExpression> getValues(); UpdateOperator getOp(); @Override JsonNode toJson(); static ArrayAddExpression fromJson(ObjectNode node); @Override int hashCode(); @Override boolean equals(Object obj); }
ArrayAddExpression extends ArrayUpdateExpression { public static ArrayAddExpression fromJson(ObjectNode node) { if (node.size() == 1) { UpdateOperator op = UpdateOperator._append; JsonNode arg = node.get(UpdateOperator._append.toString()); if (arg == null) { arg = node.get(UpdateOperator._insert.toString()); op = UpdateOperator._insert; } if (arg instanceof ObjectNode) { ObjectNode objArg = (ObjectNode) arg; if (objArg.size() == 1) { Map.Entry<String, JsonNode> item = objArg.fields().next(); Path field = new Path(item.getKey()); JsonNode valueNode = item.getValue(); List<RValueExpression> rvalues = new ArrayList<>(); if (valueNode instanceof ArrayNode) { for (Iterator<JsonNode> itr = ((ArrayNode) valueNode).elements(); itr.hasNext();) { rvalues.add(RValueExpression.fromJson(itr.next())); } } else { rvalues.add(RValueExpression.fromJson(valueNode)); } return new ArrayAddExpression(field, op, rvalues); } } } throw Error.get(QueryConstants.ERR_INVALID_ARRAY_UPDATE_EXPRESSION, node.toString()); } ArrayAddExpression(Path field, UpdateOperator op, List<RValueExpression> list); Path getField(); List<RValueExpression> getValues(); UpdateOperator getOp(); @Override JsonNode toJson(); static ArrayAddExpression fromJson(ObjectNode node); @Override int hashCode(); @Override boolean equals(Object obj);  }