@Test public void wbFromDMN() { final Import anImport = new TImport(); anImport.setImportType(DMNImportTypes.DMN.getDefaultNamespace()); final org.kie.dmn.model.api.Definitions definitions = mock(org.kie.dmn.model.api.Definitions.class); final Map<Import, org.kie.dmn.model.api.Definitions> importDefinitions = new Maps.Builder<Import, org.kie.dmn.model.api.Definitions>().put(anImport, definitions).build(); final Map<Import, PMMLDocumentMetadata> pmmlDocuments = new Maps.Builder<Import, PMMLDocumentMetadata>().build(); when(definitions.getDrgElement()).thenReturn(asList(mock(DRGElement.class), mock(DRGElement.class))); when(definitions.getItemDefinition()).thenReturn(asList(mock(ItemDefinition.class), mock(ItemDefinition.class), mock(ItemDefinition.class))); when(apiDefinitions.getImport()).thenReturn(singletonList(anImport)); final Definitions wb = DefinitionsConverter.wbFromDMN(apiDefinitions, importDefinitions, pmmlDocuments); final String defaultNs = wb.getNsContext().get(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix()); final String namespace = wb.getNamespace().getValue(); final List<org.kie.workbench.common.dmn.api.definition.model.Import> imports = wb.getImport(); assertEquals(defaultNs, namespace); assertEquals(1, imports.size()); assertTrue(imports.get(0) instanceof ImportDMN); final ImportDMN importDMN = (ImportDMN) imports.get(0); assertEquals(2, importDMN.getDrgElementsCount()); assertEquals(3, importDMN.getItemDefinitionsCount()); }
public static Definitions wbFromDMN(final org.kie.dmn.model.api.Definitions dmn, final Map<org.kie.dmn.model.api.Import, org.kie.dmn.model.api.Definitions> importDefinitions, final Map<org.kie.dmn.model.api.Import, PMMLDocumentMetadata> pmmlDocuments) { if (dmn == null) { return null; } final Id id = new Id(dmn.getId()); final Name name = new Name(dmn.getName()); final String namespace = dmn.getNamespace(); final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription()); final Definitions result = new Definitions(); result.setId(id); result.setName(name); result.setNamespace(new Text(namespace)); result.getNsContext().putIfAbsent(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix(), namespace); result.setDescription(description); for (Entry<String, String> kv : dmn.getNsContext().entrySet()) { String mappedURI = kv.getValue(); switch (mappedURI) { case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_DMN: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_DMN; break; case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_FEEL: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_FEEL; break; case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_KIE: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_KIE; break; } if (kv.getKey().equalsIgnoreCase(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) { result.getNsContext().putIfAbsent(kv.getKey(), mappedURI); } else { result.getNsContext().put(kv.getKey(), mappedURI); } } for (org.kie.dmn.model.api.ItemDefinition itemDef : dmn.getItemDefinition()) { final ItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.wbFromDMN(itemDef); if (itemDefConverted != null) { itemDefConverted.setParent(result); } result.getItemDefinition().add(itemDefConverted); } for (org.kie.dmn.model.api.Import i : dmn.getImport()) { final org.kie.dmn.model.api.Definitions definitions = importDefinitions.get(i); final PMMLDocumentMetadata pmmlDocument = pmmlDocuments.get(i); final Import importConverted = ImportConverter.wbFromDMN(i, definitions, pmmlDocument); if (importConverted != null) { importConverted.setParent(result); } result.getImport().add(importConverted); } return result; }
DefinitionsConverter { public static Definitions wbFromDMN(final org.kie.dmn.model.api.Definitions dmn, final Map<org.kie.dmn.model.api.Import, org.kie.dmn.model.api.Definitions> importDefinitions, final Map<org.kie.dmn.model.api.Import, PMMLDocumentMetadata> pmmlDocuments) { if (dmn == null) { return null; } final Id id = new Id(dmn.getId()); final Name name = new Name(dmn.getName()); final String namespace = dmn.getNamespace(); final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription()); final Definitions result = new Definitions(); result.setId(id); result.setName(name); result.setNamespace(new Text(namespace)); result.getNsContext().putIfAbsent(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix(), namespace); result.setDescription(description); for (Entry<String, String> kv : dmn.getNsContext().entrySet()) { String mappedURI = kv.getValue(); switch (mappedURI) { case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_DMN: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_DMN; break; case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_FEEL: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_FEEL; break; case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_KIE: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_KIE; break; } if (kv.getKey().equalsIgnoreCase(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) { result.getNsContext().putIfAbsent(kv.getKey(), mappedURI); } else { result.getNsContext().put(kv.getKey(), mappedURI); } } for (org.kie.dmn.model.api.ItemDefinition itemDef : dmn.getItemDefinition()) { final ItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.wbFromDMN(itemDef); if (itemDefConverted != null) { itemDefConverted.setParent(result); } result.getItemDefinition().add(itemDefConverted); } for (org.kie.dmn.model.api.Import i : dmn.getImport()) { final org.kie.dmn.model.api.Definitions definitions = importDefinitions.get(i); final PMMLDocumentMetadata pmmlDocument = pmmlDocuments.get(i); final Import importConverted = ImportConverter.wbFromDMN(i, definitions, pmmlDocument); if (importConverted != null) { importConverted.setParent(result); } result.getImport().add(importConverted); } return result; } }
DefinitionsConverter { public static Definitions wbFromDMN(final org.kie.dmn.model.api.Definitions dmn, final Map<org.kie.dmn.model.api.Import, org.kie.dmn.model.api.Definitions> importDefinitions, final Map<org.kie.dmn.model.api.Import, PMMLDocumentMetadata> pmmlDocuments) { if (dmn == null) { return null; } final Id id = new Id(dmn.getId()); final Name name = new Name(dmn.getName()); final String namespace = dmn.getNamespace(); final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription()); final Definitions result = new Definitions(); result.setId(id); result.setName(name); result.setNamespace(new Text(namespace)); result.getNsContext().putIfAbsent(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix(), namespace); result.setDescription(description); for (Entry<String, String> kv : dmn.getNsContext().entrySet()) { String mappedURI = kv.getValue(); switch (mappedURI) { case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_DMN: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_DMN; break; case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_FEEL: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_FEEL; break; case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_KIE: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_KIE; break; } if (kv.getKey().equalsIgnoreCase(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) { result.getNsContext().putIfAbsent(kv.getKey(), mappedURI); } else { result.getNsContext().put(kv.getKey(), mappedURI); } } for (org.kie.dmn.model.api.ItemDefinition itemDef : dmn.getItemDefinition()) { final ItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.wbFromDMN(itemDef); if (itemDefConverted != null) { itemDefConverted.setParent(result); } result.getItemDefinition().add(itemDefConverted); } for (org.kie.dmn.model.api.Import i : dmn.getImport()) { final org.kie.dmn.model.api.Definitions definitions = importDefinitions.get(i); final PMMLDocumentMetadata pmmlDocument = pmmlDocuments.get(i); final Import importConverted = ImportConverter.wbFromDMN(i, definitions, pmmlDocument); if (importConverted != null) { importConverted.setParent(result); } result.getImport().add(importConverted); } return result; }  }
DefinitionsConverter { public static Definitions wbFromDMN(final org.kie.dmn.model.api.Definitions dmn, final Map<org.kie.dmn.model.api.Import, org.kie.dmn.model.api.Definitions> importDefinitions, final Map<org.kie.dmn.model.api.Import, PMMLDocumentMetadata> pmmlDocuments) { if (dmn == null) { return null; } final Id id = new Id(dmn.getId()); final Name name = new Name(dmn.getName()); final String namespace = dmn.getNamespace(); final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription()); final Definitions result = new Definitions(); result.setId(id); result.setName(name); result.setNamespace(new Text(namespace)); result.getNsContext().putIfAbsent(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix(), namespace); result.setDescription(description); for (Entry<String, String> kv : dmn.getNsContext().entrySet()) { String mappedURI = kv.getValue(); switch (mappedURI) { case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_DMN: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_DMN; break; case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_FEEL: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_FEEL; break; case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_KIE: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_KIE; break; } if (kv.getKey().equalsIgnoreCase(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) { result.getNsContext().putIfAbsent(kv.getKey(), mappedURI); } else { result.getNsContext().put(kv.getKey(), mappedURI); } } for (org.kie.dmn.model.api.ItemDefinition itemDef : dmn.getItemDefinition()) { final ItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.wbFromDMN(itemDef); if (itemDefConverted != null) { itemDefConverted.setParent(result); } result.getItemDefinition().add(itemDefConverted); } for (org.kie.dmn.model.api.Import i : dmn.getImport()) { final org.kie.dmn.model.api.Definitions definitions = importDefinitions.get(i); final PMMLDocumentMetadata pmmlDocument = pmmlDocuments.get(i); final Import importConverted = ImportConverter.wbFromDMN(i, definitions, pmmlDocument); if (importConverted != null) { importConverted.setParent(result); } result.getImport().add(importConverted); } return result; }  static Definitions wbFromDMN(final org.kie.dmn.model.api.Definitions dmn,
                                        final Map<org.kie.dmn.model.api.Import, org.kie.dmn.model.api.Definitions> importDefinitions,
                                        final Map<org.kie.dmn.model.api.Import, PMMLDocumentMetadata> pmmlDocuments); static org.kie.dmn.model.api.Definitions dmnFromWB(final Definitions wb); }
DefinitionsConverter { public static Definitions wbFromDMN(final org.kie.dmn.model.api.Definitions dmn, final Map<org.kie.dmn.model.api.Import, org.kie.dmn.model.api.Definitions> importDefinitions, final Map<org.kie.dmn.model.api.Import, PMMLDocumentMetadata> pmmlDocuments) { if (dmn == null) { return null; } final Id id = new Id(dmn.getId()); final Name name = new Name(dmn.getName()); final String namespace = dmn.getNamespace(); final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription()); final Definitions result = new Definitions(); result.setId(id); result.setName(name); result.setNamespace(new Text(namespace)); result.getNsContext().putIfAbsent(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix(), namespace); result.setDescription(description); for (Entry<String, String> kv : dmn.getNsContext().entrySet()) { String mappedURI = kv.getValue(); switch (mappedURI) { case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_DMN: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_DMN; break; case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_FEEL: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_FEEL; break; case org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase.URI_KIE: mappedURI = org.kie.dmn.model.v1_2.KieDMNModelInstrumentedBase.URI_KIE; break; } if (kv.getKey().equalsIgnoreCase(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) { result.getNsContext().putIfAbsent(kv.getKey(), mappedURI); } else { result.getNsContext().put(kv.getKey(), mappedURI); } } for (org.kie.dmn.model.api.ItemDefinition itemDef : dmn.getItemDefinition()) { final ItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.wbFromDMN(itemDef); if (itemDefConverted != null) { itemDefConverted.setParent(result); } result.getItemDefinition().add(itemDefConverted); } for (org.kie.dmn.model.api.Import i : dmn.getImport()) { final org.kie.dmn.model.api.Definitions definitions = importDefinitions.get(i); final PMMLDocumentMetadata pmmlDocument = pmmlDocuments.get(i); final Import importConverted = ImportConverter.wbFromDMN(i, definitions, pmmlDocument); if (importConverted != null) { importConverted.setParent(result); } result.getImport().add(importConverted); } return result; }  static Definitions wbFromDMN(final org.kie.dmn.model.api.Definitions dmn,
                                        final Map<org.kie.dmn.model.api.Import, org.kie.dmn.model.api.Definitions> importDefinitions,
                                        final Map<org.kie.dmn.model.api.Import, PMMLDocumentMetadata> pmmlDocuments); static org.kie.dmn.model.api.Definitions dmnFromWB(final Definitions wb);  }