use of org.kie.dmn.api.marshalling.DMNMarshaller in project drools by kiegroup.
the class DMNXMLLoaderTest method test0004_multiple_extensions.
@Test
public void test0004_multiple_extensions() throws Exception {
DMNMarshaller marshaller = DMNMarshallerFactory.newMarshallerWithExtensions(Arrays.asList(new DecisionServicesExtensionRegister()));
final InputStream is = this.getClass().getResourceAsStream("0004-decision-services_multiple_extensions.dmn");
final InputStreamReader isr = new InputStreamReader(is);
final Definitions def = marshaller.unmarshal(isr);
assertThat(def.getExtensionElements().getAny().size(), is(1));
// if arrived here, means it did not fail with exception while trying to unmarshall unknown rss extension element, hence it just skipped it.
}
use of org.kie.dmn.api.marshalling.DMNMarshaller in project drools by kiegroup.
the class UnmarshalMarshalTest method test0004_ns_other_location.
@Test
public void test0004_ns_other_location() throws Exception {
DMNMarshaller marshaller = DMNMarshallerFactory.newMarshallerWithExtensions(Arrays.asList(new DecisionServicesExtensionRegister()));
testRoundTrip("org/kie/dmn/backend/marshalling/v1_1/", "0004-decision-services_ns_other_location.dmn", marshaller);
}
use of org.kie.dmn.api.marshalling.DMNMarshaller in project drools by kiegroup.
the class ValidatorTest method utilDefinitions.
private Definitions utilDefinitions(String filename, String modelName) {
// List<DMNMessage> validateXML;
// try {
// validateXML = validator.validate( new File(this.getClass().getResource(filename).toURI()), DMNValidator.Validation.VALIDATE_SCHEMA );
// assertThat( "using unit test method utilDefinitions must received a XML valid DMN file", validateXML, IsEmptyCollection.empty() );
// } catch (URISyntaxException e) {
// e.printStackTrace();
// fail("Unable for the test suite to locate the file for XML validation.");
// }
DMNMarshaller marshaller = DMNMarshallerFactory.newDefaultMarshaller();
try (InputStreamReader isr = new InputStreamReader(getClass().getResourceAsStream(filename))) {
Definitions definitions = marshaller.unmarshal(isr);
assertThat(definitions, notNullValue());
return definitions;
} catch (IOException e) {
e.printStackTrace();
fail("Unable for the test suite to locate the file for validation.");
}
return null;
}
use of org.kie.dmn.api.marshalling.DMNMarshaller in project drools by kiegroup.
the class XLS2DMNParser method parseWorkbook.
public void parseWorkbook(String dmnModelName, Workbook workbook) {
Map<String, List<String>> overview = new HashMap<>();
DataFormatter formatter = new DataFormatter();
for (int s = 0; s < workbook.getNumberOfSheets(); s++) {
Sheet sheet = workbook.getSheetAt(s);
int maxRows = sheet.getLastRowNum();
for (int i = 0; i <= maxRows; i++) {
Row row = sheet.getRow(i);
int lastCellNum = row != null ? row.getLastCellNum() : 0;
if (lastCellNum == 0) {
// skip empty row.
continue;
}
List<String> header = new ArrayList<>();
for (Cell c : row) {
String text = formatter.formatCellValue(c);
header.add(text);
}
overview.put(sheet.getSheetName(), header);
// header found.
break;
}
}
overview.entrySet().forEach(e -> LOG.debug("{}", e));
Map<String, DTHeaderInfo> headerInfos = generateDTHeaderInfo(overview);
LOG.info("Sheets have been indexed as:");
headerInfos.entrySet().forEach(e -> LOG.info("{}", e));
Definitions definitions = new TDefinitions();
setDefaultNSContext(definitions);
definitions.setId("dmnid_" + dmnModelName);
definitions.setName(dmnModelName);
String namespace = "xls2dmn_" + UUID.randomUUID();
definitions.setNamespace(namespace);
definitions.getNsContext().put(XMLConstants.DEFAULT_NS_PREFIX, namespace);
definitions.setExporter("kie-dmn-xls2dmn");
appendInputData(definitions, headerInfos);
appendDecisionDT(definitions, headerInfos);
final Map<String, List<DataListener>> sheetListeners = new HashMap<>();
for (DTHeaderInfo hi : headerInfos.values()) {
String sheetName = hi.getSheetName();
DRGElement drgElem = definitions.getDrgElement().stream().filter(e -> e.getName().equals(sheetName)).findFirst().orElseThrow(() -> new XLS2DMNException("Unable to locate DRG element for sheet: " + sheetName));
DecisionTable dt = (DecisionTable) ((Decision) drgElem).getExpression();
DTSheetListener listener = new DTSheetListener(dt, hi);
sheetListeners.put(sheetName, Arrays.asList(listener));
}
new ExcelParser(sheetListeners).parseWorkbook(workbook);
DMNMarshaller dmnMarshaller = DMNMarshallerFactory.newDefaultMarshaller();
String xml = dmnMarshaller.marshal(definitions);
try {
Files.write(outFile.toPath(), xml.getBytes());
} catch (IOException e) {
LOG.error("Unable to write to outputfile.", e);
throw new XLS2DMNException("Unable to write to outputfile", e);
}
LOG.debug("output XML can be displayed at trace level", xml);
LOG.trace("output XML:\n{}", xml);
}
use of org.kie.dmn.api.marshalling.DMNMarshaller in project kie-wb-common by kiegroup.
the class DMNMarshallerProducerTest method testGet.
@Test
public void testGet() {
final DMNMarshallerProducer producer = new DMNMarshallerProducer();
final DMNMarshaller marshaller = producer.get();
assertNotNull(marshaller);
assertSame(marshaller, producer.get());
assertSame(marshaller, producer.get());
}
Aggregations