Skip to content

Commit 30bbea9

Browse files
committed
优化角色权限、参数校验、远程函数的初始化;解决 format: true 在 Log.DEBUG 时也不返回 SQL、时间等调试信息;升级自身版本为 5.0.5;
1 parent 286dd3d commit 30bbea9

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

APIJSONORM/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>apijson.orm</groupId>
77
<artifactId>apijson-orm</artifactId>
8-
<version>5.0.0</version>
8+
<version>5.0.5</version>
99
<packaging>jar</packaging>
1010

1111
<name>APIJSONORM</name>

APIJSONORM/src/main/java/apijson/StringUtil.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ public static boolean isNotEmpty(String s, boolean trim) {
348348
public static final Pattern PATTERN_NAME;
349349
public static final Pattern PATTERN_ALPHA_BIG;
350350
public static final Pattern PATTERN_ALPHA_SMALL;
351+
public static final Pattern PATTERN_BRANCH_URL;
351352
static {
352353
PATTERN_NUMBER = Pattern.compile("^[0-9]+$");
353354
PATTERN_ALPHA = Pattern.compile("^[a-zA-Z]+$");
@@ -359,6 +360,7 @@ public static boolean isNotEmpty(String s, boolean trim) {
359360
PATTERN_EMAIL = Pattern.compile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
360361
PATTERN_ID_CARD = Pattern.compile("(^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{2}$)");
361362
PATTERN_PASSWORD = Pattern.compile("^[0-9a-zA-Z]+$");
363+
PATTERN_BRANCH_URL = Pattern.compile("^[0-9a-zA-Z-_/]+$");
362364
}
363365

364366
/**判断手机格式是否正确
@@ -392,7 +394,7 @@ public static boolean isNumberPassword(String s) {
392394
* @return
393395
*/
394396
public static boolean isEmail(String email) {
395-
if (isNotEmpty(email, true) == false) {
397+
if (isEmpty(email, true)) {
396398
return false;
397399
}
398400

@@ -512,14 +514,24 @@ public static boolean isIDCard(String number) {
512514
public static boolean isUrl(String url) {
513515
if (isNotEmpty(url, true) == false) {
514516
return false;
515-
} else if (! url.startsWith(URL_PREFIX) && ! url.startsWith(URL_PREFIXs)) {
517+
}
518+
if (! url.startsWith(URL_PREFIX) && ! url.startsWith(URL_PREFIXs)) {
516519
return false;
517520
}
518521

519522
currentString = url;
520523
return true;
521524
}
522525

526+
public static boolean isBranchUrl(String branchUrl) {
527+
if (isEmpty(branchUrl, false)) {
528+
return false;
529+
}
530+
531+
return PATTERN_BRANCH_URL.matcher(branchUrl).matches();
532+
}
533+
534+
523535
public static final String FILE_PATH_PREFIX = "file://";
524536
/**判断文件路径是否存在
525537
* @param path

APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class AbstractFunctionParser implements FunctionParser {
2828

2929
// <methodName, JSONObject>
3030
// <isContain, <arguments:"array,key", tag:null, methods:null>>
31-
public static final Map<String, JSONObject> FUNCTION_MAP;
31+
public static Map<String, JSONObject> FUNCTION_MAP;
3232
static {
3333
FUNCTION_MAP = new HashMap<>();
3434
}

APIJSONORM/src/main/java/apijson/orm/AbstractParser.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -441,16 +441,16 @@ public JSONObject parseResponse(JSONObject request) {
441441
long duration = endTime - startTime;
442442

443443
if (Log.DEBUG) {
444-
requestObject.put("sql:generate|cache|execute|maxExecute", getSQLExecutor().getGeneratedSQLCount() + "|" + getSQLExecutor().getCachedSQLCount() + "|" + getSQLExecutor().getExecutedSQLCount() + "|" + getMaxSQLCount());
445-
requestObject.put("depth:count|max", queryDepth + "|" + getMaxQueryDepth());
444+
res.put("sql:generate|cache|execute|maxExecute", getSQLExecutor().getGeneratedSQLCount() + "|" + getSQLExecutor().getCachedSQLCount() + "|" + getSQLExecutor().getExecutedSQLCount() + "|" + getMaxSQLCount());
445+
res.put("depth:count|max", queryDepth + "|" + getMaxQueryDepth());
446446

447447
executedSQLDuration += sqlExecutor.getExecutedSQLDuration() + sqlExecutor.getSqlResultDuration();
448448
long parseDuration = duration - executedSQLDuration;
449-
requestObject.put("time:start|duration|end|parse|sql", startTime + "|" + duration + "|" + endTime + "|" + parseDuration + "|" + executedSQLDuration);
449+
res.put("time:start|duration|end|parse|sql", startTime + "|" + duration + "|" + endTime + "|" + parseDuration + "|" + executedSQLDuration);
450450

451451
if (error != null) {
452-
requestObject.put("trace:throw", error.getClass().getName());
453-
requestObject.put("trace:stack", error.getStackTrace());
452+
res.put("trace:throw", error.getClass().getName());
453+
res.put("trace:stack", error.getStackTrace());
454454
}
455455
}
456456

@@ -947,7 +947,7 @@ public JSONObject getStructure(@NotNull String table, String method, String tag,
947947
}
948948

949949
if (result == null) {
950-
if (AbstractVerifier.REQUEST_MAP.isEmpty() == false) {
950+
if (Log.DEBUG == false && AbstractVerifier.REQUEST_MAP.isEmpty() == false) {
951951
return null; // 已使用 REQUEST_MAP 缓存全部,但没查到
952952
}
953953

@@ -961,7 +961,7 @@ public JSONObject getStructure(@NotNull String table, String method, String tag,
961961
where.put(JSONRequest.KEY_TAG, tag);
962962

963963
if (version > 0) {
964-
where.put(JSONRequest.KEY_VERSION + "{}", ">=" + version);
964+
where.put(JSONRequest.KEY_VERSION + ">=", version);
965965
}
966966
config.setWhere(where);
967967
config.setOrder(JSONRequest.KEY_VERSION + (version > 0 ? "+" : "-"));

APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ public abstract class AbstractVerifier<T> implements Verifier<T>, IdCallback {
109109
// <TableName, <METHOD, allowRoles>>
110110
// <User, <GET, [OWNER, ADMIN]>>
111111
@NotNull
112-
public static final Map<String, Map<RequestMethod, String[]>> SYSTEM_ACCESS_MAP;
112+
public static Map<String, Map<RequestMethod, String[]>> SYSTEM_ACCESS_MAP;
113113
@NotNull
114-
public static final Map<String, Map<RequestMethod, String[]>> ACCESS_MAP;
114+
public static Map<String, Map<RequestMethod, String[]>> ACCESS_MAP;
115115

116116
// <method tag, <version, Request>>
117117
// <PUT Comment, <1, { "method":"PUT", "tag":"Comment", "structure":{ "MUST":"id"... }... }>>
118118
@NotNull
119-
public static final Map<String, SortedMap<Integer, JSONObject>> REQUEST_MAP;
119+
public static Map<String, SortedMap<Integer, JSONObject>> REQUEST_MAP;
120120

121121
// 正则匹配的别名快捷方式,例如用 "PHONE" 代替 "^((13[0-9])|(15[^4,\\D])|(18[0-2,5-9])|(17[0-9]))\\d{8}$"
122122
@NotNull
@@ -164,7 +164,7 @@ public abstract class AbstractVerifier<T> implements Verifier<T>, IdCallback {
164164

165165
ACCESS_MAP = new HashMap<>(SYSTEM_ACCESS_MAP);
166166

167-
REQUEST_MAP = new HashMap<>(ACCESS_MAP.size()*6); // 单个与批量增删改
167+
REQUEST_MAP = new HashMap<>(ACCESS_MAP.size()*7); // 单个与批量增删改
168168

169169
COMPILE_MAP = new HashMap<String, Pattern>();
170170
}
@@ -1495,7 +1495,7 @@ public static void verifyRepeat(String table, String key, Object value, long exc
14951495
}
14961496

14971497
public static String getCacheKeyForRequest(String method, String tag) {
1498-
return method + " " + tag;
1498+
return method + "/" + tag;
14991499
}
15001500

15011501

0 commit comments

Comments
 (0)