Versioned costs for PersonalAutoCovCostData
Probably the most complicated method to implement
on CostData objects is
the getVersionedCosts
method. It finds the VersionList,
if any, of the existing cost on the coverage that points to this vehicle.
Since it has only the fixed ID of the coverage, rather than an actual
PersonalAutoCov object,
it cannot call _cov.VersionList.
However, this code can construct a VersionList
object based on the branch and the fixed ID of the Coverage.
To do this, use the EffDatedUtil.createVersionList
method. The resulting version list is typed to the root type of all version
lists. Thus, the code casts it as the more specific type, PersonalAutoCovVersionList. Next,
the code gets the List
of cost version lists, and finds the one (if any) that corresponds to
the vehicle in question.
override function getVersionedCosts(line : PersonalAutoLine) :
List<gw.pl.persistence.core.effdate.EffDatedVersionList> {
var covVL = EffDatedUtil.createVersionList( line.Branch, _covID ) as PersonalAutoCovVersionList
return covVL.Costs.where(\ costVL -> isCostVersionListForVehicle(costVL)).toList()
}
In this case, the method calls a private method called
isCostVersionListForVehicle
to do most of the work. To determine if a given PersonalAutoCovCostVersionList
applies to this vehicle, it looks at the first (chronological) version
and check the FixedId
of its associated Vehicle.
private function isCostVersionListForVehicle(
costVL : entity.windowed.PersonalAutoCovCostVersionList) : boolean {
var firstVersion = costVL.AllVersions.first()
return firstVersion typeis PersonalAutoCovCost and firstVersion.Vehicle.FixedId == _vehicleID
}
