Search in sources :

Example 6 with FromCompositeFactPattern

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

the class RuleModelDRLPersistenceImpl method parsePatternSource.

private IFactPattern parsePatternSource(final RuleModel m, final PatternDescr pattern, final PatternSourceDescr patternSource, final boolean isJavaDialect, final Map<String, String> boundParams, final PackageDataModelOracle dmo) {
    if (pattern.getIdentifier() != null) {
        boundParams.put(pattern.getIdentifier(), pattern.getObjectType());
    }
    if (patternSource instanceof AccumulateDescr) {
        AccumulateDescr accumulate = (AccumulateDescr) patternSource;
        FromAccumulateCompositeFactPattern fac = new FromAccumulateCompositeFactPattern();
        fac.setSourcePattern(parseBaseDescr(m, accumulate.getInput(), isJavaDialect, boundParams, dmo));
        fac.setInitCode(accumulate.getInitCode());
        fac.setActionCode(accumulate.getActionCode());
        fac.setReverseCode(accumulate.getReverseCode());
        fac.setResultCode(accumulate.getResultCode());
        FactPattern factPattern = new FactPattern(pattern.getObjectType());
        factPattern.setBoundName(pattern.getIdentifier());
        parseConstraint(m, factPattern, pattern.getConstraint(), isJavaDialect, boundParams, dmo);
        fac.setFactPattern(factPattern);
        for (AccumulateDescr.AccumulateFunctionCallDescr func : accumulate.getFunctions()) {
            String funcName = func.getFunction();
            boolean first = true;
            StringBuilder sb = new StringBuilder();
            for (String param : func.getParams()) {
                if (first) {
                    first = false;
                } else {
                    sb.append(", ");
                }
                sb.append(param);
            }
            fac.setFunction(funcName + "(" + sb + ")");
            break;
        }
        return fac;
    } else if (patternSource instanceof CollectDescr) {
        CollectDescr collect = (CollectDescr) patternSource;
        FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern();
        fac.setRightPattern(parseBaseDescr(m, collect.getInputPattern(), isJavaDialect, boundParams, dmo));
        fac.setFactPattern(getFactPattern(m, pattern, isJavaDialect, boundParams, dmo));
        return fac;
    } else if (patternSource instanceof EntryPointDescr) {
        EntryPointDescr entryPoint = (EntryPointDescr) patternSource;
        FromEntryPointFactPattern fep = new FromEntryPointFactPattern();
        fep.setEntryPointName(entryPoint.getText());
        fep.setFactPattern(getFactPattern(m, pattern, isJavaDialect, boundParams, dmo));
        return fep;
    } else if (patternSource instanceof FromDescr) {
        FromDescr from = (FromDescr) patternSource;
        FromCompositeFactPattern fcfp = new FromCompositeFactPattern();
        FactPattern factPattern = new FactPattern(pattern.getObjectType());
        factPattern.setBoundName(pattern.getIdentifier());
        parseConstraint(m, factPattern, pattern.getConstraint(), isJavaDialect, boundParams, dmo);
        fcfp.setFactPattern(factPattern);
        ExpressionFormLine expression = new ExpressionFormLine();
        fcfp.setExpression(expression);
        String dataSource = from.getDataSource().toString();
        String[] splitSource = dataSource.split("\\.");
        ModelField[] fields = null;
        for (int i = 0; i < splitSource.length; i++) {
            String sourcePart = splitSource[i];
            if (i == 0) {
                String type = boundParams.get(sourcePart);
                expression.appendPart(new ExpressionVariable(sourcePart, type, DataType.TYPE_NUMERIC));
                fields = findFields(m, dmo, type);
            } else {
                ModelField modelField = null;
                if (fields != null) {
                    for (ModelField field : fields) {
                        if (field.getName().equals(sourcePart)) {
                            modelField = field;
                            break;
                        }
                    }
                }
                if (modelField == null) {
                    final String previousClassName = expression.getClassType();
                    final List<MethodInfo> mis = dmo.getModuleMethodInformation().get(previousClassName);
                    boolean isMethod = false;
                    if (mis != null) {
                        for (MethodInfo mi : mis) {
                            if (mi.getName().equals(sourcePart)) {
                                expression.appendPart(new ExpressionMethod(mi.getName(), mi.getReturnClassType(), mi.getGenericType(), mi.getParametricReturnType()));
                                isMethod = true;
                                break;
                            }
                        }
                    }
                    if (isMethod == false) {
                        expression.appendPart(new ExpressionText(sourcePart));
                    }
                } else {
                    expression.appendPart(new ExpressionField(sourcePart, modelField.getClassName(), modelField.getType()));
                    fields = findFields(m, dmo, modelField.getClassName());
                }
            }
        }
        return fcfp;
    }
    throw new RuntimeException("Unknown pattern source " + patternSource);
}
Also used : FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) EntryPointDescr(org.drools.compiler.lang.descr.EntryPointDescr) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) IFactPattern(org.drools.workbench.models.datamodel.rule.IFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromDescr(org.drools.compiler.lang.descr.FromDescr) ExpressionText(org.drools.workbench.models.datamodel.rule.ExpressionText) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) AccumulateDescr(org.drools.compiler.lang.descr.AccumulateDescr) ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) ExpressionMethod(org.drools.workbench.models.datamodel.rule.ExpressionMethod) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) CollectDescr(org.drools.compiler.lang.descr.CollectDescr) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable) ArrayList(java.util.ArrayList) StringUtils.splitArgumentsList(org.drools.core.util.StringUtils.splitArgumentsList) List(java.util.List) ActionFieldList(org.drools.workbench.models.datamodel.rule.ActionFieldList) MethodInfo(org.kie.soup.project.datamodel.oracle.MethodInfo) RuleModelPersistenceHelper.findMethodInfo(org.drools.workbench.models.commons.backend.rule.RuleModelPersistenceHelper.findMethodInfo)

Example 7 with FromCompositeFactPattern

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

the class RuleModelDRLPersistenceTest method testCompositeFactPatternWithFrom.

@Test
public void testCompositeFactPatternWithFrom() {
    final RuleModel m = new RuleModel();
    m.name = "model";
    final FactPattern fp1 = new FactPattern("Data");
    fp1.setBoundName("$d");
    m.addLhsItem(fp1);
    final FactPattern fp2 = new FactPattern("Person");
    final FromCompositeFactPattern ffp1 = new FromCompositeFactPattern();
    ffp1.setExpression(new ExpressionFormLine(new ExpressionVariable(fp1.getBoundName(), fp1.getFactType())));
    ffp1.setFactPattern(fp2);
    m.addLhsItem(ffp1);
    final String actual = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    final String expected = "rule \"model\"\n" + "dialect \"mvel\"\n" + "when\n" + "$d : Data( )\n" + "(Person( ) from $d)\n" + "\n" + "then\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected, actual);
}
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) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 8 with FromCompositeFactPattern

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

the class RuleModelDRLPersistenceTest method testCompositeFactPatternWithFromWithDSL.

@Test
public void testCompositeFactPatternWithFromWithDSL() {
    final RuleModel m = new RuleModel();
    m.name = "model";
    final DSLSentence sen = new DSLSentence();
    sen.setDefinition("A DSL phrase");
    m.addLhsItem(sen);
    final FactPattern fp1 = new FactPattern("Data");
    fp1.setBoundName("$d");
    m.addLhsItem(fp1);
    final CompositeFactPattern cp = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_NOT);
    final FactPattern fp2 = new FactPattern("Person");
    final FromCompositeFactPattern ffp1 = new FromCompositeFactPattern();
    ffp1.setExpression(new ExpressionFormLine(new ExpressionVariable(fp1.getBoundName(), fp1.getFactType())));
    ffp1.setFactPattern(fp2);
    cp.addFactPattern(ffp1);
    m.addLhsItem(cp);
    final String actual = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    final String expected = "rule \"model\"\n" + "dialect \"mvel\"\n" + "when\n" + "A DSL phrase\n" + ">$d : Data( )\n" + ">not ( Person( ) from $d\n" + ")\n" + "then\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected, actual);
}
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) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) Test(org.junit.Test)

Example 9 with FromCompositeFactPattern

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

the class BaseBRLTest method whenThereIsABRLFromCompositeFactPattern.

protected BRLConditionColumn whenThereIsABRLFromCompositeFactPattern(final String factType, final String binding) {
    final FromCompositeFactPattern fcfp = new FromCompositeFactPattern();
    final FactPattern fp = new FactPattern(factType);
    fp.setBoundName(binding);
    fcfp.setFactPattern(fp);
    final BRLConditionColumn brl = new BRLConditionColumn();
    brl.getDefinition().add(fcfp);
    dtable.getConditions().add(brl);
    return brl;
}
Also used : FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern)

Example 10 with FromCompositeFactPattern

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

the class RuleModelCloneVisitor method visitFromCompositeFactPattern.

private FromCompositeFactPattern visitFromCompositeFactPattern(FromCompositeFactPattern pattern) {
    FromCompositeFactPattern clone = new FromCompositeFactPattern();
    clone.setExpression((ExpressionFormLine) visit(pattern.getExpression()));
    clone.setFactPattern((FactPattern) visit(pattern.getFactPattern()));
    return clone;
}
Also used : FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)

Aggregations

FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)29 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)24 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)22 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)22 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)18 Test (org.junit.Test)18 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)15 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)12 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)11 ExpressionVariable (org.drools.workbench.models.datamodel.rule.ExpressionVariable)10 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)9 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)8 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)7 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)5 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)5 Widget (com.google.gwt.user.client.ui.Widget)5 ExpressionText (org.drools.workbench.models.datamodel.rule.ExpressionText)5 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)4 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)4 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)3