2015-02-11 95 views
0

我有一个服务试图将博客页面导入到CQ 5.5.0中。我能够成功创建页面,但是当我添加表示内容的节点时,节点不会被保存。 CQ没有报告错误,我可以在创建后立即看到服务中的节点。但是当我查看CRXDE Light中的页面时,节点不是页面内容的一部分。添加节点的代码段位于:添加到页面的节点未保存在CQ

Node blogNode = blogPage.adaptTo(Node.class); 
    logOutput(INFO, "blogPage name = "+ blogPage.getName()); 
    // Create the author date node 
    Node authorDateNode = blogNode.addNode("jcr:content/authorDate", "nt:unstructured"); 
    authorDateNode.setProperty("author", blog.getCreator()); 
    authorDateNode.setProperty("date", sdf.format(blog.getPublishDate().getTime())); 
    authorDateNode.setProperty("sling:resourceType", "history/components/blog/authordate"); 

    // Create the content node 
    Node blogPostNode = blogNode.addNode("jcr:content/blogPostBodyParSys", "nt:unstructured"); 
    blogPostNode.setProperty("sling:resourceType", "history/components/parsys"); 

    Node blogContentNode = blogNode.addNode("jcr:content/blogPostBodyParSys/text", "nt:unstructured"); 
    blogContentNode.setProperty("sling:resourceType", "history/components/text"); 
    blogContentNode.setProperty("text", blog.getContent()); 
    blogContentNode.setProperty("textIsRich", "true"); 

    // TODO: Test code only 
    NodeIterator itr = blogNode.getNode("jcr:content").getNodes(); 
    while(itr.hasNext()) { 
     Node child = itr.nextNode(); 
     logOutput(INFO, "Child node: " + child.getName(), 1); 
     PropertyIterator propItr = child.getProperties(); 
     while(propItr.hasNext()) { 
      Property prop = propItr.nextProperty(); 
      logOutput(INFO, "Property " + prop.getName() + ", value " + prop.getValue().getString(),2); 
     } 
    } 

底部的测试代码显示新创建的节点,并且它按预期显示值。发生的最后一件事是在服务退出之前调用'session.save'。

没有错误报告,但我看不到页面上的节点。有没有人有任何关于这里可能是错误的想法?

+0

你保存会话吗? – 2015-02-12 00:54:50

回答

1

正如@Sharath Maddapa指出的那样,您需要保存会话。查看您的代码中所做的更改。

Node blogNode = blogPage.adaptTo(Node.class); 
     logOutput(INFO, "blogPage name = "+ blogPage.getName()); 
     // Create the author date node 
     Node authorDateNode = blogNode.addNode("jcr:content/authorDate", "nt:unstructured"); 
     authorDateNode.setProperty("author", blog.getCreator()); 
     authorDateNode.setProperty("date", sdf.format(blog.getPublishDate().getTime())); 
     authorDateNode.setProperty("sling:resourceType", "history/components/blog/authordate"); 

     // Create the content node 
     Node blogPostNode = blogNode.addNode("jcr:content/blogPostBodyParSys", "nt:unstructured"); 
     blogPostNode.setProperty("sling:resourceType", "history/components/parsys"); 

     Node blogContentNode = blogNode.addNode("jcr:content/blogPostBodyParSys/text", "nt:unstructured"); 
     blogContentNode.setProperty("sling:resourceType", "history/components/text"); 
     blogContentNode.setProperty("text", blog.getContent()); 
     blogContentNode.setProperty("textIsRich", "true"); 
//YOU must save the session here. 
    try { 
    blogNode.getSession().save(); 
    } catch(Exception e) {// TODO Ideally log specific exceptions 
    logOutput(ERROR, "Error saving jcr session "); 
    } 
     // TODO: Test code only 
     NodeIterator itr = blogNode.getNode("jcr:content").getNodes(); 
     while(itr.hasNext()) { 
      Node child = itr.nextNode(); 
      logOutput(INFO, "Child node: " + child.getName(), 1); 
      PropertyIterator propItr = child.getProperties(); 
      while(propItr.hasNext()) { 
       Property prop = propItr.nextProperty(); 
       logOutput(INFO, "Property " + prop.getName() + ", value " + prop.getValue().getString(),2); 
      } 
     } 
+0

我已经有一个对我的代码块没有显示的session.save的调用。我确实试图移动上面显示的session.save,但它仍然没有保存节点。任何其他想法?调试这种问题的最佳方法是什么? – rnolen 2015-02-12 15:38:57

0

我很欣赏的投入,我终于想通了,是什么原因导致我的问题:我已经创建了两个ResourceResolver情况下,所以我保存会话显然从正在创建的节点,其中一个不同的会话。那个会议没有被保存。