02-20-2019 11:03 PM
Hi everyone!
I just made a simple process: start -> service task -> end
I create a Java class to implement into service task to save diagram before process end. Here is my code:
public class CaptureProcess implements JavaDelegate{
@Override
public void execute(DelegateExecution delegateExecution) throws Exception {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.processDefinitionKey("parentProcess")
.singleResult();String diagramResourceName = processDefinition.getDiagramResourceName();
InputStream imageStream = repositoryService.getResourceAsStream(
processDefinition.getDeploymentId(), diagramResourceName);
FileOutputStream outstream = new FileOutputStream(new File("download-image.png"));
IOUtils.copy(imageStream, outstream);
outstream.close();
}
}
I copied jar file when create deployment artifact to my activiti-explorer path, but when I deploy bar file and run, it's appear warning: Invocation of method componentEvent in org.activiti.explorer.ui.task.TaskDetailPanel$4 fail.
Can you tell my what's wrong with my code?
02-25-2019 08:35 PM
Because process definition is just get the designed diagram not diagram with current task highlighted so I changed it into process instance, here is my code to get diagram with current task with process instance:
public class CaptureProcess implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
FileOutputStream outputStream = new FileOutputStream(new File("d:\\service-task.png"));
IOUtils.copy(captureProcess(execution.getProcessInstanceId()), outputStream);
outputStream.close();
}
public static InputStream captureProcess(String processInstanceId) throws IOException {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
RepositoryService repositoryService = processEngine.getRepositoryService();
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, "png" ,runtimeService.getActiveActivityIds(processInstanceId));
}
}
return null;
}
}
And if you want to get original diagram without highlighted task, you can check in Activiti User Guilde, there are a example code for you to do this:
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery() .
processDefinitionKey("expense") .singleResult();
String diagramResourceName = processDefinition.getDiagramResourceName();
InputStream imageStream = repositoryService.getResourceAsStream( processDefinition.getDeploymentId(), diagramResourceName);
02-21-2019 08:03 AM
Do you have the full stack trace for the exception to help see what is going on.
02-21-2019 09:40 PM
I fixed! Thank you!
02-25-2019 11:43 AM
Could you share how you fixed the issue? Just in case someone else runs into the same issue!
02-25-2019 08:36 PM
I updated the answer, thanks for your reply!
02-25-2019 08:35 PM
Because process definition is just get the designed diagram not diagram with current task highlighted so I changed it into process instance, here is my code to get diagram with current task with process instance:
public class CaptureProcess implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
FileOutputStream outputStream = new FileOutputStream(new File("d:\\service-task.png"));
IOUtils.copy(captureProcess(execution.getProcessInstanceId()), outputStream);
outputStream.close();
}
public static InputStream captureProcess(String processInstanceId) throws IOException {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
RepositoryService repositoryService = processEngine.getRepositoryService();
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, "png" ,runtimeService.getActiveActivityIds(processInstanceId));
}
}
return null;
}
}
And if you want to get original diagram without highlighted task, you can check in Activiti User Guilde, there are a example code for you to do this:
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery() .
processDefinitionKey("expense") .singleResult();
String diagramResourceName = processDefinition.getDiagramResourceName();
InputStream imageStream = repositoryService.getResourceAsStream( processDefinition.getDeploymentId(), diagramResourceName);
Explore our Alfresco products with the links below. Use labels to filter content by product module.