Невозможно получить версионные данные узла
Я создал узел, который содержит документ 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, а не обновленной версии, не уверен, что я делаю что-то не так?