This project has retired. For details please refer to its
Attic page.
VersioningServiceImpl 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.List;
23 import java.util.Map;
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.Acl;
28 import org.apache.chemistry.opencmis.commons.data.ContentStream;
29 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
30 import org.apache.chemistry.opencmis.commons.data.ObjectData;
31 import org.apache.chemistry.opencmis.commons.data.Properties;
32 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
33 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
34 import org.apache.chemistry.opencmis.commons.impl.Constants;
35 import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
36 import org.apache.chemistry.opencmis.commons.impl.ReturnVersion;
37 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
38 import org.apache.chemistry.opencmis.commons.spi.Holder;
39 import org.apache.chemistry.opencmis.commons.spi.VersioningService;
40
41
42
43
44 public class VersioningServiceImpl extends AbstractBrowserBindingService implements VersioningService {
45
46
47
48
49 public VersioningServiceImpl(BindingSession session) {
50 setSession(session);
51 }
52
53 public void checkOut(String repositoryId, Holder<String> objectId, ExtensionsData extension,
54 Holder<Boolean> contentCopied) {
55
56 if ((objectId == null) || (objectId.getValue() == null) || (objectId.getValue().length() == 0)) {
57 throw new CmisInvalidArgumentException("Object id must be set!");
58 }
59
60
61 UrlBuilder url = getObjectUrl(repositoryId, objectId.getValue());
62
63
64 final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_CHECK_OUT);
65
66
67 HttpUtils.Response resp = post(url, formData.getContentType(), new HttpUtils.Output() {
68 public void write(OutputStream out) throws Exception {
69 formData.write(out);
70 }
71 });
72
73 Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
74 ObjectData newObj = JSONConverter.convertObject(json);
75
76 objectId.setValue(newObj == null ? null : newObj.getId());
77 }
78
79 public void cancelCheckOut(String repositoryId, String objectId, ExtensionsData extension) {
80
81 UrlBuilder url = getObjectUrl(repositoryId, objectId);
82
83
84 final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_CANCEL_CHECK_OUT);
85
86
87 postAndConsume(url, formData.getContentType(), new HttpUtils.Output() {
88 public void write(OutputStream out) throws Exception {
89 formData.write(out);
90 }
91 });
92 }
93
94 public void checkIn(String repositoryId, Holder<String> objectId, Boolean major, Properties properties,
95 ContentStream contentStream, String checkinComment, List<String> policies, Acl addAces, Acl removeAces,
96 ExtensionsData extension) {
97
98 if ((objectId == null) || (objectId.getValue() == null) || (objectId.getValue().length() == 0)) {
99 throw new CmisInvalidArgumentException("Object id must be set!");
100 }
101
102
103 UrlBuilder url = getObjectUrl(repositoryId, objectId.getValue());
104
105
106 final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_CHECK_IN, contentStream);
107 formData.addParameter(Constants.PARAM_MAJOR, major);
108 formData.addPropertiesParameters(properties);
109 formData.addParameter(Constants.PARAM_CHECKIN_COMMENT, checkinComment);
110 formData.addPoliciesParameters(policies);
111 formData.addAddAcesParameters(addAces);
112 formData.addRemoveAcesParameters(removeAces);
113
114
115 HttpUtils.Response resp = post(url, formData.getContentType(), new HttpUtils.Output() {
116 public void write(OutputStream out) throws Exception {
117 formData.write(out);
118 }
119 });
120
121 Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
122 ObjectData newObj = JSONConverter.convertObject(json);
123
124 objectId.setValue(newObj == null ? null : newObj.getId());
125 }
126
127 public ObjectData getObjectOfLatestVersion(String repositoryId, String objectId, String versionSeriesId,
128 Boolean major, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
129 String renditionFilter, Boolean includePolicyIds, Boolean includeAcl, ExtensionsData extension) {
130
131 UrlBuilder url = getObjectUrl(repositoryId, objectId, Constants.SELECTOR_OBJECT);
132 url.addParameter(Constants.PARAM_FILTER, filter);
133 url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
134 url.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
135 url.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
136 url.addParameter(Constants.PARAM_POLICY_IDS, includePolicyIds);
137 url.addParameter(Constants.PARAM_ACL, includeAcl);
138 url.addParameter(Constants.PARAM_RETURN_VERSION,
139 (major == null || Boolean.FALSE.equals(major) ? ReturnVersion.LATEST : ReturnVersion.LASTESTMAJOR));
140
141
142 HttpUtils.Response resp = read(url);
143 Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
144
145 return JSONConverter.convertObject(json);
146 }
147
148 public Properties getPropertiesOfLatestVersion(String repositoryId, String objectId, String versionSeriesId,
149 Boolean major, String filter, ExtensionsData extension) {
150
151 UrlBuilder url = getObjectUrl(repositoryId, objectId, Constants.SELECTOR_PROPERTIES);
152 url.addParameter(Constants.PARAM_FILTER, filter);
153 url.addParameter(Constants.PARAM_RETURN_VERSION,
154 (major == null || Boolean.FALSE.equals(major) ? ReturnVersion.LATEST : ReturnVersion.LASTESTMAJOR));
155
156
157 HttpUtils.Response resp = read(url);
158 Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
159
160 return JSONConverter.convertProperties(json);
161 }
162
163 public List<ObjectData> getAllVersions(String repositoryId, String objectId, String versionSeriesId, String filter,
164 Boolean includeAllowableActions, ExtensionsData extension) {
165
166 UrlBuilder url = getObjectUrl(repositoryId, objectId, Constants.SELECTOR_VERSIONS);
167 url.addParameter(Constants.PARAM_FILTER, filter);
168 url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
169
170
171 HttpUtils.Response resp = read(url);
172 List<Object> json = parseArray(resp.getStream(), resp.getCharset());
173
174 return JSONConverter.convertObjects(json);
175 }
176 }