package gw.rating.rtm.domain.migration
uses gw.api.locale.DisplayKey
uses gw.api.database.Query
uses gw.api.database.Relop
uses gw.entity.IEntityType
uses gw.rating.rtm.valueprovider.Parser
uses gw.rating.rtm.valueprovider.RateTableCellValueProviderFactory
uses gw.rating.rtm.valueprovider.UnboundValueProvider
uses gw.rating.rtm.domain.table.RateTableModel
uses gw.rating.rtm.domain.ErrorCollector
uses gw.rating.rtm.domain.table.RateTableRow
uses gw.rating.rtm.domain.table.RateTableCell
uses java.lang.Comparable
uses gw.rating.rtm.domain.RateTableRowError
uses java.lang.UnsupportedOperationException
uses gw.rating.rtm.valueprovider.ValueProviderVisitor
uses gw.rating.rtm.util.EmptyVisitor
uses java.util.List
/**
* Perform the following validation on a RateTable:
*
RateTableDefinition for the imported RateTable is not conflicting
* with an existing RateTableDefinitionRateTable
*
* @param RateTable entity to validate
*
* @return true if the RateTable is valid; false otherwise
*/
override function valid(table : RateTable) : boolean {
validateOwnedTableExistsFor(table)
validateDefinitionFor(table)
// These validations are not trustworthy unless the others above succeeded.
if (table.TableOwningFactors == table and ValidationErrors.Empty) {
validateRowsFor(table)
}
return ValidationErrors.Empty
}
private function validateDefinitionFor(table : RateTable) {
_rateTableDefValidator.valid(table.Definition)
_validationErrors.addAll(_rateTableDefValidator.ValidationErrors)
_validationWarnings.addAll(_rateTableDefValidator.ValidationWarnings)
}
private function validateOwnedTableExistsFor(table : RateTable) {
var found : boolean = true
if (table.Reference) {
found = Query.make(RateTable).compare(RateTable#PublicID, Relop.Equals, table.RefTable.PublicID).select().HasElements
if (!found) {
addError(DisplayKey.get("Web.Rating.Errors.ReferenceTableMissing",
"'${table.RateBook.BookCode}'", "'${table.Definition.TableCode}'"))
}
}
}
// Do second-stage validation on the contents of the table, leveraging the validators
// that were originally developed for use in the GUI and Excel import.
private function validateRowsFor(table : RateTable) {
var tableModel = new RateTableModel(table, new RateTableCellValueProviderFactory())
var collector = new LocalCollector()
var beans = table.NewRowsFromBundle
// now we can add the bundle-local beans to the model.
beans.each(\ f -> tableModel.addFactorRow(f))
// finally, perform the ValueProvider validation also. RateTableValidator does not normally need to
// run this one (because in the GUI you can't generate bad data) but it is run on Excel import.
// We also want to run it on XML import in case the systems are out of sync.
tableModel.accept(new ValueProviderVisitor(collector, tableModel.ValueProviderRepository, new EmptyVisitor()))
}
// error collector for use by RateTableValidator and ValueProviderVisitor.
// It delegates addRowError and addCellError to the addError method on this validator
// and does a simple implementation of getErrorCount(). Other methods are unimplemented.
class LocalCollector implements ErrorCollector {
var count = 0
override function getErrorCount() : int {
return count
}
override function addRowError(row : RateTableRow, errorType : RateTableErrorType) {
count++
addError(DisplayKey.get("Web.Rating.Errors.RowErrorMessage", errorType.DisplayName))
}
override function addCellError(row : RateTableRow, cell : RateTableCell