Activiti5 learning materials 11 (process task highlighted)

Source: Internet
Author: User

Activiti5 learning materials 11 (process task highlighted)
First, we can see that the highlighted red part represents the task being processed, and the finished task is highlighted in green:
 

Activiti provides a flowchart. When we deploy a process file, the flowchart is automatically deployed to the database. We can retrieve it through the API provided by Activiti.
 
Looking at the source code of Activiti, we can see that the deploy () method of org. activiti. engine. impl. bpmn. deployer. BpmnDeployer has such a section:
[Java]
............
For (ProcessDefinitionEntity processDefinition: bpmnParse. getProcessDefinitions ()){
ProcessDefinition. setResourceName (resourceName );

String diagramResourceName = getDiagramResourceForProcess (resourceName, processDefinition. getKey (), resources );
If (diagramResourceName = null & processDefinition. isGraphicalNotationDefined ()){
Try {
Byte [] diagramBytes = IoUtil. readInputStream (ProcessDiagramGenerator. generatepngdition (processDefinition), null );
DiagramResourceName = getProcessImageResourceName (resourceName, processDefinition. getKey (), "png ");
CreateResource (diagramResourceName, diagramBytes, deployment );
} Catch (Exception e) {// if anything goes wrong, we don't store the image (the process will still be executable ).
LOG. log (Level. WARNING, "Error while generating process digoal, image will not be stored in repository", e );
}
}
........
Byte [] diagramBytes = IoUtil. readInputStream (ProcessDiagramGenerator. generatepngdition (processDefinition), null); indicates that ProcessDiagramGenerator is called when the DI information of the flowchart exists. generatePngDiagram () generates the corresponding flowchart and deploys it to the database.
 
ProcessDiagramGenerator. generatepngdi:
 
1. the size of the canvas is calculated based on the parsed process DI information. That is, if the x coordinate of the rightmost component is 300, the y coordinate of the bottommost component is 400, A 310*410 canvas is generated to ensure that the canvas can accommodate the entire flowchart component.
 
2. Call the corresponding rendering method based on the type of each component in the process DI information and draw a picture on the canvas.
 
3. at this point, the flowchart is finished, but there may be a lot of spaces in the upper left part. Therefore, based on the process DI information, calculate the x coordinate of the nearest left component and the y coordinate of the top component, then we make a crop to make the output flowchart exactly the same size.
 
After learning about the Activiti painting process, it is much easier to process and highlight the painting on the flowchart. The steps are as follows,
 
1. Retrieve the original flowchart.
 
2. parse process DI information.
 
3. because the third step of the preceding figure is used for cropping, the coordinate information of DI is incorrect. The actual x and y coordinates are smaller than those on DI, however, we can calculate minX and minY Based on DI, And then subtract to calculate the actual coordinates.
 
4. Load historical process data
 
5. Draw images in java 2D based on historical data and DI coordinate information.
 
In practical applications, the same process requires only one operation in the first three steps. The second operation can be shared directly without wasting system resources.
Therefore, you can use a simple LRU Map (least recently used Map) to cache the information of the flowchart. You only need to process the information on the graph each time.

[Java]
Public class LRUMap <K, V> extends hashmap <K, V> {
 
Private static final long serialVersionUID =-348656573172586525L;
 
Private final int maxCapacity;
 
Private static final float DEFAULT_LOAD_FACTOR = 0.75f;
 
Private Entry <K, V> eldestEntry;
 
Public LRUMap (int maxCapacity ){
Super (maxCapacity, DEFAULT_LOAD_FACTOR, true );
This. maxCapacity = maxCapacity;
}
 
@ Override
Protected boolean removeEldestEntry (Entry <K, V> eldest ){
Boolean remove = size ()> maxCapacity;
If (remove ){
This. eldestEntry = eldest;
}
Return remove;
}
 
Public Entry <K, V> getEldestEntry (){
Return eldestEntry;
}
 
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.