package gw.rating.flow.domain uses gw.lang.reflect.IType uses gw.lang.reflect.TypeSystem uses gw.rating.flow.util.QueryUtils uses gw.rating.flow.util.TypeMaps class RateTableSingleFactorLookupOperand extends RateTableLookupOperand { construct(code : String, opType : CalcStepOperatorType, factor : String, args : List, numLeft: int, numRight: int) { this(code, opType, factor, args, numLeft, numRight, null) } construct(code : String, opType : CalcStepOperatorType, factor : String, args : List, numLeft: int, numRight: int, aHighlightElement : RateRoutineHighlightElement) { super(code, opType, {factor}, args, numLeft, numRight) _highlightElement = aHighlightElement } override protected function generateValue(context: GenerationContext) { var patternCode = context.PatternCode var definition = QueryUtils.getRateTableDefinitionForCodeAndLine(TableCode, patternCode) if (definition == null) { throw new IllegalStateException("Could not find table ${TableCode}") } var targetFactorColName : String var rtCol : RateTableColumn // If explicit factor is targeted, grab the rate table column // from the rate table definition targetFactorColName = this.Factors.single() rtCol = definition.Factors.singleWhere(\f -> f.ColumnName == targetFactorColName) var factorType = rtCol.ColumnType.Code // Theoretically, we should always do the mapping from type string to rateflow type name. // But currently (3/13) that would map Integer -> BigDecimal, which is not correct. // Instead, we use the mapping simply to replace "Decimal" with BigDecimal. if (factorType == RateTableDataType.TC_DECIMAL.Code) { factorType = TypeMaps.typeStringToRateFlowTypeName(factorType) // There is no actual "Decimal" type } else { // else leave factorType alone except for making it the fully qualified name var factorTypeFullName = TypeSystem.getByRelativeName(factorType)?.Name if (factorTypeFullName != null) { factorType = factorTypeFullName } } var orderTable: Map = {} definition.SortedMatchOps.eachWithIndex(\op, i -> orderTable.put(op.Name, i)) if (context.WorksheetsEnabled) { context.append("gw.rating.RateRoutineExecutionLoggedRateQueryFactory.get<") } else { context.append("new gw.rating.flow.RateQuery<") } context.append(factorType) context.append(">(") if (context.WorksheetsEnabled) { context.append("_log, ") context.WorksheetHelper.generateRateQueryConstructor(this) } context.append(CalcRoutine.RATE_BOOK_SYMBOL).append(", \"") context.append(TableCode) context.append("\")") for (arg in _args.orderBy(\a -> orderTable.get(a.Parameter)) index i) { context.append(arg.genRateQueryParam(i)) } context.append(".getFactor(\"") context.append(targetFactorColName) context.append("\")") } override function getDataType(context: GenerationContext) : IType { var def = QueryUtils.getRateTableDefinitionForCodeAndLine(TableCode, context.PatternCode) var factorType = def.Factors.firstWhere(\ f -> f.ColumnName == _targetFactors.single()).ColumnType.Code if (factorType == RateTableDataType.TC_DECIMAL.Code) { return java.math.BigDecimal // always use BigDecimal for floating point numbers } else { // convert string to an IType var useMap = GosuShop.createTypeUsesMap({"java.math.BigDecimal"}) useMap.addToDefaultTypeUses("java.lang.*") useMap.addToTypeUses("java.util.Date") return TypeSystem.getByRelativeName(factorType, useMap) } } }