AnsweredAssumed Answered

Rules (Actions and ActionConditions)

Question asked by tim on Sep 6, 2007
Can anyone tell me why the following code isn't working i.e. the assert is failing.

I'm trying to set the name property of a node when it is added to a folder with the rule defined on it. The actual value is null when I was expecting it to be "test_value".

It seems to me like the rule never gets triggered (because I know the action works by itself).

      NodeRef section1 = nodeService.createNode(
            issue1,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(CommonsContentModel.CMS_NAMESPACE_URI, "section1"),
            ContentModel.TYPE_FOLDER).getChildRef();
      
      // create a rule on the section1
        
        action = actionService.createAction(SetPropertyValueActionExecuter.NAME);     // set-property-value
        action.setParameterValue(SetPropertyValueActionExecuter.PARAM_PROPERTY, CommonsContentModel.PROP_CMS_NAME);  // property, cms:name
        action.setParameterValue(SetPropertyValueActionExecuter.PARAM_VALUE, TEST_VALUE);  // value, test_value
       
        actionCondition = actionService.createActionCondition(NoConditionEvaluator.NAME);  // no-condition
       
        action.addActionCondition(actionCondition);
       
       Rule rule = new Rule();
       rule.setAction(action);
       rule.setRuleType(RuleTypeImpl.INBOUND);
       rule.applyToChildren(true);
       rule.setDescription("description");
       rule.setTitle("title");
      
        ruleService.saveRule(section1, rule);
    
      // trigger the rule
      
      NodeRef call1 = nodeService.createNode(
            section1,
            ContentModel.ASSOC_CONTAINS,
            QName.createQName(
                  CommonsContentModel.FUNDING_NAMESPACE_URI, "Call1"),
            CommonsContentModel.TYPE_FUNDING_CALL).getChildRef();

      // test the action was executed
      
      assertEquals(TEST_VALUE, nodeService.getProperty(call1, CommonsContentModel.PROP_CMS_NAME));

Outcomes