use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.
the class DefaultGuidedDecisionTableLinkManagerTest method fieldConstraintWithActionBRLFragmentFieldWithoutTemplateKey.
@Test
public void fieldConstraintWithActionBRLFragmentFieldWithoutTemplateKey() {
// Columns: Row#[0], Description[1], Action[2]
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);
// Columns: Row#[0], Description[1], Condition[2]
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(2, s);
assertEquals(2, t);
});
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.
the class DefaultGuidedDecisionTableLinkManagerTest method fieldConstraintLinksToActionUpdateField.
@Test
public void fieldConstraintLinksToActionUpdateField() {
// Columns: Row#[0], Description[1], Condition[2], Action[3]
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);
// Columns: Row#[0], Description[1], Condition[2]
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(2, t);
});
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.
the class GuidedDecisionTableModelVisitor method getConsumedModelClasses.
public Set<String> getConsumedModelClasses() {
final Set<String> factTypes = new HashSet<String>();
// Extract Fact Types from model
for (CompositeColumn<?> cc : model.getConditions()) {
if (cc instanceof BRLConditionColumn) {
final List<IPattern> definition = ((BRLConditionColumn) cc).getDefinition();
factTypes.addAll(getConditionFactTypesFromRuleModel(definition));
} else if (cc instanceof Pattern52) {
factTypes.add(((Pattern52) cc).getFactType());
}
}
for (ActionCol52 c : model.getActionCols()) {
if (c instanceof BRLActionColumn) {
final List<IAction> definition = ((BRLActionColumn) c).getDefinition();
factTypes.addAll(getActionFactTypesFromRuleModel(definition));
} else if (c instanceof ActionInsertFactCol52) {
factTypes.add(((ActionInsertFactCol52) c).getFactType());
}
}
// Convert Fact Types into Fully Qualified Class Names
final Set<String> fullyQualifiedClassNames = new HashSet<String>();
for (String factType : factTypes) {
fullyQualifiedClassNames.add(convertToFullyQualifiedClassName(factType));
}
return fullyQualifiedClassNames;
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.
the class GuidedDecisionTableFactory method makeTableWithConditionCol.
public static GuidedDecisionTable52 makeTableWithConditionCol(final String packageName, final Collection<Import> imports, final String tableName) {
final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setPackageName(packageName);
dt.getImports().getImports().addAll(imports);
dt.setTableName(tableName);
Pattern52 p1 = new Pattern52();
p1.setBoundName("$a");
p1.setFactType("Applicant");
ConditionCol52 con1 = new ConditionCol52();
con1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
con1.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
con1.setFactField("age");
con1.setHeader("Applicant age");
con1.setOperator("==");
p1.getChildColumns().add(con1);
dt.getConditions().add(p1);
Pattern52 p2 = new Pattern52();
p2.setBoundName("$m");
p2.setFactType("Mortgage");
ConditionCol52 con2 = new ConditionCol52();
con2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
con2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
con2.setFactField("amount");
con2.setHeader("Mortgage amount");
con2.setOperator("==");
p2.getChildColumns().add(con2);
dt.getConditions().add(p2);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "33", "" } }));
return dt;
}
use of org.drools.workbench.models.guided.dtable.shared.model.Pattern52 in project drools-wb by kiegroup.
the class ConditionColumnSynchronizer method doMovePattern.
private void doMovePattern(final List<MoveColumnToMetaData> metaData) throws VetoException {
final MoveColumnToMetaData md = metaData.get(0);
final ConditionCol52 srcModelColumn = (ConditionCol52) md.getColumn();
final Pattern52 srcModelPattern = model.getPattern(srcModelColumn);
if (srcModelPattern == null) {
throw new ModelSynchronizer.MoveVetoException();
}
final List<ConditionCol52> srcModelPatternConditionColumns = srcModelPattern.getChildColumns();
final int srcModelPatternConditionColumnCount = srcModelPatternConditionColumns.size();
if (srcModelPatternConditionColumnCount == 0) {
throw new ModelSynchronizer.MoveVetoException();
}
if (srcModelPatternConditionColumnCount != metaData.size()) {
throw new ModelSynchronizer.MoveVetoException();
}
final int tgtColumnIndex = md.getTargetColumnIndex();
final int tgtPatternIndex = findTargetPatternIndex(md);
final List<BaseColumn> allModelColumns = model.getExpandedColumns();
moveModelData(tgtColumnIndex, allModelColumns.indexOf(srcModelPatternConditionColumns.get(0)), allModelColumns.indexOf(srcModelPatternConditionColumns.get(0)) + srcModelPatternConditionColumnCount - 1);
model.getConditions().remove(srcModelPattern);
model.getConditions().add(tgtPatternIndex, srcModelPattern);
}
Aggregations