use of org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel in project kie-wb-common by kiegroup.
the class DefaultValueUtilitiesTest method testUpdateNewNodeName_TextAnnotation.
@Test
public void testUpdateNewNodeName_TextAnnotation() {
// Add some existing nodes to ensure naming is not affected by existing content
graph.addNode(makeMockNode(new BusinessKnowledgeModel()));
graph.addNode(makeMockNode(new Decision()));
graph.addNode(makeMockNode(new InputData()));
graph.addNode(makeMockNode(new KnowledgeSource()));
final TextAnnotation textAnnotation1 = new TextAnnotation();
final TextAnnotation textAnnotation2 = new TextAnnotation();
final TextAnnotation textAnnotation3 = new TextAnnotation();
final TextAnnotation textAnnotation4 = new TextAnnotation();
assertUpdateNewNodeName(textAnnotation1, textAnnotation2, (textAnnotation) -> textAnnotation.getText().getValue(), () -> TextAnnotation.class.getSimpleName() + "-1", () -> TextAnnotation.class.getSimpleName() + "-2");
// Update existing names manually and add two more
textAnnotation1.getText().setValue("textAnnotation");
textAnnotation2.getText().setValue(TextAnnotation.class.getSimpleName() + "-5");
assertUpdateNewNodeName(textAnnotation3, textAnnotation4, (textAnnotation) -> textAnnotation.getText().getValue(), () -> TextAnnotation.class.getSimpleName() + "-6", () -> TextAnnotation.class.getSimpleName() + "-7");
}
use of org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel in project kie-wb-common by kiegroup.
the class WrapperUtils method stunnerToDDExt.
private static JSIDMNShape stunnerToDDExt(final JSIDMNDiagram diagram, final List<String> dmnDiagramElementIds, final Definitions definitionsStunnerPojo, final View<? extends DMNElement> v, final String namespaceURI) {
final JSIDMNShape result = new JSIDMNShape();
final DMNElement definition = v.getDefinition();
final String dmnElementId = definition.getId().getValue();
final String shapeId = getShapeId(diagram, dmnDiagramElementIds, dmnElementId);
result.setId(shapeId);
result.setDmnElementRef(getDmnElementRef(definitionsStunnerPojo, v, namespaceURI));
final JSIBounds bounds = new JSIBounds();
result.setBounds(bounds);
bounds.setX(xOfBound(upperLeftBound(v)));
bounds.setY(yOfBound(upperLeftBound(v)));
result.setDMNLabel(new JSIDMNLabel());
// TODO {gcardosi}: HARDCODED
result.setIsCollapsed(false);
final JSIDMNStyle style = new JSIDMNStyle();
if (v.getDefinition() instanceof Decision) {
final Decision d = (Decision) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyStylingStyles(d.getStylingSet(), style);
} else if (v.getDefinition() instanceof InputData) {
InputData d = (InputData) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyStylingStyles(d.getStylingSet(), style);
} else if (v.getDefinition() instanceof BusinessKnowledgeModel) {
final BusinessKnowledgeModel d = (BusinessKnowledgeModel) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyStylingStyles(d.getStylingSet(), style);
} else if (v.getDefinition() instanceof KnowledgeSource) {
final KnowledgeSource d = (KnowledgeSource) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyStylingStyles(d.getStylingSet(), style);
} else if (v.getDefinition() instanceof TextAnnotation) {
final TextAnnotation d = (TextAnnotation) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyStylingStyles(d.getStylingSet(), style);
} else if (v.getDefinition() instanceof DecisionService) {
final DecisionService d = (DecisionService) v.getDefinition();
applyBounds(d.getDimensionsSet(), bounds);
applyStylingStyles(d.getStylingSet(), style);
final JSIDMNDecisionServiceDividerLine dl = new JSIDMNDecisionServiceDividerLine();
final JSIPoint leftPoint = new JSIPoint();
leftPoint.setX(v.getBounds().getUpperLeft().getX());
final double dlY = v.getBounds().getUpperLeft().getY() + d.getDividerLineY().getValue();
leftPoint.setY(dlY);
dl.addWaypoint(leftPoint);
final JSIPoint rightPoint = new JSIPoint();
rightPoint.setX(v.getBounds().getLowerRight().getX());
rightPoint.setY(dlY);
dl.addWaypoint(rightPoint);
result.setDMNDecisionServiceDividerLine(dl);
}
result.setStyle(getWrappedJSIDMNStyle(style));
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel in project kie-wb-common by kiegroup.
the class BusinessKnowledgeModelConverterTest method testWBFromDMN.
@Test
@SuppressWarnings("unchecked")
public void testWBFromDMN() {
final Node<View<BusinessKnowledgeModel>, ?> factoryNode = new NodeImpl<>(UUID.uuid());
final View<BusinessKnowledgeModel> view = new ViewImpl<>(new BusinessKnowledgeModel(), Bounds.create());
factoryNode.setContent(view);
when(factoryManager.newElement(Mockito.<String>any(), eq(getDefinitionId(BusinessKnowledgeModel.class)))).thenReturn(element);
when(element.asNode()).thenReturn(factoryNode);
final org.kie.dmn.model.api.BusinessKnowledgeModel dmn = new TBusinessKnowledgeModel();
final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
final org.kie.dmn.model.api.InformationItem informationItem = new TInformationItem();
final org.kie.dmn.model.api.FunctionDefinition functionDefinition = new TFunctionDefinition();
literalExpression.setId(EXPRESSION_UUID);
functionDefinition.setExpression(literalExpression);
functionDefinition.setId(FUNCTION_DEFINITION_UUID);
dmn.setId(DECISION_UUID);
dmn.setName(DECISION_NAME);
dmn.setDescription(DECISION_DESCRIPTION);
dmn.setVariable(informationItem);
dmn.setEncapsulatedLogic(functionDefinition);
final Node<View<BusinessKnowledgeModel>, ?> node = converter.nodeFromDMN(dmn, hasComponentWidthsConsumer);
final BusinessKnowledgeModel wb = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(node);
assertThat(wb).isNotNull();
assertThat(wb.getId()).isNotNull();
assertThat(wb.getId().getValue()).isEqualTo(DECISION_UUID);
assertThat(wb.getName()).isNotNull();
assertThat(wb.getName().getValue()).isEqualTo(DECISION_NAME);
assertThat(wb.getDescription()).isNotNull();
assertThat(wb.getDescription().getValue()).isEqualTo(DECISION_DESCRIPTION);
assertThat(wb.getVariable()).isNotNull();
assertThat(wb.getVariable().getName().getValue()).isEqualTo(DECISION_NAME);
assertThat(wb.getEncapsulatedLogic()).isNotNull();
assertThat(wb.getEncapsulatedLogic().getExpression()).isNotNull();
assertThat(wb.getEncapsulatedLogic().getExpression().getId().getValue()).isEqualTo(EXPRESSION_UUID);
verify(hasComponentWidthsConsumer).accept(eq(EXPRESSION_UUID), hasComponentWidthsCaptor.capture());
final HasComponentWidths hasComponentWidths0 = hasComponentWidthsCaptor.getValue();
assertThat(hasComponentWidths0).isNotNull();
assertThat(hasComponentWidths0).isEqualTo(wb.getEncapsulatedLogic().getExpression());
verify(hasComponentWidthsConsumer).accept(eq(FUNCTION_DEFINITION_UUID), hasComponentWidthsCaptor.capture());
final HasComponentWidths hasComponentWidths1 = hasComponentWidthsCaptor.getValue();
assertThat(hasComponentWidths1).isNotNull();
assertThat(hasComponentWidths1).isEqualTo(wb.getEncapsulatedLogic());
}
use of org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel in project kie-wb-common by kiegroup.
the class DMNMarshallerStandalone method ddExtAugmentStunner.
private void ddExtAugmentStunner(final Optional<org.kie.dmn.model.api.dmndi.DMNDiagram> dmnDDDiagram, Node currentNode) {
if (!dmnDDDiagram.isPresent()) {
return;
}
final Stream<DMNShape> drgShapeStream = dmnDDDiagram.get().getDMNDiagramElement().stream().filter(DMNShape.class::isInstance).map(DMNShape.class::cast);
final View content = (View) currentNode.getContent();
final Bound ulBound = upperLeftBound(content);
final Bound lrBound = lowerRightBound(content);
if (content.getDefinition() instanceof Decision) {
final Decision d = (Decision) content.getDefinition();
internalAugment(drgShapeStream, d.getId(), ulBound, d.getDimensionsSet(), lrBound, d.getStylingSet());
} else if (content.getDefinition() instanceof InputData) {
final InputData d = (InputData) content.getDefinition();
internalAugment(drgShapeStream, d.getId(), ulBound, d.getDimensionsSet(), lrBound, d.getStylingSet());
} else if (content.getDefinition() instanceof BusinessKnowledgeModel) {
final BusinessKnowledgeModel d = (BusinessKnowledgeModel) content.getDefinition();
internalAugment(drgShapeStream, d.getId(), ulBound, d.getDimensionsSet(), lrBound, d.getStylingSet());
} else if (content.getDefinition() instanceof KnowledgeSource) {
final KnowledgeSource d = (KnowledgeSource) content.getDefinition();
internalAugment(drgShapeStream, d.getId(), ulBound, d.getDimensionsSet(), lrBound, d.getStylingSet());
} else if (content.getDefinition() instanceof TextAnnotation) {
final TextAnnotation d = (TextAnnotation) content.getDefinition();
internalAugment(drgShapeStream, d.getId(), ulBound, d.getDimensionsSet(), lrBound, d.getStylingSet());
} else if (content.getDefinition() instanceof DecisionService) {
final DecisionService d = (DecisionService) content.getDefinition();
internalAugment(drgShapeStream, d.getId(), ulBound, d.getDimensionsSet(), lrBound, d.getStylingSet(), dividerLineY -> d.setDividerLineY(new DecisionServiceDividerLineY(dividerLineY - ulBound.getY())));
}
}
use of org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel in project kie-wb-common by kiegroup.
the class DecisionConverter method dmnFromNode.
@Override
public org.kie.dmn.model.api.Decision dmnFromNode(final Node<View<Decision>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) {
final Decision source = (Decision) DefinitionUtils.getElementDefinition(node);
final org.kie.dmn.model.api.Decision d = new org.kie.dmn.model.v1_2.TDecision();
d.setId(source.getId().getValue());
d.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
d.setName(source.getName().getValue());
final org.kie.dmn.model.api.InformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
if (variable != null) {
variable.setParent(d);
}
d.setVariable(variable);
final org.kie.dmn.model.api.Expression expression = ExpressionPropertyConverter.dmnFromWB(source.getExpression(), componentWidthsConsumer);
if (expression != null) {
expression.setParent(d);
}
d.setExpression(expression);
d.setQuestion(QuestionPropertyConverter.dmnFromWB(source.getQuestion()));
d.setAllowedAnswers(AllowedAnswersPropertyConverter.dmnFromWB(source.getAllowedAnswers()));
// 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 Decision) {
final org.kie.dmn.model.api.InformationRequirement iReq = new org.kie.dmn.model.v1_2.TInformationRequirement();
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.setRequiredDecision(ri);
d.getInformationRequirement().add(iReq);
} else 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);
d.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);
d.getAuthorityRequirement().add(iReq);
} else if (drgElement instanceof InputData) {
final org.kie.dmn.model.api.InformationRequirement iReq = new org.kie.dmn.model.v1_2.TInformationRequirement();
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.setRequiredInput(ri);
d.getInformationRequirement().add(iReq);
} else if (drgElement instanceof DecisionService) {
if (e.getContent() instanceof Child) {
// Stunner relationship of this Decision be encapsulated by the DecisionService, not managed here.
} else 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);
d.getKnowledgeRequirement().add(iReq);
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
}
}
DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, d);
return d;
}
Aggregations