use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class DefinitionsConverter method wbFromDMN.
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;
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class ImportedItemDefinitionConverter method wbFromDMN.
public static ItemDefinition wbFromDMN(final org.kie.dmn.model.api.ItemDefinition dmnItemDefinition, final String prefix) {
final org.kie.dmn.model.api.ItemDefinition dmnItemDefinitionWithNamespace = withNamespace(dmnItemDefinition, prefix);
final ItemDefinition wbItemDefinition = ItemDefinitionPropertyConverter.wbFromDMN(dmnItemDefinitionWithNamespace);
allowOnlyVisualChange(wbItemDefinition);
return wbItemDefinition;
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method mockTCompanyStructure.
private ItemDefinition mockTCompanyStructure() {
final ItemDefinition tCompany = mock(ItemDefinition.class);
final ItemDefinition name = mock(ItemDefinition.class);
final ItemDefinition tAddress = mock(ItemDefinition.class);
/* === ItemDefinition ===
* - tCompany (Structure)
* - name (String)
* - tAddress (Structure)
* ======================
*/
when(name.getName()).thenReturn(new Name("name"));
when(name.getTypeRef()).thenReturn(STRING.asQName());
when(name.getItemComponent()).thenReturn(emptyList());
when(tAddress.getName()).thenReturn(new Name("address"));
when(tAddress.getTypeRef()).thenReturn(T_ADDRESS_QNAME);
when(tAddress.getItemComponent()).thenReturn(singletonList(name));
when(tCompany.getName()).thenReturn(new Name(TYPE_COMPANY));
when(tCompany.getTypeRef()).thenReturn(null);
when(tCompany.getItemComponent()).thenReturn(asList(name, tAddress));
return tCompany;
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method mockTPersonStructure.
private ItemDefinition mockTPersonStructure() {
final ItemDefinition tPerson = mock(ItemDefinition.class);
final ItemDefinition name = mock(ItemDefinition.class);
final ItemDefinition age = mock(ItemDefinition.class);
/* === ItemDefinition ===
* - tPerson (Structure)
* - name (String)
* - age (Number)
* ======================
*/
when(name.getName()).thenReturn(new Name("name"));
when(name.getTypeRef()).thenReturn(STRING.asQName());
when(name.getItemComponent()).thenReturn(emptyList());
when(age.getName()).thenReturn(new Name("age"));
when(age.getTypeRef()).thenReturn(NUMBER.asQName());
when(age.getItemComponent()).thenReturn(emptyList());
when(tPerson.getName()).thenReturn(new Name(TYPE_PERSON));
when(tPerson.getTypeRef()).thenReturn(null);
when(tPerson.getItemComponent()).thenReturn(asList(name, age));
return tPerson;
}
use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testComputingClauseNameWithoutModelRefWhenModelRefAlreadyMissing.
@Test
public void testComputingClauseNameWithoutModelRefWhenModelRefAlreadyMissing() {
final ItemDefinition itemComponent = new ItemDefinition();
itemComponent.setName(new Name("age"));
itemComponent.setAllowOnlyVisualChange(true);
assertEquals("age", new DecisionTableEditorDefinitionEnricher(null, null, null).computeClauseName(itemComponent));
}
Aggregations