private JsonNode projectObjectField(JsonNode fieldNode, ObjectNode ret, Path fieldPath, JsonNodeCursor cursor, Projector projector, FieldTreeNode mdContext, Path contextPath, JsonNodeFactory factory, QueryEvaluationContext ctx) { if (fieldNode instanceof ObjectNode) { LOGGER.debug("projecting object node {}",fieldPath); if (cursor.firstChild()) { ObjectNode newNode = projectObject(projector, factory, mdContext, contextPath, cursor, ctx); ret.set(fieldPath.tail(0), newNode); cursor.parent(); } else { ret.set(fieldPath.tail(0), factory.objectNode()); } } else { LOGGER.warn("Expecting object node, found {} for {}", fieldNode.getClass().getName(), fieldPath); } return null; }
private BasicDBObject toBson(JsonDoc doc, EntityMetadata md,ResultMetadata rmd) { LOGGER.debug("Entity: {}", md.getName()); BasicDBObject ret = null; JsonNodeCursor cursor = doc.cursor(); if (cursor.firstChild()) { ret = objectToBson(cursor, md,rmd); } return ret; }
private BasicDBObject toBson(JsonDoc doc, EntityMetadata md) { LOGGER.debug("Entity: {}", md.getName()); BasicDBObject ret = null; JsonNodeCursor cursor = doc.cursor(); if (cursor.firstChild()) { ret = objectToBson(cursor, md); } return ret; }
/** * Projects a document */ public JsonDoc project(JsonDoc doc, JsonNodeFactory factory) { JsonNodeCursor cursor = doc.cursor(); cursor.firstChild(); ObjectNode root = (ObjectNode) project(factory, rootMdPath, cursor, new QueryEvaluationContext(doc.getRoot()), false); if (root == null) { root = factory.objectNode(); } return new JsonDoc(root); }
/** * Projects a document */ public JsonDoc project(JsonDoc doc, JsonNodeFactory factory) { JsonNodeCursor cursor = doc.cursor(); cursor.firstChild(); ObjectNode root = (ObjectNode) project(factory, rootMdPath, cursor, new QueryEvaluationContext(doc.getRoot()), false); if (root == null) { root = factory.objectNode(); } return new JsonDoc(root); }
/** * @param cursor The cursor, pointing to the first element of the array */ @SuppressWarnings({"rawtypes", "unchecked"}) private List arrayToBson(JsonNodeCursor cursor, ArrayElement el, EntityMetadata md,ResultMetadata rmd) { List l = new ArrayList(); if (el instanceof SimpleArrayElement) { Type t = el.getType(); do { Object value = toValue(t, cursor.getCurrentNode()); l.add(value); } while (cursor.nextSibling()); } else { do { JsonNode node = cursor.getCurrentNode(); if (node == null || node instanceof NullNode) { l.add(null); } else if (cursor.firstChild()) { l.add(objectToBson(cursor, md,rmd)); cursor.parent(); } else { l.add(null); } } while (cursor.nextSibling()); } return l; }
/** * @param cursor The cursor, pointing to the first element of the array */ @SuppressWarnings({"rawtypes", "unchecked"}) private List arrayToBson(JsonNodeCursor cursor, ArrayElement el, EntityMetadata md) { List l = new ArrayList(); if (el instanceof SimpleArrayElement) { Type t = el.getType(); do { Object value = toValue(t, cursor.getCurrentNode()); l.add(value); } while (cursor.nextSibling()); } else { do { JsonNode node = cursor.getCurrentNode(); if (node == null || node instanceof NullNode) { l.add(null); } else { if (cursor.firstChild()) { l.add(objectToBson(cursor, md)); cursor.parent(); } else { l.add(null); } } } while (cursor.nextSibling()); } return l; }
/** * Projects a document */ public JsonDoc project(JsonDoc doc, JsonNodeFactory factory) { JsonNodeCursor cursor = doc.cursor(); cursor.firstChild(); ObjectNode root = projectObject(this, factory, rootMdNode, rootMdPath, cursor, new QueryEvaluationContext(doc.getRoot())); return new JsonDoc(root); }
protected void translate(ObjectField field, JsonNodeCursor cursor, Object target) { if(!cursor.firstChild()){ throw Error.get(MetadataConstants.ERR_ILL_FORMED_METADATA, cursor.getCurrentPath().toString()); } do { translate(cursor, target); } while (cursor.nextSibling()); cursor.parent(); }
protected void translate(ObjectField field, JsonNodeCursor cursor, Object target) { if(!cursor.firstChild()){ throw Error.get(MetadataConstants.ERR_ILL_FORMED_METADATA, cursor.getCurrentPath().toString()); } do { translate(cursor, target); } while (cursor.nextSibling()); cursor.parent(); }
/** * Translates an entire {@link JsonDoc} to T. * @param document - {@link JsonDoc} * @param target - T */ public void translate(JsonDoc document, T target){ Error.push("translating from json"); try{ JsonNodeCursor cursor = document.cursor(); if (!cursor.firstChild()) { //TODO throw exception? return; } do { translate(cursor, target); } while (cursor.nextSibling()); } finally{ Error.pop(); } }
/** * Translates an entire {@link JsonDoc} to T. * @param document - {@link JsonDoc} * @param target - T */ public void translate(JsonDoc document, T target){ Error.push("translating from json"); try{ JsonNodeCursor cursor = document.cursor(); if (!cursor.firstChild()) { //TODO throw exception? return; } do { translate(cursor, target); } while (cursor.nextSibling()); } finally{ Error.pop(); } }
private void translate(ArrayField field, JsonNodeCursor cursor, Object target) { if(!cursor.firstChild()){ throw Error.get(MetadataConstants.ERR_ILL_FORMED_METADATA, cursor.getCurrentPath().toString()); } ArrayElement arrayElement = field.getElement(); if (arrayElement instanceof SimpleArrayElement) { List<Object> items = new ArrayList<>(); do { items.add(fromJson(arrayElement.getType(), cursor.getCurrentNode())); } while (cursor.nextSibling()); translate(field, items, target); } else if(arrayElement instanceof ObjectArrayElement){ List<Object> items = new ArrayList<>(); do { Object item = createInstanceFor(arrayElement.getFullPath()); translate((ObjectArrayElement) arrayElement, cursor.getCurrentNode(), item); items.add(item); } while (cursor.nextSibling()); translate(field, items, target); } else{ throw Error.get(MetadataConstants.ERR_UNSUPPORTED_FEATURE + arrayElement.getClass().getName(), field.getFullPath().toString()); } cursor.parent(); }
protected void translate(final ObjectArrayElement objectArrayElement, JsonNode node, Object target) { JsonNodeCursor cursor = new JsonNodeCursor(objectArrayElement.getFullPath(), node); if(!cursor.firstChild()){ throw Error.get(MetadataConstants.ERR_ILL_FORMED_METADATA, cursor.getCurrentPath().toString()); } do { translate(cursor, target); } while (cursor.nextSibling()); }
private void translate(ArrayField field, JsonNodeCursor cursor, Object target) { if(!cursor.firstChild()){ throw Error.get(MetadataConstants.ERR_ILL_FORMED_METADATA, cursor.getCurrentPath().toString()); } ArrayElement arrayElement = field.getElement(); if (arrayElement instanceof SimpleArrayElement) { List<Object> items = new ArrayList<>(); do { items.add(fromJson(arrayElement.getType(), cursor.getCurrentNode())); } while (cursor.nextSibling()); translate(field, items, target); } else if(arrayElement instanceof ObjectArrayElement){ List<Object> items = new ArrayList<>(); do { Object item = createInstanceFor(arrayElement.getFullPath()); translate((ObjectArrayElement) arrayElement, cursor.getCurrentNode(), item); items.add(item); } while (cursor.nextSibling()); translate(field, items, target); } else{ throw Error.get(MetadataConstants.ERR_UNSUPPORTED_FEATURE + arrayElement.getClass().getName(), field.getFullPath().toString()); } cursor.parent(); }
protected void translate(final ObjectArrayElement objectArrayElement, JsonNode node, Object target) { JsonNodeCursor cursor = new JsonNodeCursor(objectArrayElement.getFullPath(), node); if(!cursor.firstChild()){ throw Error.get(MetadataConstants.ERR_ILL_FORMED_METADATA, cursor.getCurrentPath().toString()); } do { translate(cursor, target); } while (cursor.nextSibling()); }
private void convertArrayFieldToBson(JsonNode node, JsonNodeCursor cursor, BasicDBObject ret, FieldTreeNode fieldMdNode, Path path, EntityMetadata md,ResultMetadata rmd) { if (node != null) { if (node instanceof ArrayNode) { if (cursor.firstChild()) { ret.append(path.tail(0), arrayToBson(cursor, ((ArrayField) fieldMdNode).getElement(), md,rmd)); cursor.parent(); } else { // empty array! add an empty list. ret.append(path.tail(0), new ArrayList()); } } else if (node instanceof NullNode) { ret.append(path.tail(0), null); } else { throw Error.get(ERR_INVALID_FIELD, path.toString()); } } }
private void convertObjectFieldToBson(JsonNode node, JsonNodeCursor cursor, BasicDBObject ret, Path path, EntityMetadata md,ResultMetadata rmd) { if (node != null) { if (node instanceof ObjectNode) { if (cursor.firstChild()) { ret.append(path.tail(0), objectToBson(cursor, md,rmd)); cursor.parent(); } } else if (node instanceof NullNode) { ret.append(path.tail(0), null); } else { throw Error.get(ERR_INVALID_FIELD, path.toString()); } } }
private void convertObjectFieldToBson(JsonNode node, JsonNodeCursor cursor, BasicDBObject ret, Path path, EntityMetadata md) { if (node != null) { if (node instanceof ObjectNode) { if (cursor.firstChild()) { ret.append(path.tail(0), objectToBson(cursor, md)); cursor.parent(); } } else if(node instanceof NullNode) { ret.append(path.tail(0),null); } else { throw Error.get(ERR_INVALID_FIELD, path.toString()); } } }
private void convertArrayFieldToBson(JsonNode node, JsonNodeCursor cursor, BasicDBObject ret, FieldTreeNode fieldMdNode, Path path, EntityMetadata md) { if (node != null) { if (node instanceof ArrayNode) { if (cursor.firstChild()) { ret.append(path.tail(0), arrayToBson(cursor, ((ArrayField) fieldMdNode).getElement(), md)); cursor.parent(); } else { // empty array! add an empty list. ret.append(path.tail(0), new ArrayList()); } } else if(node instanceof NullNode) { ret.append(path.tail(0),null); } else { throw Error.get(ERR_INVALID_FIELD, path.toString()); } } }