use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DMNElementsSynchronizerTest method testDefinitionContainsDRGElement.
@Test
public void testDefinitionContainsDRGElement() {
final Node node = mock(Node.class);
final Definition definition = mock(Definition.class);
final DRGElement drgElement = mock(DRGElement.class);
when(definition.getDefinition()).thenReturn(drgElement);
when(node.getContent()).thenReturn(definition);
final boolean containsDRGElement = synchronizer.definitionContainsDRGElement(node);
assertTrue(containsDRGElement);
}
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 KnowledgeSourceConverter method dmnFromNode.
@Override
@SuppressWarnings("unchecked")
public JSITKnowledgeSource dmnFromNode(final Node<View<KnowledgeSource>, ?> node, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
final KnowledgeSource source = (KnowledgeSource) DefinitionUtils.getElementDefinition(node);
final JSITKnowledgeSource result = new JSITKnowledgeSource();
result.setId(source.getId().getValue());
final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
description.ifPresent(result::setDescription);
result.setName(source.getName().getValue());
result.setType(source.getType().getValue());
result.setLocationURI(source.getLocationURI().getValue());
result.setAuthorityRequirement(new ArrayList<>());
DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, result);
// DMN spec table 2: Requirements connection rules
final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
for (Edge<?, ?> e : inEdges) {
final Node<?, ?> sourceNode = e.getSourceNode();
if (sourceNode.getContent() instanceof View<?>) {
final View<?> view = (View<?>) sourceNode.getContent();
if (view.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) view.getDefinition();
if (drgElement instanceof Decision) {
final JSITAuthorityRequirement iReq = new JSITAuthorityRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredDecision(ri);
result.addAuthorityRequirement(iReq);
} else if (drgElement instanceof KnowledgeSource) {
final JSITAuthorityRequirement iReq = new JSITAuthorityRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredAuthority(ri);
result.addAuthorityRequirement(iReq);
} else if (drgElement instanceof InputData) {
final JSITAuthorityRequirement iReq = new JSITAuthorityRequirement();
iReq.setId(getRawId(e.getUUID()));
final JSITDMNElementReference ri = new JSITDMNElementReference();
ri.setHref(getHref(drgElement));
iReq.setRequiredInput(ri);
result.addAuthorityRequirement(iReq);
} else {
throw new UnsupportedOperationException("wrong model definition.");
}
}
}
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.DRGElement in project kie-wb-common by kiegroup.
the class DMNMarshaller method withIncludedModels.
Node<?, ?> withIncludedModels(final Node<?, ?> node, final Definitions definitionsStunnerPojo) {
final Object elementDefinition = getElementDefinition(node);
final List<Import> diagramImports = definitionsStunnerPojo.getImport();
if (!(elementDefinition instanceof DRGElement) || diagramImports.isEmpty()) {
return node;
}
final DRGElement drgElement = (DRGElement) elementDefinition;
final Optional<Definitions> nodeDefinitions = getDefinitions(drgElement);
if (!nodeDefinitions.isPresent()) {
return node;
}
final List<Import> nodeImports = nodeDefinitions.get().getImport();
updateNodeImports(diagramImports, nodeImports);
return node;
}
Aggregations