use of org.kie.dmn.model.api.DMNModelInstrumentedBase in project drools by kiegroup.
the class DMNValidatorImpl method validateModel.
private List<DMNMessage> validateModel(DMNResource mainModel, List<DMNResource> otherModels) {
Definitions mainDefinitions = mainModel.getDefinitions();
StatelessKieSession kieSession = mainDefinitions instanceof org.kie.dmn.model.v1_1.KieDMNModelInstrumentedBase ? kb11.newStatelessKieSession() : kb12.newStatelessKieSession();
MessageReporter reporter = new MessageReporter(mainModel);
kieSession.setGlobal("reporter", reporter);
// exclude dynamicDecisionService for validation
List<DMNModelInstrumentedBase> dmnModelElements = allChildren(mainDefinitions).filter(d -> !(d instanceof DecisionService && Boolean.parseBoolean(d.getAdditionalAttributes().get(new QName("http://www.trisotech.com/2015/triso/modeling", "dynamicDecisionService"))))).collect(toList());
List<Definitions> otherModelsDefinitions = otherModels.stream().map(DMNResource::getDefinitions).collect(Collectors.toList());
BatchExecutionCommand batch = CommandFactory.newBatchExecution(Arrays.asList(CommandFactory.newInsertElements(dmnModelElements, "DEFAULT", false, "DEFAULT"), CommandFactory.newInsertElements(otherModelsDefinitions, "DMNImports", false, "DMNImports")));
kieSession.execute(batch);
return reporter.getMessages().getMessages();
}
use of org.kie.dmn.model.api.DMNModelInstrumentedBase in project drools by kiegroup.
the class DecisionServiceConverter method parseElements.
@Override
protected void parseElements(HierarchicalStreamReader reader, UnmarshallingContext context, Object parent) {
while (reader.hasMoreChildren()) {
reader.moveDown();
Object object = null;
String nodeName = reader.getNodeName();
if (nodeName.equals(INPUT_DATA)) {
// Patch because the tag name inputData is used in both decision services and as a DRG Element
DMNElementReference ref = new TDMNElementReference();
ref.setHref(reader.getAttribute("href"));
object = ref;
} else {
// Default behaviour
object = readItem(reader, context, null);
}
if (object instanceof DMNModelInstrumentedBase) {
((KieDMNModelInstrumentedBase) object).setParent((KieDMNModelInstrumentedBase) parent);
((KieDMNModelInstrumentedBase) parent).addChildren((KieDMNModelInstrumentedBase) object);
}
reader.moveUp();
assignChildElement(parent, nodeName, object);
}
}
use of org.kie.dmn.model.api.DMNModelInstrumentedBase in project drools by kiegroup.
the class XStreamMarshaller method marshal.
@Override
public String marshal(Object o) {
try (Writer writer = new StringWriter();
CustomStaxWriter hsWriter = (CustomStaxWriter) staxDriver.createWriter(writer)) {
XStream xStream = newXStream();
if (o instanceof DMNModelInstrumentedBase) {
KieDMNModelInstrumentedBase base = (KieDMNModelInstrumentedBase) o;
String dmnPrefix = base.getNsContext().entrySet().stream().filter(kv -> KieDMNModelInstrumentedBase.URI_DMN.equals(kv.getValue())).findFirst().map(Map.Entry::getKey).orElse("");
hsWriter.getQNameMap().setDefaultPrefix(dmnPrefix);
}
extensionRegisters.forEach(r -> r.beforeMarshal(o, hsWriter.getQNameMap()));
xStream.marshal(o, hsWriter);
hsWriter.flush();
return writer.toString();
} catch (Exception e) {
logger.error("Error marshalling DMN model to XML.", e);
}
return null;
}
use of org.kie.dmn.model.api.DMNModelInstrumentedBase in project drools by kiegroup.
the class DecisionServiceConverter method parseElements.
@Override
protected void parseElements(HierarchicalStreamReader reader, UnmarshallingContext context, Object parent) {
while (reader.hasMoreChildren()) {
reader.moveDown();
Object object = null;
String nodeName = reader.getNodeName();
if (nodeName.equals(INPUT_DATA)) {
// Patch because the tag name inputData is used in both decision services and as a DRG Element
DMNElementReference ref = new TDMNElementReference();
ref.setHref(reader.getAttribute("href"));
object = ref;
} else {
// Default behaviour
object = readItem(reader, context, null);
}
if (object instanceof DMNModelInstrumentedBase) {
((KieDMNModelInstrumentedBase) object).setParent((KieDMNModelInstrumentedBase) parent);
((KieDMNModelInstrumentedBase) parent).addChildren((KieDMNModelInstrumentedBase) object);
}
reader.moveUp();
assignChildElement(parent, nodeName, object);
}
}
use of org.kie.dmn.model.api.DMNModelInstrumentedBase in project drools by kiegroup.
the class ExtensionElementsConverter method unmarshal.
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
DMNModelInstrumentedBase obj = createModelObject();
assignAttributes(reader, obj);
if (extensionRegisters.size() == 0) {
while (reader.hasMoreChildren()) {
reader.moveDown();
String nodeName = reader.getNodeName();
// skipping nodeName
reader.moveUp();
}
} else {
// do as default behavior, but in case cannot unmarshall an extension element child, just skip it.
while (reader.hasMoreChildren()) {
reader.moveDown();
String nodeName = reader.getNodeName();
try {
Object object = readItem(reader, context, null);
if (object instanceof DMNModelInstrumentedBase) {
((KieDMNModelInstrumentedBase) object).setParent(obj);
((KieDMNModelInstrumentedBase) obj).addChildren((KieDMNModelInstrumentedBase) object);
}
assignChildElement(obj, nodeName, object);
} catch (CannotResolveClassException e) {
// do nothing; I tried to convert the extension element child with the converters, but no converter is registered for this child.
LOG.debug("Tried to convert the extension element child {}, but no converter is registered for this child.", nodeName);
}
reader.moveUp();
}
}
return obj;
}
Aggregations