Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package net.nan21.dnet.core.web.controller.workflow;
  
  import java.util.HashMap;
  import java.util.Map;
  import java.util.UUID;
  
  import  javax.servlet.http.HttpServletRequest;
 import  javax.servlet.http.HttpServletResponse;
 
 import  org.activiti.engine.ProcessEngine;
 import  org.activiti.engine.RepositoryService;
 import  org.activiti.engine.RuntimeService;
 import  org.activiti.engine.impl.RepositoryServiceImpl;
 import  org.activiti.engine.impl.bpmn.diagram.ProcessDiagramGenerator;
 import  org.activiti.engine.impl.persistence.entity.ExecutionEntity;
 import  org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
 import  org.activiti.engine.impl.util.IoUtil;
 import  org.activiti.engine.runtime.ProcessInstance;
 import  org.springframework.stereotype.Controller;
 import  org.springframework.web.bind.annotation.PathVariable;
 import  org.springframework.web.bind.annotation.RequestMapping;
 import  org.springframework.web.bind.annotation.RequestParam;
 import  org.springframework.web.bind.annotation.ResponseBody;
 
 @Controller
 @RequestMapping(value = "/process-instance")
 public class WorkflowProcessInstanceController extends
Start a new instance of the specified process definition

Parameters:
processDefinitionId
processDefinitionKey
businessKey
request
response
Returns:
Throws:
Exception
 
 	@SuppressWarnings("unchecked")
 	@RequestMapping(value = "/start")
 	@ResponseBody
 	public String startInstance(
 			@RequestParam(required = false, value = "processDefinitionId"String processDefinitionId,
 			@RequestParam(required = false, value = "processDefinitionKey"String processDefinitionKey,
 			@RequestParam(required = false, value = "businessKey"String businessKey,
 			HttpServletRequest request, HttpServletResponse response)
 			throws Exception {
 
 		try {
 			this.prepareRequest(requestresponse);
 
 			ProcessInstance processInstance = null;
 			Map<StringObjectvariables = new HashMap<StringObject>();
 
 			Enumeration<Stringit = request.getParameterNames();
 			while (it.hasMoreElements()) {
 				String k = it.nextElement();
 				variables.put(krequest.getParameter(k));
 			}
 
 			if (businessKey == null || businessKey.equals("")) {
 				businessKey = UUID.randomUUID().toString().toUpperCase();
 			}
 			variables.remove("processDefinitionId");
 			variables.remove("processDefinitionKey");
 			variables.remove("businessKey");
 			if (processDefinitionKey != null
 					&& !processDefinitionKey.equals("")) {
 				processInstance = getWorkflowRuntimeService()
 						.startProcessInstanceByKey(processDefinitionKey,
 								businessKeyvariables);
 			} else {
 				processInstance = getWorkflowRuntimeService()
 						.startProcessInstanceById(processDefinitionId,
 								businessKeyvariables);
 			}
 
 			return "{\"success\":true, \"id\": \"" + processInstance.getId()
 					+ "\", \"processDefinitionId\": \""
 					+ processInstance.getProcessDefinitionId()
 					+ "\",\"activityNames\": [],\"ended\": true }";
 		} catch (Exception e) {
 			return this.handleException(eresponse);
 		} finally {
 			this.finishRequest();
 		}
 	}

Get the diagram of the process definition the specified process instance belongs to.

Parameters:
processInstanceId
request
response
Returns:
Throws:
Exception
	@RequestMapping(value = "/{processInstanceId}/diagram")
	@ResponseBody
			@PathVariable("processInstanceId"String processInstanceId,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
			this.prepareRequest(requestresponse);
			ProcessEngine processEngine = getWorkflowEngine();
			RepositoryService repositoryService = processEngine
					.getRepositoryService();
			RuntimeService runtimeService = processEngine.getRuntimeService();
			ExecutionEntity pi = (ExecutionEntity) runtimeService
					.createProcessInstanceQuery()
					.processInstanceId(processInstanceId).singleResult();
			if (pi == null) {
				throw new Exception("Process instance with id"
processInstanceId + " could not be found");
			}
			ProcessDefinitionEntity pde = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
					.getDeployedProcessDefinition(pi.getProcessDefinitionId());
			if (pde != null && pde.isGraphicalNotationDefined()) {
				InputStream stream = null;
				try {
					stream = ProcessDiagramGenerator.generateDiagram(pde,
							"png"runtimeService
									.getActiveActivityIds(processInstanceId));
					this.sendFile(streamresponse.getOutputStream());
finally {
					IoUtil.closeSilently(stream);
				}
else {
				throw new Exception("Process instance with id "
processInstanceId + " has no graphic description");
			}
			return null;
catch (Exception e) {
			return this.handleException(eresponse);
finally {
		}
	}
New to GrepCode? Check out our FAQ X