use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition in project kie-wb-common by kiegroup.
the class BusinessKnowledgeModelConverter method dmnFromNode.
@Override
@SuppressWarnings("unchecked")
public JSITBusinessKnowledgeModel dmnFromNode(final Node<View<BusinessKnowledgeModel>, ?> node, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
final BusinessKnowledgeModel source = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(node);
final JSITBusinessKnowledgeModel result = new JSITBusinessKnowledgeModel();
result.setId(source.getId().getValue());
final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
description.ifPresent(result::setDescription);
result.setName(source.getName().getValue());
// Add because it is present in the original JSON when unmarshalling
if (Objects.isNull(result.getKnowledgeRequirement())) {
result.setKnowledgeRequirement(new ArrayList<>());
}
// Add because it is present in the original JSON when unmarshalling
if (Objects.isNull(result.getAuthorityRequirement())) {
result.setAuthorityRequirement(new ArrayList<>());
}
DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, result);
final JSITInformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
result.setVariable(variable);
final JSITFunctionDefinition 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 JSITComponentWidths componentWidths = new JSITComponentWidths();
componentWidths.setDmnElementRef(uuid);
source.getEncapsulatedLogic().getComponentWidths().stream().filter(Objects::nonNull).forEach(w -> componentWidths.addWidth(new Float(w)));
componentWidthsConsumer.accept(componentWidths);
}
}
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 JSITKnowledgeRequirement iReq = new JSITKnowledgeRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
result.addKnowledgeRequirement(iReq);
} else if (drgElement instanceof KnowledgeSource) {
final JSITAuthorityRequirement iReq = new JSITAuthorityRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredAuthority(ri);
result.addAuthorityRequirement(iReq);
} else if (drgElement instanceof DecisionService) {
if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) {
final JSITKnowledgeRequirement iReq = new JSITKnowledgeRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredKnowledge(ri);
result.addKnowledgeRequirement(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 NodeEntry nodeEntry) {
final JSITBusinessKnowledgeModel dmn = Js.uncheckedCast(nodeEntry.getDmnElement());
@SuppressWarnings("unchecked") final Node<View<BusinessKnowledgeModel>, ?> node = (Node<View<BusinessKnowledgeModel>, ?>) factoryManager.newElement(nodeEntry.getId(), getDefinitionId(BusinessKnowledgeModel.class)).asNode();
final Id id = IdPropertyConverter.wbFromDMN(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 JSITFunctionDefinition dmnFunctionDefinition = dmn.getEncapsulatedLogic();
final FunctionDefinition functionDefinition = FunctionDefinitionPropertyConverter.wbFromDMN(dmnFunctionDefinition, nodeEntry.getComponentWidthsConsumer());
final BusinessKnowledgeModel bkm = new BusinessKnowledgeModel(id, description, name, informationItem, functionDefinition, new StylingSet(), new GeneralRectangleDimensionsSet());
bkm.setDiagramId(nodeEntry.getDiagramId());
node.getContent().setDefinition(bkm);
if (Objects.nonNull(informationItem)) {
informationItem.setParent(bkm);
}
if (Objects.nonNull(functionDefinition)) {
functionDefinition.setParent(bkm);
}
if (Objects.nonNull(dmnFunctionDefinition)) {
nodeEntry.getComponentWidthsConsumer().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 RegisterNodeCommandTest method testExecuteWithBusinessKnowledgeModelNode.
@Test
public void testExecuteWithBusinessKnowledgeModelNode() {
when(candidateContent.getDefinition()).thenReturn(businessKnowledgeModel);
assertThat(command.execute(graphCommandExecutionContext).getType()).isEqualTo(CommandResult.Type.INFO);
final FunctionDefinition encapsulatedLogic = businessKnowledgeModel.getEncapsulatedLogic();
final Expression expression = encapsulatedLogic.getExpression();
assertThat(expression).isInstanceOf(LiteralExpression.class);
assertThat(expression.getParent()).isEqualTo(encapsulatedLogic);
assertThat(KindUtilities.getKind(encapsulatedLogic)).isEqualTo(FunctionDefinition.Kind.FEEL);
}
use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition in project kie-wb-common by kiegroup.
the class RegisterNodeCommand method setupEncapsulatedLogic.
private void setupEncapsulatedLogic(final BusinessKnowledgeModel businessKnowledgeModel) {
final LiteralExpression le = new LiteralExpression();
final FunctionDefinition function = new FunctionDefinition();
KindUtilities.setKind(function, FunctionDefinition.Kind.FEEL);
function.setExpression(le);
le.setParent(function);
businessKnowledgeModel.setEncapsulatedLogic(function);
function.setParent(businessKnowledgeModel);
}
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 JSITFunctionDefinition dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
if (Objects.isNull(dmn)) {
return null;
}
final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
Expression expression = null;
final JSITExpression jsiWrapped = dmn.getExpression();
if (Objects.nonNull(jsiWrapped)) {
final JSITExpression jsiExpression = Js.uncheckedCast(JsUtils.getUnwrappedElement(jsiWrapped));
expression = ExpressionPropertyConverter.wbFromDMN(jsiExpression, Js.uncheckedCast(dmn), hasComponentWidthsConsumer);
}
final FunctionDefinition result = new FunctionDefinition(id, description, typeRef, expression);
if (Objects.nonNull(expression)) {
expression.setParent(result);
}
// JSITFunctionKind is a String JSO so convert into the real type
final String sKind = Js.uncheckedCast(dmn.getKind());
final Kind kind = Kind.fromValue(sKind);
switch(kind) {
case FEEL:
result.setKind(Kind.FEEL);
break;
case JAVA:
result.setKind(Kind.JAVA);
break;
case PMML:
result.setKind(Kind.PMML);
convertPMMLFunctionExpression(result, hasComponentWidthsConsumer);
break;
default:
result.setKind(Kind.FEEL);
break;
}
final List<JSITInformationItem> jsiInformationItems = dmn.getFormalParameter();
for (int i = 0; i < jsiInformationItems.size(); i++) {
final JSITInformationItem jsiInformationItem = Js.uncheckedCast(jsiInformationItems.get(i));
final InformationItem iiConverted = InformationItemPropertyConverter.wbFromDMN(jsiInformationItem);
if (Objects.nonNull(iiConverted)) {
iiConverted.setParent(result);
}
result.getFormalParameter().add(iiConverted);
}
return result;
}
Aggregations