版本
6.7.2
步骤
- 根据流程定义ID查询流程模型
- 获取流程模型起始元素
- 如果起始元素是StartEvent则获取绑定的formKey
- 获取表单信息
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;
}