From a1549380bf56b7b7699a0a91800e72afdd9795f5 Mon Sep 17 00:00:00 2001 From: N Smith Date: Mon, 27 Jun 2011 20:30:37 +0000 Subject: [PATCH] Implemented publishing-queue.post REST API method. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28632 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/repository.properties | 7 +- config/alfresco/web-publishing-context.xml | 121 +++++++++--------- .../publish_web_content_processdefinition.xml | 2 +- .../org/alfresco/repo/node/NodeUtils.java | 95 ++++++++++++++ .../repo/publishing/ChannelHelper.java | 2 + .../CheckPublishingDependenciesAction.java | 28 +++- .../publishing/PublishingEventHelper.java | 37 ++++-- .../repo/publishing/PublishingQueueImpl.java | 5 + 8 files changed, 218 insertions(+), 79 deletions(-) create mode 100644 source/java/org/alfresco/repo/node/NodeUtils.java diff --git a/config/alfresco/repository.properties b/config/alfresco/repository.properties index a8258b6afe..d3240213d6 100644 --- a/config/alfresco/repository.properties +++ b/config/alfresco/repository.properties @@ -652,4 +652,9 @@ encryption.keystore.password=mp6yc0UD9e # The password protecting the alias: metadata encryption.keystore.password.metadata=oKIWzVdEdA # The password protecting the alias: solr -encryption.keystore.password.solr=TxHTtOnrwQ \ No newline at end of file +encryption.keystore.password.solr=TxHTtOnrwQ + +# +# Web Publishing Properties +# +publishing.default.environment=live \ No newline at end of file diff --git a/config/alfresco/web-publishing-context.xml b/config/alfresco/web-publishing-context.xml index 2c4aae4ed0..6f0ffa46e8 100644 --- a/config/alfresco/web-publishing-context.xml +++ b/config/alfresco/web-publishing-context.xml @@ -2,7 +2,7 @@ - + alfresco/model/publishingModel.xml @@ -10,7 +10,7 @@ - + @@ -29,80 +29,83 @@ - - - - alfresco.messages.publishing-service - - - + + + + alfresco.messages.publishing-service + + + - - + + - - - + + + - - - - - - - + + + + + + + - + - + - - - + + + - + - - - - + + + + - - + + + + + - - - - - - - - - - + + + + + + + + + + - - + + - - - - - + + + + + + + + + + + + + - - - - - - - - - diff --git a/config/alfresco/workflow/publish_web_content_processdefinition.xml b/config/alfresco/workflow/publish_web_content_processdefinition.xml index a39da4e827..45e5855729 100644 --- a/config/alfresco/workflow/publish_web_content_processdefinition.xml +++ b/config/alfresco/workflow/publish_web_content_processdefinition.xml @@ -70,7 +70,7 @@ diff --git a/source/java/org/alfresco/repo/node/NodeUtils.java b/source/java/org/alfresco/repo/node/NodeUtils.java new file mode 100644 index 0000000000..0dd9ada2a9 --- /dev/null +++ b/source/java/org/alfresco/repo/node/NodeUtils.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +package org.alfresco.repo.node; + +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.util.collections.Filter; +import org.alfresco.util.collections.Function; + +/** + * @author Nick Smith + * @since 4.0 + * + */ +public abstract class NodeUtils +{ + public static Function toNodeRef() + { + return new Function() + { + public NodeRef apply(String value) + { + return new NodeRef(value); + } + }; + } + + public static Function toChildRef() + { + return new Function() + { + public NodeRef apply(ChildAssociationRef value) + { + return value.getChildRef(); + } + }; + } + + public static Function toParentRef() + { + return new Function() + { + public NodeRef apply(ChildAssociationRef value) + { + return value.getParentRef(); + } + }; + } + + public static Function toNodeRefQueitly() + { + return new Function() + { + public NodeRef apply(String value) + { + if(value!=null && NodeRef.isNodeRef(value)) + { + return new NodeRef(value); + } + return null; + } + }; + } + + public static Filter exists(final NodeService nodeService) + { + return new Filter() + { + public Boolean apply(NodeRef value) + { + return nodeService.exists(value); + } + }; + } + + +} diff --git a/source/java/org/alfresco/repo/publishing/ChannelHelper.java b/source/java/org/alfresco/repo/publishing/ChannelHelper.java index 9d2f9422ac..3b6a1b2286 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelHelper.java +++ b/source/java/org/alfresco/repo/publishing/ChannelHelper.java @@ -64,6 +64,8 @@ import org.alfresco.util.collections.Function; */ public class ChannelHelper { + public static final String NAME = "channelHelper"; + private NodeService nodeService; private DictionaryService dictionaryService; private FileFolderService fileFolderService; diff --git a/source/java/org/alfresco/repo/publishing/CheckPublishingDependenciesAction.java b/source/java/org/alfresco/repo/publishing/CheckPublishingDependenciesAction.java index 1f55097ef3..fa072addd2 100644 --- a/source/java/org/alfresco/repo/publishing/CheckPublishingDependenciesAction.java +++ b/source/java/org/alfresco/repo/publishing/CheckPublishingDependenciesAction.java @@ -19,13 +19,19 @@ package org.alfresco.repo.publishing; +import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_STATUS; +import static org.alfresco.repo.publishing.PublishingModel.TYPE_PUBLISHING_EVENT; + import java.util.List; import org.alfresco.repo.action.executer.ActionExecuter; import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; +import org.alfresco.service.cmr.publishing.PublishingEvent.Status; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.namespace.QName; /** * This {@link ActionExecuter} checks the status of the publishing event @@ -37,15 +43,19 @@ import org.alfresco.service.cmr.repository.NodeRef; */ public class CheckPublishingDependenciesAction extends ActionExecuterAbstractBase { - + private NodeService nodeService; + /** * {@inheritDoc} */ @Override - protected void executeImpl(Action action, NodeRef actionedUponNodeRef) + protected void executeImpl(Action action, NodeRef node) { - // TODO Implement execute method. - + QName nodeType = nodeService.getType(node); + if(TYPE_PUBLISHING_EVENT.equals(nodeType)) + { + nodeService.setProperty(node, PROP_PUBLISHING_EVENT_STATUS, Status.IN_PROGRESS); + } } /** @@ -54,8 +64,14 @@ public class CheckPublishingDependenciesAction extends ActionExecuterAbstractBas @Override protected void addParameterDefinitions(List paramList) { - // TODO Implement parameter definitions. - + //NOOP } + /** + * @param nodeService the nodeService to set + */ + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } } diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java b/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java index 33dde14ef0..5a63520f61 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java +++ b/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java @@ -52,6 +52,7 @@ import java.util.TimeZone; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; +import org.alfresco.repo.node.NodeUtils; import org.alfresco.repo.workflow.WorkflowModel; import org.alfresco.service.cmr.publishing.PublishingEvent; import org.alfresco.service.cmr.publishing.PublishingEvent.Status; @@ -69,7 +70,10 @@ import org.alfresco.service.cmr.workflow.WorkflowPath; import org.alfresco.service.cmr.workflow.WorkflowService; import org.alfresco.service.cmr.workflow.WorkflowTask; import org.alfresco.service.namespace.QName; +import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.util.GUID; +import org.alfresco.util.collections.CollectionUtils; +import org.alfresco.util.collections.Filter; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -243,27 +247,36 @@ public class PublishingEventHelper return results; } - public List findPublishingEventNodes(NodeRef queue, PublishingEventFilter filter) + public List findPublishingEventNodes(final NodeRef queue, PublishingEventFilter filter) { - List results = new ArrayList(); Set ids = filter.getIds(); - if(ids != null) + if(ids != null && ids.isEmpty() == false) { - for (String id : ids) + List nodes = CollectionUtils.transform(ids, NodeUtils.toNodeRefQueitly()); + // Filter out nodes that are not Publishing Events on the specified queue. + return CollectionUtils.filter(nodes, new Filter() { - NodeRef eventNode = new NodeRef(id); - if (nodeService.exists(eventNode)) + public Boolean apply(NodeRef node) { - ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(eventNode); - if (parentAssoc.getParentRef().equals(queue) - && ASSOC_PUBLISHING_EVENT.equals(parentAssoc.getTypeQName())) + if(nodeService.exists(node)) { - results.add(eventNode); + ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(node); + if (parentAssoc.getParentRef().equals(queue) + && ASSOC_PUBLISHING_EVENT.equals(parentAssoc.getTypeQName())) + { + return true; + } } + return false; } - } + }); + } + else + { + List assocs = nodeService.getChildAssocs(queue, + ASSOC_PUBLISHING_EVENT, RegexQNamePattern.MATCH_ALL); + return CollectionUtils.transform(assocs, NodeUtils.toChildRef()); } - return results; } public List findPublishingEvents(NodeRef queue, PublishingEventFilter filter) diff --git a/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java b/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java index fc072dd337..a3804c038f 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java +++ b/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java @@ -72,6 +72,11 @@ public class PublishingQueueImpl implements PublishingQueue */ public String scheduleNewEvent(PublishingPackage publishingPackage, String channelName, Calendar schedule, String comment, StatusUpdate statusUpdate) { + if(schedule == null) + { + schedule = Calendar.getInstance(); + schedule.add(Calendar.SECOND, 1); + } try { NodeRef eventNode = publishingEventHelper.createNode(nodeRef, publishingPackage, channelName, schedule, comment, statusUpdate);