/** * Returns a deep copy of the current document */ public JsonDoc copy() { return new JsonDoc(docRoot.deepCopy()); }
/** * Returns a deep copy of the current document */ public JsonDoc copy() { return new JsonDoc(docRoot.deepCopy()); }
/** * Returns a deep copy of the current document */ public JsonDoc copy() { return new JsonDoc(docRoot.deepCopy()); }
/** * Return a list of JsonDoc objects from the given Json node * * @psram data Json document containing one or more documents * * The Json document is either an ArrayNode containing Json documents at * each element, or an ObjectNode containing only one document. */ public static List<JsonDoc> docList(JsonNode data) { ArrayList<JsonDoc> docs = null; if (data != null) { if (data instanceof ArrayNode) { docs = new ArrayList<>(((ArrayNode) data).size()); for (Iterator<JsonNode> itr = ((ArrayNode) data).elements(); itr.hasNext();) { docs.add(new JsonDoc(itr.next())); } } else if (data instanceof ObjectNode) { docs = new ArrayList<>(1); docs.add(new JsonDoc(data)); } } return docs; }
/** * Return a list of JsonDoc objects from the given Json node * * @psram data Json document containing one or more documents * * The Json document is either an ArrayNode containing Json documents at * each element, or an ObjectNode containing only one document. */ public static List<JsonDoc> docList(JsonNode data) { ArrayList<JsonDoc> docs = null; if (data != null) { if (data instanceof ArrayNode) { docs = new ArrayList<>(((ArrayNode) data).size()); for (Iterator<JsonNode> itr = ((ArrayNode) data).elements(); itr.hasNext();) { docs.add(new JsonDoc(itr.next())); } } else if (data instanceof ObjectNode) { docs = new ArrayList<>(1); docs.add(new JsonDoc(data)); } } return docs; }
public KeyValueCursor<Path, JsonNode> getNodes(Path relativePath) { return new JsonDoc(contextRoot).getAllNodes(new Path(relativePath)); }
private TranslatedDoc toJson(DBObject object, EntityMetadata md) { // Translation is metadata driven. We don't know how to // translate something that's not defined in metadata. FieldCursor cursor = md.getFieldCursor(); if (cursor.firstChild()) { return new TranslatedDoc(new JsonDoc(objectToJson(object,object, md, cursor)),getDocMetadata(object)); } else { return null; } }
private JsonDoc toJson(DBObject object, EntityMetadata md) { // Translation is metadata driven. We don't know how to // translate something that's not defined in metadata. FieldCursor cursor = md.getFieldCursor(); if (cursor.firstChild()) { return new JsonDoc(objectToJson(object, md, cursor)); } else { return null; } }
public KeyValueCursor<Path, JsonNode> getNodes(Path relativePath, boolean returnMissingNodes) { return new JsonDoc(root).getAllNodes(contextPath.isEmpty() ? relativePath : new Path(contextPath, relativePath), returnMissingNodes); }
public KeyValueCursor<Path, JsonNode> getNodes(Path relativePath) { return new JsonDoc(root).getAllNodes(contextPath.isEmpty() ? relativePath : new Path(contextPath, relativePath)); }
public KeyValueCursor<Path, JsonNode> getNodes(Path relativePath) { return new JsonDoc(root).getAllNodes(contextPath.isEmpty() ? relativePath : new Path(contextPath, relativePath)); }
public KeyValueCursor<Path, JsonNode> getNodes(Path relativePath, boolean returnMissingNodes) { return new JsonDoc(root).getAllNodes(contextPath.isEmpty() ? relativePath : new Path(contextPath, relativePath), returnMissingNodes); }
/** * 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); }
/** * Translates the source to a {@link JsonDoc}. * @param source - Object containing the source data. * @return {@link JsonDoc} */ public JsonDoc translate(S source){ Error.push("translating to json"); try{ FieldCursor cursor = entityMetadata.getFieldCursor(); if (cursor.firstChild()) { ObjectNode node = factory.objectNode(); iterateOverNodes(source, node, cursor); return new JsonDoc(node); } } finally{ Error.pop(); } //TODO: What to do in case of a null value here? return null; }
@Override public void explain(OperationContext ctx, CRUDFindRequest req) { initialize(ctx,req); ExecutionContext executionContext = new ExecutionContext(ctx,null); JsonDoc doc=new JsonDoc(executionPlan.explain(executionContext)); ctx.setDocumentStream(new ListDocumentStream<DocCtx>(Arrays.asList(new DocCtx(doc)))); }
/** * Translates the source to a {@link JsonDoc}. * @param source - Object containing the source data. * @return {@link JsonDoc} */ public JsonDoc translate(S source){ Error.push("translating to json"); try{ FieldCursor cursor = entityMetadata.getFieldCursor(); if (cursor.firstChild()) { ObjectNode node = factory.objectNode(); iterateOverNodes(source, node, cursor); return new JsonDoc(node); } } finally{ Error.pop(); } //TODO: What to do in case of a null value here? return null; }
@Override public void explain(OperationContext ctx, CRUDFindRequest req) { initialize(ctx,req); ExecutionContext executionContext = new ExecutionContext(ctx,null); JsonDoc doc=new JsonDoc(executionPlan.explain(executionContext)); ctx.setDocumentStream(new ListDocumentStream<DocCtx>(Arrays.asList(new DocCtx(doc)))); }
/** * Compares the pre- and post- documents after they are passed * through the watchProjector, and returns the delta */ private DocComparator.Difference<JsonNode> compareDocs(EntityMetadata metadata, JsonDoc preDoc, JsonDoc postDoc, Projector watchProjector) throws Exception { JsonDoc watchedPostDoc = watchProjector.project(postDoc, jsonNodeFactory); JsonDoc watchedPreDoc = preDoc == null ? new JsonDoc(jsonNodeFactory.objectNode()) : watchProjector.project(preDoc, jsonNodeFactory); // Compute diff JsonCompare cmp=metadata.getDocComparator(); LOGGER.debug("Array identities:{}",cmp.getArrayIdentities()); LOGGER.debug("Pre:{}, Post:{}",watchedPreDoc.getRoot(),watchedPostDoc.getRoot()); DocComparator.Difference<JsonNode> diff=cmp. compareNodes(watchedPreDoc.getRoot(),watchedPostDoc.getRoot()); LOGGER.debug("Diff: {}",diff); return diff; }
/** * 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); }