View Javadoc
1   /*
2    * Copyright (c) 2002-2022, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.portal.service.workflow;
35  
36  import java.util.Collection;
37  import java.util.List;
38  import java.util.Locale;
39  import java.util.Map;
40  
41  import javax.servlet.http.HttpServletRequest;
42  
43  import org.apache.commons.lang3.StringUtils;
44  import org.springframework.beans.factory.BeanDefinitionStoreException;
45  import org.springframework.beans.factory.CannotLoadBeanClassException;
46  import org.springframework.beans.factory.NoSuchBeanDefinitionException;
47  
48  import fr.paris.lutece.api.user.User;
49  import fr.paris.lutece.plugins.workflowcore.business.action.Action;
50  import fr.paris.lutece.plugins.workflowcore.business.state.State;
51  import fr.paris.lutece.plugins.workflowcore.service.workflow.IWorkflowService;
52  import fr.paris.lutece.portal.business.event.ResourceEvent;
53  import fr.paris.lutece.portal.business.user.AdminUser;
54  import fr.paris.lutece.portal.service.event.ResourceEventManager;
55  import fr.paris.lutece.portal.service.plugin.PluginService;
56  import fr.paris.lutece.portal.service.spring.SpringContextService;
57  import fr.paris.lutece.portal.service.util.AppException;
58  import fr.paris.lutece.portal.service.util.AppLogService;
59  import fr.paris.lutece.util.ReferenceList;
60  import fr.paris.lutece.util.sql.TransactionManager;
61  
62  /**
63   *
64   * WorkflowService
65   *
66   */
67  public final class WorkflowService
68  {
69      private static final String PLUGIN_WORKFLOW_NAME = "workflow";
70      private static final String BEAN_WORKFLOW_PROVIDER = "workflow.workflowProvider";
71      private static WorkflowService _singleton;
72      private boolean _bServiceAvailable = true;
73      private IWorkflowService _service;
74      private IWorkflowProvider _provider;
75  
76      /**
77       * Private constructor
78       */
79      private WorkflowService( )
80      {
81          try
82          {
83              _service = SpringContextService.getBean( fr.paris.lutece.plugins.workflowcore.service.workflow.WorkflowService.BEAN_SERVICE );
84              _provider = SpringContextService.getBean( BEAN_WORKFLOW_PROVIDER );
85              _bServiceAvailable = ( _service != null ) && ( _provider != null );
86          }
87          catch( CannotLoadBeanClassException | NoSuchBeanDefinitionException | BeanDefinitionStoreException e )
88          {
89              _bServiceAvailable = false;
90          }
91      }
92  
93      /**
94       * Returns the unique instance of the service
95       * 
96       * @return The instance of the service
97       */
98      public static synchronized WorkflowService getInstance( )
99      {
100         if ( _singleton == null )
101         {
102             _singleton = new WorkflowService( );
103         }
104         return _singleton;
105     }
106 
107     /**
108      * Check if the workflow service is available. To be available, the following conditions must be verified :
109      * <ul>
110      * <li>the Bean service is not null</li>
111      * <li>the plugin-workflow must be enable</li>
112      * </ul>
113      * 
114      * @return true if the workflow service is available
115      */
116     public boolean isAvailable( )
117     {
118         // LUTECE-1273 : Condition ( _service != null && _provider != null ) in case the
119         // plugin-workflow is removed from a webapp
120         return _bServiceAvailable && ( _service != null ) && ( _provider != null ) && PluginService.isPluginEnable( PLUGIN_WORKFLOW_NAME );
121     }
122 
123     /**
124      * returns a list of actions possible for a given document based on the status of the document in the workflow and the user role
125      * 
126      * @param nIdResource
127      *            the document id
128      * @param strResourceType
129      *            the document type
130      * @param user
131      *            the adminUser
132      * @param nIdWorkflow
133      *            the workflow id
134      * @return a list of Action
135      */
136     public Collection<Action> getActions( int nIdResource, String strResourceType, int nIdWorkflow, User user )
137     {
138         if ( isAvailable( ) )
139         {
140             Collection<Action> listActions = _service.getActions( nIdResource, strResourceType, nIdWorkflow );
141 
142             return _provider.getActions( nIdResource, strResourceType, listActions, user );
143         }
144 
145         return null;
146     }
147 
148     /**
149      * returns a list of actions possible for a given document based on the status of the document in the workflow and the user role
150      * 
151      * @param nIdResource
152      *            the document id
153      * @param strResourceType
154      *            the document type
155      * @param user
156      *            the adminUser
157      * @param nIdWorkflow
158      *            the workflow id
159      * @return a list of Action
160      * @deprecated use getActions( int, String, int, User )
161      */
162     @Deprecated
163     public Collection<Action> getActions( int nIdResource, String strResourceType, int nIdWorkflow, AdminUser user )
164     {
165         return getActions( nIdResource, strResourceType, nIdWorkflow, (User) user );
166     }
167 
168     /**
169      * returns a list of actions possible for a given document based on the status of the document in the workflow and the user role
170      * 
171      * @param listIdResource
172      *            the list of resource id
173      * @param strResourceType
174      *            the document type
175      * @param nIdExternalParentId
176      *            the external parent identifier
177      * @param nIdWorkflow
178      *            the workflow id
179      * @param user
180      *            the User
181      * @return a list of Action
182      */
183     public Map<Integer, List<Action>> getActions( List<Integer> listIdResource, String strResourceType, Integer nIdExternalParentId, int nIdWorkflow,
184             User user )
185     {
186         if ( isAvailable( ) )
187         {
188             Map<Integer, List<Action>> mapActions = _service.getActions( listIdResource, strResourceType, nIdExternalParentId, nIdWorkflow );
189 
190             return _provider.getActions( strResourceType, mapActions, user );
191         }
192 
193         return null;
194     }
195 
196     /**
197      * returns a list of actions possible for a given document based on the status of the document in the workflow and the user role
198      * 
199      * @param listIdResource
200      *            the list of resource id
201      * @param strResourceType
202      *            the document type
203      * @param nIdExternalParentId
204      *            the external parent identifier
205      * @param nIdWorkflow
206      *            the workflow id
207      * @param user
208      *            the User
209      * @return a list of Action
210      * @deprecated getActions( List, String, Integer, int, User )
211      */
212     @Deprecated
213     public Map<Integer, List<Action>> getActions( List<Integer> listIdResource, String strResourceType, Integer nIdExternalParentId, int nIdWorkflow,
214             AdminUser user )
215     {
216         return getActions( listIdResource, strResourceType, nIdExternalParentId, nIdWorkflow, (User) user );
217     }
218 
219     /**
220      * return true if a form is associate to the action
221      *
222      * @param nIdAction
223      *            the action id
224      * @param locale
225      *            the loacle
226      * @return true if a form is associate to the action
227      */
228     public boolean isDisplayTasksForm( int nIdAction, Locale locale )
229     {
230         return isAvailable( ) && _service.isDisplayTasksForm( nIdAction, locale );
231     }
232 
233     /**
234      * Proceed action given in parameter
235      * 
236      * @param nIdResource
237      *            the resource id
238      * @param strResourceType
239      *            the resource type
240      * @param nIdAction
241      *            the action id
242      * @param nExternalParentId
243      *            the external parent id
244      * @param request
245      *            the request
246      * @param locale
247      *            locale
248      * @param bIsAutomatic
249      *            Is automatic
250      * @deprecated use doProcessAction( int, String, int, Integer, HttpServletRequest, Locale, boolean, User )
251      */
252     @Deprecated
253     public void doProcessAction( int nIdResource, String strResourceType, int nIdAction, Integer nExternalParentId, HttpServletRequest request, Locale locale,
254             boolean bIsAutomatic )
255     {
256         doProcessAction( nIdResource, strResourceType, nIdAction, nExternalParentId, request, locale, bIsAutomatic, null );
257     }
258 
259     /**
260      * Proceed action given in parameter
261      * 
262      * @param nIdResource
263      *            the resource id
264      * @param strResourceType
265      *            the resource type
266      * @param nIdAction
267      *            the action id
268      * @param nExternalParentId
269      *            the external parent id
270      * @param request
271      *            the request
272      * @param locale
273      *            locale
274      * @param bIsAutomatic
275      *            Is automatic
276      * @param user
277      *            The User
278      */
279     public void doProcessAction( int nIdResource, String strResourceType, int nIdAction, Integer nExternalParentId, HttpServletRequest request, Locale locale,
280             boolean bIsAutomatic, User user )
281     {
282         if ( isAvailable( ) && canProcessAction( nIdResource, strResourceType, nIdAction, nExternalParentId, request, bIsAutomatic, user ) )
283         {
284             TransactionManager.beginTransaction( null );
285 
286             try
287             {
288                 String strUserAccessCode = bIsAutomatic ? null : _provider.getUserAccessCode( request, user );
289                 _service.doProcessAction( nIdResource, strResourceType, nIdAction, nExternalParentId, request, locale, bIsAutomatic, strUserAccessCode, user );
290                 TransactionManager.commitTransaction( null );
291 
292                 registerResourceEvent( nIdResource, strResourceType );
293             }
294             catch( Exception e )
295             {
296                 TransactionManager.rollBack( null );
297                 throw new AppException( e.getMessage( ), e );
298             }
299         }
300     }
301 
302     /**
303      * returns the actions history performed on a resource
304      * 
305      * @param nIdResource
306      *            the resource id
307      * @param strResourceType
308      *            the resource type
309      * @param request
310      *            the request
311      * @param nIdWorkflow
312      *            the workflow id
313      * @param locale
314      *            the locale
315      * @return the history of actions performed on a resource
316      * @deprecated use getDisplayDocumentHistory( int, String, int, HttpServletRequest, Locale, User )
317      */
318     @Deprecated
319     public String getDisplayDocumentHistory( int nIdResource, String strResourceType, int nIdWorkflow, HttpServletRequest request, Locale locale )
320     {
321         return getDisplayDocumentHistory( nIdResource, strResourceType, nIdWorkflow, request, locale, null );
322     }
323 
324     /**
325      * returns the actions history performed on a resource
326      * 
327      * @param nIdResource
328      *            the resource id
329      * @param strResourceType
330      *            the resource type
331      * @param request
332      *            the request
333      * @param nIdWorkflow
334      *            the workflow id
335      * @param locale
336      *            the locale
337      * @param user
338      *            The User
339      * @return the history of actions performed on a resource
340      */
341     public String getDisplayDocumentHistory( int nIdResource, String strResourceType, int nIdWorkflow, HttpServletRequest request, Locale locale, User user )
342     {
343         return isAvailable( ) ? _provider.getDisplayDocumentHistory( nIdResource, strResourceType, nIdWorkflow, request, locale, user ) : null;
344     }
345 
346     /**
347      * returns the actions history performed on a resource
348      * 
349      * @param nIdResource
350      *            the resource id
351      * @param strResourceType
352      *            the resource type
353      * @param request
354      *            the request
355      * @param nIdWorkflow
356      *            the workflow id
357      * @param locale
358      *            the locale
359      * @param model
360      *            The model to add to the default model
361      * @param strTemplate
362      *            The template
363      * @return the history of actions performed on a resource
364      * @deprecated use getDisplayDocumentHistory( int, String, int, HttpServletRequest, Locale, Map, String, User )
365      */
366     @Deprecated
367     public String getDisplayDocumentHistory( int nIdResource, String strResourceType, int nIdWorkflow, HttpServletRequest request, Locale locale,
368             Map<String, Object> model, String strTemplate )
369     {
370         return getDisplayDocumentHistory( nIdResource, strResourceType, nIdWorkflow, request, locale, model, strTemplate, null );
371     }
372 
373     /**
374      * returns the actions history performed on a resource
375      * 
376      * @param nIdResource
377      *            the resource id
378      * @param strResourceType
379      *            the resource type
380      * @param request
381      *            the request
382      * @param nIdWorkflow
383      *            the workflow id
384      * @param locale
385      *            the locale
386      * @param model
387      *            The model to add to the default model
388      * @param strTemplate
389      *            The template
390      * @param user
391      *            The User
392      * @return the history of actions performed on a resource
393      */
394     public String getDisplayDocumentHistory( int nIdResource, String strResourceType, int nIdWorkflow, HttpServletRequest request, Locale locale,
395             Map<String, Object> model, String strTemplate, User user )
396     {
397         if ( !isAvailable( ) )
398         {
399             return null;
400         }
401         try
402         {
403             return _provider.getDisplayDocumentHistory( nIdResource, strResourceType, nIdWorkflow, request, locale, model, strTemplate, user );
404         }
405         catch( NoSuchMethodError ex )
406         {
407             AppLogService.error( "You are using a too old Workflow provider version. Please upgrade." );
408             return _provider.getDisplayDocumentHistory( nIdResource, strResourceType, nIdWorkflow, request, locale, user );
409         }
410     }
411 
412     /**
413      * Perform the information on the various tasks associated with the given action specified in parameter
414      * 
415      * @param nIdResource
416      *            the resource id
417      * @param strResourceType
418      *            the resource type
419      * @param nExternalParentId
420      *            the external parent id
421      * @param request
422      *            the request
423      * @param nIdAction
424      *            the action id
425      * @param locale
426      *            the locale
427      * @return null if there is no error in the task form else return the error message url
428      * @deprecated use doSaveTasksForm( int, String, int, Integer, HttpServletRequest, Locale, User )
429      */
430     @Deprecated
431     public String doSaveTasksForm( int nIdResource, String strResourceType, int nIdAction, Integer nExternalParentId, HttpServletRequest request,
432             Locale locale )
433     {
434         return doSaveTasksForm( nIdResource, strResourceType, nIdAction, nExternalParentId, request, locale, null );
435     }
436 
437     /**
438      * Perform the information on the various tasks associated with the given action specified in parameter
439      * 
440      * @param nIdResource
441      *            the resource id
442      * @param strResourceType
443      *            the resource type
444      * @param nExternalParentId
445      *            the external parent id
446      * @param request
447      *            the request
448      * @param nIdAction
449      *            the action id
450      * @param locale
451      *            the locale
452      * @param user
453      *            the user
454      * @return null if there is no error in the task form else return the error message url
455      */
456     public String doSaveTasksForm( int nIdResource, String strResourceType, int nIdAction, Integer nExternalParentId, HttpServletRequest request, Locale locale,
457             User user )
458     {
459         if ( isAvailable( ) )
460         {
461             String strError = _provider.doValidateTasksForm( nIdResource, strResourceType, nIdAction, request, locale, user );
462 
463             if ( StringUtils.isNotBlank( strError ) )
464             {
465                 return strError;
466             }
467 
468             doProcessAction( nIdResource, strResourceType, nIdAction, nExternalParentId, request, locale, false, user );
469         }
470 
471         return null;
472     }
473 
474     /**
475      * Get the list of ids of resources of a given type that are in a given state
476      * 
477      * @param nIdState
478      *            The id of the state of resources to get
479      * @param strResourceType
480      *            The type of resources to get
481      * @return The list of resources matching both given state id and resource given. Return an empty list if no resource was found, or if the state does not
482      *         exist.
483      */
484     public List<Integer> getResourceIdListByIdState( int nIdState, String strResourceType )
485     {
486         if ( isAvailable( ) )
487         {
488             return _service.getResourceIdListByIdState( nIdState, strResourceType );
489         }
490 
491         return null;
492     }
493 
494     /**
495      * Remove in every workflows the resource specified in parameter
496      * 
497      * @param nIdResource
498      *            the resource id
499      * @param strResourceType
500      *            the resource type
501      */
502     public void doRemoveWorkFlowResource( int nIdResource, String strResourceType )
503     {
504         if ( isAvailable( ) )
505         {
506             TransactionManager.beginTransaction( null );
507 
508             try
509             {
510                 _service.doRemoveWorkFlowResource( nIdResource, strResourceType );
511                 TransactionManager.commitTransaction( null );
512             }
513             catch( Exception e )
514             {
515                 TransactionManager.rollBack( null );
516                 throw new AppException( e.getMessage( ), e );
517             }
518         }
519     }
520 
521     /**
522      * Remove list of resource workflow by list id
523      * 
524      * @param lListIdResource
525      *            list of id resource
526      * @param strResourceType
527      *            the ressource type
528      * @param nIdWorflow
529      *            the workflow id
530      */
531     public void doRemoveWorkFlowResourceByListId( List<Integer> lListIdResource, String strResourceType, Integer nIdWorflow )
532     {
533         if ( isAvailable( ) )
534         {
535             TransactionManager.beginTransaction( null );
536 
537             try
538             {
539                 _service.doRemoveWorkFlowResourceByListId( lListIdResource, strResourceType, nIdWorflow );
540                 TransactionManager.commitTransaction( null );
541             }
542             catch( Exception e )
543             {
544                 TransactionManager.rollBack( null );
545                 throw new AppException( e.getMessage( ), e );
546             }
547         }
548     }
549 
550     /**
551      * returns the tasks form
552      * 
553      * @param nIdResource
554      *            the document id
555      * @param strResourceType
556      *            the document type
557      * @param request
558      *            the request
559      * @param nIdAction
560      *            the action id
561      * @param locale
562      *            the locale
563      * @return the tasks form associated to the action
564      *
565      * @deprecated use getDisplayTasksForm( int, String, int, HttpServletRequest, Locale, User )
566      */
567     @Deprecated
568     public String getDisplayTasksForm( int nIdResource, String strResourceType, int nIdAction, HttpServletRequest request, Locale locale )
569     {
570         return getDisplayTasksForm( nIdResource, strResourceType, nIdAction, request, locale, null );
571 
572     }
573 
574     /**
575      * returns the tasks form
576      * 
577      * @param nIdResource
578      *            the document id
579      * @param strResourceType
580      *            the document type
581      * @param request
582      *            the request
583      * @param nIdAction
584      *            the action id
585      * @param locale
586      *            the locale
587      * @param user
588      *            the user
589      * @return the tasks form associated to the action
590      *
591      */
592     public String getDisplayTasksForm( int nIdResource, String strResourceType, int nIdAction, HttpServletRequest request, Locale locale, User user )
593     {
594         return isAvailable( ) ? _provider.getDisplayTasksForm( nIdResource, strResourceType, nIdAction, request, locale, user ) : null;
595     }
596 
597     /**
598      * Check that a given user is allowed to view a resource depending the state of the resource
599      * 
600      * @param nIdResource
601      *            the document id
602      * @param strResourceType
603      *            the document type
604      * @param user
605      *            the User
606      * @param nIdWorkflow
607      *            the workflow id
608      * @return a list of Action
609      */
610     public boolean isAuthorized( int nIdResource, String strResourceType, int nIdWorkflow, User user )
611     {
612         return isAvailable( ) && _provider.isAuthorized( nIdResource, strResourceType, nIdWorkflow, user );
613     }
614 
615     /**
616      * Check that a given user is allowed to view a resource depending the state of the resource
617      * 
618      * @param nIdResource
619      *            the document id
620      * @param strResourceType
621      *            the document type
622      * @param user
623      *            the User
624      * @param nIdWorkflow
625      *            the workflow id
626      * @return a list of Action
627      * @deprecated use isAuthorized( int, String, int, User )
628      */
629     @Deprecated
630     public boolean isAuthorized( int nIdResource, String strResourceType, int nIdWorkflow, AdminUser user )
631     {
632         return isAuthorized( nIdResource, strResourceType, nIdWorkflow, (User) user );
633     }
634 
635     /**
636      * Get all authorized resource Id
637      * 
638      * @param strResourceType
639      *            the resource type
640      * @param nIdWorkflow
641      *            the workflow id
642      * @param nIdWorkflowState
643      *            The workflow state id or -1 for all workflow states
644      * @param nExternalParentId
645      *            The external parent id
646      * @param user
647      *            the User
648      * @return a list resource id
649      */
650     public List<Integer> getAuthorizedResourceList( String strResourceType, int nIdWorkflow, int nIdWorkflowState, Integer nExternalParentId, User user )
651     {
652         return isAvailable( ) ? _provider.getAuthorizedResourceList( strResourceType, nIdWorkflow, nIdWorkflowState, nExternalParentId, user ) : null;
653     }
654 
655     /**
656      * Get all authorized resource Id
657      * 
658      * @param strResourceType
659      *            the resource type
660      * @param nIdWorkflow
661      *            the workflow id
662      * @param nIdWorkflowState
663      *            The workflow state id or -1 for all workflow states
664      * @param nExternalParentId
665      *            The external parent id
666      * @param user
667      *            the User
668      * @return a list resource id
669      * @deprecated use getAuthorizedResourceList( String, int, int, Integer, User )
670      */
671     @Deprecated
672     public List<Integer> getAuthorizedResourceList( String strResourceType, int nIdWorkflow, int nIdWorkflowState, Integer nExternalParentId, AdminUser user )
673     {
674         return getAuthorizedResourceList( strResourceType, nIdWorkflow, nIdWorkflowState, nExternalParentId, (User) user );
675 
676     }
677 
678     /**
679      * Get all authorized resource Id by list of state
680      * 
681      * @param strResourceType
682      *            the resource type
683      * @param nIdWorkflow
684      *            the workflow id
685      * @param lListIdWorkflowState
686      *            The workflow state <b>id or null</b> for all workflow states
687      * @param nExternalParentId
688      *            the externbal parent identifier
689      * @param user
690      *            the User
691      * @return a list resource id
692      */
693     public List<Integer> getAuthorizedResourceList( String strResourceType, int nIdWorkflow, List<Integer> lListIdWorkflowState, Integer nExternalParentId,
694             User user )
695     {
696         return isAvailable( ) ? _provider.getAuthorizedResourceList( strResourceType, nIdWorkflow, lListIdWorkflowState, nExternalParentId, user ) : null;
697     }
698 
699     /**
700      * Get all authorized resource Id by list of state
701      * 
702      * @param strResourceType
703      *            the resource type
704      * @param nIdWorkflow
705      *            the workflow id
706      * @param lListIdWorkflowState
707      *            The workflow state <b>id or null</b> for all workflow states
708      * @param nExternalParentId
709      *            the externbal parent identifier
710      * @param user
711      *            the User
712      * @return a list resource id
713      * @deprecated use getAuthorizedResourceList( String, int, List, Integer, User )
714      */
715     @Deprecated
716     public List<Integer> getAuthorizedResourceList( String strResourceType, int nIdWorkflow, List<Integer> lListIdWorkflowState, Integer nExternalParentId,
717             AdminUser user )
718     {
719         return getAuthorizedResourceList( strResourceType, nIdWorkflow, lListIdWorkflowState, nExternalParentId, (User) user );
720     }
721 
722     /**
723      * return a reference list which contains a list enabled workflow
724      * 
725      * @param user
726      *            the User
727      * @param locale
728      *            the locale
729      * @return a reference list which contains a list enabled workflow
730      */
731     public ReferenceList getWorkflowsEnabled( User user, Locale locale )
732     {
733         return isAvailable( ) ? _provider.getWorkflowsEnabled( user, locale ) : null;
734     }
735 
736     /**
737      * return a reference list which contains a list enabled workflow
738      * 
739      * @param user
740      *            the User
741      * @param locale
742      *            the locale
743      * @return a reference list which contains a list enabled workflow
744      * @deprecated use getWorkflowsEnabled( User, Locale )
745      */
746     @Deprecated
747     public ReferenceList getWorkflowsEnabled( AdminUser user, Locale locale )
748     {
749         return getWorkflowsEnabled( (User) user, locale );
750     }
751 
752     /**
753      * returns all state of a given workflow
754      * 
755      * @param user
756      *            the user
757      * @param nIdWorkflow
758      *            the workflow id
759      * @return the state of a given document
760      */
761     public Collection<State> getAllStateByWorkflow( int nIdWorkflow, User user )
762     {
763         if ( isAvailable( ) )
764         {
765             Collection<State> listStates = _service.getAllStateByWorkflow( nIdWorkflow );
766 
767             return _provider.getAllStateByWorkflow( listStates, user );
768         }
769 
770         return null;
771     }
772 
773     /**
774      * returns all state of a given workflow
775      * 
776      * @param user
777      *            the adminUser
778      * @param nIdWorkflow
779      *            the workflow id
780      * @return the state of a given document
781      * @deprecated use getAllStateByWorkflow( int, User )
782      */
783     @Deprecated
784     public Collection<State> getAllStateByWorkflow( int nIdWorkflow, AdminUser user )
785     {
786         return getAllStateByWorkflow( nIdWorkflow, (User) user );
787     }
788 
789     /**
790      * returns the state of a given document of the document in the workflow and the user role
791      * 
792      * @param nIdResource
793      *            the document id
794      * @param strResourceType
795      *            the document type
796      * @param nIdWorkflow
797      *            the workflow id
798      * @param nIdExternalParentId
799      *            the external parent id
800      * @return the state of a given document
801      */
802     public State getState( int nIdResource, String strResourceType, int nIdWorkflow, Integer nIdExternalParentId )
803     {
804         if ( isAvailable( ) )
805         {
806             State state = null;
807             TransactionManager.beginTransaction( null );
808 
809             try
810             {
811                 state = _service.getState( nIdResource, strResourceType, nIdWorkflow, nIdExternalParentId );
812                 TransactionManager.commitTransaction( null );
813             }
814             catch( Exception e )
815             {
816                 TransactionManager.rollBack( null );
817                 throw new AppException( e.getMessage( ), e );
818             }
819 
820             return state;
821         }
822 
823         return null;
824     }
825 
826     /**
827      * Execute action automatic
828      * 
829      * @param nIdResource
830      *            the document id
831      * @param strResourceType
832      *            the document type
833      * @param nIdWorkflow
834      *            the workflow id
835      * @param nExternalParentId
836      *            the external parent id
837      * @deprecated use executeActionAutomatic( int, String, int, Integer, User )
838      */
839     @Deprecated
840     public void executeActionAutomatic( int nIdResource, String strResourceType, int nIdWorkflow, Integer nExternalParentId )
841     {
842         executeActionAutomatic( nIdResource, strResourceType, nIdWorkflow, nExternalParentId, null );
843     }
844 
845     /**
846      * Execute action automatic
847      * 
848      * @param nIdResource
849      *            the document id
850      * @param strResourceType
851      *            the document type
852      * @param nIdWorkflow
853      *            the workflow id
854      * @param nExternalParentId
855      *            the external parent id
856      * @param user
857      *            the user
858      */
859     public void executeActionAutomatic( int nIdResource, String strResourceType, int nIdWorkflow, Integer nExternalParentId, User user )
860     {
861         if ( isAvailable( ) )
862         {
863             TransactionManager.beginTransaction( null );
864 
865             try
866             {
867                 _service.executeActionAutomatic( nIdResource, strResourceType, nIdWorkflow, nExternalParentId, user );
868                 TransactionManager.commitTransaction( null );
869 
870                 registerResourceEvent( nIdResource, strResourceType );
871             }
872             catch( Exception e )
873             {
874                 TransactionManager.rollBack( null );
875                 throw new AppException( e.getMessage( ), e );
876             }
877         }
878     }
879 
880     /**
881      * Get the list of mass actions from a given id workflow
882      * 
883      * @param nIdWorkflow
884      *            the id workflow
885      * @return the list of mass actions
886      */
887     public List<Action> getMassActions( int nIdWorkflow )
888     {
889         return isAvailable( ) ? _service.getMassActions( nIdWorkflow ) : null;
890     }
891 
892     /**
893      * Get the list of mass actions from a given id workflow
894      * 
895      * @param nIdWorkflow
896      *            the id workflow
897      * @param nIdState
898      * @param user
899      * @return the list of mass actions
900      */
901     public Collection<Action> getMassActions( int nIdWorkflow, int nIdState, User user )
902     {
903         if ( !isAvailable( ) )
904         {
905             return null;
906         }
907 
908         Collection<Action> listActions = _service.getMassActions( nIdWorkflow, nIdState );
909 
910         return _provider.getAuthorizedActions( listActions, user );
911     }
912 
913     /**
914      * Check if the action can be proceed for the given resource
915      * 
916      * @param nIdResource
917      *            the id resource
918      * @param strResourceType
919      *            the resource type
920      * @param nIdAction
921      *            the id action
922      * @param nExternalParentId
923      *            the external parent id
924      * @param request
925      *            the HTTP request
926      * @param bIsAutomatic
927      *            is automatic action
928      * @return true if the action can proceed, false otherwise
929      * @deprecated use canProcessAction( int, String, int, Integer, HttpServletRequest, User )
930      */
931     @Deprecated
932     public boolean canProcessAction( int nIdResource, String strResourceType, int nIdAction, Integer nExternalParentId, HttpServletRequest request,
933             boolean bIsAutomatic )
934     {
935         return canProcessAction( nIdResource, strResourceType, nIdAction, nExternalParentId, request, bIsAutomatic, null );
936     }
937 
938     /**
939      * Check if the action can be proceed for the given resource
940      * 
941      * @param nIdResource
942      *            the id resource
943      * @param strResourceType
944      *            the resource type
945      * @param nIdAction
946      *            the id action
947      * @param nExternalParentId
948      *            the external parent id
949      * @param request
950      *            the HTTP request
951      * @param bIsAutomatic
952      *            is automatic action
953      * @param user
954      *            the RBACUser
955      * @return true if the action can proceed, false otherwise
956      */
957     public boolean canProcessAction( int nIdResource, String strResourceType, int nIdAction, Integer nExternalParentId, HttpServletRequest request,
958             boolean bIsAutomatic, User user )
959     {
960         if ( isAvailable( ) && _service.canProcessAction( nIdResource, strResourceType, nIdAction, nExternalParentId ) )
961         {
962             if ( bIsAutomatic )
963             {
964                 return true;
965             }
966 
967             return _provider.canProcessAction( nIdResource, strResourceType, nIdAction, request, user );
968         }
969 
970         return false;
971     }
972 
973     /**
974      * Proceed automatic reflexive actions of state given in parameter. This method should be called anytime a service changed the state of a resource without
975      * proceeding a workflow action
976      * 
977      * @param nIdResource
978      *            the resource id
979      * @param strResourceType
980      *            the resource type
981      * @param nIdState
982      *            the state of the resource id
983      * @param nIdExternalParent
984      *            the external parent id*
985      * @param locale
986      *            locale
987      * @deprecated use doProcessAutomaticReflexiveActions( int, String, int, Integer, Locale, User )
988      */
989     @Deprecated
990     public void doProcessAutomaticReflexiveActions( int nIdResource, String strResourceType, int nIdState, Integer nIdExternalParent, Locale locale )
991     {
992         doProcessAutomaticReflexiveActions( nIdResource, strResourceType, nIdState, nIdExternalParent, locale, null );
993     }
994 
995     /**
996      * Proceed automatic reflexive actions of state given in parameter. This method should be called anytime a service changed the state of a resource without
997      * proceeding a workflow action
998      * 
999      * @param nIdResource
1000      *            the resource id
1001      * @param strResourceType
1002      *            the resource type
1003      * @param nIdState
1004      *            the state of the resource id
1005      * @param nIdExternalParent
1006      *            the external parent id*
1007      * @param locale
1008      *            locale
1009      * @param user
1010      *            the user
1011      */
1012     public void doProcessAutomaticReflexiveActions( int nIdResource, String strResourceType, int nIdState, Integer nIdExternalParent, Locale locale, User user )
1013     {
1014         if ( isAvailable( ) )
1015         {
1016             TransactionManager.beginTransaction( null );
1017 
1018             try
1019             {
1020                 _service.doProcessAutomaticReflexiveActions( nIdResource, strResourceType, nIdState, nIdExternalParent, locale, user );
1021                 TransactionManager.commitTransaction( null );
1022 
1023                 registerResourceEvent( nIdResource, strResourceType );
1024             }
1025             catch( Exception e )
1026             {
1027                 TransactionManager.rollBack( null );
1028                 throw new AppException( e.getMessage( ), e );
1029             }
1030         }
1031     }
1032 
1033     /**
1034      * Create and process a ResourceEvent.
1035      * 
1036      * @param nIdResource
1037      * @param strResourceType
1038      */
1039     private void registerResourceEvent( int nIdResource, String strResourceType )
1040     {
1041         ResourceEventsourceEvent.html#ResourceEvent">ResourceEvent formResponseEvent = new ResourceEvent( );
1042         formResponseEvent.setIdResource( String.valueOf( nIdResource ) );
1043         formResponseEvent.setTypeResource( strResourceType );
1044 
1045         ResourceEventManager.fireUpdatedResource( formResponseEvent );
1046     }
1047 }