Search in sources :

Example 1 with ModelField

use of org.kie.soup.project.datamodel.oracle.ModelField 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 2 with ModelField

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

the class ScenarioTestEditorServiceImplTest method checkSingleScenarioMultipleExecution.

@Test
public void checkSingleScenarioMultipleExecution() throws Exception {
    final ArrayList<Fixture> fixtures = new ArrayList<>();
    final Imports imports = new Imports() {

        {
            addImport(new Import("java.sql.ClientInfoStatus"));
        }
    };
    final Map<String, ModelField[]> modelFields = new HashMap<String, ModelField[]>() {

        {
            put("java.sql.ClientInfoStatus", new ModelField[] { modelField("java.sql.JDBCType") });
        }
    };
    when(scenario.getFixtures()).thenReturn(fixtures);
    when(dataModelService.getDataModel(path)).thenReturn(modelOracle);
    when(modelOracle.getModuleModelFields()).thenReturn(modelFields);
    when(scenario.getImports()).thenCallRealMethod();
    doCallRealMethod().when(scenario).setImports(any(Imports.class));
    scenario.setImports(imports);
    testEditorService.runScenario("userName", path, scenario);
    assertEquals(1, scenario.getImports().getImports().size());
    testEditorService.runScenario("userName", path, scenario);
    assertEquals(1, scenario.getImports().getImports().size());
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) Imports(org.kie.soup.project.datamodel.imports.Imports) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 3 with ModelField

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

the class ScenarioTestEditorServiceImplTest method runScenarioWithDependentImports.

@Test
public void runScenarioWithDependentImports() throws Exception {
    final ArrayList<Fixture> fixtures = new ArrayList<Fixture>() {

        {
            add(factData("java.sql.ClientInfoStatus"));
        }
    };
    final Map<String, ModelField[]> modelFields = new HashMap<String, ModelField[]>() {

        {
            put("java.sql.ClientInfoStatus", new ModelField[] { modelField("java.sql.JDBCType") });
        }
    };
    when(scenario.getFixtures()).thenReturn(fixtures);
    when(dataModelService.getDataModel(path)).thenReturn(modelOracle);
    when(modelOracle.getModuleModelFields()).thenReturn(modelFields);
    when(scenario.getImports()).thenReturn(new Imports());
    testEditorService.addDependentImportsToScenario(scenario, path);
    assertEquals(2, scenario.getImports().getImports().size());
}
Also used : ModelField(org.kie.soup.project.datamodel.oracle.ModelField) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) Mockito.anyString(org.mockito.Mockito.anyString) Imports(org.kie.soup.project.datamodel.imports.Imports) Test(org.junit.Test)

Example 4 with ModelField

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

the class ScenarioTestEditorServiceImplTest method checkDependentImportsWithPrimitiveTypes.

@Test
public void checkDependentImportsWithPrimitiveTypes() throws Exception {
    final ArrayList<Fixture> fixtures = new ArrayList<>();
    final Imports imports = new Imports() {

        {
            addImport(new Import("int"));
        }
    };
    final Map<String, ModelField[]> modelFields = new HashMap<String, ModelField[]>() {

        {
            put("java.sql.ClientInfoStatus", new ModelField[] { modelField("java.sql.JDBCType") });
        }
    };
    when(scenario.getFixtures()).thenReturn(fixtures);
    when(dataModelService.getDataModel(path)).thenReturn(modelOracle);
    when(modelOracle.getModuleModelFields()).thenReturn(modelFields);
    when(scenario.getImports()).thenCallRealMethod();
    doCallRealMethod().when(scenario).setImports(any(Imports.class));
    scenario.setImports(imports);
    testEditorService.addDependentImportsToScenario(scenario, path);
    assertEquals(1, scenario.getImports().getImports().size());
}
Also used : Import(org.kie.soup.project.datamodel.imports.Import) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) Imports(org.kie.soup.project.datamodel.imports.Imports) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 5 with ModelField

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

the class TestTestScenarioFileIndexer method getModuleDataModelOracle.

@Override
protected ModuleDataModelOracle getModuleDataModelOracle(final Path path) {
    final ModuleDataModelOracle dmo = new ModuleDataModelOracleImpl();
    dmo.addModuleModelFields(new HashMap<String, ModelField[]>() {

        {
            put("org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Applicant", new ModelField[] { new ModelField("age", "java.lang.Integer", ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.ACCESSOR, DataType.TYPE_NUMERIC_INTEGER) });
            put("org.drools.workbench.screens.testscenario.backend.server.indexing.classes.Mortgage", new ModelField[] { new ModelField("amount", "java.lang.Integer", ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.ACCESSOR, DataType.TYPE_NUMERIC_INTEGER) });
            put("java.util.Date", new ModelField[] { new ModelField("minutes", "java.lang.Integer", ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.ACCESSOR, DataType.TYPE_NUMERIC_INTEGER) });
        }
    });
    return dmo;
}
Also used : ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)

Aggregations

ModelField (org.kie.soup.project.datamodel.oracle.ModelField)70 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)36 Test (org.junit.Test)34 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)34 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)25 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)24 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)24 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)24 Path (org.uberfire.backend.vfs.Path)24 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)23 ArrayList (java.util.ArrayList)20 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)19 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)14 List (java.util.List)13 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)11 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)11 ModuleDataModelOracleImpl (org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)10 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)9 LimitedEntryActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52)9 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)9