This project has retired. For details please refer to its
Attic page.
MultiFilingService 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_FOLDER_ID;
22 import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_CONTENT;
23 import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileBaseUrl;
24 import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileUrl;
25 import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.CONTEXT_OBJECT_ID;
26 import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.getSimpleObject;
27 import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.setStatus;
28 import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.writeJSON;
29 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
30 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
31
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34
35 import org.apache.chemistry.opencmis.commons.data.ObjectData;
36 import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
37 import org.apache.chemistry.opencmis.commons.impl.Constants;
38 import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
39 import org.apache.chemistry.opencmis.commons.impl.TypeCache;
40 import org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
41 import org.apache.chemistry.opencmis.commons.impl.server.TypeCacheImpl;
42 import org.apache.chemistry.opencmis.commons.server.CallContext;
43 import org.apache.chemistry.opencmis.commons.server.CmisService;
44 import org.apache.chemistry.opencmis.commons.spi.Holder;
45
46
47
48
49 public class MultiFilingService {
50
51
52
53
54 public static void addObjectToFolder(CallContext context, CmisService service, String repositoryId,
55 HttpServletRequest request, HttpServletResponse response) throws Exception {
56
57 String objectId = (String) context.get(CONTEXT_OBJECT_ID);
58 String folderId = getStringParameter(request, PARAM_FOLDER_ID);
59 Boolean allVersions = getBooleanParameter(request, Constants.PARAM_ALL_VERSIONS);
60
61
62 Holder<String> objectIdHolder = new Holder<String>(objectId);
63 service.addObjectToFolder(repositoryId, objectId, folderId, allVersions, null);
64
65 String newObjectId = (objectIdHolder.getValue() == null ? objectId : objectIdHolder.getValue());
66
67 ObjectData object = getSimpleObject(service, repositoryId, newObjectId);
68 if (object == null) {
69 throw new CmisRuntimeException("Object is null!");
70 }
71
72
73 String location = compileUrl(compileBaseUrl(request, repositoryId), RESOURCE_CONTENT, newObjectId);
74
75 setStatus(request, response, HttpServletResponse.SC_CREATED);
76 response.setHeader("Location", location);
77
78
79 TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
80 JSONObject jsonObject = JSONConverter.convert(object, typeCache, false);
81
82 writeJSON(jsonObject, request, response);
83 }
84
85
86
87
88 public static void removeObjectFromFolder(CallContext context, CmisService service, String repositoryId,
89 HttpServletRequest request, HttpServletResponse response) throws Exception {
90
91 String objectId = (String) context.get(CONTEXT_OBJECT_ID);
92 String folderId = getStringParameter(request, PARAM_FOLDER_ID);
93
94
95 Holder<String> objectIdHolder = new Holder<String>(objectId);
96 service.removeObjectFromFolder(repositoryId, objectId, folderId, null);
97
98 String newObjectId = (objectIdHolder.getValue() == null ? objectId : objectIdHolder.getValue());
99
100 ObjectData object = getSimpleObject(service, repositoryId, newObjectId);
101 if (object == null) {
102 throw new CmisRuntimeException("Object is null!");
103 }
104
105
106 String location = compileUrl(compileBaseUrl(request, repositoryId), RESOURCE_CONTENT, newObjectId);
107
108 setStatus(request, response, HttpServletResponse.SC_CREATED);
109 response.setHeader("Location", location);
110
111
112 TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
113 JSONObject jsonObject = JSONConverter.convert(object, typeCache, false);
114
115 writeJSON(jsonObject, request, response);
116 }
117 }