use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class GuidedDecisionTreeModelUnmarshallingVisitor method visit.
private List<Node> visit(final FieldConstraint fc, final GuidedDecisionTree model, final PackageDataModelOracle dmo, final List<ParserMessage> messages) {
final List<Node> nodes = new ArrayList<Node>();
if (fc instanceof CompositeFieldConstraint) {
messages.add(new UnsupportedFieldConstraintParserMessage());
return nodes;
} else if (fc instanceof SingleFieldConstraintEBLeftSide) {
messages.add(new UnsupportedFieldConstraintParserMessage());
return nodes;
}
if (!(fc instanceof SingleFieldConstraint)) {
messages.add(new UnsupportedFieldConstraintParserMessage());
return nodes;
}
final SingleFieldConstraint sfc = (SingleFieldConstraint) fc;
if (sfc.getConnectives() != null) {
messages.add(new UnsupportedFieldConstraintParserMessage());
return nodes;
}
ConstraintNode node = null;
final String className = sfc.getFactType();
final String fieldName = sfc.getFieldName();
if (sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_LITERAL) {
final String operator = sfc.getOperator();
final boolean isValueRequired = OperatorsOracle.isValueRequired(operator);
if (isValueRequired) {
final Value value = getValue(className, fieldName, model, dmo, messages, sfc.getValue());
if (value != null) {
node = new ConstraintNodeImpl(className, fieldName, operator, value);
}
} else {
node = new ConstraintNodeImpl(className, fieldName);
}
} else if (sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_ENUM) {
final String operator = sfc.getOperator();
final boolean isValueRequired = OperatorsOracle.isValueRequired(operator);
if (isValueRequired) {
final Value value = getValue(className, fieldName, model, dmo, messages, sfc.getValue());
if (value != null) {
node = new ConstraintNodeImpl(className, fieldName, operator, value);
}
} else {
node = new ConstraintNodeImpl(className, fieldName);
}
} else if (sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_UNDEFINED) {
final String operator = sfc.getOperator();
final boolean isValueRequired = OperatorsOracle.isValueRequired(operator);
if (isValueRequired) {
node = new ConstraintNodeImpl(className, fieldName);
} else {
node = new ConstraintNodeImpl(className, fieldName, operator, null);
}
} else {
messages.add(new UnsupportedFieldConstraintTypeParserMessage());
return nodes;
}
if (node != null) {
if (sfc.isBound()) {
node.setBinding(sfc.getFieldBinding());
}
nodes.add(node);
}
return nodes;
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class BRLRuleModelTest method assertThereIsAFieldBindingFor.
private void assertThereIsAFieldBindingFor(final String fieldBinding) {
final SingleFieldConstraint sfc = rm.getLHSBoundField(fieldBinding);
assertNotNull(sfc);
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class BaseBRLTest method whenBRLFactPatternHasAField.
protected SingleFieldConstraint whenBRLFactPatternHasAField(final BRLConditionColumn brl, final String fieldName, final String fieldType, final String fieldBinding) {
assertFalse("BRLConditionColumn has not been initialised. Was 'whenThereIsABRLFactPattern' called?", brl.getDefinition().isEmpty());
assertEquals("BRLConditionColumn has not been initialised correctly. Was 'whenThereIsABRLFactPattern' called?", 1, brl.getDefinition().size());
assertTrue("BRLConditionColumn has not been initialised correctly. Was 'whenThereIsABRLFactPattern' called?", brl.getDefinition().get(0) instanceof FactPattern);
final FactPattern fp = (FactPattern) brl.getDefinition().get(0);
final SingleFieldConstraint sfc = new SingleFieldConstraint();
sfc.setFactType(fp.getFactType());
sfc.setFieldName(fieldName);
sfc.setFieldType(fieldType);
sfc.setFieldBinding(fieldBinding);
fp.addConstraint(sfc);
brl.getDefinition().add(fp);
return sfc;
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleModelUpgradeHelper3 method fixConstraints.
private void fixConstraints(FactPattern fp, SingleFieldConstraint sfc) {
final FieldConstraint parent = sfc.getParent();
if (parent == null) {
sfc.setFactType(fp.getFactType());
} else if (parent instanceof SingleFieldConstraint) {
sfc.setFactType(((SingleFieldConstraint) parent).getFieldType());
}
sfc.setFieldName(fixFieldName(sfc.getFieldName()));
if (sfc.getConnectives() == null) {
return;
}
for (ConnectiveConstraint cc : sfc.getConnectives()) {
cc.setFactType(fp.getFactType());
cc.setFieldName(fixFieldName(cc.getFieldName()));
}
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testNestedCompositeConstraints5ThirdValue.
@Test
public void testNestedCompositeConstraints5ThirdValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p = new FactPattern("Person");
CompositeFieldConstraint comp = new CompositeFieldConstraint();
comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
p.addConstraint(comp);
m.addLhsItem(p);
final SingleFieldConstraint comp1sfc1 = new SingleFieldConstraint();
comp1sfc1.setFieldName("field1");
comp1sfc1.setFieldType(DataType.TYPE_STRING);
comp1sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc1.setValue("$f1");
comp1sfc1.setOperator("==");
comp.addConstraint(comp1sfc1);
final SingleFieldConstraint comp1sfc2 = new SingleFieldConstraint();
comp1sfc2.setFieldName("field2");
comp1sfc2.setFieldType(DataType.TYPE_STRING);
comp1sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc2.setValue("$f2");
comp1sfc2.setOperator("==");
comp.addConstraint(comp1sfc2);
final SingleFieldConstraint comp1sfc3 = new SingleFieldConstraint();
comp1sfc3.setFieldName("field3");
comp1sfc3.setFieldType(DataType.TYPE_STRING);
comp1sfc3.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
comp1sfc3.setValue("$f3");
comp1sfc3.setOperator("==");
comp.addConstraint(comp1sfc3);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field3 == \"goo\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { null, null, "goo" });
checkMarshall(expected, m);
}
Aggregations