use of org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel in project kie-wb-common by kiegroup.
the class DMNMarshallerStandalone method stunnerToDDExt.
@SuppressWarnings("unchecked")
private static DMNShape stunnerToDDExt(final Definitions definitions, final View<? extends DMNElement> v) {
final DMNShape result = new org.kie.dmn.model.v1_2.dmndi.DMNShape();
result.setId("dmnshape-" + v.getDefinition().getId().getValue());
result.setDmnElementRef(getDmnElementRef(definitions, v));
final Bounds bounds = new org.kie.dmn.model.v1_2.dmndi.Bounds();
result.setBounds(bounds);
bounds.setX(xOfBound(upperLeftBound(v)));
bounds.setY(yOfBound(upperLeftBound(v)));
result.setStyle(new org.kie.dmn.model.v1_2.dmndi.DMNStyle());
result.setDMNLabel(new org.kie.dmn.model.v1_2.dmndi.DMNLabel());
if (v.getDefinition() instanceof Decision) {
final Decision d = (Decision) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyBackgroundStyles(d.getStylingSet(), result);
applyFontStyle(d.getStylingSet(), result);
} else if (v.getDefinition() instanceof InputData) {
final InputData d = (InputData) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyBackgroundStyles(d.getStylingSet(), result);
applyFontStyle(d.getStylingSet(), result);
} else if (v.getDefinition() instanceof BusinessKnowledgeModel) {
final BusinessKnowledgeModel d = (BusinessKnowledgeModel) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyBackgroundStyles(d.getStylingSet(), result);
applyFontStyle(d.getStylingSet(), result);
} else if (v.getDefinition() instanceof KnowledgeSource) {
final KnowledgeSource d = (KnowledgeSource) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyBackgroundStyles(d.getStylingSet(), result);
applyFontStyle(d.getStylingSet(), result);
} else if (v.getDefinition() instanceof TextAnnotation) {
final TextAnnotation d = (TextAnnotation) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyBackgroundStyles(d.getStylingSet(), result);
applyFontStyle(d.getStylingSet(), result);
} else if (v.getDefinition() instanceof DecisionService) {
final DecisionService d = (DecisionService) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyBackgroundStyles(d.getStylingSet(), result);
applyFontStyle(d.getStylingSet(), result);
final DMNDecisionServiceDividerLine dl = new org.kie.dmn.model.v1_2.dmndi.DMNDecisionServiceDividerLine();
final org.kie.dmn.model.api.dmndi.Point leftPoint = new org.kie.dmn.model.v1_2.dmndi.Point();
leftPoint.setX(v.getBounds().getUpperLeft().getX());
final double dlY = v.getBounds().getUpperLeft().getY() + d.getDividerLineY().getValue();
leftPoint.setY(dlY);
dl.getWaypoint().add(leftPoint);
final org.kie.dmn.model.api.dmndi.Point rightPoint = new org.kie.dmn.model.v1_2.dmndi.Point();
rightPoint.setX(v.getBounds().getLowerRight().getX());
rightPoint.setY(dlY);
dl.getWaypoint().add(rightPoint);
result.setDMNDecisionServiceDividerLine(dl);
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel 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.BusinessKnowledgeModel 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.BusinessKnowledgeModel in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsBKM.
@Test
public void testModelEnrichmentWhenParentIsBKM() {
final FunctionDefinition functionDefinition = mock(FunctionDefinition.class);
final DMNModelInstrumentedBase dmnModelInstrumentedBase = mock(DMNModelInstrumentedBase.class);
final BusinessKnowledgeModel businessKnowledgeModel = new BusinessKnowledgeModel();
businessKnowledgeModel.setVariable(new InformationItemPrimary(new Id(), new Name(), OUTPUT_DATA_QNAME));
businessKnowledgeModel.setEncapsulatedLogic(functionDefinition);
final Optional<DecisionTable> oModel = definition.getModelClass();
oModel.get().setParent(functionDefinition);
when(functionDefinition.asDMNModelInstrumentedBase()).thenReturn(dmnModelInstrumentedBase);
when(dmnModelInstrumentedBase.getParent()).thenReturn(businessKnowledgeModel);
definition.enrich(Optional.empty(), functionDefinition, oModel);
final DecisionTable model = oModel.get();
assertBasicEnrichment(model);
assertStandardInputClauseEnrichment(model);
final List<OutputClause> output = model.getOutput();
assertThat(output.size()).isEqualTo(1);
assertThat(output.get(0).getName()).isEqualTo(DEFAULT_OUTPUT_NAME);
assertThat(output.get(0).getTypeRef()).isEqualTo(OUTPUT_DATA_QNAME);
assertStandardDecisionRuleEnrichment(model);
assertParentHierarchyEnrichment(model);
}
use of org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel in project kie-wb-common by kiegroup.
the class BoxedExpressionHelper method getOptionalHasExpression.
public Optional<HasExpression> getOptionalHasExpression(final Node<View, Edge> node) {
final Object definition = DefinitionUtils.getElementDefinition(node);
final HasExpression expression;
if (definition instanceof BusinessKnowledgeModel) {
expression = ((BusinessKnowledgeModel) definition).asHasExpression();
} else if (definition instanceof Decision) {
expression = (Decision) definition;
} else {
expression = null;
}
return Optional.ofNullable(expression);
}
Aggregations