public Definitions convertToBpmnModel(JsonNode modelNode) {
//加载一个空的definitions
String nodeTempPath = ProcessEngineManagement.getDefaultProcessEngine().getProcessEngineConfiguration().getCopyTemplatePath();
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(nodeTempPath);
Definitions bpmnModel = new FixFlowConverter().getDefinitions("temp", inputStream);
BPMNDiagram bpmnDiagram=bpmnModel.getDiagrams().get(0);
BPMNPlane bpmnPlane = bpmnDiagram.getPlane();
Process process = (Process)bpmnModel.getRootElements().get(0);
Map<String, JsonNode> shapeMap = new HashMap<String, JsonNode> ();
Map<String, JsonNode> sourceRefMap = new HashMap<String, JsonNode>();
Map<String, JsonNode> edgeMap = new HashMap<String, JsonNode>();
Map<String, List<JsonNode>> sourceAndTargetMap = new HashMap<String, List<JsonNode>>();
readShapeDI(modelNode, 0, 0, shapeMap, sourceRefMap, bpmnModel);
filterAllEdges(modelNode, edgeMap, sourceAndTargetMap, shapeMap, sourceRefMap);
ArrayNode shapesArrayNode = (ArrayNode) modelNode.get(EDITOR_CHILD_SHAPES);
//做pool的时候用
boolean nonEmptyPoolFound = false;
if (nonEmptyPoolFound == false) {
JsonNode processIdNode = JsonConverterUtil.getProperty(PROPERTY_OVERRIDE_ID, modelNode);
if(processIdNode != null && StringUtils.isNotEmpty(processIdNode.asText())) {
process.setId(processIdNode.asText());
}
JsonNode processNameNode = JsonConverterUtil.getProperty(PROPERTY_NAME, modelNode);
if(processNameNode != null && StringUtils.isNotEmpty(processNameNode.asText())) {
process.setName(processNameNode.asText());
}
//加载process的扩展元素
//任务主题
JsonNode processSubject = JsonConverterUtil.getProperty(PROPERTY_PROCESS_SUBJECT, modelNode);
if(processSubject != null && StringUtils.isNotEmpty(processSubject.asText())) {
TaskSubject taskSubject = FixFlowFactory.eINSTANCE.createTaskSubject();
Expression subjectExpression = FixFlowFactory.eINSTANCE.createExpression();
subjectExpression.setName(processSubject.asText());
subjectExpression.setValue(processSubject.asText());
taskSubject.setExpression(subjectExpression);
taskSubject.setId("TaskSubject_1");
BpmnModelUtil.addExtensionElement(process, FixFlowPackage.Literals.DOCUMENT_ROOT__TASK_SUBJECT, taskSubject);
}
//流程分类
JsonNode processCategory = JsonConverterUtil.getProperty(PROPERTY_PROCESS_CATEGORY, modelNode);
if(processCategory != null &&!"null".equals(processCategory.asText()) && StringUtil.isNotEmpty(processCategory.asText())){
BpmnModelUtil.addExtensionAttribute(process, FixFlowPackage.Literals.DOCUMENT_ROOT__CATEGORY, processCategory.asText());
}
//默认表单
JsonNode processFormUri = JsonConverterUtil.getProperty(PROPERTY_PROCESS_DEFAULT_FORMURI, modelNode);
if(processFormUri != null && StringUtil.isNotEmpty(processFormUri.asText())){
FormUri formUri = FixFlowFactory.eINSTANCE.createFormUri();
Expression expression = FixFlowFactory.eINSTANCE.createExpression();
expression.setName(processFormUri.asText());
expression.setValue(processFormUri.asText());
formUri.setExpression(expression);
BpmnModelUtil.addExtensionElement(process, FixFlowPackage.Literals.DOCUMENT_ROOT__FORM_URI, formUri);
}
//流程变量
JsonNode dataVariablesNode = JsonConverterUtil.getProperty(PROPERTY_PROCESS_DATAVARIABLE, modelNode);
if(dataVariablesNode != null){
JsonNode itemsNode = dataVariablesNode.get(EDITOR_PROPERTIES_GENERAL_ITEMS);
if(itemsNode != null) {
Iterator<JsonNode> variableIterator = itemsNode.getElements();
while(variableIterator.hasNext()) {
JsonNode variableNode = variableIterator.next();
String id = variableNode.get(PROPERTY_DATAVARIABLE_ID).asText();
String dataType = variableNode.get(PROPERTY_DATAVARIABLE_TYPE).asText();
String bizType = variableNode.get(PROPERTY_DATAVARIABLE_BIZTYPE).asText();
boolean isPersistence = StringUtil.getBoolean(variableNode.get(PROPERTY_DATAVARIABLE_IS_PERSISTENCE));
String expression = "";
JsonNode tmpNode = variableNode.get(PROPERTY_DATAVARIABLE_DEFAULT_VALUE);
if(tmpNode != null){
expression = tmpNode.asText();
}
DataVariable dataVariableObj = FixFlowFactory.eINSTANCE.createDataVariable();
dataVariableObj.setBizType(bizType);
dataVariableObj.setId(id);
dataVariableObj.setDataType(dataType);
dataVariableObj.setIsPersistence(isPersistence);
Expression variableExpression = FixFlowFactory.eINSTANCE.createExpression();
variableExpression.setValue(expression);
variableExpression.setName(expression);
dataVariableObj.setExpression(variableExpression);
BpmnModelUtil.addExtensionElement(process, FixFlowPackage.Literals.DOCUMENT_ROOT__DATA_VARIABLE, dataVariableObj);
}
}
}
String isVerify = JsonConverterUtil.getProperty(PROPERTY_PROCESS_IS_VERIFY, modelNode).asText();
BpmnModelUtil.addExtensionAttribute(process, FixFlowPackage.Literals.DOCUMENT_ROOT__VERIFICATION, isVerify);
JsonNode processTargetNamespace = JsonConverterUtil.getProperty(PROPERTY_PROCESS_NAMESPACE, modelNode);
if(processTargetNamespace != null && StringUtils.isNotEmpty(processTargetNamespace.asText())) {
bpmnModel.setTargetNamespace(processTargetNamespace.asText());
}
ConnectorInstanceElm cie = new ConnectorInstanceElm();
List<ConnectorInstance> list_ci = cie.convertJsonToElement(modelNode);
if(list_ci != null){
for (int i = 0; i < list_ci.size(); i++) {
BpmnModelUtil.addExtensionElement(process, FixFlowPackage.Literals.DOCUMENT_ROOT__CONNECTOR_INSTANCE, list_ci.get(i));
}
}
processJsonElements(shapesArrayNode, modelNode, process, shapeMap,sourceAndTargetMap,bpmnModel);
}
// Add flows to map for later processing
Map<String, SequenceFlow> flowSourceMap = new HashMap<String, SequenceFlow>();
Map<String, SequenceFlow> flowTargetMap = new HashMap<String, SequenceFlow>();
//初始化线条的source map和target map,后面为flowNode加载来源和target
addAllSequenceFlows(process.getFlowElements(), flowSourceMap, flowTargetMap);
//flowElement的incoming和outgoing处理
postProcessElements(process, process.getFlowElements(), flowSourceMap, flowTargetMap);
//给根plane set 关联元素
bpmnPlane.setBpmnElement(BpmnModelUtil.getBaseElement(bpmnModel, process.getId()));
//给shape元素 set 关联元素
for(DiagramElement diagram : bpmnModel.getDiagrams().get(0).getPlane().getPlaneElement()){
if(diagram instanceof BPMNShape){
BPMNShape bpmnShape = (BPMNShape)diagram;
String shapeId = bpmnShape.getId();
String elementId = BpmnJsonConverterUtil.getElementIdFromShapeId(shapeId);
BaseElement bpmnElement = BpmnModelUtil.getElement(bpmnModel,elementId,BaseElement.class);