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