From 0c35c285bd16903b21c1878584fcacc3f74459b8 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Fri, 28 Jul 2006 15:27:28 +0000 Subject: [PATCH] . JavaScript API enhancements checkpoint: - checkout() - perform a checkout of a node, returning the working-copy as the result - checkin() - perform a checkin of a working-copy node, returning the original as the result - cancelCheckout() - cancel the checkout of a work-copy node . Fix from Roy to VersionableAspect to correctly handle making a node versionable, setting content and checking in/out all within a single transaction git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3434 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../java/org/alfresco/repo/jscript/Node.java | 144 +++++++++++++++--- .../org/alfresco/repo/jscript/Search.java | 7 +- .../repo/version/VersionableAspect.java | 14 +- 3 files changed, 134 insertions(+), 31 deletions(-) diff --git a/source/java/org/alfresco/repo/jscript/Node.java b/source/java/org/alfresco/repo/jscript/Node.java index 2d191070b7..edc57e7750 100644 --- a/source/java/org/alfresco/repo/jscript/Node.java +++ b/source/java/org/alfresco/repo/jscript/Node.java @@ -31,6 +31,7 @@ import java.util.StringTokenizer; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.repo.security.permissions.AccessDeniedException; +import org.alfresco.repo.version.VersionModel; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.InvalidAspectException; @@ -49,6 +50,8 @@ import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.TemplateImageResolver; import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.service.cmr.version.Version; +import org.alfresco.service.cmr.version.VersionType; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.RegexQNamePattern; @@ -121,6 +124,19 @@ public final class Node implements Serializable, Scopeable * @param resolver Image resolver to use to retrieve icons */ public Node(NodeRef nodeRef, ServiceRegistry services, TemplateImageResolver resolver) + { + this(nodeRef, services, resolver, null); + } + + /** + * Constructor + * + * @param nodeRef The NodeRef this Node wrapper represents + * @param services The ServiceRegistry the Node can use to access services + * @param resolver Image resolver to use to retrieve icons + * @param scope Root scope for this Node + */ + public Node(NodeRef nodeRef, ServiceRegistry services, TemplateImageResolver resolver, Scriptable scope) { if (nodeRef == null) { @@ -137,6 +153,7 @@ public final class Node implements Serializable, Scopeable this.services = services; this.nodeService = services.getNodeService(); this.imageResolver = resolver; + this.scope = scope; } /** @@ -258,8 +275,8 @@ public final class Node implements Serializable, Scopeable for (int i=0; i props = new HashMap(2, 1.0f); + props.put(Version.PROP_DESCRIPTION, history); + props.put(VersionModel.PROP_VERSION_TYPE, majorVersion ? VersionType.MAJOR : VersionType.MINOR); + NodeRef original = this.services.getCheckOutCheckInService().checkin(this.nodeRef, props); + return new Node(original, this.services, this.imageResolver, this.scope); + } + + /** + * Cancel the check-out of a working copy document. The working copy will be deleted and any + * changes made to it are lost. Note that this method can only be called on a working copy Node. + * The reference to this working copy Node should be discarded. + * + * @return the original Node that was checked out. + */ + public Node cancelCheckout() + { + NodeRef original = this.services.getCheckOutCheckInService().cancelCheckout(this.nodeRef); + return new Node(original, this.services, this.imageResolver, this.scope); + } // ------------------------------------------------------------------------------ @@ -1403,8 +1509,7 @@ public final class Node implements Serializable, Scopeable if (nodes.size() != 0) { result = new Node[1]; - result[0] = new Node(nodes.get(0), this.services, this.imageResolver); - result[0].setScope(this.scope); + result[0] = new Node(nodes.get(0), this.services, this.imageResolver, this.scope); } } // or all the results @@ -1414,8 +1519,7 @@ public final class Node implements Serializable, Scopeable for (int i=0; i versionDetails = new HashMap(1); - versionDetails.put(Version.PROP_DESCRIPTION, I18NUtil.getMessage(MSG_INITIAL_VERSION)); - this.versionService.createVersion(nodeRef, versionDetails); + Map versionedNodeRefs = (Map)AlfrescoTransactionSupport.getResource(KEY_VERSIONED_NODEREFS); + if (versionedNodeRefs == null || versionedNodeRefs.containsKey(nodeRef) == false) + { + // Queue create version action + Map versionDetails = new HashMap(1); + versionDetails.put(Version.PROP_DESCRIPTION, I18NUtil.getMessage(MSG_INITIAL_VERSION)); + this.versionService.createVersion(nodeRef, versionDetails); + } } } }