diff --git a/source/java/org/alfresco/repo/node/NodeUtils.java b/source/java/org/alfresco/repo/node/NodeUtils.java index a7b930f44b..7ff20e436b 100644 --- a/source/java/org/alfresco/repo/node/NodeUtils.java +++ b/source/java/org/alfresco/repo/node/NodeUtils.java @@ -19,9 +19,16 @@ package org.alfresco.repo.node; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import org.alfresco.model.ContentModel; import org.alfresco.service.cmr.repository.AssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; @@ -130,4 +137,38 @@ public abstract class NodeUtils } return null; } + + public List sortByCreationDate(NodeService nodeService,Collection nodes) + { + ArrayList sorted = new ArrayList(nodes); + Collections.sort(sorted, getNodeCreationDateComparator(nodeService)); + return sorted; + } + + public Comparator getNodeCreationDateComparator(final NodeService nodeService) + { + return new Comparator() + { + private Map dates = new HashMap(); + + public int compare(NodeRef o1, NodeRef o2) + { + long date1 = getDate(o1); + long date2 = getDate(o1); + return (int)(date1 - date2); + } + + private long getDate(NodeRef node) + { + Long date = dates.get(node); + if(date == null) + { + Date dateObj = (Date) nodeService.getProperty(node, ContentModel.PROP_CREATED); + date = dateObj == null ? -1 : dateObj.getTime(); + dates.put(node, date); + } + return date; + } + }; + } } diff --git a/source/java/org/alfresco/repo/publishing/PublishServiceImpl.java b/source/java/org/alfresco/repo/publishing/PublishServiceImpl.java index f414a1a663..4fb9dfba67 100644 --- a/source/java/org/alfresco/repo/publishing/PublishServiceImpl.java +++ b/source/java/org/alfresco/repo/publishing/PublishServiceImpl.java @@ -20,6 +20,7 @@ package org.alfresco.repo.publishing; import java.util.Collection; +import java.util.List; import java.util.Map; import org.alfresco.service.cmr.publishing.NodePublishStatus; @@ -65,6 +66,26 @@ public class PublishServiceImpl implements PublishingService return publishingEventHelper.getPublishingEvent(id); } + /** + * {@inheritDoc} + */ + public List getEventsForPublishedNode(NodeRef publishedNode) + { + NodeRef queueNode = rootObject.getPublishingQueue().getNodeRef(); + List eventNodes = publishingEventHelper.getEventNodesForPublishedNode(queueNode, publishedNode); + return publishingEventHelper.getPublishingEvents(eventNodes); + } + + /** + * {@inheritDoc} + */ + public List getEventsForUnpublishedNode(NodeRef unpublishedNode) + { + NodeRef queueNode = rootObject.getPublishingQueue().getNodeRef(); + List eventNodes = publishingEventHelper.getEventNodesForUnpublishedNode(queueNode, unpublishedNode); + return publishingEventHelper.getPublishingEvents(eventNodes); + } + /** * {@inheritDoc} */ @@ -77,7 +98,7 @@ public class PublishServiceImpl implements PublishingService /** * {@inheritDoc} */ - public PublishingQueue getPublishingQueue(String siteId) + public PublishingQueue getPublishingQueue() { return rootObject.getPublishingQueue(); } diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java b/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java index 8d45dc808d..a17ac2fe7a 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java +++ b/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java @@ -307,16 +307,63 @@ public class PublishingEventHelper */ public List getEventNodesForPublishedNodes(final NodeRef queue, Collection publishedNodes) { - Function> transformer = new Function>() + return getEventNodesForNodeProperty(queue, PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH, publishedNodes); + } + + /** + * Returns a {@link List} of the {@link NodeRef}s representing PublishingEvents that were scheduled to unpublish at least one of the specified unpublishedNodes. + * @param queue + * @param unpublishedNodes + * @return + */ + public List getEventNodesForUnpublishedNodes(final NodeRef queue, Collection unpublishedNodes) + { + return getEventNodesForNodeProperty(queue, PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH, unpublishedNodes); + } + + /** + * Returns a {@link List} of the {@link NodeRef}s representing PublishingEvents that were scheduled to publish the specified publishedNode. + * @param queue + * @param publishedNode + * @return + */ + public List getEventNodesForPublishedNode(final NodeRef queue, NodeRef publishedNode) + { + Function> transformer = eventNodeForNodePropertyFinder(queue, PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH); + return transformer.apply(publishedNode); + } + + /** + * Returns a {@link List} of the {@link NodeRef}s representing PublishingEvents that were scheduled to unpublish the specified unpublishedNode. + * @param queue + * @param unpublishedNode + * @return + */ + public List getEventNodesForUnpublishedNode(final NodeRef queue, NodeRef unpublishedNode) + { + Function> transformer = eventNodeForNodePropertyFinder(queue, PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH); + return transformer.apply(unpublishedNode); + } + + private List getEventNodesForNodeProperty(final NodeRef queue, final QName propertyKey, Collection publishedNodes) + { + Function> transformer = eventNodeForNodePropertyFinder(queue, propertyKey); + return transformFlat(publishedNodes, transformer); + } + + private Function> eventNodeForNodePropertyFinder(final NodeRef queue, + final QName propertyKey) + { + return new Function>() { - public Collection apply(NodeRef publishedNode) + public List apply(NodeRef publishedNode) { - List assocs = nodeService.getChildAssocsByPropertyValue(queue, PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH, publishedNode.toString()); + String nodeString = publishedNode.toString(); + List assocs = + nodeService.getChildAssocsByPropertyValue(queue, propertyKey, nodeString); return transform(assocs, NodeUtils.toChildRef()); } }; - List nodes = transformFlat(publishedNodes, transformer); - return nodes; } public List findPublishingEvents(NodeRef queue, PublishingEventFilter filter) diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventImpl.java b/source/java/org/alfresco/repo/publishing/PublishingEventImpl.java index 9ec3d7adae..c5cd5b68c5 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingEventImpl.java +++ b/source/java/org/alfresco/repo/publishing/PublishingEventImpl.java @@ -183,4 +183,22 @@ public class PublishingEventImpl implements PublishingEvent return new MutablePublishingEventImpl(this); } + /** + * {@inheritDoc} + */ + @Override + public int compareTo(PublishingEvent event) + { + if(event == null) + { + return 1; + } + Date eventTime = event.getCreatedTime(); + if(eventTime == null) + { + return 1; + } + return (int)(createdTime.getTime() - eventTime.getTime()); + } + } diff --git a/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java b/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java index 55276b57a1..cad35b55a8 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java +++ b/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java @@ -84,7 +84,7 @@ public class PublishingIntegratedTest extends BaseSpringTest NamespaceService.CONTENT_MODEL_1_0_URI, Integer.toString(i)), ContentModel.TYPE_CONTENT).getChildRef()); } - PublishingQueue liveQueue = publishingService.getPublishingQueue(siteId); + PublishingQueue liveQueue = publishingService.getPublishingQueue(); MutablePublishingPackage publishingPackage = liveQueue.createPublishingPackage(); publishingPackage.addNodesToPublish(nodes); @@ -117,7 +117,7 @@ public class PublishingIntegratedTest extends BaseSpringTest nodes.add(nodeService.createNode(channel.getNodeRef(), ContentModel.ASSOC_CONTAINS, QName.createQName( NamespaceService.CONTENT_MODEL_1_0_URI, Integer.toString(i)), ContentModel.TYPE_CONTENT).getChildRef()); } - PublishingQueue liveQueue = publishingService.getPublishingQueue(siteId); + PublishingQueue liveQueue = publishingService.getPublishingQueue(); MutablePublishingPackage publishingPackage = liveQueue.createPublishingPackage(); publishingPackage.addNodesToPublish(nodes); diff --git a/source/java/org/alfresco/service/cmr/publishing/PublishingEvent.java b/source/java/org/alfresco/service/cmr/publishing/PublishingEvent.java index de0fe58208..963826d1bf 100644 --- a/source/java/org/alfresco/service/cmr/publishing/PublishingEvent.java +++ b/source/java/org/alfresco/service/cmr/publishing/PublishingEvent.java @@ -25,9 +25,9 @@ import java.util.Date; /** * @author Brian - * + * @author Nick Smith */ -public interface PublishingEvent +public interface PublishingEvent extends Comparable { enum Status {SCHEDULED, IN_PROGRESS, CANCEL_REQUESTED, COMPLETED, FAILED} diff --git a/source/java/org/alfresco/service/cmr/publishing/PublishingQueue.java b/source/java/org/alfresco/service/cmr/publishing/PublishingQueue.java index 4789dd416a..b0668dc4d4 100644 --- a/source/java/org/alfresco/service/cmr/publishing/PublishingQueue.java +++ b/source/java/org/alfresco/service/cmr/publishing/PublishingQueue.java @@ -21,7 +21,6 @@ package org.alfresco.service.cmr.publishing; import java.util.Calendar; import java.util.Collection; -import java.util.List; import org.alfresco.service.cmr.repository.NodeRef; @@ -47,18 +46,4 @@ public interface PublishingQueue * @return The identifier of the newly scheduled event */ String scheduleNewEvent(PublishingPackage publishingPackage, String channelId, Calendar schedule, String comment, StatusUpdate statusUpdate); - - /** - * Retrieve a list of publishing events associated with this publishing environment, filtering them using the - * supplied PublishingEventFilter object (optional - may be null) - * @param filter The filter that is to be applied to the publishing events on this environment - * @return A list of PublishingEvent objects representing the publishing events that matched the supplied filter on this publishing environment - */ - List getPublishingEvents(PublishingEventFilter filter); - - /** - * A factory method that creates a {@link PublishingEventFilter} object. - * @return a new {@link PublishingEventFilter}. - */ - PublishingEventFilter createPublishingEventFilter(); } diff --git a/source/java/org/alfresco/service/cmr/publishing/PublishingService.java b/source/java/org/alfresco/service/cmr/publishing/PublishingService.java index e867b58ea0..2e7d95bbf3 100644 --- a/source/java/org/alfresco/service/cmr/publishing/PublishingService.java +++ b/source/java/org/alfresco/service/cmr/publishing/PublishingService.java @@ -19,6 +19,7 @@ package org.alfresco.service.cmr.publishing; import java.util.Collection; +import java.util.List; import java.util.Map; import org.alfresco.service.cmr.repository.NodeRef; @@ -26,7 +27,6 @@ import org.alfresco.service.cmr.repository.NodeRef; public interface PublishingService { - /** * Retrieve the publishing event that has the specified identifier * @@ -37,6 +37,20 @@ public interface PublishingService */ PublishingEvent getPublishingEvent(String id); + /** + * Retrieve a list of publishing events for which the specified node was published. + * @param publishedNode The node that was published. + * @return A list of {@link PublishingEvent}s. + */ + List getEventsForPublishedNode(NodeRef publishedNode); + + /** + * Retrieve a list of publishing events for which the specified node was unpublished. + * @param unpublishedNode The node that was unpublished. + * @return A list of {@link PublishingEvent}s. + */ + List getEventsForUnpublishedNode(NodeRef unpublishedNode); + /** * Request that the specified publishing event be cancelled. This call will * cancel the identified publishing event immediately if it hasn't been @@ -51,7 +65,7 @@ public interface PublishingService * Retrieve the publishing queue associated with this publishing environment * @return A PublishingQueue object corresponding tho this environment's publishing queue */ - PublishingQueue getPublishingQueue(String siteId); + PublishingQueue getPublishingQueue(); /** * Discover the publishing status of each of the specified nodes