규칙 조치

규칙 조치는 규칙의 if 파트가 true인 경우 규칙이 실행하는 하나 이상의 조치 구문으로 구성됩니다. 이는 규칙의 if 파트가 false인 경우 실행할 조치 구문도 포함할 수 있습니다.

규칙의 then 및 else 파트에서 조치를 정의할 수 있습니다.

규칙의 then 파트는 하나 이상의 조치를 정의해야 합니다. then 또는 else 파트가 여러 조치를 포함하는 경우 규칙이 나열된 순서대로 조치를 실행합니다.

then 파트의 예제

다음 규칙은 쇼핑 카트의 값이 $100를 초과할 때 쿠폰 이벤트를 전송하며, 그렇지 않으면 규칙이 조치를 적용하지 않습니다.

when a purchase event occurs
if    the value of 'the shopping cart' is more than 100 
then
    emit a new coupon event where
       the amount is 5,
       the customer is the customer of this purchase event,
       the message is "Thank you for your purchase. Please accept this coupon for $5.";

else 파트의 예제

다음 규칙에서는 조건이 만족하면(then) 하나의 변경사항이 적용되고 조건을 만족하지 않으면(else) 다른 변경사항이 적용됩니다.

if    the status of 'the loan report' is approved 
    and the loan grade of 'the loan report' is one of { "A", "B", "C" } 
then
    print "Your loan has been approved"; 
else 
    print "We are sorry. Your loan has not been approved";

목록의 각 항목에 대한 규칙 조치

목록에서 각 항목마다 규칙이 실행하는 조치를 정의할 수 있습니다.for each <item> in <list> 연산자를 사용하여 목록의 항목에 조치를 적용합니다.

다음 조치문의 그룹은 고가 구매('expensive purchases') 목록의 모든 항목에 적용됩니다.

definitions
    set 'expensive purchases' to all purchases in the purchases of 'the customer'
        where the price of each purchase is more than 100;
then
    for each item in the items of 'expensive purchases':
    - print "A 5% discount has been applied";

then 및 else 파트가 있는 규칙

then 및 else 파트가 포함된 규칙은 동일한 엔티티와 일치하며 서로 간에 부정되는 조건이 있는 두 개의 규칙이 압축된 양식입니다.

일부 경우에 then 파트를 실행하면 엔티티의 상태가 변경되며 else 파트를 적용할 수 있도록 합니다. 따라서 then 및 else 파트가 모두 적용될 수 있습니다.

다음 예에서는 계정이 널(null)일 때 then 파트가 적용되며 계정 엔티티가 작성됩니다. 조치는 엔티티의 상태를 변경하고 조건을 거짓으로 만들며 else 파트가 적용될 수 있도록 합니다.

when a new account event occurs, called 'the event'
if    'the account' is null
then    set 'the account' to a new account where
        the customer is the customer of 'the event',
        the opening date is 'the event',
        the status is NEW; else 
    print "The account already exists";

엔티티의 상태를 작성하거나 수정하기 위해 else 파트가 있는 규칙은 부적절하며 혼동되는 결과가 나타날 수 있습니다. 그 대신에 서로 간에 부정되는 조건으로 두 개의 규칙을 별도로 작성할 수 있습니다. 예를 들어, 다음 규칙으로 위의 규칙을 대체할 수 있습니다.

다음 규칙은 계정이 존재하는지 여부를 확인합니다.

when a new account event occurs, called 'the event'
if    'the account' is null
then    set 'the account' to a new account where
        the customer is the customer of 'the event',
        the opening date is 'the event',
        the status is NEW; 

다음 규칙은 계정이 존재하지 않는지 여부를 확인합니다.

when a new account event occurs, called 'the event'
if    'the account' is not null
then    print "The account already exists";

이벤트가 도착할 때 계정 엔티티에 널(null)값이 있는 경우에는 첫 번째 규칙이 적용되며 규칙 조치는 새 계정 엔티티를 작성합니다.

규칙이 다시 평가되는 경우, 계정의 값은 더 이상 널(null)이 아니며 이 규칙 인스턴스는 더 이상 적용되지 않습니다. 두 번째 규칙이 적용 가능하게 되며 일치하는 규칙의 목록에 추가됩니다. 두 번째 규칙이 실행되면 조치에서 "계정이 이미 존재합니다" 메시지를 인쇄합니다. 규칙 일치 및 선택 프로세스에 대한 자세한 정보는 규칙 동작을 참조하십시오.