cn.lzgabel.converter.BpmnBuilder Maven / Gradle / Ivy
package cn.lzgabel.converter;
import cn.lzgabel.converter.bean.BaseDefinition;
import cn.lzgabel.converter.bean.BpmnElementType;
import cn.lzgabel.converter.bean.Process;
import cn.lzgabel.converter.bean.ProcessDefinition;
import cn.lzgabel.converter.processing.BpmnElementProcessor;
import cn.lzgabel.converter.processing.BpmnElementProcessors;
import io.camunda.zeebe.model.bpmn.Bpmn;
import io.camunda.zeebe.model.bpmn.BpmnModelInstance;
import io.camunda.zeebe.model.bpmn.builder.AbstractBaseElementBuilder;
import io.camunda.zeebe.model.bpmn.builder.ProcessBuilder;
import io.camunda.zeebe.model.bpmn.builder.StartEventBuilder;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
/**
* 〈功能简述〉
* 〈基于 json 格式自动生成 bpmn 文件〉
*
* @author lizhi
* @since 1.0.0
*/
public class BpmnBuilder {
public static BpmnModelInstance build(String json) {
return build(ProcessDefinition.of(json));
}
public static BpmnModelInstance build(ProcessDefinition processDefinition) {
if (processDefinition == null) {
return null;
}
try {
ProcessBuilder executableProcess = Bpmn.createExecutableProcess();
Process process = processDefinition.getProcess();
Optional.ofNullable(process.getName())
.filter(StringUtils::isNotBlank)
.ifPresent(executableProcess::name);
Optional.ofNullable(process.getProcessId())
.filter(StringUtils::isNotBlank)
.ifPresent(executableProcess::id);
StartEventBuilder startEventBuilder = executableProcess.startEvent();
BaseDefinition processNode = processDefinition.getProcessNode();
BpmnElementProcessor processor =
BpmnElementProcessors.getProcessor(BpmnElementType.START_EVENT);
String lastNode = processor.onCreate(startEventBuilder, processNode);
processor.moveToNode(startEventBuilder, lastNode).endEvent();
BpmnModelInstance modelInstance = startEventBuilder.done();
Bpmn.validateModel(modelInstance);
return modelInstance;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("创建失败: e=" + e.getMessage());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy