|
23 | 23 | import static apijson.orm.Operation.UNIQUE; |
24 | 24 | import static apijson.orm.Operation.UPDATE; |
25 | 25 | import static apijson.orm.Operation.VERIFY; |
| 26 | +import static apijson.orm.Operation.ON; |
26 | 27 |
|
27 | 28 | import java.net.URL; |
28 | 29 | import java.time.LocalDate; |
@@ -151,6 +152,7 @@ public abstract class AbstractVerifier<T extends Object> implements Verifier<T>, |
151 | 152 | OPERATION_KEY_LIST.add(REMOVE.name()); |
152 | 153 | OPERATION_KEY_LIST.add(MUST.name()); |
153 | 154 | OPERATION_KEY_LIST.add(REFUSE.name()); |
| 155 | + OPERATION_KEY_LIST.add(ON.name()); |
154 | 156 | OPERATION_KEY_LIST.add(ALLOW_PARTIAL_UPDATE_FAIL.name()); |
155 | 157 |
|
156 | 158 |
|
@@ -912,6 +914,7 @@ public static <T extends Object> JSONObject parse(@NotNull final RequestMethod m |
912 | 914 | String remove = StringUtil.getString(target.getString(REMOVE.name())); |
913 | 915 | String must = StringUtil.getString(target.getString(MUST.name())); |
914 | 916 | String refuse = StringUtil.getString(target.getString(REFUSE.name())); |
| 917 | + JSONObject on = target.getJSONObject(ON.name()); |
915 | 918 | String allowPartialUpdateFail = StringUtil.getString(target.getString(ALLOW_PARTIAL_UPDATE_FAIL.name())); |
916 | 919 |
|
917 | 920 |
|
@@ -1051,6 +1054,7 @@ public static <T extends Object> JSONObject parse(@NotNull final RequestMethod m |
1051 | 1054 |
|
1052 | 1055 | // 解析不允许的字段>>>>>>>>>>>>>>>>>>> |
1053 | 1056 |
|
| 1057 | + Set<String> onKeys = new LinkedHashSet<>(); |
1054 | 1058 |
|
1055 | 1059 | // 判断不允许传的key<<<<<<<<<<<<<<<<<<<<<<<<< |
1056 | 1060 | for (String rk : rkset) { |
@@ -1084,6 +1088,11 @@ public static <T extends Object> JSONObject parse(@NotNull final RequestMethod m |
1084 | 1088 | + rk + ":[] 等未定义的 Table[]:[{}] 批量操作键值对!"); |
1085 | 1089 | } |
1086 | 1090 | } |
| 1091 | + |
| 1092 | + // 先让其它操作符完成 |
| 1093 | +// if (rv != null) { // || nulls.contains(rk)) { |
| 1094 | +// onKeys.add(rk); |
| 1095 | +// } |
1087 | 1096 | } |
1088 | 1097 | // 判断不允许传的key>>>>>>>>>>>>>>>>>>>>>>>>> |
1089 | 1098 |
|
@@ -1167,6 +1176,34 @@ public static <T extends Object> JSONObject parse(@NotNull final RequestMethod m |
1167 | 1176 | // 校验并配置允许部分批量增删改失败>>>>>>>>>>>>>>>>>>> |
1168 | 1177 |
|
1169 | 1178 |
|
| 1179 | + String[] nks = on == null ? null : StringUtil.split(real.getString(JSONRequest.KEY_NULL)); |
| 1180 | + Collection<?> nkl = nks == null || nks.length <= 0 ? new HashSet<>() : Arrays.asList(nks); |
| 1181 | + |
| 1182 | + Set<Map.Entry<String, Object>> onSet = on == null ? null : on.entrySet(); |
| 1183 | + if (onSet != null) { |
| 1184 | + // 没必要限制,都是后端配置的,安全可控,而且可能确实有特殊需求,需要 id, @column 等 |
| 1185 | +// List<String> condKeys = new ArrayList<>(Arrays.asList(apijson.JSONRequest.KEY_ID, apijson.JSONRequest.KEY_ID_IN |
| 1186 | +// , apijson.JSONRequest.KEY_USER_ID, apijson.JSONRequest.KEY_USER_ID_IN)); |
| 1187 | +// condKeys.addAll(JSONRequest.TABLE_KEY_LIST); |
| 1188 | + |
| 1189 | + for (Map.Entry<String, Object> entry : onSet) { |
| 1190 | + String k = entry == null ? null : entry.getKey(); |
| 1191 | +// if (condKeys.contains(k)) { |
| 1192 | +// throw new IllegalArgumentException("Request 表 structure 配置的 " + ON.name() |
| 1193 | +// + ":{ " + k + ":value } 中 key 不合法,不允许传 [" + StringUtil.join(condKeys.toArray(new String[]{})) + "] 中的任何一个 !"); |
| 1194 | +// } |
| 1195 | + |
| 1196 | + Object v = k == null ? null : entry.getValue(); |
| 1197 | + if (v instanceof JSONObject == false) { |
| 1198 | + throw new IllegalArgumentException("Request 表 structure 配置的 " + ON.name() |
| 1199 | + + ":{ " + k + ":value } 中 value 不合法,必须是 JSONObject {} !"); |
| 1200 | + } |
| 1201 | + |
| 1202 | + if (nkl.contains(k) || real.get(k) != null) { |
| 1203 | + real = parse(method, name, (JSONObject) v, real, database, schema, datasource, idCallback, creator, callback); |
| 1204 | + } |
| 1205 | + } |
| 1206 | + } |
1170 | 1207 | Log.i(TAG, "parse return real = " + JSON.toJSONString(real)); |
1171 | 1208 | return real; |
1172 | 1209 | } |
|
0 commit comments