Search in sources :

Example 1 with ProcessLoadError

use of org.drools.compiler.compiler.ProcessLoadError in project drools by kiegroup.

the class KnowledgeBuilderImpl method addProcessFromXml.

public void addProcessFromXml(Resource resource) {
    if (processBuilder == null) {
        throw new RuntimeException("Unable to instantiate a process assembler");
    }
    if (ResourceType.DRF.equals(resource.getResourceType())) {
        addBuilderResult(new DeprecatedResourceTypeWarning(resource, "RF"));
    }
    this.resource = resource;
    try {
        List<Process> processes = processBuilder.addProcessFromXml(resource);
        List<BaseKnowledgeBuilderResultImpl> errors = processBuilder.getErrors();
        if (errors.isEmpty()) {
            if (this.kBase != null && processes != null) {
                for (Process process : processes) {
                    if (filterAccepts(ResourceChange.Type.PROCESS, process.getNamespace(), process.getId())) {
                        this.kBase.addProcess(process);
                    }
                }
            }
        } else {
            this.results.addAll(errors);
            errors.clear();
        }
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        addBuilderResult(new ProcessLoadError(resource, "Unable to load process.", e));
    }
    this.results = getResults(this.results);
    this.resource = null;
}
Also used : ProcessLoadError(org.drools.compiler.compiler.ProcessLoadError) BaseKnowledgeBuilderResultImpl(org.drools.compiler.compiler.BaseKnowledgeBuilderResultImpl) Process(org.kie.api.definition.process.Process) DeprecatedResourceTypeWarning(org.drools.compiler.compiler.DeprecatedResourceTypeWarning) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ExpanderException(org.drools.compiler.lang.ExpanderException) DroolsParserException(org.drools.compiler.compiler.DroolsParserException) SAXException(org.xml.sax.SAXException)

Example 2 with ProcessLoadError

use of org.drools.compiler.compiler.ProcessLoadError in project drools by kiegroup.

the class RuleFlowErrorTest method testError.

@Test
public void testError() {
    ProcessLoadError err = new ProcessLoadError(null, "XXX", null);
    assertEquals("XXX", err.getMessage());
    Exception e = new RuntimeException("Q");
    err = new ProcessLoadError(null, "X", e);
    assertNotNull(err.getMessage());
    assertTrue(err instanceof DroolsError);
}
Also used : DroolsError(org.drools.compiler.compiler.DroolsError) ProcessLoadError(org.drools.compiler.compiler.ProcessLoadError) Test(org.junit.Test)

Example 3 with ProcessLoadError

use of org.drools.compiler.compiler.ProcessLoadError in project jbpm by kiegroup.

the class ProcessBuilderImpl method addProcessFromXml.

public List<Process> addProcessFromXml(final Resource resource) throws IOException {
    Reader reader = resource.getReader();
    KnowledgeBuilderConfigurationImpl configuration = knowledgeBuilder.getBuilderConfiguration();
    XmlProcessReader xmlReader = new XmlProcessReader(configuration.getSemanticModules(), knowledgeBuilder.getRootClassLoader());
    List<Process> processes = null;
    try {
        String portRuleFlow = System.getProperty("drools.ruleflow.port", "false");
        Reader portedReader = null;
        if (portRuleFlow.equalsIgnoreCase("true")) {
            portedReader = portToCurrentVersion(reader);
        } else {
            portedReader = reader;
        }
        processes = xmlReader.read(portedReader);
        if (processes != null) {
            // stop null pointers
            for (Process process : processes) {
                buildProcess(process, resource);
                xmlReader.getProcessBuildData().onBuildComplete(process);
            }
        } else {
            // @TODO could we maybe add something a bit more informative about what is wrong with the XML ?
            this.errors.add(new ProcessLoadError(resource, "unable to parse xml", null));
        }
    } catch (FactoryConfigurationError e1) {
        this.errors.add(new ProcessLoadError(resource, "FactoryConfigurationError ", e1.getException()));
    } catch (Exception e2) {
        e2.printStackTrace();
        this.errors.add(new ProcessLoadError(resource, "unable to parse xml", e2));
    } finally {
        reader.close();
    }
    return processes;
}
Also used : ProcessLoadError(org.drools.compiler.compiler.ProcessLoadError) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) XmlProcessReader(org.jbpm.compiler.xml.XmlProcessReader) XmlProcessReader(org.jbpm.compiler.xml.XmlProcessReader) Reader(java.io.Reader) StringReader(java.io.StringReader) DuplicateProcess(org.drools.compiler.compiler.DuplicateProcess) Process(org.kie.api.definition.process.Process) WorkflowProcess(org.kie.api.definition.process.WorkflowProcess) FactoryConfigurationError(javax.xml.parsers.FactoryConfigurationError) DroolsParserException(org.drools.compiler.compiler.DroolsParserException) IOException(java.io.IOException)

Aggregations

ProcessLoadError (org.drools.compiler.compiler.ProcessLoadError)3 IOException (java.io.IOException)2 DroolsParserException (org.drools.compiler.compiler.DroolsParserException)2 Process (org.kie.api.definition.process.Process)2 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 ExecutionException (java.util.concurrent.ExecutionException)1 FactoryConfigurationError (javax.xml.parsers.FactoryConfigurationError)1 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)1 BaseKnowledgeBuilderResultImpl (org.drools.compiler.compiler.BaseKnowledgeBuilderResultImpl)1 DeprecatedResourceTypeWarning (org.drools.compiler.compiler.DeprecatedResourceTypeWarning)1 DroolsError (org.drools.compiler.compiler.DroolsError)1 DuplicateProcess (org.drools.compiler.compiler.DuplicateProcess)1 ExpanderException (org.drools.compiler.lang.ExpanderException)1 XmlProcessReader (org.jbpm.compiler.xml.XmlProcessReader)1 Test (org.junit.Test)1 WorkflowProcess (org.kie.api.definition.process.WorkflowProcess)1 SAXException (org.xml.sax.SAXException)1