This project has retired. For details please refer to its Attic page.
DiscoveryServiceImpl xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.client.bindings.spi.browser;
20  
21  import java.io.OutputStream;
22  import java.math.BigInteger;
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.ExtensionsData;
28  import org.apache.chemistry.opencmis.commons.data.ObjectList;
29  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
30  import org.apache.chemistry.opencmis.commons.impl.Constants;
31  import org.apache.chemistry.opencmis.commons.impl.JSONConstants;
32  import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
33  import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
34  import org.apache.chemistry.opencmis.commons.spi.DiscoveryService;
35  import org.apache.chemistry.opencmis.commons.spi.Holder;
36  
37  /**
38   * Discovery Service Browser Binding client.
39   */
40  public class DiscoveryServiceImpl extends AbstractBrowserBindingService implements DiscoveryService {
41  
42      /**
43       * Constructor.
44       */
45      public DiscoveryServiceImpl(BindingSession session) {
46          setSession(session);
47      }
48  
49      public ObjectList query(String repositoryId, String statement, Boolean searchAllVersions,
50              Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
51              BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
52          // build URL
53          UrlBuilder url = getRepositoryUrl(repositoryId);
54  
55          // prepare form data
56          final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_QUERY);
57          formData.addParameter(Constants.PARAM_Q, statement);
58          formData.addParameter(Constants.PARAM_SEARCH_ALL_VERSIONS, searchAllVersions);
59          formData.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
60          formData.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
61          formData.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
62          formData.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
63          formData.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
64  
65          // send and parse
66          HttpUtils.Response resp = post(url, formData.getContentType(), new HttpUtils.Output() {
67              public void write(OutputStream out) throws Exception {
68                  formData.write(out);
69              }
70          });
71  
72          Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
73          return JSONConverter.convertObjectList(json, true);
74      }
75  
76      public ObjectList getContentChanges(String repositoryId, Holder<String> changeLogToken, Boolean includeProperties,
77              String filter, Boolean includePolicyIds, Boolean includeAcl, BigInteger maxItems, ExtensionsData extension) {
78          // build URL
79          UrlBuilder url = getRepositoryUrl(repositoryId, Constants.SELECTOR_CONTENT_CHANGES);
80          url.addParameter(Constants.PARAM_SUB_RELATIONSHIP_TYPES,
81                  changeLogToken == null ? null : changeLogToken.getValue());
82          url.addParameter(Constants.PARAM_PROPERTIES, includeProperties);
83          url.addParameter(Constants.PARAM_FILTER, filter);
84          url.addParameter(Constants.PARAM_POLICY_IDS, includePolicyIds);
85          url.addParameter(Constants.PARAM_ACL, includeAcl);
86          url.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
87  
88          // read and parse
89          HttpUtils.Response resp = read(url);
90          Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
91  
92          if (changeLogToken != null && json != null) {
93              Object token = json.get(JSONConstants.JSON_OBJECTLIST_CHANGE_LOG_TOKEN);
94              if (token instanceof String) {
95                  changeLogToken.setValue((String) token);
96              }
97          }
98  
99          return JSONConverter.convertObjectList(json, false);
100     }
101 }