Publishing: Hide "publish-content" from view in UI (at least until I can define a proper form for it)

Publishing: Improve "publish-content" action so it can handle folder nodes being actioned as well as content nodes

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31368 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Brian Remmington
2011-10-20 07:28:50 +00:00
parent 912e873620
commit f9bd8d3405
3 changed files with 121 additions and 42 deletions

View File

@@ -4,12 +4,13 @@ publishing.neitherNameNorIdSpecified=Neither channel name nor identifier has bee
publish-content.title=Publish publish-content.title=Publish
publish-content.description=Publish content to a publishing channel publish-content.description=Publish content to a publishing channel
publish-content.publish-channel-name.display-label=Channel to publish content to publish-content.publishChannelName.display-label=Channel to publish content to
publish-content.publish-channel-id.display-label=Channel to publish content to publish-content.publishChannelId.display-label=Channel to publish content to
publish-content.unpublish.display-label=Unpublish publish-content.unpublish.display-label=Unpublish
publish-content.status-update.display-label=Status update publish-content.statusUpdate.display-label=Status update
publish-content.include-link-in-status-update.display-label=Append link to status update publish-content.includeLinkInStatusUpdate.display-label=Append link to status update
publish-content.status-update-channel-names.display-label=Channels to post status update to publish-content.statusUpdateChannelNames.display-label=Channels to post status update to
publish-content.status-update-channel-ids.display-label=Channels to post status update to publish-content.statusUpdateChannelIds.display-label=Channels to post status update to
publish-content.scheduled-time.display-label=Time to publish publish-content.scheduledTime.display-label=Scheduled time
publish-content.comment.display-label=Comment publish-content.comment.display-label=Comment
publish-content.nodeToLinkStatusUpdateTo.display-label=Node to link status update to

View File

@@ -75,12 +75,10 @@
<bean id="publish-content" class="org.alfresco.repo.publishing.PublishContentActionExecuter" parent="action-executer"> <bean id="publish-content" class="org.alfresco.repo.publishing.PublishContentActionExecuter" parent="action-executer">
<property name="channelService" ref="ChannelService" /> <property name="channelService" ref="ChannelService" />
<property name="publishingService" ref="PublishingService" /> <property name="publishingService" ref="PublishingService" />
<property name="nodeService" ref="NodeService" />
<property name="dictionaryService" ref="DictionaryService" />
<property name="ignoreLock" value="true" /> <property name="ignoreLock" value="true" />
<property name="applicableTypes"> <property name="publicAction" value="false" />
<list>
<value>{http://www.alfresco.org/model/content/1.0}content</value>
</list>
</property>
</bean> </bean>
<bean id="ac-publishing-channels" class="org.alfresco.repo.publishing.PublishingChannelParameterConstraint" <bean id="ac-publishing-channels" class="org.alfresco.repo.publishing.PublishingChannelParameterConstraint"

View File

@@ -19,12 +19,14 @@
package org.alfresco.repo.publishing; package org.alfresco.repo.publishing;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl; import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.Action;
@@ -32,12 +34,16 @@ import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.action.ParameterizedItem; import org.alfresco.service.cmr.action.ParameterizedItem;
import org.alfresco.service.cmr.action.ParameterizedItemDefinition; import org.alfresco.service.cmr.action.ParameterizedItemDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.publishing.PublishingDetails; import org.alfresco.service.cmr.publishing.PublishingDetails;
import org.alfresco.service.cmr.publishing.PublishingService; import org.alfresco.service.cmr.publishing.PublishingService;
import org.alfresco.service.cmr.publishing.channels.Channel; import org.alfresco.service.cmr.publishing.channels.Channel;
import org.alfresco.service.cmr.publishing.channels.ChannelService; import org.alfresco.service.cmr.publishing.channels.ChannelService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.rule.RuleServiceException; import org.alfresco.service.cmr.rule.RuleServiceException;
import org.alfresco.service.namespace.QName;
/** /**
* This class defines an action that publishes or unpublishes the acted-upon * This class defines an action that publishes or unpublishes the acted-upon
@@ -48,29 +54,29 @@ import org.alfresco.service.cmr.rule.RuleServiceException;
*/ */
public class PublishContentActionExecuter extends ActionExecuterAbstractBase public class PublishContentActionExecuter extends ActionExecuterAbstractBase
{ {
public final static String NAME = "publish_content"; public final static String NAME = "publish-content";
/** /**
* A single-valued, optional text parameter that names the publishing * A single-valued, optional text parameter that names the publishing
* channel to which the specified content is to be published. Although this * channel to which the specified content is to be published. Although this
* is optional, one of either "publish-channel-name" or "publish-channel-id" * is optional, one of either "publishChannelName" or "publishChannelId"
* MUST be specified. If both are specified then "publish-channel-id" takes * MUST be specified. If both are specified then "publishChannelId" takes
* precedence. * precedence.
* *
* @see PublishContentActionExecuter#PARAM_PUBLISH_CHANNEL_ID * @see PublishContentActionExecuter#PARAM_PUBLISH_CHANNEL_ID
*/ */
public final static String PARAM_PUBLISH_CHANNEL_NAME = "publish-channel-name"; public final static String PARAM_PUBLISH_CHANNEL_NAME = "publishChannelName";
/** /**
* A single-valued, optional text parameter that identifies the publishing * A single-valued, optional text parameter that identifies the publishing
* channel to which the specified content is to be published. Although this * channel to which the specified content is to be published. Although this
* is optional, one of either "publish-channel-name" or "publish-channel-id" * is optional, one of either "publishChannelName" or "publishChannelId"
* MUST be specified. If both are specified then "publish-channel-id" takes * MUST be specified. If both are specified then "publishChannelId" takes
* precedence. * precedence.
* *
* @see PublishContentActionExecuter#PARAM_PUBLISH_CHANNEL_NAME * @see PublishContentActionExecuter#PARAM_PUBLISH_CHANNEL_NAME
*/ */
public final static String PARAM_PUBLISH_CHANNEL_ID = "publish-channel-id"; public final static String PARAM_PUBLISH_CHANNEL_ID = "publishChannelId";
/** /**
* A single-valued, optional boolean parameter that indicates whether the * A single-valued, optional boolean parameter that indicates whether the
@@ -86,7 +92,7 @@ public class PublishContentActionExecuter extends ActionExecuterAbstractBase
* *
* @see PublishContentActionExecuter#PARAM_STATUS_UPDATE_CHANNEL_NAMES * @see PublishContentActionExecuter#PARAM_STATUS_UPDATE_CHANNEL_NAMES
*/ */
public final static String PARAM_STATUS_UPDATE = "status-update"; public final static String PARAM_STATUS_UPDATE = "statusUpdate";
/** /**
* A single-valued, optional boolean parameter that specifies whether a link * A single-valued, optional boolean parameter that specifies whether a link
@@ -96,35 +102,47 @@ public class PublishContentActionExecuter extends ActionExecuterAbstractBase
* @see PublishContentActionExecuter#PARAM_STATUS_UPDATE_CHANNEL_NAMES * @see PublishContentActionExecuter#PARAM_STATUS_UPDATE_CHANNEL_NAMES
* @see PublishContentActionExecuter#PARAM_STATUS_UPDATE * @see PublishContentActionExecuter#PARAM_STATUS_UPDATE
*/ */
public final static String PARAM_INCLUDE_LINK_IN_STATUS_UPDATE = "include-link-in-status-update"; public final static String PARAM_INCLUDE_LINK_IN_STATUS_UPDATE = "includeLinkInStatusUpdate";
/**
* A single-valued, optional NodeRef parameter that specifies which published node should be
* referenced by the status update. This is only relevant if the "includeLinkInStatusUpdate" is
* true AND the node being acted upon is a folder AND the "unpublish" parameter value is false.
* If the node being acted on is not a folder then
* the link appended to the status update will always be a link to the published node. If the "unpublish"
* parameter is set to true then no link is appended to the status update.
* @see PublishContentActionExecuter#PARAM_INCLUDE_LINK_IN_STATUS_UPDATE
* @see PublishContentActionExecuter#PARAM_UNPUBLISH
*/
public final static String PARAM_NODE_TO_LINK_STATUS_UPDATE_TO = "nodeToLinkStatusUpdateTo";
/** /**
* A multi-valued, optional text parameter that identifies by name the * A multi-valued, optional text parameter that identifies by name the
* publishing channels to which the status update (if any) should be sent. * publishing channels to which the status update (if any) should be sent.
* If both this parameter and the "status-update-channel-ids" parameter are * If both this parameter and the "statusUpdateChannelIds" parameter are
* given values then they are combined. * given values then they are combined.
* *
* @see PublishContentActionExecuter#PARAM_STATUS_UPDATE * @see PublishContentActionExecuter#PARAM_STATUS_UPDATE
* @see PublishContentActionExecuter#PARAM_STATUS_UPDATE_CHANNEL_IDS * @see PublishContentActionExecuter#PARAM_STATUS_UPDATE_CHANNEL_IDS
*/ */
public final static String PARAM_STATUS_UPDATE_CHANNEL_NAMES = "status-update-channel-names"; public final static String PARAM_STATUS_UPDATE_CHANNEL_NAMES = "statusUpdateChannelNames";
/** /**
* A multi-valued, optional text parameter that identifies the publishing * A multi-valued, optional text parameter that identifies the publishing
* channels to which the status update (if any) should be sent. If both this * channels to which the status update (if any) should be sent. If both this
* parameter and the "status-update-channel-names" parameter are given * parameter and the "statusUpdateChannelNames" parameter are given
* values then they are combined. * values then they are combined.
* *
* @see PublishContentActionExecuter#PARAM_STATUS_UPDATE * @see PublishContentActionExecuter#PARAM_STATUS_UPDATE
* @see PublishContentActionExecuter#PARAM_STATUS_UPDATE_CHANNEL_NAMES * @see PublishContentActionExecuter#PARAM_STATUS_UPDATE_CHANNEL_NAMES
*/ */
public final static String PARAM_STATUS_UPDATE_CHANNEL_IDS = "status-update-channel-ids"; public final static String PARAM_STATUS_UPDATE_CHANNEL_IDS = "statusUpdateChannelIds";
/** /**
* A single-valued, optional datetime parameter that specifies when the * A single-valued, optional datetime parameter that specifies when the
* publish should happen. * publish should happen.
*/ */
public final static String PARAM_SCHEDULED_TIME = "scheduled-time"; public final static String PARAM_SCHEDULED_TIME = "scheduledTime";
/** /**
* A single-valued, optional text parameter that is stored on the publishing * A single-valued, optional text parameter that is stored on the publishing
@@ -137,6 +155,8 @@ public class PublishContentActionExecuter extends ActionExecuterAbstractBase
private PublishingService publishingService; private PublishingService publishingService;
private ChannelService channelService; private ChannelService channelService;
private NodeService nodeService;
private DictionaryService dictionaryService;
public void setPublishingService(PublishingService publishingService) public void setPublishingService(PublishingService publishingService)
{ {
@@ -148,36 +168,40 @@ public class PublishContentActionExecuter extends ActionExecuterAbstractBase
this.channelService = channelService; this.channelService = channelService;
} }
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
{ {
Boolean isUnpublish = (Boolean) action.getParameterValue(PARAM_UNPUBLISH); Boolean isUnpublish = (Boolean) action.getParameterValue(PARAM_UNPUBLISH);
boolean unpublish = ((isUnpublish == null) || isUnpublish); boolean unpublish = ((isUnpublish != null) && isUnpublish);
String publishChannelId = (String) action.getParameterValue(PARAM_PUBLISH_CHANNEL_ID); String publishChannelId = (String) action.getParameterValue(PARAM_PUBLISH_CHANNEL_ID);
String publishChannelName = (String) action.getParameterValue(PARAM_PUBLISH_CHANNEL_NAME); String publishChannelName = (String) action.getParameterValue(PARAM_PUBLISH_CHANNEL_NAME);
String statusUpdate = (String) action.getParameterValue(PARAM_STATUS_UPDATE); String statusUpdate = (String) action.getParameterValue(PARAM_STATUS_UPDATE);
List<String> statusUpdateChannelNames = buildStringList(action.getParameterValue(PARAM_STATUS_UPDATE_CHANNEL_NAMES)); List<String> statusUpdateChannelNames = buildStringList(action
.getParameterValue(PARAM_STATUS_UPDATE_CHANNEL_NAMES));
List<String> statusUpdateChannelIds = buildStringList(action.getParameterValue(PARAM_STATUS_UPDATE_CHANNEL_IDS)); List<String> statusUpdateChannelIds = buildStringList(action.getParameterValue(PARAM_STATUS_UPDATE_CHANNEL_IDS));
Boolean includeLinkInStatusUpdate = (Boolean) action.getParameterValue(PARAM_INCLUDE_LINK_IN_STATUS_UPDATE); Boolean includeLinkInStatusUpdate = (Boolean) action.getParameterValue(PARAM_INCLUDE_LINK_IN_STATUS_UPDATE);
boolean appendLink = ((includeLinkInStatusUpdate == null) || includeLinkInStatusUpdate); boolean appendLink = ((includeLinkInStatusUpdate == null) || includeLinkInStatusUpdate);
Date scheduledTime = (Date) action.getParameterValue(PARAM_SCHEDULED_TIME); Date scheduledTime = (Date) action.getParameterValue(PARAM_SCHEDULED_TIME);
String comment = (String) action.getParameterValue(PARAM_COMMENT); String comment = (String) action.getParameterValue(PARAM_COMMENT);
Channel publishChannel = publishChannelId == null ? channelService.getChannelByName(publishChannelName) : Channel publishChannel = publishChannelId == null ? channelService.getChannelByName(publishChannelName)
channelService.getChannelById(publishChannelId); : channelService.getChannelById(publishChannelId);
if (publishChannel != null) if (publishChannel != null)
{ {
PublishingDetails details = publishingService.createPublishingDetails(); PublishingDetails details = publishingService.createPublishingDetails();
details.setPublishChannelId(publishChannel.getId()); details.setPublishChannelId(publishChannel.getId());
if (unpublish) List<NodeRef> nodes = setNodes(actionedUponNodeRef, unpublish, details);
{
details.addNodesToUnpublish(actionedUponNodeRef);
}
else
{
details.addNodesToPublish(actionedUponNodeRef);
}
if (statusUpdateChannelNames != null) if (statusUpdateChannelNames != null)
{ {
for (String statusUpdateChannelName : statusUpdateChannelNames) for (String statusUpdateChannelName : statusUpdateChannelNames)
@@ -200,12 +224,25 @@ public class PublishContentActionExecuter extends ActionExecuterAbstractBase
} }
} }
} }
if (!details.getStatusUpdateChannels().isEmpty()) if (!unpublish && !details.getStatusUpdateChannels().isEmpty())
{ {
details.setStatusMessage(statusUpdate); details.setStatusMessage(statusUpdate);
if (appendLink) if (appendLink)
{ {
details.setStatusNodeToLinkTo(actionedUponNodeRef); NodeRef nodeToLinkTo = (NodeRef) action.getParameterValue(PARAM_NODE_TO_LINK_STATUS_UPDATE_TO);
if (nodeToLinkTo == null)
{
//No node has been specified explicitly as being the one to link to
//We'll make an assumption if only one node is being published...
if (nodes.size() == 1)
{
nodeToLinkTo = nodes.get(0);
}
}
if ((nodeToLinkTo != null) && nodes.contains(nodeToLinkTo))
{
details.setStatusNodeToLinkTo(nodeToLinkTo);
}
} }
} }
if (scheduledTime != null) if (scheduledTime != null)
@@ -219,16 +256,56 @@ public class PublishContentActionExecuter extends ActionExecuterAbstractBase
} }
else else
{ {
throw new AlfrescoRuntimeException(MSG_CHANNEL_NOT_FOUND, new Object[] { publishChannelId == null ? publishChannelName : publishChannelId}); throw new AlfrescoRuntimeException(MSG_CHANNEL_NOT_FOUND,
new Object[] { publishChannelId == null ? publishChannelName : publishChannelId });
} }
} }
/**
* This method sets the node(s) to publish or unpublish on the supplied publishing details.
* If the actionedUponNode is a folder then it will include all content nodes within that folder.
* @param actionedUponNodeRef
* @param unpublish
* @param details
*/
private List<NodeRef> setNodes(NodeRef actionedUponNodeRef, boolean unpublish, PublishingDetails details)
{
List<NodeRef> nodes = new ArrayList<NodeRef>();
QName nodeType = nodeService.getType(actionedUponNodeRef);
if (dictionaryService.isSubClass(nodeType, ContentModel.TYPE_FOLDER))
{
List<ChildAssociationRef> children = nodeService.getChildAssocs(actionedUponNodeRef);
for (ChildAssociationRef childRef : children)
{
NodeRef child = childRef.getChildRef();
if (dictionaryService.isSubClass(nodeService.getType(child), ContentModel.TYPE_CONTENT))
{
nodes.add(child);
}
}
}
else
{
nodes.add(actionedUponNodeRef);
}
if (unpublish)
{
details.addNodesToUnpublish(nodes);
}
else
{
details.addNodesToPublish(nodes);
}
return nodes;
}
private List<String> buildStringList(Serializable parameterValue) private List<String> buildStringList(Serializable parameterValue)
{ {
List<String> result = null; List<String> result = null;
if (parameterValue != null && String.class.isAssignableFrom(parameterValue.getClass())) if (parameterValue != null && String.class.isAssignableFrom(parameterValue.getClass()))
{ {
String[] split = ((String)parameterValue).split(","); String[] split = ((String) parameterValue).split(",");
result = Arrays.asList(split); result = Arrays.asList(split);
} }
return result; return result;
@@ -261,6 +338,9 @@ public class PublishContentActionExecuter extends ActionExecuterAbstractBase
paramList.add(new ParameterDefinitionImpl(PARAM_SCHEDULED_TIME, DataTypeDefinition.DATETIME, false, paramList.add(new ParameterDefinitionImpl(PARAM_SCHEDULED_TIME, DataTypeDefinition.DATETIME, false,
getParamDisplayLabel(PARAM_SCHEDULED_TIME), false)); getParamDisplayLabel(PARAM_SCHEDULED_TIME), false));
paramList.add(new ParameterDefinitionImpl(PARAM_NODE_TO_LINK_STATUS_UPDATE_TO, DataTypeDefinition.NODE_REF, false,
getParamDisplayLabel(PARAM_NODE_TO_LINK_STATUS_UPDATE_TO), false));
paramList.add(new ParameterDefinitionImpl(PARAM_COMMENT, DataTypeDefinition.TEXT, false, paramList.add(new ParameterDefinitionImpl(PARAM_COMMENT, DataTypeDefinition.TEXT, false,
getParamDisplayLabel(PARAM_COMMENT), false)); getParamDisplayLabel(PARAM_COMMENT), false));
} }