2017-05-10 14 views
0

일부 처리를 위해 사용자 정의 함수에서 규칙 이름을 가져야한다는 요구 사항이 있습니다. 아래 코드는 내가 수행하려는 방법입니다. 이것이 직접 가능하지 않은 경우 대안이 있습니까? BTW 현재 우리가 사용 Drools가 5.6Drools 언제 또는 조건에서 ruleContext를 얻는가?

import org.drools.spi.KnowledgeHelper;  
      function boolean printRuleName(KnowledgeHelper context) { 
       System.out.println(context.getRule().getName()); 
       return true; 
      } 

      // rule values at C15, header at C10 

      rule "MY_RULE_15" 
       salience 65521 
       when 

        k:StatefulKnowledgeSession(true == "true") 
        //context: KnowledgeHelper(true=="true") 
        m:Map(true == "true") 
        Map((printRuleName(kcontext) == "true") 

       then 
        System.out.println(kcontext.getRule().getName()); 
    //this works in action 
     end 
     //Map((printRuleName(kcontext) == "true") this is causing null pointer exception, kcontext is not getting injected 

답변

0

는 상태 평가시 룰의 좌측에는 규칙 콘텍스트, 즉 없다.

왼쪽에 규칙 이름이 필요하면 (어쨌든 유용하지는 않을 것입니다.) 규칙 이름이 들어있는 문자열 리터럴을 매개 변수로 작성해야합니다.

이 요구 사항이 적용되는 이유를 검토하는 것이 좋습니다.

부울과 문자열을 비교할 때 printRuleName(kcontext) == "true"이 절대로 안됩니다. 또한 true == "true"을 비교하는 것은 의미가 없습니다.

+0

응답 해 주셔서 감사합니다. 규칙의 이름을 매개 변수로 포함하는 문자열 리터럴을 작성해야 할 것입니다. 우리가 어떻게 할 수 있는지. – Praneeth

+0

다음과 같은 메소드 호출 :'x ("y")' – laune