Search in sources :

Example 6 with DMNElementReference

use of org.kie.workbench.common.dmn.api.definition.model.DMNElementReference in project kie-wb-common by kiegroup.

the class DecisionServiceParametersListWidgetTest method createListOfDMNElementReferenceWithIds.

private List<DMNElementReference> createListOfDMNElementReferenceWithIds(final String... ids) {
    final List<DMNElementReference> list = new ArrayList<>();
    for (final String id : ids) {
        final DMNElementReference reference = new DMNElementReference();
        reference.setHref("#" + id);
        list.add(reference);
    }
    return list;
}
Also used : DMNElementReference(org.kie.workbench.common.dmn.api.definition.model.DMNElementReference) ArrayList(java.util.ArrayList)

Example 7 with DMNElementReference

use of org.kie.workbench.common.dmn.api.definition.model.DMNElementReference in project kie-wb-common by kiegroup.

the class DecisionServiceParametersListWidgetTest method testGetSortedInputs.

@Test
public void testGetSortedInputs() {
    final DecisionServiceParametersList value = mock(DecisionServiceParametersList.class);
    final DecisionService decisionService = mock(DecisionService.class);
    final String id1 = "id1";
    final String id2 = "id2";
    final String id3 = "id3";
    final String newId1 = "newId1";
    final String newId2 = "newId2";
    final List<DMNElementReference> list = createListOfDMNElementReferenceWithIds(id1, id2, id3);
    final List<InputData> unsortedInputs = Arrays.asList(createInputDataWithId(id2), createInputDataWithId(id3), createInputDataWithId(newId2), createInputDataWithId(id1), createInputDataWithId(newId1));
    doReturn(value).when(widget).getValue();
    when(value.getDecisionService()).thenReturn(decisionService);
    when(decisionService.getInputData()).thenReturn(list);
    final List<InputData> sorted = widget.getSortedInputs(unsortedInputs);
    assertThat(sorted).extracting(inputData -> inputData.getId().getValue()).containsExactly(id1, id2, id3, newId1, newId2);
}
Also used : Arrays(java.util.Arrays) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) DecisionServiceParameters_Outputs(org.kie.workbench.common.dmn.client.resources.i18n.DMNEditorConstants.DecisionServiceParameters_Outputs) HTMLElement(org.jboss.errai.common.client.dom.HTMLElement) ClientTranslationService(org.kie.workbench.common.stunner.core.client.i18n.ClientTranslationService) Mockito.doReturn(org.mockito.Mockito.doReturn) DecisionServiceParameters_EncapsulatedDecisions(org.kie.workbench.common.dmn.client.resources.i18n.DMNEditorConstants.DecisionServiceParameters_EncapsulatedDecisions) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) Mockito.doNothing(org.mockito.Mockito.doNothing) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) List(java.util.List) Stream(java.util.stream.Stream) DMNDiagramsSession(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramsSession) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Node(org.kie.workbench.common.stunner.core.graph.Node) Mockito.mock(org.mockito.Mockito.mock) GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) DecisionServiceParameters_Inputs(org.kie.workbench.common.dmn.client.resources.i18n.DMNEditorConstants.DecisionServiceParameters_Inputs) Mockito.spy(org.mockito.Mockito.spy) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ArrayList(java.util.ArrayList) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Elemental2DomUtil(org.jboss.errai.common.client.dom.elemental2.Elemental2DomUtil) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) DecisionServiceParametersList(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceParametersList) Before(org.junit.Before) DecisionServiceDividerLineY(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Mockito.verify(org.mockito.Mockito.verify) ParameterGroup(org.kie.workbench.common.dmn.client.widgets.decisionservice.parameters.parametergroup.ParameterGroup) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Mockito.never(org.mockito.Mockito.never) HTMLDivElement(elemental2.dom.HTMLDivElement) DMNElementReference(org.kie.workbench.common.dmn.api.definition.model.DMNElementReference) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Assert.assertEquals(org.junit.Assert.assertEquals) DMNElementReference(org.kie.workbench.common.dmn.api.definition.model.DMNElementReference) DecisionServiceParametersList(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceParametersList) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Test(org.junit.Test)

Example 8 with DMNElementReference

use of org.kie.workbench.common.dmn.api.definition.model.DMNElementReference in project kie-wb-common by kiegroup.

the class DecisionServiceConverter method nodeFromDMN.

@Override
public Node<View<DecisionService>, ?> nodeFromDMN(final NodeEntry nodeEntry) {
    final JSITDecisionService dmn = Js.uncheckedCast(nodeEntry.getDmnElement());
    @SuppressWarnings("unchecked") final Node<View<DecisionService>, ?> node = (Node<View<DecisionService>, ?>) factoryManager.newElement(nodeEntry.getId(), getDefinitionId(DecisionService.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 List<DMNElementReference> outputDecision = new ArrayList<>();
    final List<DMNElementReference> encapsulatedDecision = new ArrayList<>();
    final List<DMNElementReference> inputDecision = new ArrayList<>();
    final List<DMNElementReference> inputData = new ArrayList<>();
    final List<JSITDMNElementReference> jsiOutputDecisions = dmn.getOutputDecision();
    if (Objects.nonNull(jsiOutputDecisions)) {
        for (int i = 0; i < jsiOutputDecisions.size(); i++) {
            final JSITDMNElementReference jsiOutputDecision = Js.uncheckedCast(jsiOutputDecisions.get(i));
            outputDecision.add(DMNElementReferenceConverter.wbFromDMN(jsiOutputDecision));
        }
    }
    final List<JSITDMNElementReference> jsiEncapsulatedDecisions = dmn.getEncapsulatedDecision();
    if (Objects.nonNull(jsiEncapsulatedDecisions)) {
        for (int i = 0; i < jsiEncapsulatedDecisions.size(); i++) {
            final JSITDMNElementReference jsiEncapsulatedDecision = Js.uncheckedCast(jsiEncapsulatedDecisions.get(i));
            encapsulatedDecision.add(DMNElementReferenceConverter.wbFromDMN(jsiEncapsulatedDecision));
        }
    }
    final List<JSITDMNElementReference> jsiInputDecisions = dmn.getInputDecision();
    if (Objects.nonNull(jsiInputDecisions)) {
        for (int i = 0; i < jsiInputDecisions.size(); i++) {
            final JSITDMNElementReference jsiInputDecision = Js.uncheckedCast(jsiInputDecisions.get(i));
            inputDecision.add(DMNElementReferenceConverter.wbFromDMN(jsiInputDecision));
        }
    }
    final List<JSITDMNElementReference> jsiInputDatas = dmn.getInputData();
    if (Objects.nonNull(jsiInputDatas)) {
        for (int i = 0; i < jsiInputDatas.size(); i++) {
            final JSITDMNElementReference jsiInputData = Js.uncheckedCast(jsiInputDatas.get(i));
            inputData.add(DMNElementReferenceConverter.wbFromDMN(jsiInputData));
        }
    }
    final DecisionService decisionService = new DecisionService(id, description, name, informationItem, outputDecision, encapsulatedDecision, inputDecision, inputData, new StylingSet(), new DecisionServiceRectangleDimensionsSet(), new DecisionServiceDividerLineY());
    decisionService.setDiagramId(nodeEntry.getDiagramId());
    node.getContent().setDefinition(decisionService);
    if (Objects.nonNull(informationItem)) {
        informationItem.setParent(decisionService);
    }
    DMNExternalLinksToExtensionElements.loadExternalLinksFromExtensionElements(dmn, decisionService);
    return node;
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) JSITDMNElementReference(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference) View(org.kie.workbench.common.stunner.core.graph.content.view.View) JSITDecisionService(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionService) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) DecisionServiceDividerLineY(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY) JSITDMNElementReference(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference) DMNElementReference(org.kie.workbench.common.dmn.api.definition.model.DMNElementReference) JSITDecisionService(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionService) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) BindableAdapterUtils.getDefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId) DecisionServiceRectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.DecisionServiceRectangleDimensionsSet)

Aggregations

DMNElementReference (org.kie.workbench.common.dmn.api.definition.model.DMNElementReference)8 ArrayList (java.util.ArrayList)5 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)5 InformationItemPrimary (org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary)5 DecisionServiceDividerLineY (org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)5 Node (org.kie.workbench.common.stunner.core.graph.Node)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)5 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)3 HTMLDivElement (elemental2.dom.HTMLDivElement)3 Arrays (java.util.Arrays)3 List (java.util.List)3 Optional (java.util.Optional)3 Stream (java.util.stream.Stream)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 HTMLElement (org.jboss.errai.common.client.dom.HTMLElement)3 Elemental2DomUtil (org.jboss.errai.common.client.dom.elemental2.Elemental2DomUtil)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 Assert.assertFalse (org.junit.Assert.assertFalse)3 Assert.assertTrue (org.junit.Assert.assertTrue)3