use of org.kie.dmn.feel.lang.FEELProfile in project drools by kiegroup.
the class BaseFEELTest method testExpression.
@Test
public void testExpression() {
final List<FEELProfile> profiles = getFEELProfilesForTests();
feel = FEEL.newInstance(profiles);
final FEELEventListener listener = mock(FEELEventListener.class);
feel.addListener(listener);
feel.addListener(System.out::println);
assertResult(expression, result);
if (severity != null) {
final ArgumentCaptor<FEELEvent> captor = ArgumentCaptor.forClass(FEELEvent.class);
verify(listener, atLeastOnce()).onEvent(captor.capture());
assertThat(captor.getValue().getSeverity(), is(severity));
} else {
verify(listener, never()).onEvent(any(FEELEvent.class));
}
}
use of org.kie.dmn.feel.lang.FEELProfile in project drools by kiegroup.
the class DMNImportPMMLInfo method from.
public static Either<Exception, DMNImportPMMLInfo> from(InputStream is, DMNCompilerConfigurationImpl cc, DMNModelImpl model, Import i) {
try {
final PMML pmml = org.jpmml.model.PMMLUtil.unmarshal(is);
PMMLHeaderInfo h = PMMLInfo.pmmlToHeaderInfo(pmml, pmml.getHeader());
for (DataField df : pmml.getDataDictionary().getDataFields()) {
String dfName = df.getName().getValue();
BuiltInType ft = getBuiltInTypeByDataType(df.getDataType());
List<FEELProfile> helperFEELProfiles = cc.getFeelProfiles();
DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles);
List<UnaryTest> av = new ArrayList<>();
if (df.getValues() != null && !df.getValues().isEmpty() && ft != BuiltInType.UNKNOWN) {
final BuiltInType feelType = ft;
String lov = df.getValues().stream().map(Value::getValue).map(o -> feelType == BuiltInType.STRING ? "\"" + o.toString() + "\"" : o.toString()).collect(Collectors.joining(","));
av = feel.evaluateUnaryTests(lov, Collections.emptyMap());
} else if (df.getIntervals() != null && !df.getIntervals().isEmpty() && ft != BuiltInType.UNKNOWN) {
for (Interval interval : df.getIntervals()) {
String utString = null;
switch(interval.getClosure()) {
case CLOSED_CLOSED:
utString = new StringBuilder("[").append(interval.getLeftMargin()).append("..").append(interval.getRightMargin()).append("]").toString();
break;
case CLOSED_OPEN:
utString = new StringBuilder("[").append(interval.getLeftMargin()).append("..").append(interval.getRightMargin()).append(")").toString();
break;
case OPEN_CLOSED:
utString = new StringBuilder("(").append(interval.getLeftMargin()).append("..").append(interval.getRightMargin()).append("]").toString();
break;
case OPEN_OPEN:
utString = new StringBuilder("(").append(interval.getLeftMargin()).append("..").append(interval.getRightMargin()).append(")").toString();
break;
}
List<UnaryTest> ut = feel.evaluateUnaryTests(utString, Collections.emptyMap());
av.addAll(ut);
}
}
DMNType type = new SimpleTypeImpl(i.getNamespace(), dfName, null, false, av, model.getTypeRegistry().resolveType(model.getDefinitions().getURIFEEL(), ft.getName()), ft);
model.getTypeRegistry().registerType(type);
}
pmml.getModels().stream().forEach(m -> registerOutputFieldType(m, model, i));
List<DMNPMMLModelInfo> models = pmml.getModels().stream().map(m -> PMMLInfo.pmmlToModelInfo(m)).map(proto -> DMNPMMLModelInfo.from(proto, model, i)).collect(Collectors.toList());
DMNImportPMMLInfo info = new DMNImportPMMLInfo(i, models, h);
return Either.ofRight(info);
} catch (Throwable e) {
return Either.ofLeft(new Exception("Unable to process DMNImportPMMLInfo", e));
}
}
use of org.kie.dmn.feel.lang.FEELProfile in project drools by kiegroup.
the class DMNCompilerImpl method compile.
public DMNModel compile(Definitions dmndefs, Collection<DMNModel> dmnModels, Resource resource, Function<String, Reader> relativeResolver) {
if (dmndefs == null) {
return null;
}
DMNModelImpl model = new DMNModelImpl(dmndefs, resource);
model.setRuntimeTypeCheck(((DMNCompilerConfigurationImpl) dmnCompilerConfig).getOption(RuntimeTypeCheckOption.class).isRuntimeTypeCheck());
DMNCompilerConfigurationImpl cc = (DMNCompilerConfigurationImpl) dmnCompilerConfig;
List<FEELProfile> helperFEELProfiles = cc.getFeelProfiles();
DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles);
DMNCompilerContext ctx = new DMNCompilerContext(feel);
ctx.setRelativeResolver(relativeResolver);
if (!dmndefs.getImport().isEmpty()) {
for (Import i : dmndefs.getImport()) {
if (ImportDMNResolverUtil.whichImportType(i) == ImportType.DMN) {
Either<String, DMNModel> resolvedResult = ImportDMNResolverUtil.resolveImportDMN(i, dmnModels, (DMNModel m) -> new QName(m.getNamespace(), m.getName()));
DMNModel located = resolvedResult.cata(msg -> {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, i, model, null, null, Msg.IMPORT_NOT_FOUND_FOR_NODE, msg, i);
return null;
}, Function.identity());
if (located != null) {
String iAlias = Optional.ofNullable(i.getName()).orElse(located.getName());
model.setImportAliasForNS(iAlias, located.getNamespace(), located.getName());
importFromModel(model, located, iAlias);
}
} else if (ImportDMNResolverUtil.whichImportType(i) == ImportType.PMML) {
processPMMLImport(model, i, relativeResolver);
model.setImportAliasForNS(i.getName(), i.getNamespace(), i.getName());
} else {
MsgUtil.reportMessage(logger, DMNMessage.Severity.ERROR, null, model, null, null, Msg.IMPORT_TYPE_UNKNOWN, i.getImportType());
}
}
}
processItemDefinitions(ctx, model, dmndefs);
processDrgElements(ctx, model, dmndefs);
return model;
}
Aggregations