This is the 9th day of my participation in Gwen Challenge
A brief history in Activit
- History: A component in Activiti that captures and perpetuates information as it occurs during process execution. Unlike runtime data, it remains in the database after the process instance has finished running
- There are five historical entity objects:
- HistoricProcessInstances: contains current and process instance information has come to an end
- HistoricVariableInstances: contains the latest process variables or task
- HistoricActivityInstances: contains an execution of a node of the activity or process information
- HistoricTaskInstances: Contains information about current and completed or deleted task instances
- HistoricDetails: Contains various information about historical process instances, activity instances, and task instances
- Because the database holds historical information as well as running process instance information, how can you query these tables with minimal access to running process instance data to ensure execution performance
Query history
- The Activiti API provides 5 query methods for entities in theHistoryServiceClass:
- createHistoricProcessInstanceQuery()
- createHistoricVariableInstanceQuery()
- createHistoricActivityInstanceQuery()
- createHistoricDetailQuery()
- createHistoricTaskInstanceQuery()
HistoricProcessInstanceQuery
- The process instance
- Get the 10 HistoricProcessInstances whose process definition ID is ‘XXX’, have ended, and have taken the longest (longest) time
historyService.createHistoricProcessInstanceQuery()
.finished()
.processDefinitionId("XXX")
.orderByProcessInstanceDuration().desc()
.listPage(0.10);
Copy the code
HistoricVariableInstanceQuery
- In with ID ‘XXX’, have been the end of the process instance all HistoricVariableInstances query, and sort by variable name
historyService.createHistoricVariableInstanceQuery()
.processInstanceId("XXX")
.orderByVariableName.desc()
.list();
Copy the code
HistoricActivityInstanceQuery
- Get all finished process definitions with ID ‘XXX’ and type last HistoricActivityInstance in ‘serviceTask’
historyService.createHistoricActivityInstanceQuery()
.activityType("serviceTask")
.processDefinitionId("XXX")
.finished()
.orderByHistoricActivityInstanceEndTime().desc()
.listPage(0.1);
Copy the code
HistoricDetailQuery
- Get all values with id 123The process instanceVariable update information generated in
- This query will only return HistoricVariableUpdates
- Note that some variable names may contain multiple HistoricVariableUpdate entities, which are updated each time the process runs. You can order the query using orderByTime(when the variable is updated) or orderByVariableRevision(the version of the variable when the update is run).
historyService.createHistoricDetailQuery()
.variableUpdates()
.processInstanceId("123")
.orderByVariableName().asc()
.list()
Copy the code
- Get the form-properties of all processes with process instance ID 123 when submitting tasks or starting processes. This query will only return HistoricFormPropertiess
historyService.createHistoricDetailQuery()
.formProperties()
.processInstanceId("123")
.orderByVariableName().asc()
.list()
Copy the code
- Gets all variable updates while executing task ID 123. Return HistoricVariableUpdates, not process instance variables, that are all set in the task (task-local variables)
historyService.createHistoricDetailQuery()
.variableUpdates()
.taskId("123")
.orderByVariableName().asc()
.list()
Copy the code
- Task local variables can be set using TaskService, set in TaskListener
taskService.setVariableLocal("123"."myVariable"."Variable value");
Copy the code
- Task local variables can also be set using DelegateTask, which is set in TaskListener
public void notify(DelegateTask delegateTask) {
delegateTask.setVariableLocal("myVariable"."Variable value");
}
Copy the code
HistoricTaskInstanceQuery
- Get the 10 HistoricTaskInstances that took the longest (longest) of all tasks and have ended
historyService.createHistoricTaskInstanceQuery()
.finished()
.orderByHistoricTaskInstanceDuration().desc()
.listPage(0.10);
Copy the code
- Get HistoricTaskInstances that contain “invalid” for deletion reasons and were last assigned to user “kermit”
historyService.createHistoricTaskInstanceQuery()
.finished()
.taskDeleteReasonLike("%invalid%")
.taskAssignee("kermit")
.listPage(0.10);
Copy the code
History configuration
- Historical level can configuration: using the method of writing code. Org. Activiti engine. The impl. History. HistoryLevel (enumeration)
ProcessEngine processEngine = ProcessEngineConfiguration
.createProcessEngineConfigurationFromResourceDefault()
.setHistory(HistoryLevel.AUDIT.getKey())
.buildProcessEngine();
Copy the code
- The level can be configured in the configuration file activiti.cfg. XML or in the spring-context:
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
<property name="history" value="audit" />.</bean>
Copy the code
- Historical information level:
- none:
- Ignore all historical archives:
- This is the best-performing state when the process is executing, but no history information is available
- Ignore all historical archives:
- activity:
- Save all process instance information and activity instance information:
- At the end of the process instance, the most recent variable value in the last process instance is assigned to the history variable
- Process details are not saved
- Save all process instance information and activity instance information:
- audit:
- Default value for saving all process instance information, activity information, and keeping all variables and submitted form attributes in sync
- This way all user interaction information is traceable and can be audited
- Default value for saving all process instance information, activity information, and keeping all variables and submitted form attributes in sync
- full:
- This level stores information that occurs during auditing and all other details, mainly updating process variables
- It is the highest level archive of historical information, and also the slowest
- This level stores information that occurs during auditing and all other details, mainly updating process variables
- none:
The audit
- Historical configuration inauditAbove the level, all pass:
- FormService.submitStartFormData(String processDefinitionId, Map<String, String> properties)
- FormService.submitTaskFormData(String taskId, Map<String, String> properties)
All submitted attributes are logged
- Form attributes can be queried via the API:
historyService
.createHistoricDetailQuery()
.formProperties()
...
.list();
Copy the code
Details of type HistoricFormProperty will be queried
- In the callIdentityService.setAuthenticatedUserId(String)Authentication user is set before submission:
- Users who submit forms will be saved in historical information:
- At the start of the form used in HistoricProcessInstance. GetStartUserId ()
- In task forms by HistoricActivityInstance. GetAssignee ()
- Users who submit forms will be saved in historical information: