1717import java .util .ArrayList ;
1818import java .util .Arrays ;
1919import java .util .Collection ;
20+ import java .util .List ;
2021
2122import javax .servlet .http .HttpSession ;
2223
3031import apijson .framework .APIJSONFunctionParser ;
3132import apijson .orm .AbstractVerifier ;
3233import apijson .orm .JSONRequest ;
34+ import apijson .orm .Visitor ;
3335
3436
3537/**可远程调用的函数类,用于自定义业务逻辑处理
@@ -45,31 +47,51 @@ public DemoFunctionParser() {
4547 public DemoFunctionParser (RequestMethod method , String tag , int version , JSONObject request , HttpSession session ) {
4648 super (method , tag , version , request , session );
4749 }
50+
51+ public Visitor <Long > getCurrentUser (@ NotNull JSONObject current ) {
52+ return DemoVerifier .getVisitor (getSession ());
53+ }
54+
55+ public Long getCurrentUserId (@ NotNull JSONObject current ) {
56+ return DemoVerifier .getVisitorId (getSession ());
57+ }
58+
59+ public List <Long > getCurrentUserIdAsList (@ NotNull JSONObject current ) {
60+ return Arrays .asList (DemoVerifier .getVisitorId (getSession ()));
61+ }
62+
63+ public List <Long > getCurrentContactIdList (@ NotNull JSONObject current ) {
64+ Visitor <Long > user = getCurrentUser (current );
65+ return user == null ? null : user .getContactIdList ();
66+ }
67+
4868
4969 /**
5070 * @param current
5171 * @param idList
5272 * @return
5373 * @throws Exception
5474 */
55- public Object verifyIdList (@ NotNull JSONObject current , @ NotNull String idList ) throws Exception {
75+ public void verifyIdList (@ NotNull JSONObject current , @ NotNull String idList ) throws Exception {
5676 Object obj = current .get (idList );
5777 if (obj == null ) {
58- return null ;
78+ return ;
5979 }
6080
6181 if (obj instanceof Collection == false ) {
62- throw new IllegalArgumentException (idList + " 不符合 Array 类型 ! 结构必须是 [] !" );
82+ throw new IllegalArgumentException (idList + " 不符合 Array 数组类型 ! 结构必须是 [] !" );
6383 }
64- JSONArray array = (JSONArray ) obj ;
65- if (array != null ) {
66- for (int i = 0 ; i < array .size (); i ++) {
67- if (array .get (i ) instanceof Long == false && array .get (i ) instanceof Integer == false ) {
68- throw new IllegalArgumentException (idList + " 内字符 " + array .getString (i ) + " 不符合 Long 类型!" );
84+
85+ Collection <?> collection = (Collection <?>) obj ;
86+ if (collection != null ) {
87+ int i = -1 ;
88+ for (Object item : collection ) {
89+ i ++;
90+ if (item instanceof Long == false && item instanceof Integer == false ) {
91+ throw new IllegalArgumentException (idList + "/" + i + ": " + item + " 不符合 Long 数字类型!" );
6992 }
7093 }
7194 }
72- return null ;
7395 }
7496
7597
@@ -79,24 +101,26 @@ public Object verifyIdList(@NotNull JSONObject current, @NotNull String idList)
79101 * @return
80102 * @throws Exception
81103 */
82- public Object verifyURLList (@ NotNull JSONObject current , @ NotNull String urlList ) throws Exception {
104+ public void verifyURLList (@ NotNull JSONObject current , @ NotNull String urlList ) throws Exception {
83105 Object obj = current .get (urlList );
84106 if (obj == null ) {
85- return null ;
107+ return ;
86108 }
87109
88110 if (obj instanceof Collection == false ) {
89- throw new IllegalArgumentException (urlList + " 不符合 Array 类型 ! 结构必须是 [] !" );
111+ throw new IllegalArgumentException (urlList + " 不符合 Array 数组类型 ! 结构必须是 [] !" );
90112 }
91- JSONArray array = (JSONArray ) obj ;
92- if (array != null ) {
93- for (int i = 0 ; i < array .size (); i ++) {
94- if (StringUtil .isUrl (array .getString (i )) == false ) {
95- throw new IllegalArgumentException (urlList + " 内字符 " + array .getString (i ) + " 不符合 URL 格式!" );
113+
114+ Collection <?> collection = (Collection <?>) obj ;
115+ if (collection != null ) {
116+ int i = -1 ;
117+ for (Object item : collection ) {
118+ i ++;
119+ if (item instanceof String == false || StringUtil .isUrl ((String ) item ) == false ) {
120+ throw new IllegalArgumentException (urlList + "/" + i + ": " + item + " 不符合 URL 字符串格式!" );
96121 }
97122 }
98123 }
99- return null ;
100124 }
101125
102126
@@ -211,6 +235,7 @@ public JSONArray getIdList(@NotNull JSONObject current) {
211235 * @return
212236 * @throws Exception
213237 */
238+ @ Override
214239 public Object verifyAccess (@ NotNull JSONObject current ) throws Exception {
215240 long userId = current .getLongValue (JSONRequest .KEY_USER_ID );
216241 String role = current .getString (JSONRequest .KEY_ROLE );
0 commit comments