Search in sources :

Example 1 with DMNResource

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();
}
Also used : DMNMessageManager(org.kie.dmn.core.api.DMNMessageManager) DMNResource(org.kie.dmn.core.assembler.DMNResource) DefaultDMNMessagesManager(org.kie.dmn.core.util.DefaultDMNMessagesManager)

Example 2 with DMNResource

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();
}
Also used : Arrays(java.util.Arrays) DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) DMNMessage(org.kie.dmn.api.core.DMNMessage) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) DMNCompilerImpl(org.kie.dmn.core.compiler.DMNCompilerImpl) FileSystemResource(org.drools.core.io.impl.FileSystemResource) CommandFactory(org.kie.internal.command.CommandFactory) XStreamMarshaller(org.kie.dmn.backend.marshalling.v1x.XStreamMarshaller) DMNModel(org.kie.dmn.api.core.DMNModel) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) ResourceWithConfigurationImpl(org.kie.internal.io.ResourceWithConfigurationImpl) DMNAssemblerService(org.kie.dmn.core.assembler.DMNAssemblerService) DMNCompilerConfiguration(org.kie.dmn.api.core.DMNCompilerConfiguration) DMNProfile(org.kie.dmn.core.compiler.DMNProfile) EnumSet(java.util.EnumSet) DMNFactory(org.kie.dmn.core.api.DMNFactory) DMNCompilerConfigurationImpl(org.kie.dmn.core.compiler.DMNCompilerConfigurationImpl) DefaultDMNMessagesManager(org.kie.dmn.core.util.DefaultDMNMessagesManager) DMN_VERSION(org.kie.dmn.backend.marshalling.v1x.XStreamMarshaller.DMN_VERSION) Collection(java.util.Collection) Set(java.util.Set) Reader(java.io.Reader) ChainedProperties(org.kie.internal.utils.ChainedProperties) Collectors(java.util.stream.Collectors) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) Resource(org.kie.api.io.Resource) List(java.util.List) Stream(java.util.stream.Stream) VALIDATE_SCHEMA(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_SCHEMA) SAXException(org.xml.sax.SAXException) InternalDMNDTAnalyserFactory(org.kie.dmn.validation.dtanalysis.InternalDMNDTAnalyserFactory) ANALYZE_DECISION_TABLE(org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) QName(javax.xml.namespace.QName) MsgUtil(org.kie.dmn.core.util.MsgUtil) BaseResource(org.drools.core.io.impl.BaseResource) DMNMessageImpl(org.kie.dmn.core.impl.DMNMessageImpl) VALIDATE_COMPILATION(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION) StreamSource(javax.xml.transform.stream.StreamSource) ReaderResource(org.drools.core.io.impl.ReaderResource) ClassLoaderUtil(org.kie.dmn.feel.util.ClassLoaderUtil) Source(javax.xml.transform.Source) Function(java.util.function.Function) Schema(javax.xml.validation.Schema) Definitions(org.kie.dmn.model.api.Definitions) ArrayList(java.util.ArrayList) DMNMarshallerFactory(org.kie.dmn.backend.marshalling.v1x.DMNMarshallerFactory) XMLConstants(javax.xml.XMLConstants) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) InternalDMNDTAnalyser(org.kie.dmn.validation.dtanalysis.InternalDMNDTAnalyser) Properties(java.util.Properties) SchemaFactory(javax.xml.validation.SchemaFactory) Logger(org.slf4j.Logger) DMNMessageManager(org.kie.dmn.core.api.DMNMessageManager) IOException(java.io.IOException) Validator(javax.xml.validation.Validator) File(java.io.File) KieBaseBuilder(org.drools.modelcompiler.builder.KieBaseBuilder) Collectors.toList(java.util.stream.Collectors.toList) StringReader(java.io.StringReader) DMNResourceDependenciesSorter(org.kie.dmn.core.assembler.DMNResourceDependenciesSorter) DMNResource(org.kie.dmn.core.assembler.DMNResource) Msg(org.kie.dmn.core.util.Msg) VALIDATE_MODEL(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_MODEL) Collections(java.util.Collections) DecisionService(org.kie.dmn.model.api.DecisionService) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) Definitions(org.kie.dmn.model.api.Definitions) DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) DecisionService(org.kie.dmn.model.api.DecisionService) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) StatelessKieSession(org.kie.api.runtime.StatelessKieSession)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Properties (java.util.Properties)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 XMLConstants (javax.xml.XMLConstants)1 QName (javax.xml.namespace.QName)1