use of org.kie.dmn.core.assembler.DMNResource in project drools by kiegroup.
the class DMNValidatorImpl method validate.
@Override
public List<DMNMessage> validate(Resource resource, Validation... options) {
DMNMessageManager results = new DefaultDMNMessagesManager(resource);
EnumSet<Validation> flags = EnumSet.copyOf(Arrays.asList(options));
try {
// We get passed a Resource, which might be constructed from a Reader, so we have only 1-time opportunity to be sure to read it successfully,
// we internalize the content:
String content = readContent(resource.getReader());
if (flags.contains(VALIDATE_SCHEMA)) {
results.addAll(validateSchema(content, resource.getSourcePath()));
}
if (flags.contains(VALIDATE_MODEL) || flags.contains(VALIDATE_COMPILATION) || flags.contains(ANALYZE_DECISION_TABLE)) {
DMNResource dmnResource = unmarshallDMNResource(dmnCompilerConfig, resource, content);
validateModelCompilation(dmnResource, results, flags);
}
} catch (Throwable t) {
MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, null, results, t, null, Msg.VALIDATION_RUNTIME_PROBLEM, t.getMessage());
}
return results.getMessages();
}
use of org.kie.dmn.core.assembler.DMNResource 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();
}
Aggregations