use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DecisionServiceConverter method dmnFromNode.
@Override
@SuppressWarnings("unchecked")
public JSITDecisionService dmnFromNode(final Node<View<DecisionService>, ?> node, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
final DecisionService source = (DecisionService) DefinitionUtils.getElementDefinition(node);
final JSITDecisionService ds = new JSITDecisionService();
ds.setId(source.getId().getValue());
final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
description.ifPresent(ds::setDescription);
ds.setName(source.getName().getValue());
final JSITInformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
ds.setVariable(variable);
final List<JSITDMNElementReference> existing_outputDecision = source.getOutputDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
final List<JSITDMNElementReference> existing_encapsulatedDecision = source.getEncapsulatedDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
final List<JSITDMNElementReference> existing_inputDecision = source.getInputDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
final List<JSITDMNElementReference> existing_inputData = source.getInputData().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
final List<JSITDMNElementReference> candidate_outputDecision = new ArrayList<>();
final List<JSITDMNElementReference> candidate_encapsulatedDecision = new ArrayList<>();
final List<JSITDMNElementReference> candidate_inputDecision = new ArrayList<>();
final List<JSITDMNElementReference> candidate_inputData = new ArrayList<>();
final HashSet<InputData> reqInputs = new HashSet();
final HashSet<Decision> reqDecisions = new HashSet();
// DMN spec table 2: Requirements connection rules
final List<Edge<?, ?>> outEdges = (List<Edge<?, ?>>) node.getOutEdges();
for (Edge<?, ?> e : outEdges) {
if (e.getContent() instanceof Child) {
@SuppressWarnings("unchecked") final Node<View<?>, ?> targetNode = e.getTargetNode();
final View<?> targetNodeView = targetNode.getContent();
if (targetNodeView.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) targetNodeView.getDefinition();
if (drgElement instanceof Decision) {
final Decision decision = (Decision) drgElement;
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref("#" + decision.getId().getValue());
if (isOutputDecision(targetNode.getContent(), node.getContent())) {
candidate_outputDecision.add(ri);
} else {
candidate_encapsulatedDecision.add(ri);
final List<Node> all = diagramsSession.getNodesFromAllDiagramsWithContentId(drgElement.getContentDefinitionId());
for (final Node other : all) {
if (!Objects.equals(other, targetNode)) {
inspectDecisionForDSReqs(other, reqInputs, reqDecisions);
}
}
}
inspectDecisionForDSReqs(targetNode, reqInputs, reqDecisions);
} else {
throw new UnsupportedOperationException("wrong model definition: a DecisionService is expected to encapsulate only Decision");
}
}
} else if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) {
// this was taken care by the receiving Decision or BKM.
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
reqInputs.stream().sorted(Comparator.comparing(x -> x.getName().getValue())).map(x -> {
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref("#" + x.getId().getValue());
return ri;
}).forEach(ri -> candidate_inputData.add(Js.uncheckedCast(ri)));
reqDecisions.stream().sorted(Comparator.comparing(x -> x.getName().getValue())).map(x -> {
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref("#" + x.getId().getValue());
return ri;
}).forEach(rs -> candidate_inputDecision.add(Js.uncheckedCast(rs)));
for (int i = 0; i < candidate_outputDecision.size(); i++) {
final JSITDMNElementReference er = Js.uncheckedCast(candidate_outputDecision.get(i));
candidate_inputDecision.removeIf(x -> x.getHref().equals(er.getHref()));
}
for (int i = 0; i < candidate_encapsulatedDecision.size(); i++) {
final JSITDMNElementReference er = Js.uncheckedCast(candidate_encapsulatedDecision.get(i));
candidate_inputDecision.removeIf(x -> x.getHref().equals(er.getHref()));
}
ds.setInputData(reconcileExistingAndCandidate(existing_inputData, candidate_inputData));
ds.setInputDecision(reconcileExistingAndCandidate(existing_inputDecision, candidate_inputDecision));
ds.setEncapsulatedDecision(reconcileExistingAndCandidate(existing_encapsulatedDecision, candidate_encapsulatedDecision));
ds.setOutputDecision(reconcileExistingAndCandidate(existing_outputDecision, candidate_outputDecision));
DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, ds);
return ds;
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DMNIncludedNodeFactoryTest method testMakeDMNIncludeModel.
@Test
public void testMakeDMNIncludeModel() {
final Path path = mock(Path.class);
final IncludedModel includedModel = mock(IncludedModel.class);
final String drgElementId = "0000-1111-3333-4444";
final String drgElementName = "Can Drive?";
final String expectedFileName = "file.dmn";
final String expectedModelName = "model";
final String expectedImportedElementId = "0000-1111-3333-4444";
final String expectedImportedElementName = "model.Can Drive?";
final String expectedImportedItemDefinitionName = "model.tCustomBoolean";
final DRGElement importedElementId = makeDecision(drgElementId, drgElementName, "tCustomBoolean");
when(path.getFileName()).thenReturn(expectedFileName);
when(includedModel.getModelName()).thenReturn(expectedModelName);
final DMNIncludedNode node = factory.makeDMNIncludeModel(path, includedModel, importedElementId);
final Decision drgElement = (Decision) node.getDrgElement();
assertEquals(expectedImportedElementId, drgElement.getId().getValue());
assertEquals(expectedImportedElementName, drgElement.getName().getValue());
assertEquals(expectedImportedItemDefinitionName, drgElement.getVariable().getTypeRef().getLocalPart());
assertEquals(expectedFileName, node.getFileName());
assertTrue(drgElement.isAllowOnlyVisualChange());
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class HrefBuilderTest method testGetHrefForImportedDRGElementWhenImportHasAnOddName.
@Test
public void testGetHrefForImportedDRGElementWhenImportHasAnOddName() {
final DRGElement drgElement = mock(DRGElement.class);
final Name drgElementName = mock(Name.class);
final Name importName = mock(Name.class);
final Id id = mock(Id.class);
final Definitions definitions = mock(Definitions.class);
final Import anImport = mock(Import.class);
final List<Import> imports = singletonList(anImport);
final String includedModelName = "d.i.v.i.";
when(importName.getValue()).thenReturn(includedModelName);
when(anImport.getName()).thenReturn(importName);
when(anImport.getNamespace()).thenReturn("https://github.com/kiegroup/dmn/something");
when(id.getValue()).thenReturn("0000-1111-2222");
when(drgElementName.getValue()).thenReturn(includedModelName + ".Decision");
when(drgElement.getId()).thenReturn(id);
when(drgElement.getName()).thenReturn(drgElementName);
when(drgElement.getParent()).thenReturn(definitions);
when(definitions.getImport()).thenReturn(imports);
final String actual = HrefBuilder.getHref(drgElement);
final String expected = "https://github.com/kiegroup/dmn/something#0000-1111-2222";
assertEquals(expected, actual);
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class HrefBuilderTest method testGetHref.
@Test
public void testGetHref() {
final DRGElement drgElement = mock(DRGElement.class);
final Name name = mock(Name.class);
final Id id = mock(Id.class);
final Definitions definitions = mock(Definitions.class);
final String uuid = "0000-1111-2222";
when(id.getValue()).thenReturn(uuid);
when(name.getValue()).thenReturn("Decision");
when(drgElement.getId()).thenReturn(id);
when(drgElement.getName()).thenReturn(name);
when(drgElement.getParent()).thenReturn(definitions);
when(definitions.getImport()).thenReturn(Collections.emptyList());
final String actual = HrefBuilder.getHref(drgElement);
final String expected = "#" + uuid;
assertEquals(expected, actual);
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DecisionComponentsItemViewTest method testMakeDragProxyCallbackImplWhenNodeIsDuplicated.
@Test
public void testMakeDragProxyCallbackImplWhenNodeIsDuplicated() {
final ShapeFactory factory = mock(ShapeFactory.class);
final DRGElement drgElement = mock(DRGElement.class);
final int x = 10;
final int y = 20;
final String expectedWarnMessage = "This 'DRGElement' already exists!";
final NotificationEvent.NotificationType expectedWarnType = WARNING;
final Graph<?, Node> graph = mock(Graph.class);
final List<Node> nodes = new ArrayList<>();
final String id1 = "123";
final String id2 = "123";
nodes.add(createNode(id1));
nodes.add(createNode(id2));
when(graph.nodes()).thenReturn(nodes);
when(drgElement.getId()).thenReturn(new Id(id1));
when(clientTranslationService.getValue(DecisionComponentsItemView_DuplicatedNode)).thenReturn(expectedWarnMessage);
doReturn(graph).when(view).getGraph();
view.setIsImported(true);
view.makeDragProxyCallbackImpl(drgElement, factory).onComplete(x, y);
verify(buildCanvasShapeEvent, never()).fire(any());
verify(notificationEvent).fire(notificationEventArgumentCaptor.capture());
final NotificationEvent notificationEvent = notificationEventArgumentCaptor.getValue();
assertEquals(expectedWarnMessage, notificationEvent.getNotification());
assertEquals(expectedWarnType, notificationEvent.getType());
}
Aggregations