Make JCR CMS editable more robust when rights are restricted
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 23 Oct 2022 05:57:33 +0000 (07:57 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 23 Oct 2022 05:57:33 +0000 (07:57 +0200)
swt/org.argeo.cms.jcr.ui/src/org/argeo/cms/ui/viewers/JcrVersionCmsEditable.java

index 298fbdea9b6d3dd2b58fc6e01d50a5cb954c58b8..256831468d5ab9334da2bf68d58981e873b6cc7b 100644 (file)
@@ -1,11 +1,13 @@
 package org.argeo.cms.ui.viewers;
 
+import javax.jcr.ItemNotFoundException;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.version.VersionManager;
 
+import org.argeo.api.cms.CmsLog;
 import org.argeo.api.cms.ux.CmsEditionEvent;
 import org.argeo.cms.ux.AbstractCmsEditable;
 import org.argeo.jcr.JcrException;
@@ -17,6 +19,8 @@ import org.eclipse.swt.widgets.Listener;
 
 /** Provides the CmsEditable semantic based on JCR versioning. */
 public class JcrVersionCmsEditable extends AbstractCmsEditable {
+       private final static CmsLog log = CmsLog.getLog(JcrVersionCmsEditable.class);
+
        private final String nodePath;// cache
        private final VersionManager versionManager;
        private final Boolean canEdit;
@@ -74,8 +78,8 @@ public class JcrVersionCmsEditable extends AbstractCmsEditable {
                try {
                        versionManager.checkout(nodePath);
 //                     setChanged();
-               } catch (RepositoryException e1) {
-                       throw new JcrException("Cannot publish " + nodePath, e1);
+               } catch (RepositoryException e) {
+                       throw new JcrException("Cannot publish " + nodePath, e);
                }
                notifyListeners(new CmsEditionEvent(nodePath, CmsEditionEvent.START_EDITING, this));
        }
@@ -85,8 +89,14 @@ public class JcrVersionCmsEditable extends AbstractCmsEditable {
                try {
                        versionManager.checkin(nodePath);
 //                     setChanged();
-               } catch (RepositoryException e1) {
-                       throw new JcrException("Cannot publish " + nodePath, e1);
+               } catch (ItemNotFoundException e) {
+                       // we ignore that the version was not found
+                       // since it is most likely because the user doesn't have the rights
+                       // on the whole workspace
+                       if (log.isTraceEnabled())
+                               log.trace("Cannot retrieve version after check in", e);
+               } catch (RepositoryException e) {
+                       throw new JcrException("Cannot publish " + nodePath, e);
                }
                notifyListeners(new CmsEditionEvent(nodePath, CmsEditionEvent.STOP_EDITING, this));
        }