Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Feature 5.5.0 nxp 9260 cmis locking #1

Merged
merged 1 commit into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 22, 2012
  1. @ron1
This page is out of date. Refresh to see the latest.
View
24 ...opencmis-impl/src/main/java/org/nuxeo/ecm/core/opencmis/impl/server/NuxeoCmisService.java
@@ -1688,6 +1688,7 @@ public void checkIn(String repositoryId, Holder<String> objectIdHolder,
try {
coreSession.saveDocument(doc);
DocumentRef ver = doc.checkIn(option, checkinComment);
+ doc.removeLock();
coreSession.save();
objectIdHolder.setValue(getIdFromDocumentRef(ver));
} catch (ClientException e) {
@@ -1717,6 +1718,7 @@ public String checkIn(String objectId, boolean major,
try {
coreSession.saveDocument(doc);
DocumentRef ver = doc.checkIn(option, checkinComment);
+ doc.removeLock();
coreSession.save();
return getIdFromDocumentRef(ver);
} catch (ClientException e) {
@@ -1762,6 +1764,11 @@ public String checkOut(String objectId) {
throw new CmisConstraintException("Already checked out: "
+ objectId);
}
+ if (pwc.isLocked()) {
+ throw new CmisInvalidArgumentException(
+ "Cannot check out since currently locked: " + objectId);
+ }
+ pwc.setLock();
pwc.checkOut();
coreSession.save();
return pwc.getId();
@@ -1792,6 +1799,7 @@ public void cancelCheckOut(String objectId) {
} else {
// restore and keep checked in
coreSession.restoreToVersion(docRef, verRef, true, true);
+ doc.removeLock();
}
coreSession.save();
} catch (ClientException e) {
@@ -1965,7 +1973,21 @@ public void deleteObject(String repositoryId, String objectId,
@Override
public void deleteObjectOrCancelCheckOut(String repositoryId,
String objectId, Boolean allVersions, ExtensionsData extension) {
- deleteObject(repositoryId, objectId, allVersions, extension);
+ try {
+ DocumentModel doc = getDocumentModel(objectId);
+ DocumentRef docRef = doc.getRef();
+ // find last version
+ DocumentRef verRef = coreSession.getLastDocumentVersionRef(docRef);
+ // If doc has versions, is locked, and is checkedOut, then it was likely
+ // explicitly checkedOut so invoke cancelCheckOut not delete
+ if (verRef != null && doc.isLocked() && doc.isCheckedOut()) {
+ cancelCheckOut(repositoryId, objectId, extension);
+ } else {
+ deleteObject(repositoryId, objectId, allVersions, extension);
+ }
+ } catch (ClientException e) {
+ throw new CmisRuntimeException(e.toString(), e);
+ }
}
}
View
85 ...o-opencmis-tests/src/test/java/org/nuxeo/ecm/core/opencmis/impl/NuxeoSessionTestCase.java
@@ -44,11 +44,14 @@
import org.apache.chemistry.opencmis.commons.enums.RelationshipDirection;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
import org.apache.commons.io.IOUtils;
import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.CoreSession;
+import org.nuxeo.ecm.core.api.IdRef;
+import org.nuxeo.ecm.core.api.Lock;
import org.nuxeo.ecm.core.api.security.SecurityConstants;
import org.nuxeo.ecm.core.opencmis.impl.client.NuxeoSession;
import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoRepositories;
@@ -677,6 +680,80 @@ public void testVersioning() throws Exception {
checkValue(PropertyIds.CHECKIN_COMMENT, null, co);
}
+ public void testVersionBasedLocking() throws Exception {
+ CmisObject ob = session.getObjectByPath("/testfolder1/testfile1");
+
+ // implicitly checked out after create - unlocked
+ assertFalse(isDocumentLocked(ob));
+
+ ((Document) ob).checkIn(true, null, null, "comment");
+
+ // checked in - unlocked
+ assertFalse(isDocumentLocked(ob));
+
+ CmisObject ci = session.getObject(ob);
+ ObjectId coid = ((Document) ci).checkOut();
+ session.clear(); // clear cache
+ CmisObject co = session.getObject(coid);
+
+ // explicitly checked out - locked
+ assertTrue(isDocumentLocked(co));
+
+ ((Document) co).cancelCheckOut();
+ session.clear(); // clear cache
+ CmisObject cco = session.getObject(ob);
+
+ // cancelled check out - unlocked
+ assertFalse(isDocumentLocked(cco));
+
+ // cannot check out a locked document
+ lockDocument(cco);
+ try {
+ ((Document) cco).checkOut();
+ fail("Cannot check out a locked document");
+ } catch (CmisInvalidArgumentException e) {
+ // ok
+ }
+ }
+
+ public void testDeleteObjectOrCancelCheckOut() throws Exception {
+ // test cancelCheckOut
+ CmisObject ob = session.getObjectByPath("/testfolder1/testfile1");
+
+ ((Document) ob).checkIn(true, null, null, "comment");
+ ((Document) ob).checkOut();
+
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("dc:title", "new title");
+ map.put("dc:subjects", Arrays.asList("a", "b", "c"));
+ ob.updateProperties(map);
+
+ ((Document) ob).cancelCheckOut();
+
+ session.clear();
+ ob = session.getObjectByPath("/testfolder1/testfile1");
+ assertFalse("new title".equals(ob.getPropertyValue("dc:title")));
+
+ //test deleteObject
+ ob = session.getObjectByPath("/testfolder1/testfile2");
+
+ map = new HashMap<String, Object>();
+ map.put("dc:title", "new title");
+ map.put("dc:subjects", Arrays.asList("a", "b", "c"));
+ ob.updateProperties(map);
+
+ ((Document) ob).cancelCheckOut();
+
+ session.clear();
+ try {
+ ob = session.getObjectByPath("/testfolder1/testfile2");
+ fail("Document should be deleted");
+ } catch (CmisObjectNotFoundException e) {
+ // ok
+ }
+
+ }
+
public void testCheckInWithChanges() throws Exception {
CmisObject ob = session.getObjectByPath("/testfolder1/testfile1");
@@ -724,4 +801,12 @@ protected void checkValue(String prop, Object expected, CmisObject ob) {
}
}
+ private boolean isDocumentLocked(CmisObject ob) throws ClientException {
+ return getCoreSession().getDocument(new IdRef(ob.getId())).isLocked();
+ }
+
+ private Lock lockDocument(CmisObject ob) throws ClientException {
+ return getCoreSession().getDocument(new IdRef(ob.getId())).setLock();
+ }
+
}
Something went wrong with that request. Please try again.