Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This sample demonstrates a service for specifying the charge rates for calls through the use of business rules.

...

 

Code Block
languagehtml/xml
    <ruleService
        name="CallChargingService"
        xmlns="http://wso2.org/carbon/rules"
        targetNamespace="http://com.test/callcharging">
    <ruleSet>
        <rule resourceType="regular" sourceType="inline">
            <![CDATA[
                package callcharging

                import samples.callcharging.CallLog;
                import samples.callcharging.CallCharge;

                rule "Local Call During Daytime"
                when
                      callLog : CallLog( type == "local")
                           eval((6 < callLog.now()) && (callLog.now()< 18))
                then
                           CallCharge c = new CallCharge();
                           c.setAmount(callLog.getPeriod() * 2);
                           insertLogical(c);
                end

                rule "Local Call During Night"
                when
                      callLog : CallLog( type == "local")
                           eval((18 < callLog.now()) || (callLog.now()< 5))
                then
                           CallCharge c = new CallCharge();
                           c.setAmount(callLog.getPeriod() * 1);
                           insertLogical(c);
                end

                rule "IDD Call During Daytime"
                when
                      callLog : CallLog( type == "idd")
                           eval((6 < callLog.now()) && (callLog.now()< 18))
                then
                           CallCharge c = new CallCharge();
                           c.setAmount(callLog.getPeriod() * 6);
                           insertLogical(c);
                end

                rule "IDD Call During Night"
                when
                      callLog : CallLog( type == "idd")
                           eval((18 < callLog.now()) || (callLog.now()< 5))
                then
                           CallCharge c = new CallCharge();
                           c.setAmount(callLog.getPeriod() * 4);
                           insertLogical(c);
                end

            ]]>
        </rule>
    </ruleSet>
    <operation name="charge">
        <input wrapperElementName="callCharge" namespace="http://com.test/callCharge">
            <fact elementName="callLog" namespace="http://com.test/callCharge" type="samples.callcharging.CallLog"></fact>
        </input>
        <output wrapperElementName="callChargeRespone" namespace="http://com.test/callCharge">
            <fact elementName="callCharge" namespace="http://com.test/callCharge" type="samples.callcharging.CallCharge"></fact>
        </output>
    </operation>
</ruleService>

 

Executing the Sample

To execute the sample, run the ant command from the  <PRODUCT_Home>HOME>/samples/callcharging.service directory to run the CallCharging Service.

Info

Before executing this sample, it is recommended that you refer Exposing Rules as Services which explains in detail the process of writing and deploying a business rule.

 

...