DefaultGuidedDecisionTableLinkManager implements GuidedDecisionTableLinkManager { @Override public void link(final GuidedDecisionTable52 model, final GuidedDecisionTable52 otherModel, final LinkFoundCallback callback) { if (model == null) { return; } if (otherModel == null) { return; } if (callback == null) { return; } final BRLRuleModel helper = new BRLRuleModel(model); for (CompositeColumn<? extends BaseColumn> otherDecisionTableConditions : otherModel.getConditions()) { if (otherDecisionTableConditions instanceof Pattern52) { final Pattern52 otherDecisionTablePattern = (Pattern52) otherDecisionTableConditions; for (ConditionCol52 otherDecisionTableCondition : otherDecisionTablePattern.getChildColumns()) { final String factType = otherDecisionTablePattern.getFactType(); final String fieldName = otherDecisionTableCondition.getFactField(); final ActionCol52 linkedActionColumn = getLinkedActionColumn(factType, fieldName, model, helper); if (linkedActionColumn != null) { final int sourceColumnIndex = model.getExpandedColumns().indexOf(linkedActionColumn); final int targetColumnIndex = otherModel.getExpandedColumns().indexOf(otherDecisionTableCondition); callback.link(sourceColumnIndex, targetColumnIndex); } } } else if (otherDecisionTableConditions instanceof BRLConditionColumn) { final BRLConditionColumn fragment = (BRLConditionColumn) otherDecisionTableConditions; for (BRLConditionVariableColumn var : fragment.getChildColumns()) { final String factType = var.getFactType(); final String fieldName = var.getFactField(); final ActionCol52 linkedActionColumn = getLinkedActionColumn(factType, fieldName, model, helper); if (linkedActionColumn != null) { final int sourceColumnIndex = model.getExpandedColumns().indexOf(linkedActionColumn); final int targetColumnIndex = otherModel.getExpandedColumns().indexOf(var); callback.link(sourceColumnIndex, targetColumnIndex); } } } } }  @Override void link(final GuidedDecisionTable52 model,
                     final GuidedDecisionTable52 otherModel,
                     final LinkFoundCallback callback);  }
@Test public void onlyOneDecisionTableThereforeNoLinks() { manager.link(new GuidedDecisionTable52(), null, (s, t) -> fail("There should be no links")); }
@Test public void fieldConstraintLinksToActionUpdateField() { final GuidedDecisionTable52 dt1 = new GuidedDecisionTable52(); final Pattern52 p1 = new Pattern52(); p1.setBoundName("$f"); p1.setFactType("Fact"); final ConditionCol52 p1c1 = new ConditionCol52(); p1c1.setFactField("field"); p1.getChildColumns().add(p1c1); dt1.getConditions().add(p1); final ActionSetFieldCol52 asf = new ActionSetFieldCol52(); asf.setBoundName("$f"); asf.setFactField("field"); dt1.getActionCols().add(asf); final GuidedDecisionTable52 dt2 = new GuidedDecisionTable52(); final Pattern52 p2 = new Pattern52(); p2.setBoundName("$f"); p2.setFactType("Fact"); final ConditionCol52 p2c1 = new ConditionCol52(); p2c1.setFactField("field"); p2.getChildColumns().add(p2c1); dt2.getConditions().add(p2); manager.link(dt1, dt2, (s, t) -> { assertEquals(4, s); assertEquals(3, t); }); }
@Test public void fieldConstraintLinksToActionInsertFactField() { final GuidedDecisionTable52 dt1 = new GuidedDecisionTable52(); final ActionInsertFactCol52 aif = new ActionInsertFactCol52(); aif.setFactType("Fact"); aif.setFactField("field"); dt1.getActionCols().add(aif); final GuidedDecisionTable52 dt2 = new GuidedDecisionTable52(); final Pattern52 p2 = new Pattern52(); p2.setBoundName("$f"); p2.setFactType("Fact"); final ConditionCol52 p2c1 = new ConditionCol52(); p2c1.setFactField("field"); p2.getChildColumns().add(p2c1); dt2.getConditions().add(p2); manager.link(dt1, dt2, (s, t) -> { assertEquals(3, s); assertEquals(3, t); }); }
@Test public void fieldConstraintWithActionBRLFragmentFieldWithoutTemplateKey() { final GuidedDecisionTable52 dt1 = new GuidedDecisionTable52(); final BRLActionColumn brl = new BRLActionColumn(); final ActionInsertFact aif = new ActionInsertFact(); aif.setFactType("Fact"); aif.addFieldValue(new ActionFieldValue() {{ setField("field"); setValue("10"); setNature(FieldNatureType.TYPE_LITERAL); }}); brl.setDefinition(new ArrayList<IAction>() {{ add(aif); }}); brl.getChildColumns().add(new BRLActionVariableColumn("", DataType.TYPE_BOOLEAN)); dt1.getActionCols().add(brl); final GuidedDecisionTable52 dt2 = new GuidedDecisionTable52(); final Pattern52 p2 = new Pattern52(); p2.setBoundName("$f"); p2.setFactType("Fact"); final ConditionCol52 p2c1 = new ConditionCol52(); p2c1.setFactField("field"); p2.getChildColumns().add(p2c1); dt2.getConditions().add(p2); manager.link(dt1, dt2, (s, t) -> { assertEquals(3, s); assertEquals(3, t); }); }
@Test public void fieldConstraintWithActionBRLFragmentFieldWithTemplateKey() { final GuidedDecisionTable52 dt1 = new GuidedDecisionTable52(); final BRLActionColumn brl = new BRLActionColumn(); final ActionInsertFact aif = new ActionInsertFact("Fact"); aif.addFieldValue(new ActionFieldValue() {{ setField("field"); setValue("10"); setType(DataType.TYPE_STRING); setNature(FieldNatureType.TYPE_TEMPLATE); }}); brl.setDefinition(new ArrayList<IAction>() {{ add(aif); }}); brl.getChildColumns().add(new BRLActionVariableColumn("$f", DataType.TYPE_STRING, "Fact", "field")); dt1.getActionCols().add(brl); final GuidedDecisionTable52 dt2 = new GuidedDecisionTable52(); final Pattern52 p2 = new Pattern52(); p2.setBoundName("$f"); p2.setFactType("Fact"); final ConditionCol52 p2c1 = new ConditionCol52(); p2c1.setFactField("field"); p2.getChildColumns().add(p2c1); dt2.getConditions().add(p2); manager.link(dt1, dt2, (s, t) -> { assertEquals(3, s); assertEquals(3, t); }); }