Skip to content

Commit

Permalink
refactor-修改公共异常名称 (#43)
Browse files Browse the repository at this point in the history
Co-authored-by: Liu Rui <[email protected]>
  • Loading branch information
changzheng0101 and aruis authored Dec 28, 2024
1 parent c372dee commit e20d633
Show file tree
Hide file tree
Showing 23 changed files with 81 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import net.ximatai.muyun.core.config.MuYunConfig;
import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;
import net.ximatai.muyun.core.exception.PermsException;
import net.ximatai.muyun.database.IDatabaseOperationsStd;
import net.ximatai.muyun.model.ApiRequest;
Expand Down Expand Up @@ -219,7 +219,7 @@ public boolean isDataAuthorized(String userID, String module, String action, Str
if (hit != null) {
return false;
} else {
throw new MyException("请求的数据不存在");
throw new MuYunException("请求的数据不存在");
}
}
}
Expand Down Expand Up @@ -352,7 +352,7 @@ public String dictDataAuthToCondition(String userID, String module, String dictD
.stream().map("'%s'"::formatted)
.collect(Collectors.joining(",")));
case "self" -> "%s='%s'".formatted(userColumn, userID);
default -> throw new MyException("数据权限配置有误:" + dictDataAuth);
default -> throw new MuYunException("数据权限配置有误:" + dictDataAuth);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.ximatai.muyun.ability.ITreeAbility;
import net.ximatai.muyun.ability.curd.std.ICURDAbility;
import net.ximatai.muyun.core.Scaffold;
import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;
import net.ximatai.muyun.database.IDatabaseOperations;
import net.ximatai.muyun.database.builder.Column;
import net.ximatai.muyun.database.builder.TableWrapper;
Expand Down Expand Up @@ -65,7 +65,7 @@ void testEndlessLoop() {
String y = testController.create(Map.of("v_name", "y", "pid", x));
String z = testController.create(Map.of("v_name", "z", "pid", y));

MyException exception = assertThrows(MyException.class, () -> {
MuYunException exception = assertThrows(MuYunException.class, () -> {
testController.update(x, Map.of("pid", z));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import net.ximatai.muyun.core.config.MuYunConfig;
import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;
import net.ximatai.muyun.platform.controller.RegionController;
import net.ximatai.muyun.test.testcontainers.PostgresTestResource;
import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -47,7 +47,7 @@ void testCreateWithID() {

assertEquals("test_region", id);

assertThrows(MyException.class, () -> {
assertThrows(MuYunException.class, () -> {
regionController.create(Map.of(
"id", "test_region",
"v_name", "test"
Expand All @@ -67,7 +67,7 @@ void testCreateWithID() {
"v_name", "test"
));

assertThrows(MyException.class, () -> {
assertThrows(MuYunException.class, () -> {
regionController.update(id2, Map.of(
"id", "test_new",
"v_name", "test"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.ximatai.muyun.ability;

import jakarta.transaction.Transactional;
import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;
import net.ximatai.muyun.database.IDatabaseOperations;
import net.ximatai.muyun.database.builder.TableBuilder;
import net.ximatai.muyun.database.builder.TableWrapper;
Expand All @@ -25,7 +25,7 @@ default void onTableCreated(boolean isFirst) {
default void create(IDatabaseOperations db) {
String mainTable = getMainTable();
if (!mainTable.toLowerCase().equals(mainTable)) {
throw new MyException("%s表名不合法,不允许使用大写字母".formatted(mainTable));
throw new MuYunException("%s表名不合法,不允许使用大写字母".formatted(mainTable));
}

TableWrapper wrapper = TableWrapper.withName(mainTable)
Expand All @@ -45,7 +45,7 @@ default void create(IDatabaseOperations db) {

if (this instanceof ISoftDeleteAbility ability) {
if (this instanceof IArchiveWhenDelete) {
throw new MyException("ISoftDeleteAbility 能力与 IArchiveWhenDelete 能力互斥,不可同时采用");
throw new MuYunException("ISoftDeleteAbility 能力与 IArchiveWhenDelete 能力互斥,不可同时采用");
}

wrapper.addColumn(ability.getSoftDeleteColumn());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import net.ximatai.muyun.ability.*;
import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;
import net.ximatai.muyun.database.builder.Column;
import net.ximatai.muyun.model.DataChangeChannel;
import net.ximatai.muyun.model.IRuntimeUser;
Expand Down Expand Up @@ -116,7 +116,7 @@ default List<String> batchCreate(List<Map> list) {
List<String> idList = getDB().insertList(getSchemaName(), getMainTable(), dataList);

if (idList.size() != list.size()) {
throw new MyException("数据插入不成功");
throw new MuYunException("数据插入不成功");
}

idList.forEach(id -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.ximatai.muyun.ability.IMetadataAbility;
import net.ximatai.muyun.ability.ISoftDeleteAbility;
import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;
import net.ximatai.muyun.database.metadata.DBColumn;
import net.ximatai.muyun.database.metadata.DBTable;
import net.ximatai.muyun.model.CheckConfig;
Expand Down Expand Up @@ -63,7 +63,7 @@ default void checkWhenCreate(Map body) {
Object row = getDatabaseOperations().row("select 1 from %s.%s where %s = ? %s"
.formatted(getSchemaName(), getMainTable(), column, deleteWhere), body.get(column));
if (row != null) {
throw new MyException(tip);
throw new MuYunException(tip);
}
}
});
Expand All @@ -88,7 +88,7 @@ default void checkWhenUpdate(String id, Map body) {
Object row = getDatabaseOperations().row("select 1 from %s.%s where %s = ? %s and id != ?"
.formatted(getSchemaName(), getMainTable(), column, deleteWhere), body.get(column), id);
if (row != null) {
throw new MyException(tip);
throw new MuYunException(tip);
}
}
});
Expand All @@ -100,7 +100,7 @@ private void checkColumn(Object field, String tip) {
|| (field instanceof Map<?, ?> map && map.isEmpty())
|| (field instanceof List<?> list && list.isEmpty())
|| (field instanceof Object[] arr && arr.length == 0)) {
throw new MyException(tip);
throw new MuYunException(tip);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import net.ximatai.muyun.ability.IRuntimeAbility;
import net.ximatai.muyun.ability.ISecurityAbility;
import net.ximatai.muyun.ability.ITreeAbility;
import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;
import net.ximatai.muyun.model.DataChangeChannel;
import net.ximatai.muyun.model.TreeNode;
import org.eclipse.microprofile.openapi.annotations.Operation;
Expand Down Expand Up @@ -51,14 +51,14 @@ default Integer update(@PathParam("id") String id, Map body) {

if (this instanceof ITreeAbility treeAbility) {
if (id.equals(body.get(treeAbility.getParentKeyColumn().getName()))) {
throw new MyException("树结构的父节点不能是它自身");
throw new MuYunException("树结构的父节点不能是它自身");
}

String pid = (String) body.get(treeAbility.getParentKeyColumn().getName());
if (pid != null) {
List<TreeNode> tree = treeAbility.tree(id, false, null, null);
if (isIdInTree(tree, pid)) {
throw new MyException("不能编辑该节点的父节点为其子孙节点");
throw new MuYunException("不能编辑该节点的父节点为其子孙节点");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.ximatai.muyun.core.exception;

public class MuYunException extends MyException {
public MuYunException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.ximatai.muyun.core.exception;

public class MyException extends RuntimeException {

@Deprecated
public class MyException extends RuntimeException{
public MyException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import jakarta.ws.rs.ext.Provider;
import net.ximatai.muyun.ability.IRuntimeAbility;
import net.ximatai.muyun.core.config.MuYunConfig;
import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;
import net.ximatai.muyun.core.exception.PermsException;
import net.ximatai.muyun.database.exception.MyDatabaseException;
import net.ximatai.muyun.model.IRuntimeUser;
Expand Down Expand Up @@ -56,7 +56,7 @@ public Response toResponse(Exception e) {
} else if (e instanceof PermsException exception) { // 权限报错
responseStatus = getUser().getId().equals(IRuntimeUser.WHITE.getId()) ? UNAUTHORIZED : FORBIDDEN; //说明是白名单用户,也就是登录过期情况
message = exception.getMessage();
} else if (e instanceof MyException exception) {
} else if (e instanceof MuYunException exception) {
message = exception.getMessage();
} else if (e instanceof MyDatabaseException exception) {
switch (exception.getType()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.ximatai.muyun.model.code;

import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -27,7 +27,7 @@ public CodeGenerateConfig(List<ICodePart> codePartList) {

// 验证 SerialCodePart 必须是列表中的最后一部分
if (serialIndex > -1 && serialIndex != codePartList.size() - 1) {
throw new MyException("流水号必须放置与单号生成器的最后一部分");
throw new MuYunException("流水号必须放置与单号生成器的最后一部分");
}

this.codePartList = codePartList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.ximatai.muyun.util;

import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;
import net.ximatai.muyun.model.TreeNode;

import java.util.Collections;
Expand Down Expand Up @@ -74,7 +74,7 @@ private static List<TreeNode> buildChildren(Map<String, List<Map<String, Object>
.setData(node);

if (nodes.contains(treeNode)) {
throw new MyException("树节点出现递归调用");
throw new MuYunException("树节点出现递归调用");
} else {
nodes.add(treeNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.ximatai.muyun.authorization.AuthorizationService;
import net.ximatai.muyun.core.Scaffold;
import net.ximatai.muyun.core.config.MuYunConfig;
import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;
import net.ximatai.muyun.platform.ability.IModuleRegisterAbility;
import net.ximatai.muyun.platform.model.Dict;
import net.ximatai.muyun.platform.model.ModuleAction;
Expand Down Expand Up @@ -131,15 +131,15 @@ public Integer setDataAuth(@PathParam("id") String id, Map body) {

if ("custom".equals(dataAuth)) {
if (StringUtil.isBlank(customCondition)) {
throw new MyException("自定义数据权限必须提供自定义条件");
throw new MuYunException("自定义数据权限必须提供自定义条件");
}
}

Map<String, ?> roleActionMap = roleActionController.view(id);
String actionID = (String) roleActionMap.get("id_at_app_module_action");

if (!testDataAuth(actionID, dataAuth, customCondition)) {
throw new MyException("数据权限不允许配置为:%s".formatted(dataAuth));
throw new MuYunException("数据权限不允许配置为:%s".formatted(dataAuth));
}

HashMap map = new HashMap(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.ximatai.muyun.ability.curd.std.IDataCheckAbility;
import net.ximatai.muyun.ability.curd.std.IQueryAbility;
import net.ximatai.muyun.base.BaseBusinessTable;
import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;
import net.ximatai.muyun.database.builder.TableWrapper;
import net.ximatai.muyun.model.ChildTableInfo;
import net.ximatai.muyun.model.QueryItem;
Expand Down Expand Up @@ -102,7 +102,7 @@ public String translate(@PathParam("category") String category, @QueryParam("sou
DictTreeNode node = findNode(tree(category), source);

if (node == null) {
throw new MyException("字典值 %s 在 %s 类型中不存在".formatted(source, category));
throw new MuYunException("字典值 %s 在 %s 类型中不存在".formatted(source, category));
}

return node.getData().get("v_name").toString();
Expand Down Expand Up @@ -147,15 +147,15 @@ public void check(Map body, boolean isUpdate) {
String name = (String) Objects.requireNonNull(body.get("v_name"), "数据字典类目必须提供名称");

if (!id.equals(id.toLowerCase())) {
throw new MyException("数据字典类目编码不能包含大写字母");
throw new MuYunException("数据字典类目编码不能包含大写字母");
}

if (!isUpdate) {
if (this.query(Map.of("id", id)).getTotal() > 0) {
throw new MyException("存在重复的数据字典类目编码");
throw new MuYunException("存在重复的数据字典类目编码");
}
if (this.query(Map.of("v_name", name)).getTotal() > 0) {
throw new MyException("存在重复的数据字典类目名称");
throw new MuYunException("存在重复的数据字典类目名称");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.ximatai.muyun.ability.curd.std.IDataCheckAbility;
import net.ximatai.muyun.ability.curd.std.IQueryAbility;
import net.ximatai.muyun.base.BaseBusinessTable;
import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;
import net.ximatai.muyun.database.builder.Column;
import net.ximatai.muyun.database.builder.TableWrapper;
import net.ximatai.muyun.model.PageResult;
Expand Down Expand Up @@ -101,7 +101,7 @@ public void check(Map body, boolean isUpdate) {
if (query.getTotal() > 0) {
String dictID = (String) query.getList().getFirst().get("id");
if (!dictID.equals(body.get("id"))) {
throw new MyException("该类目下存在相同的字典值");
throw new MuYunException("该类目下存在相同的字典值");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.ximatai.muyun.platform.controller;

import jakarta.ws.rs.Path;
import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;

import java.util.Map;
Expand Down Expand Up @@ -36,6 +36,6 @@ public Integer delete(String id) {

@Override
public Integer update(String id, Map body) {
throw new MyException("收件箱内容不可修改");
throw new MuYunException("收件箱内容不可修改");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.ximatai.muyun.ability.ISortAbility;
import net.ximatai.muyun.ability.curd.std.IDataCheckAbility;
import net.ximatai.muyun.core.config.MuYunConfig;
import net.ximatai.muyun.core.exception.MyException;
import net.ximatai.muyun.core.exception.MuYunException;
import net.ximatai.muyun.database.builder.Column;
import net.ximatai.muyun.database.builder.TableWrapper;
import net.ximatai.muyun.model.ChildTableInfo;
Expand Down Expand Up @@ -114,7 +114,7 @@ public String schemaForUser(@QueryParam("userID") String userID, @QueryParam("te
if (row != null) {
return row.get("id").toString();
} else {
throw new MyException("未找到该用户匹配的菜单方案");
throw new MuYunException("未找到该用户匹配的菜单方案");
}
}

Expand All @@ -123,7 +123,7 @@ public void check(Map body, boolean isUpdate) {
List terminalType = (List) body.get("dicts_terminal_type");
Objects.requireNonNull(terminalType, "终端类型必填");
if (terminalType.isEmpty()) {
throw new MyException("终端类型必填");
throw new MuYunException("终端类型必填");
}
}

Expand All @@ -132,7 +132,7 @@ public void beforeDelete(String id) {
super.beforeDelete(id);
List<TreeNode> tree = this.tree(id);
if (!tree.isEmpty()) {
throw new MyException("该菜单方案对应菜单数据不为空,不允许删除");
throw new MuYunException("该菜单方案对应菜单数据不为空,不允许删除");
}
}
}
Loading

0 comments on commit e20d633

Please sign in to comment.