package gw.rating.rtm uses com.guidewire.pl.domain.persistence.core.impl.BundleInternal uses gw.api.database.Query uses gw.api.productmodel.PolicyLinePatternLookup uses gw.api.util.LocaleUtil uses gw.rating.RatingValidationUtil uses java.util.stream.Collectors uses java.util.stream.Stream @ReadOnly enhancement RateBookCoreEnhancement: RateBook { property get OwnedTables() : RateTable[] { return this.RateTables.where(\ rt -> rt.Owned) } function tablesWithDefinitionChanges() : List { return this.RateTables.where(\ rt -> rt.LastTableRowEdit < rt.Definition.UpdateTime).toList() } public function addReferenceRateTable(rateTable: RateTable): RateTable { var refTable = RateTableFactory.createFrom(rateTable) refTable.RateBook = this return refTable } function policyLineCodeToDescription(code : String) : String { return PolicyLinePatternLookup.getByPublicID(code).DisplayName } function isActive() : boolean { return this.Status == RateBookStatus.TC_ACTIVE } function isApproved() : boolean { return this.Status == RateBookStatus.TC_APPROVED } function isDraft() : boolean { return this.Status == RateBookStatus.TC_DRAFT } function isStage() : boolean { return this.Status == RateBookStatus.TC_STAGE } property get CalcRoutines() : CalcRoutineDefinition[] { return this.RateBookCalcRoutines*.CalcRoutineDefinition } property get LocalisedBookName(): String { return this["BookName_" + LocaleUtil.getDefaultLanguageType().Code] as String } /** * * @return The RateBookExportResult of type Excel if one exists, otherwise returns null */ property get ExcelExportResult() : RateBookExportResult { return getExportResult(TC_EXCEL) } /** * This method is used to get updated RateBookExportResult entity from DB while other process is updating the entity * @return updated RateBookExportResult Bean of type Excel if one exists, otherwise returns null */ property get ExcelExportResultFromDB() : RateBookExportResult { return ExcelExportResult?.refresh() as RateBookExportResult } property get TotalItemsToProcessInRateBookExport() : int { return this.CalcRoutines.Count + this.RateTables.Count + 1 //adding 1 for ratebook sheet itself } property get XMLExportResult() : RateBookExportResult { return getExportResult(TC_XML) } property get XMLExportResultFromDB() : RateBookExportResult { return XMLExportResult?.refresh() as RateBookExportResult } property get RateTablesMissingInCalcRoutines() : Set { var rateTableCodes = Stream.of(this.RateTables) .map(\rateTable -> rateTable.Definition.TableCode) .collect(Collectors.toSet()) return preloadCalcRoutinesStepsOperands().stream() .filter(\op -> op.OperandType == TC_RATETABLE and op.TableCode != null and !rateTableCodes.contains(op.TableCode)) .map(\op -> op.TableCode) .collect(Collectors.toSet()) } private function preloadCalcRoutinesStepsOperands() : List { var calcRoutineDefinitions = this.CalcRoutines var steps = RatingValidationUtil.loadArrays(calcRoutineDefinitions.toList(), "Steps") var operands = RatingValidationUtil.loadArrays(steps, "Operands") return operands } function getExportResult(exportType : RateBookExportType) : RateBookExportResult { var rateBookExportResult : RateBookExportResult if (this.RateBookExportResults.hasMatch(\result -> result.ExportType == exportType)) { rateBookExportResult = this.RateBookExportResults.singleWhere(\result -> result.ExportType == exportType) } return rateBookExportResult } function createExportResult(exportType: RateBookExportType) : RateBookExportResult { var rateBookExportResult = new RateBookExportResult(this.Bundle) rateBookExportResult.ExportType = exportType rateBookExportResult.RateBook = this return rateBookExportResult } /** * Set of Calc Routine Definitions included in this Rate Book that are not included in any promoted Rate Book. * Effectively, the set of Calc Routine Definitions that may need to be re-validated before this Rate Book is promoted. * @return Set of Calc Routine Definitions in this Rate Book that are not included in any promoted Rate Book */ property get CalcRoutinesNotInPromotedRateBook(): Set { var calcRoutinesInThisRateBook = Query.make(CalcRoutineDefinition) .withLogSQL(true) //Broken into a separate line otherwise it alters the type of calcRoutinesInThisRateBook calcRoutinesInThisRateBook.join(RateBookCalcRoutine#CalcRoutineDefinition) .compare(RateBookCalcRoutine#RateBook, Equals, this) var calcRoutinesInPromotedRateBooksQuery = Query.make(CalcRoutineDefinition) .withLogSQL(true) //Broken into a separate line otherwise it alters the type of calcRoutinesInPromotedRateBooksQuery calcRoutinesInPromotedRateBooksQuery .join(RateBookCalcRoutine#CalcRoutineDefinition) .join(RateBookCalcRoutine#RateBook) .compare(RateBook#Status, NotEquals, RateBookStatus.TC_DRAFT) //Both calcRoutinesInThisRateBook and calcRoutinesInPromotedRateBooksQuery are Query // var calcRoutinesInThisBookThatAreNotAlreadyValidated = calcRoutinesInThisRateBook.subselect("ID", CompareNotIn, calcRoutinesInPromotedRateBooksQuery, "ID") return calcRoutinesInThisBookThatAreNotAlreadyValidated.select().toSet() } }