KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > webservice > authoring > AuthoringWebService


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.webservice.authoring;
18
19 import java.io.ByteArrayInputStream JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.Serializable JavaDoc;
22 import java.rmi.RemoteException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import org.alfresco.model.ContentModel;
30 import org.alfresco.repo.transaction.TransactionUtil;
31 import org.alfresco.repo.webservice.AbstractWebService;
32 import org.alfresco.repo.webservice.Utils;
33 import org.alfresco.repo.webservice.types.ContentFormat;
34 import org.alfresco.repo.webservice.types.NamedValue;
35 import org.alfresco.repo.webservice.types.ParentReference;
36 import org.alfresco.repo.webservice.types.Predicate;
37 import org.alfresco.repo.webservice.types.Reference;
38 import org.alfresco.repo.webservice.types.VersionHistory;
39 import org.alfresco.service.cmr.coci.CheckOutCheckInService;
40 import org.alfresco.service.cmr.lock.LockService;
41 import org.alfresco.service.cmr.lock.LockType;
42 import org.alfresco.service.cmr.repository.ContentWriter;
43 import org.alfresco.service.cmr.repository.NodeRef;
44 import org.alfresco.service.cmr.version.Version;
45 import org.alfresco.service.cmr.version.VersionService;
46 import org.alfresco.service.namespace.QName;
47 import org.alfresco.service.transaction.TransactionService;
48 import org.apache.commons.logging.Log;
49 import org.apache.commons.logging.LogFactory;
50
51 /**
52  * Web service implementation of the AuthoringService. The WSDL for this service
53  * can be accessed from
54  * http://localhost:8080/alfresco/wsdl/authoring-service.wsdl
55  *
56  * @author gavinc
57  */

58 public class AuthoringWebService extends AbstractWebService implements
59         AuthoringServiceSoapPort
60 {
61     /**
62      * Logger
63      */

64     private static Log logger = LogFactory.getLog(AuthoringWebService.class);
65
66     /**
67      * The check in check out service
68      */

69     private CheckOutCheckInService cociService;
70     
71     /**
72      * The lock service
73      */

74     private LockService lockService;
75     
76     /**
77      * The version service
78      */

79     private VersionService versionService;
80
81     /**
82      * The transaction service
83      */

84     private TransactionService transactionService;
85
86     /**
87      * Sets the CheckInCheckOutService to use
88      *
89      * @param cociService
90      * The CheckInCheckOutService
91      */

92     public void setCheckOutCheckinService(CheckOutCheckInService cociService)
93     {
94         this.cociService = cociService;
95     }
96     
97     /**
98      * Sets the LockService to use
99      *
100      * @param lockService the lock service
101      */

102     public void setLockService(LockService lockService)
103     {
104         this.lockService = lockService;
105     }
106     
107     /**
108      * Set the version service
109      *
110      * @param versionService the version service
111      */

112     public void setVersionService(VersionService versionService)
113     {
114         this.versionService = versionService;
115     }
116
117     /**
118      * Set the transaction service
119      *
120      * @param transactionService
121      * the transaction service
122      */

123     public void setTransactionService(TransactionService transactionService)
124     {
125         this.transactionService = transactionService;
126     }
127
128     /**
129      * @see org.alfresco.repo.webservice.authoring.AuthoringServiceSoapPort#checkout(org.alfresco.repo.webservice.types.Predicate,
130      * org.alfresco.repo.webservice.types.ParentReference)
131      */

132     public CheckoutResult checkout(final Predicate items, final ParentReference destination) throws RemoteException JavaDoc,
133             AuthoringFault
134     {
135         try
136         {
137             return TransactionUtil.executeInUserTransaction(
138                     this.transactionService,
139                     new TransactionUtil.TransactionWork<CheckoutResult>()
140                     {
141                         public CheckoutResult doWork()
142                         {
143                             List JavaDoc<NodeRef> nodes = Utils.resolvePredicate(items,
144                                     AuthoringWebService.this.nodeService,
145                                     AuthoringWebService.this.searchService,
146                                     AuthoringWebService.this.namespaceService);
147                             CheckoutResult checkoutResult = new CheckoutResult();
148                             Reference[] originals = new Reference[nodes.size()];
149                             Reference[] workingCopies = new Reference[nodes.size()];
150     
151                             // get a repository NodeRef for the destination (if
152
// there is one)
153
NodeRef destinationRef = null;
154                             if (destination != null)
155                             {
156                                 destinationRef = Utils.convertToNodeRef(
157                                         destination,
158                                         AuthoringWebService.this.nodeService,
159                                         AuthoringWebService.this.searchService,
160                                         AuthoringWebService.this.namespaceService);
161                             }
162     
163                             for (int x = 0; x < nodes.size(); x++)
164                             {
165                                 // get the current node
166
NodeRef original = nodes.get(x);
167     
168                                 // call the appropriate service method depending on
169
// whether a destination has been provided
170
NodeRef workingCopy = null;
171                                 if (destinationRef != null)
172                                 {
173                                      workingCopy = AuthoringWebService.this.cociService
174                                             .checkout(
175                                                     original,
176                                                     destinationRef,
177                                                     QName.createQName(destination.getAssociationType()),
178                                                     QName.createQName(destination.getChildName()));
179                                 } else
180                                 {
181                                     workingCopy = AuthoringWebService.this.cociService
182                                             .checkout(original);
183                                 }
184     
185                                 // store the results
186
originals[x] = Utils.convertToReference(original);
187                                 workingCopies[x] = Utils.convertToReference(workingCopy);
188                             }
189     
190                             // setup the result object
191
checkoutResult.setOriginals(originals);
192                             checkoutResult.setWorkingCopies(workingCopies);
193     
194                             return checkoutResult;
195                         }
196                     });
197         }
198         catch (Throwable JavaDoc e)
199         {
200            if (logger.isDebugEnabled())
201            {
202               logger.error("Unexpected error occurred", e);
203            }
204          
205            throw new AuthoringFault(0, e.getMessage());
206         }
207     }
208
209     /**
210      * @see org.alfresco.repo.webservice.authoring.AuthoringServiceSoapPort#checkin(org.alfresco.repo.webservice.types.Predicate,
211      * org.alfresco.repo.webservice.types.NamedValue[], boolean)
212      */

213     public CheckinResult checkin(final Predicate items,
214             final NamedValue[] comments, final boolean keepCheckedOut)
215             throws RemoteException JavaDoc, AuthoringFault
216     {
217         try
218         {
219             return TransactionUtil.executeInUserTransaction(
220                     this.transactionService,
221                     new TransactionUtil.TransactionWork<CheckinResult>()
222                     {
223                         public CheckinResult doWork()
224                         {
225                             // Get the passed nodes
226
List JavaDoc<NodeRef> nodes = Utils.resolvePredicate(
227                                     items,
228                                     AuthoringWebService.this.nodeService,
229                                     AuthoringWebService.this.searchService,
230                                     AuthoringWebService.this.namespaceService);
231     
232                             // Map the comments into the expected map
233
Map JavaDoc<String JavaDoc, Serializable JavaDoc> mapComments = new HashMap JavaDoc<String JavaDoc, Serializable JavaDoc>(comments.length);
234                             for (NamedValue value : comments)
235                             {
236                                 mapComments.put(value.getName(), value.getValue());
237                             }
238                             
239                             Reference[] checkedIn = new Reference[nodes.size()];
240                             List JavaDoc<Reference> listWorkingCopies = new ArrayList JavaDoc<Reference>(nodes.size());
241                             int iIndex = 0;
242     
243                             // Execute checkin for each node
244
// TODO should be able to do this as a batch so that all the nodes are versioned together
245
for (NodeRef node : nodes)
246                             {
247                                 // Checkin the node
248
NodeRef checkedInNode = AuthoringWebService.this.cociService.checkin(node, mapComments, null, keepCheckedOut);
249                                 
250                                 // Add the results to the array
251
checkedIn[iIndex] = Utils.convertToReference(checkedInNode);
252                                 
253                                 // Only return the working copies if the node is keep checked out otherwise the working copies have been deleted
254
if (keepCheckedOut == true)
255                                 {
256                                     listWorkingCopies.add(Utils.convertToReference(node));
257                                 }
258                                 iIndex++;
259                             }
260                             
261                             // Sort out the working copy list
262
Reference[] workingCopies = listWorkingCopies.toArray(new Reference[listWorkingCopies.size()]);
263                             if (workingCopies == null)
264                             {
265                                 workingCopies = new Reference[0];
266                             }
267                             
268                             // Create the result object
269
CheckinResult result = new CheckinResult();
270                             result.setCheckedIn(checkedIn);
271                             result.setWorkingCopies(workingCopies);
272                             
273                             return result;
274                         }
275                     });
276         }
277         catch (Throwable JavaDoc e)
278         {
279            if (logger.isDebugEnabled())
280            {
281               logger.error("Unexpected error occurred", e);
282            }
283          
284            throw new AuthoringFault(0, e.getMessage());
285         }
286     }
287
288     /**
289      * @see org.alfresco.repo.webservice.authoring.AuthoringServiceSoapPort#checkinExternal(org.alfresco.repo.webservice.types.Reference, org.alfresco.repo.webservice.types.NamedValue[], boolean, org.alfresco.repo.webservice.types.ContentFormat, byte[])
290      */

291     public Reference checkinExternal(final Reference node, final NamedValue[] comments, final boolean keepCheckedOut, final ContentFormat format, final byte[] content)
292             throws RemoteException JavaDoc, AuthoringFault
293     {
294         try
295         {
296             return TransactionUtil.executeInUserTransaction(
297                     this.transactionService,
298                     new TransactionUtil.TransactionWork<Reference>()
299                     {
300                         public Reference doWork()
301                         {
302                             // Get the passed nodes
303
NodeRef nodeRef = Utils.convertToNodeRef(
304                                     node,
305                                     AuthoringWebService.this.nodeService,
306                                     AuthoringWebService.this.searchService,
307                                     AuthoringWebService.this.namespaceService);
308                             
309                             // Write the content to the server
310
// TODO: Need to get the property QName into this method
311
ContentWriter contentWriter = AuthoringWebService.this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, false);
312                             if (contentWriter == null)
313                             {
314                                 throw new RuntimeException JavaDoc("Unable to write external content before checkin.");
315                             }
316                             InputStream JavaDoc is = new ByteArrayInputStream JavaDoc(content);
317                             contentWriter.setEncoding(format.getEncoding());
318                             contentWriter.setMimetype(format.getMimetype());
319                             contentWriter.putContent(is);
320                             String JavaDoc contentUrl = contentWriter.getContentUrl();
321                             
322                             // Get the version properties map
323
Map JavaDoc<String JavaDoc, Serializable JavaDoc> versionProperties = new HashMap JavaDoc<String JavaDoc, Serializable JavaDoc>(comments.length);
324                             for (NamedValue namedValue : comments)
325                             {
326                                 versionProperties.put(namedValue.getName(), namedValue.getValue());
327                             }
328                             
329                             // CheckIn the content
330
NodeRef origNodeRef = AuthoringWebService.this.cociService.checkin(
331                                                                         nodeRef,
332                                                                         versionProperties,
333                                                                         contentUrl,
334                                                                         keepCheckedOut);
335                             // Return the orig node ref
336
return Utils.convertToReference(origNodeRef);
337                         }
338                     });
339         }
340         catch (Throwable JavaDoc e)
341         {
342            if (logger.isDebugEnabled())
343            {
344               logger.error("Unexpected error occurred", e);
345            }
346          
347            throw new AuthoringFault(0, e.getMessage());
348         }
349     }
350
351     /**
352      * @see org.alfresco.repo.webservice.authoring.AuthoringServiceSoapPort#cancelCheckout(org.alfresco.repo.webservice.types.Predicate)
353      */

354     public CancelCheckoutResult cancelCheckout(final Predicate items)
355             throws RemoteException JavaDoc, AuthoringFault
356     {
357         try
358         {
359             return TransactionUtil.executeInUserTransaction(
360                     this.transactionService,
361                     new TransactionUtil.TransactionWork<CancelCheckoutResult>()
362                     {
363                         public CancelCheckoutResult doWork()
364                         {
365                             // Get the passed nodes
366
List JavaDoc<NodeRef> nodes = Utils.resolvePredicate(
367                                     items,
368                                     AuthoringWebService.this.nodeService,
369                                     AuthoringWebService.this.searchService,
370                                     AuthoringWebService.this.namespaceService);
371                             
372                             // Create the arrays to hold results
373
Reference[] origNodes = new Reference[nodes.size()];
374                             Reference[] workingCopies = new Reference[nodes.size()];
375                             int iIndex = 0;
376                             
377                             for (NodeRef node : nodes)
378                             {
379                                 // Cancel the checkout
380
NodeRef origNode = AuthoringWebService.this.cociService.cancelCheckout(node);
381                                 
382                                 // Set the value in the arrays
383
origNodes[iIndex] = Utils.convertToReference(origNode);
384                                 workingCopies[iIndex] = Utils.convertToReference(node);
385                                 iIndex ++;
386                             }
387                             
388                             CancelCheckoutResult result = new CancelCheckoutResult();
389                             result.setOriginals(origNodes);
390                             result.setWorkingCopies(workingCopies);
391                             
392                             return result;
393                         }
394                     });
395         }
396         catch (Throwable JavaDoc e)
397         {
398            if (logger.isDebugEnabled())
399            {
400               logger.error("Unexpected error occurred", e);
401            }
402          
403            throw new AuthoringFault(0, e.getMessage());
404         }
405     }
406
407     /**
408      * @see org.alfresco.repo.webservice.authoring.AuthoringServiceSoapPort#lock(org.alfresco.repo.webservice.types.Predicate,
409      * boolean, org.alfresco.repo.webservice.authoring.LockTypeEnum)
410      */

411     public Reference[] lock(final Predicate items, final boolean lockChildren, final LockTypeEnum lockType)
412             throws RemoteException JavaDoc, AuthoringFault
413     {
414         try
415         {
416             return TransactionUtil.executeInUserTransaction(
417                     this.transactionService,
418                     new TransactionUtil.TransactionWork<Reference[]>()
419                     {
420                         public Reference[] doWork()
421                         {
422                             // Get the passed nodes
423
List JavaDoc<NodeRef> nodes = Utils.resolvePredicate(
424                                     items,
425                                     AuthoringWebService.this.nodeService,
426                                     AuthoringWebService.this.searchService,
427                                     AuthoringWebService.this.namespaceService);
428                             
429                             // Gather together the results
430
Reference[] result = new Reference[nodes.size()];
431                             int iIndex = 0;
432                             for (NodeRef node : nodes)
433                             {
434                                 LockType convertedLockType = convertToLockType(lockType);
435                                 AuthoringWebService.this.lockService.lock(node, convertedLockType, 0, lockChildren);
436                                 result[iIndex] = Utils.convertToReference(node);
437                                 iIndex++;
438                             }
439                             
440                             return result;
441                         }
442                     });
443         }
444         catch (Throwable JavaDoc e)
445         {
446            if (logger.isDebugEnabled())
447            {
448               logger.error("Unexpected error occurred", e);
449            }
450            
451            throw new AuthoringFault(0, e.getMessage());
452         }
453     }
454     
455     /**
456      * Convert from the web service lock type to the Lock type enum value used by the service interface
457      *
458      * @param lockTypeEnum web service lock type value
459      * @return lock type enum value used by the service interface
460      */

461     private LockType convertToLockType(LockTypeEnum lockTypeEnum)
462     {
463         LockType lockType = null;
464         if (lockTypeEnum.equals(LockTypeEnum.write) == true)
465         {
466             lockType = LockType.WRITE_LOCK;
467         }
468         else
469         {
470             lockType = LockType.READ_ONLY_LOCK;
471         }
472         return lockType;
473     }
474
475     /**
476      * @see org.alfresco.repo.webservice.authoring.AuthoringServiceSoapPort#unlock(org.alfresco.repo.webservice.types.Predicate,
477      * boolean)
478      */

479     public Reference[] unlock(final Predicate items, final boolean unlockChildren)
480             throws RemoteException JavaDoc, AuthoringFault
481     {
482         try
483         {
484             return TransactionUtil.executeInUserTransaction(
485                     this.transactionService,
486                     new TransactionUtil.TransactionWork<Reference[]>()
487                     {
488                         public Reference[] doWork()
489                         {
490                             // Get the passed nodes
491
List JavaDoc<NodeRef> nodes = Utils.resolvePredicate(
492                                     items,
493                                     AuthoringWebService.this.nodeService,
494                                     AuthoringWebService.this.searchService,
495                                     AuthoringWebService.this.namespaceService);
496                             
497                             // Gather together the results
498
Reference[] result = new Reference[nodes.size()];
499                             int iIndex = 0;
500                             for (NodeRef node : nodes)
501                             {
502                                 AuthoringWebService.this.lockService.unlock(node, unlockChildren);
503                                 
504                                 result[iIndex] = Utils.convertToReference(node);
505                                 iIndex++;
506                             }
507                             
508                             return result;
509                         }
510                     });
511         }
512         catch (Throwable JavaDoc e)
513         {
514            if (logger.isDebugEnabled())
515            {
516               logger.error("Unexpected error occurred", e);
517            }
518          
519            throw new AuthoringFault(0, e.getMessage());
520         }
521     }
522
523     /**
524      * @see org.alfresco.repo.webservice.authoring.AuthoringServiceSoapPort#getLockStatus(org.alfresco.repo.webservice.types.Predicate)
525      */

526     public LockStatus[] getLockStatus(final Predicate items)
527             throws RemoteException JavaDoc, AuthoringFault
528     {
529         try
530         {
531             return TransactionUtil.executeInUserTransaction(
532                     this.transactionService,
533                     new TransactionUtil.TransactionWork<LockStatus[]>()
534                     {
535                         public LockStatus[] doWork()
536                         {
537                             // Get the passed nodes
538
List JavaDoc<NodeRef> nodes = Utils.resolvePredicate(
539                                     items,
540                                     AuthoringWebService.this.nodeService,
541                                     AuthoringWebService.this.searchService,
542                                     AuthoringWebService.this.namespaceService);
543                             
544                             // Gather together the results
545
LockStatus[] result = new LockStatus[nodes.size()];
546                             int iIndex = 0;
547                             for (NodeRef node : nodes)
548                             {
549                                 // Get the lock owner
550
String JavaDoc lockOwner = (String JavaDoc)AuthoringWebService.this.nodeService.getProperty(node, ContentModel.PROP_LOCK_OWNER);
551                                 
552                                 // Get the lock type
553
LockTypeEnum lockTypeEnum = convertFromLockType(AuthoringWebService.this.lockService.getLockType(node));
554     
555                                 LockStatus lockStatus = new LockStatus();
556                                 lockStatus.setLockOwner(lockOwner);
557                                 lockStatus.setLockType(lockTypeEnum);
558                                 lockStatus.setNode(Utils.convertToReference(node));
559                                 
560                                 result[iIndex] = lockStatus;
561                                 iIndex++;
562                             }
563                             
564                             return result;
565                         }
566                     });
567         }
568         catch (Throwable JavaDoc e)
569         {
570             
571            if (logger.isDebugEnabled())
572            {
573               logger.error("Unexpected error occurred", e);
574            }
575                     
576            e.printStackTrace();
577            throw new AuthoringFault(0, e.getMessage());
578         }
579     }
580     
581     private LockTypeEnum convertFromLockType(LockType lockType)
582     {
583         LockTypeEnum result = null;
584         if (lockType != null)
585         {
586             switch (lockType)
587             {
588                 case WRITE_LOCK:
589                     result = LockTypeEnum.write;
590                     break;
591                 case READ_ONLY_LOCK:
592                     result = LockTypeEnum.read;
593                     break;
594             }
595         }
596         return result;
597     }
598
599     /**
600      * @see org.alfresco.repo.webservice.authoring.AuthoringServiceSoapPort#createVersion(org.alfresco.repo.webservice.types.Predicate,
601      * org.alfresco.repo.webservice.types.NamedValue[], boolean)
602      */

603     public VersionResult createVersion(final Predicate items, final NamedValue[] comments, final boolean versionChildren)
604                 throws RemoteException JavaDoc, AuthoringFault
605     {
606         try
607         {
608             return TransactionUtil.executeInUserTransaction(
609                     this.transactionService,
610                     new TransactionUtil.TransactionWork<VersionResult>()
611                     {
612                         public VersionResult doWork()
613                         {
614                             // Get the passed nodes
615
List JavaDoc<NodeRef> nodes = Utils.resolvePredicate(
616                                     items,
617                                     AuthoringWebService.this.nodeService,
618                                     AuthoringWebService.this.searchService,
619                                     AuthoringWebService.this.namespaceService);
620                             
621                             // Map the comments into the expected map
622
Map JavaDoc<String JavaDoc, Serializable JavaDoc> mapComments = new HashMap JavaDoc<String JavaDoc, Serializable JavaDoc>(comments.length);
623                             for (NamedValue value : comments)
624                             {
625                                 mapComments.put(value.getName(), value.getValue());
626                             }
627                             
628                             List JavaDoc<Reference> versionedReferences = new ArrayList JavaDoc<Reference>(nodes.size());
629                             List JavaDoc<org.alfresco.repo.webservice.types.Version> webServiceVersions = new ArrayList JavaDoc<org.alfresco.repo.webservice.types.Version>(nodes.size());
630                             
631                             // Version each node
632
for (NodeRef node : nodes)
633                             {
634                                 Collection JavaDoc<Version> versions = AuthoringWebService.this.versionService.createVersion(node, mapComments, versionChildren);
635                                 for (Version version : versions)
636                                 {
637                                     versionedReferences.add(Utils.convertToReference(version.getVersionedNodeRef()));
638                                     webServiceVersions.add(Utils.convertToVersion(version));
639                                 }
640                             }
641                             
642                             VersionResult result = new VersionResult();
643                             result.setNodes(versionedReferences.toArray(new Reference[versionedReferences.size()]));
644                             result.setVersions(webServiceVersions.toArray(new org.alfresco.repo.webservice.types.Version[webServiceVersions.size()]));
645                             return result;
646                         }
647                     });
648         }
649         catch (Throwable JavaDoc e)
650         {
651            if (logger.isDebugEnabled())
652            {
653               logger.error("Unexpected error occurred", e);
654            }
655            
656            e.printStackTrace();
657          
658            throw new AuthoringFault(0, e.getMessage());
659         }
660     }
661
662     /**
663      * @see org.alfresco.repo.webservice.authoring.AuthoringServiceSoapPort#getVersionHistory(org.alfresco.repo.webservice.types.Reference)
664      */

665     public VersionHistory getVersionHistory(final Reference node)
666             throws RemoteException JavaDoc, AuthoringFault
667     {
668         try
669         {
670             return TransactionUtil.executeInUserTransaction(
671                     this.transactionService,
672                     new TransactionUtil.TransactionWork<VersionHistory>()
673                     {
674                         public VersionHistory doWork()
675                         {
676                             org.alfresco.service.cmr.version.VersionHistory versionHistory =
677                                 AuthoringWebService.this.versionService.getVersionHistory(
678                                                                             Utils.convertToNodeRef(
679                                                                                 node,
680                                                                                 AuthoringWebService.this.nodeService,
681                                                                                 AuthoringWebService.this.searchService,
682                                                                                 AuthoringWebService.this.namespaceService));
683                             
684                             VersionHistory webServiceVersionHistory = new VersionHistory();
685                             if (versionHistory != null)
686                             {
687                                 Collection JavaDoc<Version> versions = versionHistory.getAllVersions();
688                                 org.alfresco.repo.webservice.types.Version[] webServiceVersions = new org.alfresco.repo.webservice.types.Version[versions.size()];
689                                 int iIndex = 0;
690                                 for (Version version : versions)
691                                 {
692                                     webServiceVersions[iIndex] = Utils.convertToVersion(version);
693                                     iIndex ++;
694                                 }
695                                 webServiceVersionHistory.setVersions(webServiceVersions);
696                             }
697                             
698                             return webServiceVersionHistory;
699                         }
700                     });
701         }
702         catch (Throwable JavaDoc e)
703         {
704            if (logger.isDebugEnabled())
705            {
706               logger.error("Unexpected error occurred", e);
707            }
708          
709            throw new AuthoringFault(0, e.getMessage());
710         }
711     }
712
713     /**
714      * @see org.alfresco.repo.webservice.authoring.AuthoringServiceSoapPort#revertVersion(org.alfresco.repo.webservice.types.Reference,
715      * java.lang.String)
716      */

717     @SuppressWarnings JavaDoc("unchecked")
718     public void revertVersion(final Reference node, final String JavaDoc versionLabel)
719             throws RemoteException JavaDoc, AuthoringFault
720     {
721         try
722         {
723              TransactionUtil.executeInUserTransaction(
724                     this.transactionService,
725                     new TransactionUtil.TransactionWork()
726                     {
727                         public Object JavaDoc doWork()
728                         {
729                             NodeRef nodeRef = Utils.convertToNodeRef(
730                                                         node,
731                                                         AuthoringWebService.this.nodeService,
732                                                         AuthoringWebService.this.searchService,
733                                                         AuthoringWebService.this.namespaceService);
734                             
735                             org.alfresco.service.cmr.version.VersionHistory versionHistory = AuthoringWebService.this.versionService.getVersionHistory(nodeRef);
736                             if (versionHistory != null)
737                             {
738                                 Version version = versionHistory.getVersion(versionLabel);
739                                 if (version != null)
740                                 {
741                                     AuthoringWebService.this.versionService.revert(nodeRef, version);
742                                 }
743                                 else
744                                 {
745                                     throw new RuntimeException JavaDoc("The node could not be reverted because the version label is invalid.");
746                                 }
747                             }
748                             else
749                             {
750                                 throw new RuntimeException JavaDoc("A unversioned node cannot be reverted.");
751                             }
752                             
753                             return null;
754                         }
755                     });
756         }
757         catch (Throwable JavaDoc e)
758         {
759            if (logger.isDebugEnabled())
760            {
761               logger.error("Unexpected error occurred", e);
762            }
763          
764            throw new AuthoringFault(0, e.getMessage());
765         }
766     }
767
768     /**
769      * @see org.alfresco.repo.webservice.authoring.AuthoringServiceSoapPort#deleteAllVersions(org.alfresco.repo.webservice.types.Reference)
770      */

771     public VersionHistory deleteAllVersions(final Reference node)
772             throws RemoteException JavaDoc, AuthoringFault
773     {
774         try
775         {
776              return TransactionUtil.executeInUserTransaction(
777                     this.transactionService,
778                     new TransactionUtil.TransactionWork<VersionHistory>()
779                     {
780                         public VersionHistory doWork()
781                         {
782                             NodeRef nodeRef = Utils.convertToNodeRef(
783                                                         node,
784                                                         AuthoringWebService.this.nodeService,
785                                                         AuthoringWebService.this.searchService,
786                                                         AuthoringWebService.this.namespaceService);
787                             
788                             AuthoringWebService.this.versionService.deleteVersionHistory(nodeRef);
789                             
790                             return new VersionHistory();
791                         }
792                     });
793         }
794         catch (Throwable JavaDoc e)
795         {
796            if (logger.isDebugEnabled())
797            {
798               logger.error("Unexpected error occurred", e);
799            }
800          
801            throw new AuthoringFault(0, e.getMessage());
802         }
803     }
804 }
805
Popular Tags