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?
Solved! Go to Solution.
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);
Do you have the full stack trace for the exception to help see what is going on.
I fixed! Thank you!
Could you share how you fixed the issue? Just in case someone else runs into the same issue!
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);
I updated the answer, thanks for your reply!
Ask for and offer help to other Alfresco Process Services and Activiti Users and members of the Alfresco team.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.