diff --git a/config/test/alfresco/test-web-publishing-context.xml b/config/test/alfresco/test-web-publishing-context.xml index bf6af3562a..0808a8f23a 100644 --- a/config/test/alfresco/test-web-publishing-context.xml +++ b/config/test/alfresco/test-web-publishing-context.xml @@ -3,6 +3,7 @@ + diff --git a/source/java/org/alfresco/repo/publishing/ChannelHelper.java b/source/java/org/alfresco/repo/publishing/ChannelHelper.java index 941d6fa777..9de995017b 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelHelper.java +++ b/source/java/org/alfresco/repo/publishing/ChannelHelper.java @@ -130,7 +130,7 @@ public class ChannelHelper List channelAssocs = nodeService.getChildAssocs(environment, ASSOC_CONTAINS, channelQName); return getSingleValue(channelAssocs, true); } - + /** * Given a noderef from the editorial space (e.g. the doclib), this returns the corresponding noderef in the specified channel and environment. * @param source @@ -141,17 +141,26 @@ public class ChannelHelper public NodeRef mapSourceToEnvironment(NodeRef source, NodeRef environment, String channelName) { NodeRef channel = getChannelNodeForEnvironment(environment, channelName); - return mapSourceToEnvironment(source, channel); + return mapSourceToEnvironmentInternal(source, channel); } - /** * Given a noderef from the editorial space (e.g. the doclib), this returns the corresponding noderef in the specified channelt * @param source - * @param channel + * @param editorialChannel * @return */ - public NodeRef mapSourceToEnvironment(NodeRef source, NodeRef channel) + public NodeRef mapSourceToEnvironment(NodeRef source, NodeRef editorialChannel) { +// NodeRef liveChannel = mapChannelNOde(editorialChannel); + return mapSourceToEnvironmentInternal(source, editorialChannel); + } + + private NodeRef mapSourceToEnvironmentInternal(NodeRef source, NodeRef liveChannel) + { + if(source == null || liveChannel == null) + { + return null; + } List parentAssocs = nodeService.getParentAssocs(source, ASSOC_SOURCE, RegexQNamePattern.MATCH_ALL); if(parentAssocs != null) { @@ -159,7 +168,7 @@ public class ChannelHelper { NodeRef publishedNode = parentAssoc.getParentRef(); NodeRef parent = nodeService.getPrimaryParent(publishedNode).getParentRef(); - if(channel.equals(parent)) + if(liveChannel.equals(parent)) { return publishedNode; } @@ -178,6 +187,25 @@ public class ChannelHelper List childAssocs = nodeService.getChildAssocs(publishedNode, ASSOC_SOURCE, RegexQNamePattern.MATCH_ALL); return getSingleValue(childAssocs, true); } + + /** + * Returns the {@link NodeRef} for the live channel given the {@link NodeRef} for the editorial channel. + * @param editorialChannel + * @return + */ + public NodeRef mapChannelNOde(NodeRef editorialChannel) + { + List assocs = nodeService.getParentAssocs(editorialChannel, PublishingModel.ASSOC_EDITORIAL_CHANNEL, RegexQNamePattern.MATCH_ALL); + if(assocs.isEmpty()) + { + return null; + } + if(assocs.size()>1) + { + throw new IllegalStateException("There is more than one environment channel node!"); + } + return assocs.get(0).getParentRef(); + } /** * Finds the {@link Channel} NodeRef and {@link ChannelType} id for a given node, if such a Channel exists. diff --git a/source/java/org/alfresco/repo/publishing/ChannelImpl.java b/source/java/org/alfresco/repo/publishing/ChannelImpl.java index 9200660195..f38930f49c 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelImpl.java +++ b/source/java/org/alfresco/repo/publishing/ChannelImpl.java @@ -114,4 +114,13 @@ public class ChannelImpl implements Channel channelType.updateStatus(this, status, getProperties()); } + /** + * {@inheritDoc} + */ + public String getUrl(NodeRef publishedNode) + { + NodeRef mappedChannel = channelHelper.mapChannelNOde(nodeRef); + NodeRef mappedNode = channelHelper.mapSourceToEnvironment(publishedNode, mappedChannel); + return channelType.getNodeUrl(mappedNode); + } } diff --git a/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java b/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java index 551acd7b36..43c745bc97 100644 --- a/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java +++ b/source/java/org/alfresco/repo/publishing/PublishingEventProcessor.java @@ -99,7 +99,7 @@ public class PublishingEventProcessor NodeRef node = update.getNodeToLinkTo(); if(node!= null) { - String nodeUrl = publishChannel.getChannelType().getNodeUrl(node); + String nodeUrl = publishChannel.getUrl(node); if(nodeUrl != null) { message += urlShortener.shortenUrl(nodeUrl); diff --git a/source/java/org/alfresco/repo/urlshortening/BitlyUrlShortenerTest.java b/source/java/org/alfresco/repo/urlshortening/BitlyUrlShortenerTest.java index 98a5759a25..4f61f91f63 100644 --- a/source/java/org/alfresco/repo/urlshortening/BitlyUrlShortenerTest.java +++ b/source/java/org/alfresco/repo/urlshortening/BitlyUrlShortenerTest.java @@ -4,7 +4,7 @@ import junit.framework.TestCase; public class BitlyUrlShortenerTest extends TestCase { - private BitlyUrlShortenerImpl shortener = new BitlyUrlShortenerImpl(); + private BitlyUrlShortenerImpl shortener; public void testShorten() { @@ -15,4 +15,16 @@ public class BitlyUrlShortenerTest extends TestCase assertFalse(url.equals(shortUrl)); assertTrue(shortUrl.length()<=20); } + + /** + * {@inheritDoc} + */ + @Override + protected void setUp() throws Exception + { + this.shortener = new BitlyUrlShortenerImpl();; + shortener.setApiKey("R_ca15c6c89e9b25ccd170bafd209a0d4f"); + shortener.setUrlLength(20); + shortener.setUsername("brianalfresco"); + } } 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 91a0dfb15b..31e3877aa4 100644 --- a/source/java/org/alfresco/service/cmr/publishing/channels/Channel.java +++ b/source/java/org/alfresco/service/cmr/publishing/channels/Channel.java @@ -27,7 +27,7 @@ import org.alfresco.service.namespace.QName; /** * @author Brian - * + * @author Nick Smith */ public interface Channel { @@ -51,4 +51,10 @@ public interface Channel void unPublish(NodeRef nodeToUnpublish); void updateStatus(String status); + /** + * Returns the URL for some published content given the content node in the editorial environment. + * @param publishedNode The node representing the published content in the editorial environment. + * @return a URL for the published content. + */ + String getUrl(NodeRef publishedNode); } \ No newline at end of file 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 ac0ec2dbfd..c9c835cd3b 100644 --- a/source/java/org/alfresco/service/cmr/publishing/channels/ChannelType.java +++ b/source/java/org/alfresco/service/cmr/publishing/channels/ChannelType.java @@ -48,10 +48,15 @@ public interface ChannelType Set getSupportedMimetypes(); Set getSupportedContentTypes(); + + /** + * Returns the URL for a piece of content represented by the supplied node. + * @param node The published content node in the live environment. + * @return a URL for the published content. + */ String getNodeUrl(NodeRef node); int getMaximumStatusLength(); String getAuthorisationUrl(Channel channel, String callbackUrl); - public boolean acceptAuthorisationCallback(Channel channel, Map callbackHeaders, - Map callbackParams); + boolean acceptAuthorisationCallback(Channel channel, Map callbackHeaders, Map callbackParams); }