update - 按照框架标准调整 JSON 格式转换功能的异常错误码
This commit is contained in:
parent
2a17f2ced3
commit
52ba6778e1
@ -4,28 +4,30 @@ import cn.axzo.framework.domain.web.code.IProjectRespCode;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @Author: liyong.tian
|
||||
* @Date: 2022/9/5
|
||||
* @Description: 响应码规范:一共8位,取值范围0~9,3位项目编号(首位不能为0)+2位模块编号+3位自定义编号
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum BpmErrorCode implements IProjectRespCode {
|
||||
// ========== category 01-001 ==========
|
||||
CATEGORY_VALUE_EXISTS("01001", "分类值【{}】已经存在"),
|
||||
CATEGORY_NOT_EXISTS("01002", "指定分类不存在"),
|
||||
// ========== convertor 02-001 ==========
|
||||
// ========== model 03-001 ==========
|
||||
// ========== processDefinition 04-001 ==========
|
||||
// ========== processInstance 05-001 ==========
|
||||
// ========== task 06-001 ==========
|
||||
// ========== formDefinition 07-001 ==========
|
||||
// ========== formInstance 08-001 ==========
|
||||
// ========== flowableEngin 09-001 ==========
|
||||
* @Date: 2022/9/5
|
||||
* @Description: 响应码规范:一共8位,取值范围0~9,3位项目编号(首位不能为0)+2位模块编号+3位自定义编号
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum BpmErrorCode implements IProjectRespCode {
|
||||
// ========== category 01-001 ==========
|
||||
CATEGORY_VALUE_EXISTS("01001", "分类值【{}】已经存在"),
|
||||
CATEGORY_NOT_EXISTS("01002", "指定分类不存在"),
|
||||
// ========== convertor 02-001 ==========
|
||||
CONVERTOR_UNKNOW_NODE_TYPE("02001", "节点类型【{}】暂不支持"),
|
||||
CONVERTOR_META_DATA_FORMAT_ERROR("02002", "JSON 数据格式有误"),
|
||||
// ========== model 03-001 ==========
|
||||
// ========== processDefinition 04-001 ==========
|
||||
// ========== processInstance 05-001 ==========
|
||||
// ========== task 06-001 ==========
|
||||
// ========== formDefinition 07-001 ==========
|
||||
// ========== formInstance 08-001 ==========
|
||||
// ========== flowableEngin 09-001 ==========
|
||||
|
||||
|
||||
// ========== 流程模型 01-001 ==========
|
||||
// ========== 流程模型 01-001 ==========
|
||||
MODEL_KEY_EXISTS("01001", "已经存在流程标识为【{}】的流程"),
|
||||
|
||||
|
||||
@ -129,9 +131,9 @@ public enum BpmErrorCode implements IProjectRespCode {
|
||||
MODEL_POOL_CANT_DEPLOY("9012028", "模型已不部署,无需重复发布"),
|
||||
PROCESS_DEFINITION_IS_SUSPENDED_CANT_DEPLOY("9012029",
|
||||
"模型处于挂起状态,无法发布"),
|
||||
BPM_META_DATA_FORMAT_ERROR("9012029", "BpmJson数据格式有误"),
|
||||
|
||||
FLOWABLE_GENERAL_ERROR("9013000", "流程引擎一般错误"),
|
||||
|
||||
FLOWABLE_GENERAL_ERROR("9013000", "流程引擎一般错误"),
|
||||
FLOWABLE_ENGINE_OBJECT_NOT_FOUND("9013001", "流程引擎内部错误:流程定义未找到"),
|
||||
FLOWABLE_WRONG_DB("9013002", "数据库版本与流程引擎版本不匹配"),
|
||||
FLOWABLE_DB_OPTIMISTIC_LOCKING("9013003", "引擎内部数据乐观锁死锁"),
|
||||
|
||||
@ -1,23 +1,21 @@
|
||||
package cn.axzo.workflow.core.common.exception;
|
||||
|
||||
import cn.axzo.framework.domain.ServiceException;
|
||||
import cn.axzo.framework.domain.web.code.BaseCode;
|
||||
import cn.axzo.framework.domain.web.code.IRespCode;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
public class WorkflowEngineException extends ServiceException {
|
||||
@Slf4j
|
||||
public class WorkflowEngineException extends ServiceException {
|
||||
private String code;
|
||||
|
||||
public WorkflowEngineException() {
|
||||
this((IRespCode)BaseCode.SERVICE_UNAVAILABLE);
|
||||
}
|
||||
|
||||
public WorkflowEngineException(IRespCode code) {
|
||||
super(code.getMessage());
|
||||
this.code = code.getRespCode();
|
||||
}
|
||||
|
||||
public WorkflowEngineException(IRespCode code, String message) {
|
||||
super(message);
|
||||
public WorkflowEngineException(IRespCode code, String... params) {
|
||||
super(doFormat(code.getCode(), code.getMessage(), params));
|
||||
this.code = code.getRespCode();
|
||||
}
|
||||
|
||||
@ -25,16 +23,45 @@ public class WorkflowEngineException extends ServiceException {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public WorkflowEngineException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public WorkflowEngineException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将错误编号对应的消息使用 params 进行格式化。
|
||||
*
|
||||
* @param code 错误编号
|
||||
* @param messagePattern 消息模版
|
||||
* @param params 参数
|
||||
* @return 格式化后的提示
|
||||
*/
|
||||
@VisibleForTesting
|
||||
private static String doFormat(String code, String messagePattern, Object... params) {
|
||||
StringBuilder sbuf = new StringBuilder(messagePattern.length() + 50);
|
||||
int i = 0;
|
||||
int j;
|
||||
int l;
|
||||
for (l = 0; l < params.length; l++) {
|
||||
j = messagePattern.indexOf("{}", i);
|
||||
if (j == -1) {
|
||||
log.error("[doFormat][参数过多:错误码({})|错误内容({})|参数({})", code, messagePattern, params);
|
||||
if (i == 0) {
|
||||
return messagePattern;
|
||||
} else {
|
||||
sbuf.append(messagePattern.substring(i));
|
||||
return sbuf.toString();
|
||||
}
|
||||
} else {
|
||||
sbuf.append(messagePattern, i, j);
|
||||
sbuf.append(params[l]);
|
||||
i = j + 2;
|
||||
}
|
||||
}
|
||||
if (messagePattern.indexOf("{}", i) != -1) {
|
||||
log.error("[doFormat][参数过少:错误码({})|错误内容({})|参数({})", code, messagePattern, params);
|
||||
}
|
||||
sbuf.append(messagePattern.substring(i));
|
||||
return sbuf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +23,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
import static cn.axzo.workflow.core.common.BpmConstants.BPM_ALLOW_SKIP_USER_TASK;
|
||||
import static cn.axzo.workflow.core.common.BpmConstants.END_EVENT_ID;
|
||||
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.BPM_META_DATA_FORMAT_ERROR;
|
||||
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.CONVERTOR_META_DATA_FORMAT_ERROR;
|
||||
import static cn.axzo.workflow.core.common.enums.BpmErrorCode.CONVERTOR_UNKNOW_NODE_TYPE;
|
||||
import static org.flowable.bpmn.model.ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION;
|
||||
|
||||
@Slf4j
|
||||
@ -47,21 +48,15 @@ public class BpmTransformUtil {
|
||||
|
||||
List<SequenceFlow> sequenceFlows = Lists.newArrayList();
|
||||
Map<String, BpmJsonNode> childNodeMap = new HashMap<>();
|
||||
// JSONObject jsonObject = (JSONObject) JSONObject.toJSON(bpmnJson);
|
||||
// ExtensionAttribute extensionAttribute=new ExtensionAttribute();
|
||||
// extensionAttribute.setName("TestName");
|
||||
// extensionAttribute.setNamespace("http://flowable.org/bpmn");
|
||||
// extensionAttribute.setValue(bpmnJson.toJSONString());
|
||||
//// process.addAttribute(extensionAttribute);
|
||||
// JSONObject processNodes = bpmnJson.getJSONObject("nodeConfig");
|
||||
|
||||
String lastNode = null;
|
||||
try {
|
||||
lastNode = create(bpmnJson.getId(), bpmnJson.getChildren(), process, bpmnModel, sequenceFlows,
|
||||
childNodeMap);
|
||||
} catch (WorkflowEngineException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new WorkflowEngineException(BPM_META_DATA_FORMAT_ERROR);
|
||||
throw new WorkflowEngineException(CONVERTOR_META_DATA_FORMAT_ERROR);
|
||||
}
|
||||
EndEvent endEvent = createEndEvent();
|
||||
process.addFlowElement(endEvent);
|
||||
@ -167,7 +162,7 @@ public class BpmTransformUtil {
|
||||
return id;
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("未知节点类型: nodeType=" + nodeType);
|
||||
throw new WorkflowEngineException(CONVERTOR_UNKNOW_NODE_TYPE, nodeType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user