use of org.kie.workbench.common.dmn.api.definition.model.Definitions 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();
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions 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.Definitions 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.Definitions 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.Definitions in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndComplexCustomType.
@Test
@SuppressWarnings("unchecked")
public void testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndComplexCustomType() {
setupGraphWithDiagram();
setupGraphWithInputData();
final Definitions definitions = diagram.getDefinitions();
final String complexItemDefinitionName = "tSmurf";
final String complexItemDefinitionPart1Name = "tDateOfBirth";
final String complexItemDefinitionPart2Name = "tIsBlue";
final QName complexItemDefinitionPart1TypeRef = new QName(QName.NULL_NS_URI, BuiltInType.DATE.getName());
final QName complexItemDefinitionPart2TypeRef = new QName(QName.NULL_NS_URI, BuiltInType.BOOLEAN.getName());
final ItemDefinition complexItemDefinition = new ItemDefinition();
complexItemDefinition.setName(new Name(complexItemDefinitionName));
complexItemDefinition.getItemComponent().add(new ItemDefinition() {
{
setName(new Name(complexItemDefinitionPart1Name));
setTypeRef(complexItemDefinitionPart1TypeRef);
}
});
complexItemDefinition.getItemComponent().add(new ItemDefinition() {
{
setName(new Name(complexItemDefinitionPart2Name));
setTypeRef(complexItemDefinitionPart2TypeRef);
}
});
definitions.getItemDefinition().add(complexItemDefinition);
final QName inputData1TypeRef = new QName(QName.NULL_NS_URI, complexItemDefinitionName);
inputData1.getVariable().setTypeRef(inputData1TypeRef);
final Optional<DecisionTable> oModel = definition.getModelClass();
definition.enrich(Optional.of(NODE_UUID), decision, oModel);
final DecisionTable model = oModel.get();
assertBasicEnrichment(model);
final List<InputClause> input = model.getInput();
assertThat(input.size()).isEqualTo(3);
assertThat(input.get(0).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(0).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_2);
assertThat(input.get(0).getInputExpression().getTypeRef()).isEqualTo(INPUT_DATA_QNAME_2);
assertThat(input.get(1).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(1).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + complexItemDefinitionPart1Name);
assertThat(input.get(1).getInputExpression().getTypeRef()).isEqualTo(complexItemDefinitionPart1TypeRef);
assertThat(input.get(2).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(2).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + complexItemDefinitionPart2Name);
assertThat(input.get(2).getInputExpression().getTypeRef()).isEqualTo(complexItemDefinitionPart2TypeRef);
assertStandardOutputClauseEnrichment(model);
assertStandardDecisionRuleEnrichment(model);
assertParentHierarchyEnrichment(model);
}
Aggregations