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.server.impl.webservices;
20  
21  import com.sun.xml.ws.developer.StreamingAttachment;
22  
23  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
24  import org.apache.chemistry.opencmis.commons.data.ObjectData;
25  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
26  import static org.apache.chemistry.opencmis.commons.impl.Converter.convert;
27  import static org.apache.chemistry.opencmis.commons.impl.Converter.convertExtensionHolder;
28  import static org.apache.chemistry.opencmis.commons.impl.Converter.convertHolder;
29  import static org.apache.chemistry.opencmis.commons.impl.Converter.setExtensionValues;
30  import static org.apache.chemistry.opencmis.commons.impl.Converter.setHolderValue;
31  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisAccessControlListType;
32  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisContentStreamType;
33  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisException;
34  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisExtensionType;
35  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
36  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisPropertiesType;
37  import org.apache.chemistry.opencmis.commons.impl.jaxb.EnumIncludeRelationships;
38  import org.apache.chemistry.opencmis.commons.impl.jaxb.VersioningServicePort;
39  import org.apache.chemistry.opencmis.commons.server.CmisService;
40  
41  import java.util.ArrayList;
42  import java.util.List;
43  
44  import javax.annotation.Resource;
45  
46  import javax.jws.WebService;
47  
48  import javax.xml.ws.Holder;
49  import javax.xml.ws.WebServiceContext;
50  import javax.xml.ws.soap.MTOM;
51  
52  
53  /**
54   * CMIS Versioning Service.
55   */
56  @MTOM
57  @StreamingAttachment( parseEagerly = true, memoryThreshold = 4 * 1024 * 1204 )
58  @WebService( endpointInterface = "org.apache.chemistry.opencmis.commons.impl.jaxb.VersioningServicePort" )
59  public class VersioningService extends AbstractService implements VersioningServicePort
60  {
61      @Resource
62      public WebServiceContext wsContext;
63  
64      public void cancelCheckOut( String repositoryId, String objectId, Holder<CmisExtensionType> extension )
65          throws CmisException
66      {
67          CmisService service = null;
68  
69          try
70          {
71              service = getService( wsContext, repositoryId );
72  
73              ExtensionsData extData = convertExtensionHolder( extension );
74  
75              service.cancelCheckOut( repositoryId, objectId, extData );
76  
77              setExtensionValues( extData, extension );
78          }
79          catch ( Exception e )
80          {
81              throw convertException( e );
82          }
83          finally
84          {
85              closeService( service );
86          }
87      }
88  
89      public void checkIn( String repositoryId, Holder<String> objectId, Boolean major, CmisPropertiesType properties,
90          CmisContentStreamType contentStream, String checkinComment, List<String> policies,
91          CmisAccessControlListType addAces, CmisAccessControlListType removeAces, Holder<CmisExtensionType> extension )
92          throws CmisException
93      {
94          CmisService service = null;
95  
96          try
97          {
98              service = getService( wsContext, repositoryId );
99  
100             org.apache.chemistry.opencmis.commons.spi.Holder<String> objectIdHolder = convertHolder( objectId );
101             ExtensionsData extData = convertExtensionHolder( extension );
102 
103             service.checkIn( repositoryId, objectIdHolder, major, convert( properties ), convert( contentStream ),
104                 checkinComment, policies, convert( addAces, null ), convert( removeAces, null ), extData );
105 
106             setHolderValue( objectIdHolder, objectId );
107             setExtensionValues( extData, extension );
108         }
109         catch ( Exception e )
110         {
111             throw convertException( e );
112         }
113         finally
114         {
115             closeService( service );
116         }
117     }
118 
119     public void checkOut( String repositoryId, Holder<String> objectId, Holder<CmisExtensionType> extension,
120         Holder<Boolean> contentCopied ) throws CmisException
121     {
122         CmisService service = null;
123 
124         try
125         {
126             service = getService( wsContext, repositoryId );
127 
128             org.apache.chemistry.opencmis.commons.spi.Holder<String> objectIdHolder = convertHolder( objectId );
129             org.apache.chemistry.opencmis.commons.spi.Holder<Boolean> contentCopiedHolder = new org.apache.chemistry.opencmis.commons.spi.Holder<Boolean>(  );
130             ExtensionsData extData = convertExtensionHolder( extension );
131 
132             service.checkOut( repositoryId, objectIdHolder, extData, contentCopiedHolder );
133 
134             if ( contentCopied != null )
135             {
136                 contentCopied.value = contentCopiedHolder.getValue(  );
137             }
138 
139             setHolderValue( objectIdHolder, objectId );
140             setExtensionValues( extData, extension );
141         }
142         catch ( Exception e )
143         {
144             throw convertException( e );
145         }
146         finally
147         {
148             closeService( service );
149         }
150     }
151 
152     public List<CmisObjectType> getAllVersions( String repositoryId, String versionSeriesId, String filter,
153         Boolean includeAllowableActions, CmisExtensionType extension )
154         throws CmisException
155     {
156         CmisService service = null;
157 
158         try
159         {
160             service = getService( wsContext, repositoryId );
161 
162             List<ObjectData> versions = service.getAllVersions( repositoryId, null, versionSeriesId, filter,
163                     includeAllowableActions, convert( extension ) );
164 
165             if ( versions == null )
166             {
167                 return null;
168             }
169 
170             List<CmisObjectType> result = new ArrayList<CmisObjectType>(  );
171 
172             for ( ObjectData object : versions )
173             {
174                 result.add( convert( object ) );
175             }
176 
177             return result;
178         }
179         catch ( Exception e )
180         {
181             throw convertException( e );
182         }
183         finally
184         {
185             closeService( service );
186         }
187     }
188 
189     public CmisObjectType getObjectOfLatestVersion( String repositoryId, String versionSeriesId, Boolean major,
190         String filter, Boolean includeAllowableActions, EnumIncludeRelationships includeRelationships,
191         String renditionFilter, Boolean includePolicyIds, Boolean includeAcl, CmisExtensionType extension )
192         throws CmisException
193     {
194         CmisService service = null;
195 
196         try
197         {
198             service = getService( wsContext, repositoryId );
199 
200             return convert( service.getObjectOfLatestVersion( repositoryId, null, versionSeriesId, major, filter,
201                     includeAllowableActions, convert( IncludeRelationships.class, includeRelationships ),
202                     renditionFilter, includePolicyIds, includeAcl, convert( extension ) ) );
203         }
204         catch ( Exception e )
205         {
206             throw convertException( e );
207         }
208         finally
209         {
210             closeService( service );
211         }
212     }
213 
214     public CmisPropertiesType getPropertiesOfLatestVersion( String repositoryId, String versionSeriesId, Boolean major,
215         String filter, CmisExtensionType extension ) throws CmisException
216     {
217         CmisService service = null;
218 
219         try
220         {
221             service = getService( wsContext, repositoryId );
222 
223             return convert( service.getPropertiesOfLatestVersion( repositoryId, null, versionSeriesId, major, filter,
224                     convert( extension ) ) );
225         }
226         catch ( Exception e )
227         {
228             throw convertException( e );
229         }
230         finally
231         {
232             closeService( service );
233         }
234     }
235 }