activiti流程部署管理

ProcessEngineConfiguration.buildProcessEngine

创建ProcessEngine实例。

ProcessEngine

ProcessEngine是一个接口,实例代表一个流程引擎,实现类为ProcessEngineImpl。通过ProcessEngineConfiguration.buildProcessEngine获取时,创建ProcessEngineImpl实例,在构造中,将从ProcessEngineConfiguration获取各种服务,然后将自身保存在ProcessEngines中,其实是个Map中,key为ProcessEngine名称。
ProcessEngine包括的服务:

  • RepositoryService:提供一系列管理流程定义及流程部署的API
  • RuntimeService:在流程运行过程中对流程实例进行管理和控制
  • TaskService:对流程任务进行管理,例如任务提醒、任务完成及创建任务
  • IdentityService:提供对流程角色数据进行管理的API,7.0中取消。
  • ManagementService:提供对流程引擎进行管理和维护的服务
  • HistoryService:对流程的历史数据进行操作,包括查询、删除这些历史数据
  • DynamicBpmnService:使用该服务,进行不需要重新部署流程模型,就可以实现对流程模型的部分修改

RepositoryService

负责对流程文件的部署和流程的定义进行管理。这些流程文件会保存到ACT_GE_BYTEARRAY表中,对应的实体ResourceEntityImpl。

Deployment对象

Deployment是个接口,一个Deployment实例对应ACT_RE_DEPLOYMENT表的数据.Deployment子接口为DeploymentEntity,实现类DeploymentEntityImpl。如果要对属性进行修改,需要调用DeploymentBuilder提供的方法,DeploymentEntity只提供get方法。
DeploymentEntityImpl对应属性:

  • id 主键
  • name 部署名称
  • deploymentTime 部署时间
  • category 部署类别
  • tenantId 分布式预留字段
  • key 部署设置键属性

DeploymentBuilder对象

获取方式

RepositoryService repositoryService = processEngine.getRepositoryService();
        DeploymentBuilder deploymentBuider = repositoryService.createDeployment();

包含多个addXXX方法,可以用于部署添加资源,方法列举:

  • addClasspathResource(String resource) 添加Classpath下的流程文件
  • addInputStream(String resourceName,InputStream) 添加输入流资源
  • addString(String resourceName,String text) 添加字符串资源
  • addZipInputStream(ZipInputStream inputStream) 添加zip压缩包资源
  • addBpmnModel(String resourceName,BpmnModel bpmnModel) 解析BPMN模型资源,并作为资源保存
  • addBytes(String resourceName,byte[] bytes)添加字节资源

修改部署对象信息

 RepositoryService repositoryService = processEngine.getRepositoryService();
        DeploymentBuilder deployment = repositoryService.createDeployment();
        deployment.name("name").category("xxx").key("key").tenantId("tenantid");

检测是否重复部署

 DeploymentBuilder deployment = repositoryService.createDeployment();
        deployment.addClasspathResource("my_Resource.bpmn");
        deployment.name("name").category("xxx").key("key").tenantId("tenantid");
        deployment.enableDuplicateFiltering();  //检测是否重复部署 对比最后一条部署是否所有属性都相同
        processEngine.getName();

取消部署时的验证

 DeploymentBuilder deployment = repositoryService.createDeployment();
        deployment.addClasspathResource("my_Resource.xml");
        deployment.disableBpmnValidation(); //文件不符合规范过滤
        deployment.disableSchemaValidation(); //定义的流程不规范过滤
        deployment.deploy();

流程定义管理

RepositoryService提供的一系列对流程定义的控制,包括中止流程定义、激活流程定义、设置流程权限等

ProcessDefinition对象

ProcessDefinition是一个接口,一个ProcessDefinition实例对应一条流程定义数据.实现类为ProcessDefinitionEntityImpl,对应的数据类为ACT_RE_PROCDEF.
ProcessDefinition方法:

  • getCategory 获取category对应值
  • getDeploymentId 返回流程部署的id
  • getDescription 返回流程定义的描述
  • getDiagramResourceName 如果流程定义有流程图,则返回流程图对应的资源名称
  • getId 返回流程定义主键
  • getKey 返回流程定义的名称 唯一
  • getName 返回流程定义表示的名称
  • getResourceName 在部署时,会将流程定义的xml文件保存到资源表中,此方法获取资源的名称
  • getTenantId 返回租户id
  • getVersion 返回流程定义的版本号
  • hasStartFormKey 流程开始事件中是否存在activiti:formKey的定义
  • isSuspended 是否中断 1表示激活状态 2表示中断

流程图自动生成

如果我们在部署时不提供流程图,但在流程定义的xml文件中保存了bpmn流程图的元素,则activiti会自动创建流程图,并保存在资源表中.如果我们不希望自动生成流程图,则可以在流程引擎配置中添加一下配置:


中断和激活流程定义

RepositoryService提供了多个中断和激活流程定义的方法:

  • activateProcessDefinitionById(String processDefinitionId) 根据流程定义的id激活流程定义
  • activateProcessDefinitionById(String processDefinitionId,boolean activateProcessInstances,Date activationDate) 在某个时间激活流程定义, activateProcessInstances为true,在流程定义的实例也会被激活.

设置流程定义权限

 repositoryService.addCandidateStarterUser(deploy.getId(),"user1");//设置权限
        repositoryService.addCandidateStarterGroup(deploy.getId(),"group1");//设置权限组

IdentityLink对象

一个IdentityLink实例表示一种身份数据与流程数据绑定的关系,此处所说的身份包括用户和用户组,流程数据包括流程定义、流程任务等数据. IdentityLink对应实体类IdentityLinkEntityImpl,对应数据库表ACT_RU_IDENTITYLINK.包含属性:

  • id 主键
  • type 数据类型,共有5种类型:assignee candidate starter participant owner ,流程定义时为canditate类型,表示创建流程实例请求者
  • groupId 绑定关系中的用户组id
  • userId 绑定关系中的用户id
  • taskId 绑定关系中的任务id
  • processDefId 绑定关系中的流程定义id
    在表中还有一个REV_字段,在IdentityLinkEntityImpl中没有对应属性,在实体与数据表映射的配置文件中,该字段的值被设置为1

流程定义中IdentityLink的获取:

ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult();
List identityLinks = repositoryService.getIdentityLinksForProcessDefinition(processDefinition.getId());

查询流程文件

InputStream processModel = repositoryService.getProcessModel(processDefinition.getId());

查询流程资源名

List names = repositoryService.getDeploymentResourceNames(processDefinition.getId());

删除部署资源

repositoryService.deleteDeployment(deploy.getId());
repositoryService.deleteDeployment(deploy.getId(),true);//集联删除对应流程实例数据.

DeploymentQuery对象

DeploymentQuery部署查询对象
相关方法:

  • deploymentId(String id):根据部署流程id查询
  • deploymentName(String name):根据名称查询
  • deploymentNameLike(string name):名称模糊查询
  • orderByDeploymentId:根据id排序,根据asc 还是desc决定排列顺序
  • orderByDeploymentTime:根据部署时间排序
  • orderByDeploymentName:根据名称排序

ProcessDefinitionQuery对象

和DeploymentQuery相似,针对流程定义数据查询.

你可能感兴趣的:(activiti流程部署管理)