This project has retired. For details please refer to its
Attic page.
PolicyServiceImpl 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.client.bindings.spi.browser;
20
21 import java.io.OutputStream;
22 import java.util.Collections;
23 import java.util.List;
24
25 import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
26 import org.apache.chemistry.opencmis.client.bindings.spi.http.HttpUtils;
27 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
28 import org.apache.chemistry.opencmis.commons.data.ObjectData;
29 import org.apache.chemistry.opencmis.commons.impl.Constants;
30 import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
31 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
32 import org.apache.chemistry.opencmis.commons.spi.PolicyService;
33
34
35
36
37 public class PolicyServiceImpl extends AbstractBrowserBindingService implements PolicyService {
38
39
40
41
42 public PolicyServiceImpl(BindingSession session) {
43 setSession(session);
44 }
45
46 public void applyPolicy(String repositoryId, String policyId, String objectId, ExtensionsData extension) {
47
48 UrlBuilder url = getObjectUrl(repositoryId, objectId);
49
50
51 final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_APPLY_POLICY);
52 formData.addPoliciesParameters(Collections.singletonList(policyId));
53
54
55 postAndConsume(url, formData.getContentType(), new HttpUtils.Output() {
56 public void write(OutputStream out) throws Exception {
57 formData.write(out);
58 }
59 });
60 }
61
62 public void removePolicy(String repositoryId, String policyId, String objectId, ExtensionsData extension) {
63
64 UrlBuilder url = getObjectUrl(repositoryId, objectId);
65
66
67 final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_REMOVE_POLICY);
68 formData.addPoliciesParameters(Collections.singletonList(policyId));
69
70
71 postAndConsume(url, formData.getContentType(), new HttpUtils.Output() {
72 public void write(OutputStream out) throws Exception {
73 formData.write(out);
74 }
75 });
76 }
77
78 public List<ObjectData> getAppliedPolicies(String repositoryId, String objectId, String filter,
79 ExtensionsData extension) {
80
81 UrlBuilder url = getObjectUrl(repositoryId, objectId, Constants.SELECTOR_POLICIES);
82 url.addParameter(Constants.PARAM_FILTER, filter);
83
84
85 HttpUtils.Response resp = read(url);
86 List<Object> json = parseArray(resp.getStream(), resp.getCharset());
87
88 return JSONConverter.convertObjects(json);
89 }
90 }