From: Mathieu Baudier Date: Sat, 24 Jun 2023 05:18:00 +0000 (+0200) Subject: Adapt to changes in Argeo Commons X-Git-Tag: v2.3.15~5 X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-jcr.git;a=commitdiff_plain;h=430186c4592de79dee70eb0b1ddab03ca89125d7 Adapt to changes in Argeo Commons --- diff --git a/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java b/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java index 258facc..5fc7d7c 100644 --- a/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java +++ b/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrContentProvider.java @@ -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 doInAdminSession(Function 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 doInAdminSession(Function toDo) { + try { + return toDo.apply(adminSession); + } finally { + try { + if (adminSession.hasPendingChanges()) + adminSession.save(); + } catch (RepositoryException e) { + throw new JcrException("Cannot save admin session", e); + } + } + } + } diff --git a/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrSessionAdapter.java b/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrSessionAdapter.java index e1ded7d..0fc46b8 100644 --- a/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrSessionAdapter.java +++ b/org.argeo.cms.jcr/src/org/argeo/cms/jcr/acr/JcrSessionAdapter.java @@ -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); diff --git a/org.argeo.cms.jcr/src/org/argeo/cms/jcr/internal/servlet/CmsSessionProvider.java b/org.argeo.cms.jcr/src/org/argeo/cms/jcr/internal/servlet/CmsSessionProvider.java index 4e067ee..7c8e95f 100644 --- a/org.argeo.cms.jcr/src/org/argeo/cms/jcr/internal/servlet/CmsSessionProvider.java +++ b/org.argeo.cms.jcr/src/org/argeo/cms/jcr/internal/servlet/CmsSessionProvider.java @@ -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() { diff --git a/swt/org.argeo.cms.jcr.ui/src/org/argeo/cms/ui/viewers/JcrVersionCmsEditable.java b/swt/org.argeo.cms.jcr.ui/src/org/argeo/cms/ui/viewers/JcrVersionCmsEditable.java index 42e8716..9122449 100644 --- a/swt/org.argeo.cms.jcr.ui/src/org/argeo/cms/ui/viewers/JcrVersionCmsEditable.java +++ b/swt/org.argeo.cms.jcr.ui/src/org/argeo/cms/ui/viewers/JcrVersionCmsEditable.java @@ -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;