use of org.kie.workbench.common.dmn.api.definition.v1_1.FunctionDefinition in project drools by kiegroup.
the class FunctionDefinitionConverter method writeChildren.
@Override
protected void writeChildren(HierarchicalStreamWriter writer, MarshallingContext context, Object parent) {
super.writeChildren(writer, context, parent);
FunctionDefinition fd = (FunctionDefinition) parent;
for (InformationItem fparam : fd.getFormalParameter()) {
writeChildrenNode(writer, context, fparam, FORMAL_PARAMETER);
}
if (fd.getExpression() != null)
writeChildrenNode(writer, context, fd.getExpression(), MarshallingUtils.defineExpressionNodeName(fd.getExpression()));
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.FunctionDefinition in project drools by kiegroup.
the class BusinessKnowledgeModelCompiler method compileEvaluator.
@Override
public void compileEvaluator(DMNNode node, DMNCompilerImpl compiler, DMNCompilerContext ctx, DMNModelImpl model) {
BusinessKnowledgeModelNodeImpl bkmi = (BusinessKnowledgeModelNodeImpl) node;
compiler.linkRequirements(model, bkmi);
ctx.enterFrame();
try {
for (DMNNode dep : bkmi.getDependencies().values()) {
if (dep instanceof BusinessKnowledgeModelNode) {
// might need to create a DMNType for "functions" and replace the type here by that
ctx.setVariable(dep.getName(), ((BusinessKnowledgeModelNode) dep).getResultType());
}
}
// to allow recursive call from inside a BKM node, a variable for self must be available for the compiler context:
ctx.setVariable(bkmi.getName(), bkmi.getResultType());
FunctionDefinition funcDef = bkmi.getBusinessKnowledModel().getEncapsulatedLogic();
DMNExpressionEvaluator exprEvaluator = compiler.getEvaluatorCompiler().compileExpression(ctx, model, bkmi, bkmi.getName(), funcDef);
bkmi.setEvaluator(exprEvaluator);
} finally {
ctx.exitFrame();
}
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.FunctionDefinition in project kie-wb-common by kiegroup.
the class FunctionDefinitionPropertyConverter method wbFromDMN.
public static FunctionDefinition wbFromDMN(final org.kie.dmn.model.v1_1.FunctionDefinition dmn) {
if (dmn == null) {
return null;
}
Id id = new Id(dmn.getId());
Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
Expression expression = ExpressionPropertyConverter.wbFromDMN(dmn.getExpression());
FunctionDefinition result = new FunctionDefinition(id, description, typeRef, expression);
result.getNsContext().putAll(dmn.getNsContext());
for (Entry<javax.xml.namespace.QName, String> kv : dmn.getAdditionalAttributes().entrySet()) {
QName convertedQName = QNamePropertyConverter.wbFromDMN(kv.getKey());
result.getAdditionalAttributes().put(convertedQName, kv.getValue());
}
for (org.kie.dmn.model.v1_1.InformationItem ii : dmn.getFormalParameter()) {
InformationItem iiConverted = InformationItemPropertyConverter.wbFromDMN(ii);
result.getFormalParameter().add(iiConverted);
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.FunctionDefinition in project kie-wb-common by kiegroup.
the class FunctionDefinitionPropertyConverter method dmnFromWB.
public static org.kie.dmn.model.v1_1.FunctionDefinition dmnFromWB(final FunctionDefinition wb) {
if (wb == null) {
return null;
}
org.kie.dmn.model.v1_1.FunctionDefinition result = new org.kie.dmn.model.v1_1.FunctionDefinition();
result.setId(wb.getId().getValue());
result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
result.setExpression(ExpressionPropertyConverter.dmnFromWB(wb.getExpression()));
result.getNsContext().putAll(wb.getNsContext());
for (Entry<QName, String> kv : wb.getAdditionalAttributes().entrySet()) {
Optional<javax.xml.namespace.QName> convertedQName = QNamePropertyConverter.dmnFromWB(kv.getKey());
if (convertedQName.isPresent()) {
javax.xml.namespace.QName qNameFromWB = convertedQName.get();
String determinePrefix = qNameFromWB.getPrefix();
if (XMLConstants.DEFAULT_NS_PREFIX.equals(determinePrefix)) {
// if the QName for an "additional attribute" was created from WB side, it would not be aware of the prefix, so setting it manually in the direction WB->DMN.
determinePrefix = result.getPrefixForNamespaceURI(qNameFromWB.getNamespaceURI()).orElse(XMLConstants.DEFAULT_NS_PREFIX);
}
javax.xml.namespace.QName qNameWithPrefix = new javax.xml.namespace.QName(qNameFromWB.getNamespaceURI(), qNameFromWB.getLocalPart(), determinePrefix);
result.getAdditionalAttributes().put(qNameWithPrefix, kv.getValue());
}
}
for (InformationItem ii : wb.getFormalParameter()) {
org.kie.dmn.model.v1_1.InformationItem iiConverted = InformationItemPropertyConverter.dmnFromWB(ii);
result.getFormalParameter().add(iiConverted);
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.FunctionDefinition in project kie-wb-common by kiegroup.
the class FunctionGrid method doSetKind.
void doSetKind(final FunctionDefinition.Kind kind, final FunctionDefinition function, final Optional<ExpressionEditorDefinition<Expression>> oDefinition) {
oDefinition.ifPresent(definition -> {
final GridCellTuple expressionParent = new GridCellTuple(0, 0, this);
final Optional<Expression> expression = definition.getModelClass();
final Optional<BaseExpressionGrid> gridWidget = definition.getEditor(expressionParent, Optional.empty(), hasExpression, expression, hasName, nesting);
doSetKind(kind, function, expression, gridWidget);
});
}
Aggregations