This project has retired. For details please refer to its Attic page.
VersioningServiceImpl 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.webservices;
20  
21  import static org.apache.chemistry.opencmis.commons.impl.Converter.convert;
22  import static org.apache.chemistry.opencmis.commons.impl.Converter.convertExtensionHolder;
23  import static org.apache.chemistry.opencmis.commons.impl.Converter.convertHolder;
24  import static org.apache.chemistry.opencmis.commons.impl.Converter.setExtensionValues;
25  import static org.apache.chemistry.opencmis.commons.impl.Converter.setHolderValue;
26  
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
31  import org.apache.chemistry.opencmis.commons.data.Acl;
32  import org.apache.chemistry.opencmis.commons.data.ContentStream;
33  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
34  import org.apache.chemistry.opencmis.commons.data.ObjectData;
35  import org.apache.chemistry.opencmis.commons.data.Properties;
36  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
37  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
38  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisException;
39  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisExtensionType;
40  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
41  import org.apache.chemistry.opencmis.commons.impl.jaxb.EnumIncludeRelationships;
42  import org.apache.chemistry.opencmis.commons.impl.jaxb.VersioningServicePort;
43  import org.apache.chemistry.opencmis.commons.spi.Holder;
44  import org.apache.chemistry.opencmis.commons.spi.VersioningService;
45  
46  /**
47   * Versioning Service Web Services client.
48   */
49  public class VersioningServiceImpl extends AbstractWebServicesService implements VersioningService {
50  
51      private final AbstractPortProvider portProvider;
52  
53      /**
54       * Constructor.
55       */
56      public VersioningServiceImpl(BindingSession session, AbstractPortProvider portProvider) {
57          setSession(session);
58          this.portProvider = portProvider;
59      }
60  
61      public void checkOut(String repositoryId, Holder<String> objectId, ExtensionsData extension,
62              Holder<Boolean> contentCopied) {
63          VersioningServicePort port = portProvider.getVersioningServicePort();
64  
65          try {
66              javax.xml.ws.Holder<String> portObjectId = convertHolder(objectId);
67              javax.xml.ws.Holder<Boolean> portContentCopied = new javax.xml.ws.Holder<Boolean>();
68              javax.xml.ws.Holder<CmisExtensionType> portExtension = convertExtensionHolder(extension);
69  
70              port.checkOut(repositoryId, portObjectId, portExtension, portContentCopied);
71  
72              setHolderValue(portObjectId, objectId);
73              setHolderValue(portContentCopied, contentCopied);
74              setExtensionValues(portExtension, extension);
75          } catch (CmisException e) {
76              throw convertException(e);
77          } catch (Exception e) {
78              throw new CmisRuntimeException("Error: " + e.getMessage(), e);
79          } finally {
80              portProvider.endCall(port);
81          }
82      }
83  
84      public void cancelCheckOut(String repositoryId, String objectId, ExtensionsData extension) {
85          VersioningServicePort port = portProvider.getVersioningServicePort();
86  
87          try {
88              javax.xml.ws.Holder<CmisExtensionType> portExtension = convertExtensionHolder(extension);
89  
90              port.cancelCheckOut(repositoryId, objectId, portExtension);
91  
92              setExtensionValues(portExtension, extension);
93          } catch (CmisException e) {
94              throw convertException(e);
95          } catch (Exception e) {
96              throw new CmisRuntimeException("Error: " + e.getMessage(), e);
97          } finally {
98              portProvider.endCall(port);
99          }
100     }
101 
102     public void checkIn(String repositoryId, Holder<String> objectId, Boolean major, Properties properties,
103             ContentStream contentStream, String checkinComment, List<String> policies, Acl addACEs, Acl removeACEs,
104             ExtensionsData extension) {
105         VersioningServicePort port = portProvider.getVersioningServicePort();
106 
107         try {
108             javax.xml.ws.Holder<String> portObjectId = convertHolder(objectId);
109             javax.xml.ws.Holder<CmisExtensionType> portExtension = convertExtensionHolder(extension);
110 
111             port.checkIn(repositoryId, portObjectId, major, convert(properties), convert(contentStream),
112                     checkinComment, policies, convert(addACEs), convert(removeACEs), portExtension);
113 
114             setHolderValue(portObjectId, objectId);
115             setExtensionValues(portExtension, extension);
116         } catch (CmisException e) {
117             throw convertException(e);
118         } catch (Exception e) {
119             throw new CmisRuntimeException("Error: " + e.getMessage(), e);
120         } finally {
121             portProvider.endCall(port);
122         }
123     }
124 
125     public List<ObjectData> getAllVersions(String repositoryId, String objectId, String versionSeriesId, String filter,
126             Boolean includeAllowableActions, ExtensionsData extension) {
127         VersioningServicePort port = portProvider.getVersioningServicePort();
128 
129         try {
130             List<CmisObjectType> versionList = port.getAllVersions(repositoryId, versionSeriesId, filter,
131                     includeAllowableActions, convert(extension));
132 
133             // no list?
134             if (versionList == null) {
135                 return null;
136             }
137 
138             // convert list
139             List<ObjectData> result = new ArrayList<ObjectData>();
140             for (CmisObjectType version : versionList) {
141                 result.add(convert(version));
142             }
143 
144             return result;
145         } catch (CmisException e) {
146             throw convertException(e);
147         } catch (Exception e) {
148             throw new CmisRuntimeException("Error: " + e.getMessage(), e);
149         } finally {
150             portProvider.endCall(port);
151         }
152     }
153 
154     public ObjectData getObjectOfLatestVersion(String repositoryId, String objectId, String versionSeriesId,
155             Boolean major, String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
156             String renditionFilter, Boolean includePolicyIds, Boolean includeACL, ExtensionsData extension) {
157         VersioningServicePort port = portProvider.getVersioningServicePort();
158 
159         try {
160             return convert(port.getObjectOfLatestVersion(repositoryId, versionSeriesId, major, filter,
161                     includeAllowableActions, convert(EnumIncludeRelationships.class, includeRelationships),
162                     renditionFilter, includePolicyIds, includeACL, convert(extension)));
163         } catch (CmisException e) {
164             throw convertException(e);
165         } catch (Exception e) {
166             throw new CmisRuntimeException("Error: " + e.getMessage(), e);
167         } finally {
168             portProvider.endCall(port);
169         }
170     }
171 
172     public Properties getPropertiesOfLatestVersion(String repositoryId, String objectId, String versionSeriesId,
173             Boolean major, String filter, ExtensionsData extension) {
174         VersioningServicePort port = portProvider.getVersioningServicePort();
175 
176         try {
177             return convert(port.getPropertiesOfLatestVersion(repositoryId, versionSeriesId, major, filter,
178                     convert(extension)));
179         } catch (CmisException e) {
180             throw convertException(e);
181         } catch (Exception e) {
182             throw new CmisRuntimeException("Error: " + e.getMessage(), e);
183         } finally {
184             portProvider.endCall(port);
185         }
186     }
187 }