This project has retired. For details please refer to its
Attic page.
PolicyService xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.server.impl.browser;
20
21 import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_FILTER;
22 import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_POLICY_ID;
23 import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.CONTEXT_OBJECT_ID;
24 import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.getSimpleObject;
25 import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.writeJSON;
26 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
27
28 import java.util.List;
29
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32
33 import org.apache.chemistry.opencmis.commons.data.ObjectData;
34 import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
35 import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
36 import org.apache.chemistry.opencmis.commons.impl.TypeCache;
37 import org.apache.chemistry.opencmis.commons.impl.json.JSONArray;
38 import org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
39 import org.apache.chemistry.opencmis.commons.impl.server.TypeCacheImpl;
40 import org.apache.chemistry.opencmis.commons.server.CallContext;
41 import org.apache.chemistry.opencmis.commons.server.CmisService;
42
43
44
45
46 public class PolicyService {
47
48
49
50
51 public static void getAppliedPolicies(CallContext context, CmisService service, String repositoryId,
52 HttpServletRequest request, HttpServletResponse response) throws Exception {
53
54 String objectId = (String) context.get(CONTEXT_OBJECT_ID);
55 String filter = getStringParameter(request, PARAM_FILTER);
56
57
58 List<ObjectData> policies = service.getAppliedPolicies(repositoryId, objectId, filter, null);
59
60 JSONArray jsonPolicies = new JSONArray();
61 if (policies != null) {
62 TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
63 for (ObjectData policy : policies) {
64 jsonPolicies.add(JSONConverter.convert(policy, typeCache, false));
65 }
66 }
67
68 response.setStatus(HttpServletResponse.SC_OK);
69 writeJSON(jsonPolicies, request, response);
70 }
71
72
73
74
75 public static void applyPolicy(CallContext context, CmisService service, String repositoryId,
76 HttpServletRequest request, HttpServletResponse response) throws Exception {
77
78 String objectId = (String) context.get(CONTEXT_OBJECT_ID);
79 String policyId = getStringParameter(request, PARAM_POLICY_ID);
80
81
82 service.applyPolicy(repositoryId, policyId, objectId, null);
83
84 ObjectData object = getSimpleObject(service, repositoryId, objectId);
85 if (object == null) {
86 throw new CmisRuntimeException("Object is null!");
87 }
88
89
90 response.setStatus(HttpServletResponse.SC_OK);
91
92 TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
93 JSONObject jsonObject = JSONConverter.convert(object, typeCache, false);
94
95 writeJSON(jsonObject, request, response);
96 }
97
98
99
100
101 public static void removePolicy(CallContext context, CmisService service, String repositoryId,
102 HttpServletRequest request, HttpServletResponse response) throws Exception {
103
104 String objectId = (String) context.get(CONTEXT_OBJECT_ID);
105 String policyId = getStringParameter(request, PARAM_POLICY_ID);
106
107
108 service.removePolicy(repositoryId, policyId, objectId, null);
109
110 ObjectData object = getSimpleObject(service, repositoryId, objectId);
111 if (object == null) {
112 throw new CmisRuntimeException("Object is null!");
113 }
114
115
116 response.setStatus(HttpServletResponse.SC_OK);
117
118 TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
119 JSONObject jsonObject = JSONConverter.convert(object, typeCache, false);
120
121 writeJSON(jsonObject, request, response);
122 }
123 }