Advanced version list examples
The following examples use a variety of PolicyCenter
objects and includes some more advanced VersionList APIs. For version
list APIs that return lists or lists of version lists, you can use the
powerful Gosu enhancements for collections to make Gosu code as concise
as possible. For example, you can use code such as
vehicle.VersionList.AllVersions.first()Many collection enhancements have arguments that are Gosu blocks, which are in-line functions that make powerful Gosu code easy to read.
For more information about collection enhancements, see Collections. For more information about blocks, see Blocks.
Get all costs from an auto policy line
For example, suppose you have a PersonalAutoLine. If you want
to get all its personal auto costs (in its PACosts property) in the contractual
period, use the Gosu code:
myCostVersionLists = autoPolicyLine.VersionList.PACostsThis returns a list of version lists. Each of these version lists represent one cost and all its costs across effective time.
It is an extremely common mistake to use code that looks like
notAllCosts = autoPolicyLine.PACosts // generally NOT what you want to doThis code does not get all the costs. It gets only the costs associated only at the slice date (which typically is meaningless). You usually want all the costs for the policy period, which represents the total price of the policy.
Extract all costs from an auto policy line and return them in a 1-dimensional array
To extract all cost entities across effective
time, use the flatMap
collection enhancement method. As an argument it takes a Gosu block.
In this case, the block takes a cost version list as an argument. Then
the code gets all versions of this cost. Then finally the flatMap enhancement method combines
them into a single list.
var allCosts = autoPolicyLine.VersionList.PACosts.flatMap( \ costVL -> costVL.AllVersions )The result is a list that contains all auto costs as one flattened list.
Some cost objects have the same fixed IDs as other costs (they are the same cost) but vary in effective dates.
Original drivers of a vehicle
Get the drivers of the vehicle as of the earliest effective date on the policy for this vehicle:
var firstVersionUnsliced = vehicleVL.AllVersions.First()
var origDrivers = firstVersion.getSlice(firstVersion.EffectiveDate).DriversThe list that vehicle.AllVersions returns is
ordered by effective date. Getting the first item from the list (as this
example does) gets the item with the earliest effective date.
Get all coverages on a vehicle and print data from each version, segregated by each unique coverage
Display all the coverages that any time were on the vehicle along with display name and the date range covered by that version:
for (covVL in vehicleVL.Coverages) {
for (cov in covVL.AllVersions) {
print("${cov.Pattern.DisplayName}: effdate ${cov.EffectiveDate}, expdate ${cov.ExpirationDate}")
}
}Get a vehicle’s garage location at a specific date
Suppose you want to get a vehicle’s garage location. Since the location might have changed, you
often just want to show one location, usually the last one or
perhaps the one as of a particular date. This example assumes you
have a vehicle version list in a variable called
vehicleVL.
// find out which version of this object was effective on that date
var vehicleUnsliced = vehicleVL.AsOf(asOfDate)
if (vehicleUnsliced == null) throw "No vehicle effective on that date"
// get the version of the garage at that date
// Get the Garage in slice mode, just before the end of its active time
Var vehicleSliced = vehicleVersion.getSlice(vehicleUnsliced.ExpirationDate – 1 sec)
var g = vehicleSliced.garageLocation
// print the location (in real world code, display in PCF files instead)
print("garage ${g.AddressLine1} / ${g.AddressLine2} / ${g.City} / ${g.State} ")
See Safely accessing foreign keys with slice mode for related discussion.
Get all available drivers for a vehicle at a specific date
This example assumes you have a vehicle
version list in a variable called vehicleVL.
var vv = vehicleVL.AsOf(asOfDate).AvailableDriversAlthough PersonalVehicle.AvailableDrivers returns an array of driver objects, it
is an enhancement property not a database-backed property. The
version list properties that Gosu creates for array properties (such
as vehicle.DriversAsOf(date)) only exist for
database-backed properties. Thus, it might seem like the following
Gosu code works, but it results in a compile error:
var v2 = vehicleVL.AvailableDriversAsOf(asOfDate) // compile error!