GuidedDTDRLPersistence { void doConditions(List<BaseColumn> allColumns, List<CompositeColumn<? extends BaseColumn>> conditionPatterns, TemplateDataProvider rowDataProvider, List<DTCellValue52> row, List<List<DTCellValue52>> data, RuleModel rm) { List<IPattern> patterns = new ArrayList<IPattern>(); for (CompositeColumn<?> cc : conditionPatterns) { if (cc instanceof LimitedEntryBRLConditionColumn) { doCondition(allColumns, (LimitedEntryBRLConditionColumn) cc, patterns, rowDataProvider, row, rm); } else if (cc instanceof BRLConditionColumn) { doCondition(allColumns, (BRLConditionColumn) cc, patterns, rowDataProvider, row, rm); } else if (cc instanceof Pattern52) { doCondition(allColumns, (Pattern52) cc, patterns, row, data, rm); } } rm.lhs = patterns.toArray(new IPattern[patterns.size()]); }  static GuidedDTDRLPersistence getInstance(); String marshal(final GuidedDecisionTable52 originalDTable);  }
@Test public void testLHS() { GuidedDTDRLPersistence p = new GuidedDTDRLPersistence(); String[] row = new String[]{"1", "desc", "a", "mike", "33 + 1", "age > 6", "stilton"}; String[][] data = new String[1][]; data[0] = row; List<BaseColumn> allColumns = new ArrayList<BaseColumn>(); List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<CompositeColumn<? extends BaseColumn>>(); allColumns.add(new RowNumberCol52()); allColumns.add(new DescriptionCol52()); allColumns.add(new MetadataCol52()); Pattern52 p1 = new Pattern52(); p1.setBoundName("p1"); p1.setFactType("Person"); allPatterns.add(p1); ConditionCol52 col = new ConditionCol52(); col.setFactField("name"); col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL); col.setOperator("=="); p1.getChildColumns().add(col); allColumns.add(col); ConditionCol52 col2 = new ConditionCol52(); col2.setFactField("age"); col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_RET_VALUE); col2.setOperator("<"); p1.getChildColumns().add(col2); allColumns.add(col2); ConditionCol52 col3 = new ConditionCol52(); col3.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE); p1.getChildColumns().add(col3); allColumns.add(col3); Pattern52 p2 = new Pattern52(); p2.setBoundName("c"); p2.setFactType("Cheese"); allPatterns.add(p2); ConditionCol52 col4 = new ConditionCol52(); col4.setFactField("type"); col4.setOperator("=="); col4.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL); p2.getChildColumns().add(col4); allColumns.add(col4); RuleModel rm = new RuleModel(); List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row); TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData); p.doConditions(allColumns, allPatterns, rowDataProvider, rowData, DataUtilities.makeDataLists(data), rm); assertEquals(2, rm.lhs.length); assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType()); assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName()); assertEquals("Cheese", ((FactPattern) rm.lhs[1]).getFactType()); assertEquals("c", ((FactPattern) rm.lhs[1]).getBoundName()); FactPattern person = (FactPattern) rm.lhs[0]; assertEquals(3, person.getConstraintList().getConstraints().length); SingleFieldConstraint cons = (SingleFieldConstraint) person.getConstraint(0); assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cons.getConstraintValueType()); assertEquals("name", cons.getFieldName()); assertEquals("==", cons.getOperator()); assertEquals("mike", cons.getValue()); cons = (SingleFieldConstraint) person.getConstraint(1); assertEquals(BaseSingleFieldConstraint.TYPE_RET_VALUE, cons.getConstraintValueType()); assertEquals("age", cons.getFieldName()); assertEquals("<", cons.getOperator()); assertEquals("33 + 1", cons.getValue()); cons = (SingleFieldConstraint) person.getConstraint(2); assertEquals(BaseSingleFieldConstraint.TYPE_PREDICATE, cons.getConstraintValueType()); assertEquals("age > 6", cons.getValue()); FactPattern cheese = (FactPattern) rm.lhs[1]; assertEquals(1, cheese.getConstraintList().getConstraints().length); cons = (SingleFieldConstraint) cheese.getConstraint(0); assertEquals("type", cons.getFieldName()); assertEquals("==", cons.getOperator()); assertEquals("stilton", cons.getValue()); assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cons.getConstraintValueType()); }
@Test public void testLHSBindings() { GuidedDTDRLPersistence p = new GuidedDTDRLPersistence(); String[] row = new String[]{"1", "desc", "mike", "33 + 1", "age > 6"}; String[][] data = new String[1][]; data[0] = row; List<BaseColumn> allColumns = new ArrayList<BaseColumn>(); List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<CompositeColumn<? extends BaseColumn>>(); allColumns.add(new RowNumberCol52()); allColumns.add(new DescriptionCol52()); Pattern52 p1 = new Pattern52(); p1.setBoundName("p1"); p1.setFactType("Person"); allPatterns.add(p1); ConditionCol52 col = new ConditionCol52(); col.setFactField("name"); col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL); col.setOperator("=="); col.setBinding("$name"); p1.getChildColumns().add(col); allColumns.add(col); ConditionCol52 col2 = new ConditionCol52(); col2.setFactField("age"); col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_RET_VALUE); col2.setOperator("<"); col2.setBinding("$age"); p1.getChildColumns().add(col2); allColumns.add(col2); ConditionCol52 col3 = new ConditionCol52(); col3.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE); col3.setBinding("$name"); p1.getChildColumns().add(col3); allColumns.add(col3); List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row); TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData); RuleModel rm = new RuleModel(); p.doConditions(allColumns, allPatterns, rowDataProvider, rowData, DataUtilities.makeDataLists(data), rm); assertEquals(1, rm.lhs.length); assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType()); assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName()); FactPattern person = (FactPattern) rm.lhs[0]; assertEquals(3, person.getConstraintList().getConstraints().length); SingleFieldConstraint cons = (SingleFieldConstraint) person.getConstraint(0); assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cons.getConstraintValueType()); assertEquals("name", cons.getFieldName()); assertEquals("==", cons.getOperator()); assertEquals("mike", cons.getValue()); assertEquals("$name", cons.getFieldBinding()); cons = (SingleFieldConstraint) person.getConstraint(1); assertEquals(BaseSingleFieldConstraint.TYPE_RET_VALUE, cons.getConstraintValueType()); assertEquals("age", cons.getFieldName()); assertEquals("<", cons.getOperator()); assertEquals("33 + 1", cons.getValue()); assertEquals("$age", cons.getFieldBinding()); cons = (SingleFieldConstraint) person.getConstraint(2); assertEquals(BaseSingleFieldConstraint.TYPE_PREDICATE, cons.getConstraintValueType()); assertEquals("age > 6", cons.getValue()); assertNull(cons.getFieldBinding()); }
@Test public void testLHSWithBRLColumn_ParseToRuleModel() { GuidedDecisionTable52 dtable = new GuidedDecisionTable52(); GuidedDTDRLPersistence p = new GuidedDTDRLPersistence(); String[][] data = new String[][]{ new String[]{"1", "", "desc", "Gargamel", "Pupa", "50"}, new String[]{"2", "", "desc", "Gargamel", "", "50"}, new String[]{"3", "", "desc", "Gargamel", "Pupa", ""} }; dtable.setRowNumberCol(new RowNumberCol52()); dtable.setDescriptionCol(new DescriptionCol52()); Pattern52 p1 = new Pattern52(); p1.setFactType("Baddie"); ConditionCol52 con = new ConditionCol52(); con.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL); con.setFactField("name"); con.setOperator("=="); p1.getChildColumns().add(con); dtable.getConditions().add(p1); BRLConditionColumn brl1 = new BRLConditionColumn(); List<IPattern> brl1Definition = new ArrayList<IPattern>(); FactPattern brl1DefinitionFactPattern1 = new FactPattern("Smurf"); SingleFieldConstraint brl1DefinitionFactPattern1Constraint1 = new SingleFieldConstraint(); brl1DefinitionFactPattern1Constraint1.setFieldType(DataType.TYPE_STRING); brl1DefinitionFactPattern1Constraint1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE); brl1DefinitionFactPattern1Constraint1.setFieldName("name"); brl1DefinitionFactPattern1Constraint1.setOperator("=="); brl1DefinitionFactPattern1Constraint1.setValue("$name"); brl1DefinitionFactPattern1.addConstraint(brl1DefinitionFactPattern1Constraint1); SingleFieldConstraint brl1DefinitionFactPattern1Constraint2 = new SingleFieldConstraint(); brl1DefinitionFactPattern1Constraint2.setFieldType(DataType.TYPE_NUMERIC_INTEGER); brl1DefinitionFactPattern1Constraint2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE); brl1DefinitionFactPattern1Constraint2.setFieldName("age"); brl1DefinitionFactPattern1Constraint2.setOperator("=="); brl1DefinitionFactPattern1Constraint2.setValue("$age"); brl1DefinitionFactPattern1.addConstraint(brl1DefinitionFactPattern1Constraint2); brl1Definition.add(brl1DefinitionFactPattern1); brl1.setDefinition(brl1Definition); BRLConditionVariableColumn brl1Variable1 = new BRLConditionVariableColumn("$name", DataType.TYPE_STRING, "Person", "name"); brl1.getChildColumns().add(brl1Variable1); BRLConditionVariableColumn brl1Variable2 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Person", "age"); brl1.getChildColumns().add(brl1Variable2); dtable.getConditions().add(brl1); RuleModel rm = new RuleModel(); List<BaseColumn> allColumns = dtable.getExpandedColumns(); List<CompositeColumn<? extends BaseColumn>> allPatterns = dtable.getConditions(); List<List<DTCellValue52>> dtData = DataUtilities.makeDataLists(data); List<DTCellValue52> dtRowData0 = DataUtilities.makeDataRowList(data[0]); TemplateDataProvider rowDataProvider0 = new GuidedDTTemplateDataProvider(allColumns, dtRowData0); p.doConditions(allColumns, allPatterns, rowDataProvider0, dtRowData0, dtData, rm); assertEquals(2, rm.lhs.length); assertEquals("Baddie", ((FactPattern) rm.lhs[0]).getFactType()); assertEquals("Smurf", ((FactPattern) rm.lhs[1]).getFactType()); FactPattern result0Fp1 = (FactPattern) rm.lhs[0]; assertEquals(1, result0Fp1.getConstraintList().getConstraints().length); SingleFieldConstraint result0Fp1Con1 = (SingleFieldConstraint) result0Fp1.getConstraint(0); assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, result0Fp1Con1.getConstraintValueType()); assertEquals("name", result0Fp1Con1.getFieldName()); assertEquals("==", result0Fp1Con1.getOperator()); assertEquals("Gargamel", result0Fp1Con1.getValue()); FactPattern result0Fp2 = (FactPattern) rm.lhs[1]; assertEquals(2, result0Fp2.getConstraintList().getConstraints().length); SingleFieldConstraint result0Fp2Con1 = (SingleFieldConstraint) result0Fp2.getConstraint(0); assertEquals(BaseSingleFieldConstraint.TYPE_TEMPLATE, result0Fp2Con1.getConstraintValueType()); assertEquals("name", result0Fp2Con1.getFieldName()); assertEquals("==", result0Fp2Con1.getOperator()); assertEquals("$name", result0Fp2Con1.getValue()); SingleFieldConstraint result0Fp2Con2 = (SingleFieldConstraint) result0Fp2.getConstraint(1); assertEquals(BaseSingleFieldConstraint.TYPE_TEMPLATE, result0Fp2Con2.getConstraintValueType()); assertEquals("age", result0Fp2Con2.getFieldName()); assertEquals("==", result0Fp2Con2.getOperator()); assertEquals("$age", result0Fp2Con2.getValue()); List<DTCellValue52> dtRowData1 = DataUtilities.makeDataRowList(data[1]); TemplateDataProvider rowDataProvider1 = new GuidedDTTemplateDataProvider(allColumns, dtRowData1); p.doConditions(allColumns, allPatterns, rowDataProvider1, dtRowData1, dtData, rm); assertEquals(2, rm.lhs.length); assertEquals("Baddie", ((FactPattern) rm.lhs[0]).getFactType()); FactPattern result1Fp1 = (FactPattern) rm.lhs[0]; assertEquals(1, result1Fp1.getConstraintList().getConstraints().length); SingleFieldConstraint result1Fp1Con1 = (SingleFieldConstraint) result1Fp1.getConstraint(0); assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, result1Fp1Con1.getConstraintValueType()); assertEquals("name", result1Fp1Con1.getFieldName()); assertEquals("==", result1Fp1Con1.getOperator()); assertEquals("Gargamel", result1Fp1Con1.getValue()); FactPattern result1Fp2 = (FactPattern) rm.lhs[1]; assertEquals(2, result1Fp2.getConstraintList().getConstraints().length); SingleFieldConstraint result1Fp2Con1 = (SingleFieldConstraint) result1Fp2.getConstraint(0); assertEquals(BaseSingleFieldConstraint.TYPE_TEMPLATE, result1Fp2Con1.getConstraintValueType()); assertEquals("name", result1Fp2Con1.getFieldName()); assertEquals("==", result1Fp2Con1.getOperator()); assertEquals("$name", result1Fp2Con1.getValue()); SingleFieldConstraint result1Fp2Con2 = (SingleFieldConstraint) result1Fp2.getConstraint(1); assertEquals(BaseSingleFieldConstraint.TYPE_TEMPLATE, result1Fp2Con2.getConstraintValueType()); assertEquals("age", result1Fp2Con2.getFieldName()); assertEquals("==", result1Fp2Con2.getOperator()); assertEquals("$age", result1Fp2Con2.getValue()); List<DTCellValue52> dtRowData2 = DataUtilities.makeDataRowList(data[2]); TemplateDataProvider rowDataProvider2 = new GuidedDTTemplateDataProvider(allColumns, dtRowData2); p.doConditions(allColumns, allPatterns, rowDataProvider2, dtRowData2, dtData, rm); assertEquals(2, rm.lhs.length); assertEquals("Baddie", ((FactPattern) rm.lhs[0]).getFactType()); FactPattern result2Fp1 = (FactPattern) rm.lhs[0]; assertEquals(1, result2Fp1.getConstraintList().getConstraints().length); SingleFieldConstraint result2Fp1Con1 = (SingleFieldConstraint) result2Fp1.getConstraint(0); assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, result2Fp1Con1.getConstraintValueType()); assertEquals("name", result2Fp1Con1.getFieldName()); assertEquals("==", result2Fp1Con1.getOperator()); assertEquals("Gargamel", result2Fp1Con1.getValue()); FactPattern result2Fp2 = (FactPattern) rm.lhs[1]; assertEquals(2, result2Fp2.getConstraintList().getConstraints().length); SingleFieldConstraint result2Fp2Con1 = (SingleFieldConstraint) result2Fp2.getConstraint(0); assertEquals(BaseSingleFieldConstraint.TYPE_TEMPLATE, result2Fp2Con1.getConstraintValueType()); assertEquals("name", result2Fp2Con1.getFieldName()); assertEquals("==", result2Fp2Con1.getOperator()); assertEquals("$name", result2Fp2Con1.getValue()); SingleFieldConstraint result2Fp2Con2 = (SingleFieldConstraint) result2Fp2.getConstraint(1); assertEquals(BaseSingleFieldConstraint.TYPE_TEMPLATE, result2Fp2Con2.getConstraintValueType()); assertEquals("age", result2Fp2Con2.getFieldName()); assertEquals("==", result2Fp2Con2.getOperator()); assertEquals("$age", result2Fp2Con2.getValue()); }