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);
}
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());
}
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());
}
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());
}
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;
}
Aggregations