use of org.alfresco.service.cmr.action.CompositeAction in project acs-community-packaging by Alfresco.
the class CreateRuleWizard method setupRule.
// ------------------------------------------------------------------------------
// Helper methods
/**
* Sets up the given rule using the current state of the wizard
*
* @param context FacesContext
* @param rule The rule to setup
* @param outcome The default outcome
* @return The outcome
*/
@SuppressWarnings("unchecked")
protected String setupRule(FacesContext context, Rule rule, String outcome) {
if (logger.isDebugEnabled())
logger.debug("Saving Rules - setupRule");
// setup the rule and add it to the space
rule.setTitle(this.title);
rule.setDescription(this.description);
rule.applyToChildren(this.applyToSubSpaces);
rule.setExecuteAsynchronously(this.runInBackground);
rule.setRuleDisabled(this.ruleDisabled);
CompositeAction compositeAction = this.getActionService().createCompositeAction();
rule.setAction(compositeAction);
int i = 1;
// add all the conditions to the rule
for (Object condParamsObj : this.allConditionsPropertiesList) {
if (logger.isDebugEnabled())
logger.debug("Saving Condition " + i++ + " of " + this.allConditionsPropertiesList.size());
Map<String, Serializable> uiConditionParams = (Map<String, Serializable>) condParamsObj;
ActionCondition condition = createCondition(uiConditionParams);
if (condition instanceof CompositeActionCondition) {
CompositeActionCondition compositeCondition = (CompositeActionCondition) condition;
List<Map<String, Serializable>> subconditionProps = (List<Map<String, Serializable>>) uiConditionParams.get(CompositeConditionHandler.PROP_COMPOSITE_CONDITION);
int j = 1;
compositeCondition.setORCondition(((Boolean) uiConditionParams.get(CompositeConditionHandler.PROP_CONDITION_OR)).booleanValue());
compositeCondition.setInvertCondition((((Boolean) uiConditionParams.get(CompositeConditionHandler.PROP_CONDITION_NOT)).booleanValue()));
for (Map<String, Serializable> props : subconditionProps) {
if (logger.isDebugEnabled())
logger.debug("Saving Composite Condition " + j++ + " of " + subconditionProps.size());
compositeCondition.addActionCondition(createCondition(props));
}
}
compositeAction.addActionCondition(condition);
}
// add all the actions to the rule
for (Map<String, Serializable> actionParams : this.allActionsProperties) {
// use the base class version of buildActionParams(), but for this
// we need
// to setup the currentActionProperties and action variables
String actionName = (String) actionParams.get(PROP_ACTION_NAME);
this.action = actionName;
// 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.getActionService().createAction(actionName);
action.setParameterValues(repoActionParams);
compositeAction.addAction(action);
}
return outcome;
}
use of org.alfresco.service.cmr.action.CompositeAction in project acs-community-packaging by Alfresco.
the class EditRuleWizard method init.
// ------------------------------------------------------------------------------
// Wizard implementation
/* Loads up conditions and actions from the repository
*/
@Override
public void init(Map<String, String> parameters) {
super.init(parameters);
// get hold of the current rule details
Rule rule = this.rulesDialog.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();
this.ruleDisabled = rule.getRuleDisabled();
FacesContext context = FacesContext.getCurrentInstance();
// Get the composite action
CompositeAction compositeAction = getCompositeAction(rule);
populateConditions(context, compositeAction);
populateActions(context, compositeAction);
// reset the current condition
this.selectedCondition = null;
// reset the current action
this.action = null;
}
use of org.alfresco.service.cmr.action.CompositeAction in project acs-community-packaging by Alfresco.
the class EditRuleWizard method populateActions.
protected void populateActions(FacesContext context, CompositeAction compositeAction) {
// 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.currentEmailRecipientsDataModel = null;
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-parameter
// action, use the action title as the summary
ActionDefinition actionDef = this.getActionService().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);
}
}
use of org.alfresco.service.cmr.action.CompositeAction in project acs-community-packaging by Alfresco.
the class EditRuleWizard method finishImpl.
@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.rulesDialog.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.getRuleService().saveRule(currentSpace.getNodeRef(), rule);
if (logger.isDebugEnabled())
logger.debug("Updated rule '" + this.title + "'");
return outcome;
}
Aggregations