정적 메소드 개발

CER은 사용자에게 필요한 계산을 제공할 가능성이 큰 다양한 표현식을 지원합니다.

CER 표현식을 사용하여 구현할 수 없는 비즈니스 계산이 있는 경우 CER은 규칙 세트에서 사용자 정의 Java 클래스의 정적 메소드를 호출할 수 있도록 call 표현식을 지원합니다. CER 편집기는 사용자 정의 Java 클래스에 정적 메소드를 정의할 수 있는 몇 가지 규칙 요소(예: "호출")를 제공합니다. 호출에서 "호출" 규칙 요소를 참조하십시오.

다음은 Java 메소드를 호출하는 예제 규칙 세트입니다.

<?xml version="1.0" encoding="UTF-8"?>
<RuleSet name="Example_StaticMethodDevelopment"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation=
"http://www.curamsoftware.com/CreoleRulesSchema.xsd">
  <Class name="Income">

    <Attribute name="paymentReceivedDate">
      <type>
        <javaclass name="curam.util.type.Date"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <Attribute name="amount">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

  </Class>

  <Class name="Person">

    <Attribute name="incomes">
      <type>
        <javaclass name="List">
          <ruleclass name="Income"/>
        </javaclass>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <Attribute name="mostRecentIncome">
      <type>
        <ruleclass name="Income"/>
      </type>
      <derivation>
        <!-- 개발 초기에는 identifyMostRecentIncome_StronglyTyped
             메소드를 사용합니다.

             실제로는 각 메소드의 두 버전을 유지보수하지
             않습니다. 단순히 인수 및 리턴 유형의
             정확도를 저하시키고 단일 메소드를 유지합니다.
          -->

        <call class="curam.creole.example.BestPracticeDevelopment"
          method="identifyMostRecentIncome_WeaklyTyped">
          <type>
            <ruleclass name="Income"/>
          </type>
          <arguments>
            <this/>
          </arguments>
        </call>
      </derivation>
    </Attribute>
  </Class>

</RuleSet>

정적 메소드를 개발할 때 CER의 생성된 Java 클래스를 메소드의 인수 유형 및/또는 리턴 유형으로 사용하여 시작할 수 있습니다.

package curam.creole.example;

import java.util.List;

import curam.creole.execution.session.Session;
import
 curam.creole.ruleclass.Example_StaticMethodDevelopment.impl.Income;
import
 curam.creole.ruleclass.Example_StaticMethodDevelopment.impl.Person;

public class BestPracticeDevelopment {

  /**
   * 개인의 최신 수입을 식별합니다.
   *
   * 이 계산은 CER 표현식을 사용하여 수행할 수
   * 있지만 여기에서는 CER과 사용하기 위해 정적
   * Java 메소드를 개발할 때 생성된 유형의 사용을
   * 설명하기 위해 Java로만 표시됩니다.
   *
   * 이 메소드는 개발 시 사용하는 데만 적합합니다.
   * 프로덕션 시에는 아래에서
   * {@linkplain #identifyMostRecentIncome_WeaklyTyped}를 참조하십시오.
   *
   * 실제로는 각 메소드의 두 버전을 유지보수하지
   * 않습니다. 단순히 인수 및 리턴 유형의
   * 정확도를 저하시키고 단일 메소드를 유지합니다.
   */
  public static Income identifyMostRecentIncome_StronglyTyped(
      final Session session, final Person person) {

    Income mostRecentIncome = null;
    final List<? extends Income> incomes =
        person.incomes().getValue();
    for (final Income current : incomes) {
      if (mostRecentIncome == null
          || mostRecentIncome.paymentReceivedDate().getValue()
              .before(current.paymentReceivedDate().getValue())) {
        mostRecentIncome = current;
      }
    }

    return mostRecentIncome;
  }
}

Java 메소드가 만족스럽게 작동하면 다음과 같이 생성된 Java 클래스(프로덕션 환경에서는 사용하지 않아야 함)가 아니라 동적 규칙 오브젝트를 사용하도록 유형을 약화시켜야 합니다.

/**
   * 개인의 최신 수입을 식별합니다.
   *
   * 이 계산은 CER 표현식을 사용하여 수행할 수
   * 있지만 여기에서는 CER과 사용하기 위해 정적
   * Java 메소드를 개발할 때 생성된 유형의 사용을
   * 설명하기 위해 Java로만 표시됩니다.
   *
   * 이 메소드는 프로덕션에서 사용하는 데 적합합니다. 초기
   * 개발 시에는 위의
   * {@linkplain #identifyMostRecentIncome_StronglyTyped}를 참조하십시오.
   *
   * 실제로는 각 메소드의 두 버전을 유지보수하지
   * 않습니다. 단순히 인수 및 리턴 유형의
   * 정확도를 저하시키고 단일 메소드를 유지합니다.
   */
  public static RuleObject identifyMostRecentIncome_WeaklyTyped(
      final Session session, final RuleObject person) {

    RuleObject mostRecentIncome = null;
    final List<? extends RuleObject> incomes =
        (List<? extends RuleObject>) person.getAttributeValue(
            "incomes").getValue();
    for (final RuleObject current : incomes) {
      if (mostRecentIncome == null
          || ((Date) mostRecentIncome.getAttributeValue(
              "paymentReceivedDate").getValue())
              .before((Date) current.getAttributeValue(
                  "paymentReceivedDate").getValue())) {
        mostRecentIncome = current;
      }
    }

    return mostRecentIncome;

  }
경고:
정적 메소드의 구현을 변경하면 CER이 이전 버전의 정적 메소드를 사용하여 계산된 속성 값을 다시 계산해야 한다는 사실을 자동으로 알지 못합니다.

프로덕션 환경에서 저장된 속성 값에 대해 정적 메소드를 사용한 경우 구현을 변경하는 대신 새 정적 메소드(필요한 새 구현을 포함)를 작성한 다음 규칙 세트가 새 정적 메소드를 사용하도록 변경해야 합니다. 새 정적 메소드를 가리키도록 규칙 세트 변경사항을 공개하면 CER이 영향받는 속성 값의 모든 인스턴스를 자동으로 다시 계산합니다.

CER에서 호출된 정적 메소드(또는 특성 메소드)는 다음과 같아야 합니다.