前端使用的bpmn-js
进行flowable
的兼容适配,通过flowableui
进行页面的导入、创建、部署进程都很成功,但是和后端对接使用zip方式导入一直是导入成功但是后端的ACT_RE_PROCDEF
表一直没有数据,找了好长时间原因,幸好找到这篇文章,解决了大问题,感谢原作者,如下是原文内容。
问题描述
流程在部署的时候调用服务RepositoryService
,该服务通过createDeployment
,创建了一个DeploymentBuilder
,由builder
的deploy
,问题代码如下:
inputStream=new FileInputStream(new File(filePath));
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().name("TEST_FLOW")
.addInputStream("flowname",inputStream);
Deployment deployment= deploymentBuilder.deploy();
调用后查看部署信息表ACT_RE_DEPLOYMENT有内容,如下图:
查询ACT_RE_PROCDEF
表发现没有内容:
问题定位
跟踪代码进入类ParsedDeploymentBuilder
,build
函数如下:
public ParsedDeployment build() {
List<ProcessDefinitionEntity> processDefinitions = new ArrayList();
Map<ProcessDefinitionEntity, BpmnParse> processDefinitionsToBpmnParseMap = new LinkedHashMap();
Map<ProcessDefinitionEntity, EngineResource> processDefinitionsToResourceMap = new LinkedHashMap();
DeploymentEntity deploymentEntity = (DeploymentEntity)this.deployment;
Iterator var5 = deploymentEntity.getResources().values().iterator();
while(true) {
EngineResource resource;
do {
if (!var5.hasNext()) {
return new ParsedDeployment(deploymentEntity, processDefinitions, processDefinitionsToBpmnParseMap, processDefinitionsToResourceMap);
}
resource = (EngineResource)var5.next();
} while(!this.isBpmnResource(resource.getName()));
LOGGER.debug("Processing BPMN resource {}", resource.getName());
BpmnParse parse = this.createBpmnParseFromResource(resource);
Iterator var8 = parse.getProcessDefinitions().iterator();
while(var8.hasNext()) {
ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity)var8.next();
processDefinitions.add(processDefinition);
processDefinitionsToBpmnParseMap.put(processDefinition, parse);
processDefinitionsToResourceMap.put(processDefinition, resource);
}
}
}
看到调用了this.isBpmnResource(resource.getName())
,我们输入的名字会进行校验,校验函数如下:
protected boolean isBpmnResource(String resourceName) {
String[] var2 = ResourceNameUtil.BPMN_RESOURCE_SUFFIXES;
int var3 = var2.length;
for(int var4 = 0; var4 < var3; ++var4) {
String suffix = var2[var4];
if (resourceName.endsWith(suffix)) {
return true;
}
}
return false;
}
其中资源后缀的定义如下:
public static final String[] BPMN_RESOURCE_SUFFIXES = new String[]{"bpmn20.xml", "bpmn"};
也就是说我们必须以这2个格式结束,否则无法加入流程中。
解决方案
调整资源名以bpmn
或者bpmn20.xml
结尾。调整如下:
repositoryService.createDeployment().name("TEST_FLOW")
.addInputStream("flowname.bpmn20.xml",inputStream);
验证结果
修改后重新调用,验证结果如下: