前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >flowable 获取流程启动事件表单信息

flowable 获取流程启动事件表单信息

作者头像
路过君
发布2022-09-16 11:15:01
9730
发布2022-09-16 11:15:01
举报
文章被收录于专栏:路过君BLOG from CSDN

版本

6.7.2

步骤

  1. 根据流程定义ID查询流程模型
  2. 获取流程模型起始元素
  3. 如果起始元素是StartEvent则获取绑定的formKey
  4. 获取表单信息

flowable-rest 中的实现

maven:org.flowable:flowable-rest

org.flowable.rest.service.api.repository.ProcessDefinitionResource

代码语言:javascript
复制
@ApiOperation(value = "Get a process definition start form", tags = { "Process Definitions" })
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Indicates request was successful and the process definition form is returned"),
        @ApiResponse(code = 404, message = "Indicates the requested process definition was not found.")
})
@GetMapping(value = "/repository/process-definitions/{processDefinitionId}/start-form", produces = "application/json")
public String getProcessDefinitionStartForm(@ApiParam(name = "processDefinitionId") @PathVariable String processDefinitionId, HttpServletRequest request) {
    if (formRepositoryService == null) {
        return null;
    }    
    ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
    FormInfo formInfo = getStartForm(processDefinition);
    if (formHandlerRestApiInterceptor != null) {
        return formHandlerRestApiInterceptor.convertStartFormInfo(formInfo, processDefinition);
    } else {
        SimpleFormModel formModel = (SimpleFormModel) formInfo.getFormModel();
        return restResponseFactory.getFormModelString(new FormModelResponse(formInfo, formModel));
    }
}
protected FormInfo getStartForm(ProcessDefinition processDefinition) {
    FormInfo formInfo = null;
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
    Process process = bpmnModel.getProcessById(processDefinition.getKey());
    FlowElement startElement = process.getInitialFlowElement();
    if (startElement instanceof StartEvent) {
        StartEvent startEvent = (StartEvent) startElement;
        if (StringUtils.isNotEmpty(startEvent.getFormKey())) {
            if (startEvent.isSameDeployment()) {
                Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(processDefinition.getDeploymentId()).singleResult();
                formInfo = formRepositoryService.getFormModelByKeyAndParentDeploymentId(startEvent.getFormKey(),
                                deployment.getParentDeploymentId(), processDefinition.getTenantId(), processEngineConfiguration.isFallbackToDefaultTenant());
            } else {
                formInfo = formRepositoryService.getFormModelByKey(startEvent.getFormKey(), processDefinition.getTenantId(),
                        processEngineConfiguration.isFallbackToDefaultTenant());
            }
        }
    }
    if (formInfo == null) {
        // Definition found, but no form attached
        throw new FlowableObjectNotFoundException("Process definition does not have a form defined: " + processDefinition.getId());
    }    
    return formInfo;
}

flowable-ui 中的实现

maven:org.flowable:flowable-ui-task-rest

org.flowable.ui.task.rest.runtime.ProcessDefinitionResource

代码语言:javascript
复制
@RestController
@RequestMapping("/app")
public class ProcessDefinitionResource {

    @Autowired
    protected FlowableProcessDefinitionService processDefinitionService;

    @GetMapping(value = "/rest/process-definitions/{processDefinitionId}/start-form", produces = "application/json")
    public FormModelRepresentation getProcessDefinitionStartForm(@PathVariable String processDefinitionId) {
        FormInfo formInfo = processDefinitionService.getProcessDefinitionStartForm(processDefinitionId);
        SimpleFormModel formModel = (SimpleFormModel) formInfo.getFormModel();
        return new FormModelRepresentation(formInfo, formModel);
    }
}

org.flowable.ui.task.service.runtime.FlowableProcessDefinitionService

代码语言:javascript
复制
public FormInfo getProcessDefinitionStartForm(String processDefinitionId) {
    ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processDefinitionId);
    try {
        return getStartForm(processDefinition);
    } catch (FlowableObjectNotFoundException aonfe) {
        // Process definition does not exist
        throw new NotFoundException("No process definition found with the given id: " + processDefinitionId);
    }
}
protected FormInfo getStartForm(ProcessDefinition processDefinition) {
    FormInfo formInfo = null;
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
    Process process = bpmnModel.getProcessById(processDefinition.getKey());
    FlowElement startElement = process.getInitialFlowElement();
    if (startElement instanceof StartEvent) {
        StartEvent startEvent = (StartEvent) startElement;
        if (StringUtils.isNotEmpty(startEvent.getFormKey())) {
            Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(processDefinition.getDeploymentId()).singleResult();
            formInfo = formRepositoryService.getFormModelByKeyAndParentDeploymentId(startEvent.getFormKey(), deployment.getParentDeploymentId(), 
                            processDefinition.getTenantId(), processEngineConfiguration.isFallbackToDefaultTenant());
        }
    }
    if (formInfo == null) {
        // Definition found, but no form attached
        throw new NotFoundException("Process definition does not have a form defined: " + processDefinition.getId());
    }
    return formInfo;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-07-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 版本
  • 步骤
  • flowable-rest 中的实现
  • flowable-ui 中的实现
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档