Search in sources :

Example 11 with ExpressionVariable

use of org.drools.workbench.models.datamodel.rule.ExpressionVariable in project drools-wb by kiegroup.

the class GuidedRuleEditorValidatorTest method testComparingFieldToExpression.

@Test
public void testComparingFieldToExpression() throws Exception {
    FactPattern f1 = new FactPattern();
    f1.setBoundName("f1");
    FactPattern f2 = new FactPattern();
    SingleFieldConstraint constraint = new SingleFieldConstraint();
    constraint.setOperator("==");
    constraint.getExpressionValue().appendPart(new ExpressionVariable("field", "java.lang.Number", "Number"));
    f2.addConstraint(constraint);
    model.lhs = new IPattern[] { f1, f2 };
    assertTrue(validator.isValid());
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable) Test(org.junit.Test)

Example 12 with ExpressionVariable

use of org.drools.workbench.models.datamodel.rule.ExpressionVariable in project drools-wb by kiegroup.

the class GuidedRuleEditorValidatorTest method testValidFromCompositeFactPattern.

@Test
public void testValidFromCompositeFactPattern() throws Exception {
    FactPattern factPattern = new FactPattern("SomeList");
    factPattern.setBoundName("list");
    FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern();
    fromCompositeFactPattern.setFactPattern(new FactPattern("Person"));
    ExpressionFormLine expression = new ExpressionFormLine();
    expression.appendPart(new ExpressionVariable("list", "SomeList", "SomeList"));
    fromCompositeFactPattern.setExpression(expression);
    model.lhs = new IPattern[] { fromCompositeFactPattern };
    assertTrue(validator.isValid());
}
Also used : ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable) Test(org.junit.Test)

Example 13 with ExpressionVariable

use of org.drools.workbench.models.datamodel.rule.ExpressionVariable in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testDSLWithFrom.

/*
     * https://issues.jboss.org/browse/DROOLS-1903
     */
@Test
public void testDSLWithFrom() {
    final RuleModel m = new RuleModel();
    m.name = "testDSLWithFrom";
    m.lhs = new IPattern[2];
    m.rhs = new IAction[0];
    final FromCollectCompositeFactPattern from = new FromCollectCompositeFactPattern();
    final FromCompositeFactPattern rightPattern = new FromCompositeFactPattern();
    final FactPattern person = new FactPattern("Person");
    person.setBoundName("$person");
    m.lhs[0] = person;
    rightPattern.setFactPattern(new FactPattern("Person"));
    rightPattern.setExpression(new ExpressionFormLine(new ExpressionVariable(person.getBoundName(), person.getFactType())));
    from.setRightPattern(rightPattern);
    from.setFactPattern(new FactPattern("java.util.List"));
    m.lhs[1] = from;
    final RuleModel modelSpy = spy(m);
    doReturn(true).when(modelSpy).hasDSLSentences();
    final String drl = ruleModelPersistence.marshal(modelSpy);
    final RuleModel tempModel = spy(ruleModelPersistence.unmarshalUsingDSL(drl, null, dmo, ""));
    doReturn(true).when(tempModel).hasDSLSentences();
    final String newDrl = ruleModelPersistence.marshal(tempModel);
    final RuleModel newModel = ruleModelPersistence.unmarshalUsingDSL(newDrl, null, dmo, "");
    assertTrue(newModel.lhs[0] instanceof FactPattern);
    assertTrue(newModel.lhs[1] instanceof FromCollectCompositeFactPattern);
    assertDSLEscaping(newDrl);
}
Also used : ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 14 with ExpressionVariable

use of org.drools.workbench.models.datamodel.rule.ExpressionVariable in project drools by kiegroup.

the class RuleModelDRLPersistenceUnmarshallingTest method testExpressionEditorLeftToOperator.

@Test
public void testExpressionEditorLeftToOperator() throws Exception {
    String drl = "" + "rule \"r1\"\n" + "dialect \"mvel\"\n" + "when\n" + " a: Applicant()\n" + " Applicant( age == a.age )\n" + "then\n" + "end";
    addModelField("Applicant", "this", "Applicant", DataType.TYPE_THIS);
    addModelField("Applicant", "age", "java.lang.Integer", "Integer");
    RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    FactPattern pattern1 = (FactPattern) m.lhs[0];
    assertEquals("a", pattern1.getBoundName());
    FactPattern pattern2 = (FactPattern) m.lhs[1];
    assertEquals(1, pattern2.getConstraintList().getNumberOfConstraints());
    assertTrue(pattern2.getConstraintList().getConstraint(0) instanceof SingleFieldConstraint);
    SingleFieldConstraint constraint = (SingleFieldConstraint) pattern2.getConstraintList().getConstraint(0);
    assertEquals("age", constraint.getFieldName());
    assertEquals("==", constraint.getOperator());
    assertEquals(BaseSingleFieldConstraint.TYPE_EXPR_BUILDER_VALUE, constraint.getConstraintValueType());
    assertEquals("", constraint.getValue());
    assertEquals(2, constraint.getExpressionValue().getParts().size());
    assertTrue(constraint.getExpressionValue().getParts().get(0) instanceof ExpressionVariable);
    ExpressionVariable expressionVariable = (ExpressionVariable) constraint.getExpressionValue().getParts().get(0);
    assertEquals("a", expressionVariable.getName());
    assertEquals("Applicant", expressionVariable.getClassType());
    assertEquals("this", expressionVariable.getGenericType());
    assertEquals(constraint.getExpressionValue().getParts().get(1), expressionVariable.getNext());
    assertTrue(constraint.getExpressionValue().getParts().get(1) instanceof ExpressionField);
    ExpressionField expressionField = (ExpressionField) constraint.getExpressionValue().getParts().get(1);
    assertEquals("age", expressionField.getName());
    assertEquals("java.lang.Integer", expressionField.getClassType());
    assertEquals("Integer", expressionField.getGenericType());
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 15 with ExpressionVariable

use of org.drools.workbench.models.datamodel.rule.ExpressionVariable in project drools by kiegroup.

the class CopyExpressionVisitor method visit.

public void visit(ExpressionVariable part) {
    add(new ExpressionVariable(part.getName(), part.getFactType()));
    moveNext(part);
}
Also used : ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable)

Aggregations

ExpressionVariable (org.drools.workbench.models.datamodel.rule.ExpressionVariable)16 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)14 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)13 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)13 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)13 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)13 Test (org.junit.Test)13 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)10 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)10 ExpressionText (org.drools.workbench.models.datamodel.rule.ExpressionText)6 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)6 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)5 ExpressionField (org.drools.workbench.models.datamodel.rule.ExpressionField)5 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)5 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)5 ExpressionMethod (org.drools.workbench.models.datamodel.rule.ExpressionMethod)3 ExpressionFieldVariable (org.drools.workbench.models.datamodel.rule.ExpressionFieldVariable)2 ExpressionUnboundFact (org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1