1 /*
2 * Copyright (c) 2002-2025, 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 * Get the list of ids of resources of a given type that are in a given state
496 * and have a specific external parent id
497 *
498 * @param nIdState
499 * The id of the state of resources to get
500 * @param strResourceType
501 * The type of resources to get
502 * @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
503 * exist.
504 */
505 public List<Integer> getResourceIdListByIdState( int nIdState, String strResourceType, int nExternalParentId )
506 {
507 if ( isAvailable( ) )
508 {
509 return _service.getResourceIdListByIdState( nIdState, strResourceType, nExternalParentId );
510 }
511
512 return null;
513 }
514
515
516 /**
517 * Remove in every workflows the resource specified in parameter
518 *
519 * @param nIdResource
520 * the resource id
521 * @param strResourceType
522 * the resource type
523 */
524 public void doRemoveWorkFlowResource( int nIdResource, String strResourceType )
525 {
526 if ( isAvailable( ) )
527 {
528 TransactionManager.beginTransaction( null );
529
530 try
531 {
532 _service.doRemoveWorkFlowResource( nIdResource, strResourceType );
533 TransactionManager.commitTransaction( null );
534 }
535 catch( Exception e )
536 {
537 TransactionManager.rollBack( null );
538 throw new AppException( e.getMessage( ), e );
539 }
540 }
541 }
542
543 /**
544 * Remove list of resource workflow by list id
545 *
546 * @param lListIdResource
547 * list of id resource
548 * @param strResourceType
549 * the ressource type
550 * @param nIdWorflow
551 * the workflow id
552 */
553 public void doRemoveWorkFlowResourceByListId( List<Integer> lListIdResource, String strResourceType, Integer nIdWorflow )
554 {
555 if ( isAvailable( ) )
556 {
557 TransactionManager.beginTransaction( null );
558
559 try
560 {
561 _service.doRemoveWorkFlowResourceByListId( lListIdResource, strResourceType, nIdWorflow );
562 TransactionManager.commitTransaction( null );
563 }
564 catch( Exception e )
565 {
566 TransactionManager.rollBack( null );
567 throw new AppException( e.getMessage( ), e );
568 }
569 }
570 }
571
572 /**
573 * returns the tasks form
574 *
575 * @param nIdResource
576 * the document id
577 * @param strResourceType
578 * the document type
579 * @param request
580 * the request
581 * @param nIdAction
582 * the action id
583 * @param locale
584 * the locale
585 * @return the tasks form associated to the action
586 *
587 * @deprecated use getDisplayTasksForm( int, String, int, HttpServletRequest, Locale, User )
588 */
589 @Deprecated
590 public String getDisplayTasksForm( int nIdResource, String strResourceType, int nIdAction, HttpServletRequest request, Locale locale )
591 {
592 return getDisplayTasksForm( nIdResource, strResourceType, nIdAction, request, locale, null );
593
594 }
595
596 /**
597 * returns the tasks form
598 *
599 * @param nIdResource
600 * the document id
601 * @param strResourceType
602 * the document type
603 * @param request
604 * the request
605 * @param nIdAction
606 * the action id
607 * @param locale
608 * the locale
609 * @param user
610 * the user
611 * @return the tasks form associated to the action
612 *
613 */
614 public String getDisplayTasksForm( int nIdResource, String strResourceType, int nIdAction, HttpServletRequest request, Locale locale, User user )
615 {
616 return isAvailable( ) ? _provider.getDisplayTasksForm( nIdResource, strResourceType, nIdAction, request, locale, user ) : null;
617 }
618
619 /**
620 * Check that a given user is allowed to view a resource depending the state of the resource
621 *
622 * @param nIdResource
623 * the document id
624 * @param strResourceType
625 * the document type
626 * @param user
627 * the User
628 * @param nIdWorkflow
629 * the workflow id
630 * @return a list of Action
631 */
632 public boolean isAuthorized( int nIdResource, String strResourceType, int nIdWorkflow, User user )
633 {
634 return isAvailable( ) && _provider.isAuthorized( nIdResource, strResourceType, nIdWorkflow, user );
635 }
636
637 /**
638 * Check that a given user is allowed to view a resource depending the state of the resource
639 *
640 * @param nIdResource
641 * the document id
642 * @param strResourceType
643 * the document type
644 * @param user
645 * the User
646 * @param nIdWorkflow
647 * the workflow id
648 * @return a list of Action
649 * @deprecated use isAuthorized( int, String, int, User )
650 */
651 @Deprecated
652 public boolean isAuthorized( int nIdResource, String strResourceType, int nIdWorkflow, AdminUser user )
653 {
654 return isAuthorized( nIdResource, strResourceType, nIdWorkflow, (User) user );
655 }
656
657 /**
658 * Get all authorized resource Id
659 *
660 * @param strResourceType
661 * the resource type
662 * @param nIdWorkflow
663 * the workflow id
664 * @param nIdWorkflowState
665 * The workflow state id or -1 for all workflow states
666 * @param nExternalParentId
667 * The external parent id
668 * @param user
669 * the User
670 * @return a list resource id
671 */
672 public List<Integer> getAuthorizedResourceList( String strResourceType, int nIdWorkflow, int nIdWorkflowState, Integer nExternalParentId, User user )
673 {
674 return isAvailable( ) ? _provider.getAuthorizedResourceList( strResourceType, nIdWorkflow, nIdWorkflowState, nExternalParentId, user ) : null;
675 }
676
677 /**
678 * Get all authorized resource Id
679 *
680 * @param strResourceType
681 * the resource type
682 * @param nIdWorkflow
683 * the workflow id
684 * @param nIdWorkflowState
685 * The workflow state id or -1 for all workflow states
686 * @param nExternalParentId
687 * The external parent id
688 * @param user
689 * the User
690 * @return a list resource id
691 * @deprecated use getAuthorizedResourceList( String, int, int, Integer, User )
692 */
693 @Deprecated
694 public List<Integer> getAuthorizedResourceList( String strResourceType, int nIdWorkflow, int nIdWorkflowState, Integer nExternalParentId, AdminUser user )
695 {
696 return getAuthorizedResourceList( strResourceType, nIdWorkflow, nIdWorkflowState, nExternalParentId, (User) user );
697
698 }
699
700 /**
701 * Get all authorized resource Id by list of state
702 *
703 * @param strResourceType
704 * the resource type
705 * @param nIdWorkflow
706 * the workflow id
707 * @param lListIdWorkflowState
708 * The workflow state <b>id or null</b> for all workflow states
709 * @param nExternalParentId
710 * the externbal parent identifier
711 * @param user
712 * the User
713 * @return a list resource id
714 */
715 public List<Integer> getAuthorizedResourceList( String strResourceType, int nIdWorkflow, List<Integer> lListIdWorkflowState, Integer nExternalParentId,
716 User user )
717 {
718 return isAvailable( ) ? _provider.getAuthorizedResourceList( strResourceType, nIdWorkflow, lListIdWorkflowState, nExternalParentId, user ) : null;
719 }
720
721 /**
722 * Get all authorized resource Id by list of state
723 *
724 * @param strResourceType
725 * the resource type
726 * @param nIdWorkflow
727 * the workflow id
728 * @param lListIdWorkflowState
729 * The workflow state <b>id or null</b> for all workflow states
730 * @param nExternalParentId
731 * the externbal parent identifier
732 * @param user
733 * the User
734 * @return a list resource id
735 * @deprecated use getAuthorizedResourceList( String, int, List, Integer, User )
736 */
737 @Deprecated
738 public List<Integer> getAuthorizedResourceList( String strResourceType, int nIdWorkflow, List<Integer> lListIdWorkflowState, Integer nExternalParentId,
739 AdminUser user )
740 {
741 return getAuthorizedResourceList( strResourceType, nIdWorkflow, lListIdWorkflowState, nExternalParentId, (User) user );
742 }
743
744 /**
745 * return a reference list which contains a list enabled workflow
746 *
747 * @param user
748 * the User
749 * @param locale
750 * the locale
751 * @return a reference list which contains a list enabled workflow
752 */
753 public ReferenceList getWorkflowsEnabled( User user, Locale locale )
754 {
755 return isAvailable( ) ? _provider.getWorkflowsEnabled( user, locale ) : null;
756 }
757
758 /**
759 * return a reference list which contains a list enabled workflow
760 *
761 * @param user
762 * the User
763 * @param locale
764 * the locale
765 * @return a reference list which contains a list enabled workflow
766 * @deprecated use getWorkflowsEnabled( User, Locale )
767 */
768 @Deprecated
769 public ReferenceList getWorkflowsEnabled( AdminUser user, Locale locale )
770 {
771 return getWorkflowsEnabled( (User) user, locale );
772 }
773
774 /**
775 * returns all state of a given workflow
776 *
777 * @param user
778 * the user
779 * @param nIdWorkflow
780 * the workflow id
781 * @return the state of a given document
782 */
783 public Collection<State> getAllStateByWorkflow( int nIdWorkflow, User user )
784 {
785 if ( isAvailable( ) )
786 {
787 Collection<State> listStates = _service.getAllStateByWorkflow( nIdWorkflow );
788
789 return _provider.getAllStateByWorkflow( listStates, user );
790 }
791
792 return null;
793 }
794
795 /**
796 * returns all state of a given workflow
797 *
798 * @param user
799 * the adminUser
800 * @param nIdWorkflow
801 * the workflow id
802 * @return the state of a given document
803 * @deprecated use getAllStateByWorkflow( int, User )
804 */
805 @Deprecated
806 public Collection<State> getAllStateByWorkflow( int nIdWorkflow, AdminUser user )
807 {
808 return getAllStateByWorkflow( nIdWorkflow, (User) user );
809 }
810
811 /**
812 * returns the state of a given document of the document in the workflow and the user role
813 *
814 * @param nIdResource
815 * the document id
816 * @param strResourceType
817 * the document type
818 * @param nIdWorkflow
819 * the workflow id
820 * @param nIdExternalParentId
821 * the external parent id
822 * @return the state of a given document
823 */
824 public State getState( int nIdResource, String strResourceType, int nIdWorkflow, Integer nIdExternalParentId )
825 {
826 if ( isAvailable( ) )
827 {
828 State state = null;
829 TransactionManager.beginTransaction( null );
830
831 try
832 {
833 state = _service.getState( nIdResource, strResourceType, nIdWorkflow, nIdExternalParentId );
834 TransactionManager.commitTransaction( null );
835 }
836 catch( Exception e )
837 {
838 TransactionManager.rollBack( null );
839 throw new AppException( e.getMessage( ), e );
840 }
841
842 return state;
843 }
844
845 return null;
846 }
847
848 /**
849 * Execute action automatic
850 *
851 * @param nIdResource
852 * the document id
853 * @param strResourceType
854 * the document type
855 * @param nIdWorkflow
856 * the workflow id
857 * @param nExternalParentId
858 * the external parent id
859 * @deprecated use executeActionAutomatic( int, String, int, Integer, User )
860 */
861 @Deprecated
862 public void executeActionAutomatic( int nIdResource, String strResourceType, int nIdWorkflow, Integer nExternalParentId )
863 {
864 executeActionAutomatic( nIdResource, strResourceType, nIdWorkflow, nExternalParentId, null );
865 }
866
867 /**
868 * Execute action automatic
869 *
870 * @param nIdResource
871 * the document id
872 * @param strResourceType
873 * the document type
874 * @param nIdWorkflow
875 * the workflow id
876 * @param nExternalParentId
877 * the external parent id
878 * @param user
879 * the user
880 */
881 public void executeActionAutomatic( int nIdResource, String strResourceType, int nIdWorkflow, Integer nExternalParentId, User user )
882 {
883 if ( isAvailable( ) )
884 {
885 TransactionManager.beginTransaction( null );
886
887 try
888 {
889 _service.executeActionAutomatic( nIdResource, strResourceType, nIdWorkflow, nExternalParentId, user );
890 TransactionManager.commitTransaction( null );
891
892 registerResourceEvent( nIdResource, strResourceType );
893 }
894 catch( Exception e )
895 {
896 TransactionManager.rollBack( null );
897 throw new AppException( e.getMessage( ), e );
898 }
899 }
900 }
901
902 /**
903 * Get the list of mass actions from a given id workflow
904 *
905 * @param nIdWorkflow
906 * the id workflow
907 * @return the list of mass actions
908 */
909 public List<Action> getMassActions( int nIdWorkflow )
910 {
911 return isAvailable( ) ? _service.getMassActions( nIdWorkflow ) : null;
912 }
913
914 /**
915 * Get the list of mass actions from a given id workflow
916 *
917 * @param nIdWorkflow
918 * the id workflow
919 * @param nIdState
920 * @param user
921 * @return the list of mass actions
922 */
923 public Collection<Action> getMassActions( int nIdWorkflow, int nIdState, User user )
924 {
925 if ( !isAvailable( ) )
926 {
927 return null;
928 }
929
930 Collection<Action> listActions = _service.getMassActions( nIdWorkflow, nIdState );
931
932 return _provider.getAuthorizedActions( listActions, user );
933 }
934
935 /**
936 * Check if the action can be proceed for the given resource
937 *
938 * @param nIdResource
939 * the id resource
940 * @param strResourceType
941 * the resource type
942 * @param nIdAction
943 * the id action
944 * @param nExternalParentId
945 * the external parent id
946 * @param request
947 * the HTTP request
948 * @param bIsAutomatic
949 * is automatic action
950 * @return true if the action can proceed, false otherwise
951 * @deprecated use canProcessAction( int, String, int, Integer, HttpServletRequest, User )
952 */
953 @Deprecated
954 public boolean canProcessAction( int nIdResource, String strResourceType, int nIdAction, Integer nExternalParentId, HttpServletRequest request,
955 boolean bIsAutomatic )
956 {
957 return canProcessAction( nIdResource, strResourceType, nIdAction, nExternalParentId, request, bIsAutomatic, null );
958 }
959
960 /**
961 * Check if the action can be proceed for the given resource
962 *
963 * @param nIdResource
964 * the id resource
965 * @param strResourceType
966 * the resource type
967 * @param nIdAction
968 * the id action
969 * @param nExternalParentId
970 * the external parent id
971 * @param request
972 * the HTTP request
973 * @param bIsAutomatic
974 * is automatic action
975 * @param user
976 * the RBACUser
977 * @return true if the action can proceed, false otherwise
978 */
979 public boolean canProcessAction( int nIdResource, String strResourceType, int nIdAction, Integer nExternalParentId, HttpServletRequest request,
980 boolean bIsAutomatic, User user )
981 {
982 if ( isAvailable( ) && _service.canProcessAction( nIdResource, strResourceType, nIdAction, nExternalParentId ) )
983 {
984 if ( bIsAutomatic )
985 {
986 return true;
987 }
988
989 return _provider.canProcessAction( nIdResource, strResourceType, nIdAction, request, user );
990 }
991
992 return false;
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 * @deprecated use doProcessAutomaticReflexiveActions( int, String, int, Integer, Locale, User )
1010 */
1011 @Deprecated
1012 public void doProcessAutomaticReflexiveActions( int nIdResource, String strResourceType, int nIdState, Integer nIdExternalParent, Locale locale )
1013 {
1014 doProcessAutomaticReflexiveActions( nIdResource, strResourceType, nIdState, nIdExternalParent, locale, null );
1015 }
1016
1017 /**
1018 * Proceed automatic reflexive actions of state given in parameter. This method should be called anytime a service changed the state of a resource without
1019 * proceeding a workflow action
1020 *
1021 * @param nIdResource
1022 * the resource id
1023 * @param strResourceType
1024 * the resource type
1025 * @param nIdState
1026 * the state of the resource id
1027 * @param nIdExternalParent
1028 * the external parent id*
1029 * @param locale
1030 * locale
1031 * @param user
1032 * the user
1033 */
1034 public void doProcessAutomaticReflexiveActions( int nIdResource, String strResourceType, int nIdState, Integer nIdExternalParent, Locale locale, User user )
1035 {
1036 if ( isAvailable( ) )
1037 {
1038 TransactionManager.beginTransaction( null );
1039
1040 try
1041 {
1042 _service.doProcessAutomaticReflexiveActions( nIdResource, strResourceType, nIdState, nIdExternalParent, locale, user );
1043 TransactionManager.commitTransaction( null );
1044
1045 registerResourceEvent( nIdResource, strResourceType );
1046 }
1047 catch( Exception e )
1048 {
1049 TransactionManager.rollBack( null );
1050 throw new AppException( e.getMessage( ), e );
1051 }
1052 }
1053 }
1054
1055 /**
1056 * Create and process a ResourceEvent.
1057 *
1058 * @param nIdResource
1059 * @param strResourceType
1060 */
1061 private void registerResourceEvent( int nIdResource, String strResourceType )
1062 {
1063 ResourceEventsourceEvent.html#ResourceEvent">ResourceEvent formResponseEvent = new ResourceEvent( );
1064 formResponseEvent.setIdResource( String.valueOf( nIdResource ) );
1065 formResponseEvent.setTypeResource( strResourceType );
1066
1067 ResourceEventManager.fireUpdatedResource( formResponseEvent );
1068 }
1069 }