Some default configuration files are included in the root path of the officially released jbpm.jar. We can choose to include or exclude certain features by importing the required configuration files in the jbpm.cfg.xml configuration file.
configuration file | illustrate |
---|---|
jbpm.default.cfg.xml | Main placement. |
jbpm.identity.cfg.xml | Authentication. |
jbpm.jbossremote.cfg.xml | Distributed remote invocation based on JBoss application server. |
jbpm.jobexecutor.cfg.xml | Job executor configuration, which is used to configure the execution strategy of asynchronous activities and timer jobs. |
jbpm.task.lifecycle.cfg.xml | The task declaration cycle state defines the configuration, and the states are: open, suspended, canceled, completed. |
jbpm.tx.hibernate.cfg.xml、jbpm.tx.jta.cfg.xml、jbpm.tx.spring.cfg.xml | Hibernate transactions, JTA transactions and Spring transaction configuration. |
jbpm.variable.types.xml | Process variable data type mapping configuration. |
jbpm.wire.bindings.xml、jbpm.jpdl.bindings.xml | Based on the IoC architecture of jBPM4, the engine components are bound to the runtime environment through dependency injection. |
jbpm.businesscalendar.cfg.xml | Work calendar configuration. |
1 Typical configuration
A typical jBPM4 configuration is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<jbpm-configuration>
<import resource="jbpm.default.cfg.xml" />
<import resource="jbpm.businesscalendar.cfg.xml" />
<import resource="jbpm.tx.hibernate.cfg.xml" />
<import resource="jbpm.jpdl.cfg.xml" />
<import resource="jbpm.bpmn.cfg.xml" />
<import resource="jbpm.identity.cfg.xml" />
<!-- Job executor is excluded for running the example test cases. -->
<!-- To enable timers and messages in production use, this should be included. -->
<!--
<import resource="jbpm.jobexecutor.cfg.xml" />
-->
</jbpm-configuration>
jbpm.default.cfg.xml contains key configurations, such as Service:
<repository-service />
<repository-cache />
<execution-service />
<history-service />
<management-service />
<identity-service />
<task-service />
If you need to run jBPM4 in a JTA environment, you can replace jbpm.tx.hibernate.cfg.xml with jbpm.tx.jta.cfg.xml.
By default, Hibernate is used to manage transactions, and jbpm.hibernate.cfg.xml is referenced in jbpm.tx.hibernate.cfg.xml:
<hibernate-configuration>
<cfg resource="jbpm.hibernate.cfg.xml" />
</hibernate-configuration>
jbpm.hibernate.cfg.xml is responsible for specifying the entity mapping relationship of jBPM4:
<mapping resource="jbpm.repository.hbm.xml" />
<mapping resource="jbpm.execution.hbm.xml" />
<mapping resource="jbpm.history.hbm.xml" />
<mapping resource="jbpm.task.hbm.xml" />
<mapping resource="jbpm.identity.hbm.xml" />
2 Customized work calendar
You can modify jbpm.businesscalendar.cfg.xml to customize the work calendar we need:
<business-calendar>
<monday hours="9:00-12:00 and 12:30-17:00"/>
<tuesday hours="9:00-12:00 and 12:30-17:00"/>
<wednesday hours="9:00-12:00 and 12:30-17:00"/>
<thursday hours="9:00-12:00 and 12:30-17:00"/>
<friday hours="9:00-12:00 and 12:30-17:00"/>
<holiday period="01/07/2008 - 31/08/2008"/>
</business-calendar>
3 Custom Authentication
JBPM4 provides two sets of authentication components:
* IdentitySessionImpl - default.
* JBossIdmIdentitySessionImpl - Based on JBoss Application Server IDM.
To customize the authentication component:
1. Delete the jbpm.identity.cfg.xml configuration in jbpm.cfg.xml.
2. Add the following configuration:
<transaction-context>
<object class="net.deniro.jbpm.java.identity.CustomIdentitySession"/>
</transaction-context>
CustomIdentitySession needs to implement the IdentitySession interface, which contains these methods:
method | illustrate |
---|---|
String createUser(String userId, String givenName, String familyName, String businessEmail) | Create users. |
User findUserById(String userId) | Get user by user ID. |
List findUsersById(String… userIds) | Get a list of users by user ID group. |
List findUsers() | Get all users. |
void deleteUser(String userId) | delete users. |
String createGroup(String groupName, String groupType, String parentGroupId) | Create a user group, returning the user ID. |
List findUsersByGroup(String groupId) | Get a list of users in the group based on the group ID. |
Group findGroupById(String groupId) | Get the group object based on the group ID. |
List findGroupsByUserAndGroupType(String userId, String groupType) | Get a list of groups based on user ID and group type. |
List findGroupsByUser(String userId) | Get a list of groups to which a user belongs based on their ID. |
void deleteGroup(String groupId) | Delete group. |
void createMembership(String userId, String groupId, String role) | Associate users and groups, and the role attribute is optional. |
void deleteMembership(String userId, String groupId, String role) | Delete the relationship between the user and the group. |
Then implement the custom User (org.jbpm.api.identity.User) and Group (org.jbpm.api.identity.Group) interfaces.
User interface methods:
method | illustrate |
---|---|
String getId() | Get user ID. |
String getGivenName() | Get username. |
String getFamilyName() | Get the user's last name. |
String getBusinessEmail() | Get user email. |
Group interface methods:
method | illustrate |
---|---|
String getId() | Get the group ID. |
String getName() | Get the group name. |
String getType() | Get the group category. |
A user can belong to multiple groups.
The User interface and the Group interface conform to the minimal definition of the organization model, and we can extend these two interfaces according to business requirements.
For example, we can customize a new CustomUser interface to inherit the User interface and add the following methods:
method | illustrate |
---|---|
String getAddress() | Get user address. |
User getLeader() | Get the user's immediate superior. |
Customize a new CustomGroup interface to inherit the Group interface and add the following methods:
method | illustrate |
---|---|
String getDesc() | Get group description. |
Group getSuperGroup() | 获取上级部门(假设组被视为组织结构的部门) |
通过扩展,我们就可以基于业务需求,来重建整个组织权限系统的持久化层啦O(∩_∩)O哈哈~