Search in sources :

Example 1 with NamedElement

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

the class DMNMarshallerStandalone method getImportPrefix.

private static Optional<String> getImportPrefix(final Definitions definitions, final DMNElement dmnElement) {
    if (!(dmnElement instanceof NamedElement)) {
        return Optional.empty();
    }
    final NamedElement namedElement = (NamedElement) dmnElement;
    final Optional<String> name = Optional.ofNullable(namedElement.getName().getValue());
    return definitions.getImport().stream().filter(anImport -> {
        final String importName = anImport.getName().getValue();
        return name.map(n -> n.startsWith(importName + ".")).orElse(false);
    }).map(anImport -> {
        final String importNamespace = anImport.getNamespace();
        return getNsContextsByNamespace(definitions, importNamespace);
    }).findFirst();
}
Also used : Edge(org.kie.workbench.common.stunner.core.graph.Edge) PointUtils.yOfBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.yOfBound) PointUtils.xOfBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.xOfBound) DoubleConsumer(java.util.function.DoubleConsumer) Bounds(org.kie.dmn.model.api.dmndi.Bounds) Map(java.util.Map) NamedElement(org.kie.workbench.common.dmn.api.definition.model.NamedElement) FactoryManager(org.kie.workbench.common.stunner.core.api.FactoryManager) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) Height(org.kie.workbench.common.dmn.api.property.dimensions.Height) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) Set(java.util.Set) BusinessKnowledgeModelConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.BusinessKnowledgeModelConverter) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) PointUtils.heightOfShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.heightOfShape) Stream(java.util.stream.Stream) PointUtils(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils) QName(javax.xml.namespace.QName) PointUtils.widthOfShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.widthOfShape) DMNMarshaller(org.kie.dmn.api.marshalling.DMNMarshaller) PointUtils.yOfShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.yOfShape) DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) DMNStyle(org.kie.dmn.model.api.dmndi.DMNStyle) Point(org.kie.dmn.model.api.dmndi.Point) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) Color(org.kie.dmn.model.api.dmndi.Color) ItemDefinitionPropertyConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.ItemDefinitionPropertyConverter) DiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.definition.service.DiagramMetadataMarshaller) ArrayList(java.util.ArrayList) FontSetPropertyConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.FontSetPropertyConverter) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) PointUtils.upperLeftBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.upperLeftBound) BiConsumer(java.util.function.BiConsumer) StreamSupport(java.util.stream.StreamSupport) BindableAdapterUtils(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils) IOException(java.io.IOException) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) InputStreamReader(java.io.InputStreamReader) InputDataConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.InputDataConverter) Association(org.kie.workbench.common.dmn.api.definition.model.Association) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) KnowledgeSourceConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.KnowledgeSourceConverter) Graph(org.kie.workbench.common.stunner.core.graph.Graph) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) DecisionConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DecisionConverter) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) DMNDecisionServiceDividerLine(org.kie.dmn.model.api.dmndi.DMNDecisionServiceDividerLine) DMNEdge(org.kie.dmn.model.api.dmndi.DMNEdge) UUID(org.kie.workbench.common.stunner.core.util.UUID) BorderColour(org.kie.workbench.common.dmn.api.property.styling.BorderColour) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) TextAnnotationConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.TextAnnotationConverter) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) Collectors.toMap(java.util.stream.Collectors.toMap) PointUtils.lowerRightBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.lowerRightBound) InformationRequirement(org.kie.workbench.common.dmn.api.definition.model.InformationRequirement) DiagramElement(org.kie.dmn.model.v1_2.dmndi.DiagramElement) Collections.emptyList(java.util.Collections.emptyList) DiagramMarshaller(org.kie.workbench.common.stunner.core.definition.service.DiagramMarshaller) Import(org.kie.dmn.model.api.Import) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Collectors(java.util.stream.Collectors) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Objects(java.util.Objects) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) List(java.util.List) DMNShape(org.kie.dmn.model.api.dmndi.DMNShape) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths) BgColour(org.kie.workbench.common.dmn.api.property.styling.BgColour) DMNDI(org.kie.dmn.model.v1_2.dmndi.DMNDI) Entry(java.util.Map.Entry) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Node(org.kie.workbench.common.stunner.core.graph.Node) PointUtils.xOfShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.xOfShape) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Width(org.kie.workbench.common.dmn.api.property.dimensions.Width) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) RectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.RectangleDimensionsSet) DefinitionsConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DefinitionsConverter) HashMap(java.util.HashMap) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ColorUtils(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ColorUtils) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ComponentsWidthsExtension(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentsWidthsExtension) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) BindableAdapterUtils.getDefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId) KnowledgeRequirement(org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) DMNViewDefinition(org.kie.workbench.common.dmn.api.definition.DMNViewDefinition) SimpleEntry(java.util.AbstractMap.SimpleEntry) DecisionServiceDividerLineY(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) AssociationConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.AssociationConverter) DMNMarshallerImportsHelperStandalone(org.kie.workbench.common.dmn.backend.common.DMNMarshallerImportsHelperStandalone) DecisionServiceConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DecisionServiceConverter) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) AuthorityRequirement(org.kie.workbench.common.dmn.api.definition.model.AuthorityRequirement) Consumer(java.util.function.Consumer) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DiscreteConnection(org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection) InputStream(java.io.InputStream) NamedElement(org.kie.workbench.common.dmn.api.definition.model.NamedElement)

Example 2 with NamedElement

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

the class InformationItemPrimaryPropertyConverterTest method testDmnFromWBWhenWBIsNotNull.

@Test
public void testDmnFromWBWhenWBIsNotNull() {
    final String expectedId = "id";
    final String expectedName = "name";
    final Id id = new Id(expectedId);
    final Name name = new Name(expectedName);
    final String qNameNamespaceURI = "qName namespaceURI";
    final String qNameLocalPart = "qName local part";
    final String qNamePrefix = "qName prefix";
    final InformationItemPrimary wb = mock(InformationItemPrimary.class);
    final QName qName = mock(QName.class);
    final javax.xml.namespace.QName expectedQName = new javax.xml.namespace.QName(qNameNamespaceURI, qNameLocalPart, qNamePrefix);
    final NamedElement parentElement = mock(NamedElement.class);
    when(wb.getId()).thenReturn(id);
    when(wb.getName()).thenReturn(name);
    when(wb.getTypeRef()).thenReturn(qName);
    when(wb.getParent()).thenReturn(parentElement);
    when(parentElement.getName()).thenReturn(name);
    when(qName.getNamespaceURI()).thenReturn(qNameNamespaceURI);
    when(qName.getLocalPart()).thenReturn(qNameLocalPart);
    when(qName.getPrefix()).thenReturn(qNamePrefix);
    final TInformationItem informationItem = InformationItemPrimaryPropertyConverter.dmnFromWB(wb, wb);
    final String actualId = informationItem.getId();
    final String actualName = informationItem.getName();
    final javax.xml.namespace.QName actualQName = informationItem.getTypeRef();
    assertEquals(expectedId, actualId);
    assertEquals(expectedName, actualName);
    assertEquals(expectedQName, actualQName);
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) NamedElement(org.kie.workbench.common.dmn.api.definition.model.NamedElement) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 3 with NamedElement

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

the class DefaultValueUtilitiesTest method testUpdateNewNodeNameWhenNomeIsAlreadySet.

@Test
public void testUpdateNewNodeNameWhenNomeIsAlreadySet() {
    final String existingName = "existingName";
    final NamedElement dec = mock(NamedElement.class);
    final Name name = new Name();
    name.setValue(existingName);
    when(dec.getName()).thenReturn(name);
    DefaultValueUtilities.updateNewNodeName(graph, dec);
    assertEquals(existingName, dec.getName().getValue());
}
Also used : NamedElement(org.kie.workbench.common.dmn.api.definition.model.NamedElement) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 4 with NamedElement

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

the class NodeTextSetterTest method testGetName.

@Test
public void testGetName() {
    final NamedElement named = mock(NamedElement.class);
    final Node node = mock(Node.class);
    final Name name = mock(Name.class);
    final String nodeName = "node name";
    when(name.getValue()).thenReturn(nodeName);
    when(named.getName()).thenReturn(name);
    doReturn(Optional.of(named)).when(nodeTextSetter).getNamedElement(node);
    final String actualName = nodeTextSetter.getName(node);
    assertEquals(nodeName, actualName);
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) NamedElement(org.kie.workbench.common.dmn.api.definition.model.NamedElement) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 5 with NamedElement

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

the class NodeTextSetterTest method testGetNamedElement.

@Test
public void testGetNamedElement() {
    final Node node = mock(Node.class);
    final View content = mock(View.class);
    final NamedElement namedElement = mock(NamedElement.class);
    when(node.getContent()).thenReturn(content);
    when(content.getDefinition()).thenReturn(namedElement);
    final Optional<NamedElement> actualNamed = nodeTextSetter.getNamedElement(node);
    assertTrue(actualNamed.isPresent());
    assertEquals(namedElement, actualNamed.get());
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) View(org.kie.workbench.common.stunner.core.graph.content.view.View) NamedElement(org.kie.workbench.common.dmn.api.definition.model.NamedElement) Test(org.junit.Test)

Aggregations

NamedElement (org.kie.workbench.common.dmn.api.definition.model.NamedElement)9 Test (org.junit.Test)6 Node (org.kie.workbench.common.stunner.core.graph.Node)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)4 View (org.kie.workbench.common.stunner.core.graph.content.view.View)4 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 QName (javax.xml.namespace.QName)2 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)2 DMNElement (org.kie.workbench.common.dmn.api.definition.model.DMNElement)2 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)2 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)2 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)2 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)2 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)2 TextAnnotation (org.kie.workbench.common.dmn.api.definition.model.TextAnnotation)2 RectangleDimensionsSet (org.kie.workbench.common.dmn.api.property.dimensions.RectangleDimensionsSet)2 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)2