diff --git a/source/java/org/alfresco/repo/publishing/ChannelImpl.java b/source/java/org/alfresco/repo/publishing/ChannelImpl.java index a3c02f6eb8..9c9c8267e2 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelImpl.java +++ b/source/java/org/alfresco/repo/publishing/ChannelImpl.java @@ -113,9 +113,20 @@ public class ChannelImpl implements Channel /** * {@inheritDoc} */ - public void updateStatus(String status) + public void updateStatus(String status, String nodeUrl) { - channelType.updateStatus(this, status, getProperties()); + if(channelType.canPublishStatusUpdates()) + { + int urlLength = nodeUrl == null ? 0 : nodeUrl.length(); + int maxLength = channelType.getMaximumStatusLength() - urlLength; + if (maxLength > 0) + { + int endpoint = Math.min(maxLength, status.length()); + status = status.substring(0, endpoint ); + } + String msg = nodeUrl==null ? status : status + nodeUrl; + channelType.updateStatus(this, msg, getProperties()); + } } /** diff --git a/source/java/org/alfresco/repo/publishing/ChannelImplTest.java b/source/java/org/alfresco/repo/publishing/ChannelImplTest.java new file mode 100644 index 0000000000..384519ffa7 --- /dev/null +++ b/source/java/org/alfresco/repo/publishing/ChannelImplTest.java @@ -0,0 +1,113 @@ +/* + * 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 static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import junit.framework.TestCase; + +import org.alfresco.service.cmr.publishing.channels.ChannelType; +import org.alfresco.service.cmr.repository.NodeRef; +/** + * @author Nick Smith + * @since 4.0 + * + */ +public class ChannelImplTest extends TestCase +{ + public void testUpdateStatus() throws Exception + { + int maxLength = 30; + ChannelType channelType = mockChannelType(maxLength); + + ChannelHelper helper = mock(ChannelHelper.class); + when(helper.getChannelProperties(any(NodeRef.class))).thenReturn(null); + NodeRef node = new NodeRef("test://channel/node"); + + ChannelImpl channel = new ChannelImpl(channelType, node, "Name", helper); + + String msg = "Here is a message"; + channel.updateStatus(msg, null); + verify(channelType).updateStatus(channel, msg, null); + } + + public void testUpdateStatusTruncates() throws Exception + { + int maxLength = 30; + ChannelType channelType = mockChannelType(maxLength); + + ChannelHelper helper = mock(ChannelHelper.class); + when(helper.getChannelProperties(any(NodeRef.class))).thenReturn(null); + NodeRef node = new NodeRef("test://channel/node"); + + ChannelImpl channel = new ChannelImpl(channelType, node, "Name", helper); + + String msg = "Here is a much longer message to truncate."; + String expMsg = msg.substring(0, maxLength); + channel.updateStatus(msg, null); + verify(channelType).updateStatus(channel, expMsg, null); + } + + public void testUpdateStatusTruncatesWithUrl() throws Exception + { + int maxLength = 30; + ChannelType channelType = mockChannelType(maxLength); + + ChannelHelper helper = mock(ChannelHelper.class); + when(helper.getChannelProperties(any(NodeRef.class))).thenReturn(null); + NodeRef node = new NodeRef("test://channel/node"); + + ChannelImpl channel = new ChannelImpl(channelType, node, "Name", helper); + String nodeUrl ="http://foo/bar"; + int endpoint = maxLength - nodeUrl.length(); + + String msg = "Here is a much longer message to truncate."; + String expMsg = msg.substring(0, endpoint) + nodeUrl; + channel.updateStatus(msg, nodeUrl); + verify(channelType).updateStatus(channel, expMsg, null); + } + + public void testUpdateStatusNoMaxLength() throws Exception + { + ChannelType channelType = mockChannelType(0); + + ChannelHelper helper = mock(ChannelHelper.class); + when(helper.getChannelProperties(any(NodeRef.class))).thenReturn(null); + NodeRef node = new NodeRef("test://channel/node"); + + ChannelImpl channel = new ChannelImpl(channelType, node, "Name", helper); + String nodeUrl ="http://foo/bar"; + + String msg = "Here is a much longer message to truncate."; + String expMsg = msg + nodeUrl; + channel.updateStatus(msg, nodeUrl); + verify(channelType).updateStatus(channel, expMsg, null); + } + + private ChannelType mockChannelType(int maxLength) + { + ChannelType channelType = mock(ChannelType.class); + when(channelType.canPublishStatusUpdates()).thenReturn(true); + when(channelType.getMaximumStatusLength()).thenReturn(maxLength); + return channelType; + } +} diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java b/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java index 1ff1f3172b..719806f7a5 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java +++ b/source/java/org/alfresco/repo/publishing/PublishingEventHelper.java @@ -466,8 +466,7 @@ public class PublishingEventHelper //End the start task. //TODO Replace with endStartTask() call after merge to HEAD. - List tasks = workflowService.getTasksForWorkflowPath(path.getId()); - WorkflowTask startTask = tasks.get(0); + WorkflowTask startTask = workflowService.getStartTask(instanceId); workflowService.endTask(startTask.getId(), null); return instanceId; } diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java b/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java index 135e089cf8..c46cc70231 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java +++ b/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java @@ -112,26 +112,38 @@ public class PublishingEventProcessor return; } String message = update.getMessage(); - NodeRef node = update.getNodeToLinkTo(); - if(node!= null) - { - String nodeUrl = publishChannel.getUrl(node); - if(nodeUrl != null) - { - message += " " + urlShortener.shortenUrl(nodeUrl); - } - } + String nodeUrl = getNodeUrl(publishChannel, update); Set channels = update.getChannelIds(); for (String channelId : channels) { Channel channel = channelService.getChannelById(channelId); - if(channel != null && channel.getChannelType().canPublishStatusUpdates()) + if(channel != null) { - channel.updateStatus(message); + channel.updateStatus(message, nodeUrl); } } } + /** + * @param publishChannel + * @param update + * @return + */ + private String getNodeUrl(Channel publishChannel, StatusUpdate update) + { + NodeRef node = update.getNodeToLinkTo(); + String nodeUrl = null; + if(node!= null) + { + nodeUrl = publishChannel.getUrl(node); + if(nodeUrl != null) + { + nodeUrl = " " + urlShortener.shortenUrl(nodeUrl); + } + } + return nodeUrl; + } + public void publishEvent(Channel channel, PublishingEvent event) { NodeRef eventNode = eventHelper.getPublishingEventNode(event.getId()); @@ -155,6 +167,8 @@ public class PublishingEventProcessor if(NodeUtils.exists(publishedNode, nodeService)) { channel.unPublish(publishedNode); + // Need to set as temporary to delete node instead of archiving. + nodeService.addAspect(publishedNode, ContentModel.ASPECT_TEMPORARY, null); nodeService.deleteNode(publishedNode); } } diff --git a/source/java/org/alfresco/service/cmr/publishing/channels/Channel.java b/source/java/org/alfresco/service/cmr/publishing/channels/Channel.java index 64f421f7ec..2266d71c8d 100644 --- a/source/java/org/alfresco/service/cmr/publishing/channels/Channel.java +++ b/source/java/org/alfresco/service/cmr/publishing/channels/Channel.java @@ -57,7 +57,7 @@ public interface Channel void publish(NodeRef nodeToPublish); void unPublish(NodeRef nodeToUnpublish); - void updateStatus(String status); + void updateStatus(String status, String nodeUrl); /** * Returns the URL for some published content given the content node in the editorial environment. 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 19b3c22c7c..a9123a347c 100644 --- a/source/java/org/alfresco/service/cmr/publishing/channels/ChannelType.java +++ b/source/java/org/alfresco/service/cmr/publishing/channels/ChannelType.java @@ -35,7 +35,7 @@ import org.springframework.core.io.Resource; */ public interface ChannelType { - enum AuthStatus {AUTHORISED, RETRY, UNAUTHORISED}; + enum AuthStatus {AUTHORISED, RETRY, UNAUTHORISED} String getId(); QName getChannelNodeType();