diff --git a/config/alfresco/model/publishingModel.xml b/config/alfresco/model/publishingModel.xml index 527d68be98..06f97bc8b0 100644 --- a/config/alfresco/model/publishingModel.xml +++ b/config/alfresco/model/publishingModel.xml @@ -180,6 +180,19 @@ The Id of the associated Publishing Event Workflow Instance d:text + + The status update message + d:text + + + The status update NodeRef used to generate a URL + d:text + + + The names of the channels to be notified of this status update. + d:text + true + cm:auditable diff --git a/source/java/org/alfresco/repo/publishing/ChannelHelper.java b/source/java/org/alfresco/repo/publishing/ChannelHelper.java index ceb49b4c19..5e7784666d 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelHelper.java +++ b/source/java/org/alfresco/repo/publishing/ChannelHelper.java @@ -109,6 +109,16 @@ public class ChannelHelper 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) { QName channelQName = getChannelQName(channelName); @@ -343,5 +353,5 @@ public class ChannelHelper { this.contentService = contentService; } - + } diff --git a/source/java/org/alfresco/repo/publishing/ChannelImpl.java b/source/java/org/alfresco/repo/publishing/ChannelImpl.java index 4e3e8d94cb..5db79ed209 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelImpl.java +++ b/source/java/org/alfresco/repo/publishing/ChannelImpl.java @@ -111,8 +111,7 @@ public class ChannelImpl implements Channel @Override public void updateStatus(String status) { - // TODO Auto-generated method stub - + channelType.updateStatus(status, getProperties()); } } diff --git a/source/java/org/alfresco/repo/publishing/EnvironmentImplTest.java b/source/java/org/alfresco/repo/publishing/EnvironmentImplTest.java index 66a419e0f7..6aad592fbf 100644 --- a/source/java/org/alfresco/repo/publishing/EnvironmentImplTest.java +++ b/source/java/org/alfresco/repo/publishing/EnvironmentImplTest.java @@ -63,7 +63,7 @@ public class EnvironmentImplTest extends AbstractPublishingIntegrationTest schedule.add(Calendar.YEAR, 1); MutablePublishingPackage pckg =queue.createPublishingPackage(); pckg.addNodesToPublish(first); - queue.scheduleNewEvent(pckg, channel1Name, schedule, null); + queue.scheduleNewEvent(pckg, channel1Name, schedule, null, null); results = environment.checkPublishStatus(channel1Name, first, second); assertEquals(2, results.size()); diff --git a/source/java/org/alfresco/repo/publishing/MockChannelType.java b/source/java/org/alfresco/repo/publishing/MockChannelType.java index 3f3bc5d754..34c546dd92 100644 --- a/source/java/org/alfresco/repo/publishing/MockChannelType.java +++ b/source/java/org/alfresco/repo/publishing/MockChannelType.java @@ -138,7 +138,15 @@ public class MockChannelType extends AbstractChannelType @Override public boolean canPublishStatusUpdates() { - // TODO Auto-generated method stub return false; } + + /** + * {@inheritDoc} + */ + public String getNodeUrl(NodeRef node) + { + return null; + } + } diff --git a/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java b/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java index 64b3974185..52dcdc20fb 100644 --- a/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java +++ b/source/java/org/alfresco/repo/publishing/PublishEventActionTest.java @@ -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.TYPE_CONTENT; 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.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.PublishingPackage; 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.ChannelType; 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.RegexQNamePattern; import org.junit.Test; -import org.mockito.exceptions.verification.NeverWantedButInvoked; import org.springframework.beans.factory.annotation.Autowired; /** @@ -228,6 +233,7 @@ public class PublishEventActionTest extends AbstractPublishingIntegrationTest verify(channelType, times(1)).publish(eq(publishedNode), anyMap()); } + @SuppressWarnings("unchecked") public void testChannelTypePublishIsCalledOnUpdate() throws Exception { // Create content node with appropriate aspects added. @@ -319,11 +325,33 @@ public class PublishEventActionTest extends AbstractPublishingIntegrationTest 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) + { + return publishNode(source, null); + } + + private NodeRef publishNode(NodeRef source, StatusUpdate statusUpdate) { MutablePublishingPackage pckg = queue.createPublishingPackage(); pckg.addNodesToPublish(source); - scheduleEvent(pckg); + scheduleEvent(pckg, statusUpdate); assertNotNull(eventId); NodeRef eventNode = new NodeRef(eventId); @@ -333,11 +361,11 @@ public class PublishEventActionTest extends AbstractPublishingIntegrationTest return eventNode; } - private void scheduleEvent(PublishingPackage publishPckg) + private void scheduleEvent(PublishingPackage publishPckg, StatusUpdate statusUpdate) { Calendar schedule = Calendar.getInstance(); 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) diff --git a/source/java/org/alfresco/repo/publishing/PublishWebContentJbpmTest.java b/source/java/org/alfresco/repo/publishing/PublishWebContentJbpmTest.java index 3197673fb5..795d370ff3 100644 --- a/source/java/org/alfresco/repo/publishing/PublishWebContentJbpmTest.java +++ b/source/java/org/alfresco/repo/publishing/PublishWebContentJbpmTest.java @@ -104,7 +104,7 @@ public class PublishWebContentJbpmTest public void testProcessTimers() throws Exception { final Calendar scheduledTime = Calendar.getInstance(); - scheduledTime.add(Calendar.SECOND, 10); + scheduledTime.add(Calendar.SECOND, 5); startWorkflowAndCommit(scheduledTime); @@ -112,7 +112,7 @@ public class PublishWebContentJbpmTest checkNode("waitForScheduledTime"); // Wait for scheduled time to elapse. - Thread.sleep(11000); + Thread.sleep(10000); // Check the Publish Event Action was called verify(checkPublishingDependenciesAction).execute(any(Action.class), any(NodeRef.class)); diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java b/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java index e915067d41..33dde14ef0 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java +++ b/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java @@ -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_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_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; @@ -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.PublishingEventFilter; 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.ContentReader; import org.alfresco.service.cmr.repository.ContentService; @@ -150,10 +154,26 @@ public class PublishingEventHelper Calendar scheduledTime = getScheduledTime(props); String channel = (String) props.get(PROP_PUBLISHING_EVENT_CHANNEL); + StatusUpdate statusUpdate = buildStatusUpdate(props); return new PublishingEventImpl(eventNode.toString(), status, channel, publishingPackage, createdTime, - creator,modifiedTime, modifier, scheduledTime, comment); + creator,modifiedTime, modifier, + scheduledTime, comment, statusUpdate); + } + + @SuppressWarnings("unchecked") + private StatusUpdate buildStatusUpdate(Map props) + { + String message = (String) props.get(PROP_STATUS_UPDATE_MESSAGE); + Collection channelNames = (Collection) 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 getPublishingEvents(List 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 { if (schedule == null) { schedule = Calendar.getInstance(); } - Map props = new HashMap(); String name = GUID.generate(); + Map 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 buildPublishingEventProperties(PublishingPackage publishingPackage, + String channelName, Calendar schedule, String comment, StatusUpdate statusUpdate, String name) + { + Map props = new HashMap(); props.put(ContentModel.PROP_NAME, name); props.put(PROP_PUBLISHING_EVENT_STATUS, Status.IN_PROGRESS.name()); 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); Collection unpublshStrings = mapNodesToStrings(publishingPackage.getNodesToUnpublish()); props.put(PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH, (Serializable) unpublshStrings); - 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; + if(statusUpdate != null) + { + props.put(PROP_STATUS_UPDATE_MESSAGE, statusUpdate.getMessage()); + props.put(PROP_STATUS_UPDATE_NODE_REF, statusUpdate.getNodeToLinkTo().toString()); + props.put(PROP_STATUS_UPDATE_CHANNEL_NAMES, (Serializable) statusUpdate.getChannelNames()); + } + return props; } private Collection mapNodesToStrings(Collection nodes) diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventHelperTest.java b/source/java/org/alfresco/repo/publishing/PublishingEventHelperTest.java index 4df368e4ca..c1e9d631fd 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingEventHelperTest.java +++ b/source/java/org/alfresco/repo/publishing/PublishingEventHelperTest.java @@ -190,7 +190,7 @@ public class PublishingEventHelperTest Calendar schedule = Calendar.getInstance(); 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); ArgumentCaptor argument = ArgumentCaptor.forClass(Map.class); diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventImpl.java b/source/java/org/alfresco/repo/publishing/PublishingEventImpl.java index ae7aad195b..6cd72d422e 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingEventImpl.java +++ b/source/java/org/alfresco/repo/publishing/PublishingEventImpl.java @@ -25,6 +25,7 @@ import java.util.Date; import org.alfresco.service.cmr.publishing.MutablePublishingEvent; import org.alfresco.service.cmr.publishing.PublishingEvent; import org.alfresco.service.cmr.publishing.PublishingPackage; +import org.alfresco.service.cmr.publishing.StatusUpdate; /** * @author Nick Smith @@ -41,6 +42,7 @@ public class PublishingEventImpl implements PublishingEvent private final String creator; private final Date modifiedTime; private final String modifier; + private final StatusUpdate statusUpdate; protected final Calendar scheduledTime; protected String comment; @@ -48,7 +50,8 @@ public class PublishingEventImpl implements PublishingEvent Status status, String channelName, PublishingPackage publishingPackage,Date createdTime, String creator, Date modifiedTime, - String modifier, Calendar scheduledTime, String comment) + String modifier, Calendar scheduledTime, String comment, + StatusUpdate statusUpdate) { this.id = id; this.status = status; @@ -60,6 +63,7 @@ public class PublishingEventImpl implements PublishingEvent this.modifier = modifier; this.scheduledTime = scheduledTime; this.comment = comment; + this.statusUpdate = statusUpdate; } public PublishingEventImpl(PublishingEvent event) @@ -68,7 +72,8 @@ public class PublishingEventImpl implements PublishingEvent event.getStatus(), event.getChannelName(), event.getPackage(), event.getCreatedTime(), 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; } + /** + * {@inheritDoc} + */ + @Override + public StatusUpdate getStatusUpdate() + { + return statusUpdate; + } + /** * {@inheritDoc} */ diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java b/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java index f4786d0f41..a2fb9c47a2 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java +++ b/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java @@ -36,6 +36,7 @@ import org.alfresco.repo.policy.BehaviourFilter; import org.alfresco.service.cmr.publishing.NodeSnapshot; import org.alfresco.service.cmr.publishing.PublishingEvent; 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.ChannelService; import org.alfresco.service.cmr.repository.ChildAssociationRef; @@ -67,14 +68,15 @@ public class PublishingEventProcessor PublishingEvent event = eventHelper.getPublishingEvent(eventNode); NodeRef environment = eventHelper.getEnvironmentNodeForPublishingEvent(eventNode); String channelName = event.getChannelName(); - NodeRef channelNode = channelHelper.getChannelNodeForEnvironment(environment, channelName); - if (channelNode == null) + Channel channel = channelHelper.getChannel(environment, channelName, channelService); + if (channel == null) { fail(event, "No channel found"); } else { - publishEvent(channelNode, event); + publishEvent(channel, event); + updateStatus(channel, environment, event.getStatusUpdate()); } } 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 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()); for (PublishingPackageEntry entry : event.getPackage().getEntries()) { diff --git a/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java b/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java index a36ddfe1d2..18a2a46dd2 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java +++ b/source/java/org/alfresco/repo/publishing/PublishingIntegratedTest.java @@ -139,7 +139,7 @@ public class PublishingIntegratedTest Calendar scheduleTime = Calendar.getInstance(); 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); @@ -174,7 +174,7 @@ public class PublishingIntegratedTest Calendar scheduleTime = Calendar.getInstance(); 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); Assert.assertNotNull(event); publishingService.cancelPublishingEvent(eventId); diff --git a/source/java/org/alfresco/repo/publishing/PublishingModel.java b/source/java/org/alfresco/repo/publishing/PublishingModel.java index f901c4ea73..471601cfc9 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingModel.java +++ b/source/java/org/alfresco/repo/publishing/PublishingModel.java @@ -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_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_NODES_TO_PUBLISH = QName.createQName(NAMESPACE, - "publishingEventNodesToPublish"); - public static final QName PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH = QName.createQName(NAMESPACE, - "publishingEventNodesToUnpublish"); + public static final QName PROP_PUBLISHING_EVENT_NODES_TO_PUBLISH = QName.createQName(NAMESPACE, "publishingEventNodesToPublish"); + public static final QName PROP_PUBLISHING_EVENT_NODES_TO_UNPUBLISH = QName.createQName(NAMESPACE, "publishingEventNodesToUnpublish"); + public static final QName PROP_STATUS_UPDATE_CHANNEL_NAMES = QName.createQName(NAMESPACE, "statusUpdateChannelNames"); + 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_IN_PROGRESS = "IN_PROGRESS"; diff --git a/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java b/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java index 0a4edac2c3..fc072dd337 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java +++ b/source/java/org/alfresco/repo/publishing/PublishingQueueImpl.java @@ -19,17 +19,21 @@ package org.alfresco.repo.publishing; +import java.util.Arrays; import java.util.Calendar; +import java.util.Collection; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.transfer.manifest.TransferManifestNodeFactory; import org.alfresco.service.cmr.publishing.MutablePublishingPackage; import org.alfresco.service.cmr.publishing.PublishingPackage; import org.alfresco.service.cmr.publishing.PublishingQueue; +import org.alfresco.service.cmr.publishing.StatusUpdate; import org.alfresco.service.cmr.repository.NodeRef; /** * @author Brian + * @author Nick Smith * */ public class PublishingQueueImpl implements PublishingQueue @@ -39,33 +43,38 @@ public class PublishingQueueImpl implements PublishingQueue private TransferManifestNodeFactory transferManifestNodeFactory; private PublishingEventHelper publishingEventHelper; - /* - * (non-Javadoc) - * - * @see - * org.alfresco.service.cmr.publishing.PublishingQueue#createPublishingPackage - * () - */ - @Override - public MutablePublishingPackage createPublishingPackage() + /** + * {@inheritDoc} + */ + public MutablePublishingPackage createPublishingPackage() { return new MutablePublishingPackageImpl(transferManifestNodeFactory); } - /* - * (non-Javadoc) - * - * @see - * org.alfresco.service.cmr.publishing.PublishingQueue#scheduleNewEvent( - * org.alfresco.service.cmr.publishing.PublishingPackage, - * java.util.Calendar, java.lang.String) + /** + * {@inheritDoc} */ - @Override - public String scheduleNewEvent(PublishingPackage publishingPackage, String channelName, Calendar schedule, String comment) + public StatusUpdate createStatusUpdate(String message, NodeRef nodeToLinkTo, String... channelNames) + { + return createStatusUpdate(message, nodeToLinkTo, Arrays.asList(channelNames)); + } + + /** + * {@inheritDoc} + */ + public StatusUpdate createStatusUpdate(String message, NodeRef nodeToLinkTo, Collection channelNames) + { + return new StatusUpdateImpl(message, nodeToLinkTo, channelNames); + } + + /** + * {@inheritDoc} + */ + public String scheduleNewEvent(PublishingPackage publishingPackage, String channelName, Calendar schedule, String comment, StatusUpdate statusUpdate) { try { - NodeRef eventNode = publishingEventHelper.createNode(nodeRef, publishingPackage, channelName, schedule, comment); + NodeRef eventNode = publishingEventHelper.createNode(nodeRef, publishingPackage, channelName, schedule, comment, statusUpdate); publishingEventHelper.startPublishingWorkflow(eventNode, schedule); return eventNode.toString(); } diff --git a/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java b/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java index 0919e780b0..112c003b32 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java +++ b/source/java/org/alfresco/repo/publishing/PublishingQueueImplTest.java @@ -20,6 +20,7 @@ package org.alfresco.repo.publishing; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertTrue; 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.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.List; import java.util.Map; +import java.util.Set; 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.PublishingPackageEntry; 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.workflow.WorkflowInstance; import org.alfresco.service.cmr.workflow.WorkflowPath; @@ -56,6 +60,9 @@ import org.junit.Test; */ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest { + private static final String channelName = "TheChannel"; + private static final String comment = "The Comment"; + @Resource(name="publishingService") protected PublishingService publishingService; @@ -66,8 +73,8 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest @Test public void testScheduleNewPublishingEvent() throws Exception { - NodeRef firstNode = fileFolderService.create(docLib, "First", ContentModel.TYPE_CONTENT).getNodeRef(); - NodeRef secondNode = fileFolderService.create(docLib, "second", ContentModel.TYPE_CONTENT).getNodeRef(); + NodeRef firstNode = createContent("First"); + NodeRef secondNode = createContent("second"); MutablePublishingPackage publishingPackage = queue.createPublishingPackage(); publishingPackage.addNodesToPublish(firstNode, secondNode); @@ -76,13 +83,10 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest // NodeRef thirdNode = fileFolderService.create(docLib, "third", ContentModel.TYPE_CONTENT).getNodeRef(); // publishingPackage.addNodesToUnpublish(thirdNode); - String channelName = "The channel"; Calendar schedule = Calendar.getInstance(); schedule.add(Calendar.HOUR, 2); - String comment = "The Comment"; - - this.eventId = queue.scheduleNewEvent(publishingPackage, channelName, schedule, comment); + this.eventId = queue.scheduleNewEvent(publishingPackage, channelName, schedule, comment, null); PublishingEvent event = publishingService.getPublishingEvent(eventId); assertEquals(eventId, event.getId()); @@ -90,6 +94,8 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest assertEquals(Status.SCHEDULED, event.getStatus()); assertEquals(AuthenticationUtil.getAdminUserName(), event.getCreator()); assertEquals(schedule, event.getScheduledTime()); + assertEquals(channelName, event.getChannelName()); + assertNull(event.getStatusUpdate()); PublishingPackage pckg = event.getPackage(); ArrayList toPublish = new ArrayList(2); @@ -124,8 +130,36 @@ public class PublishingQueueImplTest extends AbstractPublishingIntegrationTest Map props = workflowService.getPathProperties(paths.get(0).getId()); assertEquals(eventNode, props.get(PROP_WF_PUBLISHING_EVENT)); assertEquals(schedule.getTime(), props.get(PROP_WF_SCHEDULED_PUBLISH_DATE)); + } + + public void testScheduleNewPublishingEventWithStatusUpdate() throws Exception + { + NodeRef firstNode = createContent("First"); + NodeRef secondNode = createContent("Second"); + List 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 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(); } /** diff --git a/source/java/org/alfresco/repo/publishing/StatusUpdateImpl.java b/source/java/org/alfresco/repo/publishing/StatusUpdateImpl.java new file mode 100644 index 0000000000..8d93b9937c --- /dev/null +++ b/source/java/org/alfresco/repo/publishing/StatusUpdateImpl.java @@ -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 . + */ + +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 channelNames; + + public StatusUpdateImpl(String message, NodeRef nodeToLinkTo, Collection channelNames) + { + this.message = message; + this.nodeToLinkTo = nodeToLinkTo; + this.channelNames = Collections.unmodifiableSet(new HashSet(channelNames)); + } + + /** + * {@inheritDoc} + */ + public String getMessage() + { + return message; + } + + /** + * {@inheritDoc} + */ + public Set getChannelNames() + { + return channelNames; + } + + /** + * {@inheritDoc} + */ + public NodeRef getNodeToLinkTo() + { + return nodeToLinkTo; + } + +} diff --git a/source/java/org/alfresco/service/cmr/publishing/PublishingEvent.java b/source/java/org/alfresco/service/cmr/publishing/PublishingEvent.java index c2613b9751..751a3bf253 100644 --- a/source/java/org/alfresco/service/cmr/publishing/PublishingEvent.java +++ b/source/java/org/alfresco/service/cmr/publishing/PublishingEvent.java @@ -52,4 +52,6 @@ public interface PublishingEvent MutablePublishingEvent edit(); String getChannelName(); + + StatusUpdate getStatusUpdate(); } diff --git a/source/java/org/alfresco/service/cmr/publishing/PublishingQueue.java b/source/java/org/alfresco/service/cmr/publishing/PublishingQueue.java index 65c1760551..0f213a61b7 100644 --- a/source/java/org/alfresco/service/cmr/publishing/PublishingQueue.java +++ b/source/java/org/alfresco/service/cmr/publishing/PublishingQueue.java @@ -20,23 +20,32 @@ package org.alfresco.service.cmr.publishing; import java.util.Calendar; +import java.util.Collection; + +import org.alfresco.service.cmr.repository.NodeRef; public interface PublishingQueue { /** * 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. */ MutablePublishingPackage createPublishingPackage(); + StatusUpdate createStatusUpdate(String message, NodeRef nodeToLinkTo, String... channelNames); + StatusUpdate createStatusUpdate(String message, NodeRef nodeToLinkTo, Collection channelNames); + /** * Adds the supplied publishing package onto the queue. * @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 schedule The time at which the new publishing event should be scheduled (optional - null indicates "as soon as possible") * @param comment A comment to be stored with this new event (optional - may be null) + * @param statusUpdate TODO * @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); + + } diff --git a/source/java/org/alfresco/service/cmr/publishing/StatusUpdate.java b/source/java/org/alfresco/service/cmr/publishing/StatusUpdate.java new file mode 100644 index 0000000000..cb43ea901f --- /dev/null +++ b/source/java/org/alfresco/service/cmr/publishing/StatusUpdate.java @@ -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 . + */ + +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 getChannelNames(); + NodeRef getNodeToLinkTo(); +} diff --git a/source/java/org/alfresco/service/cmr/publishing/channels/ChannelType.java b/source/java/org/alfresco/service/cmr/publishing/channels/ChannelType.java index 88029f413e..bc6a74e0f3 100644 --- a/source/java/org/alfresco/service/cmr/publishing/channels/ChannelType.java +++ b/source/java/org/alfresco/service/cmr/publishing/channels/ChannelType.java @@ -49,4 +49,5 @@ public interface ChannelType Set getSupportedMimetypes(); Set getSupportedContentTypes(); + String getNodeUrl(NodeRef node); }