@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()); }
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; } }
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; } } }
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; } }  }
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); }
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);  }