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 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 DataTypePickerWidget method addItemDefinitions.
void addItemDefinitions() {
final Definitions definitions = dmnGraphUtils.getModelDefinitions();
final List<ItemDefinition> itemDefinitions = definitions != null ? definitions.getItemDefinition() : Collections.emptyList();
final OptGroup group = GWT.create(OptGroup.class);
group.setLabel(translationService.getTranslation(DMNEditorConstants.DataTypeSelectView_CustomTitle));
itemDefinitions.stream().sorted(ITEM_DEFINITION_COMPARATOR).map(this::makeTypeSelector).filter(Optional::isPresent).forEach(o -> group.add(o.get()));
typeSelector.add(group);
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DefinitionsConverterTest method wbFromDMN.
@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());
}
use of org.kie.workbench.common.dmn.api.definition.model.Definitions in project kie-wb-common by kiegroup.
the class DMNDomainValidatorImplTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() throws IOException {
this.definitions = new Definitions();
this.validationMessages = new ArrayList<>();
this.domainValidator = spy(new DMNDomainValidatorImpl(dmnMarshaller, dmnDiagramUtils, importsHelper, dmnIOHelper));
doReturn(dmnValidator).when(domainValidator).getDMNValidator();
domainValidator.setupValidator();
when(dmnMarshaller.marshall(diagram)).thenReturn(DMN_XML);
when(dmnDiagramUtils.getDefinitions(diagram)).thenReturn(definitions);
when(dmnValidator.validateUsing(any())).thenReturn(dmnValidatorBuilder);
when(dmnValidatorBuilder.usingImports(resolver)).thenReturn(dmnValidatorBuilder);
when(dmnValidatorBuilder.theseModels(Mockito.<Reader>any())).thenReturn(validationMessages);
when(diagram.getMetadata()).thenReturn(metadata);
}
Aggregations