Created channels.get Rest Api webscript. Tested in PublishingRestApiTest

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28454 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
N Smith
2011-06-17 12:46:17 +00:00
parent 830a5e259c
commit f3902d9eb5
3 changed files with 89 additions and 54 deletions

View File

@@ -95,6 +95,10 @@ public class ChannelHelper
public Channel buildChannelObject(NodeRef nodeRef, ChannelService channelService) public Channel buildChannelObject(NodeRef nodeRef, ChannelService channelService)
{ {
if(nodeRef == null || nodeService.exists(nodeRef)==false)
{
return null;
}
Map<QName, Serializable> props = nodeService.getProperties(nodeRef); Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
String channelTypeId = (String) props.get(PublishingModel.PROP_CHANNEL_TYPE_ID); String channelTypeId = (String) props.get(PublishingModel.PROP_CHANNEL_TYPE_ID);
ChannelType channelType = channelService.getChannelType(channelTypeId); ChannelType channelType = channelService.getChannelType(channelTypeId);

View File

@@ -19,7 +19,8 @@
package org.alfresco.repo.publishing; 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.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
@@ -139,10 +140,16 @@ public class ChannelServiceImpl implements ChannelService
public Channel createChannel(String siteId, String channelTypeId, String name, Map<QName, Serializable> properties) public Channel createChannel(String siteId, String channelTypeId, String name, Map<QName, Serializable> properties)
{ {
NodeRef channelContainer = getChannelContainer(siteId); NodeRef channelContainer = getChannelContainer(siteId);
ChannelType channelType = channelTypes.get(channelTypeId); if(channelContainer==null)
Channel channel = null;
if (channelType != null)
{ {
channelContainer = createChannelContainer(siteId);
}
ChannelType channelType = channelTypes.get(channelTypeId);
if(channelType == null)
{
String message = "Channel Type: " + channelTypeId + " does not exist!";
throw new IllegalArgumentException(message);
}
HashMap<QName, Serializable> actualProps = new HashMap<QName, Serializable>(); HashMap<QName, Serializable> actualProps = new HashMap<QName, Serializable>();
if (properties != null) if (properties != null)
{ {
@@ -151,7 +158,7 @@ public class ChannelServiceImpl implements ChannelService
actualProps.put(ContentModel.PROP_NAME, name); actualProps.put(ContentModel.PROP_NAME, name);
actualProps.put(PROP_CHANNEL_TYPE_ID, channelType.getId()); actualProps.put(PROP_CHANNEL_TYPE_ID, channelType.getId());
NodeRef channelNode = channelHelper.createChannelNode(channelContainer, channelType, name, actualProps); NodeRef channelNode = channelHelper.createChannelNode(channelContainer, channelType, name, actualProps);
channel = channelHelper.buildChannelObject(channelNode, this); Channel channel = channelHelper.buildChannelObject(channelNode, this);
// Now create the corresponding channel nodes in each of the // Now create the corresponding channel nodes in each of the
// configured environments // configured environments
@@ -162,7 +169,6 @@ public class ChannelServiceImpl implements ChannelService
{ {
channelHelper.addChannelToEnvironment(environment, channel, actualProps); channelHelper.addChannelToEnvironment(environment, channel, actualProps);
} }
}
return channel; return channel;
} }
@@ -171,10 +177,7 @@ public class ChannelServiceImpl implements ChannelService
*/ */
public void deleteChannel(String siteId, String channelName) public void deleteChannel(String siteId, String channelName)
{ {
Map<String, NodeRef> environments = environmentHelper.getEnvironments(siteId); Set<NodeRef> containers = getAllChannelContainers(siteId);
Set<NodeRef> containers = new HashSet<NodeRef>();
containers.add(getChannelContainer(siteId));
containers.addAll(environments.values());
for (NodeRef channelContainer : containers) for (NodeRef channelContainer : containers)
{ {
NodeRef channel = nodeService.getChildByName(channelContainer, ContentModel.ASSOC_CONTAINS, channelName); NodeRef channel = nodeService.getChildByName(channelContainer, ContentModel.ASSOC_CONTAINS, channelName);
@@ -193,6 +196,10 @@ public class ChannelServiceImpl implements ChannelService
ParameterCheck.mandatory("siteId", siteId); ParameterCheck.mandatory("siteId", siteId);
NodeRef channelContainer = getChannelContainer(siteId); NodeRef channelContainer = getChannelContainer(siteId);
if(channelContainer == null)
{
return Collections.emptyList();
}
Collection<QName> channelNodeTypes = dictionaryService.getSubTypes(TYPE_DELIVERY_CHANNEL, true); Collection<QName> channelNodeTypes = dictionaryService.getSubTypes(TYPE_DELIVERY_CHANNEL, true);
HashSet<QName> childNodeTypeQNames = new HashSet<QName>(channelNodeTypes); HashSet<QName> childNodeTypeQNames = new HashSet<QName>(channelNodeTypes);
List<ChildAssociationRef> channelAssocs = nodeService.getChildAssocs(channelContainer, childNodeTypeQNames); List<ChildAssociationRef> channelAssocs = nodeService.getChildAssocs(channelContainer, childNodeTypeQNames);
@@ -232,27 +239,34 @@ public class ChannelServiceImpl implements ChannelService
return null; return null;
} }
/**
* @param siteId
* @return
*/
private NodeRef getChannelContainer(final String siteId) private NodeRef getChannelContainer(final String siteId)
{
return siteService.getContainer(siteId, CHANNEL_CONTAINER_NAME);
}
private Set<NodeRef> getAllChannelContainers(String siteId)
{
Set<NodeRef> containers = new HashSet<NodeRef>();
Map<String, NodeRef> 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<NodeRef>() return AuthenticationUtil.runAs(new RunAsWork<NodeRef>()
{ {
public NodeRef doWork() throws Exception public NodeRef doWork() throws Exception
{ {
NodeRef channelContainer = siteService.getContainer(siteId, CHANNEL_CONTAINER_NAME); return siteService.createContainer(siteId, CHANNEL_CONTAINER_NAME,
if (channelContainer == null)
{
// No channel container exists for this site yet. Create it.
channelContainer = siteService.createContainer(siteId, CHANNEL_CONTAINER_NAME,
PublishingModel.TYPE_CHANNEL_CONTAINER, null); PublishingModel.TYPE_CHANNEL_CONTAINER, null);
} }
return channelContainer;
}
}, AuthenticationUtil.getSystemUserName()); }, AuthenticationUtil.getSystemUserName());
} }
/** /**
@@ -263,30 +277,28 @@ public class ChannelServiceImpl implements ChannelService
return channelTypes.get(id); return channelTypes.get(id);
} }
/**
* {@inheritDoc}
*/
public NodeFinder getChannelDependancyNodeFinder() public NodeFinder getChannelDependancyNodeFinder()
{ {
return new ChannelDependancyNodeFinder(this); return new ChannelDependancyNodeFinder(this);
} }
/**
* {@inheritDoc}
*/
public NodeFilter getChannelDependancyNodeFilter() public NodeFilter getChannelDependancyNodeFilter()
{ {
return new ChannelDependancyNodeFilter(this); return new ChannelDependancyNodeFilter(this);
} }
/* /**
* (non-Javadoc) * {@inheritDoc}
*
* @see
* org.alfresco.service.cmr.publishing.channels.ChannelService#renameChannel
* (java.lang.String, java.lang.String, java.lang.String)
*/ */
@Override
public void renameChannel(String siteId, String oldName, String newName) public void renameChannel(String siteId, String oldName, String newName)
{ {
Map<String, NodeRef> environments = environmentHelper.getEnvironments(siteId); Set<NodeRef> containers = getAllChannelContainers(siteId);
Set<NodeRef> containers = new HashSet<NodeRef>();
containers.add(getChannelContainer(siteId));
containers.addAll(environments.values());
for (NodeRef channelContainer : containers) for (NodeRef channelContainer : containers)
{ {
NodeRef channel = nodeService.getChildByName(channelContainer, ContentModel.ASSOC_CONTAINS, oldName); NodeRef channel = nodeService.getChildByName(channelContainer, ContentModel.ASSOC_CONTAINS, oldName);
@@ -309,10 +321,7 @@ public class ChannelServiceImpl implements ChannelService
@Override @Override
public void updateChannel(String siteId, String channelName, Map<QName, Serializable> properties) public void updateChannel(String siteId, String channelName, Map<QName, Serializable> properties)
{ {
Map<String, NodeRef> environments = environmentHelper.getEnvironments(siteId); Set<NodeRef> containers = getAllChannelContainers(siteId);
Set<NodeRef> containers = new HashSet<NodeRef>();
containers.add(getChannelContainer(siteId));
containers.addAll(environments.values());
for (NodeRef channelContainer : containers) for (NodeRef channelContainer : containers)
{ {
NodeRef channel = nodeService.getChildByName(channelContainer, ContentModel.ASSOC_CONTAINS, channelName); 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;
}
} }

View File

@@ -23,6 +23,7 @@ import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
/** /**
@@ -99,4 +100,11 @@ public interface ChannelService
* @return The specified Channel objects or <code>null</code> if the specified channel does not exist. * @return The specified Channel objects or <code>null</code> if the specified channel does not exist.
*/ */
Channel getChannel(String siteId, String channelName); 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 <code>null</code> if the specified channel does not exist.
*/
Channel getChannel(String id);
} }