1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.RenditionData;
25 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
26 import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
27 import org.apache.chemistry.opencmis.commons.enums.VersioningState;
28 import static org.apache.chemistry.opencmis.commons.impl.Converter.convert;
29 import static org.apache.chemistry.opencmis.commons.impl.Converter.convertExtensionHolder;
30 import static org.apache.chemistry.opencmis.commons.impl.Converter.convertHolder;
31 import static org.apache.chemistry.opencmis.commons.impl.Converter.setExtensionValues;
32 import static org.apache.chemistry.opencmis.commons.impl.Converter.setHolderValue;
33 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisAccessControlListType;
34 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisAllowableActionsType;
35 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisContentStreamType;
36 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisException;
37 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisExtensionType;
38 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
39 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisPropertiesType;
40 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisRenditionType;
41 import org.apache.chemistry.opencmis.commons.impl.jaxb.DeleteTreeResponse.FailedToDelete;
42 import org.apache.chemistry.opencmis.commons.impl.jaxb.EnumIncludeRelationships;
43 import org.apache.chemistry.opencmis.commons.impl.jaxb.EnumUnfileObject;
44 import org.apache.chemistry.opencmis.commons.impl.jaxb.EnumVersioningState;
45 import org.apache.chemistry.opencmis.commons.impl.jaxb.ObjectServicePort;
46 import org.apache.chemistry.opencmis.commons.server.CmisService;
47
48 import java.math.BigInteger;
49
50 import java.util.ArrayList;
51 import java.util.List;
52
53 import javax.annotation.Resource;
54
55 import javax.jws.WebService;
56
57 import javax.xml.ws.Holder;
58 import javax.xml.ws.WebServiceContext;
59 import javax.xml.ws.soap.MTOM;
60
61
62
63
64
65 @MTOM
66 @StreamingAttachment( parseEagerly = true, memoryThreshold = 4 * 1024 * 1204 )
67 @WebService( endpointInterface = "org.apache.chemistry.opencmis.commons.impl.jaxb.ObjectServicePort" )
68 public class ObjectService extends AbstractService implements ObjectServicePort
69 {
70 @Resource
71 public WebServiceContext wsContext;
72
73 public void createDocument( String repositoryId, CmisPropertiesType properties, String folderId,
74 CmisContentStreamType contentStream, EnumVersioningState versioningState, List<String> policies,
75 CmisAccessControlListType addAces, CmisAccessControlListType removeAces, Holder<CmisExtensionType> extension,
76 Holder<String> objectId ) throws CmisException
77 {
78 CmisService service = null;
79
80 try
81 {
82 service = getService( wsContext, repositoryId );
83
84 ExtensionsData extData = convertExtensionHolder( extension );
85
86 String id = service.createDocument( repositoryId, convert( properties ), folderId,
87 convert( contentStream ), convert( VersioningState.class, versioningState ), policies,
88 convert( addAces, null ), convert( removeAces, null ), extData );
89
90 if ( objectId != null )
91 {
92 objectId.value = id;
93 }
94
95 setExtensionValues( extData, extension );
96 }
97 catch ( Exception e )
98 {
99 throw convertException( e );
100 }
101 finally
102 {
103 closeService( service );
104 }
105 }
106
107 public void createDocumentFromSource( String repositoryId, String sourceId, CmisPropertiesType properties,
108 String folderId, EnumVersioningState versioningState, List<String> policies, CmisAccessControlListType addAces,
109 CmisAccessControlListType removeAces, Holder<CmisExtensionType> extension, Holder<String> objectId )
110 throws CmisException
111 {
112 CmisService service = null;
113
114 try
115 {
116 service = getService( wsContext, repositoryId );
117
118 ExtensionsData extData = convertExtensionHolder( extension );
119
120 String id = service.createDocumentFromSource( repositoryId, sourceId, convert( properties ), folderId,
121 convert( VersioningState.class, versioningState ), policies, convert( addAces, null ),
122 convert( removeAces, null ), extData );
123
124 if ( objectId != null )
125 {
126 objectId.value = id;
127 }
128
129 setExtensionValues( extData, extension );
130 }
131 catch ( Exception e )
132 {
133 throw convertException( e );
134 }
135 finally
136 {
137 closeService( service );
138 }
139 }
140
141 public void createFolder( String repositoryId, CmisPropertiesType properties, String folderId,
142 List<String> policies, CmisAccessControlListType addAces, CmisAccessControlListType removeAces,
143 Holder<CmisExtensionType> extension, Holder<String> objectId )
144 throws CmisException
145 {
146 CmisService service = null;
147
148 try
149 {
150 service = getService( wsContext, repositoryId );
151
152 ExtensionsData extData = convertExtensionHolder( extension );
153
154 String id = service.createFolder( repositoryId, convert( properties ), folderId, policies,
155 convert( addAces, null ), convert( removeAces, null ), extData );
156
157 if ( objectId != null )
158 {
159 objectId.value = id;
160 }
161
162 setExtensionValues( extData, extension );
163 }
164 catch ( Exception e )
165 {
166 throw convertException( e );
167 }
168 finally
169 {
170 closeService( service );
171 }
172 }
173
174 public void createPolicy( String repositoryId, CmisPropertiesType properties, String folderId,
175 List<String> policies, CmisAccessControlListType addAces, CmisAccessControlListType removeAces,
176 Holder<CmisExtensionType> extension, Holder<String> objectId )
177 throws CmisException
178 {
179 CmisService service = null;
180
181 try
182 {
183 service = getService( wsContext, repositoryId );
184
185 ExtensionsData extData = convertExtensionHolder( extension );
186
187 String id = service.createPolicy( repositoryId, convert( properties ), folderId, policies,
188 convert( addAces, null ), convert( removeAces, null ), extData );
189
190 if ( objectId != null )
191 {
192 objectId.value = id;
193 }
194
195 setExtensionValues( extData, extension );
196 }
197 catch ( Exception e )
198 {
199 throw convertException( e );
200 }
201 finally
202 {
203 closeService( service );
204 }
205 }
206
207 public void createRelationship( String repositoryId, CmisPropertiesType properties, List<String> policies,
208 CmisAccessControlListType addAces, CmisAccessControlListType removeAces, Holder<CmisExtensionType> extension,
209 Holder<String> objectId ) throws CmisException
210 {
211 CmisService service = null;
212
213 try
214 {
215 service = getService( wsContext, repositoryId );
216
217 ExtensionsData extData = convertExtensionHolder( extension );
218
219 String id = service.createRelationship( repositoryId, convert( properties ), policies,
220 convert( addAces, null ), convert( removeAces, null ), extData );
221
222 if ( objectId != null )
223 {
224 objectId.value = id;
225 }
226
227 setExtensionValues( extData, extension );
228 }
229 catch ( Exception e )
230 {
231 throw convertException( e );
232 }
233 finally
234 {
235 closeService( service );
236 }
237 }
238
239 public void deleteContentStream( String repositoryId, Holder<String> objectId, Holder<String> changeToken,
240 Holder<CmisExtensionType> extension ) throws CmisException
241 {
242 CmisService service = null;
243
244 try
245 {
246 service = getService( wsContext, repositoryId );
247
248 org.apache.chemistry.opencmis.commons.spi.Holder<String> objectIdHolder = convertHolder( objectId );
249 org.apache.chemistry.opencmis.commons.spi.Holder<String> changeTokenHolder = convertHolder( changeToken );
250 ExtensionsData extData = convertExtensionHolder( extension );
251
252 service.deleteContentStream( repositoryId, objectIdHolder, changeTokenHolder, extData );
253
254 setHolderValue( objectIdHolder, objectId );
255 setHolderValue( changeTokenHolder, changeToken );
256 setExtensionValues( extData, extension );
257 }
258 catch ( Exception e )
259 {
260 throw convertException( e );
261 }
262 finally
263 {
264 closeService( service );
265 }
266 }
267
268 public void deleteObject( String repositoryId, String objectId, Boolean allVersions,
269 Holder<CmisExtensionType> extension ) throws CmisException
270 {
271 CmisService service = null;
272
273 try
274 {
275 service = getService( wsContext, repositoryId );
276
277 ExtensionsData extData = convertExtensionHolder( extension );
278
279 service.deleteObjectOrCancelCheckOut( repositoryId, objectId, allVersions, extData );
280
281 setExtensionValues( extData, extension );
282 }
283 catch ( Exception e )
284 {
285 throw convertException( e );
286 }
287 finally
288 {
289 closeService( service );
290 }
291 }
292
293 public FailedToDelete deleteTree( String repositoryId, String folderId, Boolean allVersions,
294 EnumUnfileObject unfileObjects, Boolean continueOnFailure, CmisExtensionType extension )
295 throws CmisException
296 {
297 CmisService service = null;
298
299 try
300 {
301 service = getService( wsContext, repositoryId );
302
303 return convert( service.deleteTree( repositoryId, folderId, allVersions,
304 convert( UnfileObject.class, unfileObjects ), continueOnFailure, convert( extension ) ) );
305 }
306 catch ( Exception e )
307 {
308 throw convertException( e );
309 }
310 finally
311 {
312 closeService( service );
313 }
314 }
315
316 public CmisAllowableActionsType getAllowableActions( String repositoryId, String objectId,
317 CmisExtensionType extension ) throws CmisException
318 {
319 CmisService service = null;
320
321 try
322 {
323 service = getService( wsContext, repositoryId );
324
325 return convert( service.getAllowableActions( repositoryId, objectId, convert( extension ) ) );
326 }
327 catch ( Exception e )
328 {
329 throw convertException( e );
330 }
331 finally
332 {
333 closeService( service );
334 }
335 }
336
337 public CmisContentStreamType getContentStream( String repositoryId, String objectId, String streamId,
338 BigInteger offset, BigInteger length, CmisExtensionType extension )
339 throws CmisException
340 {
341 CmisService service = null;
342
343 try
344 {
345 service = getService( wsContext, repositoryId );
346
347 return convert( service.getContentStream( repositoryId, objectId, streamId, offset, length,
348 convert( extension ) ) );
349 }
350 catch ( Exception e )
351 {
352 throw convertException( e );
353 }
354 finally
355 {
356 closeService( service );
357 }
358 }
359
360 public CmisObjectType getObject( String repositoryId, String objectId, String filter,
361 Boolean includeAllowableActions, EnumIncludeRelationships includeRelationships, String renditionFilter,
362 Boolean includePolicyIds, Boolean includeAcl, CmisExtensionType extension )
363 throws CmisException
364 {
365 CmisService service = null;
366
367 try
368 {
369 service = getService( wsContext, repositoryId );
370
371 return convert( service.getObject( repositoryId, objectId, filter, includeAllowableActions,
372 convert( IncludeRelationships.class, includeRelationships ), renditionFilter, includePolicyIds,
373 includeAcl, convert( extension ) ) );
374 }
375 catch ( Exception e )
376 {
377 throw convertException( e );
378 }
379 finally
380 {
381 closeService( service );
382 }
383 }
384
385 public CmisObjectType getObjectByPath( String repositoryId, String path, String filter,
386 Boolean includeAllowableActions, EnumIncludeRelationships includeRelationships, String renditionFilter,
387 Boolean includePolicyIds, Boolean includeAcl, CmisExtensionType extension )
388 throws CmisException
389 {
390 CmisService service = null;
391
392 try
393 {
394 service = getService( wsContext, repositoryId );
395
396 return convert( service.getObjectByPath( repositoryId, path, filter, includeAllowableActions,
397 convert( IncludeRelationships.class, includeRelationships ), renditionFilter, includePolicyIds,
398 includeAcl, convert( extension ) ) );
399 }
400 catch ( Exception e )
401 {
402 throw convertException( e );
403 }
404 finally
405 {
406 closeService( service );
407 }
408 }
409
410 public CmisPropertiesType getProperties( String repositoryId, String objectId, String filter,
411 CmisExtensionType extension ) throws CmisException
412 {
413 CmisService service = null;
414
415 try
416 {
417 service = getService( wsContext, repositoryId );
418
419 return convert( service.getProperties( repositoryId, objectId, filter, convert( extension ) ) );
420 }
421 catch ( Exception e )
422 {
423 throw convertException( e );
424 }
425 finally
426 {
427 closeService( service );
428 }
429 }
430
431 public List<CmisRenditionType> getRenditions( String repositoryId, String objectId, String renditionFilter,
432 BigInteger maxItems, BigInteger skipCount, CmisExtensionType extension )
433 throws CmisException
434 {
435 CmisService service = null;
436
437 try
438 {
439 service = getService( wsContext, repositoryId );
440
441 List<CmisRenditionType> result = new ArrayList<CmisRenditionType>( );
442
443 List<RenditionData> renditionList = service.getRenditions( repositoryId, objectId, renditionFilter,
444 maxItems, skipCount, convert( extension ) );
445
446 if ( renditionList != null )
447 {
448 for ( RenditionData rendition : renditionList )
449 {
450 result.add( convert( rendition ) );
451 }
452 }
453
454 return result;
455 }
456 catch ( Exception e )
457 {
458 throw convertException( e );
459 }
460 finally
461 {
462 closeService( service );
463 }
464 }
465
466 public void moveObject( String repositoryId, Holder<String> objectId, String targetFolderId, String sourceFolderId,
467 Holder<CmisExtensionType> extension ) throws CmisException
468 {
469 CmisService service = null;
470
471 try
472 {
473 service = getService( wsContext, repositoryId );
474
475 org.apache.chemistry.opencmis.commons.spi.Holder<String> objectIdHolder = convertHolder( objectId );
476 ExtensionsData extData = convertExtensionHolder( extension );
477
478 service.moveObject( repositoryId, objectIdHolder, targetFolderId, sourceFolderId, extData );
479
480 setHolderValue( objectIdHolder, objectId );
481 setExtensionValues( extData, extension );
482 }
483 catch ( Exception e )
484 {
485 throw convertException( e );
486 }
487 finally
488 {
489 closeService( service );
490 }
491 }
492
493 public void setContentStream( String repositoryId, Holder<String> objectId, Boolean overwriteFlag,
494 Holder<String> changeToken, CmisContentStreamType contentStream, Holder<CmisExtensionType> extension )
495 throws CmisException
496 {
497 CmisService service = null;
498
499 try
500 {
501 service = getService( wsContext, repositoryId );
502
503 org.apache.chemistry.opencmis.commons.spi.Holder<String> objectIdHolder = convertHolder( objectId );
504 org.apache.chemistry.opencmis.commons.spi.Holder<String> changeTokenHolder = convertHolder( changeToken );
505 ExtensionsData extData = convertExtensionHolder( extension );
506
507 service.setContentStream( repositoryId, objectIdHolder, overwriteFlag, changeTokenHolder,
508 convert( contentStream ), extData );
509
510 setHolderValue( objectIdHolder, objectId );
511 setHolderValue( changeTokenHolder, changeToken );
512 setExtensionValues( extData, extension );
513 }
514 catch ( Exception e )
515 {
516 throw convertException( e );
517 }
518 finally
519 {
520 closeService( service );
521 }
522 }
523
524 public void updateProperties( String repositoryId, Holder<String> objectId, Holder<String> changeToken,
525 CmisPropertiesType properties, Holder<CmisExtensionType> extension )
526 throws CmisException
527 {
528 CmisService service = null;
529
530 try
531 {
532 service = getService( wsContext, repositoryId );
533
534 org.apache.chemistry.opencmis.commons.spi.Holder<String> objectIdHolder = convertHolder( objectId );
535 org.apache.chemistry.opencmis.commons.spi.Holder<String> changeTokenHolder = convertHolder( changeToken );
536 ExtensionsData extData = convertExtensionHolder( extension );
537
538 service.updateProperties( repositoryId, objectIdHolder, changeTokenHolder, convert( properties ), extData );
539
540 setHolderValue( objectIdHolder, objectId );
541 setHolderValue( changeTokenHolder, changeToken );
542 setExtensionValues( extData, extension );
543 }
544 catch ( Exception e )
545 {
546 throw convertException( e );
547 }
548 finally
549 {
550 closeService( service );
551 }
552 }
553 }