cancel
Showing results for 
Search instead for 
Did you mean: 

Invocation of method componentEvent in org.activiti.explorer.ui.task.TaskDetailPanel$4 fail

nhhao1996
Confirmed Champ
Confirmed Champ

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?

1 ACCEPTED ANSWER

nhhao1996
Confirmed Champ
Confirmed Champ

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);

View answer in original post

5 REPLIES 5

pault
Star Contributor
Star Contributor

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!

I updated the answer, thanks for your reply!

nhhao1996
Confirmed Champ
Confirmed Champ

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);