Status Updates can now be sent when publishing content to a channel.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28392 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
N Smith
2011-06-14 15:15:30 +00:00
parent 233cf9a368
commit 38dd3a04fb
20 changed files with 362 additions and 63 deletions

View File

@@ -180,6 +180,19 @@
<title>The Id of the associated Publishing Event Workflow Instance</title> <title>The Id of the associated Publishing Event Workflow Instance</title>
<type>d:text</type> <type>d:text</type>
</property> </property>
<property name="pub:statusUpdateMessage">
<title>The status update message</title>
<type>d:text</type>
</property>
<property name="pub:statusUpdateNodeRef">
<title>The status update NodeRef used to generate a URL</title>
<type>d:text</type>
</property>
<property name="pub:statusUpdateChannelNames">
<title>The names of the channels to be notified of this status update.</title>
<type>d:text</type>
<multiple>true</multiple>
</property>
</properties> </properties>
<mandatory-aspects> <mandatory-aspects>
<aspect>cm:auditable</aspect> <aspect>cm:auditable</aspect>

View File

@@ -109,6 +109,16 @@ public class ChannelHelper
return createChannelNode(environment, channelType, channelName, properties); return createChannelNode(environment, channelType, channelName, properties);
} }
public Channel getChannel(NodeRef environment, String channelName, ChannelService channelService)
{
NodeRef channelNode = getChannelNodeForEnvironment(environment, channelName);
if(channelNode != null)
{
return buildChannelObject(channelNode, channelService);
}
return null;
}
public NodeRef getChannelNodeForEnvironment(NodeRef environment, String channelName) public NodeRef getChannelNodeForEnvironment(NodeRef environment, String channelName)
{ {
QName channelQName = getChannelQName(channelName); QName channelQName = getChannelQName(channelName);

View File

@@ -111,8 +111,7 @@ public class ChannelImpl implements Channel
@Override @Override
public void updateStatus(String status) public void updateStatus(String status)
{ {
// TODO Auto-generated method stub channelType.updateStatus(status, getProperties());
} }
} }

View File

@@ -63,7 +63,7 @@ public class EnvironmentImplTest extends AbstractPublishingIntegrationTest
schedule.add(Calendar.YEAR, 1); schedule.add(Calendar.YEAR, 1);
MutablePublishingPackage pckg =queue.createPublishingPackage(); MutablePublishingPackage pckg =queue.createPublishingPackage();
pckg.addNodesToPublish(first); pckg.addNodesToPublish(first);
queue.scheduleNewEvent(pckg, channel1Name, schedule, null); queue.scheduleNewEvent(pckg, channel1Name, schedule, null, null);
results = environment.checkPublishStatus(channel1Name, first, second); results = environment.checkPublishStatus(channel1Name, first, second);
assertEquals(2, results.size()); assertEquals(2, results.size());

View File

@@ -138,7 +138,15 @@ public class MockChannelType extends AbstractChannelType
@Override @Override
public boolean canPublishStatusUpdates() public boolean canPublishStatusUpdates()
{ {
// TODO Auto-generated method stub
return false; return false;
} }
/**
* {@inheritDoc}
*/
public String getNodeUrl(NodeRef node)
{
return null;
}
} }

View File

@@ -32,7 +32,12 @@ import static org.alfresco.model.ContentModel.PROP_LONGITUDE;
import static org.alfresco.model.ContentModel.PROP_NAME; import static org.alfresco.model.ContentModel.PROP_NAME;
import static org.alfresco.model.ContentModel.TYPE_CONTENT; import static org.alfresco.model.ContentModel.TYPE_CONTENT;
import static org.alfresco.repo.publishing.PublishingModel.ASSOC_LAST_PUBLISHING_EVENT; import static org.alfresco.repo.publishing.PublishingModel.ASSOC_LAST_PUBLISHING_EVENT;
import static org.mockito.Mockito.*; import static org.mockito.Matchers.anyMap;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.Serializable; import java.io.Serializable;
import java.util.Calendar; import java.util.Calendar;
@@ -49,6 +54,7 @@ import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.publishing.MutablePublishingPackage; import org.alfresco.service.cmr.publishing.MutablePublishingPackage;
import org.alfresco.service.cmr.publishing.PublishingPackage; import org.alfresco.service.cmr.publishing.PublishingPackage;
import org.alfresco.service.cmr.publishing.PublishingService; import org.alfresco.service.cmr.publishing.PublishingService;
import org.alfresco.service.cmr.publishing.StatusUpdate;
import org.alfresco.service.cmr.publishing.channels.ChannelService; import org.alfresco.service.cmr.publishing.channels.ChannelService;
import org.alfresco.service.cmr.publishing.channels.ChannelType; import org.alfresco.service.cmr.publishing.channels.ChannelType;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
@@ -59,7 +65,6 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.service.namespace.RegexQNamePattern;
import org.junit.Test; import org.junit.Test;
import org.mockito.exceptions.verification.NeverWantedButInvoked;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
/** /**
@@ -228,6 +233,7 @@ public class PublishEventActionTest extends AbstractPublishingIntegrationTest
verify(channelType, times(1)).publish(eq(publishedNode), anyMap()); verify(channelType, times(1)).publish(eq(publishedNode), anyMap());
} }
@SuppressWarnings("unchecked")
public void testChannelTypePublishIsCalledOnUpdate() throws Exception public void testChannelTypePublishIsCalledOnUpdate() throws Exception
{ {
// Create content node with appropriate aspects added. // Create content node with appropriate aspects added.
@@ -319,11 +325,33 @@ public class PublishEventActionTest extends AbstractPublishingIntegrationTest
verify(channelType, times(1)).publish(eq(publishedNode), anyMap()); verify(channelType, times(1)).publish(eq(publishedNode), anyMap());
} }
@SuppressWarnings("unchecked")
public void testStatusUpdate() throws Exception
{
NodeRef source = createContentNode(contentNodeName, content);
// Create Status Update
String message = "Here is the message ";
StatusUpdate status = queue.createStatusUpdate(message, source, channelName);
String url = "http://test/url";
publishNode(source, status);
String expMessage = message + url;
verify(channelType, times(1)).updateStatus(eq(expMessage), anyMap());
}
private NodeRef publishNode(NodeRef source) private NodeRef publishNode(NodeRef source)
{
return publishNode(source, null);
}
private NodeRef publishNode(NodeRef source, StatusUpdate statusUpdate)
{ {
MutablePublishingPackage pckg = queue.createPublishingPackage(); MutablePublishingPackage pckg = queue.createPublishingPackage();
pckg.addNodesToPublish(source); pckg.addNodesToPublish(source);
scheduleEvent(pckg); scheduleEvent(pckg, statusUpdate);
assertNotNull(eventId); assertNotNull(eventId);
NodeRef eventNode = new NodeRef(eventId); NodeRef eventNode = new NodeRef(eventId);
@@ -333,11 +361,11 @@ public class PublishEventActionTest extends AbstractPublishingIntegrationTest
return eventNode; return eventNode;
} }
private void scheduleEvent(PublishingPackage publishPckg) private void scheduleEvent(PublishingPackage publishPckg, StatusUpdate statusUpdate)
{ {
Calendar schedule = Calendar.getInstance(); Calendar schedule = Calendar.getInstance();
schedule.add(Calendar.YEAR, 1); schedule.add(Calendar.YEAR, 1);
this.eventId = queue.scheduleNewEvent(publishPckg, channelName, schedule, null); this.eventId = queue.scheduleNewEvent(publishPckg, channelName, schedule, null, statusUpdate);
} }
private void addGeographicAspect(NodeRef source, double lattitude, double longtitude) private void addGeographicAspect(NodeRef source, double lattitude, double longtitude)

View File

@@ -104,7 +104,7 @@ public class PublishWebContentJbpmTest
public void testProcessTimers() throws Exception public void testProcessTimers() throws Exception
{ {
final Calendar scheduledTime = Calendar.getInstance(); final Calendar scheduledTime = Calendar.getInstance();
scheduledTime.add(Calendar.SECOND, 10); scheduledTime.add(Calendar.SECOND, 5);
startWorkflowAndCommit(scheduledTime); startWorkflowAndCommit(scheduledTime);
@@ -112,7 +112,7 @@ public class PublishWebContentJbpmTest
checkNode("waitForScheduledTime"); checkNode("waitForScheduledTime");
// Wait for scheduled time to elapse. // Wait for scheduled time to elapse.
Thread.sleep(11000); Thread.sleep(10000);
// Check the Publish Event Action was called // Check the Publish Event Action was called
verify(checkPublishingDependenciesAction).execute(any(Action.class), any(NodeRef.class)); verify(checkPublishingDependenciesAction).execute(any(Action.class), any(NodeRef.class));

View File

@@ -30,6 +30,9 @@ import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT
import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_TIME; import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_TIME;
import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_TIME_ZONE; 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_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_WF_PUBLISHING_EVENT; 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.PROP_WF_SCHEDULED_PUBLISH_DATE;
import static org.alfresco.repo.publishing.PublishingModel.TYPE_PUBLISHING_EVENT; import static org.alfresco.repo.publishing.PublishingModel.TYPE_PUBLISHING_EVENT;
@@ -54,6 +57,7 @@ import org.alfresco.service.cmr.publishing.PublishingEvent;
import org.alfresco.service.cmr.publishing.PublishingEvent.Status; import org.alfresco.service.cmr.publishing.PublishingEvent.Status;
import org.alfresco.service.cmr.publishing.PublishingEventFilter; import org.alfresco.service.cmr.publishing.PublishingEventFilter;
import org.alfresco.service.cmr.publishing.PublishingPackage; import org.alfresco.service.cmr.publishing.PublishingPackage;
import org.alfresco.service.cmr.publishing.StatusUpdate;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentService;
@@ -150,10 +154,26 @@ public class PublishingEventHelper
Calendar scheduledTime = getScheduledTime(props); Calendar scheduledTime = getScheduledTime(props);
String channel = (String) props.get(PROP_PUBLISHING_EVENT_CHANNEL); String channel = (String) props.get(PROP_PUBLISHING_EVENT_CHANNEL);
StatusUpdate statusUpdate = buildStatusUpdate(props);
return new PublishingEventImpl(eventNode.toString(), return new PublishingEventImpl(eventNode.toString(),
status, channel, status, channel,
publishingPackage, createdTime, publishingPackage, createdTime,
creator,modifiedTime, modifier, scheduledTime, comment); creator,modifiedTime, modifier,
scheduledTime, comment, statusUpdate);
}
@SuppressWarnings("unchecked")
private StatusUpdate buildStatusUpdate(Map<QName, Serializable> props)
{
String message = (String) props.get(PROP_STATUS_UPDATE_MESSAGE);
Collection<String> channelNames = (Collection<String>) props.get(PROP_STATUS_UPDATE_CHANNEL_NAMES);
if(channelNames == null || channelNames.isEmpty())
{
return null;
}
String nodeId = (String) props.get(PROP_STATUS_UPDATE_NODE_REF);
NodeRef nodeToLinkTo = nodeId==null ? null : new NodeRef(nodeId);
return new StatusUpdateImpl(message, nodeToLinkTo, channelNames);
} }
public List<PublishingEvent> getPublishingEvents(List<NodeRef> eventNodes) public List<PublishingEvent> getPublishingEvents(List<NodeRef> eventNodes)
@@ -167,15 +187,29 @@ public class PublishingEventHelper
}); });
} }
public NodeRef createNode(NodeRef queueNode, PublishingPackage publishingPackage, String channelName, Calendar schedule, String comment) public NodeRef createNode(NodeRef queueNode, PublishingPackage publishingPackage, String channelName, Calendar schedule, String comment, StatusUpdate statusUpdate)
throws Exception throws Exception
{ {
if (schedule == null) if (schedule == null)
{ {
schedule = Calendar.getInstance(); schedule = Calendar.getInstance();
} }
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
String name = GUID.generate(); String name = GUID.generate();
Map<QName, Serializable> props =
buildPublishingEventProperties(publishingPackage, channelName, schedule, comment, statusUpdate, name);
ChildAssociationRef newAssoc = nodeService.createNode(queueNode,
ASSOC_PUBLISHING_EVENT,
QName.createQName(NAMESPACE, name),
TYPE_PUBLISHING_EVENT, props);
NodeRef eventNode = newAssoc.getChildRef();
setPayload(eventNode, publishingPackage);
return eventNode;
}
private Map<QName, Serializable> buildPublishingEventProperties(PublishingPackage publishingPackage,
String channelName, Calendar schedule, String comment, StatusUpdate statusUpdate, String name)
{
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(ContentModel.PROP_NAME, name); props.put(ContentModel.PROP_NAME, name);
props.put(PROP_PUBLISHING_EVENT_STATUS, Status.IN_PROGRESS.name()); props.put(PROP_PUBLISHING_EVENT_STATUS, Status.IN_PROGRESS.name());
props.put(PROP_PUBLISHING_EVENT_TIME, schedule.getTime()); props.put(PROP_PUBLISHING_EVENT_TIME, schedule.getTime());
@@ -190,13 +224,13 @@ public class PublishingEventHelper
props.put(PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH, (Serializable) publshStrings); props.put(PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH, (Serializable) publshStrings);
Collection<String> unpublshStrings = mapNodesToStrings(publishingPackage.getNodesToUnpublish()); Collection<String> unpublshStrings = mapNodesToStrings(publishingPackage.getNodesToUnpublish());
props.put(PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH, (Serializable) unpublshStrings); props.put(PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH, (Serializable) unpublshStrings);
ChildAssociationRef newAssoc = nodeService.createNode(queueNode, if(statusUpdate != null)
ASSOC_PUBLISHING_EVENT, {
QName.createQName(NAMESPACE, name), props.put(PROP_STATUS_UPDATE_MESSAGE, statusUpdate.getMessage());
TYPE_PUBLISHING_EVENT, props); props.put(PROP_STATUS_UPDATE_NODE_REF, statusUpdate.getNodeToLinkTo().toString());
NodeRef eventNode = newAssoc.getChildRef(); props.put(PROP_STATUS_UPDATE_CHANNEL_NAMES, (Serializable) statusUpdate.getChannelNames());
setPayload(eventNode, publishingPackage); }
return eventNode; return props;
} }
private Collection<String> mapNodesToStrings(Collection<NodeRef> nodes) private Collection<String> mapNodesToStrings(Collection<NodeRef> nodes)

View File

@@ -190,7 +190,7 @@ public class PublishingEventHelperTest
Calendar schedule = Calendar.getInstance(); Calendar schedule = Calendar.getInstance();
String comment = "The comment"; String comment = "The comment";
NodeRef result = helper.createNode(queue, pckg, channelName, schedule, comment); NodeRef result = helper.createNode(queue, pckg, channelName, schedule, comment, null);
assertEquals(event, result); assertEquals(event, result);
ArgumentCaptor<Map> argument = ArgumentCaptor.forClass(Map.class); ArgumentCaptor<Map> argument = ArgumentCaptor.forClass(Map.class);

View File

@@ -25,6 +25,7 @@ import java.util.Date;
import org.alfresco.service.cmr.publishing.MutablePublishingEvent; import org.alfresco.service.cmr.publishing.MutablePublishingEvent;
import org.alfresco.service.cmr.publishing.PublishingEvent; import org.alfresco.service.cmr.publishing.PublishingEvent;
import org.alfresco.service.cmr.publishing.PublishingPackage; import org.alfresco.service.cmr.publishing.PublishingPackage;
import org.alfresco.service.cmr.publishing.StatusUpdate;
/** /**
* @author Nick Smith * @author Nick Smith
@@ -41,6 +42,7 @@ public class PublishingEventImpl implements PublishingEvent
private final String creator; private final String creator;
private final Date modifiedTime; private final Date modifiedTime;
private final String modifier; private final String modifier;
private final StatusUpdate statusUpdate;
protected final Calendar scheduledTime; protected final Calendar scheduledTime;
protected String comment; protected String comment;
@@ -48,7 +50,8 @@ public class PublishingEventImpl implements PublishingEvent
Status status, String channelName, Status status, String channelName,
PublishingPackage publishingPackage,Date createdTime, PublishingPackage publishingPackage,Date createdTime,
String creator, Date modifiedTime, String creator, Date modifiedTime,
String modifier, Calendar scheduledTime, String comment) String modifier, Calendar scheduledTime, String comment,
StatusUpdate statusUpdate)
{ {
this.id = id; this.id = id;
this.status = status; this.status = status;
@@ -60,6 +63,7 @@ public class PublishingEventImpl implements PublishingEvent
this.modifier = modifier; this.modifier = modifier;
this.scheduledTime = scheduledTime; this.scheduledTime = scheduledTime;
this.comment = comment; this.comment = comment;
this.statusUpdate = statusUpdate;
} }
public PublishingEventImpl(PublishingEvent event) public PublishingEventImpl(PublishingEvent event)
@@ -68,7 +72,8 @@ public class PublishingEventImpl implements PublishingEvent
event.getStatus(), event.getChannelName(), event.getStatus(), event.getChannelName(),
event.getPackage(), event.getCreatedTime(), event.getPackage(), event.getCreatedTime(),
event.getCreator(), event.getModifiedTime(), event.getCreator(), event.getModifiedTime(),
event.getModifier(), event.getScheduledTime(), event.getComment()); event.getModifier(), event.getScheduledTime(), event.getComment(),
event.getStatusUpdate());
} }
/** /**
@@ -160,6 +165,15 @@ public class PublishingEventImpl implements PublishingEvent
return comment; return comment;
} }
/**
* {@inheritDoc}
*/
@Override
public StatusUpdate getStatusUpdate()
{
return statusUpdate;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View File

@@ -36,6 +36,7 @@ import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.service.cmr.publishing.NodeSnapshot; import org.alfresco.service.cmr.publishing.NodeSnapshot;
import org.alfresco.service.cmr.publishing.PublishingEvent; import org.alfresco.service.cmr.publishing.PublishingEvent;
import org.alfresco.service.cmr.publishing.PublishingPackageEntry; import org.alfresco.service.cmr.publishing.PublishingPackageEntry;
import org.alfresco.service.cmr.publishing.StatusUpdate;
import org.alfresco.service.cmr.publishing.channels.Channel; import org.alfresco.service.cmr.publishing.channels.Channel;
import org.alfresco.service.cmr.publishing.channels.ChannelService; import org.alfresco.service.cmr.publishing.channels.ChannelService;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
@@ -67,14 +68,15 @@ public class PublishingEventProcessor
PublishingEvent event = eventHelper.getPublishingEvent(eventNode); PublishingEvent event = eventHelper.getPublishingEvent(eventNode);
NodeRef environment = eventHelper.getEnvironmentNodeForPublishingEvent(eventNode); NodeRef environment = eventHelper.getEnvironmentNodeForPublishingEvent(eventNode);
String channelName = event.getChannelName(); String channelName = event.getChannelName();
NodeRef channelNode = channelHelper.getChannelNodeForEnvironment(environment, channelName); Channel channel = channelHelper.getChannel(environment, channelName, channelService);
if (channelNode == null) if (channel == null)
{ {
fail(event, "No channel found"); fail(event, "No channel found");
} }
else else
{ {
publishEvent(channelNode, event); publishEvent(channel, event);
updateStatus(channel, environment, event.getStatusUpdate());
} }
} }
finally finally
@@ -83,9 +85,35 @@ public class PublishingEventProcessor
} }
} }
public void publishEvent(NodeRef channelNode, PublishingEvent event) public void updateStatus(Channel publishChannel, NodeRef environment, StatusUpdate update)
{
if(update == null)
{
return;
}
String message = update.getMessage();
NodeRef node = update.getNodeToLinkTo();
if(node!= null)
{
String nodeUrl = publishChannel.getChannelType().getNodeUrl(node);
if(nodeUrl != null)
{
message += nodeUrl;
}
}
Set<String> channels = update.getChannelNames();
for (String channelName : channels)
{
Channel channel = channelHelper.getChannel(environment, channelName, channelService);
if(channel != null && channel.getChannelType().canPublishStatusUpdates())
{
channel.updateStatus(message);
}
}
}
public void publishEvent(Channel channel, PublishingEvent event)
{ {
Channel channel = channelHelper.buildChannelObject(channelNode, channelService);
NodeRef eventNode = eventHelper.getPublishingEventNode(event.getId()); NodeRef eventNode = eventHelper.getPublishingEventNode(event.getId());
for (PublishingPackageEntry entry : event.getPackage().getEntries()) for (PublishingPackageEntry entry : event.getPackage().getEntries())
{ {

View File

@@ -139,7 +139,7 @@ public class PublishingIntegratedTest
Calendar scheduleTime = Calendar.getInstance(); Calendar scheduleTime = Calendar.getInstance();
scheduleTime.add(Calendar.HOUR, 1); scheduleTime.add(Calendar.HOUR, 1);
String eventId = liveQueue.scheduleNewEvent(publishingPackage, channelName, scheduleTime, null); String eventId = liveQueue.scheduleNewEvent(publishingPackage, channelName, scheduleTime, null, null);
PublishingEvent event = publishingService.getPublishingEvent(eventId); PublishingEvent event = publishingService.getPublishingEvent(eventId);
@@ -174,7 +174,7 @@ public class PublishingIntegratedTest
Calendar scheduleTime = Calendar.getInstance(); Calendar scheduleTime = Calendar.getInstance();
scheduleTime.add(Calendar.HOUR, 1); scheduleTime.add(Calendar.HOUR, 1);
String eventId = liveQueue.scheduleNewEvent(publishingPackage, channelName, scheduleTime, null); String eventId = liveQueue.scheduleNewEvent(publishingPackage, channelName, scheduleTime, null, null);
PublishingEvent event = publishingService.getPublishingEvent(eventId); PublishingEvent event = publishingService.getPublishingEvent(eventId);
Assert.assertNotNull(event); Assert.assertNotNull(event);
publishingService.cancelPublishingEvent(eventId); publishingService.cancelPublishingEvent(eventId);

View File

@@ -55,10 +55,11 @@ public interface PublishingModel
public static final QName PROP_PUBLISHING_EVENT_CHANNEL= QName.createQName(NAMESPACE, "publishingEventChannel"); public static final QName PROP_PUBLISHING_EVENT_CHANNEL= QName.createQName(NAMESPACE, "publishingEventChannel");
public static final QName PROP_PUBLISHING_EVENT_WORKFLOW_ID= QName.createQName(NAMESPACE, "publishingEventWorkflowId"); public static final QName PROP_PUBLISHING_EVENT_WORKFLOW_ID= QName.createQName(NAMESPACE, "publishingEventWorkflowId");
public static final QName PROP_PUBLISHING_EVENT_PAYLOAD = QName.createQName(NAMESPACE, "publishingEventPayload"); public static final QName PROP_PUBLISHING_EVENT_PAYLOAD = QName.createQName(NAMESPACE, "publishingEventPayload");
public static final QName PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH = QName.createQName(NAMESPACE, public static final QName PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH = QName.createQName(NAMESPACE, "publishingEventNodesToPublish");
"publishingEventNodesToPublish"); public static final QName PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH = QName.createQName(NAMESPACE, "publishingEventNodesToUnpublish");
public static final QName PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH = QName.createQName(NAMESPACE, public static final QName PROP_STATUS_UPDATE_CHANNEL_NAMES = QName.createQName(NAMESPACE, "statusUpdateChannelNames");
"publishingEventNodesToUnpublish"); public static final QName PROP_STATUS_UPDATE_NODE_REF = QName.createQName(NAMESPACE, "statusUpdateNodeRef");
public static final QName PROP_STATUS_UPDATE_MESSAGE = QName.createQName(NAMESPACE, "statusUpdateMessage");
public static final String PROPVAL_PUBLISHING_EVENT_STATUS_SCHEDULED = "SCHEDULED"; public static final String PROPVAL_PUBLISHING_EVENT_STATUS_SCHEDULED = "SCHEDULED";
public static final String PROPVAL_PUBLISHING_EVENT_STATUS_IN_PROGRESS = "IN_PROGRESS"; public static final String PROPVAL_PUBLISHING_EVENT_STATUS_IN_PROGRESS = "IN_PROGRESS";

View File

@@ -19,17 +19,21 @@
package org.alfresco.repo.publishing; package org.alfresco.repo.publishing;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.transfer.manifest.TransferManifestNodeFactory; import org.alfresco.repo.transfer.manifest.TransferManifestNodeFactory;
import org.alfresco.service.cmr.publishing.MutablePublishingPackage; import org.alfresco.service.cmr.publishing.MutablePublishingPackage;
import org.alfresco.service.cmr.publishing.PublishingPackage; import org.alfresco.service.cmr.publishing.PublishingPackage;
import org.alfresco.service.cmr.publishing.PublishingQueue; import org.alfresco.service.cmr.publishing.PublishingQueue;
import org.alfresco.service.cmr.publishing.StatusUpdate;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
/** /**
* @author Brian * @author Brian
* @author Nick Smith
* *
*/ */
public class PublishingQueueImpl implements PublishingQueue public class PublishingQueueImpl implements PublishingQueue
@@ -39,33 +43,38 @@ public class PublishingQueueImpl implements PublishingQueue
private TransferManifestNodeFactory transferManifestNodeFactory; private TransferManifestNodeFactory transferManifestNodeFactory;
private PublishingEventHelper publishingEventHelper; private PublishingEventHelper publishingEventHelper;
/* /**
* (non-Javadoc) * {@inheritDoc}
*
* @see
* org.alfresco.service.cmr.publishing.PublishingQueue#createPublishingPackage
* ()
*/ */
@Override
public MutablePublishingPackage createPublishingPackage() public MutablePublishingPackage createPublishingPackage()
{ {
return new MutablePublishingPackageImpl(transferManifestNodeFactory); return new MutablePublishingPackageImpl(transferManifestNodeFactory);
} }
/* /**
* (non-Javadoc) * {@inheritDoc}
*
* @see
* org.alfresco.service.cmr.publishing.PublishingQueue#scheduleNewEvent(
* org.alfresco.service.cmr.publishing.PublishingPackage,
* java.util.Calendar, java.lang.String)
*/ */
@Override public StatusUpdate createStatusUpdate(String message, NodeRef nodeToLinkTo, String... channelNames)
public String scheduleNewEvent(PublishingPackage publishingPackage, String channelName, Calendar schedule, String comment) {
return createStatusUpdate(message, nodeToLinkTo, Arrays.asList(channelNames));
}
/**
* {@inheritDoc}
*/
public StatusUpdate createStatusUpdate(String message, NodeRef nodeToLinkTo, Collection<String> channelNames)
{
return new StatusUpdateImpl(message, nodeToLinkTo, channelNames);
}
/**
* {@inheritDoc}
*/
public String scheduleNewEvent(PublishingPackage publishingPackage, String channelName, Calendar schedule, String comment, StatusUpdate statusUpdate)
{ {
try try
{ {
NodeRef eventNode = publishingEventHelper.createNode(nodeRef, publishingPackage, channelName, schedule, comment); NodeRef eventNode = publishingEventHelper.createNode(nodeRef, publishingPackage, channelName, schedule, comment, statusUpdate);
publishingEventHelper.startPublishingWorkflow(eventNode, schedule); publishingEventHelper.startPublishingWorkflow(eventNode, schedule);
return eventNode.toString(); return eventNode.toString();
} }

View File

@@ -20,6 +20,7 @@
package org.alfresco.repo.publishing; package org.alfresco.repo.publishing;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.assertTrue;
import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_WORKFLOW_ID; import static org.alfresco.repo.publishing.PublishingModel.PROP_PUBLISHING_EVENT_WORKFLOW_ID;
@@ -28,9 +29,11 @@ import static org.alfresco.repo.publishing.PublishingModel.PROP_WF_SCHEDULED_PUB
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
@@ -42,6 +45,7 @@ import org.alfresco.service.cmr.publishing.PublishingEvent.Status;
import org.alfresco.service.cmr.publishing.PublishingPackage; import org.alfresco.service.cmr.publishing.PublishingPackage;
import org.alfresco.service.cmr.publishing.PublishingPackageEntry; import org.alfresco.service.cmr.publishing.PublishingPackageEntry;
import org.alfresco.service.cmr.publishing.PublishingService; import org.alfresco.service.cmr.publishing.PublishingService;
import org.alfresco.service.cmr.publishing.StatusUpdate;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.workflow.WorkflowInstance; import org.alfresco.service.cmr.workflow.WorkflowInstance;
import org.alfresco.service.cmr.workflow.WorkflowPath; import org.alfresco.service.cmr.workflow.WorkflowPath;
@@ -56,6 +60,9 @@ import org.junit.Test;
*/ */
public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest
{ {
private static final String channelName = "TheChannel";
private static final String comment = "The Comment";
@Resource(name="publishingService") @Resource(name="publishingService")
protected PublishingService publishingService; protected PublishingService publishingService;
@@ -66,8 +73,8 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest
@Test @Test
public void testScheduleNewPublishingEvent() throws Exception public void testScheduleNewPublishingEvent() throws Exception
{ {
NodeRef firstNode = fileFolderService.create(docLib, "First", ContentModel.TYPE_CONTENT).getNodeRef(); NodeRef firstNode = createContent("First");
NodeRef secondNode = fileFolderService.create(docLib, "second", ContentModel.TYPE_CONTENT).getNodeRef(); NodeRef secondNode = createContent("second");
MutablePublishingPackage publishingPackage = queue.createPublishingPackage(); MutablePublishingPackage publishingPackage = queue.createPublishingPackage();
publishingPackage.addNodesToPublish(firstNode, secondNode); publishingPackage.addNodesToPublish(firstNode, secondNode);
@@ -76,13 +83,10 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest
// NodeRef thirdNode = fileFolderService.create(docLib, "third", ContentModel.TYPE_CONTENT).getNodeRef(); // NodeRef thirdNode = fileFolderService.create(docLib, "third", ContentModel.TYPE_CONTENT).getNodeRef();
// publishingPackage.addNodesToUnpublish(thirdNode); // publishingPackage.addNodesToUnpublish(thirdNode);
String channelName = "The channel";
Calendar schedule = Calendar.getInstance(); Calendar schedule = Calendar.getInstance();
schedule.add(Calendar.HOUR, 2); schedule.add(Calendar.HOUR, 2);
String comment = "The Comment"; this.eventId = queue.scheduleNewEvent(publishingPackage, channelName, schedule, comment, null);
this.eventId = queue.scheduleNewEvent(publishingPackage, channelName, schedule, comment);
PublishingEvent event = publishingService.getPublishingEvent(eventId); PublishingEvent event = publishingService.getPublishingEvent(eventId);
assertEquals(eventId, event.getId()); assertEquals(eventId, event.getId());
@@ -90,6 +94,8 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest
assertEquals(Status.SCHEDULED, event.getStatus()); assertEquals(Status.SCHEDULED, event.getStatus());
assertEquals(AuthenticationUtil.getAdminUserName(), event.getCreator()); assertEquals(AuthenticationUtil.getAdminUserName(), event.getCreator());
assertEquals(schedule, event.getScheduledTime()); assertEquals(schedule, event.getScheduledTime());
assertEquals(channelName, event.getChannelName());
assertNull(event.getStatusUpdate());
PublishingPackage pckg = event.getPackage(); PublishingPackage pckg = event.getPackage();
ArrayList<NodeRef> toPublish = new ArrayList<NodeRef>(2); ArrayList<NodeRef> toPublish = new ArrayList<NodeRef>(2);
@@ -124,8 +130,36 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest
Map<QName, Serializable> props = workflowService.getPathProperties(paths.get(0).getId()); Map<QName, Serializable> props = workflowService.getPathProperties(paths.get(0).getId());
assertEquals(eventNode, props.get(PROP_WF_PUBLISHING_EVENT)); assertEquals(eventNode, props.get(PROP_WF_PUBLISHING_EVENT));
assertEquals(schedule.getTime(), props.get(PROP_WF_SCHEDULED_PUBLISH_DATE)); assertEquals(schedule.getTime(), props.get(PROP_WF_SCHEDULED_PUBLISH_DATE));
}
public void testScheduleNewPublishingEventWithStatusUpdate() throws Exception
{
NodeRef firstNode = createContent("First");
NodeRef secondNode = createContent("Second");
List<String> channelNames = Arrays.asList("Channel1", "Channel2", "Channel3" );
String message = "The message";
queue.createStatusUpdate(message, secondNode, channelNames);
// Publish an event with the StatusUpdate
MutablePublishingPackage publishingPackage = queue.createPublishingPackage();
publishingPackage.addNodesToPublish(firstNode, secondNode);
Calendar schedule = Calendar.getInstance();
schedule.add(Calendar.HOUR, 2);
this.eventId = queue.scheduleNewEvent(publishingPackage, channelName, schedule, comment, null);
PublishingEvent event = publishingService.getPublishingEvent(eventId);
StatusUpdate update = event.getStatusUpdate();
assertEquals(message, update.getMessage());
assertEquals(secondNode, update.getNodeToLinkTo());
Set<String> names = update.getChannelNames();
assertEquals(3, names.size());
assertTrue(names.containsAll(channelNames));
}
private NodeRef createContent(String name)
{
return fileFolderService.create(docLib, name, ContentModel.TYPE_CONTENT).getNodeRef();
} }
/** /**

View File

@@ -0,0 +1,73 @@
/*
* 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;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.alfresco.service.cmr.publishing.StatusUpdate;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* @author Nick Smith
* @since 4.0
*
*/
public class StatusUpdateImpl implements StatusUpdate
{
private final String message;
private final NodeRef nodeToLinkTo;
private final Set<String> channelNames;
public StatusUpdateImpl(String message, NodeRef nodeToLinkTo, Collection<String> channelNames)
{
this.message = message;
this.nodeToLinkTo = nodeToLinkTo;
this.channelNames = Collections.unmodifiableSet(new HashSet<String>(channelNames));
}
/**
* {@inheritDoc}
*/
public String getMessage()
{
return message;
}
/**
* {@inheritDoc}
*/
public Set<String> getChannelNames()
{
return channelNames;
}
/**
* {@inheritDoc}
*/
public NodeRef getNodeToLinkTo()
{
return nodeToLinkTo;
}
}

View File

@@ -52,4 +52,6 @@ public interface PublishingEvent
MutablePublishingEvent edit(); MutablePublishingEvent edit();
String getChannelName(); String getChannelName();
StatusUpdate getStatusUpdate();
} }

View File

@@ -20,23 +20,32 @@
package org.alfresco.service.cmr.publishing; package org.alfresco.service.cmr.publishing;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection;
import org.alfresco.service.cmr.repository.NodeRef;
public interface PublishingQueue public interface PublishingQueue
{ {
/** /**
* A factory method to create an empty publishing package that can be populated before being passed into * A factory method to create an empty publishing package that can be populated before being passed into
* a call to the {@link PublishingQueue#scheduleNewEvent(PublishingPackage, String, Calendar, String)} operation. * a call to the {@link PublishingQueue#scheduleNewEvent(PublishingPackage, String, Calendar, String, StatusUpdate)} operation.
* @return A publishing package that can be populated before being placed on the publishing queue. * @return A publishing package that can be populated before being placed on the publishing queue.
*/ */
MutablePublishingPackage createPublishingPackage(); MutablePublishingPackage createPublishingPackage();
StatusUpdate createStatusUpdate(String message, NodeRef nodeToLinkTo, String... channelNames);
StatusUpdate createStatusUpdate(String message, NodeRef nodeToLinkTo, Collection<String> channelNames);
/** /**
* Adds the supplied publishing package onto the queue. * Adds the supplied publishing package onto the queue.
* @param publishingPackage The publishing package that is to be enqueued * @param publishingPackage The publishing package that is to be enqueued
* @param channelName The name of the channel that the package is to be published to * @param channelName The name of the channel that the package is to be published to
* @param schedule The time at which the new publishing event should be scheduled (optional - <code>null</code> indicates "as soon as possible") * @param schedule The time at which the new publishing event should be scheduled (optional - <code>null</code> indicates "as soon as possible")
* @param comment A comment to be stored with this new event (optional - may be <code>null</code>) * @param comment A comment to be stored with this new event (optional - may be <code>null</code>)
* @param statusUpdate TODO
* @return The identifier of the newly scheduled event * @return The identifier of the newly scheduled event
*/ */
String scheduleNewEvent(PublishingPackage publishingPackage, String channelName, Calendar schedule, String comment); String scheduleNewEvent(PublishingPackage publishingPackage, String channelName, Calendar schedule, String comment, StatusUpdate statusUpdate);
} }

View File

@@ -0,0 +1,36 @@
/*
* 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.service.cmr.publishing;
import java.util.Set;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* @author Nick Smith
* @since 4.0
*
*/
public interface StatusUpdate
{
String getMessage();
Set<String> getChannelNames();
NodeRef getNodeToLinkTo();
}

View File

@@ -49,4 +49,5 @@ public interface ChannelType
Set<String> getSupportedMimetypes(); Set<String> getSupportedMimetypes();
Set<QName> getSupportedContentTypes(); Set<QName> getSupportedContentTypes();
String getNodeUrl(NodeRef node);
} }