1
2
3
4
5 package gboat2.base.core.web;
6
7 import gboat2.base.bridge.debug.DefaultDebugHook;
8 import gboat2.base.bridge.util.ClassHelper;
9
10 import java.util.List;
11
12 import net.sf.json.JSONArray;
13 import net.sf.json.JSONObject;
14
15
16
17
18
19
20
21
22
23 public class MetadataList extends SplitMetadataStrategy {
24
25 private static SplitMetadataStrategy instance = new MetadataList();
26
27 private MetadataList() {
28 super();
29 }
30
31 public JSONObject decorateMetadata(JSONObject returned, String invokeMethod, BaseActionSupport action) {
32
33 Class<?> domain;
34 domain = action.getDomainClassAnnotationedForList();
35 if (domain == null) {
36 throw new RuntimeException("no Domain or ListDomain annotation exist.");
37 }
38 List<String> fields = ClassHelper.getFieldNames(domain);
39
40 JSONArray operas = (JSONArray) returned.get("operations");
41 if (operas == null) {
42 operas = new JSONArray();
43 } else {
44 fields.add("operations");
45 }
46 returned.accumulate("fields", fields.toArray());
47
48 if (DefaultDebugHook.getInstance().devMode) {
49
50 operas.addAll(getSystemButtonsJSON(action, invokeMethod));
51 }
52
53
54 operas = filtMetaOperas(operas, action);
55 returned.put("operations", operas);
56
57 return returned;
58 }
59
60 public static SplitMetadataStrategy getInstance() {
61 return instance;
62 }
63 }