Search in sources :

Example 1 with ExternalLink

use of org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ExternalLink 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 ExternalLink

use of org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ExternalLink in project kie-wb-common by kiegroup.

the class DMNExternalLinksToExtensionElementsTest method createExternalLinkMock.

private ExternalLink createExternalLinkMock(final String description, final String url) {
    final ExternalLink external = mock(ExternalLink.class);
    when(external.getName()).thenReturn(description);
    when(external.getUrl()).thenReturn(url);
    return external;
}
Also used : ExternalLink(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ExternalLink)

Example 3 with ExternalLink

use of org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ExternalLink in project kie-wb-common by kiegroup.

the class DMNExternalLinksToExtensionElementsTest method testLoadExternalLinksFromExtensionElements.

@Test
public void testLoadExternalLinksFromExtensionElements() {
    final org.kie.dmn.model.api.DRGElement source = mock(org.kie.dmn.model.api.DRGElement.class);
    final org.kie.workbench.common.dmn.api.definition.model.DRGElement target = mock(org.kie.workbench.common.dmn.api.definition.model.DRGElement.class);
    final DMNElement.ExtensionElements extensionElements = mock(DMNElement.ExtensionElements.class);
    final List<Object> externalLinks = new ArrayList<>();
    final String linkDescription1 = "l1";
    final String url1 = "url1";
    final ExternalLink external1 = createExternalLinkMock(linkDescription1, url1);
    externalLinks.add(external1);
    final String linkDescription2 = "l2";
    final String url2 = "url2";
    final ExternalLink external2 = createExternalLinkMock(linkDescription2, url2);
    externalLinks.add(external2);
    when(extensionElements.getAny()).thenReturn(externalLinks);
    when(source.getExtensionElements()).thenReturn(extensionElements);
    final DocumentationLinksHolder linksHolder = mock(DocumentationLinksHolder.class);
    final DocumentationLinks links = new DocumentationLinks();
    when(linksHolder.getValue()).thenReturn(links);
    when(target.getLinksHolder()).thenReturn(linksHolder);
    loadExternalLinksFromExtensionElements(source, target);
    assertEquals(2, links.getLinks().size());
    compare(links.getLinks().get(0), linkDescription1, url1);
    compare(links.getLinks().get(1), linkDescription2, url2);
}
Also used : ArrayList(java.util.ArrayList) DocumentationLinksHolder(org.kie.workbench.common.dmn.api.property.dmn.DocumentationLinksHolder) ExternalLink(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ExternalLink) DocumentationLinks(org.kie.workbench.common.dmn.api.property.dmn.DocumentationLinks) DMNElement(org.kie.dmn.model.api.DMNElement) DRGElement(org.kie.dmn.model.api.DRGElement) Test(org.junit.Test)

Example 4 with ExternalLink

use of org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ExternalLink in project kie-wb-common by kiegroup.

the class DMNExternalLinksToExtensionElements method loadExternalLinksFromExtensionElements.

static void loadExternalLinksFromExtensionElements(final org.kie.dmn.model.api.DRGElement source, final org.kie.workbench.common.dmn.api.definition.model.DRGElement target) {
    if (!Objects.isNull(source.getExtensionElements())) {
        for (final Object obj : source.getExtensionElements().getAny()) {
            if (obj instanceof ExternalLink) {
                final ExternalLink el = (ExternalLink) obj;
                final DMNExternalLink external = new DMNExternalLink();
                external.setDescription(el.getName());
                external.setUrl(el.getUrl());
                target.getLinksHolder().getValue().addLink(external);
            }
        }
    }
}
Also used : 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)

Aggregations

ExternalLink (org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ExternalLink)4 DMNElement (org.kie.dmn.model.api.DMNElement)2 DMNExternalLink (org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink)2 DocumentationLinks (org.kie.workbench.common.dmn.api.property.dmn.DocumentationLinks)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 DRGElement (org.kie.dmn.model.api.DRGElement)1 TDMNElement (org.kie.dmn.model.v1_2.TDMNElement)1 DocumentationLinksHolder (org.kie.workbench.common.dmn.api.property.dmn.DocumentationLinksHolder)1