Summary
Rollover bundles are used to enable transfer some of the remaining free units from one period to an another later period. The purpose of this document is to describe, how this functionality is implemented as a part of the core project.
Rollover Concept
Rollover means, that some part of the free units from one SubscriptionBundle
which have not been used in one period, can be used later on by an another later SubscriptionBundle
. The amount to be 'rolled over' to another bundle can also be called "surplus". The Rollover can be described with four parameters:
- Maximum rollover amount per
SubscriptionBundle
- how much can be transferred from one period to another. - Rollover validity\Rollover period length - For how long is the rollover valid, i.e. how many periods from the past can be used.
- Rollover usage mode - In use, should free units first be subtracted from surplus or from the current
SubscriptionBundle
. - Internal order of the surplus - Are the 'newer' or 'older' free units used first.
Design and implementation
The starting point of the design was the fact, that a subscription bundle
has to work in two contexts:
- in the original - when a billing record has the charge date between start and end date of the
subscription bundle
- as a container of surplus available for other
subscription_bundles
.
In the rating process, it should be the responsibility of the bundle to fetch and update both original and additional, used for surplus subscription bundles.
SubscriptionBundle
The existing SubscriptionBundle_
has been extended with methods defined by RolloverSurplus
interface. These are:
getSurplus
- returns amount of units that can be used by another bundles,updateSurplus
- updates the surplus with a given value, returns the part above the maximum surplus value -VALUE_3
,save
- saves the object.
A subscription_bundle
that is used by rollover bundles, utilizes all four value parameters:
VALUE_1
- number of units inside bundle,VALUE_2
- number of units used,VALUE_3
- number of units, that can be rolled over,VALUE_4
- number of used rollover units.
Updating SubscriptionBundle
Standard Update
When a SubscriptionBundle
object is used in the normal way, the used units are accumulated on VALUE_2
. When VALUE_2
is greater than VALUE_1 - VALUE_3
, then VALUE_4
gets a new value calculated in the following way VALUE_2 - (VALUE_1 - VALUE_3)
. If VALUE_4
is greater than VALUE_3
then VALUE_3
is set.
Update through rollover
The surplus units are aggregated on VALUE_2
and VALUE_4
, until the maximum defined by VALUE_3
is reached.
Bundle
If a bundle is designed as a rollover bundle, it must implement the RolloverBundle
interface. The interface has five methods and two enumeration types:
getSurplusContainter
- returns aSurplusContainter
object, that wraps surplus for a givenSubscriptionBundle
. TheSurplusContainter
is described in the following paragraph,getMaxTransferableAmount
- returns the maximum amount of units that can be transferred as surplus from aSubscriptionBundle
,getSurplusPeriodOrder
- returns one of the values ofSURPLUS_PERIOD_ORDER
, which indicates whetherSubscriptionBundle
used for surplus should be ordered from newer to older units, or the other way around,getSurplusUsageMode
- returns one of the values ofSURPLUS_PERIOD_ORDER
and is used to define, whether surplus should be used before or afterSubscriptionBundle
,getAmountOfRolloverPeriods
- returns an amount of previous periods from which surplus can be usedSURPLUS_PERIOD_ORDER
- an enum with two values:NEWER_FIRST
andOLDER_FIRST
used bygetSurplusPeriodOrder
,SURPLUS_USAGE_MODE
- - an enum with two values:USE_SURPLUS_BEFORE_BUNDLE
andUSE_SURPLUS_AFTER_BUNDLE
used bygetSurplusUsageMode
,
Currently, the onlyBundle
, that implements theRolloverBundle
interface isRestrictActive
. This means thatDataBundle
,DurationBundle
,EventBundle
andForwardBundle
have a possibility, when properly configured, to behave like aRolloverBundle
.
One thing is worth pointing out: a new method, for calculating the amount of free units on a SubscriptionBundle
, has been introduced on the Bundle_
class . It is called getFreeUnits
. This was done, because the classical VALUE_1 - VALUE_2
is no longer valid, when surplus is used.
SurplusContainer
SurplusContainer
is a wrapper object that encapsulates a list of RolloverSurplus
objects. It has two methods:
getSurplusValue
returns the sum of surplus for the whole period,updateSurplus
updates the whole surplus by looping through the list ofRolloverSurplus
; returns the remainder from the lastRolloverSurplus.updateSurplus
.
The class does not have a default constructor and can be only constructed bySurplusContainter(List<RolloverSurplus> surplusList)
. The list can be constructed with a helper classSurplusContainerFetcher
.
Configuration
In order to configure DataBundle
, DurationBundle
, EventBundle
or ForwardBundle
to use rollover functionality following parameters must be set up:
Name |
Description |
---|---|
ROLLOVER.PERIOD.ORDER |
Defines whether older or newer surplus should be used first. Two possible values are possible: NEWER_FIRST and OLDER_FIRST |
ROLLOVER.USAGE.MODE |
Indicates whether surplus should be used before or after the |
ROLLOVER.PERIODS |
Amount of previous |