Search in sources :

Example 11 with MethodInfo

use of org.kie.soup.project.datamodel.oracle.MethodInfo in project drools-wb by kiegroup.

the class ActionCallMethodWidget method setMethodInfos.

private void setMethodInfos(List<MethodInfo> methodInfos, String factType) {
    this.fieldCompletionTexts = new String[methodInfos.size()];
    this.fieldCompletionValues = new String[methodInfos.size()];
    int i = 0;
    for (MethodInfo methodInfo : methodInfos) {
        this.fieldCompletionTexts[i] = methodInfo.getName();
        this.fieldCompletionValues[i] = methodInfo.getNameWithParameters();
        i++;
    }
    this.variableClass = factType;
}
Also used : MethodInfo(org.kie.soup.project.datamodel.oracle.MethodInfo) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)

Example 12 with MethodInfo

use of org.kie.soup.project.datamodel.oracle.MethodInfo in project drools by kiegroup.

the class ActionCallMethodBuilder method getDataType.

private String getDataType(String param) {
    String dataType;
    MethodInfo methodInfo = getMethodInfo();
    if (methodInfo != null) {
        dataType = methodInfo.getParams().get(index++);
    } else {
        dataType = boundParams.get(param);
    }
    if (dataType == null) {
        dataType = inferDataTypeFromActionValue(param, boundParams, isJavaDialect);
    }
    return dataType;
}
Also used : MethodInfo(org.kie.soup.project.datamodel.oracle.MethodInfo)

Example 13 with MethodInfo

use of org.kie.soup.project.datamodel.oracle.MethodInfo in project drools by kiegroup.

the class RuleModelDRLPersistenceUnmarshallingTest method testLHSNumberExpressionWithThisPrefix.

@Test
public void testLHSNumberExpressionWithThisPrefix() throws Exception {
    String drl = "package org.mortgages;\n" + "import java.lang.Number\n" + "rule \"test\"\n" + " dialect \"mvel\"\n" + " when\n" + "  Number( this.intValue() > 5 )\n" + " then\n" + "end";
    final HashMap<String, List<MethodInfo>> map = new HashMap<>();
    final ArrayList<MethodInfo> methodInfos = new ArrayList<>();
    methodInfos.add(new MethodInfo("intValue", Collections.emptyList(), "int", null, DataType.TYPE_NUMERIC_INTEGER));
    map.put("java.lang.Number", methodInfos);
    when(dmo.getModuleMethodInformation()).thenReturn(map);
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(1, m.lhs.length);
    assertTrue(m.lhs[0] instanceof FactPattern);
    final FactPattern fp = (FactPattern) m.lhs[0];
    assertEquals("Number", fp.getFactType());
    assertEquals(1, fp.getNumberOfConstraints());
    assertTrue(fp.getConstraint(0) instanceof SingleFieldConstraintEBLeftSide);
    final SingleFieldConstraintEBLeftSide exp = (SingleFieldConstraintEBLeftSide) fp.getConstraint(0);
    assertEquals("int", exp.getFieldType());
    assertEquals(">", exp.getOperator());
    assertEquals("5", exp.getValue());
    assertEquals(3, exp.getExpressionLeftSide().getParts().size());
    assertTrue(exp.getExpressionLeftSide().getParts().get(0) instanceof ExpressionUnboundFact);
    final ExpressionUnboundFact expPart0 = (ExpressionUnboundFact) exp.getExpressionLeftSide().getParts().get(0);
    assertEquals("Number", expPart0.getFactType());
    assertTrue(exp.getExpressionLeftSide().getParts().get(1) instanceof ExpressionField);
    final ExpressionField expPart1 = (ExpressionField) exp.getExpressionLeftSide().getParts().get(1);
    assertEquals("this", expPart1.getName());
    assertTrue(exp.getExpressionLeftSide().getParts().get(2) instanceof ExpressionMethod);
    final ExpressionMethod expPart2 = (ExpressionMethod) exp.getExpressionLeftSide().getParts().get(2);
    assertEquals("intValue", expPart2.getName());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) ExpressionMethod(org.drools.workbench.models.datamodel.rule.ExpressionMethod) List(java.util.List) ArrayList(java.util.ArrayList) MethodInfo(org.kie.soup.project.datamodel.oracle.MethodInfo) Test(org.junit.Test)

Example 14 with MethodInfo

use of org.kie.soup.project.datamodel.oracle.MethodInfo in project drools by kiegroup.

the class RuleModelDRLPersistenceUnmarshallingTest method testLHSNumberExpressionWithoutThisPrefix.

@Test
public void testLHSNumberExpressionWithoutThisPrefix() throws Exception {
    String drl = "package org.mortgages;\n" + "import java.lang.Number\n" + "rule \"test\"\n" + " dialect \"mvel\"\n" + " when\n" + "  Number( intValue() > 5 )\n" + " then\n" + "end";
    final HashMap<String, List<MethodInfo>> map = new HashMap<>();
    final ArrayList<MethodInfo> methodInfos = new ArrayList<>();
    methodInfos.add(new MethodInfo("intValue", Collections.emptyList(), "int", null, DataType.TYPE_NUMERIC_INTEGER));
    map.put("java.lang.Number", methodInfos);
    when(dmo.getModuleMethodInformation()).thenReturn(map);
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(1, m.lhs.length);
    assertTrue(m.lhs[0] instanceof FactPattern);
    final FactPattern fp = (FactPattern) m.lhs[0];
    assertEquals("Number", fp.getFactType());
    assertEquals(1, fp.getNumberOfConstraints());
    assertTrue(fp.getConstraint(0) instanceof SingleFieldConstraintEBLeftSide);
    final SingleFieldConstraintEBLeftSide exp = (SingleFieldConstraintEBLeftSide) fp.getConstraint(0);
    assertEquals("int", exp.getFieldType());
    assertEquals(">", exp.getOperator());
    assertEquals("5", exp.getValue());
    assertEquals(2, exp.getExpressionLeftSide().getParts().size());
    assertTrue(exp.getExpressionLeftSide().getParts().get(0) instanceof ExpressionUnboundFact);
    final ExpressionUnboundFact expPart0 = (ExpressionUnboundFact) exp.getExpressionLeftSide().getParts().get(0);
    assertEquals("Number", expPart0.getFactType());
    assertTrue(exp.getExpressionLeftSide().getParts().get(1) instanceof ExpressionMethod);
    final ExpressionMethod expPart1 = (ExpressionMethod) exp.getExpressionLeftSide().getParts().get(1);
    assertEquals("intValue", expPart1.getName());
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) ExpressionMethod(org.drools.workbench.models.datamodel.rule.ExpressionMethod) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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) List(java.util.List) ArrayList(java.util.ArrayList) MethodInfo(org.kie.soup.project.datamodel.oracle.MethodInfo) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) Test(org.junit.Test)

Example 15 with MethodInfo

use of org.kie.soup.project.datamodel.oracle.MethodInfo in project drools by kiegroup.

the class RuleModelDRLPersistenceUnmarshallingTest method testFunctionsWithVariableParameters.

@Test
public void testFunctionsWithVariableParameters() throws Exception {
    String drl = "package org.mortgages;\n" + "rule \"test\"\n" + " dialect \"mvel\"\n" + " when\n" + "  Calculator( s : summer)\n" + "  Applicant( $age : age)\n" + " then\n" + "  s.sum( $age, $age );\n" + "end";
    addModelField("Calculator", "summer", "Summer", "Summer");
    addModelField("Applicant", "age", "java.lang.Integer", DataType.TYPE_NUMERIC_INTEGER);
    HashMap<String, List<MethodInfo>> map = new HashMap<>();
    ArrayList<MethodInfo> methodInfos = new ArrayList<>();
    ArrayList<String> params = new ArrayList<>();
    params.add("Integer");
    params.add("Integer");
    methodInfos.add(new MethodInfo("sum", params, "java.lang.Integer", null, "Summer"));
    map.put("Calculator", methodInfos);
    when(dmo.getModuleMethodInformation()).thenReturn(map);
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(2, m.lhs.length);
    assertEquals(1, m.rhs.length);
    ActionCallMethod actionCallMethod = (ActionCallMethod) m.rhs[0];
    assertEquals("sum", actionCallMethod.getMethodName());
    assertEquals("s", actionCallMethod.getVariable());
    assertEquals(2, actionCallMethod.getFieldValues().length);
    assertEquals("sum", actionCallMethod.getFieldValue(0).getField());
    assertEquals("$age", actionCallMethod.getFieldValue(0).getValue());
    assertEquals(2, actionCallMethod.getFieldValue(0).getNature());
    assertEquals("java.lang.Integer", actionCallMethod.getFieldValue(0).getType());
    assertEquals("sum", actionCallMethod.getFieldValue(1).getField());
    assertEquals("$age", actionCallMethod.getFieldValue(1).getValue());
    assertEquals(2, actionCallMethod.getFieldValue(1).getNature());
    assertEquals("java.lang.Integer", actionCallMethod.getFieldValue(1).getType());
    assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) List(java.util.List) ArrayList(java.util.ArrayList) MethodInfo(org.kie.soup.project.datamodel.oracle.MethodInfo) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Aggregations

MethodInfo (org.kie.soup.project.datamodel.oracle.MethodInfo)16 ArrayList (java.util.ArrayList)12 List (java.util.List)12 HashMap (java.util.HashMap)11 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)11 Test (org.junit.Test)11 ActionCallMethod (org.drools.workbench.models.datamodel.rule.ActionCallMethod)9 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)3 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)3 ExpressionMethod (org.drools.workbench.models.datamodel.rule.ExpressionMethod)3 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)3 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)3 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)3 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)3 ExpressionField (org.drools.workbench.models.datamodel.rule.ExpressionField)2 ExpressionUnboundFact (org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact)2 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)2 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)2 AccumulateDescr (org.drools.compiler.lang.descr.AccumulateDescr)1 CollectDescr (org.drools.compiler.lang.descr.CollectDescr)1