Search in sources :

Example 1 with CompositeAction

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;
}
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 CompositeAction

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;
}
Also used : FacesContext(javax.faces.context.FacesContext) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) CompositeAction(org.alfresco.service.cmr.action.CompositeAction) Rule(org.alfresco.service.cmr.rule.Rule)

Example 3 with CompositeAction

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);
    }
}
Also used : Action(org.alfresco.service.cmr.action.Action) CompositeAction(org.alfresco.service.cmr.action.CompositeAction) Serializable(java.io.Serializable) IHandler(org.alfresco.web.bean.actions.IHandler) ActionDefinition(org.alfresco.service.cmr.action.ActionDefinition)

Example 4 with CompositeAction

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;
}
Also used : Node(org.alfresco.web.bean.repository.Node) CompositeAction(org.alfresco.service.cmr.action.CompositeAction) Rule(org.alfresco.service.cmr.rule.Rule)

Aggregations

CompositeAction (org.alfresco.service.cmr.action.CompositeAction)4 Serializable (java.io.Serializable)2 Action (org.alfresco.service.cmr.action.Action)2 Rule (org.alfresco.service.cmr.rule.Rule)2 IHandler (org.alfresco.web.bean.actions.IHandler)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 FacesContext (javax.faces.context.FacesContext)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 ActionCondition (org.alfresco.service.cmr.action.ActionCondition)1 ActionDefinition (org.alfresco.service.cmr.action.ActionDefinition)1 CompositeActionCondition (org.alfresco.service.cmr.action.CompositeActionCondition)1 Node (org.alfresco.web.bean.repository.Node)1