This is the 10th day of my participation in Gwen Challenge

Activiti Explorer profile

  • Activiti Explorer: The Activiti console is a Web application
  • When you download the Activiti zip file from the Activiti website, the Activiti console is under the ${Activiti_home}/wars folder
  • The goal of the console is not to create a full-fledged Web application, just an application for client users. For this console, an in-memory database is used, or a custom database can be used (see the applicationContext.xml file under the WEB-INF folder)
  • Login console, there are four main function modules:
    • Tasks:Task management function
      • If you are a task executor, you can see the to-do tasks of the running process instance, and you can also pick up group tasks
      • The console involves functions such as sub-task work, people in different roles…
      • The console allows you to create a standalone task that does not require any process instances to be associated
    • Processes: Displays a list of deployed process definitions and can start a new process instance
    • Reports: Generates Reports and displays historical results
    • Manage:The process engine for managing Activiti
      • Manage users and groups
      • Execute and view the stopped jobs
      • View the database and deploy the new process definition
      • The login user is displayed only when the user has the super administrator permission

The flow chart

  • The console contains functions to useRaphaëlJavascriptThe framework automatically generates a flow chart:
    • The flowchart can only be generated when the process defines the BPMN injection information contained in the XML
    • When there is no BPMN injection information in the process definition XML, but a flowchart is included at deployment time, this image will also be displayed

  • If you don’t want to use Javascript to generate flowcharts, you can disable it in the UI.properties file
activiti.ui.jsdiagram = false
Copy the code
  • The flow chart can also be displayed on the console, and the process definition picture can be displayed according to the ID of the process definition:
http://localhost:8080/activiti-explorer/diagram-viewer/index.html?processDefinitionId=reviewSaledLead:1:36
Copy the code
  • The request parameter for processInstanceId displays the status of the current process instance:
http://localhost:8080/activiti-explorer/diagram-viewer/index.html?processDefinitionId=reviewSaledLead:1:36&processInstan ceId=41Copy the code

Tasks

  • task

  • Inbox: Displays a list of all tasks that a logged-in user needs to perform
  • My Tasks:Displays the task list of the logged user task owner:
    • When a standalone task is created, it can be automated
  • Queued:Displays a list of unused group tasks and the logged-in user is in the group:
    • All tasks here must be picked up before they can be completed
  • Involved: displays tasks that the logged-in user is Involved in, that is, not the executor or the task owner
  • Archived: Contains historical tasks that have been completed

Processes

Deployed Process Definitions

  • In the process Definition TAB, you can view all the process definitions deployed by the Activiti process engine
  • You can start a new process instance using the buttons at the top right of the page
  • If the process definition has a start form, the form is displayed before the process instance is started

My Instances (My instances)

  • Displays all process instances of unfinished user tasks for the currently logged in user
  • Visually displays the current activity of the process instance and stored process variables

Manage

  • In the admin function, this function is displayed only when the logged-in user is a member of the admin permission group
  • When clicking the Manage icon button:

Database

  • Database: indicates the Database. Displays Activiti content. This is useful when developing processes or troubleshooting problems

Deployments

  • Deployments: deployment. Displays the currently deployed process engine, and you can see the deployed content: process definitions, flowcharts, business rules, and so on…

  • New deployments can be uploaded when the Deploy button is clicked:
    • Select a business document or a BPMN20.xml file from your computer
    • A new business process can be deployed by simply dragging and dropping to the specified region

Jobs

  • Jobs:homework
    • Displays the current job (timers, etc.) on the left and runs manual execution (such as triggering timers before the deadline)
    • If the job fails to execute (for example, if the mail server is not working properly), all exceptions are displayed

Users

  • Users:Manage users
    • Create, modify, and delete users. Associated with the user
    • Obtain permission View information about a specific user assigned by a task

Groups

  • Groups:Management group
    • Create, modify, and delete groups and associate groups
    • Obtain permission View information about task assignment, such as task assignment groups

Reports

  • Report:

  • == Note :== If the report is to work, the console needs to configure the level of history not to be None. The default configuration is satisfactory
  • The report TAB has two subtabs:
    • Report generation:
      • Displays a list of known reports in the system
      • Allows the generated report to run
    • Save report:
      • Displays a list of all previously saved reports
      • Only the personally saved reports are displayed, and others’ saved reports are not visible
  • Data from the process is used to generate lists and ICONS in the report. Advantages of using processes to generate report data:
    • The process has direct access to the inside of the Activiti process engine:
      • The database can be accessed directly using the process engine
    • The job executor can be used for any other process:
      • Ability to generate processes asynchronously
      • Only some steps are performed asynchronously
      • You can use timers to generate report data at certain points in time
    • You can create a new report with known tools and known concepts:
      • No new concepts, services or applications are needed
      • Deploying or uploading a new report is the same process as deploying a new report
    • You can use the BPMN2.0 structure:
      • It means all sorts of things: parallel gateways, for example, that can branch based on data or user request input
  • The process definition for generating report data requires that activiti-Report be set to category so that it can be displayed in the Report list in Explorer.
  • The only requirement to be able to see the report is:
    • The process creates a process variable named reportData, which must be a binary array of JSON objects
    • Variables must be saved to Activiti’s history table, so the engine must have history enabled
    • So it can be retrieved later when the report is saved

reportData

  • The report process must generate a variable reportData as JSON data to present to the user:
{
  "title": "My Report"."datasets": [{"type" : "lineChart"."description" : "My first chart"."xaxis" : "Year"
      "yaxis" : "Total sales"
      "data" :
      {
        "2010" : 50."2011" : 33."2012" : 17."2013" : 87,}}]}Copy the code

Json data is retrieved in Explorer and used to generate charts or lists

  • Json elements are:
    • Title: Indicates the report title
    • Datasets: an array of datasets that correspond to different charts and lists in a report
    • type:The type of the data set. This type determines how to render the data. Supported values:
      • pieChart
      • lineChart
      • barChart
      • list
    • Description: Each chart displays an optional description in the report
    • Xaxis: Applies only to lineChart types. This parameter is optional and is used to change the name of the X-axis of the charting coordinate system
    • Yaxis: Applies only to lineChart types. This parameter is optional and is used to change the name of the Y-axis of the charting coordinate system
    • Data: Indicates actual data. Data is a JSON object in key:value format

The process instance

  • Process Instance Overview Report:
    • Contains only one script task: generate a JSON data set using javascript
    • While all of the examples in Explorer use javascript, you can also use Java service tasks
    • The result of executing the process is the reportData variable, which saves the data

      
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
    xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
    xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
    expressionLanguage="http://www.w3.org/1999/XPath"
    targetNamespace="activiti-report">

    <process id="process-instance-overview-report" name="Process Instance Overview" isExecutable="true">

        <startEvent id="startevent1" name="Start" />
        <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="generateDataset" />

        <scriptTask id="generateDataset" name="Execute script" scriptFormat="JavaScript" activiti:autoStoreVariables="false">
          <script><! [CDATA[ importPackage(java.sql); importPackage(java.lang); importPackage(org.activiti.explorer.reporting);var result = ReportingUtil.executeSelectSqlQuery("SELECT PD.NAME_, PD.VERSION_ , count(*) FROM ACT_HI_PROCINST PI inner join ACT_RE_PROCDEF PD on PI.PROC_DEF_ID_ = PD.ID_ group by PROC_DEF_ID_");

               var reportData = {};
               reportData.datasets = [];

               var dataset = {};
               dataset.type = "pieChart";
               dataset.description = "Process instance overview (" + new java.util.Date() + ")";
               dataset.data = {};

               while (result.next()) { // process results one row at a time
                 var name = result.getString(1);
                 var version = result.getLong(2)
                 var count = result.getLong(3);
                 dataset.data[name + " (v" + version + ")"] = count;
               }
               reportData.datasets.push(dataset);

               execution.setVariable("reportData".new java.lang.String(JSON.stringify(reportData)).getBytes("UTF-8")); ] ] ></script>
        </scriptTask>
        <sequenceFlow id="flow3" sourceRef="generateDataset" targetRef="theEnd" />

        <endEvent id="theEnd" />

    </process>

</definitions>
Copy the code
  • Besides the standard XML at the top of the process XML, the main differences aretargetNamespaceSet toactiviti-report,classificationSet to and deployedThe process definitionSame name
    • The first line of the script does some imports to avoid writing the package name every time it is used
    • The first code that makes sense is to read the Activiti database using ReportingUtil. The return result is a JDBC result set
    • Below the query statement,javascript creates the JSON. json meets the requirements described above
    • The last line of the script, first need to putjsonObject to a string, usingjavascriptfunctionJSON.stringify().Strings need to be saved as variables of binary array type
      • This is a technical question:
        • The size of a binary array is infinite, but the length of the string is limited
        • Is that why a javascript string has to be converted to a Java string in order to be converted to binary
  • Json native ReportData and Dataset unavailable

      
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
    xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
    xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
    expressionLanguage="http://www.w3.org/1999/XPath"
    targetNamespace="activiti-report">

    <process id="process-instance-overview-report" name="Process Instance Overview" isExecutable="true">

        <startEvent id="startevent1" name="Start" />
        <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="generateDataset" />

        <scriptTask id="generateDataset" name="Execute script" scriptFormat="js" activiti:autoStoreVariables="false">
          <script><! [CDATA[ importPackage(java.sql); importPackage(java.lang); importPackage(org.activiti.explorer.reporting);var result = ReportingUtil.executeSelectSqlQuery("SELECT PD.NAME_, PD.VERSION_ , count(*) FROM ACT_HI_PROCINST PI inner join ACT_RE_PROCDEF PD on PI.PROC_DEF_ID_ = PD.ID_ group by PROC_DEF_ID_");





               var reportData = new ReportData;
               var dataset = reportData.newDataset();
               dataset.type = "pieChart";
               dataset.description = "Process instance overview (" + new java.util.Date() + ")"


               while (result.next()) { // process results one row at a time
                 var name = result.getString(1);
                 var version = result.getLong(2);
                 var count = result.getLong(3);
                 dataset.add(name + " (v" + version + ")", count);
               }

               execution.setVariable("reportData", reportData.toBytes()); ] ] ></script>
        </scriptTask>
        <sequenceFlow id="flow3" sourceRef="generateDataset" targetRef="theEnd" />

        <endEvent id="theEnd" />

    </process>

</definitions>
Copy the code

Report Start Form

  • Reports are generated using a normal process, so forms functionality can also be used
  • Simply add a start form to the start event and Explorer will show it to the user before generating the report
<startEvent id="startevent1" name="Start">
  <extensionElements>
    <activiti:formProperty id="processDefinition" name="Select process definition" type="processDefinition" required="true" />
      <activiti:formProperty id="chartType" name="Chart type" type="enum" required="true">
        <activiti:value id="pieChart" name="Pie chart" />
        <activiti:value id="barChart" name="Bar chart" />
      </activiti:formProperty>
  </extensionElements>
</startEvent>
Copy the code
  • Render a normal form for the user:

  • Form attributes are submitted when the process is started and can then be used like normal process variables. These process variables can be used in scripts to generate data:
var processDefinition = execution.getVariable("processDefinition");
Copy the code

Process example

  • The console contains four sample reports:
    • Employee productivity:
      • Report presentations use line charts and start forms
      • The script for the report is more complex than the other examples because the data is interpreted in the script before being saved to the report data
    • Helpdesk(Frontline and Upgrade):
      • Use pie charts for presentation
      • Combine the results of two different database queries
    • Process Instance Overview:
      • Report instances that use multiple data sets
      • Reports contain pie charts and list views that use the same data
      • Presenting multiple data sets can be used to generate different charts on a single page
    • Task duration:
      • Another example of using a start form
      • The corresponding variables are used to dynamically generate SQL queries

Modifying a Database

  • To modify the database used for the console example:
    • Change the properties file: apps/apache tomcat – 6. X/webapps/activiti explorer/WEB – INF/classes/db. The properties
    • Put the appropriate database driver on the classpath:
      • Tomcat shares the class library
      • In the apps/apache tomcat – 6. X/webapps/activiti explorer/WEB – INF/lib /