无法检索节点的版本化数据

时间:2017-02-13 23:22:26

标签: jcr jackrabbit modeshape

我创建了一个包含MS office word文档的节点。

  VersionManager versionManager = session.getWorkspace().getVersionManager();
                    File wordFile = new File("DMS.docx");
                     Node documentNode = rootNode.addNode("Documents");
                     Node fileNode = documentNode.addNode(wordFile.getName(),"nt:file");
                     fileNode.addMixin("mix:versionable");

                     // Upload the file to that node ...
                     Node contentNode = fileNode.addNode("jcr:content", "nt:resource");
                     Binary binary = getFileBinary(wordFile);
                     contentNode.setProperty("jcr:data", binary);
                     session.save();
                     Version v1 =   versionManager.checkin(fileNode.getPath());

现在我通过versionManager检出文件并更新内容,然后再回来查看。

  fileNode = session.getRootNode().getNode("Documents").getNode(wordFile.getName());
                             versionManager.checkout(fileNode.getPath());
    java.nio.file.Path path = Paths.get("DMSUpdated.docx");
                         if (!Files.exists(path)) {
                             Files.createFile(path);
                         }
                         Files.write(path, "Text to be added".getBytes(), StandardOpenOption.APPEND);
                         Binary updatedBinary = getFileBinary(new File(filePath));
                         contentNode.setProperty("jcr:data", updatedBinary);

                         session.save();
//check - in
 Version updatedVersion =   versionManager.checkin(fileNode.getPath());

现在我正在尝试将节点恢复到更新版本,如下所示:

Node finalFileNode =   session.getNode("/Documents").getNode(wordFile.getName());
          versionManager.restore(finalFileNode.getPath(),updatedVersion,false);
    Node finalContentNode = finalFileNode.getNode("jcr:content");
                 InputStream initialStream = finalContentNode.getProperty("jcr:data").getBinary().getStream();
                    byte[] buffer = new byte[initialStream.available()];
                    initialStream.read(buffer);
                      File updatedFile = new File("//TestFiles//FinalDMS.docx");
                    OutputStream outStream = new FileOutputStream(updatedFile);
                    outStream.write(buffer);

这给了我v1版本的内容而没有更新版本,不确定我做错了什么?

0 个答案:

没有答案