Implemented channel.put Rest method for renaming channels. Also renamed publishing-events-for-node.get to publishing-events.get.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29312 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
N Smith
2011-07-25 15:06:14 +00:00
parent 12a03e1653
commit 4be0baaeb3
9 changed files with 68 additions and 138 deletions

View File

@@ -294,14 +294,14 @@ public class ChannelServiceImpl implements ChannelService
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void renameChannel(String oldName, String newName) public void renameChannel(Channel channel, String newName)
{
NodeRef channelNode = channel.getNodeRef();
if (channelNode != null && nodeService.exists(channelNode))
{ {
NodeRef channelContainer = getChannelContainer(); NodeRef channelContainer = getChannelContainer();
NodeRef channel = nodeService.getChildByName(channelContainer, ContentModel.ASSOC_CONTAINS, oldName); nodeService.setProperty(channelNode, ContentModel.PROP_NAME, newName);
if (channel != null) nodeService.moveNode(channelNode, channelContainer, ContentModel.ASSOC_CONTAINS,
{
nodeService.setProperty(channel, ContentModel.PROP_NAME, newName);
nodeService.moveNode(channel, channelContainer, ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.APP_MODEL_1_0_URI, newName)); QName.createQName(NamespaceService.APP_MODEL_1_0_URI, newName));
} }
} }
@@ -331,8 +331,7 @@ public class ChannelServiceImpl implements ChannelService
@Override @Override
public Channel getChannelById(String id) public Channel getChannelById(String id)
{ {
if(id!=null&& id.isEmpty()==false if(id!=null&& NodeRef.isNodeRef(id))
&& NodeRef.isNodeRef(id))
{ {
NodeRef node = new NodeRef(id); NodeRef node = new NodeRef(id);
return channelHelper.buildChannelObject(node, this); return channelHelper.buildChannelObject(node, this);

View File

@@ -94,7 +94,7 @@ public class ChannelServiceImplIntegratedTest extends AbstractPublishingIntegrat
{ {
String newChannelName = "New Channel Name"; String newChannelName = "New Channel Name";
Channel channel = createChannel(); Channel channel = createChannel();
channelService.renameChannel(channelName, newChannelName); channelService.renameChannel(channel, newChannelName);
Channel renamedChannel = channelService.getChannelById(channel.getId()); Channel renamedChannel = channelService.getChannelById(channel.getId());
assertNotNull(renamedChannel); assertNotNull(renamedChannel);

View File

@@ -1,107 +0,0 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.publishing;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* A utility class to help out with environment-related operations that are used
* by both the channel service and the publishing service.
*
* @author Brian
* @author Nick Smith
*
*/
public class EnvironmentHelper
{
private PublishingRootObject rootObject;
public NodeRef getChannelContainer()
{
return rootObject.getChannelContainer();
}
public PublishingQueueImpl getPublishingQueue()
{
return rootObject.getPublishingQueue();
}
// public NodePublishStatus checkNodeStatus(NodeRef node, String channelId)
// {
// PublishingEvent queuedEvent = getQueuedPublishingEvent(node, channelId);
// PublishingEvent lastEvent= getLastPublishingEvent(node, environment, channelName);
// if(queuedEvent != null)
// {
// if(lastEvent != null)
// {
// return new NodePublishStatusPublishedAndOnQueue(node, channelName, queuedEvent, lastEvent);
// }
// else
// {
// return new NodePublishStatusOnQueue(node, channelName, queuedEvent);
// }
// }
// else
// {
// if(lastEvent != null)
// {
// return new NodePublishStatusPublished(node, channelName, lastEvent);
// }
// else
// {
// return new NodePublishStatusNotPublished(node, channelName);
// }
// }
// }
//
// private PublishingEvent getQueuedPublishingEvent(NodeRef node, String channelId)
// {
// NodeRef queue = getPublishingQueue().getNodeRef();
// Calendar nextPublishTime = null;
// NodeRef nextEventNode = null;
// List<NodeRef> eventNodes = publishingEventHelper.getEventNodesForPublishedNodes(queue, node);
// for (NodeRef eventNode: eventNodes)
// {
// if (isActiveEvent(eventNode))
// {
// Map<QName, Serializable> props = nodeService.getProperties(eventNode);
// Serializable eventChannel = props.get(PublishingModel.PROP_PUBLISHING_EVENT_CHANNEL);
// if(channelId.equals(eventChannel))
// {
// Calendar schedule = publishingEventHelper.getScheduledTime(props);
// if (nextPublishTime == null || schedule.before(nextPublishTime))
// {
// nextPublishTime = schedule;
// nextEventNode = eventNode;
// }
// }
// }
// }
// return publishingEventHelper.getPublishingEvent(nextEventNode);
// }
//
// private boolean isActiveEvent(NodeRef eventNode)
// {
// String statusStr = (String) nodeService.getProperty( eventNode, PROP_PUBLISHING_EVENT_STATUS);
// Status status = Status.valueOf(statusStr);
// return status == Status.IN_PROGRESS || status == Status.SCHEDULED;
// }
}

View File

@@ -509,15 +509,7 @@ public class PublishingEventHelper
} }
} }
public NodeRef getEnvironmentNodeForPublishingEvent(NodeRef publishingEvent) public AssociationRef linkToLastEvent(NodeRef publishedNode, NodeRef eventNode)
{
ChildAssociationRef queueAssoc = nodeService.getPrimaryParent(publishingEvent);
ChildAssociationRef environmentAssoc = nodeService.getPrimaryParent(queueAssoc.getParentRef());
NodeRef environment = environmentAssoc.getParentRef();
return environment;
}
public AssociationRef linkeToLastEvent(NodeRef publishedNode, NodeRef eventNode)
{ {
List<AssociationRef> assocs = nodeService.getTargetAssocs(publishedNode, ASSOC_LAST_PUBLISHING_EVENT); List<AssociationRef> assocs = nodeService.getTargetAssocs(publishedNode, ASSOC_LAST_PUBLISHING_EVENT);
if(isEmpty(assocs)==false) if(isEmpty(assocs)==false)
@@ -528,4 +520,51 @@ public class PublishingEventHelper
} }
return nodeService.createAssociation(publishedNode, eventNode, ASSOC_LAST_PUBLISHING_EVENT); return nodeService.createAssociation(publishedNode, eventNode, ASSOC_LAST_PUBLISHING_EVENT);
} }
// public NodePublishStatus checkNodeStatus(NodeRef node, String channelId, NodeRef queue)
// {
// PublishingEvent queuedEvent = getQueuedPublishingEvent(node, channelId, queue);
// PublishingEvent lastEvent= getLastPublishingEvent(node, channelId, queue);
// if(queuedEvent != null)
// {
// if(lastEvent != null)
// {
// return new NodePublishStatusPublishedAndOnQueue(node, channelId, queuedEvent, lastEvent);
// }
// else
// {
// return new NodePublishStatusOnQueue(node, channelId, queuedEvent);
// }
// }
// else
// {
// if(lastEvent != null)
// {
// return new NodePublishStatusPublished(node, channelId, lastEvent);
// }
// else
// {
// return new NodePublishStatusNotPublished(node, channelId);
// }
// }
// }
//
// private PublishingEvent getLastPublishingEvent(NodeRef node, String channelId, NodeRef queue)
// {
// getEventNodesForPublishedNode(queue, node);
// return null;
// }
//
// private PublishingEvent getQueuedPublishingEvent(NodeRef node, String channelId)
// {
// return publishingEventHelper.getPublishingEvent(nextEventNode);
// }
//
// private boolean isActiveEvent(NodeRef eventNode)
// {
// String statusStr = (String) nodeService.getProperty( eventNode, PROP_PUBLISHING_EVENT_STATUS);
// Status status = Status.valueOf(statusStr);
// return status == Status.IN_PROGRESS || status == Status.SCHEDULED;
// }
} }

View File

@@ -74,7 +74,6 @@ public class PublishingEventProcessor
String inProgressStatus = PublishingEvent.Status.IN_PROGRESS.name(); String inProgressStatus = PublishingEvent.Status.IN_PROGRESS.name();
nodeService.setProperty(eventNode, PublishingModel.PROP_PUBLISHING_EVENT_STATUS, inProgressStatus); nodeService.setProperty(eventNode, PublishingModel.PROP_PUBLISHING_EVENT_STATUS, inProgressStatus);
PublishingEvent event = eventHelper.getPublishingEvent(eventNode); PublishingEvent event = eventHelper.getPublishingEvent(eventNode);
NodeRef environment = eventHelper.getEnvironmentNodeForPublishingEvent(eventNode);
String channelName = event.getChannelId(); String channelName = event.getChannelId();
Channel channel = channelService.getChannelById(channelName); Channel channel = channelService.getChannelById(channelName);
if (channel == null) if (channel == null)
@@ -84,7 +83,7 @@ public class PublishingEventProcessor
else else
{ {
publishEvent(channel, event); publishEvent(channel, event);
updateStatus(channel, environment, event.getStatusUpdate()); updateStatus(channel, event.getStatusUpdate());
String completedStatus = PublishingEvent.Status.COMPLETED.name(); String completedStatus = PublishingEvent.Status.COMPLETED.name();
nodeService.setProperty(eventNode, PublishingModel.PROP_PUBLISHING_EVENT_STATUS, completedStatus); nodeService.setProperty(eventNode, PublishingModel.PROP_PUBLISHING_EVENT_STATUS, completedStatus);
} }
@@ -99,7 +98,7 @@ public class PublishingEventProcessor
} }
} }
public void updateStatus(Channel publishChannel, NodeRef environment, StatusUpdate update) public void updateStatus(Channel publishChannel, StatusUpdate update)
{ {
if(update == null) if(update == null)
{ {
@@ -166,7 +165,7 @@ public class PublishingEventProcessor
{ {
updatePublishedNode(publishedNode, entry); updatePublishedNode(publishedNode, entry);
} }
eventHelper.linkeToLastEvent(publishedNode, eventNode); eventHelper.linkToLastEvent(publishedNode, eventNode);
channel.publish(publishedNode); channel.publish(publishedNode);
return publishedNode; return publishedNode;
} }

View File

@@ -29,12 +29,12 @@ import org.alfresco.service.cmr.repository.NodeRef;
public abstract class BaseNodePublishStatus implements NodePublishStatus public abstract class BaseNodePublishStatus implements NodePublishStatus
{ {
private final NodeRef nodeRef; private final NodeRef nodeRef;
private final String channelName; private final String channelId;
public BaseNodePublishStatus(NodeRef nodeRef, String channelName) public BaseNodePublishStatus(NodeRef nodeRef, String channelName)
{ {
this.nodeRef = nodeRef; this.nodeRef = nodeRef;
this.channelName = channelName; this.channelId = channelName;
} }
/** /**
@@ -48,8 +48,8 @@ public abstract class BaseNodePublishStatus implements NodePublishStatus
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public String getChannelName() public String getChannelId()
{ {
return channelName; return channelId;
} }
} }

View File

@@ -35,5 +35,5 @@ public interface NodePublishStatus
Status getStatus(); Status getStatus();
String getChannelName(); String getChannelId();
} }

View File

@@ -30,9 +30,9 @@ public class NodePublishStatusPublished extends BaseNodePublishStatus
private final PublishingEvent lastEvent; private final PublishingEvent lastEvent;
public NodePublishStatusPublished(NodeRef node, String channelName, PublishingEvent lastEvent) public NodePublishStatusPublished(NodeRef node, String channelId, PublishingEvent lastEvent)
{ {
super(node, channelName); super(node, channelId);
this.lastEvent = lastEvent; this.lastEvent = lastEvent;
} }

View File

@@ -70,10 +70,10 @@ public interface ChannelService
/** /**
* Rename the specified channel * Rename the specified channel
* @param oldName The current name of the channel that is to be renamed. * @param channel The current name of the channel that is to be renamed.
* @param newName The new name of the channel * @param newName The new name of the channel
*/ */
void renameChannel(String oldName, String newName); void renameChannel(Channel channel, String newName);
/** /**
* Update the properties of the specified channel. * Update the properties of the specified channel.