Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
h2. 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.

h2. 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 - Should free units be used first subtracted from surplus or from the current {{SubscriptionBundle}}.
# Internall order of the surplus - Are the 'newer' or 'older' free units used first.

h1. Design and implementation
{gliffy:name=Rollover design|align=left|size=L|version=7}
The starting point for the design, was the fact, that a {{subscription bundle}} needs 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 a responsibility of the bundle to fetch and update both original and additional, used for surplus subscription bundles.

h2. 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 remnant, that is above the maximal 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.

h3. Updating SubscriptionBundle


h4. 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.

h4. Update through rollover

The usageused units isare aggregated together on {{VALUE_2}} and {{VALUE_4}} until the maximum, defined by {{VALUE_3}} is reached.


h2. Bundle

If a bundle is supposed to be a rollover bundle, it is a requirement for it to implement the {{RolloverBundle}} interface. The interface has five methods and two enumeration types:
* {{getSurplusContainter}} \- returns a {{SurplusContainter}} object, that wraps surplus for a given {{SubscriptionBundle}}. The {{SurplusContainter}} is described in the following paragraph,
* {{getMaxTransferableAmount}} \- returns the maximum amount of units, that can be transferred as surplus from a {{SubscriptionBundle}},
* {{getSurplusPeriodOrder}} \- returns one of the values of {{SURPLUS_PERIOD_ORDER}}, which indicates, whether {{SubscriptionBundle}} used for surplus should be ordered from newer to older or the other way around,
* {{getSurplusUsageMode}} \- returns one of the values of {{SURPLUS_PERIOD_ORDER}} and is used to define, whether surplus should be used before or after {{SubscriptionBundle}},
* {{getAmountOfRolloverPeriods}} \- returns an amount of previous periods, from which surplus can be used
* {{SURPLUS_PERIOD_ORDER}} \- an enum with two values: {{NEWER_FIRST}} and {{OLDER_FIRST}} used by {{getSurplusPeriodOrder}},
* {{SURPLUS_USAGE_MODE}} \- - an enum with two values: {{USE_SURPLUS_BEFORE_BUNDLE}} and {{USE_SURPLUS_AFTER_BUNDLE}} used by {{getSurplusUsageMode}},
Currently, the only {{Bundle}}, that implements the {{RolloverBundle}} interface is {{RestrictActive}}. This means, that {{DataBundle}}, {{DurationBundle}}, {{EventBundle}} and {{ForwardBundle}} have a possibility, when properly configured, to behave like a {{RolloverBundle}}.

One thing is worth to point 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 has happened, because the classical {{VALUE_1 - VALUE_2}} is no longer valid, when surplus is used.


h2. SurplusContainer

{{SurplusContainer}} is a wrapper object, that encapsulates a list of {{RolloverSurplus}} objects. It has two methods:
* {{getSurplusValue}} returns sum of surplus for the whole period,
* {{updateSurplus}} updates the whole surplus, through looping through the list of {{RolloverSurplus}}; returns the remainder from the last {{RolloverSurplus.updateSurplus}}.
The class doesn't have a default constructor and can be only constructed by {{SurplusContainter(List<RolloverSurplus> surplusList)}}. The list can be contructed with a helper class {{SurplusContainerFetcher}}.

h1. Configuration

In order to configure {{DataBundle}}, {{DurationBundle}}, {{EventBundle}} or {{ForwardBundle}} to use rollover functionality following parameters need to 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 {{SubscriptionBundles}}. Again two values are possible: USE_SURPLUS_BEFORE_BUNDLE, USE_SURPLUS_AFTER_BUNDLE |
| ROLLOVER.PERIODS | Amount of previous {{SubscriptionBundles}} used in rollover. In other words, the number defines how many times surplus can be rolled over |