@@ -132,45 +132,56 @@ public static JSONObject initAccess(APIJSONCreator creator) throws ServerExcepti
132132 * @throws ServerException
133133 */
134134 public static JSONObject initAccess (boolean shutdownWhenServerError , APIJSONCreator creator ) throws ServerException {
135+ return initAccess (shutdownWhenServerError , creator , null );
136+ }
137+ /**初始化,加载所有权限配置
138+ * @param shutdownWhenServerError
139+ * @param creator
140+ * @param table 表内自定义数据过滤条件
141+ * @return
142+ * @throws ServerException
143+ */
144+ public static JSONObject initAccess (boolean shutdownWhenServerError , APIJSONCreator creator , JSONObject table ) throws ServerException {
135145 if (creator == null ) {
136146 creator = APIJSON_CREATOR ;
137147 }
138148 APIJSON_CREATOR = creator ;
139149
140- JSONRequest request = new JSONRequest ();
141-
142- { //Access[]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
143- JSONRequest accessItem = new JSONRequest ();
150+
151+ boolean isAll = table == null || table .isEmpty ();
144152
145- { //Access<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
146- JSONRequest access = new JSONRequest ();
147- if (Log .DEBUG == false ) {
148- access .put ("debug" , 0 );
149- }
150- accessItem .put (ACCESS_ , access );
151- } //Access>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
153+ JSONObject access = isAll ? new JSONRequest () : table ;
154+ if (Log .DEBUG == false ) {
155+ access .put ("debug" , 0 );
156+ }
157+ JSONRequest accessItem = new JSONRequest ();
158+ accessItem .put (ACCESS_ , access );
152159
153- request . putAll ( accessItem . toArray ( 0 , 0 , ACCESS_ ) );
154- } //Access[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
160+ JSONRequest request = new JSONRequest ( );
161+ request . putAll ( accessItem . toArray ( 0 , 0 , ACCESS_ ));
155162
163+
156164 JSONObject response = creator .createParser ().setMethod (RequestMethod .GET ).setNeedVerify (false ).parseResponse (request );
157165 if (JSONResponse .isSuccess (response ) == false ) {
158166 Log .e (TAG , "\n \n \n \n \n !!!! 查询权限配置异常 !!!\n " + response .getString (JSONResponse .KEY_MSG ) + "\n \n \n \n \n " );
159167 onServerError ("查询权限配置异常 !" , shutdownWhenServerError );
160168 }
161169
162170 JSONArray list = response .getJSONArray (ACCESS_ + "[]" );
163- if (list == null || list .isEmpty ()) {
164- Log .w (TAG , "init list == null || list.isEmpty(),没有可用的权限配置" );
171+ int size = list == null ? 0 : list .size ();
172+ if (isAll && size <= 0 ) {
173+ Log .w (TAG , "initAccess isAll && size <= 0,,没有可用的权限配置" );
165174 throw new NullPointerException ("没有可用的权限配置" );
166175 }
167176
168- Log .d (TAG , "init < for ACCESS_MAP.size() = " + ACCESS_MAP .size () + " <<<<<<<<<<<<<<<<<<<<<<<<" );
177+ Log .d (TAG , "initAccess < for ACCESS_MAP.size() = " + ACCESS_MAP .size () + " <<<<<<<<<<<<<<<<<<<<<<<<" );
169178
170- ACCESS_MAP .clear ();
179+ if (isAll ) { // 全量更新
180+ ACCESS_MAP .clear ();
181+ }
171182
172183 JSONObject item ;
173- for (int i = 0 ; i < list . size () ; i ++) {
184+ for (int i = 0 ; i < size ; i ++) {
174185 item = list .getJSONObject (i );
175186 if (item == null ) {
176187 continue ;
@@ -215,7 +226,7 @@ public static JSONObject initAccess(boolean shutdownWhenServerError, APIJSONCrea
215226 APIJSONSQLConfig .TABLE_KEY_MAP .put (alias , name );
216227 }
217228
218- Log .d (TAG , "init for /> ACCESS_MAP.size() = " + ACCESS_MAP .size () + " >>>>>>>>>>>>>>>>>>>>>>>" );
229+ Log .d (TAG , "initAccess for /> ACCESS_MAP.size() = " + ACCESS_MAP .size () + " >>>>>>>>>>>>>>>>>>>>>>>" );
219230
220231 return response ;
221232 }
@@ -251,23 +262,29 @@ public static JSONObject initRequest(APIJSONCreator creator) throws ServerExcept
251262 * @throws ServerException
252263 */
253264 public static JSONObject initRequest (boolean shutdownWhenServerError , APIJSONCreator creator ) throws ServerException {
265+ return initRequest (shutdownWhenServerError , creator , null );
266+ }
267+ /**初始化,加载所有请求校验配置
268+ * @param shutdownWhenServerError
269+ * @param creator
270+ * @param table 表内自定义数据过滤条件
271+ * @return
272+ * @throws ServerException
273+ */
274+ public static JSONObject initRequest (boolean shutdownWhenServerError , APIJSONCreator creator , JSONObject table ) throws ServerException {
254275 if (creator == null ) {
255276 creator = APIJSON_CREATOR ;
256277 }
257278 APIJSON_CREATOR = creator ;
258279
259- JSONRequest request = new JSONRequest ();
260-
261- { //Request[]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
262- JSONRequest requestItem = new JSONRequest ();
280+
281+ boolean isAll = table == null || table .isEmpty ();
263282
264- { //Request<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
265- requestItem .put (REQUEST_ , new JSONRequest ().setOrder ("version-,id+" )); // 方便查找
266- } //Request>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
283+ JSONRequest requestItem = new JSONRequest ();
284+ requestItem .put (REQUEST_ , isAll ? new JSONRequest ().setOrder ("version-,id+" ) : table ); // 方便查找
267285
268- request .putAll (requestItem .toArray (0 , 0 , REQUEST_ ));
269-
270- } //Request[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
286+ JSONRequest request = new JSONRequest ();
287+ request .putAll (requestItem .toArray (0 , 0 , REQUEST_ ));
271288
272289
273290 JSONObject response = creator .createParser ().setMethod (RequestMethod .GET ).setNeedVerify (false ).parseResponse (request );
@@ -277,37 +294,40 @@ public static JSONObject initRequest(boolean shutdownWhenServerError, APIJSONCre
277294 }
278295
279296 JSONArray list = response .getJSONArray (REQUEST_ + "[]" );
280- if (list == null || list .isEmpty ()) {
281- Log .w (TAG , "init list == null || list.isEmpty(),没有可用的权限配置" );
297+ int size = list == null ? 0 : list .size ();
298+ if (isAll && size <= 0 ) {
299+ Log .w (TAG , "initRequest isAll && size <= 0,没有可用的权限配置" );
282300 throw new NullPointerException ("没有可用的权限配置" );
283301 }
284302
285- Log .d (TAG , "init < for REQUEST_MAP.size() = " + REQUEST_MAP .size () + " <<<<<<<<<<<<<<<<<<<<<<<<" );
303+ Log .d (TAG , "initRequest < for REQUEST_MAP.size() = " + REQUEST_MAP .size () + " <<<<<<<<<<<<<<<<<<<<<<<<" );
286304
287- REQUEST_MAP .clear ();
305+ if (isAll ) { // 全量更新
306+ REQUEST_MAP .clear ();
307+ }
288308
289309 JSONObject item ;
290- for (int i = 0 ; i < list . size () ; i ++) {
310+ for (int i = 0 ; i < size ; i ++) {
291311 item = list .getJSONObject (i );
292312 if (item == null ) {
293313 continue ;
294314 }
295315
296316 String version = item .getString ("version" );
297317 if (StringUtil .isEmpty (version , true )) {
298- Log .e (TAG , "init for StringUtil.isEmpty(version, true),Request 表中的 version 不能为空!" );
318+ Log .e (TAG , "initRequest for StringUtil.isEmpty(version, true),Request 表中的 version 不能为空!" );
299319 onServerError ("服务器内部错误,Request 表中的 version 不能为空!" , shutdownWhenServerError );
300320 }
301321
302322 String method = item .getString ("method" );
303323 if (StringUtil .isEmpty (method , true )) {
304- Log .e (TAG , "init for StringUtil.isEmpty(method, true),Request 表中的 method 不能为空!" );
324+ Log .e (TAG , "initRequest for StringUtil.isEmpty(method, true),Request 表中的 method 不能为空!" );
305325 onServerError ("服务器内部错误,Request 表中的 method 不能为空!" , shutdownWhenServerError );
306326 }
307327
308328 String tag = item .getString ("tag" );
309329 if (StringUtil .isEmpty (tag , true )) {
310- Log .e (TAG , "init for StringUtil.isEmpty(tag, true),Request 表中的 tag 不能为空!" );
330+ Log .e (TAG , "initRequest for StringUtil.isEmpty(tag, true),Request 表中的 tag 不能为空!" );
311331 onServerError ("服务器内部错误,Request 表中的 tag 不能为空!" , shutdownWhenServerError );
312332 }
313333
@@ -335,7 +355,7 @@ public static JSONObject initRequest(boolean shutdownWhenServerError, APIJSONCre
335355 }
336356
337357 if (target == null || target .isEmpty ()) {
338- Log .e (TAG , "init for target == null || target.isEmpty()" );
358+ Log .e (TAG , "initRequest for target == null || target.isEmpty()" );
339359 onServerError ("服务器内部错误,Request 表中的 version = " + version + ", method = " + method + ", tag = " + tag + " 对应的 structure 不能为空!" , shutdownWhenServerError );
340360 }
341361
@@ -354,7 +374,7 @@ public int compare(Integer o1, Integer o2) {
354374 REQUEST_MAP .put (cacheKey , versionedMap );
355375 }
356376
357- Log .d (TAG , "init for /> REQUEST_MAP.size() = " + REQUEST_MAP .size () + " >>>>>>>>>>>>>>>>>>>>>>>" );
377+ Log .d (TAG , "initRequest for /> REQUEST_MAP.size() = " + REQUEST_MAP .size () + " >>>>>>>>>>>>>>>>>>>>>>>" );
358378
359379 return response ;
360380 }
0 commit comments