1
2
3
4
5 package gboat2.base.core.web;
6
7 import gboat2.base.core.validate.PrivilegeCheckServiceFactory;
8
9 import java.util.Iterator;
10 import java.util.Map;
11
12 import net.sf.json.JSONArray;
13 import net.sf.json.JSONObject;
14
15 import org.apache.commons.lang3.StringUtils;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19
20
21
22
23
24
25
26
27
28 public abstract class SplitMetadataStrategy {
29
30
31 Logger logger = LoggerFactory.getLogger(MetadataSupportStrategy.class);
32
33 public abstract JSONObject decorateMetadata(JSONObject returned, String invokeMethod, BaseActionSupport action);
34
35
36
37
38
39 public JSONArray getSystemButtonsJSON(BaseActionSupport action, String invokeMethod) {
40 JSONArray jsonArr = new JSONArray();
41 SystemButtonProvider[] providers = SystemButtonProviderTracker.getProviders();
42 if (null != providers) {
43 for (SystemButtonProvider proivder : providers) {
44 jsonArr.addAll(proivder.getSystemButtons(action, invokeMethod));
45 }
46 }
47 return jsonArr;
48 }
49
50
51
52
53
54
55
56
57
58
59
60 public boolean checkOperaAuthorityByMethodCode(JSONObject jsonObject, BaseActionSupport action) {
61 String operCode = (String) jsonObject.get("code");
62 String actionName = (String) jsonObject.get("actionName");
63 actionName = StringUtils.isEmpty(actionName) == true ? action.getClass().getName() : actionName;
64 if (StringUtils.isNotEmpty(operCode)) {
65
66 Map<Object, Object> params = action.getPriCheckParams();
67 params.put("ACTION_NAME", actionName);
68 params.put("METHOD_CODE", operCode);
69 params.put("REQUEST", action.request);
70 return PrivilegeCheckServiceFactory.operationCheckServiceByMethodCode(params);
71 }
72 return true;
73 }
74
75
76
77
78
79
80
81
82 public JSONArray filtMetaOperas(JSONArray preJSONArray, BaseActionSupport action) {
83 Iterator<?> jsonIter = preJSONArray.iterator();
84 JSONArray returnJSONArray = new JSONArray();
85 Object itObj;
86 JSONObject jsonObj;
87 while (jsonIter.hasNext()) {
88 itObj = jsonIter.next();
89 if (!(itObj instanceof JSONObject)) {
90 logger.warn(itObj + " is not JSONObject, skipped.");
91 continue;
92 }
93
94 jsonObj = (JSONObject) itObj;
95 Boolean isHandle = (Boolean) ((Boolean) jsonObj.get("global") == null ? false : jsonObj.get("global"));
96
97 if (isHandle) {
98 if (checkOperaAuthorityByMethodCode(jsonObj, action)) {
99 returnJSONArray.add(jsonObj);
100 }
101 } else {
102 returnJSONArray.add(jsonObj);
103 }
104 }
105 return returnJSONArray;
106 }
107
108 }