8 Replies Latest reply on Aug 20, 2010 3:29 AM by Adwait Chitaley

    Visualize workflow and it's current state

    Eugene Dzhurinsky Newbie

      Hello, all!

       

      Can somebody please advice, is there any easy way to visualize a workflow and create an image with it's current state, transitions etc? We would like to get an image as ouput from our web application, which uses JBPM engine.

       

      Thank you in advance!

        • 1. Re: Visualize workflow and it's current state
          HuiSheng Xu Master

          Hi Eugene,

           

          First you could get process picture from repostitoryService.

           

           

                      String imageName = processDefinition.getImageResourceName();
          
                      InputStream imageInputStream = repositoryService
                          .getResourceAsStream(processDefinition.getDeploymentId(),
                              imageName);
          

           

           

          Second you could get activityCoordinates from repositoryService.

           

           

          ActivityCoordinates ac = repositoryService
                          .getActivityCoordinates(processDefinitionId, activityName);
          
          • 2. Re: Visualize workflow and it's current state
            Eugene Dzhurinsky Newbie

            Oh, thanks a lot for the quick and prompt response!

             

            Do you know, are there any examples of images, which could be retrieved from JBPM with this approach? And are they customizable (e.g is it possible to change fonts, colors etc)?

             

            Thanks again!

            • 4. Re: Visualize workflow and it's current state
              Eugene Dzhurinsky Newbie

              Well, in the meantime I tried to implement generation of an image after workflow is deployed.

               

              I tried to get image with the following code:

               

                      NewDeployment deployment = repositoryService.createDeployment();
                      String name = workflow.getName().replaceAll(" ", "_");
                      String key = deployment.addResourceFromString(
                              name + "_" + workflow.getVersion() + ".jpdl.xml",
                              workflowSerializer.serialize(workflow)).deploy();
                      ProcessDefinitionQuery pdq = repositoryService
                              .createProcessDefinitionQuery();
                      List<ProcessDefinition> processDefinitions = pdq.processDefinitionKey(
                              key).list();
                      for (ProcessDefinition pd : processDefinitions) {
                          String imageName = pd.getImageResourceName();
                          File f = new File("/home/bofh/" + imageName);
                          try {
                              FileOutputStream fos = new FileOutputStream(f);
                              System.out.println("Created file " + f.getAbsolutePath());
                              InputStream imageInputStream = repositoryService
                                      .getResourceAsStream(pd.getDeploymentId(), imageName);
                              byte[] buffer = new byte[10240];
                              int read = 0;
                              while ((read = imageInputStream.read(buffer)) > 0) {
                                  fos.write(buffer, 0, read);
                              }
                              fos.flush();
                              fos.close();
                              imageInputStream.close();
                          } catch (Exception e) {
                              e.printStackTrace();
                          }
                      }

               

              However the name of image at line

               

              String imageName = pd.getImageResourceName();

               

              is always null, which causes NPE on getting the actual image stream

               

              Am I missing something?

               

              Thank you in advance!

              • 5. Re: Visualize workflow and it's current state
                HuiSheng Xu Master

                Hi Eugene,

                 

                You must deploy both xml and png in the same NewDeployment.

                 

                If you deploy them separately,  They will have different deploymentId,  so you can't get png by deploymentId of xml.

                 

                You could see these records in table JBPM4_LOB of database.

                • 6. Re: Visualize workflow and it's current state
                  Eugene Dzhurinsky Newbie

                  Well, the problem is that I don't have an image to deploy. I want JBPM engine to generate it for me from a workflow.

                   

                  Is that possible?

                  • 7. Re: Visualize workflow and it's current state
                    HuiSheng Xu Master

                    Hi Eugene,

                     

                    At this moment,  PVM can't provide this feature.  And still somebody mentioned that the server may be not provide graphic utils.  So event if we could provide an automatic generated image feature,  we cannot guarantee whether this feature could run successfully.

                     

                    So we suggest you use GPD designing process definition, and it could generate the related png image for you.

                     

                    Regards.

                    • 8. Re: Visualize workflow and it's current state
                      Adwait Chitaley Newbie

                      To Eugene Dzhurinsky, HuiSheng Xu and other JBPM Users who desire to view the Current Status of a Process Instance in a Graphical Mode / PNG Image.

                       

                      I have received a generous assistance of Roberto Harihar, who has developed this code in viewing the Current Status of A Process Instance Graphically. (See attached Image - Sample.png & Code : jbpm_sample_image.jar)

                       

                      With the attached files and steps mentioned below, we can generate an Image of the Current Status of Process Instance. This can be integrated into our application as well.

                       

                       

                      1) Use the attached File (jbpm_image_sample.jar) and extract it. This JAR Contains the necessary code to generate PNG Image of Current Process Instance at Runtime. This also contains the required images to generate the PNG Image.

                       

                      2) In addition to above, in the same package, create a Java Class File named Render.java and insert the following code in it:

                       

                       

                       

                      import java.io.File;
                      import java.util.List;
                      import javax.imageio.ImageIO;
                      import org.jbpm.api.Configuration;
                      import org.jbpm.api.ProcessEngine;
                      import org.jbpm.api.model.OpenExecution;
                      import com.airsanchay.jbpm.JBPMUtilities;
                      import org.jbpm.api.ExecutionService;
                      import org.jbpm.api.HistoryService;
                      import org.jbpm.api.IdentityService;
                      import org.jbpm.api.ManagementService;
                      import org.jbpm.api.RepositoryService;
                      import org.jbpm.api.TaskService;
                      public class Render {
                      
                          /**
                           * @param args
                           */
                          public static void main(String[] args) throws Exception {
                              String processInstanceId = "AIRSanchayWorkflow.1870001";
                              /** if you are running as a java application - outside a j2ee container */
                              ProcessEngine processEngine = new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine();
                              List historyActivities = processEngine.getHistoryService().createHistoryActivityInstanceQuery().processInstanceId(processInstanceId).list();
                              RenderImage_JpdlModel jpdlModel = new RenderImage_JpdlModel(JBPMUtilities.class.getResourceAsStream("AIRSanchayWorkflow.jpdl.xml"), historyActivities);
                              ImageIO.write(new RenderImage_JpdlModelDrawer().draw(jpdlModel), "png", new File("/root/Desktop/myprocess.png"));
                          }
                      }
                      

                       

                      3) In the above Code, JBPMUtilities.class is the class wherein I have specified all initial parameters for JBPM in my application. Replace this with your equivalent file.

                       

                      4) Due Credits to Ricardo!

                       

                      5) If you can update the code to include Assignee Name and Task Due Date also, do email me the revised code.

                       

                      6) At last, to all JBPM Developers and Users --- Keep the good work &  Enjoy !!!!!!!

                       

                       

                       

                      Adwait Chitaley

                      Avid JBPM User

                      India