Search in sources :

Example 1 with CompositeActionCondition

use of org.alfresco.service.cmr.action.CompositeActionCondition 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;
}
Also used : Serializable(java.io.Serializable) Action(org.alfresco.service.cmr.action.Action) CompositeAction(org.alfresco.service.cmr.action.CompositeAction) HashMap(java.util.HashMap) CompositeActionCondition(org.alfresco.service.cmr.action.CompositeActionCondition) ActionCondition(org.alfresco.service.cmr.action.ActionCondition) IHandler(org.alfresco.web.bean.actions.IHandler) CompositeAction(org.alfresco.service.cmr.action.CompositeAction) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) CompositeActionCondition(org.alfresco.service.cmr.action.CompositeActionCondition)

Example 2 with CompositeActionCondition

use of org.alfresco.service.cmr.action.CompositeActionCondition in project acs-community-packaging by Alfresco.

the class EditRuleWizard method populateConditions.

protected void populateConditions(FacesContext context, CompositeAction compositeAction) {
    // populate the conditions list with maps of properties representing each condition
    List<ActionCondition> conditions = compositeAction.getActionConditions();
    for (ActionCondition toplevel_condition : conditions) {
        this.selectedCondition = toplevel_condition.getActionConditionDefinitionName();
        this.currentConditionProperties = new HashMap<String, Serializable>();
        if (logger.isDebugEnabled())
            logger.debug("Preparing for Edit Condition " + this.selectedCondition);
        if (toplevel_condition instanceof CompositeActionCondition) {
            if (logger.isDebugEnabled())
                logger.debug("\tDetected CompositeCondition");
            CompositeActionCondition compositeCondition = (CompositeActionCondition) toplevel_condition;
            this.currentCompositeConditionPropertiesList = new ArrayList<Map<String, Serializable>>();
            for (ActionCondition subcondition : compositeCondition.getActionConditions()) {
                if (logger.isDebugEnabled())
                    logger.debug("\tSetting ... SubConditions " + subcondition.getActionConditionDefinitionName());
                this.selectedCondition = subcondition.getActionConditionDefinitionName();
                Map<String, Serializable> subConditionProperties = new HashMap<String, Serializable>();
                populateProperties(context, subcondition, subConditionProperties);
                this.currentCompositeConditionPropertiesList.add(subConditionProperties);
            }
            this.selectedCondition = CompositeConditionHandler.NAME;
            this.currentConditionProperties.put(CompositeConditionHandler.PROP_COMPOSITE_CONDITION, (Serializable) this.currentCompositeConditionPropertiesList);
            populateProperties(context, compositeCondition, currentConditionProperties);
        } else
            populateProperties(context, toplevel_condition, this.currentConditionProperties);
        // add the populated currentConditionProperties to the list
        this.allConditionsPropertiesList.add(this.currentConditionProperties);
        printConditionState();
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) CompositeActionCondition(org.alfresco.service.cmr.action.CompositeActionCondition) CompositeActionCondition(org.alfresco.service.cmr.action.CompositeActionCondition) ActionCondition(org.alfresco.service.cmr.action.ActionCondition)

Aggregations

Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ActionCondition (org.alfresco.service.cmr.action.ActionCondition)2 CompositeActionCondition (org.alfresco.service.cmr.action.CompositeActionCondition)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Action (org.alfresco.service.cmr.action.Action)1 CompositeAction (org.alfresco.service.cmr.action.CompositeAction)1 IHandler (org.alfresco.web.bean.actions.IHandler)1