From f198084c668c6550cd1c318d0e5566b14f5279ac Mon Sep 17 00:00:00 2001 From: N Smith Date: Wed, 29 Jun 2011 16:54:11 +0000 Subject: [PATCH] Added capability to search for published nodes on PublishingEventFilter. Also, improved robustness of publishing-queue.post REST method. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28704 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/publishing/EnvironmentHelper.java | 31 ++--- .../publishing/PublishingEventFilterImpl.java | 23 ++++ .../publishing/PublishingEventHelper.java | 125 ++++++++++++------ .../repo/publishing/PublishingQueueImpl.java | 1 - .../springsocial/ConnectionSerializer.java | 45 +++++++ .../springsocial/OAuth1ChannelType.java | 71 ++++++++++ .../cmr/publishing/PublishingEventFilter.java | 6 + 7 files changed, 239 insertions(+), 63 deletions(-) create mode 100644 source/java/org/alfresco/repo/publishing/springsocial/ConnectionSerializer.java create mode 100644 source/java/org/alfresco/repo/publishing/springsocial/OAuth1ChannelType.java diff --git a/source/java/org/alfresco/repo/publishing/EnvironmentHelper.java b/source/java/org/alfresco/repo/publishing/EnvironmentHelper.java index 163e242746..4041e9ddb4 100644 --- a/source/java/org/alfresco/repo/publishing/EnvironmentHelper.java +++ b/source/java/org/alfresco/repo/publishing/EnvironmentHelper.java @@ -19,20 +19,15 @@ package org.alfresco.repo.publishing; -import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH; import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_STATUS; -import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_TIME; -import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_TIME_ZONE; import java.io.Serializable; import java.util.Calendar; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.TimeZone; import java.util.TreeMap; import org.alfresco.model.ContentModel; @@ -59,6 +54,7 @@ import org.alfresco.util.ParameterCheck; * by both the channel service and the publishing service. * * @author Brian + * @author Nick Smith * */ public class EnvironmentHelper @@ -249,21 +245,20 @@ public class EnvironmentHelper NodeRef queue = getPublishingQueue(environment.getNodeRef()); Calendar nextPublishTime = null; NodeRef nextEventNode = null; - List results = nodeService.getChildAssocsByPropertyValue( queue, - PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH, node.toString()); - for (ChildAssociationRef childAssoc : results) + List eventNodes = publishingEventHelper.getEventNodesForPublishedNodes(queue, node); + for (NodeRef eventNode: eventNodes) { - NodeRef child = childAssoc.getChildRef(); - if (isActiveEvent(child)) + if (isActiveEvent(eventNode)) { - Serializable eventChannel = nodeService.getProperty(child, PublishingModel.PROP_PUBLISHING_EVENT_CHANNEL); + Map props = nodeService.getProperties(eventNode); + Serializable eventChannel = props.get(PublishingModel.PROP_PUBLISHING_EVENT_CHANNEL); if(channelName.equals(eventChannel)) { - Calendar schedule = getScheduledTime(child); + Calendar schedule = publishingEventHelper.getScheduledTime(props); if (nextPublishTime == null || schedule.before(nextPublishTime)) { nextPublishTime = schedule; - nextEventNode = child; + nextEventNode = eventNode; } } } @@ -271,16 +266,6 @@ public class EnvironmentHelper return publishingEventHelper.getPublishingEvent(nextEventNode); } - private Calendar getScheduledTime(NodeRef child) - { - Date time = (Date) nodeService.getProperty( child, PROP_PUBLISHING_EVENT_TIME); - String timeZone = (String) nodeService.getProperty( child,PROP_PUBLISHING_EVENT_TIME_ZONE); - Calendar schedule = Calendar.getInstance(); - schedule.setTimeZone(TimeZone.getTimeZone(timeZone)); - schedule.setTime(time); - return schedule; - } - private boolean isActiveEvent(NodeRef eventNode) { String statusStr = (String) nodeService.getProperty( eventNode, PROP_PUBLISHING_EVENT_STATUS); diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventFilterImpl.java b/source/java/org/alfresco/repo/publishing/PublishingEventFilterImpl.java index 2e2101d6ce..87805e8313 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingEventFilterImpl.java +++ b/source/java/org/alfresco/repo/publishing/PublishingEventFilterImpl.java @@ -25,6 +25,7 @@ import java.util.HashSet; import java.util.Set; import org.alfresco.service.cmr.publishing.PublishingEventFilter; +import org.alfresco.service.cmr.repository.NodeRef; /** * @author Nick Smith @@ -34,6 +35,7 @@ import org.alfresco.service.cmr.publishing.PublishingEventFilter; public class PublishingEventFilterImpl implements PublishingEventFilter { private Set ids = new HashSet(); + private Set publishedNodes = new HashSet(); /** * {@inheritDoc} @@ -54,5 +56,26 @@ public class PublishingEventFilterImpl implements PublishingEventFilter { return Collections.unmodifiableSet(ids); } + + /** + * {@inheritDoc} + */ + public PublishingEventFilter setPublishedNodes(NodeRef... publishedNodes) + { + if(ids != null && publishedNodes.length>0) + { + this.publishedNodes.addAll(Arrays.asList(publishedNodes)); + } + return this; + } + + /** + * {@inheritDoc} + */ + public Set getPublishedNodes() + { + // TODO Auto-generated method stub + return null; + } } diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java b/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java index 5a63520f61..6cc22b20c7 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java +++ b/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java @@ -31,16 +31,21 @@ import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_TIME_ZONE; import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_WORKFLOW_ID; import static org.alfresco.repo.publishing.PublishingModel.PROP_STATUS_UPDATE_CHANNEL_NAMES; -import static org.alfresco.repo.publishing.PublishingModel.PROP_STATUS_UPDATE_NODE_REF; import static org.alfresco.repo.publishing.PublishingModel.PROP_STATUS_UPDATE_MESSAGE; +import static org.alfresco.repo.publishing.PublishingModel.PROP_STATUS_UPDATE_NODE_REF; import static org.alfresco.repo.publishing.PublishingModel.PROP_WF_PUBLISHING_EVENT; import static org.alfresco.repo.publishing.PublishingModel.PROP_WF_SCHEDULED_PUBLISH_DATE; import static org.alfresco.repo.publishing.PublishingModel.TYPE_PUBLISHING_EVENT; +import static org.alfresco.util.collections.CollectionUtils.filter; +import static org.alfresco.util.collections.CollectionUtils.isEmpty; +import static org.alfresco.util.collections.CollectionUtils.toListOfStrings; +import static org.alfresco.util.collections.CollectionUtils.transform; +import static org.alfresco.util.collections.CollectionUtils.transformFlat; import java.io.InputStream; import java.io.OutputStream; import java.io.Serializable; -import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.Collection; import java.util.Date; @@ -72,14 +77,11 @@ 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.alfresco.util.collections.Function; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import com.google.common.base.Function; -import com.google.common.collect.Lists; - /** * @author Brian * @author Nick Smith @@ -182,7 +184,7 @@ public class PublishingEventHelper public List getPublishingEvents(List eventNodes) { - return Lists.transform(eventNodes, new Function() + return transform(eventNodes, new Function() { public PublishingEvent apply(NodeRef eventNode) { @@ -231,52 +233,88 @@ public class PublishingEventHelper if(statusUpdate != null) { props.put(PROP_STATUS_UPDATE_MESSAGE, statusUpdate.getMessage()); - props.put(PROP_STATUS_UPDATE_NODE_REF, statusUpdate.getNodeToLinkTo().toString()); + NodeRef statusNode = statusUpdate.getNodeToLinkTo(); + if(statusNode != null) + { + props.put(PROP_STATUS_UPDATE_NODE_REF, statusNode.toString()); + } props.put(PROP_STATUS_UPDATE_CHANNEL_NAMES, (Serializable) statusUpdate.getChannelNames()); } return props; } - private Collection mapNodesToStrings(Collection nodes) + private List mapNodesToStrings(Collection nodes) { - Collection results = new ArrayList(nodes.size()); - for (NodeRef node : nodes) - { - results.add(node.toString()); - } - return results; + return toListOfStrings(nodes); } public List findPublishingEventNodes(final NodeRef queue, PublishingEventFilter filter) { - Set ids = filter.getIds(); - if(ids != null && ids.isEmpty() == false) + List eventNodes; + Set publishedNodes = filter.getPublishedNodes(); + if(isEmpty(publishedNodes) == false) { - 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() - { - public Boolean apply(NodeRef node) - { - if(nodeService.exists(node)) - { - ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(node); - if (parentAssoc.getParentRef().equals(queue) - && ASSOC_PUBLISHING_EVENT.equals(parentAssoc.getTypeQName())) - { - return true; - } - } - return false; - } - }); + eventNodes= getEventNodesForPublishedNodes(queue, publishedNodes); } else { - List assocs = nodeService.getChildAssocs(queue, - ASSOC_PUBLISHING_EVENT, RegexQNamePattern.MATCH_ALL); - return CollectionUtils.transform(assocs, NodeUtils.toChildRef()); + eventNodes = getAllPublishingEventNodes(queue); } + Set ids = filter.getIds(); + if(isEmpty(ids) == false) + { + eventNodes = filterEventNodesById(eventNodes, ids); + } + return eventNodes; + } + + private List filterEventNodesById(Collection eventNodes, final Collection ids) + { + return filter(eventNodes, new Filter() + { + public Boolean apply(NodeRef node) + { + return ids.contains(node.toString()); + } + }); + } + + private List getAllPublishingEventNodes(final NodeRef queue) + { + List assocs = + nodeService.getChildAssocs(queue, ASSOC_PUBLISHING_EVENT, RegexQNamePattern.MATCH_ALL); + return transform(assocs, NodeUtils.toChildRef()); + } + + /** + * Returns a {@link List} of the {@link NodeRef}s representing PublishingEvents that were scheduled to publish at least one of the specified publishedNodes. + * @param queue + * @param publishedNodes + * @return + */ + public List getEventNodesForPublishedNodes(final NodeRef queue, NodeRef... publishedNodes) + { + return getEventNodesForPublishedNodes(queue, Arrays.asList(publishedNodes)); + } + + /** + * Returns a {@link List} of the {@link NodeRef}s representing PublishingEvents that were scheduled to publish at least one of the specified publishedNodes. + * @param queue + * @param publishedNodes + * @return + */ + public List getEventNodesForPublishedNodes(final NodeRef queue, Collection publishedNodes) + { + Function> transformer = new Function>() + { + public Collection apply(NodeRef publishedNode) + { + List assocs = nodeService.getChildAssocsByPropertyValue(queue, PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH, publishedNode.toString()); + return transform(assocs, NodeUtils.toChildRef()); + } + }; + List nodes = transformFlat(publishedNodes, transformer); + return nodes; } public List findPublishingEvents(NodeRef queue, PublishingEventFilter filter) @@ -340,7 +378,16 @@ public class PublishingEventHelper return definition.getId(); } - private Calendar getScheduledTime(Map eventProperties) + public Calendar getScheduledTime(NodeRef eventNode) + { + if(eventNode == null) + { + return null; + } + return getScheduledTime(nodeService.getProperties(eventNode)); + } + + public Calendar getScheduledTime(Map eventProperties) { Date time = (Date) eventProperties.get(PROP_PUBLISHING_EVENT_TIME); String timezone= (String) eventProperties.get(PROP_PUBLISHING_EVENT_TIME_ZONE); diff --git a/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java b/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java index a3804c038f..9ad8109148 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java +++ b/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java @@ -75,7 +75,6 @@ public class PublishingQueueImpl implements PublishingQueue if(schedule == null) { schedule = Calendar.getInstance(); - schedule.add(Calendar.SECOND, 1); } try { diff --git a/source/java/org/alfresco/repo/publishing/springsocial/ConnectionSerializer.java b/source/java/org/alfresco/repo/publishing/springsocial/ConnectionSerializer.java new file mode 100644 index 0000000000..26c00f19b2 --- /dev/null +++ b/source/java/org/alfresco/repo/publishing/springsocial/ConnectionSerializer.java @@ -0,0 +1,45 @@ +/* + * 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.publishing.springsocial; + +import org.springframework.social.connect.ConnectionData; + +/** + * @author Nick Smith + * @since 4.0 + * + */ +public class ConnectionSerializer +{ + + public ConnectionData deSerialize() + { + Long expireTime = null; + String refreshToken = null; + String secret = null; + String accessToken = null; + String providerId = null; + String imageUrl = null; + String profileUrl = null; + String providerUserId = null; + String displayName = null; + return new ConnectionData(providerId, providerUserId, displayName, profileUrl, imageUrl, accessToken, secret, refreshToken, expireTime); + } +} diff --git a/source/java/org/alfresco/repo/publishing/springsocial/OAuth1ChannelType.java b/source/java/org/alfresco/repo/publishing/springsocial/OAuth1ChannelType.java new file mode 100644 index 0000000000..959fe519e5 --- /dev/null +++ b/source/java/org/alfresco/repo/publishing/springsocial/OAuth1ChannelType.java @@ -0,0 +1,71 @@ +/* + * 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.publishing.springsocial; + +import java.io.Serializable; +import java.util.Map; +import java.util.Set; + +import org.alfresco.repo.publishing.AbstractChannelType; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; +import org.springframework.social.oauth1.OAuth1ServiceProvider; + +/** + * @author Nick Smith + * @since 4.0 + * + */ +public abstract class OAuth1ChannelType extends AbstractChannelType +{ + OAuth1ServiceProvider serviceProvider; + + /** + * {@inheritDoc} + */ + @Override + public void publish(NodeRef nodeToPublish, Map properties) + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + @Override + public void unpublish(NodeRef nodeToUnpublish, Map properties) + { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + @Override + public void updateStatus(String status, Map properties) + { + + // TODO Auto-generated method stub + + } + +} diff --git a/source/java/org/alfresco/service/cmr/publishing/PublishingEventFilter.java b/source/java/org/alfresco/service/cmr/publishing/PublishingEventFilter.java index 18d1e20978..23b0a34a31 100644 --- a/source/java/org/alfresco/service/cmr/publishing/PublishingEventFilter.java +++ b/source/java/org/alfresco/service/cmr/publishing/PublishingEventFilter.java @@ -21,6 +21,8 @@ package org.alfresco.service.cmr.publishing; import java.util.Set; +import org.alfresco.service.cmr.repository.NodeRef; + /** * @author Brian * @@ -30,4 +32,8 @@ public interface PublishingEventFilter PublishingEventFilter setIds(String... ids); Set getIds(); + + PublishingEventFilter setPublishedNodes(NodeRef... publishedNodes); + + Set getPublishedNodes(); }