package gw.rating.rtm.valueprovider uses gw.api.locale.DisplayKey uses gw.api.productmodel.PolicyLinePattern uses gw.rating.rtm.domain.PersistenceAdapter uses gw.rating.rtm.domain.table.RateTableCell uses java.lang.IllegalArgumentException uses gw.rating.flow.util.InScopeUsage uses gw.rating.rtm.util.AvailableAttributePresenter uses gw.rating.flow.util.RatingEntityGraphTraverser uses gw.lang.reflect.IType uses gw.rating.flow.util.TypeMaps uses java.util.Set uses java.util.Map uses gw.entity.TypeKey uses java.util.List /** * Base abstract class for rate table cell value providers. *

* A value provider is used to provide a list of values for a column in a list * of factor rows of the rate table maintenance screen. The list contains codes * that are stored in the database. *

*

* A value provider may use an optional list of string arguments. *

*/ @ReadOnly abstract class RateTableCellValueProvider { /** * An array of optional string arguments. */ var _args : String[] as Arguments private var _columnDef : RateTableColumn as readonly ColumnDefinition /** * Creates a value provider for a specific rate table column. * @param column rate table column from rate table definition. */ construct(column : RateTableColumn) { if (column == null) { throw new IllegalArgumentException("Can't create a value provider for NULL column") } _columnDef = column } function getDependentValuesAsTypeKeys(dependencies : String[]) : List { return {} } function getDependentValues(dependencies : String[]) : Map { return {} } /** * @return map of value -> displayname */ abstract function getValueMap(args : String[]) : Map /** * Returns an array of string codes for a particular rate table row. * @param bean physical bean that stores rate table row (a set of rate * table parameters and factor(s). * @returns an array of string codes. */ abstract function getValues(adapter : PersistenceAdapter) : String[] /** * Returns a displayable string for a specific code value. * @param bean physical bean that stores rate table row (a set of rate * table parameters and factor(s). * @param code a string code, one of the codes returned by {@link #getValues getValues} method. * @returns a displayable string. */ abstract function valueByCode(adapter : PersistenceAdapter, code : String) : String /** * Checks if a list of codes contains the value of the rate table cell. * @param cell rate table cell wrapper. * @returns true, if list of codes contains cell value, false otherwise */ function containsCodeFor(cell : RateTableCell) : boolean { return getValues(cell.Adapter).toSet().containsAll(cell.ValueSet) } function convertCodeIdentifierToPublicID(str : String) : String { return str.Empty ? null : String.valueOf(str) } function convertPublicIDToCodeIdentifier(str : String) : String { return str } /** * Indicates if a value provider trully supports code/value pairs. * Should return false if codes and values are the same. */ property get HasCodedValue() : boolean { return true } protected function coveragePatternMatchesCoverageArgument(p : CalcRoutineParameter) : boolean { return (Arguments != null and Arguments.length > 0) ? Arguments[0] == p.CoveragePattern : false } function availableAttributes(line : PolicyLinePattern, paramSet : CalcRoutineParameterSet) : List { var usages = availableUsages(line, paramSet, TypeRestrictionForAvailableAttributes) var availAttributes = usages return availAttributes } protected property get TypeRestrictionForAvailableAttributes() : Set { return TypeMaps.rateTableColumnTypeToComparableTypes(ColumnDefinition.ColumnType).toSet() } protected function availableUsages(line : PolicyLinePattern, paramSet : CalcRoutineParameterSet, restrictToTypes : Set) : List { var regt : RatingEntityGraphTraverser var usages : List if (paramSet == null) { return {} } else { regt = new RatingEntityGraphTraverser(paramSet) var usagesMap = regt.getRestrictedTargetableElementsForParameter(paramSet, restrictToTypes) usages = usagesMap.Values.flatten().toList() } return usages.toTypedArray().map(\ u -> new AvailableAttributePresenter(u)).toList() } property get ArgumentsHelpText(): String { return DisplayKey.get("Web.Rating.RateTableDefinition.ValueProvider.HelpText.Default") } }