简体   繁体   中英

Get Process Diagram with Service Task in Activiti

I'm using Activiti 5.22.0.
I use Activiti Designer plugin in Eclispe to create a process.
Now I want to use a service task to get process diagram with current task higlighted and save it to database to show on web later.
I'm new to Activiti so I really don't know what I should to write in Java class of Service Task to get process diagram image.
Can you help me? Thank you very much.

Activiti comes with a Diagram generator in the org.activiti.image module. use can use the DefaultDiagramGenerator for your case. below is a sample code to get you started. please inject the required services.

/**
 * Get Process instance diagram
 */
public InputStream getProcessDiagram(String processInstanceId) {
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
            .processInstanceId(processInstanceId).singleResult();

    // null check
    if (processInstance != null) {
        // get process model
        BpmnModel model = repositoryService.getBpmnModel(processInstance.getProcessDefinitionId());

        if (model != null && model.getLocationMap().size() > 0) {
            ProcessDiagramGenerator generator = new DefaultProcessDiagramGenerator();
            return generator.generateDiagram(model, ActivitiConstants.PROCESS_INSTANCE_IMAGE_FORMAT,
                    runtimeService.getActiveActivityIds(processInstanceId));
        }
    }
    return null;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM