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.webservices;
20  
21  import static org.apache.chemistry.opencmis.commons.impl.WSConverter.convert;
22  import static org.apache.chemistry.opencmis.commons.impl.WSConverter.convertHolder;
23  import static org.apache.chemistry.opencmis.commons.impl.WSConverter.setHolderValue;
24  
25  import java.math.BigInteger;
26  
27  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
28  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
29  import org.apache.chemistry.opencmis.commons.data.ObjectList;
30  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
31  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
32  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisException;
33  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectListType;
34  import org.apache.chemistry.opencmis.commons.impl.jaxb.DiscoveryServicePort;
35  import org.apache.chemistry.opencmis.commons.impl.jaxb.EnumIncludeRelationships;
36  import org.apache.chemistry.opencmis.commons.spi.DiscoveryService;
37  import org.apache.chemistry.opencmis.commons.spi.Holder;
38  
39  /**
40   * Discovery Service Web Services client.
41   */
42  public class DiscoveryServiceImpl extends AbstractWebServicesService implements DiscoveryService {
43  
44      private final AbstractPortProvider portProvider;
45  
46      /**
47       * Constructor.
48       */
49      public DiscoveryServiceImpl(BindingSession session, AbstractPortProvider portProvider) {
50          setSession(session);
51          this.portProvider = portProvider;
52      }
53  
54      @Override
55      public ObjectList getContentChanges(String repositoryId, Holder<String> changeLogToken, Boolean includeProperties,
56              String filter, Boolean includePolicyIds, Boolean includeACL, BigInteger maxItems, ExtensionsData extension) {
57          DiscoveryServicePort port = portProvider.getDiscoveryServicePort(getCmisVersion(repositoryId),
58                  "getContentChanges");
59  
60          try {
61              javax.xml.ws.Holder<String> portChangeLokToken = convertHolder(changeLogToken);
62              javax.xml.ws.Holder<CmisObjectListType> portObjects = new javax.xml.ws.Holder<CmisObjectListType>();
63  
64              port.getContentChanges(repositoryId, portChangeLokToken, includeProperties, filter, includePolicyIds,
65                      includeACL, maxItems, convert(extension), portObjects);
66  
67              setHolderValue(portChangeLokToken, changeLogToken);
68  
69              return convert(portObjects.value);
70          } catch (CmisException e) {
71              throw convertException(e);
72          } catch (Exception e) {
73              throw new CmisRuntimeException("Error: " + e.getMessage(), e);
74          } finally {
75              portProvider.endCall(port);
76          }
77      }
78  
79      @Override
80      public ObjectList query(String repositoryId, String statement, Boolean searchAllVersions,
81              Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
82              BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
83          DiscoveryServicePort port = portProvider.getDiscoveryServicePort(getCmisVersion(repositoryId), "query");
84  
85          try {
86              return convert(port.query(repositoryId, statement, searchAllVersions, includeAllowableActions,
87                      convert(EnumIncludeRelationships.class, includeRelationships), renditionFilter, maxItems,
88                      skipCount, convert(extension)));
89          } catch (CmisException e) {
90              throw convertException(e);
91          } catch (Exception e) {
92              throw new CmisRuntimeException("Error: " + e.getMessage(), e);
93          } finally {
94              portProvider.endCall(port);
95          }
96      }
97  }