View Javadoc

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.IOException;
22  import java.io.OutputStream;
23  import java.math.BigInteger;
24  import java.util.Map;
25  
26  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
27  import org.apache.chemistry.opencmis.client.bindings.spi.http.Output;
28  import org.apache.chemistry.opencmis.client.bindings.spi.http.Response;
29  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
30  import org.apache.chemistry.opencmis.commons.data.ObjectList;
31  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
32  import org.apache.chemistry.opencmis.commons.impl.Constants;
33  import org.apache.chemistry.opencmis.commons.impl.JSONConstants;
34  import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
35  import org.apache.chemistry.opencmis.commons.impl.TypeCache;
36  import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
37  import org.apache.chemistry.opencmis.commons.spi.DiscoveryService;
38  import org.apache.chemistry.opencmis.commons.spi.Holder;
39  
40  /**
41   * Discovery Service Browser Binding client.
42   */
43  public class DiscoveryServiceImpl extends AbstractBrowserBindingService implements DiscoveryService {
44  
45      /**
46       * Constructor.
47       */
48      public DiscoveryServiceImpl(BindingSession session) {
49          setSession(session);
50      }
51  
52      @Override
53      public ObjectList query(String repositoryId, String statement, Boolean searchAllVersions,
54              Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
55              BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
56          // build URL
57          UrlBuilder url = getRepositoryUrl(repositoryId);
58  
59          // prepare form data
60          final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_QUERY);
61          formData.addParameter(Constants.PARAM_STATEMENT, statement);
62          formData.addParameter(Constants.PARAM_SEARCH_ALL_VERSIONS, searchAllVersions);
63          formData.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
64          formData.addParameter(Constants.PARAM_RELATIONSHIPS, includeRelationships);
65          formData.addParameter(Constants.PARAM_RENDITION_FILTER, renditionFilter);
66          formData.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
67          formData.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
68          formData.addParameter(Constants.PARAM_DATETIME_FORMAT, getDateTimeFormatParameter());
69          // Important: No succinct flag here!!!
70  
71          // send and parse
72          Response resp = post(url, formData.getContentType(), new Output() {
73              @Override
74              public void write(OutputStream out) throws IOException {
75                  formData.write(out);
76              }
77          });
78  
79          TypeCache typeCache = new ClientTypeCacheImpl(repositoryId, this);
80  
81          Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
82          return JSONConverter.convertObjectList(json, typeCache, true);
83      }
84  
85      @Override
86      public ObjectList getContentChanges(String repositoryId, Holder<String> changeLogToken, Boolean includeProperties,
87              String filter, Boolean includePolicyIds, Boolean includeAcl, BigInteger maxItems, ExtensionsData extension) {
88          // build URL
89          UrlBuilder url = getRepositoryUrl(repositoryId, Constants.SELECTOR_CONTENT_CHANGES);
90          url.addParameter(Constants.PARAM_CHANGE_LOG_TOKEN, changeLogToken == null ? null : changeLogToken.getValue());
91          url.addParameter(Constants.PARAM_PROPERTIES, includeProperties);
92          url.addParameter(Constants.PARAM_FILTER, filter);
93          url.addParameter(Constants.PARAM_POLICY_IDS, includePolicyIds);
94          url.addParameter(Constants.PARAM_ACL, includeAcl);
95          url.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
96          url.addParameter(Constants.PARAM_SUCCINCT, getSuccinctParameter());
97  
98          // read and parse
99          Response resp = read(url);
100         Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
101 
102         if (changeLogToken != null && json != null) {
103             Object token = json.get(JSONConstants.JSON_OBJECTLIST_CHANGE_LOG_TOKEN);
104             if (token instanceof String) {
105                 changeLogToken.setValue((String) token);
106             }
107         }
108 
109         TypeCache typeCache = new ClientTypeCacheImpl(repositoryId, this);
110 
111         return JSONConverter.convertObjectList(json, typeCache, false);
112     }
113 }