Rating System Overview
The rating system transforms raw usage events (EDRs) into priced wallet operations.
Complete Rating Flow
EDR (OPEN)
↓ UsageRatingService.rateUsage()
↓ Match UsageChargeInstance by filterParam1-4 + filterExpression
↓
UsageChargeInstance (matched)
↓ PricePlanSelectionService.determineDefaultPricePlan()
↓
PricePlanMatrix Selection (Step 1 - Container)
Filters: chargeCode, seller, offer, country, currency, criteria1-3,
subscriptionDateRange, ratingDateRange, subscriptionAge, quantity
Ordered by: priority ASC
↓
PricePlanMatrixVersion Selection (Step 2 - Active Version)
Filters: status=PUBLISHED, validity.from <= operationDate < validity.to
↓
PricePlanMatrixLine Selection (Step 3 - Price Line)
If isMatrix=false: use version.price directly
If isMatrix=true:
- Match attribute values against line values
- Order by priority ASC, ratingAccuracy DESC
- Return first fully matching line
- Fallback: line with ratingAccuracy=0 (default)
↓
WalletOperation Created
- Stores: priceplan, pricePlanMatrixVersion, pricePlanMatrixLine
- Status: OPEN
↓
RatedTransaction Created (aggregation)
- Status: OPEN → BILLED (at invoicing)
Key Entities
EDR (Event Detail Record)
Raw usage event before rating.
Key Fields:
subscription- Target subscriptionquantity- Usage amountparameter1-9- String parametersdateParam1-5- Date parametersdecimalParam1-5- Numeric parametersstatus- OPEN → RATED or REJECTED
WalletOperation
Priced result of rating.
Key Fields:
amountWithoutTax,amountWithTax- Calculated amountsunitAmountWithoutTax,unitAmountWithTax- Per-unit amountsrawAmountWithoutTax,rawAmountWithTax- Before minimumpriceplan,pricePlanMatrixVersion,pricePlanMatrixLine- Pricing contextstatus- OPEN → TREATED (when RT created) → RERATEDoverrodePrice- Manual override flag
RatedTransaction
Aggregated transaction for invoicing.
Key Fields:
walletOperations- Source wallet operationsinvoiceLine- Target invoice linestatus- OPEN → BILLED (invoiced) → CANCELED
EDR Status Lifecycle
OPEN → RATED (success)
→ REJECTED (failure)
→ CANCELLED (versioning conflict)
→ DUPLICATED
→ AGGREGATED
→ MEDIATING
WalletOperation Status
OPEN → TREATED (RT created)
→ RERATED (if re-rated)
→ CANCELED (if reversed)
Price Override Mechanisms
1. ChargeInstance Level
ChargeInstance ci = ...;
ci.setAmountWithoutTax(new BigDecimal("100.00"));
ci.setAmountWithTax(new BigDecimal("120.00"));
ci.setApplyDiscountsOnOverridenPrice(true);
2. WalletOperation Level
WalletOperation wo = ...;
wo.setOverrodePrice(true);
wo.setUnitAmountWithoutTax(new BigDecimal("50.00"));
3. PricePlanMatrix EL Expressions
PricePlanMatrix ppm = ...;
ppm.setAmountWithoutTaxEL("#{basePrice * (1 - discount)}");
ppm.setAmountWithTaxEL("#{amountWithoutTax * 1.2}");
4. Script-Based Pricing
PricePlanMatrix ppm = ...;
ppm.setScriptInstance(customPricingScript);
5. Discount Plans
Negative wallet operations created via DiscountPlan.
Counter Management
Counters track usage limits and aggregation.
CounterTemplate
counterType- CONSUMPTION (decrement) or ACCUMULATOR (sum)ceiling- Maximum value for consumption counterscalendar- Period reset timingnotificationLevels- JSON for threshold alerts
CounterPeriod
periodStartDate,periodEndDate- Period boundariesvalue- Current accumulated valuelevel- Current notification level
Counter-Based Rating
EDR arrives
↓
Check CounterPeriod.value
↓
If ceiling reached → Rate at overage price
If not reached → Decrement counter (no charge)
↓
At billing period end → Aggregate and apply tiered pricing