mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -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);
|
||||||
|
@@ -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,29 +140,34 @@ 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)
|
|
||||||
{
|
{
|
||||||
HashMap<QName, Serializable> actualProps = new HashMap<QName, Serializable>();
|
channelContainer = createChannelContainer(siteId);
|
||||||
if (properties != null)
|
}
|
||||||
{
|
ChannelType channelType = channelTypes.get(channelTypeId);
|
||||||
actualProps.putAll(properties);
|
if(channelType == null)
|
||||||
}
|
{
|
||||||
actualProps.put(ContentModel.PROP_NAME, name);
|
String message = "Channel Type: " + channelTypeId + " does not exist!";
|
||||||
actualProps.put(PROP_CHANNEL_TYPE_ID, channelType.getId());
|
throw new IllegalArgumentException(message);
|
||||||
NodeRef channelNode = channelHelper.createChannelNode(channelContainer, channelType, name, actualProps);
|
}
|
||||||
channel = channelHelper.buildChannelObject(channelNode, this);
|
HashMap<QName, Serializable> actualProps = new HashMap<QName, Serializable>();
|
||||||
|
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
|
// Now create the corresponding channel nodes in each of the
|
||||||
// configured environments
|
// configured environments
|
||||||
// FIXME: BJR: 20110506: Should we provide a means for supplying
|
// FIXME: BJR: 20110506: Should we provide a means for supplying
|
||||||
// separate properties for each environment?
|
// separate properties for each environment?
|
||||||
Map<String, NodeRef> environments = environmentHelper.getEnvironments(siteId);
|
Map<String, NodeRef> environments = environmentHelper.getEnvironments(siteId);
|
||||||
for (NodeRef environment : environments.values())
|
for (NodeRef environment : environments.values())
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user