Search in sources :

Example 6 with IHandler

use of org.alfresco.web.bean.actions.IHandler in project acs-community-packaging by Alfresco.

the class CreateRuleWizard method addCondition.

/**
 * Adds the condition just setup by the user to the list of conditions for the rule
 */
public void addCondition() {
    FacesContext context = FacesContext.getCurrentInstance();
    if (logger.isDebugEnabled())
        logger.debug("Adding Condition '" + selectedCondition + "'");
    IHandler handler = this.conditionHandlers.get(this.selectedCondition);
    // 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 = handler.generateSummary(context, this, this.currentConditionProperties);
    if (summary != null) {
        this.currentConditionProperties.put(PROP_CONDITION_SUMMARY, summary);
    }
    if (logger.isDebugEnabled())
        logger.debug("Generated Summary - [" + summary + "] + selectedCondition " + this.selectedCondition);
    if (this.editingCondition == false) {
        this.allConditionsPropertiesList.add(this.currentConditionProperties);
    }
    // reset the action drop down
    this.selectedCondition = null;
    // refresh the wizard
    goToPage(context, this.returnViewId);
}
Also used : FacesContext(javax.faces.context.FacesContext) IHandler(org.alfresco.web.bean.actions.IHandler)

Example 7 with IHandler

use of org.alfresco.web.bean.actions.IHandler 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 8 with IHandler

use of org.alfresco.web.bean.actions.IHandler in project acs-community-packaging by Alfresco.

the class EditRuleWizard method populateProperties.

protected void populateProperties(FacesContext context, ActionCondition condition, Map<String, Serializable> uiConditionProperties) {
    uiConditionProperties.put(PROP_CONDITION_NAME, this.selectedCondition);
    uiConditionProperties.put(BaseConditionHandler.PROP_CONDITION_NOT, Boolean.valueOf(condition.getInvertCondition()));
    IHandler handler = this.conditionHandlers.get(this.selectedCondition);
    if (handler != null) {
        // use the handler to populate the properties and summary
        handler.prepareForEdit(uiConditionProperties, condition.getParameterValues());
        uiConditionProperties.put(PROP_CONDITION_SUMMARY, handler.generateSummary(context, this, uiConditionProperties));
    } else {
        // there's no handler, so we presume it is a no-parameter
        // condition, use the condition title as the summary
        ActionConditionDefinition conditionDef = this.getActionService().getActionConditionDefinition(this.selectedCondition);
        uiConditionProperties.put(PROP_CONDITION_SUMMARY, conditionDef.getTitle());
        // add the no params marker so we can disable the edit action
        uiConditionProperties.put(NO_PARAMS_MARKER, "no-params");
    }
}
Also used : IHandler(org.alfresco.web.bean.actions.IHandler) ActionConditionDefinition(org.alfresco.service.cmr.action.ActionConditionDefinition)

Example 9 with IHandler

use of org.alfresco.web.bean.actions.IHandler 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 10 with IHandler

use of org.alfresco.web.bean.actions.IHandler in project acs-community-packaging by Alfresco.

the class CreateRuleWizard method createCondition.

private ActionCondition createCondition(Map<String, Serializable> uiConditionParams) {
    // get the condition handler to prepare for the save
    String conditionName = (String) uiConditionParams.get(PROP_CONDITION_NAME);
    Map<String, Serializable> repoCondParams = new HashMap<String, Serializable>();
    if (logger.isDebugEnabled()) {
        logger.debug("\tSaving " + conditionName);
    }
    IHandler handler = this.conditionHandlers.get(conditionName);
    if (handler != null) {
        handler.prepareForSave(uiConditionParams, repoCondParams);
    }
    // add the condition to the rule
    ActionCondition condition = this.getActionService().createActionCondition(conditionName);
    condition.setParameterValues(repoCondParams);
    // specify whether the condition result should be inverted
    Boolean not = (Boolean) uiConditionParams.get(BaseConditionHandler.PROP_CONDITION_NOT);
    if (not == null) {
        logger.warn("Property missing NOT parameter value (currently null)");
        not = Boolean.TRUE;
    }
    condition.setInvertCondition(((Boolean) not).booleanValue());
    return condition;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) IHandler(org.alfresco.web.bean.actions.IHandler) CompositeActionCondition(org.alfresco.service.cmr.action.CompositeActionCondition) ActionCondition(org.alfresco.service.cmr.action.ActionCondition)

Aggregations

IHandler (org.alfresco.web.bean.actions.IHandler)10 Serializable (java.io.Serializable)5 FacesContext (javax.faces.context.FacesContext)5 HashMap (java.util.HashMap)2 Action (org.alfresco.service.cmr.action.Action)2 ActionCondition (org.alfresco.service.cmr.action.ActionCondition)2 ActionConditionDefinition (org.alfresco.service.cmr.action.ActionConditionDefinition)2 CompositeAction (org.alfresco.service.cmr.action.CompositeAction)2 CompositeActionCondition (org.alfresco.service.cmr.action.CompositeActionCondition)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 ActionDefinition (org.alfresco.service.cmr.action.ActionDefinition)1 Config (org.springframework.extensions.config.Config)1 ConfigElement (org.springframework.extensions.config.ConfigElement)1 ConfigService (org.springframework.extensions.config.ConfigService)1