package gw.rating.rtm.validation uses gw.rating.rtm.domain.ErrorCollectingVisitor uses gw.rating.rtm.domain.table.RateBookModel uses gw.rating.rtm.domain.table.RateTableRow uses gw.rating.rtm.domain.table.RateTableCell uses java.lang.Comparable uses java.util.Set uses gw.rating.rtm.domain.ErrorCollector class RemovedParameterValidationVisitor extends ErrorCollectingVisitor { var _matchOps : Set = null var _currentRow : RateTableRow = null construct(collector : ErrorCollector) { super(collector) } override function visitBoolean(ratingCell: RateTableCell>) { checkIfMatchOpRemoved(ratingCell) } override function visitDate(ratingCell: RateTableCell>) { checkIfMatchOpRemoved(ratingCell) } override function visitDecimal(ratingCell: RateTableCell>) { checkIfMatchOpRemoved(ratingCell) } override function visitInteger(ratingCell: RateTableCell>) { checkIfMatchOpRemoved(ratingCell) } override function visitString(ratingCell: RateTableCell>) { checkIfMatchOpRemoved(ratingCell) } override function visitEmpty(ratingCell: RateTableCell>) { } override function visitingEmptyCells(): boolean { return true } override function visit(ratingRow: RateTableRow) { _currentRow = ratingRow } override function visit(bookModel: RateBookModel) { } /** * It is possible that the RTD underlying the rate table has had a parameter * removed while this rate table was being edited. This function checks for that, * by grabbing the up-to-date definition from the database, and checking that * {@code ratingCell}'s matchop is still exists on the RTD. If it does not, * that means that the parameter was removed from the definition, and so this * rate table is no longer allowed to fill in a value for it. */ private function checkIfMatchOpRemoved(ratingCell : RateTableCell>) { if (_matchOps == null) { var tableDefinition = gw.api.database.Query.make(RateTableDefinition) .compare(RateTableDefinition#TableCode, Equals, ratingCell.ColumnDefinition.Definition.TableCode) .compare(RateTableDefinition#PolicyLine, Equals, ratingCell.ColumnDefinition.Definition.PolicyLine) .select() .single() _matchOps = tableDefinition.MatchOps.toSet() } var matchOp = ratingCell.MatchOp if (matchOp != null and not _matchOps.contains(matchOp)) { addCellError(_currentRow, ratingCell, RateTableErrorType.TC_PARAMETERREMOVED) } } }