use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class HrefBuilderTest method testGetHrefForImportedDRGElement.
@Test
public void testGetHrefForImportedDRGElement() {
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 = "includedModel";
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 DMNDomainValidatorImpl method validate.
@Override
public Collection<DomainViolation> validate(final Diagram diagram, final String diagramXml) {
final List<Reader> dmnXMLReaders = new ArrayList<>();
try {
dmnXMLReaders.add(getStringReader(diagramXml));
// Load Readers for all other imported DMN models.
final Definitions uiDefinitions = dmnDiagramUtils.getDefinitions(diagram);
final List<Import> uiImports = uiDefinitions.getImport();
final List<org.kie.dmn.model.api.Import> dmnImports = uiImports.stream().map(ImportConverter::dmnFromWb).collect(Collectors.toList());
final Metadata metadata = diagram.getMetadata();
final Map<org.kie.dmn.model.api.Import, String> importedDiagramsXML = importsHelper.getImportXML(metadata, dmnImports);
importedDiagramsXML.values().forEach(importedDiagramXML -> dmnXMLReaders.add(getStringReader(importedDiagramXML)));
final Reader[] aDMNXMLReaders = new Reader[] {};
final List<DMNMessage> messages = dmnValidator.validateUsing(DMNValidator.Validation.VALIDATE_MODEL, DMNValidator.Validation.VALIDATE_COMPILATION, DMNValidator.Validation.ANALYZE_DECISION_TABLE).usingImports(getValidatorImportReaderResolver(metadata)).theseModels(dmnXMLReaders.toArray(aDMNXMLReaders));
return convert(messages);
} finally {
dmnXMLReaders.forEach(reader -> {
try {
reader.close();
} catch (IOException ioe) {
// Swallow. The Reader is already closed.
}
});
}
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenTopLevelDecisionTableWithMultipleHierarchyCustomTypes.
@Test
@SuppressWarnings("unchecked")
public void testModelEnrichmentWhenTopLevelDecisionTableWithMultipleHierarchyCustomTypes() {
setupGraphWithDiagram();
setupGraphWithInputData();
final Definitions definitions = diagram.getDefinitions();
final String tSmurf = "tSmurf";
final String tSmurfAddress = "tSmurfAddress";
final QName dateBuiltInType = new QName(QName.NULL_NS_URI, BuiltInType.DATE.getName());
final QName stringBuiltInType = new QName(QName.NULL_NS_URI, STRING.getName());
final ItemDefinition tSmurfAddressCustomDataType = new ItemDefinition();
tSmurfAddressCustomDataType.setName(new Name(tSmurfAddress));
tSmurfAddressCustomDataType.getItemComponent().add(new ItemDefinition() {
{
setName(new Name("line1"));
setTypeRef(stringBuiltInType);
}
});
tSmurfAddressCustomDataType.getItemComponent().add(new ItemDefinition() {
{
setName(new Name("line2"));
setTypeRef(stringBuiltInType);
}
});
final ItemDefinition tSmurfCustomDataType = new ItemDefinition();
tSmurfCustomDataType.setName(new Name(tSmurf));
tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {
{
setName(new Name("dob"));
setTypeRef(dateBuiltInType);
}
});
tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {
{
setName(new Name("address"));
getItemComponent().add(tSmurfAddressCustomDataType);
}
});
definitions.getItemDefinition().add(tSmurfCustomDataType);
final QName inputData1TypeRef = new QName(QName.NULL_NS_URI, tSmurf);
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 + ".address." + tSmurfAddress + ".line1");
assertThat(input.get(1).getInputExpression().getTypeRef()).isEqualTo(stringBuiltInType);
assertThat(input.get(2).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(2).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + ".address." + tSmurfAddress + ".line2");
assertThat(input.get(2).getInputExpression().getTypeRef()).isEqualTo(stringBuiltInType);
assertThat(input.get(3).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(3).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + ".dob");
assertThat(input.get(3).getInputExpression().getTypeRef()).isEqualTo(dateBuiltInType);
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 AbstractDMNDiagramFactory method updateName.
private void updateName(final Node<Definition<DMNDiagram>, ?> diagramNode, final String name) {
final DMNDiagram dmnDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(diagramNode);
final Definitions dmnDefinitions = dmnDiagram.getDefinitions();
final Name dmnName = dmnDefinitions.getName();
if (StringUtils.isEmpty(dmnName.getValue())) {
dmnName.setValue(name);
}
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class AbstractDMNDiagramFactory method updateDefaultNameSpaces.
private void updateDefaultNameSpaces(final Node<Definition<DMNDiagram>, ?> diagramNode) {
final DMNDiagram dmnDiagram = (DMNDiagram) DefinitionUtils.getElementDefinition(diagramNode);
final Definitions dmnDefinitions = dmnDiagram.getDefinitions();
Stream.of(DMNModelInstrumentedBase.Namespace.values()).filter(namespace -> !dmnDefinitions.getNsContext().containsValue(namespace.getUri())).forEach(namespace -> {
if (!namespace.getPrefix().equalsIgnoreCase(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix())) {
dmnDefinitions.getNsContext().put(namespace.getPrefix(), namespace.getUri());
}
});
String defaultNamespace = !StringUtils.isEmpty(dmnDefinitions.getNamespace().getValue()) ? dmnDefinitions.getNamespace().getValue() : DMNModelInstrumentedBase.Namespace.DEFAULT.getUri() + UUID.uuid();
dmnDefinitions.setNamespace(new Text(defaultNamespace));
dmnDefinitions.getNsContext().putIfAbsent(DMNModelInstrumentedBase.Namespace.DEFAULT.getPrefix(), defaultNamespace);
}
Aggregations