Search in sources :

Example 51 with ActivitiException

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

the class MailActivityBehavior method execute.

@Override
public void execute(ActivityExecution execution) {
    boolean doIgnoreException = Boolean.parseBoolean(getStringFromField(ignoreException, execution));
    String exceptionVariable = getStringFromField(exceptionVariableName, execution);
    Email email = null;
    try {
        String toStr = getStringFromField(to, execution);
        String fromStr = getStringFromField(from, execution);
        String ccStr = getStringFromField(cc, execution);
        String bccStr = getStringFromField(bcc, execution);
        String subjectStr = getStringFromField(subject, execution);
        String textStr = textVar == null ? getStringFromField(text, execution) : getStringFromField(getExpression(execution, textVar), execution);
        String htmlStr = htmlVar == null ? getStringFromField(html, execution) : getStringFromField(getExpression(execution, htmlVar), execution);
        String charSetStr = getStringFromField(charset, execution);
        List<File> files = new LinkedList<File>();
        List<DataSource> dataSources = new LinkedList<DataSource>();
        getFilesFromFields(attachments, execution, files, dataSources);
        email = createEmail(textStr, htmlStr, attachmentsExist(files, dataSources));
        addTo(email, toStr);
        setFrom(email, fromStr, execution.getTenantId());
        addCc(email, ccStr);
        addBcc(email, bccStr);
        setSubject(email, subjectStr);
        setMailServerProperties(email, execution.getTenantId());
        setCharset(email, charSetStr);
        attach(email, files, dataSources);
        email.send();
    } catch (ActivitiException e) {
        handleException(execution, e.getMessage(), e, doIgnoreException, exceptionVariable);
    } catch (EmailException e) {
        handleException(execution, "Could not send e-mail in execution " + execution.getId(), e, doIgnoreException, exceptionVariable);
    }
    leave(execution);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Email(org.apache.commons.mail.Email) HtmlEmail(org.apache.commons.mail.HtmlEmail) MultiPartEmail(org.apache.commons.mail.MultiPartEmail) SimpleEmail(org.apache.commons.mail.SimpleEmail) EmailException(org.apache.commons.mail.EmailException) File(java.io.File) LinkedList(java.util.LinkedList) DataSource(javax.activation.DataSource)

Example 52 with ActivitiException

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

the class ShellActivityBehavior method execute.

public void execute(ActivityExecution execution) {
    readFields(execution);
    List<String> argList = new ArrayList<String>();
    argList.add(commandStr);
    if (arg1Str != null)
        argList.add(arg1Str);
    if (arg2Str != null)
        argList.add(arg2Str);
    if (arg3Str != null)
        argList.add(arg3Str);
    if (arg4Str != null)
        argList.add(arg4Str);
    if (arg5Str != null)
        argList.add(arg5Str);
    ProcessBuilder processBuilder = new ProcessBuilder(argList);
    try {
        processBuilder.redirectErrorStream(redirectErrorFlag);
        if (cleanEnvBoolan) {
            Map<String, String> env = processBuilder.environment();
            env.clear();
        }
        if (directoryStr != null && directoryStr.length() > 0)
            processBuilder.directory(new File(directoryStr));
        Process process = processBuilder.start();
        if (waitFlag) {
            int errorCode = process.waitFor();
            if (resultVariableStr != null) {
                String result = convertStreamToStr(process.getInputStream());
                execution.setVariable(resultVariableStr, result);
            }
            if (errorCodeVariableStr != null) {
                execution.setVariable(errorCodeVariableStr, Integer.toString(errorCode));
            }
        }
    } catch (Exception e) {
        throw new ActivitiException("Could not execute shell command ", e);
    }
    leave(execution);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ArrayList(java.util.ArrayList) File(java.io.File) ActivitiException(org.activiti.engine.ActivitiException) IOException(java.io.IOException)

Example 53 with ActivitiException

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

the class SubProcessActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    PvmActivity activity = execution.getActivity();
    ActivityImpl initialActivity = (ActivityImpl) activity.getProperty(BpmnParse.PROPERTYNAME_INITIAL);
    if (initialActivity == null) {
        throw new ActivitiException("No initial activity found for subprocess " + execution.getActivity().getId());
    }
    // initialize the template-defined data objects as variables
    initializeDataObjects(execution, activity);
    if (initialActivity.getActivityBehavior() != null && initialActivity.getActivityBehavior() instanceof NoneStartEventActivityBehavior) {
        // embedded subprocess: only none start allowed
        ((ExecutionEntity) execution).setActivity(initialActivity);
        Context.getCommandContext().getHistoryManager().recordActivityStart((ExecutionEntity) execution);
    }
    execution.executeActivity(initialActivity);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) PvmActivity(org.activiti.engine.impl.pvm.PvmActivity)

Example 54 with ActivitiException

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

the class CallActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    String processDefinitonKey = this.processDefinitonKey;
    if (processDefinitionExpression != null) {
        processDefinitonKey = (String) processDefinitionExpression.getValue(execution);
    }
    DeploymentManager deploymentManager = Context.getProcessEngineConfiguration().getDeploymentManager();
    ProcessDefinitionEntity processDefinition = null;
    if (execution.getTenantId() == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(execution.getTenantId())) {
        processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKey(processDefinitonKey);
    } else {
        processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKeyAndTenantId(processDefinitonKey, execution.getTenantId());
    }
    // Do not start a process instance if the process definition is suspended
    if (deploymentManager.isProcessDefinitionSuspended(processDefinition.getId())) {
        throw new ActivitiException("Cannot start process instance. Process definition " + processDefinition.getName() + " (id = " + processDefinition.getId() + ") is suspended");
    }
    PvmProcessInstance subProcessInstance = execution.createSubProcessInstance(processDefinition);
    if (inheritVariables) {
        Map<String, Object> variables = execution.getVariables();
        for (Map.Entry<String, Object> entry : variables.entrySet()) {
            subProcessInstance.setVariable(entry.getKey(), entry.getValue());
        }
    }
    // copy process variables
    for (AbstractDataAssociation dataInputAssociation : dataInputAssociations) {
        Object value = null;
        if (dataInputAssociation.getSourceExpression() != null) {
            value = dataInputAssociation.getSourceExpression().getValue(execution);
        } else {
            value = execution.getVariable(dataInputAssociation.getSource());
        }
        subProcessInstance.setVariable(dataInputAssociation.getTarget(), value);
    }
    try {
        subProcessInstance.start();
    } catch (Exception e) {
        if (!ErrorPropagation.mapException(e, execution, mapExceptions, true))
            throw e;
    }
}
Also used : PvmProcessInstance(org.activiti.engine.impl.pvm.PvmProcessInstance) ActivitiException(org.activiti.engine.ActivitiException) AbstractDataAssociation(org.activiti.engine.impl.bpmn.data.AbstractDataAssociation) DeploymentManager(org.activiti.engine.impl.persistence.deploy.DeploymentManager) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) Map(java.util.Map) ActivitiException(org.activiti.engine.ActivitiException)

Example 55 with ActivitiException

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

the class CancelEndEventActivityBehavior method execute.

@Override
public void execute(ActivityExecution execution) throws Exception {
    // find cancel boundary event:
    ActivityImpl cancelBoundaryEvent = ScopeUtil.findInParentScopesByBehaviorType((ActivityImpl) execution.getActivity(), CancelBoundaryEventActivityBehavior.class);
    if (cancelBoundaryEvent == null) {
        throw new ActivitiException("Could not find cancel boundary event for cancel end event " + execution.getActivity());
    }
    ActivityExecution scopeExecution = ScopeUtil.findScopeExecutionForScope((ExecutionEntity) execution, cancelBoundaryEvent.getParentActivity());
    // end all executions and process instances in the scope of the transaction
    scopeExecution.destroyScope("cancel end event fired");
    // the scope execution executes the boundary event
    InterpretableExecution outgoingExecution = (InterpretableExecution) scopeExecution;
    outgoingExecution.setActivity(cancelBoundaryEvent);
    outgoingExecution.setActive(true);
    // execute the boundary
    cancelBoundaryEvent.getActivityBehavior().execute(outgoingExecution);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution) InterpretableExecution(org.activiti.engine.impl.pvm.runtime.InterpretableExecution)

Aggregations

ActivitiException (org.activiti.engine.ActivitiException)289 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)45 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)44 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)38 IOException (java.io.IOException)35 ArrayList (java.util.ArrayList)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)22 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 FlowElement (org.activiti.bpmn.model.FlowElement)19 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Expression (org.activiti.engine.delegate.Expression)17 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)17 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)17 ObjectOutputStream (java.io.ObjectOutputStream)15 WorkflowException (org.alfresco.service.cmr.workflow.WorkflowException)15 HashMap (java.util.HashMap)12 ExecutionEntityManager (org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)11 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)11 InputStream (java.io.InputStream)10