felipeek
felipeek

Reputation: 1213

CMIS Versioning not working as expected

I'm creating a file on my document service with CMIS API using the following code:

zipMapFile.put(PropertyIds.OBJECT_TYPE_ID, "sap:versioned");
zipMapFile.put(PropertyIds.NAME, "g" + g.getId() + ".zip");
Document versionedDocument = openCmisSession.getRootFolder().createDocument(zipMapFile, contentStream, VersioningState.MAJOR);
newZipFileId = versionedDocument.checkOut();
...

The code above is working and the file is being correctly generated. When I run the following code:

cmisSession.getObject(newZipFileId.getId());

I get the file that I created before, with no errors.

However, I'm having a problem when I try to upload a new version for this file.

To do this, I'm using the following piece of code:

oldZipFileId = newZipFileId;
Document pwc = (Document) cmisSession.getObject(oldZipFileId);
pwc.setContentStream(contentStream, true);
newZipFileId = pwc.checkIn(false, null, null, null);

Whenever I do this, I can access the newer version with no problems running the following code:

cmisSession.getObject(newZipFileId.getId());

However, I can't access the older version anymore! If I try to run:

cmisSession.getObject(oldZipFileId);

I get an CmisObjectNotFoundException

The moment that I lose the access to the older version is exactly when the method pwc.checkIn(false, null, null, null); is executed. After this call, trying to get the object referenced by oldZipId gives me a CmisObjectNotFoundException.

I'm using MongoDB.

Any help is appreciated! Thank you!

Upvotes: 0

Views: 626

Answers (3)

achim
achim

Reputation: 21

And the working code should look like the following:

Document versionedDocument = openCmisSession.getRootFolder().createDocument(zipMapFile, contentStream, VersioningState.MAJOR);
oldZipFileId = versionedDocument.getId();

newZipFileId = versionedDocument.checkOut();
Document pwc = (Document) cmisSession.getObject(newZipFileId);
pwc.setContentStream(contentStream, true);
newZipFileId = pwc.checkIn(false, null, null, null);

// access last version
cmisSession.getObject(newZipFileId.getId());

// access old version
cmisSession.getObject(oldZipFileId);

Upvotes: 2

Heiko Kiessling
Heiko Kiessling

Reputation: 11

Although I'm not an expert with versioning in the HCP Document Service everything you write works as designed AFAIK. When you checkIn a pwc there will be a new actual version (latest version in the history), and the pwc is gone. Consequently, your oldZipFileId identifying the pwc becomes invalid. The new actual version that the pwc became gets a new object id. This seems to be exactly what you observed.

Upvotes: 1

daves
daves

Reputation: 21

See if the old version is in document.getAllVersions().

Upvotes: 0

Related Questions