Adapt to changes in Argeo Commons
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 24 Jun 2023 05:18:00 +0000 (07:18 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 24 Jun 2023 05:18:00 +0000 (07:18 +0200)
org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java
org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrSessionAdapter.java
org.argeo.cms.jcr/src/org/argeo/cms/jcr/internal/servlet/CmsSessionProvider.java
swt/org.argeo.cms.jcr.ui/src/org/argeo/cms/ui/viewers/JcrVersionCmsEditable.java

index 258facc6c1b6c3658fc786ef4a45339eaaab8eab..5fc7d7c241d2496b040a13d2f2a0b68fa1fc7ed8 100644 (file)
@@ -61,10 +61,18 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext {
                this.jcrRepository = jcrRepository;
        }
 
+       @Override
+       public String getMountPath() {
+               return mountPath;
+       }
+
+       /*
+        * READ
+        */
+
        @Override
        public ProvidedContent get(ProvidedSession contentSession, String relativePath) {
-               String jcrPath = "/" + relativePath;
-               return new JcrContent(contentSession, this, jcrWorkspace, jcrPath);
+               return new JcrContent(contentSession, this, jcrWorkspace, toJcrPath(relativePath));
        }
 
        @Override
@@ -98,7 +106,7 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext {
        /*
         * WRITE
         */
-       public Node openForEdit(ProvidedSession contentSession, String jcrWorkspace, String jcrPath) {
+       Node openForEdit(ProvidedSession contentSession, String jcrWorkspace, String jcrPath) {
                try {
                        if (contentSession.isEditing()) {
                                JcrSessionAdapter sessionAdapter = getJcrSessionAdapter(contentSession);
@@ -121,21 +129,37 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext {
                }
        }
 
+       /*
+        * EDITING
+        */
+
        @Override
-       public String getMountPath() {
-               return mountPath;
+       public void openForEdit(ProvidedSession session, String relativePath) {
+               openForEdit(session, relativePath, toJcrPath(relativePath));
        }
 
-       public synchronized <T> T doInAdminSession(Function<Session, T> toDo) {
+       @Override
+       public void freeze(ProvidedSession session, String relativePath) {
                try {
-                       return toDo.apply(adminSession);
-               } finally {
-                       try {
-                               if (adminSession.hasPendingChanges())
-                                       adminSession.save();
-                       } catch (RepositoryException e) {
-                               throw new JcrException("Cannot save admin session", e);
+                       String jcrPath = toJcrPath(relativePath);
+                       if (session.isEditing()) {
+                               JcrSessionAdapter sessionAdapter = getJcrSessionAdapter(session);
+                               sessionAdapter.freeze(jcrWorkspace, jcrPath);
                        }
+               } catch (RepositoryException e) {
+                       throw new JcrException("Cannot freeze " + relativePath + " in workspace " + jcrWorkspace, e);
+               }
+       }
+
+       @Override
+       public boolean isOpenForEdit(ProvidedSession session, String relativePath) {
+               try {
+                       String jcrPath = toJcrPath(relativePath);
+                       JcrSessionAdapter sessionAdapter = getJcrSessionAdapter(session);
+                       return sessionAdapter.isOpenForEdit(jcrWorkspace, jcrPath);
+               } catch (RepositoryException e) {
+                       throw new JcrException(
+                                       "Cannot check whether " + relativePath + " is open for edit in workspace " + jcrWorkspace, e);
                }
        }
 
@@ -228,4 +252,33 @@ public class JcrContentProvider implements ContentProvider, NamespaceContext {
                }
 
        }
+
+       /*
+        * UTILITIES
+        */
+       /**
+        * Just adds a '/' so that it becomes an absolute JCR path within the JCR
+        * workspace of this provider.
+        */
+       private String toJcrPath(String relativePath) {
+               return ContentUtils.SLASH + relativePath;
+       }
+
+       /*
+        * TRANSITIONAL, WHILE MIGRATING FROM JCR TO ACR
+        */
+       @Deprecated
+       public synchronized <T> T doInAdminSession(Function<Session, T> toDo) {
+               try {
+                       return toDo.apply(adminSession);
+               } finally {
+                       try {
+                               if (adminSession.hasPendingChanges())
+                                       adminSession.save();
+                       } catch (RepositoryException e) {
+                               throw new JcrException("Cannot save admin session", e);
+                       }
+               }
+       }
+
 }
index e1ded7d1f8aab9141e05ef9e21cf409ad2a533a0..0fc46b8c9cc734f344ecc2233922a006734d20a5 100644 (file)
@@ -123,6 +123,24 @@ class JcrSessionAdapter {
                return node;
        }
 
+       public synchronized Node freeze(String workspace, String jcrPath) throws RepositoryException {
+               Session session = getWriteSession(workspace);
+               Node node = session.getNode(jcrPath);
+               if (node.isNodeType(NodeType.MIX_SIMPLE_VERSIONABLE)) {
+                       VersionManager versionManager = session.getWorkspace().getVersionManager();
+                       if (versionManager.isCheckedOut(jcrPath)) {
+                               versionManager.checkin(jcrPath);
+                       }
+               }
+               return node;
+       }
+
+       public synchronized boolean isOpenForEdit(String workspace, String jcrPath) throws RepositoryException {
+               Session session = getWriteSession(workspace);
+               VersionManager versionManager = session.getWorkspace().getVersionManager();
+               return versionManager.isCheckedOut(jcrPath);
+       }
+
        public synchronized void persist() throws RepositoryException {
                for (String workspace : writeSessions.keySet()) {
                        Session session = writeSessions.get(workspace);
index 4e067eea25a01653e1e7a0fbb318687628497091..7c8e95f1e2f8fb786bd990b219e013909ddd2b44 100644 (file)
@@ -159,7 +159,7 @@ public class CmsSessionProvider implements SessionProvider, Serializable {
                private void checkValid() {
                        if (!cmsSession.isValid())
                                throw new IllegalStateException(
-                                               "CMS session " + cmsSession.getUuid() + " is not valid since " + cmsSession.getEnd());
+                                               "CMS session " + cmsSession.uuid() + " is not valid since " + cmsSession.getEnd());
                }
 
                protected void close() {
index 42e87161fced48b9b49650017edbcafba826bd0b..91224490a7aa4d8c54fffd03f3986ab0183bca90 100644 (file)
@@ -30,10 +30,10 @@ public class JcrVersionCmsEditable extends AbstractCmsEditable {
                if (node.getSession().hasPermission(node.getPath(), Session.ACTION_SET_PROPERTY)) {
                        // was Session.ACTION_ADD_NODE
                        canEdit = true;
-                       if (!node.isNodeType(NodeType.MIX_SIMPLE_VERSIONABLE)) {
-                               node.addMixin(NodeType.MIX_SIMPLE_VERSIONABLE);
-                               node.getSession().save();
-                       }
+//                     if (!node.isNodeType(NodeType.MIX_SIMPLE_VERSIONABLE)) {
+//                             node.addMixin(NodeType.MIX_SIMPLE_VERSIONABLE);
+//                             node.getSession().save();
+//                     }
                        versionManager = node.getSession().getWorkspace().getVersionManager();
                } else {
                        canEdit = false;