Getting versioned costs that match this cost data object
After you create cost data objects, the default
rating engine must find the set of Cost
entity instances that correspond to each set of cost data objects. In
this context, a set refers to all cost data objects that share the same
cost data object key values. The cost data object key values are a list
of values that the property get
function for the KeyValues
returns.
The rating engine must find the corresponding costs entity instances for two different reasons.
- Find existing premium overrides to apply to a newly-created cost data object
- Use the cost data objects to update the Cost entity instances in the database
To find the set of versioned costs, the rating engine asks each cost data object. Every cost data class must override the getVersionedCosts method to provide this information. This is the most complicated function that a cost data subclass must implement. It is complicated because it requires careful application of knowledge about the PolicyCenter revisioning system.
The cost data object’s getVersionedCosts method must
return a list of version lists for the appropriate cost object type.
A VersionList represents
a set of cost rows that represent the cost for the same thing. Each row
represents a different date range, and the price for that date range.
For example, for a PersonalAutoCovCostData object, the getVersionedCosts method returns a list of version lists that represent PersonalAutoCovCost entity instances.
The calling code expects to receive a
List containing only one
version list, or an empty list if no existing cost entities match this
cost data object.
A general approach for the getVersionedCosts method is to first get a reference to the version list for the relevant object that has a cost. Use the PolicyLine method argument (which identifies the branch) and any private variables from your cost data object that contain Key objects.
Remember that a cost data object does not directly link to persisted entity instances. In the place of a direct link, the cost data object instead stores a fixed ID Key object. The fixed ID Key object encapsulates the entity type and the numeric fixed ID for the target object. The fixed ID uniquely represents the object within that branch (and across branches), across all of effective time.
Cost data objects store these fixed ID
Key objects in private
variables to refer to other entities. For example, a PersonalAutoCovCostData object
links to a coverage with a fixed ID Key
object for the coverage using its private variable called _covID.
To create a version list from a fixed
ID Key object, use the
EffDatedUtil static method
createVersionList.
EffDatedUtil.createVersionList( branch : PolicyPeriod, fixedIDKey : Key)The first argument is the
root PolicyPeriod for
that branch. You can easily get that from the getVersionedCosts first parameter
of type PolicyLine. Simply
get the PolicyLine.Branch
property. The getVersionedCosts
second parameter is the fixed ID Key
that identifies the desired object with a cost. Get this information
from a private variable in your cost data object. For example, the PersonalAutoCovCostData._covID property.
The createVersionList method returns that object’s version list, which is an object that can provide information about a revisioned entity and how it changes across time. The compile-time type of this version list is an untyped version list (typed to the version list superclass). Cast it as appropriate to the more specific type to access type-specific properties on it.
For a real world example, a PersonalVehicleCovCostData gets
the coverage version list as shown below.
// Get the version list for the auto coverage
var covVL = EffDatedUtil.createVersionList( line.Branch, _covID ) as PersonalVehicleCovVersionList
For the common simple case, the target object directly
contains costs for only one thing and stores it the Costs property. In this simple
case, the version list for this object also contains a Costs property. It is important
to note that this version list property does not contain costs directly.
Instead, it returns a list containing one version list that represents
one or more database rows of Cost
entities in the branch that represent that same thing. Your getVersionedCosts method can return
this list containing a single version list.
The Costs
property on the version list is an example of a generated property. Gosu
dynamically adds it to the PersonalVehicleCovVersionList
object because it is a property on a PersonalVehicleCov
entity and contains an array of entities.
If no such cost object exists, the version
list Costs property instead
contains an empty list. In other words, it is a list containing zero
version lists. Return that value to tell the rating engine that no such
cost objects yet exist.
It is unsupported to return more than
one version list in the list that you return from getVersionedCosts. In real world
conditions, each cost data object corresponds to no more than one fixed
ID, so no more than one version list is supported. The code that calls
the getVersionedCosts
method throws an exception if it gets more than one version list.
For example, the personal vehicle coverage
cost data class (PersonalVehicleCovCostData)
creates a version list and simply gets the version list property called
Costs.
override function getVersionedCosts(line : PersonalAutoLine) :
List<com.guidewire.commons.entity.effdate.EffDatedVersionList> {
// Get the version list for the auto coverage
var covVL = EffDatedUtil.createVersionList( line.Branch, _covID ) as PersonalVehicleCovVersionList
// Get versionlist.Costs. It contains a list of 1 version list for costs, or is an empty list
return covVL.Costs
}
However, some cases are more complex. In some cases
the target object may have a Costs
property but it represents multiple types of costs. For example, a personal
auto coverage may support multiple vehicles. In such a case, there is
a separate cost for each vehicle. This means that this method must iterate
across all costs for the target object and determine which cost entity
instances correspond to the current cost data object.
For example, for the personal vehicle
coverage cost data class (PersonalVehicleCovCostData),
some costs represent taxes, fees, or costs for vehicles other than the
one we want. To find the right cost, use the where collection enhancement method
and to determine if the cost matches the current cost data object.
In the personal vehicle coverage example, the Gosu block that tests each item must match a cost object if and only if all of the following are true.
- The cost is associated with the coverage for the cost data.
- The coverage’s cost
object has the right type (
PersonalAutoCovCost). - The coverage’s cost
object is for a vehicle whose fixed ID
Keymatches the vehicle ID stored in the cost data object.
This example uses a separate helper method called
isCostVersionListForVehicle,
which determines if the cost is for the same vehicle. Note that this
helper method is actually comparing a version list for the cost not the
cost entity itself.
override function getVersionedCosts(line : PersonalAutoLine) :
List<com.guidewire.commons.entity.effdate.EffDatedVersionList> {
var covVL = EffDatedUtil.createVersionList( line.Branch, _covID ) as PersonalAutoCovVersionList
return covVL.Costs.where(\ costVL -> isCostVersionListForVehicle(costVL)).toList()
}
[...]
private function isCostVersionListForVehicle(costVL : entity.windowed.PersonalAutoCovCostVersionList)
: boolean {
// Among all rows in the database for this cost, choose the one with the earliest effective date
var firstVersion = costVL.AllVersions.first()
return firstVersion typeis PersonalAutoCovCost and firstVersion.Vehicle.FixedId == _vehicleID
}
This example chooses the coverage version with earliest effective date. Although this choice appears arbitrary, cost cannot represent more than one car and a car cannot change its fixed ID value over time. Thus, you can get any coverage version from the version list, dereference its vehicle, and get the fixed ID from that entity instance.
