diff --git a/source/java/org/alfresco/repo/publishing/ChannelHelper.java b/source/java/org/alfresco/repo/publishing/ChannelHelper.java index 5e7784666d..f88d6d1bd9 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelHelper.java +++ b/source/java/org/alfresco/repo/publishing/ChannelHelper.java @@ -95,6 +95,10 @@ public class ChannelHelper public Channel buildChannelObject(NodeRef nodeRef, ChannelService channelService) { + if(nodeRef == null || nodeService.exists(nodeRef)==false) + { + return null; + } Map props = nodeService.getProperties(nodeRef); String channelTypeId = (String) props.get(PublishingModel.PROP_CHANNEL_TYPE_ID); ChannelType channelType = channelService.getChannelType(channelTypeId); diff --git a/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java b/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java index 4fb44d0fa6..995434a9d9 100644 --- a/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java +++ b/source/java/org/alfresco/repo/publishing/ChannelServiceImpl.java @@ -19,7 +19,8 @@ package org.alfresco.repo.publishing; -import static org.alfresco.repo.publishing.PublishingModel.*; +import static org.alfresco.repo.publishing.PublishingModel.PROP_CHANNEL_TYPE_ID; +import static org.alfresco.repo.publishing.PublishingModel.TYPE_DELIVERY_CHANNEL; import java.io.Serializable; import java.util.ArrayList; @@ -139,29 +140,34 @@ public class ChannelServiceImpl implements ChannelService public Channel createChannel(String siteId, String channelTypeId, String name, Map properties) { NodeRef channelContainer = getChannelContainer(siteId); - ChannelType channelType = channelTypes.get(channelTypeId); - Channel channel = null; - if (channelType != null) + if(channelContainer==null) { - HashMap actualProps = new HashMap(); - if (properties != null) - { - actualProps.putAll(properties); - } - actualProps.put(ContentModel.PROP_NAME, name); - actualProps.put(PROP_CHANNEL_TYPE_ID, channelType.getId()); - NodeRef channelNode = channelHelper.createChannelNode(channelContainer, channelType, name, actualProps); - channel = channelHelper.buildChannelObject(channelNode, this); + channelContainer = createChannelContainer(siteId); + } + ChannelType channelType = channelTypes.get(channelTypeId); + if(channelType == null) + { + String message = "Channel Type: " + channelTypeId + " does not exist!"; + throw new IllegalArgumentException(message); + } + HashMap actualProps = new HashMap(); + if (properties != null) + { + actualProps.putAll(properties); + } + actualProps.put(ContentModel.PROP_NAME, name); + actualProps.put(PROP_CHANNEL_TYPE_ID, channelType.getId()); + NodeRef channelNode = channelHelper.createChannelNode(channelContainer, channelType, name, actualProps); + Channel channel = channelHelper.buildChannelObject(channelNode, this); - // Now create the corresponding channel nodes in each of the - // configured environments - // FIXME: BJR: 20110506: Should we provide a means for supplying - // separate properties for each environment? - Map environments = environmentHelper.getEnvironments(siteId); - for (NodeRef environment : environments.values()) - { - channelHelper.addChannelToEnvironment(environment, channel, actualProps); - } + // Now create the corresponding channel nodes in each of the + // configured environments + // FIXME: BJR: 20110506: Should we provide a means for supplying + // separate properties for each environment? + Map environments = environmentHelper.getEnvironments(siteId); + for (NodeRef environment : environments.values()) + { + channelHelper.addChannelToEnvironment(environment, channel, actualProps); } return channel; } @@ -171,10 +177,7 @@ public class ChannelServiceImpl implements ChannelService */ public void deleteChannel(String siteId, String channelName) { - Map environments = environmentHelper.getEnvironments(siteId); - Set containers = new HashSet(); - containers.add(getChannelContainer(siteId)); - containers.addAll(environments.values()); + Set containers = getAllChannelContainers(siteId); for (NodeRef channelContainer : containers) { NodeRef channel = nodeService.getChildByName(channelContainer, ContentModel.ASSOC_CONTAINS, channelName); @@ -193,6 +196,10 @@ public class ChannelServiceImpl implements ChannelService ParameterCheck.mandatory("siteId", siteId); NodeRef channelContainer = getChannelContainer(siteId); + if(channelContainer == null) + { + return Collections.emptyList(); + } Collection channelNodeTypes = dictionaryService.getSubTypes(TYPE_DELIVERY_CHANNEL, true); HashSet childNodeTypeQNames = new HashSet(channelNodeTypes); List channelAssocs = nodeService.getChildAssocs(channelContainer, childNodeTypeQNames); @@ -232,27 +239,34 @@ public class ChannelServiceImpl implements ChannelService return null; } - /** - * @param siteId - * @return - */ private NodeRef getChannelContainer(final String siteId) + { + return siteService.getContainer(siteId, CHANNEL_CONTAINER_NAME); + } + + private Set getAllChannelContainers(String siteId) + { + Set containers = new HashSet(); + Map environments = environmentHelper.getEnvironments(siteId); + containers.addAll(environments.values()); + NodeRef editorialContainer = getChannelContainer(siteId); + if(editorialContainer!=null) + { + containers.add(editorialContainer); + } + return containers; + } + + private NodeRef createChannelContainer(final String siteId) { return AuthenticationUtil.runAs(new RunAsWork() { public NodeRef doWork() throws Exception { - NodeRef channelContainer = siteService.getContainer(siteId, CHANNEL_CONTAINER_NAME); - if (channelContainer == null) - { - // No channel container exists for this site yet. Create it. - channelContainer = siteService.createContainer(siteId, CHANNEL_CONTAINER_NAME, + return siteService.createContainer(siteId, CHANNEL_CONTAINER_NAME, PublishingModel.TYPE_CHANNEL_CONTAINER, null); - } - return channelContainer; } }, AuthenticationUtil.getSystemUserName()); - } /** @@ -263,30 +277,28 @@ public class ChannelServiceImpl implements ChannelService return channelTypes.get(id); } + /** + * {@inheritDoc} + */ public NodeFinder getChannelDependancyNodeFinder() { return new ChannelDependancyNodeFinder(this); } + /** + * {@inheritDoc} + */ public NodeFilter getChannelDependancyNodeFilter() { return new ChannelDependancyNodeFilter(this); } - /* - * (non-Javadoc) - * - * @see - * org.alfresco.service.cmr.publishing.channels.ChannelService#renameChannel - * (java.lang.String, java.lang.String, java.lang.String) - */ - @Override + /** + * {@inheritDoc} + */ public void renameChannel(String siteId, String oldName, String newName) { - Map environments = environmentHelper.getEnvironments(siteId); - Set containers = new HashSet(); - containers.add(getChannelContainer(siteId)); - containers.addAll(environments.values()); + Set containers = getAllChannelContainers(siteId); for (NodeRef channelContainer : containers) { NodeRef channel = nodeService.getChildByName(channelContainer, ContentModel.ASSOC_CONTAINS, oldName); @@ -309,10 +321,7 @@ public class ChannelServiceImpl implements ChannelService @Override public void updateChannel(String siteId, String channelName, Map properties) { - Map environments = environmentHelper.getEnvironments(siteId); - Set containers = new HashSet(); - containers.add(getChannelContainer(siteId)); - containers.addAll(environments.values()); + Set containers = getAllChannelContainers(siteId); for (NodeRef channelContainer : containers) { NodeRef channel = nodeService.getChildByName(channelContainer, ContentModel.ASSOC_CONTAINS, channelName); @@ -323,4 +332,18 @@ public class ChannelServiceImpl implements ChannelService } } + /** + * {@inheritDoc} + */ + @Override + public Channel getChannel(String id) + { + if(id!=null) + { + NodeRef node = new NodeRef(id); + return channelHelper.buildChannelObject(node, this); + } + return null; + } + } diff --git a/source/java/org/alfresco/service/cmr/publishing/channels/ChannelService.java b/source/java/org/alfresco/service/cmr/publishing/channels/ChannelService.java index d290edecee..64137262f1 100644 --- a/source/java/org/alfresco/service/cmr/publishing/channels/ChannelService.java +++ b/source/java/org/alfresco/service/cmr/publishing/channels/ChannelService.java @@ -23,6 +23,7 @@ import java.io.Serializable; import java.util.List; import java.util.Map; +import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.namespace.QName; /** @@ -99,4 +100,11 @@ public interface ChannelService * @return The specified Channel objects or null if the specified channel does not exist. */ Channel getChannel(String siteId, String channelName); + + /** + * Retrieve the channel with the given id. + * @param id The string value of the channel {@link NodeRef}. + * @return The specified Channel objects or null if the specified channel does not exist. + */ + Channel getChannel(String id); }