use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition in project kie-wb-common by kiegroup.
the class BusinessKnowledgeModelConverter method dmnFromNode.
@Override
public org.kie.dmn.model.api.BusinessKnowledgeModel dmnFromNode(final Node<View<BusinessKnowledgeModel>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) {
final BusinessKnowledgeModel source = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(node);
final org.kie.dmn.model.api.BusinessKnowledgeModel result = new org.kie.dmn.model.v1_2.TBusinessKnowledgeModel();
result.setId(source.getId().getValue());
result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
result.setName(source.getName().getValue());
DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, result);
final org.kie.dmn.model.api.InformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
if (variable != null) {
variable.setParent(result);
}
result.setVariable(variable);
final org.kie.dmn.model.api.FunctionDefinition functionDefinition = FunctionDefinitionPropertyConverter.dmnFromWB(source.getEncapsulatedLogic(), componentWidthsConsumer);
final FunctionDefinition wbFunctionDefinition = source.getEncapsulatedLogic();
if (Objects.nonNull(wbFunctionDefinition)) {
final String uuid = wbFunctionDefinition.getId().getValue();
if (Objects.nonNull(uuid)) {
final ComponentWidths componentWidths = new ComponentWidths();
componentWidths.setDmnElementRef(new QName(uuid));
componentWidths.setWidths(new ArrayList<>(source.getEncapsulatedLogic().getComponentWidths()));
componentWidthsConsumer.accept(componentWidths);
}
}
if (functionDefinition != null) {
functionDefinition.setParent(result);
}
result.setEncapsulatedLogic(functionDefinition);
// DMN spec table 2: Requirements connection rules
final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
for (Edge<?, ?> e : inEdges) {
final Node<?, ?> sourceNode = e.getSourceNode();
if (sourceNode.getContent() instanceof View<?>) {
final View<?> view = (View<?>) sourceNode.getContent();
if (view.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) view.getDefinition();
if (drgElement instanceof BusinessKnowledgeModel) {
final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
result.getKnowledgeRequirement().add(iReq);
} else if (drgElement instanceof KnowledgeSource) {
final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredAuthority(ri);
result.getAuthorityRequirement().add(iReq);
} else if (drgElement instanceof DecisionService) {
if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) {
final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement();
iReq.setId(e.getUUID());
final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
result.getKnowledgeRequirement().add(iReq);
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
}
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition in project kie-wb-common by kiegroup.
the class BusinessKnowledgeModelConverter method nodeFromDMN.
@Override
public Node<View<BusinessKnowledgeModel>, ?> nodeFromDMN(final org.kie.dmn.model.api.BusinessKnowledgeModel dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
@SuppressWarnings("unchecked") final Node<View<BusinessKnowledgeModel>, ?> node = (Node<View<BusinessKnowledgeModel>, ?>) factoryManager.newElement(dmn.getId(), getDefinitionId(BusinessKnowledgeModel.class)).asNode();
final Id id = new Id(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final Name name = new Name(dmn.getName());
final InformationItemPrimary informationItem = InformationItemPrimaryPropertyConverter.wbFromDMN(dmn.getVariable(), dmn);
final org.kie.dmn.model.api.FunctionDefinition dmnFunctionDefinition = dmn.getEncapsulatedLogic();
final FunctionDefinition functionDefinition = FunctionDefinitionPropertyConverter.wbFromDMN(dmnFunctionDefinition, hasComponentWidthsConsumer);
final BusinessKnowledgeModel bkm = new BusinessKnowledgeModel(id, description, name, informationItem, functionDefinition, new StylingSet(), new GeneralRectangleDimensionsSet());
node.getContent().setDefinition(bkm);
if (informationItem != null) {
informationItem.setParent(bkm);
}
if (functionDefinition != null) {
functionDefinition.setParent(bkm);
}
if (Objects.nonNull(dmnFunctionDefinition)) {
hasComponentWidthsConsumer.accept(dmnFunctionDefinition.getId(), functionDefinition);
}
DMNExternalLinksToExtensionElements.loadExternalLinksFromExtensionElements(dmn, bkm);
return node;
}
use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition in project kie-wb-common by kiegroup.
the class FunctionDefinitionPropertyConverter method wbFromDMN.
public static FunctionDefinition wbFromDMN(final org.kie.dmn.model.api.FunctionDefinition dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
if (dmn == null) {
return null;
}
final Id id = new Id(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef(), dmn);
final Expression expression = ExpressionPropertyConverter.wbFromDMN(dmn.getExpression(), hasComponentWidthsConsumer);
final FunctionDefinition result = new FunctionDefinition(id, description, typeRef, expression);
if (expression != null) {
expression.setParent(result);
}
final FunctionKind kind = dmn.getKind();
switch(kind) {
case FEEL:
result.setKind(Kind.FEEL);
break;
case JAVA:
result.setKind(Kind.JAVA);
break;
case PMML:
result.setKind(Kind.PMML);
convertPMMLFunctionExpression(result);
break;
default:
result.setKind(Kind.FEEL);
break;
}
for (org.kie.dmn.model.api.InformationItem ii : dmn.getFormalParameter()) {
final InformationItem iiConverted = InformationItemPropertyConverter.wbFromDMN(ii);
if (iiConverted != null) {
iiConverted.setParent(result);
}
result.getFormalParameter().add(iiConverted);
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition in project kie-wb-common by kiegroup.
the class ExpressionPropertyConverter method dmnFromWB.
public static org.kie.dmn.model.api.Expression dmnFromWB(final Expression wb, final Consumer<ComponentWidths> componentWidthsConsumer) {
if (Objects.isNull(wb)) {
return null;
}
final String uuid = wb.getId().getValue();
if (Objects.nonNull(uuid)) {
final ComponentWidths componentWidths = new ComponentWidths();
componentWidths.setDmnElementRef(new QName(uuid));
componentWidths.setWidths(new ArrayList<>(wb.getComponentWidths()));
componentWidthsConsumer.accept(componentWidths);
}
if (wb instanceof IsLiteralExpression) {
return LiteralExpressionPropertyConverter.dmnFromWB((IsLiteralExpression) wb);
} else if (wb instanceof Context) {
return ContextPropertyConverter.dmnFromWB((Context) wb, componentWidthsConsumer);
} else if (wb instanceof Relation) {
return RelationPropertyConverter.dmnFromWB((Relation) wb, componentWidthsConsumer);
} else if (wb instanceof List) {
return ListPropertyConverter.dmnFromWB((List) wb, componentWidthsConsumer);
} else if (wb instanceof Invocation) {
return InvocationPropertyConverter.dmnFromWB((Invocation) wb, componentWidthsConsumer);
} else if (wb instanceof FunctionDefinition) {
return FunctionDefinitionPropertyConverter.dmnFromWB((FunctionDefinition) wb, componentWidthsConsumer);
} else if (wb instanceof DecisionTable) {
return DecisionTablePropertyConverter.dmnFromWB((DecisionTable) wb);
}
return null;
}
use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition in project kie-wb-common by kiegroup.
the class DMNDeepCloneProcessTest method buildFunctionDefinition.
private FunctionDefinition buildFunctionDefinition() {
final FunctionDefinition encapsulatedLogic = new FunctionDefinition(new Id(FUNCTION_ID), new Description(), new QName(BuiltInType.BOOLEAN), new Context(new Id(CONTEXT_ID), new Description(), new QName(BuiltInType.NUMBER)));
encapsulatedLogic.setKind(JAVA);
return encapsulatedLogic;
}
Aggregations