ShowTable of Contents
To archive the content going to follow simple logic of changing the category of content to Archive & content will be in Publish Stage so can be accessed by Menu or Navigator Component. In normal 3 stage workflow we have
Document stages
Documents in Workplace Web Content Management that have workflows enabled (content is a good example of this) are associated with one of the following four stages:
- Draft. In the draft stage, the document has not yet been approved to be released to the live site. Changes are usually being made when the document is in this stage.
- Published. When the document is published, it has been approved to be released to the live site. In order for it to be published, the publish date of the document must have been reached. If it has moved to the workflow stage associated with the publish action, but the publish date has not been reached, the document is in a pending Publish state.
- Expired. The document in the expired stage must have an expiry date set on it. If the document has reached a workflow stage that is associated with the expire action, but the expiry date hasn't yet been reached, the document will be in a pending expiration state.
Workflow actions
Workflow actions are associated with a workflow stage so that when a document enters or exits the workflow stage, the workflow action occurs. There are three different types of workflow actions: Native actions, Email actions, and Scheduled move actions.
Native actions
There are three workflow actions that come predefined with Workplace Web Content Management:
- Expire is used if you want a document to expire. After the published document has been live for a certain amount of time, the document is no longer relevant and should expire. By associating this action with a workflow stage and setting the expiration date on the document itself, you move the document to an expired state when it reaches the stage that has the expire action associated with it.
- Publish is used to move a document to a published state. When the workflow stage with which this action is associated is reached, the document attains a published state. After that happens, the document is available on the live site and viewable through portlets and Workplace Web Content Management requests outside the authoring portlet. Until a document is published, however, it is unavailable outside the realm of authoring (assuming the object is workflow enabled).
An important thing to note about the publish action is that it's possible for a document to reach a stage that has the publish action associated with it, but the document may have a publish date that is later than the current date. If this happens, the document is in a pending published state in which it is in a workflow stage that is associated with the publish action, but the publish date hasn't yet been reached. In this case, the document is not available on the live site until the published date has been reached.
- Publish and Version move the document to the published stage similar to the publish action described above, making it available from the live site. However, it has the additional functionality of creating a version of the document in its current form. If you have enabled versioning on the document type (such as Content or Site Area), then once this action is performed, a copy of the document is created as one version of the document. Versioning allows you to have different versions of the same document. If the author wants to use a previous version of the document, he can revert to it at any time.
- Archive Action(Custom Workflow Action) Change the existing categories to Archive category keepign the same Publish stage of document.
To get this working First deploy the attached ArchiveContentPluginEAR using WAS admin console & start the application. Find attached screen shot of deployment of ear file.
Create Custom Workflow Action - Find attached Workflow Action - Custom Action.png for details
Create Archive Workflow Stage - Find attached Acrchive-Stage.png
Update Workflow & add archive Stage- Find attached Updated-Workflow.png
Once you complete all the changes create content & test content which have now Archive Content. If you want to have content by year wise create category in WCM & get current year & do mapping of category in ArchiveContent.java execute method.
-
package com.ibm.workflow.archive;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.ibm.portal.um.Principal;
import com.ibm.workplace.wcm.api.Content;
import com.ibm.workplace.wcm.api.Document;
import com.ibm.workplace.wcm.api.DocumentId;
import com.ibm.workplace.wcm.api.DocumentIdIterator;
import com.ibm.workplace.wcm.api.DocumentTypes;
import com.ibm.workplace.wcm.api.Workspace;
import com.ibm.workplace.wcm.api.custom.CustomWorkflowAction;
import com.ibm.workplace.wcm.api.custom.CustomWorkflowActionResult;
import com.ibm.workplace.wcm.api.custom.Directives;
public class ArchiveContent implements CustomWorkflowAction{
/** class name for the logger */
private static final String LOG_CLASS = ArchiveContent.class.getName();
/** logging level */
private static final Level LOG_LEVEL = Level.FINER;
/** class logger */
private static final Logger LOGGER = Logger.getLogger(LOG_CLASS);
private static final String ARCHIVE_CATEGORY_NAME = "Archive";
Principal approverPrincipal = null;
Content content = null;
String message = null;
/**
* Get the date to run this action.
*/
public Date getExecuteDate(Document aDocument)
{
return DATE_EXECUTE_NOW;
}
/**
* Changes documents
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public CustomWorkflowActionResult execute(Document aDocument)
{
final String LOG_METHOD = "execute(p_document)";
boolean isLogging = LOGGER.isLoggable(LOG_LEVEL);
if (isLogging)
{
LOGGER.entering(LOG_CLASS, LOG_METHOD, new Object[] {});
LOGGER.fine("aDocument title"+aDocument.getTitle());
}
ActionResultBuilder builder = ActionResultBuilder.with(Directives.CONTINUE);
boolean isInstanceOfContent=aDocument instanceof Content;
if (isLogging)
{
LOGGER.logp(Level.FINE,LOG_CLASS, LOG_METHOD,"aDocument instanceof Content=="+isInstanceOfContent);
}
if (isInstanceOfContent)
{
try
{
content = (Content) aDocument;
Workspace workspace = content.getSourceWorkspace();
DocumentId [] existingCatIds=content.getCategoryIds();
content.removeCategoryIds(existingCatIds);
DocumentIdIterator catIter=workspace.findByType(DocumentTypes.Category);
if (isLogging)
{
LOGGER.logp(Level.FINE,LOG_CLASS, LOG_METHOD,"No of Category=="+catIter.getCount());
}
DocumentId catId = null;
DocumentId[] catIds = null;
catId = (DocumentId)workspace.findByName(DocumentTypes.Category, ARCHIVE_CATEGORY_NAME).next();
catIds = new DocumentId[1];
catIds[0] = catId;
if(catIds.length > 0){
content.addCategoryIds(catIds);
}
if (isLogging)
{
LOGGER.logp(Level.FINE,LOG_CLASS, LOG_METHOD,"Added archive category==");
}
}
catch (Exception exception)
{
exception.printStackTrace();
builder.rollback(exception.getMessage());
}
}else{
builder.rollback("aDocument is not instance of content");
}
if (isLogging)
{
LOGGER.exiting(LOG_CLASS, LOG_METHOD);
}
return builder.toResult();
}
}
/*
* Copyright 2014 IBM Corp.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing permissions and limitations under the
* License.
*/
package com.ibm.workflow.archive;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.ibm.workplace.wcm.api.Document;
import com.ibm.workplace.wcm.api.custom.CustomWorkflowAction;
import com.ibm.workplace.wcm.api.custom.CustomWorkflowActionFactory;
/**
* Simple implementation of a custom workflow action factory.
* The factory follows these rules:
*
* - factory name will be SampleCustomWorkflowActionFactory
* - factory title will be Sample Custom Workflow Action Factory
* - read a property file that stores a list of classnames for the actions
* - Action titles and descriptions will come from the CustomActionResources bundle
* - getAction will use a no-argument constructor to create the action if it is in the list of classes
*
*/
public class CustomWorkflowActionFactoryImpl implements CustomWorkflowActionFactory
{
/** class name for the logger */
private static final String LOG_CLASS = CustomWorkflowActionFactoryImpl.class.getName();
/** logging level */
private static final Level LOG_LEVEL = Level.FINER;
/** class logger */
private static final Logger LOGGER = Logger.getLogger(LOG_CLASS);
/** The unique factory name */
private static final String FACTORY_NAME = "CustomWorkflowActionFactory";
/** Properties file path */
public static final String PROPERTIES = "factory.properties";
/** Actions property. Holds a comma-separated list of action class names. */
public static final String PROPERTY_ACTIONS = "actions";
/** Delimiter used to separate class names in the actions property. */
public static final String ACTIONS_DELIMITER = ",";
/** Set of fully qualified class names for the registered actions for easy lookup */
private Set m_actionClassNames = new HashSet();
/** Array of fully qualified class names for the registered actions for the API */
private String[] m_actionClassNamesArray;
/**
* Construct a simple custom workflow action factory using default properties.
*/
public CustomWorkflowActionFactoryImpl()
{
this(PROPERTIES);
}
/**
* Construct a simple custom workflow action factory
* @param p_propertiesPath Properties file to drive this factory
*/
public CustomWorkflowActionFactoryImpl(String p_propertiesPath)
{
loadProperties(p_propertiesPath);
}
/**
* Load the action class names, titles and descriptions from the default properties file.
*/
protected void loadProperties(String p_propertiesPath)
{
final String LOG_METHOD = "loadProperties(p_propertiesPath)";
boolean isFiner = LOGGER.isLoggable(LOG_LEVEL);
if (isFiner)
{
LOGGER.entering(LOG_CLASS, LOG_METHOD, new Object[] {p_propertiesPath});
}
InputStream stream = CustomWorkflowActionFactoryImpl.class.getResourceAsStream(p_propertiesPath);
Properties properties = new Properties();
try
{
properties.load(stream);
}
catch (IOException e)
{
String msg = CustomActionResources.getFormattedString(CustomActionResources.UNABLE_TO_LOAD_PROPERTIES_1, Locale.getDefault(), new Object[]{e.getMessage()});
LOGGER.log(Level.WARNING, msg, e);
}
String actionsProperty = properties.getProperty(PROPERTY_ACTIONS, "");
StringTokenizer tokenizer = new StringTokenizer(actionsProperty, ACTIONS_DELIMITER);
List actions = new ArrayList();
while (tokenizer.hasMoreTokens())
{
String className = tokenizer.nextToken();
  Add to list of action class names
actions.add(className);
m_actionClassNames.add(className);
}
m_actionClassNamesArray = actions.toArray(new String[actions.size()]);
if (isFiner)
{
LOGGER.exiting(LOG_CLASS, LOG_METHOD);
}
}
/**
* Get the factory name.
* @return Factory name
*/
public String getName()
{
Use a unique name for the factory to avoid name conflicts
return FACTORY_NAME;
}
/**
* Get the display title for this factory.
* @param locale Locale to display title in.
* @return Factory title
*/
public String getTitle(Locale locale)
{
return CustomActionResources.getString(CustomActionResources.FACTORY_TITLE, locale);
}
/**
* Get the registered action names. Uses the class names for names and titles.
* @return Array of action names.
*/
public String[] getActionNames()
{
return m_actionClassNamesArray;
}
/**
* Get the display title for the supplied action name
* @param p_displayLocale Locale to display title in.
* @param p_actionName Action name.
* @return Action display title.
*/
public String getActionTitle(Locale locale, String actionName)
{
return CustomActionResources.getActionTitle(actionName, locale);
}
/**
* Get the description for the supplied action name
* @param locale Locale to display title in.
* @param actionName Action name.
* @return Action display title.
*/
public String getActionDescription(Locale locale, String actionName)
{
return CustomActionResources.getActionDescription(actionName, locale);
}
/**
* Get the custom workflow action for the supplied action name.
* Assumes that the supplied action name is the action class which
* has a no-argument constructor.
* @param actionName Assumed to be the class name
* @param document Target document. Ignored by this implementation.
* @return Custom workflow action. Null if the action could not be retrieved
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public CustomWorkflowAction getAction(String actionName, Document document)
{
final String LOG_METHOD = "getAction(actionName, document)";
boolean isFiner = LOGGER.isLoggable(LOG_LEVEL);
if (isFiner)
{
LOGGER.entering(LOG_CLASS, LOG_METHOD, new Object[] {actionName, document});
}
CustomWorkflowAction action = null;
Determine if the action name is a registered action class name
if (m_actionClassNames.contains(actionName))
{
Use reflection to create a new instance of the action class
  using the no-argument constructor
Object actionObject = null;
try
{
Class actionClass = Class.forName(actionName);
Constructor constructor = actionClass.getConstructor(new Class[]{});
actionObject = constructor.newInstance(new Object[]{});
if (actionObject instanceof CustomWorkflowAction)
{
action = (CustomWorkflowAction) actionObject;
}
else
{
Action object does not implement CustomWorkflowAction interface
System.err.println(ResourceBundleUtility.getFormattedString(
CustomActionResources.BUNDLE_NAME,
CustomActionResources.ACTION_DOES_NOT_IMPLEMENT_INTERFACE_1,
Locale.getDefault(),
new Object[] {actionName}
));
}
}
catch (ClassNotFoundException e)
{
String msg = CustomActionResources.getFormattedString(
CustomActionResources.ACTION_CLASS_NOT_FOUND_1,
Locale.getDefault(),
new Object[]{actionName});
LOGGER.log(Level.WARNING, msg, e);
}
catch (NoSuchMethodException e)
{
String msg = CustomActionResources.getFormattedString(
CustomActionResources.ACTION_CONSTRUCTOR_NOT_FOUND_1,
Locale.getDefault(),
new Object[]{actionName});
LOGGER.log(Level.WARNING, msg, e);
}
catch (InstantiationException e)
{
String msg = CustomActionResources.getFormattedString(
CustomActionResources.UNABLE_TO_INSTANTIATE_ACTION_2,
Locale.getDefault(),
new Object[]{actionName, e.getMessage()});
LOGGER.log(Level.WARNING, msg, e);
}
catch (IllegalAccessException e)
{
String msg = CustomActionResources.getFormattedString(
CustomActionResources.UNABLE_TO_INSTANTIATE_ACTION_2,
Locale.getDefault(),
new Object[]{actionName, e.getMessage()});
LOGGER.log(Level.WARNING, msg, e);
}
catch (InvocationTargetException e)
{
String msg = CustomActionResources.getFormattedString(
CustomActionResources.UNABLE_TO_INSTANTIATE_ACTION_2,
Locale.getDefault(),
new Object[]{actionName, e.getMessage()});
LOGGER.log(Level.WARNING, msg, e);
}
}
else
{
String msg = CustomActionResources.getFormattedString(
CustomActionResources.UNKNOWN_ACTION_NAME_1,
Locale.getDefault(),
new Object[]{actionName});
LOGGER.log(Level.WARNING, msg);
}
if (isFiner)
{
LOGGER.exiting(LOG_CLASS, LOG_METHOD, action);
}
return action;
}
}
/*
* Copyright 2014 IBM Corp.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing permissions and limitations under the
* License.
*/
package com.ibm.workflow.archive;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
* Utility to retrieve messages from a resource bundle.
*/
public class ResourceBundleUtility
{
/**
* Retrieves a resource bundle string with substituted argument values using the
* default locale in the JVM
*
* @param p_bundleName the name of the resource bundle, cannot be null
* @param p_key the key of the string, cannot be null
* @param p_locale Display locale
* @param p_arguments an object array of values to substitute into the
* string. Cannot be null. If there are fewer arguments than required,
* the remaining values will display as "null".
*
* @return the resource bundle string with substituted values
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public static final String getFormattedString(String p_bundleName,
String p_key,
Locale p_locale,
Object[] p_arguments)
{
Locale locale = p_locale;
if (p_locale == null)
{
p_locale = Locale.getDefault();
}
String messagePattern = null;
try
{
ResourceBundle bundle = ResourceBundle.getBundle(p_bundleName, locale);
messagePattern = bundle.getString(p_key);
}
catch (MissingResourceException e)
{
  Ignore missing resource bundle or message
}
String message = null;
if (messagePattern == null)
{
No message pattern found - return a string in the format !p_key!p_arguments
ArrayList argsList = new ArrayList();
if (p_arguments != null)
{
for (int i = 0; i < p_arguments.length; i++)
{
argsList.add(p_arguments[i]);
}
}
message = "!" + p_key + "! " + argsList;
}
else
{
  Format the message pattern to get the message
MessageFormat formatter = new MessageFormat(messagePattern);
formatter.setLocale(locale);
message = formatter.format(p_arguments);
}
return message;
}
/**
* Retrieves a resource bundle string with no argument values using the
* default locale in the JVM
*
* @param p_bundleName the name of the resource bundle, cannot be null
* @param p_key the key of the string, cannot be null
* @param p_locale Display locale
*
* @return the resource bundle string
*/
public static String getString(String p_bundleName, String p_key, Locale p_locale)
{
return getFormattedString(p_bundleName, p_key, p_locale, new Object[]{});
}
}
/*
* Copyright 2014 IBM Corp.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing permissions and limitations under the
* License.
*/
package com.ibm.workflow.archive;
import java.util.Locale;
public class CustomActionResources
{
public static final String BUNDLE_NAME = "com.mca.workflow.archive.CustomActionResources";
/** Prefix used for the title property. */
public static final String PROPERTY_PREFIX_TITLE = "title.";
/** Prefix used for the description property. */
public static final String PROPERTY_PREFIX_DESCRIPTION = "description.";
public static final String FACTORY_TITLE = "FACTORY_TITLE";
public static final String UNKNOWN_ACTION_NAME_1 = "UNKNOWN_ACTION_NAME_1";
public static final String UNABLE_TO_LOAD_PROPERTIES_1 = "UNABLE_TO_LOAD_PROPERTIES_1";
public static final String ACTION_CLASS_NOT_FOUND_1 = "ACTION_CLASS_NOT_FOUND_1";
public static final String ACTION_CONSTRUCTOR_NOT_FOUND_1 = "ACTION_CONSTRUCTOR_NOT_FOUND_1";
public static final String UNABLE_TO_INSTANTIATE_ACTION_2 = "UNABLE_TO_INSTANTIATE_ACTION_2";
public static final String ACTION_DOES_NOT_IMPLEMENT_INTERFACE_1 ="ACTION_DOES_NOT_IMPLEMENT_INTERFACE_1";
public static final String CONFIG_FACTORY_NAME_1 = "CONFIG_FACTORY_NAME_1";
public static final String CONFIG_ACTION_NAMES = "CONFIG_ACTION_NAMES";
public static final String ACTION_MSG_SUCCESS = "ACTION_MSG_SUCCESS";
public static final String ACTION_MSG_CATEGORY_NOT_FOUND_2 = "ACTION_MSG_CATEGORY_NOT_FOUND_2";
public static final String ACTION_MSG_CATEGORY_NOT_DEFINED = "ACTION_MSG_CATEGORY_NOT_DEFINED";
public static final String ACTION_MSG_TARGET_NOT_CONTENT = "ACTION_MSG_TARGET_NOT_CONTENT";
/**
* Returns the title corresponding to the action supplied.
*
* @param actionClassName the custom workflow action class name
* @param locale the locale
*
* @return the title corresponding to the action supplied.
*/
public static String getActionTitle(String actionClassName, Locale locale)
{
return getString(PROPERTY_PREFIX_TITLE + actionClassName, locale);
}
/**
* Returns the description corresponding to the action supplied.
*
* @param actionClassName the custom workflow action class name
* @param locale the locale
*
* @return the description corresponding to the action supplied.
*/
public static String getActionDescription(String actionClassName, Locale locale)
{
return getString(PROPERTY_PREFIX_DESCRIPTION + actionClassName, locale);
}
/**
* Retrieves the resource bundle string with substituted argument values from
* the CustomActionResources bundle.
*
* @param resourceKey the key of the string, cannot be null
* @param locale Display locale
* @param arguments an object array of values to substitute into the
* string. Cannot be null. If there are fewer arguments than required,
* the remaining values will display as "null".
*
* @return the resource bundle string with substituted values
*/
public static String getFormattedString(String resourceKey, Locale locale, Object[] arguments)
{
return ResourceBundleUtility.getFormattedString(
CustomActionResources.BUNDLE_NAME,
resourceKey,
locale,
arguments
);
}
/**
* Retrieves a resource bundle string with no argument values from
* the CustomActionResources bundle.
*
* @param resourceKey the key of the string, cannot be null
* @param locale Display locale
*
* @return the resource bundle string
*/
public static String getString(String resourceKey, Locale locale)
{
return ResourceBundleUtility.getString(
CustomActionResources.BUNDLE_NAME,
resourceKey,
locale
);
}
}
/*
* Copyright 2014 IBM Corp.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing permissions and limitations under the
* License.
*/
package com.ibm.workflow.archive;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.ibm.workplace.wcm.api.WebContentCustomWorkflowService;
import com.ibm.workplace.wcm.api.custom.CustomWorkflowActionResult;
import com.ibm.workplace.wcm.api.custom.Directive;
import com.ibm.workplace.wcm.api.custom.DirectiveParams;
import com.ibm.workplace.wcm.api.custom.Directives;
import com.ibm.workplace.wcm.api.custom.RollbackDirectiveParams;
/**
* Builder to help generate the CustomWorkflowActionResult that are returned to WCM
* after executing the custom workflow actions.
*/
public class ActionResultBuilder
{
/** Class name for the logger */
private static final String LOG_CLASS = ActionResultBuilder.class.getName();
/** Class logger */
private static final Logger LOGGER = Logger.getLogger(LOG_CLASS);
/** The message to return to WCM */
String message;
/** The directive to return to WCM */
Directive directive;
/** The directive params that match the directive passed in. */
DirectiveParams params;
/** Custom Workflow Service JNDI name */
private static final String WCM_CUSTOM_WORKFLOW_SERVICE = "portal:service/wcm/WebContentCustomWorkflowService";
/** Reference to the WebContentCustomWorkflowService */
private static WebContentCustomWorkflowService CUSTOM_WF_SERVICE;
static
{
try
{
  Construct and inital Context
InitialContext ctx = new InitialContext();
Retrieve Custom Workflow Service
CUSTOM_WF_SERVICE = (WebContentCustomWorkflowService) ctx.lookup(WCM_CUSTOM_WORKFLOW_SERVICE);
}
catch (NamingException ne)
{
  Exception retrieving Service
LOGGER.log(Level.SEVERE, ne.getMessage(), ne);
}
}
/**
* Constructor
* @param directive the initial directive. If none supplied defaults to CONTINUE
*/
private ActionResultBuilder(Directive directive)
{
if (directive != null)
{
this.directive = directive;
}
else
{
directive = Directives.CONTINUE;
}
}
/**
* Create a new builder with the initial directive
*
* @param directive the directive
*
* @return new builder with the initial directive
*/
public static final ActionResultBuilder with(Directive directive)
{
return new ActionResultBuilder(directive);
}
/**
* Set the directive to return to WCM. Null values will be ignored.
*
*
Note if directive params have been set for a previous directive they will be cleared.
*
* @param directive the directive to return to WCM
*
* @return this builder
*/
public ActionResultBuilder directive(Directive directive)
{
if (directive != null)
{
this.directive = directive;
checkParamsMatchDirectiveType();
}
return this;
}
/**
* Checks that the directive params are valid for the current directive. If they are not
* then they will be cleared.
*/
private void checkParamsMatchDirectiveType()
{
if (params != null && directive != null)
{
DirectiveParams mockParams = directive.createDirectiveParams();
if (mockParams != null && !mockParams.getClass().isAssignableFrom(this.params.getClass()))
{
this.params = null;
}
}
}
/**
*
* message description
* @param message
* @return this builder
*/
public ActionResultBuilder message(String message)
{
this.message = message;
return this;
}
/**
* Set the directive params to return to WCM. If the params
* are not compatible with the current directive then they will be ignored
*
* @param params the directive params
*
* @return this builder
*/
public ActionResultBuilder params(DirectiveParams params)
{
this.params = params;
checkParamsMatchDirectiveType();
return this;
}
/**
* Set the message to return to WCM
*
* @param message the message
*
* @return this builder
*/
public ActionResultBuilder rollback(String message)
{
this.directive = Directives.ROLLBACK_DOCUMENT;
RollbackDirectiveParams params = (RollbackDirectiveParams) Directives.ROLLBACK_DOCUMENT.createDirectiveParams();
params.setCustomErrorMsg(message);
return this;
}
/**
* Returns the CustomWorkflowActionResult with the values set on this builder
*
* @return CustomWorkflowActionResult with the values set on this builder
*/
public CustomWorkflowActionResult toResult()
{
Create a result object
return CUSTOM_WF_SERVICE.createResult(this.directive, this.message, this.params);
}
}
CustomActionResources.properties
# Action titles and descriptions can be assigned to each action by specifying properties
- Action title. Format: title.=Title text
- Action description. Format: description.=Description text
title.com.ibm.workflow.archive.ArchiveContent=ArchiveContent
description.com.ibm.workflow.archive.ArchiveContent=Change the category of the item to the archive category
FACTORY_TITLE=Custom Workflow Actions
UNKNOWN_ACTION_NAME_1=Unknown action name {0}. Action name is not in the list of registered class names.
UNABLE_TO_LOAD_PROPERTIES_1=Unable to load properties file. Exception: {0}
ACTION_CLASS_NOT_FOUND_1=Action class name {0} was not found.
ACTION_CONSTRUCTOR_NOT_FOUND_1=The no-argument constructor for action class {0} was not found.
UNABLE_TO_INSTANTIATE_ACTION_2=Unable to instantiate action class {0}. Exception: {1}
ACTION_DOES_NOT_IMPLEMENT_INTERFACE_1=Action class {0} does not implement the CustomWorkflowAction interface.
CONFIG_FACTORY_NAME_1=Configured factory name: {0}
CONFIG_ACTION_NAMES=Configured action class names:
ACTION_MSG_SUCCESS=Categories were added successfully
ACTION_MSG_CATEGORY_NOT_FOUND_2=Category {0} was not found in library {1}. No change was made.
ACTION_MSG_CATEGORY_NOT_DEFINED=Category name was not defined in the properties file. No change was made
ACTION_MSG_TARGET_NOT_CONTENT=Target document was not Content. No change was made.
factory.properties
# Registered action class names. Use fully qualified class names.
- Use a comma-separated string to specify more than one action name.
- Order of the class names specify the order of the actions in getActionNames().
- e.g. actions=com.ibm.workplace.wcm.sample.customworkflowaction.ActionA,com.ibm.workplace.wcm.sample.customworkflowaction.ActionB
actions=com.ibm.workflow.archive.ArchiveContent