Activiti6.0 javaDoc翻译

org.acitviti.engine

注意:所有的Native的方法使用都如下:

List list = identityService.createNativeGroupQuery()
				.sql("select * from " + activitiRule.getManagementService().getTableName(Group.class)
						+ " where  NAME_ = #{groupName} ").parameter("groupName", "管理").list();

FormService:

API 返回值 描述
getRenderedStartForm(String processDefinitionId) StartFormData 将当前节点的表单的key输出,即表单定义的值
getRenderedStartForm(String processDefinitionId, String formEngineName)
getRenderedTaskForm(String taskId) Object 获取Task关联的formKey的内容
getRenderedTaskForm(String taskId, String formEngineName) Object 同上
getStartFormData(String processDefinitionId) ProcessInstance 将开始节点表单所需信息由Map带入
getStartFormKey(String processDefinitionId) String 获取start节点的绝对路径
getTaskFormData(String taskId) TaskFormData 获取task节点的表单信息
getTaskFormKey(String processDefinitionId, String taskDefinitionKey) String 获取当前节点的formKey
saveFormData(String taskId, Map properties) void 保存表单所需参数到流程中
submitStartFormData(String processDefinitionId, Map properties) ProcessInstance 调用了一次saveFormData
submitStartFormData(String processDefinitionId, String businessKey, Map properties) 启动的时候可以加入bussinessKey,算是一个业务秘钥,必须是独一无二的,可以查询一些与流程相关的事项
submitTaskFormData(String taskId, Map properties) void 向流程task节点中提交表单信息

HistoryService

API 返回值 描述
createHistoricActivityInstanceQuery() HistoricActivityInstanceQuery 输出流程完成情况 完成时间更新时间等
createHistoricDetailQuery() HistoricDetailQuery 各条流程定义的详细信息
createHistoricProcessInstanceQuery() HistoricProcessInstanceQuery 创建一个历史详细查询,通过指定方法查询历史节点信息
createHistoricTaskInstanceQuery() HistoricTaskInstanceQuery
createHistoricVariableInstanceQuery() HistoricVariableInstanceQuery 获取流程节点表单变量填写信息
createNativeHistoricActivityInstanceQuery() NativeHistoricActivityInstanceQuery 查看有无活动的线程,如果没有会报错
createNativeHistoricDetailQuery() NativeHistoricDetailQuery 没有会报错
createNativeHistoricProcessInstanceQuery() NativeHistoricProcessInstanceQuery
createNativeHistoricTaskInstanceQuery() NativeHistoricTaskInstanceQuery
createNativeHistoricVariableInstanceQuery() NativeHistoricVariableInstanceQuery
createProcessInstanceHistoryLogQuery(String processInstanceId) ProcessInstanceHistoryLogQuery 通过流程实例id查询流程日志
deleteHistoricProcessInstance(String processInstanceId) void 通过流程实例id删除
deleteHistoricTaskInstance(String taskId) void 通过taskid删除
getHistoricIdentityLinksForProcessInstance(String processInstanceId) List act_hi_identitylink 对这个表进行查询
getHistoricIdentityLinksForTask(String taskId) List act_hi_identitylink 对这个表进行查询

identityService

API 返回值 描述
checkPassword(String userId, String password) boolean 检查密码
createGroupQuery() GroupQuery 创建组查找
createMembership(String userId, String groupId) 创建对应关系
createNativeGroupQuery() NativeGroupQuery
createNativeUserQuery() NativeUserQuery
createUserQuery() UserQuery 通过系统给的查询方法查询
deleteGroup(String groupId) 删除指定组
deleteMembership(String userId, String groupId) 删除指定用户组关系
deleteUser(String userId) 删除指定用户
deleteUserInfo(String userId, String key) 删除用户拓展信息
getUserInfo(String userId, String key) String 根据指定key 和 userid获取拓展信息
getUserInfoKeys(String userId) List 通过userId获取该userId的拓展信息
getUserPicture(String userId) Picture 获取头像
newGroup(String groupId) Group 新建组
newUser(String userId) User 新建User
saveGroup(Group group) 保存
saveUser(User user) 保存
setAuthenticatedUserId(String authenticatedUserId) 将USER设置为当前流程发起者
setUserInfo(String userId, String key, String value) 设置拓展信息
setUserPicture(String userId, Picture picture) 设置头像

ManagerService

API 返回值 描述
createTimerJobQuery 获取定时任务
createSuspendedJobQuery 获取暂停任务
createDeadLetterJobQuery 获取死信表内容,运维人员应关注这个表
createTablePageQuery() 用法 tableName(managementService.getTableName(ProcessDefinitionEntity.class)) 根据实体名查表全部内容

通过自定义sql查询:

  List> mapList = managementService.executeCustomSql(new AbstractCustomSqlExecution>>(MyCustomMapper.class) {

            @Override
            public List> execute(MyCustomMapper myCustomMapper) {

                return myCustomMapper.findAll();
            }
        });

通过自定义命令查询流程定义:

 ProcessDefinitionEntity processDefinitionEntity = managementService.executeCommand(new Command() {
            @Override
            public ProcessDefinitionEntity execute(CommandContext commandContext) {

                ProcessDefinitionEntity processDefinitionEntity = commandContext.getProcessDefinitionEntityManager()
                        .findLatestProcessDefinitionByKey("my-process");
                return processDefinitionEntity;
            }
        });

RepositoryService

activateProcessDefinitionById(String processDefinitionId)  是和 	suspendProcessDefinitionById(String processDefinitionId)

搭配使用的具体代码如下:

//暂停
		repositoryService.suspendProcessDefinitionById(processDefinition.getId());

		//启动
		try {
			LOGGER.info("启动");
			runtimeService.startProcessInstanceById(processDefinition.getId());
			LOGGER.info("启动成功");
		} catch (Exception e) {
			LOGGER.info("启动失败, 原因 {}", e.getMessage());

//			Cannot start process instance. Process definition null (id = my-process:1:127503) is suspended
		}

		//重新激活再启动
		repositoryService.activateProcessDefinitionById(processDefinition.getId());
		LOGGER.info("启动");
		runtimeService.startProcessInstanceById(processDefinition.getId());
		LOGGER.info("启动成功");

可以通过 addCandidateStarterUser or addCandidateStarterGroup指定候选人或者组;
可以通过 changeDeploymentTenantId 更改承租人id,也就是整个流程定义中的tenant的id;


	/** 获取流程图 */
	@Test
	public void testIO() throws Exception {

		// 查询流程定义
		ProcessDefinition def = repositoryService.createProcessDefinitionQuery()
				.deploymentId("192501").singleResult();
		// 查询资源文件
		InputStream is = repositoryService.getProcessDiagram(def.getId());
		// 将输入流转换为图片对象
		BufferedImage image = ImageIO.read(is);
		// 保存为图片文件
		File file = new File("result.png");
		if (!file.exists()) file.createNewFile();
		FileOutputStream fos = new FileOutputStream(file);
		ImageIO.write(image, "png", fos);
		fos.close();
		is.close();
	}

	/** 获取图片 并当前节点高亮显示 */
	@Test
	public void testLight() throws IOException {

		//查询历史流程实例节点
		HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
				.processInstanceId("172505").singleResult();

		//获取流程定义
		ProcessDefinition processDefinition = repositoryService.getProcessDefinition(historicProcessInstance.getProcessDefinitionId());

		//获取流程历史中已执行节点,并按照节点在流程中执行顺序排列
		List list = historyService.createHistoricActivityInstanceQuery()
				.processInstanceId("172505").orderByHistoricActivityInstanceId().asc().list();

		//已执行的节点ID的集合
		List excutedActivityIdList = Lists.newArrayList();
		AtomicInteger index = new AtomicInteger(1);
		System.out.println("获取已经执行的节点");
		list.forEach(l -> {
			excutedActivityIdList.add(l.getActivityId());
			System.out.println("第[" + index + "]节点已执行 = " + l.getActivityId()
			+ ":" + l.getActivityName());
			index.getAndIncrement();
		});

		//获取流程图向字符流  现在已经分离需要加载一个依赖
		//
//		  
//        
//            org.activiti
//            activiti-image-generator
//            6.0.0
//        
//
//        
//        
//            org.activiti
//            activiti-bpmn-model
//            6.0.0
//        
		BpmnModel bpmnModel = repositoryService.getBpmnModel("myProcess:1:172504");
		ProcessDiagramGenerator ge = new DefaultProcessDiagramGenerator();
		InputStream inputStream = ge.generateDiagram(bpmnModel,"png",excutedActivityIdList);
		File file = new File("resultLight.png");
		FileOutputStream fos = new FileOutputStream(file);
		byte bytes[] = new byte[1024];
		int temp = 0;
		while ((temp=inputStream.read(bytes))!=-1) {
			fos.write(bytes,0,temp);
		}
		fos.close();
		inputStream.close();


	}

	/** 获取xml */
	@Test
	public void testIOXML() throws IOException {
		// 查询流程定义
		ProcessDefinition def = repositoryService.createProcessDefinitionQuery()
				.deploymentId("192501").singleResult();
		// 查询资源文件
		InputStream is = repositoryService.getProcessModel(def.getId());
		File file = new File("result.xml");
		FileOutputStream fos = new FileOutputStream(file);
		byte bytes[] = new byte[1024];
		int temp = 0;
		while ((temp=is.read(bytes))!=-1) {
			fos.write(bytes,0,temp);
		}
		fos.close();
		is.close();
	}

你可能感兴趣的:(后端开发成长记)