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>
<type>d:text</type>
</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>
<mandatory-aspects>
<aspect>cm:auditable</aspect>

View File

@@ -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);

View File

@@ -111,8 +111,7 @@ public class ChannelImpl implements Channel
@Override
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);
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());

View File

@@ -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;
}
}

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.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)

View File

@@ -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));

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_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<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)
@@ -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<QName, Serializable> props = new HashMap<QName, Serializable>();
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(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<String> 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<String> mapNodesToStrings(Collection<NodeRef> nodes)

View File

@@ -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<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.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}
*/

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.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<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());
for (PublishingPackageEntry entry : event.getPackage().getEntries())
{

View File

@@ -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);

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_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";

View File

@@ -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<String> 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();
}

View File

@@ -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<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());
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<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();
String getChannelName();
StatusUpdate getStatusUpdate();
}

View File

@@ -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<String> 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 - <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 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);
}

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<QName> getSupportedContentTypes();
String getNodeUrl(NodeRef node);
}