package gw.rating.rtm.util uses gw.api.database.Query uses gw.api.productmodel.Offering uses gw.api.productmodel.PolicyLinePattern uses gw.api.productmodel.PolicyLinePatternLookup uses gw.api.productmodel.Product uses gw.api.system.PCDependenciesGateway uses java.util.ArrayList uses java.util.Collection uses gw.api.productmodel.ProductLookup uses gw.rating.GenericRateBookFieldSearch uses gw.util.Pair uses gw.api.locale.DisplayKey class ProductModelUtils { static function getAllPolicyLines() : List { return PolicyLinePatternLookup.All.map(\ p -> p.PublicID) } static function getAllPolicyLinesForSearch() : List { return getAllPolicyLines() .concat({GenericRateBookFieldSearch.GENERIC_POLICY_LINE_CODE}) .toList() } static function getAllPolicyLinePatterns() : Collection { return PolicyLinePatternLookup.All } static function getPolicyLinesWithTables() : List { var lines = new ArrayList() var lobPatterns = getAllPolicyLinePatterns() for (lobPattern in lobPatterns) { var lobTables = Query.make(RateTableDefinition) .compare(RateTableDefinition#PolicyLine, Equals, lobPattern.PublicID).select() if (lobTables.HasElements) { lines.add(lobPattern.PublicID) } } return lines } static function getAllUWCompanies() : List { return PCDependenciesGateway.getUWCompanyFinder().findUWCompanies().toList() } static function getAllUWCompaniesForSearch() : List> { return getAllUWCompanies() .map(\ uwCompany -> new Pair(uwCompany.DisplayName, uwCompany)) .concat({new Pair(DisplayKey.get("Web.Rating.Filter.Generic"), null)}) .toList() } static function getAllJurisdictionsForSearch() : List> { return Jurisdiction .getTypeKeys(false) .map(\ jurisdiction -> new Pair(jurisdiction.DisplayName, jurisdiction)) .concat({new Pair(DisplayKey.get("Web.Rating.Filter.Generic"), null)}) .toList() } static function getOfferingDisplayName(code : String) : String { if (code == null) return null var o = PCDependenciesGateway.getProductModel().getAllInstances(Offering) .firstWhere(\ o -> o.PublicID.equals(code)) return o.Product.Name + " - " + o.Name } static function getOfferingsFor(line : String) : List { var products = productsFor(line) return buildOfferingList(products) } static function getAllSearchOfferingsFor(line : String) : List { var offerings = line == null ? buildOfferingList(allProducts()) : getOfferingsFor(line) return {GenericRateBookFieldSearch.GENERIC_OFFERING_CODE} .concat(offerings) .toList() } static function getAllDisplayOfferingsFor(line : String) : List { var offerings = getOfferingsFor(line) return {GenericRateBookFieldSearch.GENERIC_OFFERING_CODE} .concat(offerings) .toList() } private static function allProducts() : List { return PCDependenciesGateway.getProductModel().getAllInstances(Product).toList() } private static function productsFor(line : String) : List { return allProducts().where(\ prod -> prod.LinePatterns.contains(PolicyLinePatternLookup.getByPublicID(line))) } private static function buildOfferingList(products : List) : List { var offerings = new ArrayList() products.each(\ p -> { // need to create a copy because p.Offerings is of type LocableList that can't be sorted var copy = p.Offerings.copy() copy.sortBy(\ o -> o.Priority).each(\ o -> offerings.add(o.PublicID)) }) return offerings } /** * If more than one product has the same displayname, display with the abbreviation appended. * * Use case: if the ISO GL7 line is applied, General Liability shows up twice, once for base GL and once for GL7. * Since the rating screen is outside the context of a policy, there's no good way to call the availability logic and discover that the base GL is unavailable. * Therefore, the products in a pulldown will be displayed like this: * * ... * Commercial Property * General Liability (GL) * General Liability (GL7) * Inland Marine * ... */ static function lineStyleProductDisplay(p : Product) : String { var productsKeyedByDisplayname = ProductLookup.getAll().partition(\ prod -> prod.DisplayName) var isDuplicated = productsKeyedByDisplayname.get(p.DisplayName).Count > 1 return isDuplicated ? p + " (" + p.Abbreviation + ")" : p.DisplayName } static function getPolicyLinePattern(linePatternCode : String) : PolicyLinePattern { return linePatternCode == GenericRateBookFieldSearch.GENERIC_POLICY_LINE_CODE ? null : PolicyLinePatternLookup.All.singleWhere(\p -> p.PublicID == linePatternCode) } }