새 문서를 만들고 콘텐츠 스트림을 업데이트하여 문서를 업데이트하는 데 필요한 OpenCMIS 코드를 게시 할 수 있습니까? 원본 문서를 잃고 싶지 않습니다. 새 문서가 업데이트 될 때 버전 기록을 유지하고 싶습니다. Alfresco를 사용하고 있지만 이것은 모든 CMIS 저장소에 적용 가능해야합니다.OpenCMIS를 사용하여 버전 기록을 유지하면서 문서를 만들고 업데이트하십시오.
답변
새 버전을 만들려면 체크 아웃 후 반환되는 개인 작업 복사본을 얻고 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
정말 고마워요. 라벨을 1.1 대신 2.0으로 바꿀 수있는 것과 같은 것을 하나 더 알고 싶습니다. ?? – user2106213
예, major 플래그를 false에서 true로 변경하면됩니다. ObjectId objectId = pwc.checkIn (true, null, contentStream, "this is a major change"); –
Jeff에게 감사드립니다 ... 당신은 천재입니다. – user2106213
당신이 "버전을 유지"무엇을 의미합니까? 마찬가지로 버전 번호를 유지하거나 제어하고 싶습니까? – skuro
document.setContentStream (..)으로 문서를 업데이트하면 문서 자체의 버전이 변경되고 문서의 내용이 변경되어 버전 기록에 문서가 모두 유지됩니다. 나는 이것을 좋아한다 – user2106213
당신은 문서를 만들 수있는 코드를 올리시겠습니까 ?? 버전 관리가 필요 하신가요? – user2106213