mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
- Updated web services, SDK and web client where appropraite - Patch added to migrate existing rules - Entire rule service can now be disabled programmatically - Rule service is now disabled during the patching process - StoreEnum and languageEnum types removed from web service interfaces - Multiple rule types now supported in the repo (but not in the UI) - Removed owning node ref from action and rule .. now calculated from methods on the rule service git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3464 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
179 lines
6.9 KiB
Java
179 lines
6.9 KiB
Java
package org.alfresco.web.bean.rules;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import javax.faces.context.FacesContext;
|
|
|
|
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.action.ActionDefinition;
|
|
import org.alfresco.service.cmr.action.CompositeAction;
|
|
import org.alfresco.service.cmr.rule.Rule;
|
|
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;
|
|
|
|
|
|
/**
|
|
* Bean implementation for the "Edit Rule" wizard
|
|
*
|
|
* @author gavinc
|
|
*/
|
|
public class EditRuleWizard extends CreateRuleWizard
|
|
{
|
|
private static final Log logger = LogFactory.getLog(EditRuleWizard.class);
|
|
|
|
// ------------------------------------------------------------------------------
|
|
// Wizard implementation
|
|
|
|
@Override
|
|
public void init(Map<String, String> parameters)
|
|
{
|
|
super.init(parameters);
|
|
|
|
// get hold of the current rule details
|
|
Rule rule = this.rulesBean.getCurrentRule();
|
|
|
|
if (rule == null)
|
|
{
|
|
throw new AlfrescoRuntimeException("Failed to locate the current rule");
|
|
}
|
|
|
|
// populate the bean with current values
|
|
this.type = rule.getRuleTypes().get(0);
|
|
this.title = rule.getTitle();
|
|
this.description = rule.getDescription();
|
|
this.applyToSubSpaces = rule.isAppliedToChildren();
|
|
this.runInBackground = rule.getExecuteAsynchronously();
|
|
|
|
FacesContext context = FacesContext.getCurrentInstance();
|
|
|
|
// Get the composite action
|
|
CompositeAction compositeAction = getCompositeAction(rule);
|
|
|
|
// populate the conditions list with maps of properties representing each condition
|
|
List<ActionCondition> conditions = compositeAction.getActionConditions();
|
|
for (ActionCondition condition : conditions)
|
|
{
|
|
this.currentConditionProperties = new HashMap<String, Serializable>(3);
|
|
this.condition = condition.getActionConditionDefinitionName();
|
|
this.currentConditionProperties.put(PROP_CONDITION_NAME, this.condition);
|
|
this.currentConditionProperties.put(BaseConditionHandler.PROP_CONDITION_NOT,
|
|
Boolean.valueOf(condition.getInvertCondition()));
|
|
|
|
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);
|
|
}
|
|
|
|
// populate the actions list with maps of properties representing each action
|
|
List<Action> actions = compositeAction.getActions();
|
|
for (Action action : actions)
|
|
{
|
|
this.currentActionProperties = new HashMap<String, Serializable>(3);
|
|
this.action = action.getActionDefinitionName();
|
|
this.currentActionProperties.put(PROP_ACTION_NAME, this.action);
|
|
|
|
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);
|
|
}
|
|
|
|
// reset the current condition
|
|
this.condition = null;
|
|
|
|
// reset the current action
|
|
this.action = null;
|
|
}
|
|
|
|
@Override
|
|
protected String finishImpl(FacesContext context, String outcome) throws Exception
|
|
{
|
|
// get hold of the space the rule will apply to and make sure
|
|
// it is actionable
|
|
Node currentSpace = browseBean.getActionSpace();
|
|
|
|
// get the existing rule
|
|
Rule rule = this.rulesBean.getCurrentRule();
|
|
|
|
// Get the composite action
|
|
CompositeAction compositeAction = getCompositeAction(rule);
|
|
|
|
// remove all the conditions and actions from the current rule
|
|
compositeAction.removeAllActionConditions();
|
|
compositeAction.removeAllActions();
|
|
|
|
// re-setup the rule
|
|
outcome = setupRule(context, rule, outcome);
|
|
|
|
// Save the rule
|
|
this.ruleService.saveRule(currentSpace.getNodeRef(), rule);
|
|
|
|
if (logger.isDebugEnabled())
|
|
logger.debug("Updated rule '" + this.title + "'");
|
|
|
|
return outcome;
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
// Bean Getters and Setters
|
|
|
|
/**
|
|
* Determines whether the rule type drop down list should be enabled.
|
|
*
|
|
* @return true as the rule type drop down should be disabled
|
|
*/
|
|
public boolean getRuleTypeDisabled()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------
|
|
// Helper methods
|
|
|
|
}
|