cancel
Showing results for 
Search instead for 
Did you mean: 

How to create rule for aspect programmatically

gox
Champ in-the-making
Champ in-the-making
Any idea how action rule for an aspect can be added (created) programmatically?

Thanks in advance,
Goran
1 REPLY 1

rwetherall
Confirmed Champ
Confirmed Champ
Hi,

This snipit might help to give somewhere to start …


  
        Map<String, Serializable> params = new HashMap<String, Serializable>(1);
        params.put("aspect-name", ContentModel.ASPECT_VERSIONABLE);       
       
        Rule rule = createRule(
              RuleType.INBOUND,
              AddFeaturesActionExecuter.NAME,
              params,
              NoConditionEvaluator.NAME,
              null);

       ruleService.saveRule(nodeRef, rule);

       ……

       private Rule createRule(
         String ruleTypeName,
         String actionName,
         Map<String, Serializable> actionParams,
         String conditionName,
         Map<String, Serializable> conditionParams)
   {
            Rule rule = new Rule();
            rule.setRuleType(ruleTypeName);       
       
            Action action = this.actionService.createAction(actionName, actionParams);       
            ActionCondition condition = this.actionService.createActionCondition(conditionName, conditionParams);
            action.addActionCondition(condition);
            rule.setAction(action); 
       
            return rule;
   }


Cheers,
Roy