Merged up to HEAD.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3129 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-06-16 19:18:30 +00:00
parent 77df6eb45d
commit d2f8666983
39 changed files with 2129 additions and 1142 deletions

View File

@@ -1,7 +1,6 @@
package org.alfresco.web.bean.rules;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -16,25 +15,21 @@ import javax.faces.model.SelectItem;
import org.alfresco.config.Config;
import org.alfresco.config.ConfigElement;
import org.alfresco.config.ConfigService;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.evaluator.CompareMimeTypeEvaluator;
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
import org.alfresco.repo.action.evaluator.HasAspectEvaluator;
import org.alfresco.repo.action.evaluator.InCategoryEvaluator;
import org.alfresco.repo.action.evaluator.IsSubTypeEvaluator;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ActionConditionDefinition;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.rule.Rule;
import org.alfresco.service.cmr.rule.RuleService;
import org.alfresco.service.cmr.rule.RuleType;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.actions.BaseActionWizard;
import org.alfresco.web.bean.actions.IHandler;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.rules.handlers.BaseConditionHandler;
import org.alfresco.web.data.IDataContainer;
import org.alfresco.web.data.QuickSort;
import org.alfresco.web.ui.common.Utils;
@@ -48,9 +43,8 @@ import org.apache.commons.logging.LogFactory;
*/
public class CreateRuleWizard extends BaseActionWizard
{
public static final String PROP_CONDITION_NAME = "conditionName";
public static final String PROP_CONDITION_SUMMARY = "conditionSummary";
public static final String PROP_CONDITION_NOT = "notcondition";
protected static final String PROP_CONDITION_NAME = "conditionName";
protected static final String PROP_CONDITION_SUMMARY = "conditionSummary";
protected RuleService ruleService;
protected RulesBean rulesBean;
@@ -60,6 +54,7 @@ public class CreateRuleWizard extends BaseActionWizard
private List<SelectItem> types;
private List<SelectItem> conditions;
protected Map<String, IHandler> conditionHandlers;
protected Map<String, Serializable> currentConditionProperties;
protected List<Map<String, Serializable>> allConditionsProperties;
@@ -73,8 +68,6 @@ public class CreateRuleWizard extends BaseActionWizard
protected boolean applyToSubSpaces;
protected boolean editingCondition;
protected static final String CONDITION_PAGES_LOCATION = "/jsp/rules/";
private static final Log logger = LogFactory.getLog(CreateRuleWizard.class);
// ------------------------------------------------------------------------------
@@ -94,6 +87,8 @@ public class CreateRuleWizard extends BaseActionWizard
this.conditions = null;
this.allConditionsProperties = new ArrayList<Map<String, Serializable>>();
initialiseConditionHandlers();
}
@Override
@@ -488,29 +483,31 @@ public class CreateRuleWizard extends BaseActionWizard
FacesContext context = FacesContext.getCurrentInstance();
this.returnViewId = context.getViewRoot().getViewId();
String viewId = calculateConditionViewId(this.condition);
String viewId = null;
HashMap<String, Serializable> condProps = new HashMap<String, Serializable>(3);
condProps.put(PROP_CONDITION_NAME, this.condition);
this.currentConditionProperties = condProps;
// determine whether the condition being added has any parameters
ActionConditionDefinition conditionDef = this.actionService.
getActionConditionDefinition(this.condition);
if (conditionDef.hasParameterDefinitions())
// get the handler for the condition, if there isn't one we presume it
// is a no-parameter condition
IHandler handler = this.conditionHandlers.get(this.condition);
if (handler != null)
{
// setup any defaults for the UI and override the viewId if necessary
String overridenViewId = setupUIDefaultsForCondition(condProps);
if (overridenViewId != null)
{
viewId = overridenViewId;
}
// setup any UI defaults the condition may have and get the location of
// the JSP used to collect the parameters
handler.setupUIDefaults(condProps);
viewId = handler.getJSPPath();
}
else
{
// just add the condition to the list and use the title as the summary
// just add the action to the list and use the title as the summary
ActionConditionDefinition conditionDef = this.actionService.
getActionConditionDefinition(this.condition);
condProps.put(PROP_CONDITION_SUMMARY, conditionDef.getTitle());
condProps.put(PROP_CONDITION_NOT, Boolean.FALSE);
condProps.put(BaseConditionHandler.PROP_CONDITION_NOT, Boolean.FALSE);
// add the no params marker so we can disable the edit action
condProps.put(NO_PARAMS_MARKER, "no-params");
this.allConditionsProperties.add(condProps);
// come back to the same page we're on now as there are no params to collect
@@ -543,8 +540,9 @@ public class CreateRuleWizard extends BaseActionWizard
FacesContext context = FacesContext.getCurrentInstance();
this.returnViewId = context.getViewRoot().getViewId();
// refresh the wizard
goToPage(context, calculateConditionViewId(this.condition));
// go to the condition page (as there is an edit option visible,
// there must be a handler for the condition so we don't check)
goToPage(context, this.conditionHandlers.get(this.condition).getJSPPath());
}
/**
@@ -553,7 +551,11 @@ public class CreateRuleWizard extends BaseActionWizard
public void addCondition()
{
FacesContext context = FacesContext.getCurrentInstance();
String summary = buildConditionSummary();
// this is called from the actions page so there must be a handler
// present so there's no need to check for null
String summary = this.conditionHandlers.get(this.condition).generateSummary(
context, this, this.currentConditionProperties);
if (summary != null)
{
@@ -654,8 +656,14 @@ public class CreateRuleWizard extends BaseActionWizard
{
String conditionName = (String)condParams.get(PROP_CONDITION_NAME);
this.condition = conditionName;
this.currentConditionProperties = condParams;
Map<String, Serializable> repoCondParams = buildConditionParams();
// get the condition handler to prepare for the save
Map<String, Serializable> repoCondParams = new HashMap<String, Serializable>();
IHandler handler = this.conditionHandlers.get(this.condition);
if (handler != null)
{
handler.prepareForSave(condParams, repoCondParams);
}
// add the condition to the rule
ActionCondition condition = this.actionService.
@@ -663,7 +671,7 @@ public class CreateRuleWizard extends BaseActionWizard
condition.setParameterValues(repoCondParams);
// specify whether the condition result should be inverted
Boolean not = (Boolean)condParams.get(PROP_CONDITION_NOT);
Boolean not = (Boolean)condParams.get(BaseConditionHandler.PROP_CONDITION_NOT);
condition.setInvertCondition(((Boolean)not).booleanValue());
rule.addActionCondition(condition);
@@ -676,8 +684,14 @@ public class CreateRuleWizard extends BaseActionWizard
// to setup the currentActionProperties and action variables
String actionName = (String)actionParams.get(PROP_ACTION_NAME);
this.action = actionName;
this.currentActionProperties = actionParams;
Map<String, Serializable> repoActionParams = buildActionParams();
// get the action handler to prepare for the save
Map<String, Serializable> repoActionParams = new HashMap<String, Serializable>();
IHandler handler = this.actionHandlers.get(this.action);
if (handler != null)
{
handler.prepareForSave(actionParams, repoActionParams);
}
// add the action to the rule
Action action = this.actionService.createAction(actionName);
@@ -689,170 +703,53 @@ public class CreateRuleWizard extends BaseActionWizard
}
/**
* Sets up any default state required by the UI for collecting the
* condition settings. The view id to use for the condition UI can also
* be overridden by returing the path to the relevant JSP.
*
* @props The map of properties being used for the current condition
* @return An optional overridden JSP to use for condition settings collection
* Initialises the condition handlers from the current configuration.
*/
protected String setupUIDefaultsForCondition(HashMap<String, Serializable> props)
protected void initialiseConditionHandlers()
{
// NOTE: none of the built in conditions have any defaults to setup
return null;
}
/**
* Builds the Map of properties for the given condition in the format the repo is expecting
*
* @return The Map the repo is expecting
*/
protected Map<String, Serializable> buildConditionParams()
{
Map<String, Serializable> repoParams = new HashMap<String, Serializable>();
if (ComparePropertyValueEvaluator.NAME.equals(this.condition))
if (this.conditionHandlers == null)
{
// add the text to compare
String text = (String)this.currentConditionProperties.get(PROP_CONTAINS_TEXT);
repoParams.put(ComparePropertyValueEvaluator.PARAM_VALUE, text);
}
else if (InCategoryEvaluator.NAME.equals(this.condition))
{
// put the selected category in the condition params
NodeRef nodeRef = (NodeRef)this.currentConditionProperties.get(PROP_CATEGORY);
repoParams.put(InCategoryEvaluator.PARAM_CATEGORY_VALUE, nodeRef);
// add the classifiable aspect
repoParams.put(InCategoryEvaluator.PARAM_CATEGORY_ASPECT, ContentModel.ASPECT_GEN_CLASSIFIABLE);
}
else if (IsSubTypeEvaluator.NAME.equals(this.condition))
{
// add the model type
QName type = QName.createQName((String)this.currentConditionProperties.get(PROP_MODEL_TYPE));
repoParams.put(IsSubTypeEvaluator.PARAM_TYPE, type);
}
else if (HasAspectEvaluator.NAME.equals(this.condition))
{
// add the aspect
QName aspect = QName.createQName((String)this.currentConditionProperties.get(PROP_ASPECT));
repoParams.put(HasAspectEvaluator.PARAM_ASPECT, aspect);
}
else if (CompareMimeTypeEvaluator.NAME.equals(this.condition))
{
// add the mimetype
String mimeType = (String)this.currentConditionProperties.get(PROP_MIMETYPE);
repoParams.put(CompareMimeTypeEvaluator.PARAM_VALUE, mimeType);
}
return repoParams;
}
/**
* Returns a summary string for the current condition
*
* @return The summary or null if a summary could not be built
*/
protected String buildConditionSummary()
{
String summary = null;
FacesContext context = FacesContext.getCurrentInstance();
Boolean not = (Boolean)this.currentConditionProperties.get(PROP_CONDITION_NOT);
if (ComparePropertyValueEvaluator.NAME.equals(this.condition))
{
String msgId = not.booleanValue() ?
"condition_compare_property_value_not" : "condition_compare_property_value";
String text = (String)this.currentConditionProperties.get(PROP_CONTAINS_TEXT);
summary = MessageFormat.format(Application.getMessage(context, msgId),
new Object[] {text});
}
else if (InCategoryEvaluator.NAME.equals(this.condition))
{
String msgId = not.booleanValue() ? "condition_in_category_not" : "condition_in_category";
String name = Repository.getNameForNode(this.nodeService,
(NodeRef)this.currentConditionProperties.get(PROP_CATEGORY));
summary = MessageFormat.format(Application.getMessage(context, msgId),
new Object[] {name});
}
else if (IsSubTypeEvaluator.NAME.equals(this.condition))
{
String msgId = not.booleanValue() ? "condition_is_subtype_not" : "condition_is_subtype";
String label = null;
String typeName = (String)this.currentConditionProperties.get(PROP_MODEL_TYPE);
for (SelectItem item : this.getModelTypes())
ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
Config wizardCfg = svc.getConfig("Action Wizards");
if (wizardCfg != null)
{
if (item.getValue().equals(typeName))
ConfigElement conditionHandlerCfg = wizardCfg.getConfigElement("condition-handlers");
if (conditionHandlerCfg != null)
{
label = item.getLabel();
break;
this.conditionHandlers = new HashMap<String, IHandler>(20);
// instantiate each handler and store in the map
for (ConfigElement child : conditionHandlerCfg.getChildren())
{
String conditionName = child.getAttribute("name");
String handlerClass = child.getAttribute("class");
if (conditionName != null && conditionName.length() > 0 &&
handlerClass != null && handlerClass.length() > 0)
{
try
{
Class klass = Class.forName(handlerClass);
IHandler handler = (IHandler)klass.newInstance();
this.conditionHandlers.put(conditionName, handler);
}
catch (Exception e)
{
throw new AlfrescoRuntimeException("Failed to setup condition handler for '" +
conditionName + "'", e);
}
}
}
}
else
{
logger.warn("Could not find 'condition-handlers' configuration element");
}
}
summary = MessageFormat.format(Application.getMessage(context, msgId),
new Object[] {label});
}
else if (HasAspectEvaluator.NAME.equals(this.condition))
{
String msgId = not.booleanValue() ? "condition_has_aspect_not" : "condition_has_aspect";
String label = null;
String aspectName = (String)this.currentConditionProperties.get(PROP_ASPECT);
for (SelectItem item : this.getAspects())
else
{
if (item.getValue().equals(aspectName))
{
label = item.getLabel();
break;
}
logger.warn("Could not find 'Action Wizards' configuration section");
}
summary = MessageFormat.format(Application.getMessage(context, msgId),
new Object[] {label});
}
else if (CompareMimeTypeEvaluator.NAME.equals(this.condition))
{
String msgId = not.booleanValue() ? "condition_compare_mime_type_not" : "condition_compare_mime_type";
String label = null;
String mimetype = (String)this.currentConditionProperties.get(PROP_MIMETYPE);
for (SelectItem item : this.getMimeTypes())
{
if (item.getValue().equals(mimetype))
{
label = item.getLabel();
break;
}
}
summary = MessageFormat.format(Application.getMessage(context, msgId),
new Object[] {label});
}
else
{
// as the default case (i.e. for conditions with no parameters) use the title
ActionConditionDefinition conditionDef = this.actionService.
getActionConditionDefinition(this.condition);
summary = conditionDef.getTitle();
}
return summary;
}
/**
* Calculates the viewId for the given condition id
*
* @param conditionId The id of the condition to generate the view id for
* @return The view id
*/
protected String calculateConditionViewId(String conditionId)
{
return CONDITION_PAGES_LOCATION + conditionId + ".jsp";
}
}

View File

@@ -8,31 +8,14 @@ import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.action.evaluator.CompareMimeTypeEvaluator;
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
import org.alfresco.repo.action.evaluator.HasAspectEvaluator;
import org.alfresco.repo.action.evaluator.InCategoryEvaluator;
import org.alfresco.repo.action.evaluator.IsSubTypeEvaluator;
import org.alfresco.repo.action.executer.AddFeaturesActionExecuter;
import org.alfresco.repo.action.executer.CheckInActionExecuter;
import org.alfresco.repo.action.executer.CheckOutActionExecuter;
import org.alfresco.repo.action.executer.CopyActionExecuter;
import org.alfresco.repo.action.executer.ImageTransformActionExecuter;
import org.alfresco.repo.action.executer.ImporterActionExecuter;
import org.alfresco.repo.action.executer.LinkCategoryActionExecuter;
import org.alfresco.repo.action.executer.MailActionExecuter;
import org.alfresco.repo.action.executer.MoveActionExecuter;
import org.alfresco.repo.action.executer.RemoveFeaturesActionExecuter;
import org.alfresco.repo.action.executer.ScriptActionExecutor;
import org.alfresco.repo.action.executer.SimpleWorkflowActionExecuter;
import org.alfresco.repo.action.executer.SpecialiseTypeActionExecuter;
import org.alfresco.repo.action.executer.TransformActionExecuter;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.action.ActionConditionDefinition;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.alfresco.service.cmr.rule.Rule;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.bean.actions.IHandler;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.rules.handlers.BaseConditionHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -69,20 +52,39 @@ public class EditRuleWizard extends CreateRuleWizard
this.applyToSubSpaces = rule.isAppliedToChildren();
this.runInBackground = rule.getExecuteAsychronously();
FacesContext context = FacesContext.getCurrentInstance();
// populate the conditions list with maps of properties representing each condition
List<ActionCondition> conditions = rule.getActionConditions();
for (ActionCondition condition : conditions)
{
this.currentConditionProperties = new HashMap<String, Serializable>(3);
this.condition = condition.getActionConditionDefinitionName();
populateCondition(condition.getParameterValues());
// add the name, summary and not condition flag
this.currentConditionProperties.put(PROP_CONDITION_NAME, this.condition);
this.currentConditionProperties.put(PROP_CONDITION_NOT,
this.currentConditionProperties.put(BaseConditionHandler.PROP_CONDITION_NOT,
Boolean.valueOf(condition.getInvertCondition()));
this.currentConditionProperties.put(PROP_CONDITION_SUMMARY, buildConditionSummary());
IHandler handler = this.conditionHandlers.get(this.condition);
if (handler != null)
{
// use the handler to populate the properties and summary
handler.prepareForEdit(this.currentConditionProperties,
condition.getParameterValues());
this.currentConditionProperties.put(PROP_CONDITION_SUMMARY,
handler.generateSummary(context, this, this.currentConditionProperties));
}
else
{
// there's no handler, so we presume it is a no-paramter
// condition, use the condition title as the summary
ActionConditionDefinition conditionDef = this.actionService.
getActionConditionDefinition(this.condition);
this.currentConditionProperties.put(PROP_CONDITION_SUMMARY,
conditionDef.getTitle());
// add the no params marker so we can disable the edit action
this.currentConditionProperties.put(NO_PARAMS_MARKER, "no-params");
}
// add the populated currentConditionProperties to the list
this.allConditionsProperties.add(this.currentConditionProperties);
}
@@ -93,11 +95,25 @@ public class EditRuleWizard extends CreateRuleWizard
{
this.currentActionProperties = new HashMap<String, Serializable>(3);
this.action = action.getActionDefinitionName();
populateAction(action.getParameterValues());
// also add the name and summary
this.currentActionProperties.put(PROP_ACTION_NAME, this.action);
this.currentActionProperties.put(PROP_ACTION_SUMMARY, buildActionSummary());
IHandler handler = this.actionHandlers.get(this.action);
if (handler != null)
{
// use the handler to populate the properties and summary
handler.prepareForEdit(this.currentActionProperties, action.getParameterValues());
this.currentActionProperties.put(PROP_ACTION_SUMMARY,
handler.generateSummary(context, this, this.currentActionProperties));
}
else
{
// there's no handler, so we presume it is a no-paramter
// action, use the action title as the summary
ActionDefinition actionDef = this.actionService.getActionDefinition(this.action);
this.currentActionProperties.put(PROP_ACTION_SUMMARY, actionDef.getTitle());
// add the no params marker so we can disable the edit action
this.currentActionProperties.put(NO_PARAMS_MARKER, "no-params");
}
// add the populated currentActionProperties to the list
this.allActionsProperties.add(this.currentActionProperties);
@@ -151,183 +167,5 @@ public class EditRuleWizard extends CreateRuleWizard
// ------------------------------------------------------------------------------
// Helper methods
/**
* Populates a Map of properties the wizard is expecting for the given condition
*
* @param condition The condition to build the map for
*/
protected void populateCondition(Map<String, Serializable> conditionProps)
{
if (ComparePropertyValueEvaluator.NAME.equals(this.condition))
{
String propValue = (String)conditionProps.get(ComparePropertyValueEvaluator.PARAM_VALUE);
this.currentConditionProperties.put(PROP_CONTAINS_TEXT, propValue);
}
else if (InCategoryEvaluator.NAME.equals(this.condition))
{
NodeRef catNodeRef = (NodeRef)conditionProps.get(InCategoryEvaluator.PARAM_CATEGORY_VALUE);
this.currentConditionProperties.put(PROP_CATEGORY, catNodeRef);
}
else if (IsSubTypeEvaluator.NAME.equals(this.condition))
{
QName type = (QName)conditionProps.get(IsSubTypeEvaluator.PARAM_TYPE);
this.currentConditionProperties.put(PROP_MODEL_TYPE, type.toString());
}
else if (HasAspectEvaluator.NAME.equals(this.condition))
{
QName aspect = (QName)conditionProps.get(HasAspectEvaluator.PARAM_ASPECT);
this.currentConditionProperties.put(PROP_ASPECT, aspect.toString());
}
else if (CompareMimeTypeEvaluator.NAME.equals(this.condition))
{
String mimeType = (String)conditionProps.get(CompareMimeTypeEvaluator.PARAM_VALUE);
this.currentConditionProperties.put(PROP_MIMETYPE, mimeType);
}
}
/**
* Populate the actionProperties member variable with correct props for the current action
* using the supplied property map.
*
* @param actionProps Map to retrieve props appropriate to the current action from
*/
protected void populateAction(Map<String, Serializable> actionProps)
{
if (AddFeaturesActionExecuter.NAME.equals(this.action))
{
QName aspect = (QName)actionProps.get(AddFeaturesActionExecuter.PARAM_ASPECT_NAME);
this.currentActionProperties.put(PROP_ASPECT, aspect.toString());
}
else if (RemoveFeaturesActionExecuter.NAME.equals(this.action))
{
QName aspect = (QName)actionProps.get(RemoveFeaturesActionExecuter.PARAM_ASPECT_NAME);
this.currentActionProperties.put(PROP_ASPECT, aspect.toString());
}
else if (CopyActionExecuter.NAME.equals(this.action))
{
NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER);
this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
}
else if (MoveActionExecuter.NAME.equals(this.action))
{
NodeRef destNodeRef = (NodeRef)actionProps.get(MoveActionExecuter.PARAM_DESTINATION_FOLDER);
this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
}
else if (SimpleWorkflowActionExecuter.NAME.equals(this.action))
{
String approveStep = (String)actionProps.get(SimpleWorkflowActionExecuter.PARAM_APPROVE_STEP);
Boolean approveMove = (Boolean)actionProps.get(SimpleWorkflowActionExecuter.PARAM_APPROVE_MOVE);
NodeRef approveFolderNode = (NodeRef)actionProps.get(
SimpleWorkflowActionExecuter.PARAM_APPROVE_FOLDER);
String rejectStep = (String)actionProps.get(SimpleWorkflowActionExecuter.PARAM_REJECT_STEP);
Boolean rejectMove = (Boolean)actionProps.get(SimpleWorkflowActionExecuter.PARAM_REJECT_MOVE);
NodeRef rejectFolderNode = (NodeRef)actionProps.get(
SimpleWorkflowActionExecuter.PARAM_REJECT_FOLDER);
this.currentActionProperties.put(PROP_APPROVE_STEP_NAME, approveStep);
this.currentActionProperties.put(PROP_APPROVE_ACTION, approveMove ? "move" : "copy");
this.currentActionProperties.put(PROP_APPROVE_FOLDER, approveFolderNode);
if (rejectStep == null && rejectMove == null && rejectFolderNode == null)
{
this.currentActionProperties.put(PROP_REJECT_STEP_PRESENT, "no");
}
else
{
this.currentActionProperties.put(PROP_REJECT_STEP_PRESENT, "yes");
this.currentActionProperties.put(PROP_REJECT_STEP_NAME, rejectStep);
this.currentActionProperties.put(PROP_REJECT_ACTION, rejectMove ? "move" : "copy");
this.currentActionProperties.put(PROP_REJECT_FOLDER, rejectFolderNode);
}
}
else if (LinkCategoryActionExecuter.NAME.equals(this.action))
{
NodeRef catNodeRef = (NodeRef)actionProps.get(LinkCategoryActionExecuter.PARAM_CATEGORY_VALUE);
this.currentActionProperties.put(PROP_CATEGORY, catNodeRef);
}
else if (CheckOutActionExecuter.NAME.equals(this.action))
{
NodeRef destNodeRef = (NodeRef)actionProps.get(CheckOutActionExecuter.PARAM_DESTINATION_FOLDER);
this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
}
else if (CheckInActionExecuter.NAME.equals(this.action))
{
String checkDesc = (String)actionProps.get(CheckInActionExecuter.PARAM_DESCRIPTION);
this.currentActionProperties.put(PROP_CHECKIN_DESC, checkDesc);
Boolean minorChange = (Boolean)actionProps.get(CheckInActionExecuter.PARAM_MINOR_CHANGE);
this.currentActionProperties.put(PROP_CHECKIN_MINOR, minorChange);
}
else if (TransformActionExecuter.NAME.equals(this.action))
{
String transformer = (String)actionProps.get(TransformActionExecuter.PARAM_MIME_TYPE);
this.currentActionProperties.put(PROP_TRANSFORMER, transformer);
NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER);
this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
}
else if (ImageTransformActionExecuter.NAME.equals(this.action))
{
String transformer = (String)actionProps.get(TransformActionExecuter.PARAM_MIME_TYPE);
this.currentActionProperties.put(PROP_IMAGE_TRANSFORMER, transformer);
String options = (String)actionProps.get(ImageTransformActionExecuter.PARAM_CONVERT_COMMAND);
this.currentActionProperties.put(PROP_TRANSFORM_OPTIONS, options != null ? options : "");
NodeRef destNodeRef = (NodeRef)actionProps.get(CopyActionExecuter.PARAM_DESTINATION_FOLDER);
this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
}
else if (MailActionExecuter.NAME.equals(this.action))
{
String subject = (String)actionProps.get(MailActionExecuter.PARAM_SUBJECT);
this.currentActionProperties.put(PROP_SUBJECT, subject);
String message = (String)actionProps.get(MailActionExecuter.PARAM_TEXT);
this.currentActionProperties.put(PROP_MESSAGE, message);
// handle single email or multiple authority recipients
String to = (String)actionProps.get(MailActionExecuter.PARAM_TO);
if (to != null)
{
this.currentActionProperties.put(PROP_TO, to);
}
else
{
List<String> recipients = (List<String>)actionProps.get(MailActionExecuter.PARAM_TO_MANY);
if (recipients != null && recipients.size() != 0)
{
// rebuild the list of RecipientWrapper objects from the stored action
for (String authority : recipients)
{
this.emailRecipients.add(
new RecipientWrapper(displayLabelForAuthority(authority), authority));
}
}
}
NodeRef templateRef = (NodeRef)actionProps.get(MailActionExecuter.PARAM_TEMPLATE);
if (templateRef != null)
{
this.currentActionProperties.put(PROP_TEMPLATE, templateRef.getId());
this.usingTemplate = templateRef.getId();
}
}
else if (ImporterActionExecuter.NAME.equals(this.action))
{
NodeRef destNodeRef = (NodeRef)actionProps.get(ImporterActionExecuter.PARAM_DESTINATION_FOLDER);
this.currentActionProperties.put(PROP_DESTINATION, destNodeRef);
}
else if (SpecialiseTypeActionExecuter.NAME.equals(this.action))
{
QName specialiseType = (QName)actionProps.get(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME);
this.currentActionProperties.put(PROP_OBJECT_TYPE, specialiseType.toString());
}
else if (ScriptActionExecutor.NAME.equals(this.action))
{
NodeRef scriptRef = (NodeRef)actionProps.get(ScriptActionExecutor.PARAM_SCRIPTREF);
this.currentActionProperties.put(PROP_SCRIPT, scriptRef.getId());
}
}
}

View File

@@ -0,0 +1,34 @@
package org.alfresco.web.bean.rules.handlers;
import java.io.Serializable;
import java.util.Map;
import org.alfresco.web.bean.actions.IHandler;
/**
* Base class for all condition handler implementations.
*
* @author gavinc
*/
public abstract class BaseConditionHandler implements IHandler
{
protected static final String CONDITION_PAGES_LOCATION = "/jsp/rules/";
public static final String PROP_CONDITION_NOT = "notcondition";
public void setupUIDefaults(Map<String, Serializable> conditionProps)
{
// do nothing by default, only those condition handlers that need
// to setup defaults need override this method
}
/**
* Given the condition name, generates the default path for the JSP
*
* @param conditionName The name of the condition
* @return The path to the JSP used for the condition
*/
protected String getJSPPath(String conditionName)
{
return CONDITION_PAGES_LOCATION + conditionName + ".jsp";
}
}

View File

@@ -0,0 +1,63 @@
package org.alfresco.web.bean.rules.handlers;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import org.alfresco.repo.action.evaluator.CompareMimeTypeEvaluator;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.rules.CreateRuleWizard;
import org.alfresco.web.bean.wizard.IWizardBean;
/**
* Condition handler for the "compare-mime-type" condition
*
* @author gavinc
*/
public class CompareMimeTypeHandler extends BaseConditionHandler
{
protected static final String PROP_MIMETYPE = "mimetype";
public String getJSPPath()
{
return getJSPPath(CompareMimeTypeEvaluator.NAME);
}
public void prepareForSave(Map<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
String mimeType = (String)conditionProps.get(PROP_MIMETYPE);
repoProps.put(CompareMimeTypeEvaluator.PARAM_VALUE, mimeType);
}
public void prepareForEdit(Map<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
String mimeType = (String)repoProps.get(CompareMimeTypeEvaluator.PARAM_VALUE);
conditionProps.put(PROP_MIMETYPE, mimeType);
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> conditionProps)
{
Boolean not = (Boolean)conditionProps.get(PROP_CONDITION_NOT);
String msgId = not.booleanValue() ? "condition_compare_mime_type_not" : "condition_compare_mime_type";
String label = null;
String mimetype = (String)conditionProps.get(PROP_MIMETYPE);
for (SelectItem item : ((CreateRuleWizard)wizard).getMimeTypes())
{
if (item.getValue().equals(mimetype))
{
label = item.getLabel();
break;
}
}
return MessageFormat.format(Application.getMessage(context, msgId),
new Object[] {label});
}
}

View File

@@ -0,0 +1,64 @@
package org.alfresco.web.bean.rules.handlers;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import org.alfresco.repo.action.evaluator.HasAspectEvaluator;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.rules.CreateRuleWizard;
import org.alfresco.web.bean.wizard.IWizardBean;
/**
* Condition handler for the "has-aspect" condition.
*
* @author gavinc
*/
public class HasAspectHandler extends BaseConditionHandler
{
protected static final String PROP_ASPECT = "aspect";
public String getJSPPath()
{
return getJSPPath(HasAspectEvaluator.NAME);
}
public void prepareForSave(Map<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
QName aspect = QName.createQName((String)conditionProps.get(PROP_ASPECT));
repoProps.put(HasAspectEvaluator.PARAM_ASPECT, aspect);
}
public void prepareForEdit(Map<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
QName aspect = (QName)repoProps.get(HasAspectEvaluator.PARAM_ASPECT);
conditionProps.put(PROP_ASPECT, aspect.toString());
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> conditionProps)
{
Boolean not = (Boolean)conditionProps.get(PROP_CONDITION_NOT);
String msgId = not.booleanValue() ? "condition_has_aspect_not" : "condition_has_aspect";
String label = null;
String aspectName = (String)conditionProps.get(PROP_ASPECT);
for (SelectItem item : ((CreateRuleWizard)wizard).getAspects())
{
if (item.getValue().equals(aspectName))
{
label = item.getLabel();
break;
}
}
return MessageFormat.format(Application.getMessage(context, msgId),
new Object[] {label});
}
}

View File

@@ -0,0 +1,61 @@
package org.alfresco.web.bean.rules.handlers;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.evaluator.InCategoryEvaluator;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.wizard.IWizardBean;
/**
* Condition handler for the "in-category" condition.
*
* @author gavinc
*/
public class InCategoryHandler extends BaseConditionHandler
{
protected static final String PROP_CATEGORY = "category";
public String getJSPPath()
{
return getJSPPath(InCategoryEvaluator.NAME);
}
public void prepareForSave(Map<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
// put the selected category in the condition params
NodeRef nodeRef = (NodeRef)conditionProps.get(PROP_CATEGORY);
repoProps.put(InCategoryEvaluator.PARAM_CATEGORY_VALUE, nodeRef);
// add the classifiable aspect
repoProps.put(InCategoryEvaluator.PARAM_CATEGORY_ASPECT,
ContentModel.ASPECT_GEN_CLASSIFIABLE);
}
public void prepareForEdit(Map<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
NodeRef catNodeRef = (NodeRef)repoProps.get(InCategoryEvaluator.PARAM_CATEGORY_VALUE);
conditionProps.put(PROP_CATEGORY, catNodeRef);
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> conditionProps)
{
Boolean not = (Boolean)conditionProps.get(PROP_CONDITION_NOT);
String msgId = not.booleanValue() ? "condition_in_category_not" : "condition_in_category";
String name = Repository.getNameForNode(Repository.getServiceRegistry(context).
getNodeService(), (NodeRef)conditionProps.get(PROP_CATEGORY));
return MessageFormat.format(Application.getMessage(context, msgId),
new Object[] {name});
}
}

View File

@@ -0,0 +1,64 @@
package org.alfresco.web.bean.rules.handlers;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import org.alfresco.repo.action.evaluator.IsSubTypeEvaluator;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.rules.CreateRuleWizard;
import org.alfresco.web.bean.wizard.IWizardBean;
/**
* Condition handler to the "is-subtype" condition.
*
* @author gavinc
*/
public class IsSubTypeHandler extends BaseConditionHandler
{
protected static final String PROP_MODEL_TYPE = "modeltype";
public String getJSPPath()
{
return getJSPPath(IsSubTypeEvaluator.NAME);
}
public void prepareForSave(Map<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
QName type = QName.createQName((String)conditionProps.get(PROP_MODEL_TYPE));
repoProps.put(IsSubTypeEvaluator.PARAM_TYPE, type);
}
public void prepareForEdit(Map<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
QName type = (QName)repoProps.get(IsSubTypeEvaluator.PARAM_TYPE);
conditionProps.put(PROP_MODEL_TYPE, type.toString());
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> conditionProps)
{
Boolean not = (Boolean)conditionProps.get(PROP_CONDITION_NOT);
String msgId = not.booleanValue() ? "condition_is_subtype_not" : "condition_is_subtype";
String label = null;
String typeName = (String)conditionProps.get(PROP_MODEL_TYPE);
for (SelectItem item : ((CreateRuleWizard)wizard).getModelTypes())
{
if (item.getValue().equals(typeName))
{
label = item.getLabel();
break;
}
}
return MessageFormat.format(Application.getMessage(context, msgId),
new Object[] {label});
}
}

View File

@@ -0,0 +1,53 @@
package org.alfresco.web.bean.rules.handlers;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.wizard.IWizardBean;
/**
* Condition handler for the "compare-property-value" condition.
*
* @author gavinc
*/
public class PropertyValueHandler extends BaseConditionHandler
{
public static final String PROP_CONTAINS_TEXT = "containstext";
public String getJSPPath()
{
return getJSPPath(ComparePropertyValueEvaluator.NAME);
}
public void prepareForSave(Map<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
String text = (String)conditionProps.get(PROP_CONTAINS_TEXT);
repoProps.put(ComparePropertyValueEvaluator.PARAM_VALUE, text);
}
public void prepareForEdit(Map<String, Serializable> conditionProps,
Map<String, Serializable> repoProps)
{
String propValue = (String)repoProps.get(ComparePropertyValueEvaluator.PARAM_VALUE);
conditionProps.put(PROP_CONTAINS_TEXT, propValue);
}
public String generateSummary(FacesContext context, IWizardBean wizard,
Map<String, Serializable> conditionProps)
{
Boolean not = (Boolean)conditionProps.get(PROP_CONDITION_NOT);
String msgId = not.booleanValue() ?
"condition_compare_property_value_not" : "condition_compare_property_value";
String text = (String)conditionProps.get(PROP_CONTAINS_TEXT);
return MessageFormat.format(Application.getMessage(context, msgId),
new Object[] {text});
}
}