You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2016/10/19 15:10:05 UTC

svn commit: r1765637 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java

Author: chetanm
Date: Wed Oct 19 15:10:05 2016
New Revision: 1765637

URL: http://svn.apache.org/viewvc?rev=1765637&view=rev
Log:
OAK-1312 -  [bundling] Bundle nodes into a document

Handle serialization of DocumentNodeState

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java?rev=1765637&r1=1765636&r2=1765637&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java Wed Oct 19 15:10:05 2016
@@ -334,7 +334,10 @@ public class DocumentNodeState extends A
     }
 
     String getPropertyAsString(String propertyName) {
-        PropertyState prop = properties.get(propertyName);
+        return asString(properties.get(propertyName));
+    }
+
+    private String asString(PropertyState prop) {
         if (prop == null) {
             return null;
         } else if (prop instanceof DocumentPropertyState) {
@@ -514,11 +517,10 @@ public class DocumentNodeState extends A
         if (hasChildren) {
             json.key("hasChildren").value(true);
         }
-        //TODO [bundling] Handle serialization
         if (properties.size() > 0) {
             json.key("prop").object();
-            for (String k : properties.keySet()) {
-                json.key(k).value(getPropertyAsString(k));
+            for (Map.Entry<String, PropertyState> e : bundlingContext.getAllProperties().entrySet()) {
+                json.key(e.getKey()).value(asString(e.getValue()));
             }
             json.endObject();
         }
@@ -782,6 +784,10 @@ public class DocumentNodeState extends A
             return rootProperties;
         }
 
+        public Map<String, PropertyState> getAllProperties(){
+            return rootProperties;
+        }
+
         public boolean hasChildNode(String relativePath){
             String key = concat(relativePath, DocumentBundlor.META_PROP_NODE);
             return rootProperties.containsKey(key);

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java?rev=1765637&r1=1765636&r2=1765637&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java Wed Oct 19 15:10:05 2016
@@ -33,12 +33,14 @@ import org.apache.jackrabbit.oak.commons
 import org.apache.jackrabbit.oak.plugins.document.Collection;
 import org.apache.jackrabbit.oak.plugins.document.Document;
 import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeState;
 import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
 import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
 import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
 import org.apache.jackrabbit.oak.plugins.document.util.Utils;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
 import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
+import org.apache.jackrabbit.oak.spi.state.AbstractNodeState;
 import org.apache.jackrabbit.oak.spi.state.EqualsDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -442,6 +444,28 @@ public class DocumentBundlingTest {
         assertTrue(getNodeDocument("/test/book.jpg").hasBinary());
     }
 
+    @Test
+    public void jsonSerialization() throws Exception{
+        NodeBuilder builder = store.getRoot().builder();
+        NodeBuilder appNB = newNode("app:Asset");
+        createChild(appNB,
+                "jcr:content",
+                "jcr:content/comments", //not bundled
+                "jcr:content/metadata",
+                "jcr:content/metadata/xmp", //not bundled
+                "jcr:content/renditions", //includes all
+                "jcr:content/renditions/original",
+                "jcr:content/renditions/original/jcr:content"
+        );
+        builder.child("test").setChildNode("book.jpg", appNB.getNodeState());
+
+        merge(builder);
+        DocumentNodeState appNode = (DocumentNodeState) getNode(store.getRoot(), "test/book.jpg");
+        String json = appNode.asString();
+        NodeState appNode2 = DocumentNodeState.fromString(store, json);
+        AssertingDiff.assertEquals(appNode, appNode2);
+    }
+
     private void createTestNode(String path, NodeState state) throws CommitFailedException {
         String parentPath = PathUtils.getParentPath(path);
         NodeBuilder builder = store.getRoot().builder();
@@ -532,8 +556,10 @@ public class DocumentBundlingTest {
         );
 
         public static boolean assertEquals(NodeState before, NodeState after) {
+            //Do not rely on default compareAgainstBaseState as that works at lastRev level
+            //and we need proper equals
             return before.exists() == after.exists()
-                    && after.compareAgainstBaseState(before, new AssertingDiff());
+                    && AbstractNodeState.compareAgainstBaseState(after, before, new AssertingDiff());
         }
 
         @Override