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);
}
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;
}
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);
}
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);
}
}
}
}
Aggregations