package gw.rating.rtm.validation uses java.lang.Comparable uses gw.rating.rtm.domain.ErrorCollectingVisitor uses gw.rating.rtm.domain.ErrorCollector uses gw.rating.rtm.domain.table.RateTableCell uses gw.rating.rtm.domain.table.RateTableRow uses gw.rating.rtm.domain.table.RateBookModel uses gw.api.system.PCLoggerCategory class RangeValidatorVisitor extends ErrorCollectingVisitor { var _minCell : RateTableCell var _maxCell : RateTableCell var _currentRow: RateTableRow construct(collector : ErrorCollector) { super(collector) } override function visitBoolean(ratingCell : RateTableCell) {} override function visitDate(ratingCell : RateTableCell) { apply(ratingCell, ratingCell) } override function visitDecimal(ratingCell : RateTableCell) { apply(ratingCell, ratingCell) } override function visitInteger(ratingCell : RateTableCell) { apply(ratingCell, ratingCell) } override function visitString(ratingCell : RateTableCell) { } override function visitEmpty(ratingCell : RateTableCell) { apply(ratingCell, null) } override function visit(ratingRow : RateTableRow) { _currentRow = ratingRow } override function visit(bookModel : RateBookModel) {} private function apply(ratingCell : RateTableCell, cellValue : RateTableCell) { var ratingCellColumnDef = ratingCell.ColumnDefinition if (not ratingCellColumnDef.IsParameterColumn) { return } var ratingCellMatchOp = ratingCell.MatchOp var validator = ratingCellMatchOp.MatchOpDefinition.validator() if (PCLoggerCategory.RTM.DebugEnabled) { PCLoggerCategory.RTM.debug("Using ratingCellMatchOp: " + ratingCellMatchOp) PCLoggerCategory.RTM.debug("Using MatchOpDefinition: " + ratingCellMatchOp.MatchOpDefinition) PCLoggerCategory.RTM.debug("Running RangeValidatorVisitor with: " + validator) PCLoggerCategory.RTM.debug("cellValue: " + cellValue.Value) final var rateTableColumns = ratingCellMatchOp.sortedParams() PCLoggerCategory.RTM.debug("first: " + rateTableColumns.first()) PCLoggerCategory.RTM.debug("last: " + rateTableColumns.last()) } // only a RangeMatchOpValidator knows how to validate a visited range // Note that we are assuming we will see the min cell before we see the max cell if (validator typeis RangeMatchOpValidator) { var ratingCellMatchOpSortedParams = ratingCellMatchOp.sortedParams() if (ratingCellMatchOpSortedParams.first() == ratingCellColumnDef) { _minCell = cellValue } if (ratingCellMatchOpSortedParams.last() == ratingCellColumnDef) { _maxCell = cellValue validate(validator) } } } private function validate(validator : RangeMatchOpValidator) { if (!validator.validate({_minCell.Value, _maxCell.Value})) { addCellError(_currentRow, _minCell, RateTableErrorType.TC_INVALIDRANGE) } } override function visitingEmptyCells() : boolean { return true } }