This project has retired. For details please refer to its Attic page.
RepositoryServiceImpl 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.math.BigInteger;
22  import java.util.List;
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.RepositoryInfo;
29  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
30  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
31  import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList;
32  import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
33  import org.apache.chemistry.opencmis.commons.impl.Constants;
34  import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
35  import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
36  import org.apache.chemistry.opencmis.commons.spi.RepositoryService;
37  
38  /**
39   * Repository Service Browser Binding client.
40   */
41  public class RepositoryServiceImpl extends AbstractBrowserBindingService implements RepositoryService {
42  
43      /**
44       * Constructor.
45       */
46      public RepositoryServiceImpl(BindingSession session) {
47          setSession(session);
48      }
49  
50      public List<RepositoryInfo> getRepositoryInfos(ExtensionsData extension) {
51          return getRepositoriesInternal(null);
52      }
53  
54      public RepositoryInfo getRepositoryInfo(String repositoryId, ExtensionsData extension) {
55          List<RepositoryInfo> repositoryInfos = getRepositoriesInternal(repositoryId);
56  
57          // find the repository
58          for (RepositoryInfo info : repositoryInfos) {
59              if (info.getId() == null) {
60                  continue;
61              }
62  
63              if (info.getId().equals(repositoryId)) {
64                  return info;
65              }
66          }
67  
68          throw new CmisObjectNotFoundException("Repository not found!");
69      }
70  
71      public TypeDefinition getTypeDefinition(String repositoryId, String typeId, ExtensionsData extension) {
72          return getTypeDefinitionInternal(repositoryId, typeId);
73      }
74  
75      public TypeDefinitionList getTypeChildren(String repositoryId, String typeId, Boolean includePropertyDefinitions,
76              BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
77          // build URL
78          UrlBuilder url = getRepositoryUrl(repositoryId, Constants.SELECTOR_TYPE_CHILDREN);
79          url.addParameter(Constants.PARAM_TYPE_ID, typeId);
80          url.addParameter(Constants.PARAM_PROPERTY_DEFINITIONS, includePropertyDefinitions);
81          url.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
82          url.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
83  
84          // read and parse
85          HttpUtils.Response resp = read(url);
86          Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
87  
88          return JSONConverter.convertTypeChildren(json);
89      }
90  
91      public List<TypeDefinitionContainer> getTypeDescendants(String repositoryId, String typeId, BigInteger depth,
92              Boolean includePropertyDefinitions, ExtensionsData extension) {
93          // build URL
94          UrlBuilder url = getRepositoryUrl(repositoryId, Constants.SELECTOR_TYPE_DESCENDANTS);
95          url.addParameter(Constants.PARAM_TYPE_ID, typeId);
96          url.addParameter(Constants.PARAM_DEPTH, depth);
97          url.addParameter(Constants.PARAM_PROPERTY_DEFINITIONS, includePropertyDefinitions);
98  
99          // read and parse
100         HttpUtils.Response resp = read(url);
101         List<Object> json = parseArray(resp.getStream(), resp.getCharset());
102 
103         return JSONConverter.convertTypeDescendants(json);
104     }
105 }