use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndRecursiveCustomType.
@Test
@SuppressWarnings("unchecked")
public void testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndRecursiveCustomType() {
setupGraphWithDiagram();
setupGraphWithInputData();
final Definitions definitions = diagram.getDefinitions();
final String tSmurfName = "tSmurf";
final String tDateOfBirthName = "tDateOfBirth";
final String tIsBlueName = "tIsBlue";
final String tParentName = "tParent";
final QName dateBuiltInType = new QName(QName.NULL_NS_URI, BuiltInType.DATE.getName());
final QName booleanBuiltInType = new QName(QName.NULL_NS_URI, BuiltInType.BOOLEAN.getName());
final QName parentCustomType = new QName(QName.NULL_NS_URI, tSmurfName);
final ItemDefinition tSmurfCustomDataType = new ItemDefinition();
tSmurfCustomDataType.setName(new Name(tSmurfName));
tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {
{
setName(new Name(tDateOfBirthName));
setTypeRef(dateBuiltInType);
}
});
tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {
{
setName(new Name(tIsBlueName));
setTypeRef(booleanBuiltInType);
}
});
tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {
{
setName(new Name(tParentName));
setTypeRef(parentCustomType);
}
});
definitions.getItemDefinition().add(tSmurfCustomDataType);
final QName inputData1TypeRef = new QName(QName.NULL_NS_URI, tSmurfName);
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(4);
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 + "." + tDateOfBirthName);
assertThat(input.get(1).getInputExpression().getTypeRef()).isEqualTo(dateBuiltInType);
assertThat(input.get(2).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(2).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + tIsBlueName);
assertThat(input.get(2).getInputExpression().getTypeRef()).isEqualTo(booleanBuiltInType);
assertThat(input.get(3).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(3).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + tParentName);
assertThat(input.get(3).getInputExpression().getTypeRef()).isEqualTo(parentCustomType);
assertStandardOutputClauseEnrichment(model);
assertStandardDecisionRuleEnrichment(model);
assertParentHierarchyEnrichment(model);
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class PMMLDocumentMetadataProviderTest method setup.
@Before
public void setup() {
this.definitions = new Definitions();
this.provider = new PMMLDocumentMetadataProvider(graphUtils, clientServicesProxy, stateProvider);
final Diagram diagram = mock(Diagram.class);
final Metadata metadata = mock(Metadata.class);
when(stateProvider.getDiagram()).thenReturn(Optional.of(diagram));
when(diagram.getMetadata()).thenReturn(metadata);
when(metadata.getPath()).thenReturn(dmnModelPath);
when(graphUtils.getDefinitions(diagram)).thenReturn(definitions);
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class ExpressionEditor method handleCanvasElementUpdated.
@Override
public void handleCanvasElementUpdated(final CanvasElementUpdatedEvent event) {
final Element<?> element = event.getElement();
if ((element instanceof Node)) {
if (element.getContent() instanceof Definition) {
final Definition definition = (Definition) element.getContent();
final Optional<Definitions> definitions = Optional.ofNullable(dmnGraphUtils.getModelDefinitions());
definitions.ifPresent(d -> {
if (Objects.equals(d, definition.getDefinition())) {
view.setReturnToLinkText(returnToLinkTextSupplier.get());
}
});
hasExpression.ifPresent(e -> {
if (Objects.equals(e.asDMNModelInstrumentedBase(), definition.getDefinition())) {
view.setExpressionNameText(Optional.ofNullable((HasName) definition.getDefinition()));
view.refresh();
}
});
}
}
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class WrapperUtils 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 JSITDefinitions dmn, final Map<JSITImport, JSITDefinitions> importDefinitions, final Map<JSITImport, PMMLDocumentMetadata> pmmlDocuments) {
if (Objects.isNull(dmn)) {
return null;
}
final Id id = IdPropertyConverter.wbFromDMN(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.setExpressionLanguage(ExpressionLanguagePropertyConverter.wbFromDMN(dmn.getExpressionLanguage()));
result.setTypeLanguage(dmn.getTypeLanguage());
result.setDmnDiagramElements(getDMNDiagramElements(dmn));
result.setDescription(description);
final Map<String, String> namespaces = NameSpaceUtils.extractNamespacesKeyedByPrefix(dmn);
for (Entry<String, String> kv : namespaces.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);
}
}
final List<JSITItemDefinition> jsiItemDefinitions = dmn.getItemDefinition();
for (int i = 0; i < jsiItemDefinitions.size(); i++) {
final JSITItemDefinition jsiItemDefinition = Js.uncheckedCast(jsiItemDefinitions.get(i));
final ItemDefinition itemDefConverted = ItemDefinitionPropertyConverter.wbFromDMN(jsiItemDefinition);
if (Objects.nonNull(itemDefConverted)) {
itemDefConverted.setParent(result);
result.getItemDefinition().add(itemDefConverted);
}
}
final List<JSITImport> jsiImports = dmn.getImport();
for (int i = 0; i < jsiImports.size(); i++) {
final JSITImport jsiImport = Js.uncheckedCast(jsiImports.get(i));
final JSITDefinitions definitions = Js.uncheckedCast(importDefinitions.get(jsiImport));
final PMMLDocumentMetadata pmmlDocument = pmmlDocuments.get(jsiImport);
final Import importConverted = ImportConverter.wbFromDMN(jsiImport, definitions, pmmlDocument);
if (Objects.nonNull(importConverted)) {
importConverted.setParent(result);
result.getImport().add(importConverted);
}
}
return result;
}
Aggregations