2013-02-25 1804 views
0

有人可以发布创建新文档所需的OpenCMIS代码,然后通过更新其内容流来更新该文档吗?我不想丢失原始文档 - 我想在新文档更新时保留版本历史记录。我正在使用Alfresco,但这应该适用于任何CMIS存储库。使用OpenCMIS创建和更新文档,同时保持版本历史记录

+0

你是什么意思与 “维护版本”?就像,你想要坚持或控制版本号? – skuro 2013-02-25 12:16:02

+0

当我使用document.setContentStream(..)更新Document时,它应该通过它自己更改版本并更改文档的内容,并将这两个文档保留在版本History中。我想要这样 – user2106213 2013-02-25 12:19:32

+0

你可以请发布代码创建文件?与版本控制? – user2106213 2013-02-25 12:31:04

回答

7

在露天,创建一个新的版本,只是让被检出后,返回给你的私人工作副本,更新PWC的内容流,然后检查回。Alfresco的将管理的版本为您服务。这是一个例子。

Folder folder = (Folder) getSession().getObjectByPath("/cmis-demo"); 

String timeStamp = new Long(System.currentTimeMillis()).toString(); 
String filename = "cmis-demo-doc (" + timeStamp + ")"; 

// Create a doc 
Map <String, Object> properties = new HashMap<String, Object>(); 
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); 
properties.put(PropertyIds.NAME, filename); 
String docText = "This is a sample document"; 
byte[] content = docText.getBytes(); 
InputStream stream = new ByteArrayInputStream(content); 
ContentStream contentStream = getSession().getObjectFactory().createContentStream(filename, Long.valueOf(content.length), "text/plain", stream); 

Document doc = folder.createDocument(
      properties, 
      contentStream, 
      VersioningState.MAJOR); 

System.out.println("Created: " + doc.getId()); 
System.out.println("Content Length: " + doc.getContentStreamLength()); 
System.out.println("Version label:" + doc.getVersionLabel()); 

// Now update it with a new version 
if (doc.getAllowableActions().getAllowableActions().contains(org.apache.chemistry.opencmis.commons.enums.Action.CAN_CHECK_OUT)) { 
    doc.refresh(); 
    String testName = doc.getContentStream().getFileName(); 
    ObjectId idOfCheckedOutDocument = doc.checkOut(); 
    Document pwc = (Document) session.getObject(idOfCheckedOutDocument); 
    docText = "This is a sample document with an UPDATE"; 
    content = docText.getBytes(); 
    stream = new ByteArrayInputStream(content);   
    contentStream = getSession().getObjectFactory().createContentStream(filename, Long.valueOf(content.length), "text/plain", stream);   
    ObjectId objectId = pwc.checkIn(false, null, contentStream, "just a minor change"); 
    doc = (Document) session.getObject(objectId); 
    System.out.println("Version label is now:" + doc.getVersionLabel()); 
} 

运行时,它输出这样的:

Created: workspace://SpacesStore/d6f3fca2-bf9c-4a0e-8141-088d07d45359;1.0 
Content Length: 25 
Version label:1.0 
Version label is now:1.1 
Done 
+0

非常感谢你...我想知道更多的事情,我们可以将标签更改为2.0而不是1.1? – user2106213 2013-02-26 07:04:19

+0

是的,你只需要将主标志从false更改为true,所以你应该这样做:ObjectId objectId = pwc.checkIn(true,null,contentStream,“这是一个重大改变”); – 2013-02-27 01:22:58

+0

谢谢你杰夫......你是天才 – user2106213 2013-02-27 05:29:25

相关问题