2 Replies Latest reply on Dec 9, 2012 5:36 AM by antondigi

    Reverse Replication not working on custom content...

    antondigi

      Hello,

      I have been trying to create some content in the jcr on a publish instance of CQ5.4 and have it be reverse replicated back to the author instance.   The node is being created by the following bit of test code in a custom servlet in a bundle:

      // session is an admin session
      Node rootNode = session.getRootNode();
      if (rootNode != null) {
         baseNode = rootNode.getNode("content/usergenerated/content");
         if (baseNode != null) {
            Date now = new Date();
            String name = "test-" + String.valueOf(now.getTime());
            Node pageNode = baseNode.addNode(name, "cq:Page");
            if (pageNode != null) {
               Node contentNode = pageNode.addNode("jcr:content", "nt:unstructured");
               // If I leave the following 3 lines out and add manually (via CRXDE Lite), 
               // the node gets replicated.
               contentNode.setProperty("cq:distribute", true);
               contentNode.setProperty("cq:lastModified", Calendar.getInstance());
               contentNode.setProperty("cq:lastModifiedBy", session.getUserID());
            }
         }
      }
      session.save()
      

      I see the node being created in the proper location (/content/usergenerated/content/test-1234567890) and the properties being added. 

      The funny thing is that if I don't add the 3 properties (cq:distribute, cq:lastModified, and cq:lastModifiedBy) with code, but through CRXDE Lite, the node is replicated just fine.

       

      What am I missing?  Any help is greatly appreciated.

      I am running this code with both the author instance and publish instance on my local machine.

        • 1. Re: Reverse Replication not working on custom content...
          rush_pawan Level 4

          Hello,

           

          In your code your are creating a node with remaining properties using servlet on your publish instance. I think there is know issue for that "http://dev.day.com/docs/en/cq/current/deploying/configuring_cq.html" just search "Reverse replication does not happen when a node is created".

           

          Also if you refer http://helpx.adobe.com/cq/kb/HowToUseReverseReplication.html it suggested for already existing node.

           

          Now you have two choices either

          1. create the node (means after below line just save the node and again refer it to modify using followed code)

          Node contentNode = pageNode.addNode("jcr:content", "nt:unstructured");

          2.Else follow the soltution mentioned in http://dev.day.com/docs/en/cq/current/deploying/configuring_cq.html

           

          I hope it helps you to proceed. let me know for more information.

           

          Thanks,

          Pawan


          • 2. Re: Reverse Replication not working on custom content...
            antondigi Level 1

            Pawan,

            Thanks for the reply and the insight.  By putting session.save() call after the addNode() call, reverse replication was triggered.  So, in the end, my test code looked like the following :

            // session is an admin session
            Node rootNode = session.getRootNode();
            if (rootNode != null) {
               baseNode = rootNode.getNode("content/usergenerated/content");
               if (baseNode != null) {
                  Date now = new Date();
                  String name = "test-" + String.valueOf(now.getTime());
                  Node pageNode = baseNode.addNode(name, "cq:Page");
                  if (pageNode != null) {
                     Node contentNode = pageNode.addNode("jcr:content", "nt:unstructured");
            
                     // Added this save call to get reverse replication working.
                     session.save();
            
            
                     contentNode.setProperty("cq:distribute", true);
                     contentNode.setProperty("cq:lastModified", Calendar.getInstance());
                     contentNode.setProperty("cq:lastModifiedBy", session.getUserID());
                  }
               }
            }
            session.save();
            

             

            Summary: save all newly created nodes BEFORE add the 3 replication properties (cq:distribution, cq:lastModified, cq:lastModifiedBy) in order for reverse replication to work.

             

            Thanks again, Pawan!