介绍:在发布一次资源后,会生成对应的流程定义(存储在表act_re_procdef)中,该定义记录一个流程的信息,如下图所有:
资源图片:
数据库中查看:
注意匹配流程图的规则:
3.只发布bpmn文件,并且不加自己的png图片时,同时我们也不想activiti帮我们生成png时,只需要在activiti.cfg.xml配置文件中添加如下属性:
<!--该属性是在我们发布资源时,是否自动生成对应png流程图-->
<property name="createDiagramOnDeploy" value="false" />
介绍:发布流程定义后,定义只是一个规则,我们去用的时候才会真正的生成实例。不过我们在生成实例之前可以对流程定义中止和激活,测试如下:
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
RepositoryService repositoryService = processEngine.getRepositoryService();
DeploymentBuilder builder = repositoryService.createDeployment().addClasspathResource("test3.bpmn");
Deployment deployment = builder.deploy();
//获取流程定义
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
//将流程定义中止(使流程定义不生效,即不能生成实例)
System.out.println("processDefinition的id:" + processDefinition.getId());
repositoryService.suspendProcessDefinitionById(processDefinition.getId());
RuntimeService runtimeService = processEngine.getRuntimeService();
//尝试生成一个流程实例
//因为流程定义被中止了,所有会报异常:
// Exception in thread "main" org.activiti.engine.ActivitiException: Cannot start process instance. Process definition My Process (id = myProcess_1:20:90003) is suspended
try {
runtimeService.startProcessInstanceById(processDefinition.getId());
}catch (Exception e){
e.printStackTrace();
}
//此处把流程定义再激活
repositoryService.activateProcessDefinitionById(processDefinition.getId());
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
System.out.println("实例:" + processInstance);
processEngine.close();
System.exit(0);
结果如下:
processDefinition的id:myProcess_1:25:102503
#失效后不能生成实例
org.activiti.engine.ActivitiException: Cannot start process instance. Process definition My Process (id = myProcess_1:25:102503) is suspended
at org.activiti.engine.impl.util.ProcessInstanceHelper.createAndStartProcessInstance(ProcessInstanceHelper.java:67)
at org.activiti.engine.impl.util.ProcessInstanceHelper.createAndStartProcessInstance(ProcessInstanceHelper.java:51)
at org.activiti.engine.impl.cmd.StartProcessInstanceCmd.createAndStartProcessInstance(StartProcessInstanceCmd.java:109)
.......
at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:39)
at org.activiti.engine.impl.RuntimeServiceImpl.startProcessInstanceById(RuntimeServiceImpl.java:114)
at com.xjf.test.Test3.main(Test3.java:37)
#重新激活后生成实例
实例:ProcessInstance[102504]
介绍:流程定义发布后,我们可以对流程定义的使用进行权限控制。指定用户或用户组来使流程定义只能由对应的用户来使用(只有保存关系的作用,activiti不会主动进行权限控制)。可以使用repositoryService.createProcessDefinitionQuery().startableByUser()方法来查关系。
设置的代码如下:
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//首先创建用户
IdentityService identityService = processEngine.getIdentityService();
User user = identityService.newUser(UUID.randomUUID().toString());
user.setFirstName("xu");
user.setLastName("xiaoming");
user.setPassword("123456");
identityService.saveUser(user);
//发布流程定义
RepositoryService repositoryService = processEngine.getRepositoryService();
Deployment deployment = repositoryService.createDeployment().addClasspathResource("test3.bpmn").deploy();
//获取流程定义
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
//给流程定义指定候选人
repositoryService.addCandidateStarterUser(processDefinition.getId(),user.getId());
//查询用户能使用流程定义,从act_ru_identitylink表中去查
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().startableByUser(user.getId()).list();
list.forEach(System.out::println);
processEngine.close();
System.exit(0);
结果:
ProcessDefinitionEntity[myProcess_1:26:105003]
数据库查看: 用户数据表(act_id_user)查看:
流程定义(act_re_procedef)查看:
此时对应的关联关系会保存到表 act_ru_identitylink 中:
**介绍:**流程定义跟用户或用户组的权限关系会保存在act_ru_identitylink表中,不过Activiti不会对这些权限进行拦截或者检查,只能根据这些关系与查询条件,返回相应的符合要求的数据。下面测试为用户查流程定义和流程定义查用户: