package gw.rating.rtm.validation uses gw.rating.rtm.domain.ErrorCollector uses java.lang.Comparable uses gw.rating.rtm.domain.table.RateTableCell uses gw.rating.rtm.domain.ErrorCollectingVisitor uses gw.rating.rtm.domain.table.RateTableRow uses gw.rating.rtm.domain.table.RateBookModel uses gw.util.AutoMap class NullParamValidationVisitor extends ErrorCollectingVisitor { var _nullSeen = false var _currentRow : RateTableRow var _minCell : RateTableCell var _maxCell : RateTableCell var _columnDefinitionIsParameterMap : AutoMap construct(collector : ErrorCollector) { super(collector) _columnDefinitionIsParameterMap = new AutoMap({}, \ key -> key.IsParameterColumn) } override function visitBoolean(ratingCell : RateTableCell) { apply(ratingCell, ratingCell) } 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) { apply(ratingCell, ratingCell) } override function visitEmpty(ratingCell : RateTableCell) { apply(ratingCell, null) } override function visit(ratingRow : RateTableRow) { _currentRow = ratingRow _nullSeen = false // reset for each row } override function visit(bookModel : RateBookModel) {} private function validate(cellValue : RateTableCell) { if (cellValue.Value == null) { _nullSeen = true return } // if we are here, cellValue.Value != null if (_nullSeen) { addCellError(_currentRow, cellValue, RateTableErrorType.TC_VALUEAFTERNULL) } } private function apply(ratingCell : RateTableCell, cellValue : RateTableCell) { var ratingCellColumnDef = ratingCell.ColumnDefinition if (not _columnDefinitionIsParameterMap.get(ratingCellColumnDef)) { return } var ratingCellMatchOp = ratingCell.MatchOp var validator = ratingCellMatchOp.MatchOpDefinition.validator() // Range will explicitly match even with one null endpoint. In other words, // it is considered to contain data if one of the two columns is non-null, and // to be a relaxed matchop if both of them are null. if (validator typeis RangeMatchOpValidator) { var ratingCellMatchOpSortedParams = ratingCellMatchOp.sortedParams() // NOTE: like the range validator, we assume the min column will have lower priority than the max column if (ratingCellMatchOpSortedParams.first() == ratingCellColumnDef) { _minCell = cellValue } else if (ratingCellMatchOpSortedParams.last() == ratingCellColumnDef) { _maxCell = cellValue if (_minCell == null and _maxCell == null) { _nullSeen = true } else { if (_minCell != null) validate(_minCell) if (_maxCell != null) validate(_maxCell) } } } else { validate(cellValue) } } override function visitingEmptyCells() : boolean { return true } }