use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide 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.SingleFieldConstraintEBLeftSide in project drools-wb by kiegroup.
the class RuleModelCloneVisitorTest method buildSingleFieldConstraintEBLeftSide.
private static SingleFieldConstraintEBLeftSide buildSingleFieldConstraintEBLeftSide() {
SingleFieldConstraintEBLeftSide sfc = new SingleFieldConstraintEBLeftSide();
sfc.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
sfc.setExpressionValue(buildExpressionFormLine());
sfc.setExpressionLeftSide(buildExpressionFormLine());
sfc.setFactType("FactType");
// do not set fieldBinding, fieldName and fieldType, these are computed from expressionLeftSide
sfc.setId("id");
sfc.setOperator("operator");
sfc.setParameter("key", "parameter");
sfc.setParent(new SingleFieldConstraint("parentFieldName"));
sfc.setValue("value");
sfc.addNewConnective();
return sfc;
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide in project drools-wb by kiegroup.
the class PopupCreatorTest method testOnExpressionEditorButtonClick.
@Test
public void testOnExpressionEditorButtonClick() {
final String factType = "factType";
final FactPattern factPattern = mock(FactPattern.class);
final HasConstraints hasConstraints = mock(HasConstraints.class);
final FormStylePopup popup = mock(FormStylePopup.class);
final SingleFieldConstraintEBLeftSide constraint = mock(SingleFieldConstraintEBLeftSide.class);
final RuleModeller ruleModeller = mock(RuleModeller.class);
final ClickEvent clickEvent = mock(ClickEvent.class);
doReturn(factType).when(factPattern).getFactType();
doReturn(constraint).when(popupCreator).makeSingleFieldConstraintEBLeftSide(factType);
doReturn(ruleModeller).when(popupCreator).getModeller();
doReturn(factPattern).when(popupCreator).getPattern();
final ClickHandler clickHandler = popupCreator.onExpressionEditorButtonClick(hasConstraints, popup);
clickHandler.onClick(clickEvent);
verify(hasConstraints).addConstraint(constraint);
verify(ruleModeller).refreshWidget();
verify(popup).hide();
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide in project drools-wb by kiegroup.
the class FactPatternWidget method renderSingleFieldConstraint.
/**
* Applies a single field constraint to the given table, and start row.
*/
private void renderSingleFieldConstraint(final FlexTable inner, final int row, final SingleFieldConstraint constraint, final HasConstraints hasConstraints, boolean showBinding, final int tabs) {
// for offsetting, just a slight indent
final int col = 1;
inner.setWidget(row, 0, new HTML(" "));
if (constraint.getConstraintValueType() != SingleFieldConstraint.TYPE_PREDICATE) {
HorizontalPanel ebContainer = null;
if (constraint instanceof SingleFieldConstraintEBLeftSide) {
ebContainer = expressionBuilderLS((SingleFieldConstraintEBLeftSide) constraint, showBinding);
inner.setWidget(row, 0 + col, ebContainer);
} else {
inner.setWidget(row, 0 + col, fieldLabel(constraint, hasConstraints, showBinding, tabs * 20));
}
inner.setWidget(row, 1 + col, operatorDropDown(constraint, inner, row, 2 + col));
// Get first part of constraint.fieldName? #1=Fact1, #2=SubFact1
inner.setWidget(row, 2 + col, createValueEditor(constraint));
inner.setWidget(row, 3 + col, getConnectives().connectives(constraint));
if (ebContainer != null && ebContainer.getWidgetCount() > 0) {
if (ebContainer.getWidget(0) instanceof ExpressionBuilder) {
associateExpressionWithChangeHandler(inner, row, constraint, col, ebContainer);
}
}
} else if (constraint.getConstraintValueType() == SingleFieldConstraint.TYPE_PREDICATE) {
inner.setWidget(row, 1, predicateEditor(constraint));
inner.getFlexCellFormatter().setColSpan(row, 1, 5);
}
}
use of org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testLHSExpressionString1.
@Test
public void testLHSExpressionString1() {
RuleModel m = new RuleModel();
m.name = "test expressionsString1";
FactPattern p = new FactPattern("Person");
SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide();
con.getExpressionLeftSide().appendPart(new ExpressionText("field1"));
con.setOperator("==");
con.setValue("goo");
con.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
p.addConstraint(con);
m.addLhsItem(p);
String expected = "rule \"test expressionsString1\"" + "\tdialect \"mvel\"\n when " + " Person( field1 == \"goo\" )" + " then " + "end";
checkMarshalling(expected, m);
}
Aggregations