GuidedDTDRLPersistence { void doActions(List<BaseColumn> allColumns, List<ActionCol52> actionCols, TemplateDataProvider rowDataProvider, List<DTCellValue52> row, RuleModel rm) { List<LabelledAction> actions = new ArrayList<LabelledAction>(); for (ActionCol52 c : actionCols) { if (c instanceof LimitedEntryBRLActionColumn) { doAction(allColumns, (LimitedEntryBRLActionColumn) c, actions, rowDataProvider, row, rm); } else if (c instanceof BRLActionColumn) { doAction(allColumns, (BRLActionColumn) c, actions, rowDataProvider, row, rm); } else { int index = allColumns.indexOf(c); DTCellValue52 dcv = row.get(index); String cell = ""; if (c instanceof LimitedEntryCol) { if (dcv.getBooleanValue() == true) { LimitedEntryCol lec = (LimitedEntryCol) c; cell = GuidedDTDRLUtilities.convertDTCellValueToString(lec.getValue()); } } else { cell = GuidedDTDRLUtilities.convertDTCellValueToString(dcv); } if (validCell(cell, dcv.getDataType())) { if (c instanceof ActionWorkItemInsertFactCol52) { doAction(actions, (ActionWorkItemInsertFactCol52) c, cell); } else if (c instanceof ActionInsertFactCol52) { doAction(actions, (ActionInsertFactCol52) c, cell); } else if (c instanceof ActionWorkItemSetFieldCol52) { doAction(actions, (ActionWorkItemSetFieldCol52) c, cell); } else if (c instanceof ActionSetFieldCol52) { doAction(actions, (ActionSetFieldCol52) c, cell); } else if (c instanceof ActionRetractFactCol52) { doAction(actions, cell); } else if (c instanceof ActionWorkItemCol52) { doAction(actions, (ActionWorkItemCol52) c, cell); } } } } rm.rhs = new IAction[actions.size()]; for (int i = 0; i < rm.rhs.length; i++) { rm.rhs[i] = actions.get(i).action; } }  static GuidedDTDRLPersistence getInstance(); String marshal(final GuidedDecisionTable52 originalDTable);  }
@Test public void testRHS() { GuidedDTDRLPersistence p = new GuidedDTDRLPersistence(); String[] row = new String[]{"1", "desc", "a", "a condition", "actionsetfield1", "actionupdatefield2", "retract", "actioninsertfact1", "actioninsertfact2"}; List<BaseColumn> allColumns = new ArrayList<BaseColumn>(); allColumns.add(new RowNumberCol52()); allColumns.add(new DescriptionCol52()); allColumns.add(new MetadataCol52()); allColumns.add(new ConditionCol52()); List<ActionCol52> cols = new ArrayList<ActionCol52>(); ActionSetFieldCol52 asf1 = new ActionSetFieldCol52(); asf1.setBoundName("a"); asf1.setFactField("field1"); asf1.setType(DataType.TYPE_STRING); cols.add(asf1); ActionSetFieldCol52 asf2 = new ActionSetFieldCol52(); asf2.setBoundName("a"); asf2.setFactField("field2"); asf2.setUpdate(true); asf2.setType(DataType.TYPE_NUMERIC_INTEGER); cols.add(asf2); ActionRetractFactCol52 ret = new ActionRetractFactCol52(); cols.add(ret); ActionInsertFactCol52 ins1 = new ActionInsertFactCol52(); ins1.setBoundName("ins"); ins1.setFactType("Cheese"); ins1.setFactField("price"); ins1.setType(DataType.TYPE_NUMERIC_INTEGER); cols.add(ins1); ActionInsertFactCol52 ins2 = new ActionInsertFactCol52(); ins2.setBoundName("ins"); ins2.setFactType("Cheese"); ins2.setFactField("type"); ins2.setType(DataType.TYPE_NUMERIC_INTEGER); cols.add(ins2); RuleModel rm = new RuleModel(); allColumns.addAll(cols); List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row); TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData); p.doActions(allColumns, cols, rowDataProvider, rowData, rm); assertEquals(4, rm.rhs.length); ActionSetField a1 = (ActionSetField) rm.rhs[0]; assertEquals("a", a1.getVariable()); assertEquals(1, a1.getFieldValues().length); assertEquals("field1", a1.getFieldValues()[0].getField()); assertEquals("actionsetfield1", a1.getFieldValues()[0].getValue()); assertEquals(DataType.TYPE_STRING, a1.getFieldValues()[0].getType()); ActionSetField a2 = (ActionSetField) rm.rhs[1]; assertEquals("a", a2.getVariable()); assertEquals(1, a2.getFieldValues().length); assertEquals("field2", a2.getFieldValues()[0].getField()); assertEquals("actionupdatefield2", a2.getFieldValues()[0].getValue()); assertEquals(DataType.TYPE_NUMERIC_INTEGER, a2.getFieldValues()[0].getType()); ActionRetractFact a3 = (ActionRetractFact) rm.rhs[2]; assertEquals("retract", a3.getVariableName()); ActionInsertFact a4 = (ActionInsertFact) rm.rhs[3]; assertEquals("Cheese", a4.getFactType()); assertEquals(2, a4.getFieldValues().length); assertEquals("price", a4.getFieldValues()[0].getField()); assertEquals("actioninsertfact1", a4.getFieldValues()[0].getValue()); assertEquals(DataType.TYPE_NUMERIC_INTEGER, a4.getFieldValues()[0].getType()); assertEquals("type", a4.getFieldValues()[1].getField()); assertEquals("actioninsertfact2", a4.getFieldValues()[1].getValue()); assertEquals(DataType.TYPE_NUMERIC_INTEGER, a4.getFieldValues()[1].getType()); }
@Test public void testRHSExecuteWorkItem() { GuidedDTDRLPersistence p = new GuidedDTDRLPersistence(); String[] row = new String[]{"1", "desc", "true"}; List<BaseColumn> allColumns = new ArrayList<BaseColumn>(); allColumns.add(new RowNumberCol52()); allColumns.add(new DescriptionCol52()); List<ActionCol52> cols = new ArrayList<ActionCol52>(); ActionWorkItemCol52 awi = new ActionWorkItemCol52(); PortableWorkDefinition pwd = new PortableWorkDefinition(); pwd.setName("work-item"); awi.setWorkItemDefinition(pwd); PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition(); p1.setName("BooleanParameter"); p1.setValue(Boolean.TRUE); pwd.addParameter(p1); PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition(); p2.setName("FloatParameter"); p2.setValue(123.456f); pwd.addParameter(p2); PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition(); p3.setName("IntegerParameter"); p3.setValue(123); pwd.addParameter(p3); PortableStringParameterDefinition p4 = new PortableStringParameterDefinition(); p4.setName("StringParameter"); p4.setValue("hello"); pwd.addParameter(p4); cols.add(awi); RuleModel rm = new RuleModel(); allColumns.addAll(cols); List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row); TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData); p.doActions(allColumns, cols, rowDataProvider, rowData, rm); assertEquals(1, rm.rhs.length); ActionExecuteWorkItem aw = (ActionExecuteWorkItem) rm.rhs[0]; assertNotNull(aw); PortableWorkDefinition mpwd = aw.getWorkDefinition(); assertNotNull(mpwd); assertEquals(4, mpwd.getParameters().size()); PortableBooleanParameterDefinition mp1 = (PortableBooleanParameterDefinition) mpwd.getParameter("BooleanParameter"); assertNotNull(mp1); assertEquals(Boolean.TRUE, mp1.getValue()); PortableFloatParameterDefinition mp2 = (PortableFloatParameterDefinition) mpwd.getParameter("FloatParameter"); assertNotNull(mp2); assertEquals(new Float(123.456f), mp2.getValue()); PortableIntegerParameterDefinition mp3 = (PortableIntegerParameterDefinition) mpwd.getParameter("IntegerParameter"); assertNotNull(mp3); assertEquals(new Integer(123), mp3.getValue()); PortableStringParameterDefinition mp4 = (PortableStringParameterDefinition) mpwd.getParameter("StringParameter"); assertNotNull(mp4); assertEquals("hello", mp4.getValue()); }
@Test public void testRHSExecuteWorkItemWithBindings() { GuidedDTDRLPersistence p = new GuidedDTDRLPersistence(); String[] row = new String[]{"1", "desc", "true"}; List<BaseColumn> allColumns = new ArrayList<BaseColumn>(); allColumns.add(new RowNumberCol52()); allColumns.add(new DescriptionCol52()); List<ActionCol52> cols = new ArrayList<ActionCol52>(); ActionWorkItemCol52 awi = new ActionWorkItemCol52(); PortableWorkDefinition pwd = new PortableWorkDefinition(); pwd.setName("work-item"); awi.setWorkItemDefinition(pwd); PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition(); p1.setName("BooleanParameter"); p1.setValue(Boolean.TRUE); p1.setBinding("$b"); pwd.addParameter(p1); PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition(); p2.setName("FloatParameter"); p2.setValue(123.456f); p2.setBinding("$f"); pwd.addParameter(p2); PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition(); p3.setName("IntegerParameter"); p3.setValue(123); p3.setBinding("$i"); pwd.addParameter(p3); PortableStringParameterDefinition p4 = new PortableStringParameterDefinition(); p4.setName("StringParameter"); p4.setValue("hello"); p4.setBinding("$s"); pwd.addParameter(p4); cols.add(awi); RuleModel rm = new RuleModel(); allColumns.addAll(cols); List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row); TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData); p.doActions(allColumns, cols, rowDataProvider, rowData, rm); assertEquals(1, rm.rhs.length); ActionExecuteWorkItem aw = (ActionExecuteWorkItem) rm.rhs[0]; assertNotNull(aw); PortableWorkDefinition mpwd = aw.getWorkDefinition(); assertNotNull(mpwd); assertEquals(4, mpwd.getParameters().size()); PortableBooleanParameterDefinition mp1 = (PortableBooleanParameterDefinition) mpwd.getParameter("BooleanParameter"); assertNotNull(mp1); assertEquals(Boolean.TRUE, mp1.getValue()); assertEquals("$b", mp1.getBinding()); PortableFloatParameterDefinition mp2 = (PortableFloatParameterDefinition) mpwd.getParameter("FloatParameter"); assertNotNull(mp2); assertEquals(new Float(123.456f), mp2.getValue()); assertEquals("$f", mp2.getBinding()); PortableIntegerParameterDefinition mp3 = (PortableIntegerParameterDefinition) mpwd.getParameter("IntegerParameter"); assertNotNull(mp3); assertEquals(new Integer(123), mp3.getValue()); assertEquals("$i", mp3.getBinding()); PortableStringParameterDefinition mp4 = (PortableStringParameterDefinition) mpwd.getParameter("StringParameter"); assertNotNull(mp4); assertEquals("hello", mp4.getValue()); assertEquals("$s", mp4.getBinding()); }
@Test public void testRHSWithBRLColumn_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()); ActionInsertFactCol52 a1 = new ActionInsertFactCol52(); a1.setBoundName("$b"); a1.setFactType("Baddie"); a1.setFactField("name"); a1.setType(DataType.TYPE_STRING); dtable.getActionCols().add(a1); BRLActionColumn brl1 = new BRLActionColumn(); List<IAction> brl1Definition = new ArrayList<IAction>(); ActionInsertFact brl1DefinitionAction1 = new ActionInsertFact("Smurf"); ActionFieldValue brl1DefinitionAction1FieldValue1 = new ActionFieldValue("name", "$name", DataType.TYPE_STRING); brl1DefinitionAction1FieldValue1.setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE); brl1DefinitionAction1.addFieldValue(brl1DefinitionAction1FieldValue1); ActionFieldValue brl1DefinitionAction1FieldValue2 = new ActionFieldValue("age", "$age", DataType.TYPE_NUMERIC_INTEGER); brl1DefinitionAction1FieldValue2.setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE); brl1DefinitionAction1.addFieldValue(brl1DefinitionAction1FieldValue2); brl1Definition.add(brl1DefinitionAction1); brl1.setDefinition(brl1Definition); BRLActionVariableColumn brl1Variable1 = new BRLActionVariableColumn("$name", DataType.TYPE_STRING, "Person", "name"); brl1.getChildColumns().add(brl1Variable1); BRLActionVariableColumn brl1Variable2 = new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Person", "age"); brl1.getChildColumns().add(brl1Variable2); dtable.getActionCols().add(brl1); RuleModel rm = new RuleModel(); List<BaseColumn> allColumns = dtable.getExpandedColumns(); List<ActionCol52> allActions = dtable.getActionCols(); List<DTCellValue52> dtRowData0 = DataUtilities.makeDataRowList(data[0]); TemplateDataProvider rowDataProvider0 = new GuidedDTTemplateDataProvider(allColumns, dtRowData0); p.doActions(allColumns, allActions, rowDataProvider0, dtRowData0, rm); assertEquals(2, rm.rhs.length); assertEquals("Baddie", ((ActionInsertFact) rm.rhs[0]).getFactType()); assertEquals("Smurf", ((ActionInsertFact) rm.rhs[1]).getFactType()); ActionInsertFact result0Action1 = (ActionInsertFact) rm.rhs[0]; assertEquals(1, result0Action1.getFieldValues().length); ActionFieldValue result0Action1FieldValue1 = (ActionFieldValue) result0Action1.getFieldValues()[0]; assertEquals(DataType.TYPE_STRING, result0Action1FieldValue1.getType()); assertEquals("name", result0Action1FieldValue1.getField()); assertEquals("Gargamel", result0Action1FieldValue1.getValue()); ActionInsertFact result0Action2 = (ActionInsertFact) rm.rhs[1]; assertEquals(2, result0Action2.getFieldValues().length); ActionFieldValue result0Action2FieldValue1 = (ActionFieldValue) result0Action2.getFieldValues()[0]; assertEquals(DataType.TYPE_STRING, result0Action2FieldValue1.getType()); assertEquals("name", result0Action2FieldValue1.getField()); assertEquals("$name", result0Action2FieldValue1.getValue()); ActionFieldValue result0Action2FieldValue2 = (ActionFieldValue) result0Action2.getFieldValues()[1]; assertEquals(DataType.TYPE_NUMERIC_INTEGER, result0Action2FieldValue2.getType()); assertEquals("age", result0Action2FieldValue2.getField()); assertEquals("$age", result0Action2FieldValue2.getValue()); List<DTCellValue52> dtRowData1 = DataUtilities.makeDataRowList(data[1]); TemplateDataProvider rowDataProvider1 = new GuidedDTTemplateDataProvider(allColumns, dtRowData1); p.doActions(allColumns, allActions, rowDataProvider1, dtRowData1, rm); assertEquals(2, rm.rhs.length); assertEquals("Baddie", ((ActionInsertFact) rm.rhs[0]).getFactType()); assertEquals("Smurf", ((ActionInsertFact) rm.rhs[1]).getFactType()); ActionInsertFact result1Action1 = (ActionInsertFact) rm.rhs[0]; assertEquals(1, result1Action1.getFieldValues().length); ActionFieldValue result1Action1FieldValue1 = (ActionFieldValue) result1Action1.getFieldValues()[0]; assertEquals(DataType.TYPE_STRING, result1Action1FieldValue1.getType()); assertEquals("name", result1Action1FieldValue1.getField()); assertEquals("Gargamel", result1Action1FieldValue1.getValue()); ActionInsertFact result1Action2 = (ActionInsertFact) rm.rhs[1]; assertEquals(2, result1Action2.getFieldValues().length); ActionFieldValue result1Action2FieldValue1 = (ActionFieldValue) result1Action2.getFieldValues()[0]; assertEquals(DataType.TYPE_STRING, result1Action2FieldValue1.getType()); assertEquals("name", result1Action2FieldValue1.getField()); assertEquals("$name", result1Action2FieldValue1.getValue()); ActionFieldValue result1Action2FieldValue2 = (ActionFieldValue) result1Action2.getFieldValues()[1]; assertEquals(DataType.TYPE_NUMERIC_INTEGER, result1Action2FieldValue2.getType()); assertEquals("age", result1Action2FieldValue2.getField()); assertEquals("$age", result1Action2FieldValue2.getValue()); List<DTCellValue52> dtRowData2 = DataUtilities.makeDataRowList(data[2]); TemplateDataProvider rowDataProvider2 = new GuidedDTTemplateDataProvider(allColumns, dtRowData2); p.doActions(allColumns, allActions, rowDataProvider2, dtRowData2, rm); assertEquals(2, rm.rhs.length); assertEquals("Baddie", ((ActionInsertFact) rm.rhs[0]).getFactType()); assertEquals("Smurf", ((ActionInsertFact) rm.rhs[1]).getFactType()); ActionInsertFact result2Action1 = (ActionInsertFact) rm.rhs[0]; assertEquals(1, result2Action1.getFieldValues().length); ActionFieldValue result2Action1FieldValue1 = (ActionFieldValue) result2Action1.getFieldValues()[0]; assertEquals(DataType.TYPE_STRING, result2Action1FieldValue1.getType()); assertEquals("name", result2Action1FieldValue1.getField()); assertEquals("Gargamel", result2Action1FieldValue1.getValue()); ActionInsertFact result2Action2 = (ActionInsertFact) rm.rhs[1]; assertEquals(2, result2Action2.getFieldValues().length); ActionFieldValue result2Action2FieldValue1 = (ActionFieldValue) result2Action2.getFieldValues()[0]; assertEquals(DataType.TYPE_STRING, result2Action2FieldValue1.getType()); assertEquals("name", result2Action2FieldValue1.getField()); assertEquals("$name", result2Action2FieldValue1.getValue()); ActionFieldValue result3Action2FieldValue2 = (ActionFieldValue) result2Action2.getFieldValues()[1]; assertEquals(DataType.TYPE_NUMERIC_INTEGER, result3Action2FieldValue2.getType()); assertEquals("age", result3Action2FieldValue2.getField()); assertEquals("$age", result3Action2FieldValue2.getValue()); }