Search in sources :

Example 1 with DMNExternalLink

use of org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink in project kie-wb-common by kiegroup.

the class DMNExternalLinksToExtensionElements method loadExternalLinksIntoExtensionElements.

static void loadExternalLinksIntoExtensionElements(final org.kie.workbench.common.dmn.api.definition.model.DRGElement source, final org.kie.dmn.model.api.DRGElement target) {
    if (Objects.isNull(source.getLinksHolder()) || Objects.isNull(source.getLinksHolder().getValue())) {
        return;
    }
    final DocumentationLinks links = source.getLinksHolder().getValue();
    final DMNElement.ExtensionElements elements = getOrCreateExtensionElements(target);
    removeAllExistingLinks(elements);
    for (final DMNExternalLink link : links.getLinks()) {
        final ExternalLink external = new ExternalLink();
        external.setName(link.getDescription());
        external.setUrl(link.getUrl());
        elements.getAny().add(external);
    }
    target.setExtensionElements(elements);
}
Also used : DocumentationLinks(org.kie.workbench.common.dmn.api.property.dmn.DocumentationLinks) DMNElement(org.kie.dmn.model.api.DMNElement) TDMNElement(org.kie.dmn.model.v1_2.TDMNElement) DMNExternalLink(org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink) ExternalLink(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ExternalLink) DMNExternalLink(org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink)

Example 2 with DMNExternalLink

use of org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink in project kie-wb-common by kiegroup.

the class DMNExternalLinksToExtensionElements method loadExternalLinksFromExtensionElements.

static void loadExternalLinksFromExtensionElements(final JSITDRGElement source, final DRGElement target) {
    if (!Objects.isNull(source.getExtensionElements())) {
        final List<Object> extensions = source.getExtensionElements().getAny();
        if (!Objects.isNull(extensions)) {
            for (int i = 0; i < extensions.size(); i++) {
                final Object extension = extensions.get(i);
                if (JSITAttachment.instanceOf(extension)) {
                    final JSITAttachment jsiExtension = Js.uncheckedCast(extension);
                    final DMNExternalLink external = new DMNExternalLink();
                    external.setDescription(jsiExtension.getName());
                    external.setUrl(jsiExtension.getUrl());
                    target.getLinksHolder().getValue().addLink(external);
                }
            }
        }
    }
}
Also used : JSITAttachment(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITAttachment) DMNExternalLink(org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink)

Example 3 with DMNExternalLink

use of org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink in project kie-wb-common by kiegroup.

the class NameAndUrlPopoverViewImplTest method testOnClickOkButton.

@Test
public void testOnClickOkButton() {
    final String description = "description";
    final String url = "url";
    final ArgumentCaptor<DMNExternalLink> captor = ArgumentCaptor.forClass(DMNExternalLink.class);
    final Consumer onExternalLinkCreated = mock(Consumer.class);
    attachmentNameInput.value = description;
    urlInput.value = url;
    popover.setOnExternalLinkCreated(onExternalLinkCreated);
    popover.onClickOkButton(null);
    verify(onExternalLinkCreated).accept(captor.capture());
    final DMNExternalLink externalLink = captor.getValue();
    assertEquals(description, externalLink.getDescription());
    assertEquals(url, externalLink.getUrl());
    verify(popover).hide();
}
Also used : Consumer(java.util.function.Consumer) DMNExternalLink(org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink) Test(org.junit.Test)

Example 4 with DMNExternalLink

use of org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink in project kie-wb-common by kiegroup.

the class DocumentationLinksWidgetTest method testOnExternalLinkDeleted.

@Test
public void testOnExternalLinkDeleted() {
    final DocumentationLinks value = mock(DocumentationLinks.class);
    final DMNExternalLink externalLink = mock(DMNExternalLink.class);
    final List<DMNExternalLink> links = new ArrayList<>();
    links.add(externalLink);
    when(value.getLinks()).thenReturn(links);
    widget.setValue(value);
    widget.onExternalLinkDeleted(externalLink);
    assertFalse(links.contains(externalLink));
    verify(widget).refresh();
    verify(locker).fire(any());
}
Also used : DocumentationLinks(org.kie.workbench.common.dmn.api.property.dmn.DocumentationLinks) ArrayList(java.util.ArrayList) DMNExternalLink(org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink) Test(org.junit.Test)

Example 5 with DMNExternalLink

use of org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink in project kie-wb-common by kiegroup.

the class NameAndUrlPopoverViewImpl method onClickOkButton.

@EventHandler("okButton")
@SuppressWarnings("unused")
public void onClickOkButton(final ClickEvent clickEvent) {
    final Consumer<DMNExternalLink> consumer = getOnExternalLinkCreated();
    if (!Objects.isNull(consumer)) {
        final String description = attachmentNameInput.value;
        final String url = urlInput.value;
        final DMNExternalLink externalLink = new DMNExternalLink(url, description);
        consumer.accept(externalLink);
    }
    hide();
}
Also used : DMNExternalLink(org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink) EventHandler(org.jboss.errai.ui.shared.api.annotations.EventHandler)

Aggregations

DMNExternalLink (org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink)14 Test (org.junit.Test)8 DocumentationLinks (org.kie.workbench.common.dmn.api.property.dmn.DocumentationLinks)6 ArrayList (java.util.ArrayList)3 ExternalLink (org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ExternalLink)2 JSITAttachment (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITAttachment)2 HTMLElement (elemental2.dom.HTMLElement)1 Consumer (java.util.function.Consumer)1 EventHandler (org.jboss.errai.ui.shared.api.annotations.EventHandler)1 DMNElement (org.kie.dmn.model.api.DMNElement)1 TDMNElement (org.kie.dmn.model.v1_2.TDMNElement)1 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)1 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)1 InformationItemPrimary (org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary)1 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)1 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)1 DocumentationLinksHolder (org.kie.workbench.common.dmn.api.property.dmn.DocumentationLinksHolder)1 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)1 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)1 ExpressionEditorView (org.kie.workbench.common.dmn.client.editors.expressions.ExpressionEditorView)1