This project has retired. For details please refer to its
Attic page.
DiscoveryService 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_ACL;
22 import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_CHANGE_LOG_TOKEN;
23 import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_FILTER;
24 import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_POLICY_IDS;
25 import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_PROPERTIES;
26 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBigIntegerParameter;
27 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
28 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getEnumParameter;
29 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
30
31 import java.math.BigInteger;
32
33 import javax.servlet.http.HttpServletRequest;
34 import javax.servlet.http.HttpServletResponse;
35
36 import org.apache.chemistry.opencmis.commons.data.ObjectList;
37 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
38 import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
39 import org.apache.chemistry.opencmis.commons.impl.Constants;
40 import org.apache.chemistry.opencmis.commons.impl.JSONConstants;
41 import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
42 import org.apache.chemistry.opencmis.commons.impl.TypeCache;
43 import org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
44 import org.apache.chemistry.opencmis.commons.impl.server.TypeCacheImpl;
45 import org.apache.chemistry.opencmis.commons.server.CallContext;
46 import org.apache.chemistry.opencmis.commons.server.CmisService;
47 import org.apache.chemistry.opencmis.commons.spi.Holder;
48
49
50
51
52 public class DiscoveryService {
53
54 private DiscoveryService() {
55 }
56
57
58
59
60 public static void query(CallContext context, CmisService service, String repositoryId, HttpServletRequest request,
61 HttpServletResponse response) throws Exception {
62
63 String statement = getStringParameter(request, Constants.PARAM_Q);
64 Boolean searchAllVersions = getBooleanParameter(request, Constants.PARAM_SEARCH_ALL_VERSIONS);
65 Boolean includeAllowableActions = getBooleanParameter(request, Constants.PARAM_ALLOWABLE_ACTIONS);
66 IncludeRelationships includeRelationships = getEnumParameter(request, Constants.PARAM_RELATIONSHIPS,
67 IncludeRelationships.class);
68 String renditionFilter = getStringParameter(request, Constants.PARAM_RENDITION_FILTER);
69 BigInteger maxItems = getBigIntegerParameter(request, Constants.PARAM_MAX_ITEMS);
70 BigInteger skipCount = getBigIntegerParameter(request, Constants.PARAM_SKIP_COUNT);
71
72
73 ObjectList results = service.query(repositoryId, statement, searchAllVersions, includeAllowableActions,
74 includeRelationships, renditionFilter, maxItems, skipCount, null);
75
76 if (results == null) {
77 throw new CmisRuntimeException("Results are null!");
78 }
79
80 TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
81 JSONObject jsonResults = JSONConverter.convert(results, typeCache, true);
82
83 response.setStatus(HttpServletResponse.SC_OK);
84 BrowserBindingUtils.writeJSON(jsonResults, request, response);
85 }
86
87
88
89
90 public static void getContentChanges(CallContext context, CmisService service, String repositoryId,
91 HttpServletRequest request, HttpServletResponse response) throws Exception {
92
93 String changeLogToken = getStringParameter(request, PARAM_CHANGE_LOG_TOKEN);
94 Boolean includeProperties = getBooleanParameter(request, PARAM_PROPERTIES);
95 String filter = getStringParameter(request, PARAM_FILTER);
96 Boolean includePolicyIds = getBooleanParameter(request, PARAM_POLICY_IDS);
97 Boolean includeAcl = getBooleanParameter(request, PARAM_ACL);
98 BigInteger maxItems = getBigIntegerParameter(request, Constants.PARAM_MAX_ITEMS);
99
100 Holder<String> changeLogTokenHolder = new Holder<String>(changeLogToken);
101 ObjectList changes = service.getContentChanges(repositoryId, changeLogTokenHolder, includeProperties, filter,
102 includePolicyIds, includeAcl, maxItems, null);
103
104 TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
105 JSONObject jsonChanges = JSONConverter.convert(changes, typeCache, false);
106 jsonChanges.put(JSONConstants.JSON_OBJECTLIST_CHANGE_LOG_TOKEN, changeLogTokenHolder.getValue());
107
108 response.setStatus(HttpServletResponse.SC_OK);
109 BrowserBindingUtils.writeJSON(jsonChanges, request, response);
110 }
111 }