Search in sources :

Example 46 with ItemDefinition

use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.

the class ItemDefinitionConverter method writeAttributes.

@Override
protected void writeAttributes(HierarchicalStreamWriter writer, Object parent) {
    super.writeAttributes(writer, parent);
    ItemDefinition id = (ItemDefinition) parent;
    if (id.getTypeLanguage() != null)
        writer.addAttribute(TYPE_LANGUAGE, id.getTypeLanguage());
    writer.addAttribute(IS_COLLECTION, Boolean.valueOf(id.isIsCollection()).toString());
}
Also used : TItemDefinition(org.kie.dmn.model.v1_3.TItemDefinition) ItemDefinition(org.kie.dmn.model.api.ItemDefinition)

Example 47 with ItemDefinition

use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.

the class DefinitionsConverter method assignChildElement.

@Override
protected void assignChildElement(Object parent, String nodeName, Object child) {
    Definitions def = (Definitions) parent;
    if (IMPORT.equals(nodeName)) {
        def.getImport().add((Import) child);
    } else if (ITEM_DEFINITION.equals(nodeName)) {
        def.getItemDefinition().add((ItemDefinition) child);
    } else if (child instanceof DRGElement) {
        def.getDrgElement().add((DRGElement) child);
    } else if (child instanceof Artifact) {
        def.getArtifact().add((Artifact) child);
    } else if (ELEMENT_COLLECTION.equals(nodeName)) {
        def.getElementCollection().add((ElementCollection) child);
    } else if (child instanceof BusinessContextElement) {
        def.getBusinessContextElement().add((BusinessContextElement) child);
    } else if (child instanceof DMNDI) {
        DMNDI dmndi = (DMNDI) child;
        dmndi.normalize();
        def.setDMNDI(dmndi);
    } else {
        super.assignChildElement(def, nodeName, child);
    }
}
Also used : Definitions(org.kie.dmn.model.api.Definitions) TDefinitions(org.kie.dmn.model.v1_3.TDefinitions) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) DMNDI(org.kie.dmn.model.api.dmndi.DMNDI) BusinessContextElement(org.kie.dmn.model.api.BusinessContextElement) Artifact(org.kie.dmn.model.api.Artifact) DRGElement(org.kie.dmn.model.api.DRGElement)

Example 48 with ItemDefinition

use of org.kie.dmn.model.api.ItemDefinition in project drools by kiegroup.

the class TDefinitions method processQNameURIs.

private static void processQNameURIs(ItemDefinition iDef) {
    final QName typeRef = iDef.getTypeRef();
    if (typeRef != null && XMLConstants.NULL_NS_URI.equals(typeRef.getNamespaceURI())) {
        final String namespace = iDef.getNamespaceURI(typeRef.getPrefix());
        iDef.setTypeRef(new QName(namespace, typeRef.getLocalPart(), typeRef.getPrefix()));
    }
    for (ItemDefinition comp : iDef.getItemComponent()) {
        processQNameURIs(comp);
    }
}
Also used : QName(javax.xml.namespace.QName) ItemDefinition(org.kie.dmn.model.api.ItemDefinition)

Example 49 with ItemDefinition

use of org.kie.dmn.model.api.ItemDefinition in project kie-wb-common by kiegroup.

the class DMNMarshallerImportsHelperStandaloneImplTest method testGetImportedItemDefinitions.

@Test
public void testGetImportedItemDefinitions() {
    final Map<Import, Definitions> importDefinitions = new HashMap<>();
    final Import anImport = mock(Import.class);
    final Definitions definitions = mock(Definitions.class);
    final ItemDefinition itemDefinition1 = mock(ItemDefinition.class);
    final ItemDefinition itemDefinition2 = mock(ItemDefinition.class);
    final ItemDefinition itemDefinition3 = mock(ItemDefinition.class);
    final List<ItemDefinition> expectedItemDefinitions = asList(itemDefinition1, itemDefinition2, itemDefinition3);
    doReturn(expectedItemDefinitions).when(helper).getItemDefinitionsWithNamespace(definitions, anImport);
    importDefinitions.put(anImport, definitions);
    final List<ItemDefinition> actualItemDefinitions = helper.getImportedItemDefinitions(importDefinitions);
    assertEquals(expectedItemDefinitions, actualItemDefinitions);
}
Also used : Import(org.kie.dmn.model.api.Import) HashMap(java.util.HashMap) Definitions(org.kie.dmn.model.api.Definitions) TItemDefinition(org.kie.dmn.model.v1_2.TItemDefinition) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) Test(org.junit.Test)

Example 50 with ItemDefinition

use of org.kie.dmn.model.api.ItemDefinition in project kie-wb-common by kiegroup.

the class DMNMarshallerImportsHelperStandaloneImplTest method testGetImportedItemDefinitionsByNamespace.

@Test
public void testGetImportedItemDefinitionsByNamespace() {
    final WorkspaceProject workspaceProject = mock(WorkspaceProject.class);
    final String modelName = "model1";
    final String namespace = "://namespace1";
    final Path path1 = makePath("../file1.dmn");
    final Path path2 = makePath("../file2.dmn");
    final Path path3 = makePath("../file3.dmn");
    final Path path4 = makePath("../file4.dmn");
    final InputStream inputStream1 = mock(InputStream.class);
    final InputStream inputStream2 = mock(InputStream.class);
    final InputStream inputStream3 = mock(InputStream.class);
    final InputStreamReader inputStreamReader1 = mock(InputStreamReader.class);
    final InputStreamReader inputStreamReader2 = mock(InputStreamReader.class);
    final InputStreamReader inputStreamReader3 = mock(InputStreamReader.class);
    final Definitions definitions1 = mock(Definitions.class);
    final Definitions definitions2 = mock(Definitions.class);
    final Definitions definitions3 = mock(Definitions.class);
    final ItemDefinition itemDefinition1 = mock(ItemDefinition.class);
    final ItemDefinition itemDefinition2 = mock(ItemDefinition.class);
    final List<Path> paths = asList(path1, path2, path3, path4);
    when(pathsHelper.getDMNModelsPaths(any())).thenReturn(paths);
    doReturn(Optional.of(inputStream1)).when(helper).loadPath(path1);
    doReturn(Optional.of(inputStream2)).when(helper).loadPath(path2);
    doReturn(Optional.of(inputStream3)).when(helper).loadPath(path3);
    doReturn(inputStreamReader1).when(helper).toInputStreamReader(inputStream1);
    doReturn(inputStreamReader2).when(helper).toInputStreamReader(inputStream2);
    doReturn(inputStreamReader3).when(helper).toInputStreamReader(inputStream3);
    doReturn(Optional.empty()).when(helper).loadPath(path4);
    when(marshaller.unmarshal(inputStreamReader1)).thenReturn(definitions1);
    when(marshaller.unmarshal(inputStreamReader2)).thenReturn(definitions2);
    when(marshaller.unmarshal(inputStreamReader3)).thenReturn(definitions3);
    when(definitions1.getNamespace()).thenReturn("://namespace1");
    when(definitions2.getNamespace()).thenReturn("://namespace2");
    when(definitions3.getNamespace()).thenReturn("://namespace3");
    when(definitions1.getItemDefinition()).thenReturn(asList(itemDefinition1, itemDefinition2));
    final List<ItemDefinition> actualItemDefinitions = helper.getImportedItemDefinitionsByNamespace(workspaceProject, modelName, namespace);
    final List<ItemDefinition> expectedItemDefinitions = asList(itemDefinition1, itemDefinition2);
    assertEquals(expectedItemDefinitions, actualItemDefinitions);
}
Also used : Path(org.uberfire.backend.vfs.Path) InputStreamReader(java.io.InputStreamReader) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Definitions(org.kie.dmn.model.api.Definitions) TItemDefinition(org.kie.dmn.model.v1_2.TItemDefinition) ItemDefinition(org.kie.dmn.model.api.ItemDefinition) Test(org.junit.Test)

Aggregations

ItemDefinition (org.kie.dmn.model.api.ItemDefinition)50 TItemDefinition (org.kie.dmn.model.v1_1.TItemDefinition)19 Test (org.junit.Test)15 QName (javax.xml.namespace.QName)13 Definitions (org.kie.dmn.model.api.Definitions)13 ArrayList (java.util.ArrayList)10 DRGElement (org.kie.dmn.model.api.DRGElement)9 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 Artifact (org.kie.dmn.model.api.Artifact)7 BusinessContextElement (org.kie.dmn.model.api.BusinessContextElement)7 Decision (org.kie.dmn.model.api.Decision)7 Import (org.kie.dmn.model.api.Import)7 Collection (java.util.Collection)6 TItemDefinition (org.kie.dmn.model.v1_2.TItemDefinition)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 DecisionService (org.kie.dmn.model.api.DecisionService)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4