use of org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource 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.KnowledgeSource 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;
}
use of org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource in project kie-wb-common by kiegroup.
the class KnowledgeSourceConverter method nodeFromDMN.
@Override
public Node<View<KnowledgeSource>, ?> nodeFromDMN(final org.kie.dmn.model.api.KnowledgeSource dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
@SuppressWarnings("unchecked") final Node<View<KnowledgeSource>, ?> node = (Node<View<KnowledgeSource>, ?>) factoryManager.newElement(dmn.getId(), getDefinitionId(KnowledgeSource.class)).asNode();
final Id id = new Id(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final Name name = new Name(dmn.getName());
final KnowledgeSourceType ksType = new KnowledgeSourceType(dmn.getType());
final LocationURI locationURI = new LocationURI(dmn.getLocationURI());
final KnowledgeSource ks = new KnowledgeSource(id, description, name, ksType, locationURI, new StylingSet(), new GeneralRectangleDimensionsSet());
node.getContent().setDefinition(ks);
DMNExternalLinksToExtensionElements.loadExternalLinksFromExtensionElements(dmn, ks);
return node;
}
use of org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource in project kie-wb-common by kiegroup.
the class DMNSVGShapeDefImplTest method testNewViewInstance.
@Test
public void testNewViewInstance() {
final BusinessKnowledgeModel businessKnowledgeModel = new BusinessKnowledgeModel();
shapeDef.newViewInstance(viewFactory, businessKnowledgeModel);
verify(viewFactory).businessKnowledgeModel();
verify(viewResource).build(businessKnowledgeModel.getDimensionsSet().getWidth().getValue(), businessKnowledgeModel.getDimensionsSet().getHeight().getValue(), true);
reset(viewResource);
final Decision decision = new Decision();
shapeDef.newViewInstance(viewFactory, decision);
verify(viewFactory).decision();
verify(viewResource).build(decision.getDimensionsSet().getWidth().getValue(), decision.getDimensionsSet().getHeight().getValue(), true);
reset(viewResource);
shapeDef.newViewInstance(viewFactory, new InputData());
verify(viewFactory).inputData();
verify(viewResource).build(businessKnowledgeModel.getDimensionsSet().getWidth().getValue(), businessKnowledgeModel.getDimensionsSet().getHeight().getValue(), true);
reset(viewResource);
final KnowledgeSource knowledgeSource = new KnowledgeSource();
shapeDef.newViewInstance(viewFactory, knowledgeSource);
verify(viewFactory).knowledgeSource();
verify(viewResource).build(knowledgeSource.getDimensionsSet().getWidth().getValue(), knowledgeSource.getDimensionsSet().getHeight().getValue(), true);
reset(viewResource);
final TextAnnotation textAnnotation = new TextAnnotation();
shapeDef.newViewInstance(viewFactory, textAnnotation);
verify(viewFactory).textAnnotation();
verify(viewResource).build(textAnnotation.getDimensionsSet().getWidth().getValue(), textAnnotation.getDimensionsSet().getHeight().getValue(), true);
}
use of org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource in project kie-wb-common by kiegroup.
the class DecisionNavigatorItemsProviderTest method testGetItems.
@Test
public void testGetItems() {
final Diagram stunnerDiagram1 = mock(Diagram.class);
final Diagram stunnerDiagram2 = mock(Diagram.class);
final DMNDiagramElement dmnDiagramElement1 = mock(DMNDiagramElement.class);
final DMNDiagramElement dmnDiagramElement2 = mock(DMNDiagramElement.class);
final DMNDiagramTuple dmnDiagramTuple1 = new DMNDiagramTuple(stunnerDiagram1, dmnDiagramElement1);
final DMNDiagramTuple dmnDiagramTuple2 = new DMNDiagramTuple(stunnerDiagram2, dmnDiagramElement2);
final DecisionNavigatorItem decisionNavigatorItem1 = mock(DecisionNavigatorItem.class);
final DecisionNavigatorItem decisionNavigatorItem2 = mock(DecisionNavigatorItem.class);
final DecisionNavigatorItem decisionNavigatorItem3 = mock(DecisionNavigatorItem.class);
final DecisionNavigatorItem decisionNavigatorItem4 = mock(DecisionNavigatorItem.class);
final DecisionNavigatorItem decisionNavigatorItem5 = mock(DecisionNavigatorItem.class);
final DecisionNavigatorItem decisionNavigatorItem6 = mock(DecisionNavigatorItem.class);
final DecisionNavigatorItem decisionNavigatorItem7 = mock(DecisionNavigatorItem.class);
final DecisionNavigatorItem decisionNavigatorItem8 = mock(DecisionNavigatorItem.class);
final DecisionNavigatorItem decisionNavigatorItem9 = mock(DecisionNavigatorItem.class);
final DecisionNavigatorItem decisionNavigatorItem10 = mock(DecisionNavigatorItem.class);
final List<DMNDiagramTuple> diagramTuples = asList(dmnDiagramTuple1, dmnDiagramTuple2);
final Node node1 = mockNode(new Decision());
final Node node2 = mockNode(new InputData());
final Node node3 = mockNode(new TextAnnotation());
final Node node4 = mockNode(new BusinessKnowledgeModel());
final Node node5 = mockNode(new KnowledgeSource());
final Node node6 = mockNode(new TextAnnotation());
final Stream<Node> stunnerNodes1 = Stream.of(node1, node2, node3);
final Stream<Node> stunnerNodes2 = Stream.of(node4, node5, node6);
when(dmnDiagramElement1.getName()).thenReturn(new Name("DRD"));
when(dmnDiagramElement2.getName()).thenReturn(new Name("DRG"));
when(dmnDiagramsSession.getDMNDiagrams()).thenReturn(diagramTuples);
when(itemFactory.makeRoot(dmnDiagramTuple1)).thenReturn(decisionNavigatorItem1);
when(itemFactory.makeRoot(dmnDiagramTuple2)).thenReturn(decisionNavigatorItem2);
when(itemFactory.makeItem(node1)).thenReturn(decisionNavigatorItem5);
when(itemFactory.makeItem(node2)).thenReturn(decisionNavigatorItem6);
when(itemFactory.makeItem(node3)).thenReturn(decisionNavigatorItem7);
when(itemFactory.makeItem(node4)).thenReturn(decisionNavigatorItem8);
when(itemFactory.makeItem(node5)).thenReturn(decisionNavigatorItem9);
when(itemFactory.makeItem(node6)).thenReturn(decisionNavigatorItem10);
when(itemFactory.makeSeparator(DRG)).thenReturn(decisionNavigatorItem3);
when(itemFactory.makeSeparator(DRDs)).thenReturn(decisionNavigatorItem4);
when(dmnDiagramUtils.getNodeStream(stunnerDiagram1)).thenReturn(stunnerNodes1);
when(dmnDiagramUtils.getNodeStream(stunnerDiagram2)).thenReturn(stunnerNodes2);
final List<DecisionNavigatorItem> actualItems = itemsProvider.getItems();
final List<DecisionNavigatorItem> expectedItems = asList(decisionNavigatorItem3, decisionNavigatorItem2, decisionNavigatorItem4, decisionNavigatorItem1);
assertEquals(expectedItems, actualItems);
verify(decisionNavigatorItem1).addChild(decisionNavigatorItem5);
verify(decisionNavigatorItem1).addChild(decisionNavigatorItem6);
verify(decisionNavigatorItem1).addChild(decisionNavigatorItem7);
verify(decisionNavigatorItem2).addChild(decisionNavigatorItem8);
verify(decisionNavigatorItem2).addChild(decisionNavigatorItem9);
verify(decisionNavigatorItem2).addChild(decisionNavigatorItem10);
}
Aggregations