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);
}
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);
}
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);
}
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;
}
}
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);
}
Aggregations