mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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
This commit is contained in:
@@ -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<ChildAssociationRef> results = nodeService.getChildAssocsByPropertyValue( queue,
|
||||
PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH, node.toString());
|
||||
for (ChildAssociationRef childAssoc : results)
|
||||
List<NodeRef> 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<QName, Serializable> 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);
|
||||
|
@@ -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<String> ids = new HashSet<String>();
|
||||
private Set<NodeRef> publishedNodes = new HashSet<NodeRef>();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@@ -55,4 +57,25 @@ 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<NodeRef> getPublishedNodes()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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<PublishingEvent> getPublishingEvents(List<NodeRef> eventNodes)
|
||||
{
|
||||
return Lists.transform(eventNodes, new Function<NodeRef, PublishingEvent>()
|
||||
return transform(eventNodes, new Function<NodeRef, PublishingEvent>()
|
||||
{
|
||||
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<String> mapNodesToStrings(Collection<NodeRef> nodes)
|
||||
private List<String> mapNodesToStrings(Collection<NodeRef> nodes)
|
||||
{
|
||||
Collection<String> results = new ArrayList<String>(nodes.size());
|
||||
for (NodeRef node : nodes)
|
||||
{
|
||||
results.add(node.toString());
|
||||
}
|
||||
return results;
|
||||
return toListOfStrings(nodes);
|
||||
}
|
||||
|
||||
public List<NodeRef> findPublishingEventNodes(final NodeRef queue, PublishingEventFilter filter)
|
||||
{
|
||||
Set<String> ids = filter.getIds();
|
||||
if(ids != null && ids.isEmpty() == false)
|
||||
List<NodeRef> eventNodes;
|
||||
Set<NodeRef> publishedNodes = filter.getPublishedNodes();
|
||||
if(isEmpty(publishedNodes) == false)
|
||||
{
|
||||
List<NodeRef> 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>()
|
||||
{
|
||||
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<ChildAssociationRef> assocs = nodeService.getChildAssocs(queue,
|
||||
ASSOC_PUBLISHING_EVENT, RegexQNamePattern.MATCH_ALL);
|
||||
return CollectionUtils.transform(assocs, NodeUtils.toChildRef());
|
||||
eventNodes = getAllPublishingEventNodes(queue);
|
||||
}
|
||||
Set<String> ids = filter.getIds();
|
||||
if(isEmpty(ids) == false)
|
||||
{
|
||||
eventNodes = filterEventNodesById(eventNodes, ids);
|
||||
}
|
||||
return eventNodes;
|
||||
}
|
||||
|
||||
private List<NodeRef> filterEventNodesById(Collection<NodeRef> eventNodes, final Collection<String> ids)
|
||||
{
|
||||
return filter(eventNodes, new Filter<NodeRef>()
|
||||
{
|
||||
public Boolean apply(NodeRef node)
|
||||
{
|
||||
return ids.contains(node.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private List<NodeRef> getAllPublishingEventNodes(final NodeRef queue)
|
||||
{
|
||||
List<ChildAssociationRef> 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 <code>publishedNodes</code>.
|
||||
* @param queue
|
||||
* @param publishedNodes
|
||||
* @return
|
||||
*/
|
||||
public List<NodeRef> 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 <code>publishedNodes</code>.
|
||||
* @param queue
|
||||
* @param publishedNodes
|
||||
* @return
|
||||
*/
|
||||
public List<NodeRef> getEventNodesForPublishedNodes(final NodeRef queue, Collection<NodeRef> publishedNodes)
|
||||
{
|
||||
Function<NodeRef, Collection<NodeRef>> transformer = new Function<NodeRef, Collection<NodeRef>>()
|
||||
{
|
||||
public Collection<NodeRef> apply(NodeRef publishedNode)
|
||||
{
|
||||
List<ChildAssociationRef> assocs = nodeService.getChildAssocsByPropertyValue(queue, PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH, publishedNode.toString());
|
||||
return transform(assocs, NodeUtils.toChildRef());
|
||||
}
|
||||
};
|
||||
List<NodeRef> nodes = transformFlat(publishedNodes, transformer);
|
||||
return nodes;
|
||||
}
|
||||
|
||||
public List<PublishingEvent> findPublishingEvents(NodeRef queue, PublishingEventFilter filter)
|
||||
@@ -340,7 +378,16 @@ public class PublishingEventHelper
|
||||
return definition.getId();
|
||||
}
|
||||
|
||||
private Calendar getScheduledTime(Map<QName, Serializable> eventProperties)
|
||||
public Calendar getScheduledTime(NodeRef eventNode)
|
||||
{
|
||||
if(eventNode == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return getScheduledTime(nodeService.getProperties(eventNode));
|
||||
}
|
||||
|
||||
public Calendar getScheduledTime(Map<QName, Serializable> eventProperties)
|
||||
{
|
||||
Date time = (Date) eventProperties.get(PROP_PUBLISHING_EVENT_TIME);
|
||||
String timezone= (String) eventProperties.get(PROP_PUBLISHING_EVENT_TIME_ZONE);
|
||||
|
@@ -75,7 +75,6 @@ public class PublishingQueueImpl implements PublishingQueue
|
||||
if(schedule == null)
|
||||
{
|
||||
schedule = Calendar.getInstance();
|
||||
schedule.add(Calendar.SECOND, 1);
|
||||
}
|
||||
try
|
||||
{
|
||||
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<T> extends AbstractChannelType
|
||||
{
|
||||
OAuth1ServiceProvider<T> serviceProvider;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void publish(NodeRef nodeToPublish, Map<QName, Serializable> properties)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void unpublish(NodeRef nodeToUnpublish, Map<QName, Serializable> properties)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void updateStatus(String status, Map<QName, Serializable> properties)
|
||||
{
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -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<String> getIds();
|
||||
|
||||
PublishingEventFilter setPublishedNodes(NodeRef... publishedNodes);
|
||||
|
||||
Set<NodeRef> getPublishedNodes();
|
||||
}
|
||||
|
Reference in New Issue
Block a user