Activiti flowchart view the example

  • 2020-04-01 03:24:17
  • OfStack

The example of this paper shows the implementation method of Activiti flowchart view, the specific steps are as follows:

1. Test case view picture code is as follows:


public void viewImage() throws Exception {
 //Create a repository service against the object
 RepositoryService repositoryService = processEngine.getRepositoryService();
 //Search the warehouse for documents that need to be displayed
 String deploymentId = "701";
 List<String> names = repositoryService.getDeploymentResourceNames(deploymentId);
 String imageName = null;
 for (String name : names) {
  if(name.indexOf(".png")>=0){
  imageName = name;
  }
 }
 if(imageName!=null){
//   System.out.println(imageName);
  File f = new File("e:/"+ imageName);
  //Get the input stream of the file by the deployment ID and the file name
  InputStream in = repositoryService.getResourceAsStream(deploymentId, imageName);
  FileUtils.copyInputStreamToFile(in, f);
 }

Description:

1)         DeploymentId is the process deploymentId

2)         ResourceName is the value of the NAME_ column in the act_ge_bytearray table

3)         Use the repositoryService getDeploymentResourceNames method can obtain specified deployment of the names of all files

4)         Using the getResourceAsStream method of repositoryService to pass in the deployment ID and file name, you get the input stream for the named file under deployment

5)         For the final IO stream operation, use the FileUtils tool's copyInputStreamToFile method to complete the process flow to the file copy

2. View pictures on the process definition page in the web project:


public String viewImage(){
InputStream in = repositoryService.getResourceAsStream.getImageStream(deploymentId,imageName);//Here the actual project of the method should be placed in the service
HttpServletResponse resp = ServletActionContext.getResponse();
try {
  OutputStream out = resp.getOutputStream();
  //Writes the input flow of the image into the resp output stream
  byte[] b = new byte[1024];
  for (int len = -1; (len= in.read(b))!=-1; ) {
 out.write(b, 0, len);
  }
  //Close the stream
  out.close();
  in.close();
} catch (IOException e) {
  e.printStackTrace();
}
return null;
}

Description:

1)         DeploymentId is the process deploymentId and imageName is the imageName

2)         Because images are viewed from the ProcessDefinition list page, the id and imageName can be retrieved from the ProcessDefinition (String getDeploymentId(); And the String getDiagramResourceName ())

3) web page tags < A target = "_blank" href = "viewImage & # 63; DeploymentId = 1 & amp; ImageName = imageName. PNG "rel =" external nofollow "> View flow chart < / a>

3. View the current flow chart of the web project


public String viewCurrentImage(){
ProcessDefinition pd = service.getProcessDefinitionByTaskId(taskId);
//1. Get the process deployment ID
putContext("deploymentId", pd.getDeploymentId());
//2. Get the name of the process picture
putContext("imageName", pd.getDiagramResourceName());

//3. Get the coordinates of the current activity
Map<String,Object> currentActivityCoordinates =service.getCurrentActivityCoordinates(taskId);
putContext("acs", currentActivityCoordinates);
return "image";
}

Which service. GetProcessDefinitionByTaskId (taskId); Code implementation:


public ProcessDefinition getProcessDefinitionByTaskId(String taskId) {
//1. Get the task
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
//2. Get the process definition object through the pdid of the task object
ProcessDefinition pd = repositoryService.getProcessDefinition(task.getProcessDefinitionId());
return pd;
}

Which service. GetCurrentActivityCoordinates (taskId); Code implementation:


public Map<String, Object> getCurrentActivityCoordinates(String taskId) {
Map<String, Object> coordinates = new HashMap<String, Object>();
//1. Get the ID of the current activity
Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
String currentActivitiId = pi.getActivityId();
//2. Get the process definition
ProcessDefinitionEntity pd = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(task.getProcessDefinitionId());
//Use the process definition to get the active object by currentActivitiId
ActivityImpl activity = pd.findActivity(currentActivitiId);
//Get the coordinates of the activity
coordinates.put("x", activity.getX());
coordinates.put("y", activity.getY());
coordinates.put("width", activity.getWidth());
coordinates.put("height", activity.getHeight());
return coordinates;
}

Image page:

From the personal task list page click on < A target = "_blank" href = "/ viewCurrentImage & # 63; TaskId = 1 external "rel =" nofollow "> View the current flow chart < / a> Skip to the following page:


<body>
<!-- 1. Gets the rule flow diagram   Here it is strust2 Gets the value of the stack on top -->
<img style="position: absolute;top: 0px;left: 0px;" src="viewImage?deploymentId=<s:property value='#deploymentId'/>&imageName=<s:property value='#imageName'/>">

<!-- 2. Draws dynamically according to the coordinates of the current activity DIV -->
<div style="position: absolute;border:1px solid red;top:<s:property value='#acs.y'/>px;left: <s:property value='#acs.x'/>px;width: <s:property value='#acs.width'/>px;height:<s:property value='#acs.height'/>px;  "></div>
</body>

Related articles: