Search in sources :

Example 6 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class CamelBehavior method setAppropriateCamelContext.

protected void setAppropriateCamelContext(ActivityExecution execution) {
    //Check to see if the springConfiguration has been set. If not, set it.
    if (springConfiguration == null) {
        //Get the ProcessEngineConfiguration object.
        ProcessEngineConfiguration engineConfiguration = Context.getProcessEngineConfiguration();
        // (ActivitiException extends RuntimeException.)
        try {
            springConfiguration = (SpringProcessEngineConfiguration) engineConfiguration;
        } catch (Exception e) {
            throw new ActivitiException("Expecting a SpringProcessEngineConfiguration for the Activiti Camel module.", e);
        }
    }
    //Get the appropriate String representation of the CamelContext object from ActivityExecution (if available).
    String camelContextValue = getStringFromField(camelContext, execution);
    //If the String representation of the CamelContext object from ActivityExecution is empty, use the default.
    if (StringUtils.isEmpty(camelContextValue) && camelContextObj != null) {
    //No processing required. No custom CamelContext & the default is already set.
    } else {
        if (StringUtils.isEmpty(camelContextValue) && camelContextObj == null) {
            camelContextValue = springConfiguration.getDefaultCamelContext();
        }
        //Get the CamelContext object and set the super's member variable.
        Object ctx = springConfiguration.getApplicationContext().getBean(camelContextValue);
        if (ctx == null || ctx instanceof CamelContext == false) {
            throw new ActivitiException("Could not find CamelContext named " + camelContextValue + ".");
        }
        camelContextObj = (CamelContext) ctx;
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) ActivitiException(org.activiti.engine.ActivitiException) SpringProcessEngineConfiguration(org.activiti.spring.SpringProcessEngineConfiguration) ProcessEngineConfiguration(org.activiti.engine.ProcessEngineConfiguration) ActivitiException(org.activiti.engine.ActivitiException)

Example 7 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class DeploymentQueryTest method testQueryNoCriteria.

public void testQueryNoCriteria() {
    DeploymentQuery query = repositoryService.createDeploymentQuery();
    assertEquals(2, query.list().size());
    assertEquals(2, query.count());
    try {
        query.singleResult();
        fail();
    } catch (ActivitiException e) {
    }
}
Also used : DeploymentQuery(org.activiti.engine.repository.DeploymentQuery) ActivitiException(org.activiti.engine.ActivitiException)

Example 8 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class CallActivityTest method testInstantiateSubprocess.

public void testInstantiateSubprocess() throws Exception {
    BpmnModel mainBpmnModel = loadBPMNModel(MAIN_PROCESS_RESOURCE);
    BpmnModel childBpmnModel = loadBPMNModel(CHILD_PROCESS_RESOURCE);
    Deployment childDeployment = processEngine.getRepositoryService().createDeployment().name("childProcessDeployment").addBpmnModel("childProcess.bpmn20.xml", childBpmnModel).deploy();
    Deployment masterDeployment = processEngine.getRepositoryService().createDeployment().name("masterProcessDeployment").addBpmnModel("masterProcess.bpmn20.xml", mainBpmnModel).deploy();
    suspendProcessDefinitions(childDeployment);
    try {
        ProcessInstance masterProcessInstance = runtimeService.startProcessInstanceByKey("masterProcess");
        fail("Exception expected");
    } catch (ActivitiException ae) {
        assertTextPresent("Cannot start process instance. Process definition Child Process", ae.getMessage());
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Deployment(org.activiti.engine.repository.Deployment) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 9 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class DelegateExpressionTaskListener method notify.

public void notify(DelegateTask delegateTask) {
    // Note: we can't cache the result of the expression, because the
    // execution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}'
    Object delegate = expression.getValue(delegateTask.getExecution());
    ClassDelegate.applyFieldDeclaration(fieldDeclarations, delegate);
    if (delegate instanceof TaskListener) {
        try {
            Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new TaskListenerInvocation((TaskListener) delegate, delegateTask));
        } catch (Exception e) {
            throw new ActivitiException("Exception while invoking TaskListener: " + e.getMessage(), e);
        }
    } else {
        throw new ActivitiIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + TaskListener.class);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskListenerInvocation(org.activiti.engine.impl.delegate.TaskListenerInvocation) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) TaskListener(org.activiti.engine.delegate.TaskListener) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Example 10 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class BpmnParse method execute.

public BpmnParse execute() {
    try {
        ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
        BpmnXMLConverter converter = new BpmnXMLConverter();
        boolean enableSafeBpmnXml = false;
        String encoding = null;
        if (processEngineConfiguration != null) {
            enableSafeBpmnXml = processEngineConfiguration.isEnableSafeBpmnXml();
            encoding = processEngineConfiguration.getXmlEncoding();
        }
        if (encoding != null) {
            bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml, encoding);
        } else {
            bpmnModel = converter.convertToBpmnModel(streamSource, validateSchema, enableSafeBpmnXml);
        }
        // XSD validation goes first, then process/semantic validation
        if (validateProcess) {
            ProcessValidator processValidator = processEngineConfiguration.getProcessValidator();
            if (processValidator == null) {
                LOGGER.warn("Process should be validated, but no process validator is configured on the process engine configuration!");
            } else {
                List<ValidationError> validationErrors = processValidator.validate(bpmnModel);
                if (validationErrors != null && !validationErrors.isEmpty()) {
                    StringBuilder warningBuilder = new StringBuilder();
                    StringBuilder errorBuilder = new StringBuilder();
                    for (ValidationError error : validationErrors) {
                        if (error.isWarning()) {
                            warningBuilder.append(error.toString());
                            warningBuilder.append("\n");
                        } else {
                            errorBuilder.append(error.toString());
                            errorBuilder.append("\n");
                        }
                    }
                    // Throw exception if there is any error
                    if (errorBuilder.length() > 0) {
                        throw new ActivitiException("Errors while parsing:\n" + errorBuilder.toString());
                    }
                    // Write out warnings (if any)
                    if (warningBuilder.length() > 0) {
                        LOGGER.warn("Following warnings encountered during process validation: " + warningBuilder.toString());
                    }
                }
            }
        }
        // Validation successfull (or no validation)
        createImports();
        createItemDefinitions();
        createMessages();
        createOperations();
        transformProcessDefinitions();
    } catch (Exception e) {
        if (e instanceof ActivitiException) {
            throw (ActivitiException) e;
        } else if (e instanceof XMLException) {
            throw (XMLException) e;
        } else {
            throw new ActivitiException("Error parsing XML", e);
        }
    }
    return this;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) XMLException(org.activiti.bpmn.exceptions.XMLException) ValidationError(org.activiti.validation.ValidationError) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ProcessValidator(org.activiti.validation.ProcessValidator) ActivitiException(org.activiti.engine.ActivitiException) XMLException(org.activiti.bpmn.exceptions.XMLException) MalformedURLException(java.net.MalformedURLException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter)

Aggregations

ActivitiException (org.activiti.engine.ActivitiException)247 Deployment (org.activiti.engine.test.Deployment)38 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)36 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)35 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)31 IOException (java.io.IOException)28 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)21 ArrayList (java.util.ArrayList)20 TaskQuery (org.activiti.engine.task.TaskQuery)16 HashMap (java.util.HashMap)14 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)14 Task (org.activiti.engine.task.Task)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 ObjectOutputStream (java.io.ObjectOutputStream)10 Date (java.util.Date)10 RestVariable (org.activiti.rest.service.api.engine.variable.RestVariable)10 JobExecutor (org.activiti.engine.impl.jobexecutor.JobExecutor)9