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.plugins.workflow.service;
35  
36  import java.util.ArrayList;
37  import java.util.Collection;
38  import java.util.HashMap;
39  import java.util.List;
40  import java.util.Locale;
41  import java.util.Map;
42  import java.util.Map.Entry;
43  import java.util.stream.Collectors;
44  
45  import javax.inject.Inject;
46  import javax.servlet.http.HttpServletRequest;
47  
48  import org.apache.commons.collections.CollectionUtils;
49  
50  import fr.paris.lutece.api.user.User;
51  import fr.paris.lutece.plugins.workflow.service.prerequisite.IManualActionPrerequisiteService;
52  import fr.paris.lutece.plugins.workflow.utils.WorkflowUtils;
53  import fr.paris.lutece.plugins.workflowcore.business.action.Action;
54  import fr.paris.lutece.plugins.workflowcore.business.prerequisite.IPrerequisiteConfig;
55  import fr.paris.lutece.plugins.workflowcore.business.prerequisite.Prerequisite;
56  import fr.paris.lutece.plugins.workflowcore.business.resource.ResourceHistory;
57  import fr.paris.lutece.plugins.workflowcore.business.resource.ResourceWorkflow;
58  import fr.paris.lutece.plugins.workflowcore.business.resource.ResourceWorkflowFilter;
59  import fr.paris.lutece.plugins.workflowcore.business.state.State;
60  import fr.paris.lutece.plugins.workflowcore.business.state.StateFilter;
61  import fr.paris.lutece.plugins.workflowcore.business.workflow.Workflow;
62  import fr.paris.lutece.plugins.workflowcore.business.workflow.WorkflowFilter;
63  import fr.paris.lutece.plugins.workflowcore.service.action.IActionService;
64  import fr.paris.lutece.plugins.workflowcore.service.prerequisite.IAutomaticActionPrerequisiteService;
65  import fr.paris.lutece.plugins.workflowcore.service.prerequisite.IPrerequisiteManagementService;
66  import fr.paris.lutece.plugins.workflowcore.service.resource.IResourceHistoryService;
67  import fr.paris.lutece.plugins.workflowcore.service.resource.IResourceWorkflowService;
68  import fr.paris.lutece.plugins.workflowcore.service.state.IStateService;
69  import fr.paris.lutece.plugins.workflowcore.service.task.ITask;
70  import fr.paris.lutece.plugins.workflowcore.service.task.ITaskService;
71  import fr.paris.lutece.plugins.workflowcore.service.workflow.IWorkflowService;
72  import fr.paris.lutece.plugins.workflowcore.web.task.ITaskComponentManager;
73  import fr.paris.lutece.portal.business.user.AdminUserHome;
74  import fr.paris.lutece.portal.service.admin.AdminUserService;
75  import fr.paris.lutece.portal.service.plugin.PluginService;
76  import fr.paris.lutece.portal.service.rbac.RBACService;
77  import fr.paris.lutece.portal.service.template.AppTemplateService;
78  import fr.paris.lutece.portal.service.workflow.IWorkflowProvider;
79  import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
80  import fr.paris.lutece.util.ReferenceList;
81  import fr.paris.lutece.util.html.HtmlTemplate;
82  
83  /**
84   *
85   * WorkflowProvider
86   *
87   */
88  public class WorkflowProvider implements IWorkflowProvider
89  {
90      // MARKS
91      private static final String MARK_RESOURCE_HISTORY = "resource_history";
92      private static final String MARK_TASK_INFORMATION_LIST = "task_information_list";
93      private static final String MARK_USER_HISTORY = "user_history";
94      private static final String MARK_HISTORY_INFORMATION_LIST = "history_information_list";
95      private static final String MARK_TASK_FORM_ENTRY_LIST = "task_form_entry_list";
96      private static final String MARK_ADMIN_AVATAR = "adminAvatar";
97  
98      // TEMPLATES
99      private static final String TEMPLATE_RESOURCE_HISTORY = "admin/plugins/workflow/resource_history.html";
100     private static final String TEMPLATE_TASKS_FORM = "admin/plugins/workflow/tasks_form.html";
101 
102     // SERVICES
103     @Inject
104     private IActionService _actionService;
105     @Inject
106     private IResourceWorkflowService _resourceWorkflowService;
107     @Inject
108     private IResourceHistoryService _resourceHistoryService;
109     @Inject
110     private IStateService _stateService;
111     @Inject
112     private ITaskService _taskService;
113     @Inject
114     private IWorkflowService _workflowService;
115     @Inject
116     private ITaskComponentManager _taskComponentManager;
117     @Inject
118     private IPrerequisiteManagementService _prerequisiteManagementService;
119 
120     /**
121      * {@inheritDoc}
122      */
123     // @Override don't declare as Override to be compatible with older Lutece Core version
124     public Collection<Action> getActions( int nIdResource, String strResourceType, Collection<Action> listActions, User user )
125     {
126         listActions = listActions.stream( ).filter( a -> canActionBeProcessed( user, nIdResource, strResourceType, a.getId( ) ) )
127                 .collect( Collectors.toList( ) );
128         return RBACService.getAuthorizedCollection( listActions, ActionResourceIdService.PERMISSION_VIEW, user );
129     }
130 
131     /**
132      * {@inheritDoc}
133      */
134     // @Override don't declare as Override to be compatible with older Lutece Core version
135     public Collection<Action> getAuthorizedActions( Collection<Action> listActions, User user )
136     {
137         return RBACService.getAuthorizedCollection( listActions, ActionResourceIdService.PERMISSION_VIEW, user );
138     }
139 
140     /**
141      * {@inheritDoc}
142      */
143     // @Override don't declare as Override to be compatible with older Lutece Core version
144     public Map<Integer, List<Action>> getActions( String strResourceType, Map<Integer, List<Action>> mapActions, User user )
145     {
146         for ( Entry<Integer, List<Action>> entry : mapActions.entrySet( ) )
147         {
148             List<Action> listActions = entry.getValue( );
149             listActions = listActions.stream( ).filter( a -> canActionBeProcessed( user, entry.getKey( ), strResourceType, a.getId( ) ) )
150                     .collect( Collectors.toList( ) );
151             listActions = (List<Action>) RBACService.getAuthorizedCollection( listActions, ActionResourceIdService.PERMISSION_VIEW, user );
152             mapActions.put( entry.getKey( ), listActions );
153         }
154 
155         return mapActions;
156     }
157 
158     private boolean canActionBeProcessed( User user, int nIdResource, String strResourceType, int nIdAction )
159     {
160         for ( Prerequisite prerequisite : _prerequisiteManagementService.getListPrerequisite( nIdAction ) )
161         {
162             IAutomaticActionPrerequisiteService prerequisiteService = _prerequisiteManagementService
163                     .getPrerequisiteService( prerequisite.getPrerequisiteType( ) );
164 
165             IPrerequisiteConfig config = _prerequisiteManagementService.getPrerequisiteConfiguration( prerequisite.getIdPrerequisite( ), prerequisiteService );
166             boolean canBePerformed = false;
167             if ( prerequisiteService instanceof IManualActionPrerequisiteService )
168             {
169                 canBePerformed = ( (IManualActionPrerequisiteService) prerequisiteService ).canManualActionBePerformed( user, nIdResource, strResourceType,
170                         config, nIdAction );
171             }
172             else
173             {
174                 canBePerformed = prerequisiteService.canActionBePerformed( nIdResource, strResourceType, config, nIdAction );
175             }
176 
177             if ( !canBePerformed )
178             {
179                 return false;
180             }
181         }
182         return true;
183     }
184 
185     /**
186      * {@inheritDoc}
187      */
188     @Override
189     public Collection<State> getAllStateByWorkflow( Collection<State> listStates, User user )
190     {
191         return RBACService.getAuthorizedCollection( listStates, StateResourceIdService.PERMISSION_VIEW, user );
192     }
193 
194     /**
195      * {@inheritDoc}
196      */
197     @Override
198     public List<Integer> getAuthorizedResourceList( String strResourceType, int nIdWorkflow, int nIdWorkflowState, Integer nExternalParentId, User user )
199     {
200         if ( nIdWorkflowState < 1 )
201         {
202             return this.getAuthorizedResourceList( strResourceType, nIdWorkflow, null, nExternalParentId, user );
203         }
204 
205         List<Integer> resourceIdList = new ArrayList<>( );
206 
207         State state = _stateService.findByPrimaryKey( nIdWorkflowState );
208 
209         ResourceWorkflowFilter resourceWorkflowFilter = new ResourceWorkflowFilter( );
210 
211         if ( user != null )
212         {
213             if ( RBACService.isAuthorized( state, StateResourceIdService.PERMISSION_VIEW, user ) )
214             {
215                 if ( Boolean.TRUE.equals( state.isRequiredWorkgroupAssigned( ) ) )
216                 {
217 
218                     ReferenceList refWorkgroupKey = getUserWorkgroups( user );
219                     resourceWorkflowFilter.setWorkgroupKeyList( refWorkgroupKey.toMap( ) );
220                 }
221 
222                 resourceWorkflowFilter.setIdState( state.getId( ) );
223                 resourceWorkflowFilter.setIdWorkflow( nIdWorkflow );
224                 resourceWorkflowFilter.setResourceType( strResourceType );
225                 resourceWorkflowFilter.setExternalParentId( nExternalParentId );
226                 resourceIdList = _resourceWorkflowService.getListResourceIdWorkflowByFilter( resourceWorkflowFilter );
227             }
228         }
229         else
230         // WARNING : if content "user!=null" because for the batch the user is null, for the other case the user is not null
231         {
232             resourceWorkflowFilter.setIdState( state.getId( ) );
233             resourceWorkflowFilter.setIdWorkflow( nIdWorkflow );
234             resourceWorkflowFilter.setResourceType( strResourceType );
235             resourceWorkflowFilter.setExternalParentId( nExternalParentId );
236             resourceIdList = _resourceWorkflowService.getListResourceIdWorkflowByFilter( resourceWorkflowFilter );
237         }
238 
239         return resourceIdList;
240     }
241 
242     /**
243      * {@inheritDoc}
244      */
245     @Override
246     public List<Integer> getAuthorizedResourceList( String strResourceType, int nIdWorkflow, List<Integer> lListIdWorkflowState, Integer nExternalParentId,
247             User user )
248     {
249         List<Integer> lListAutorizedIdSate = new ArrayList<>( );
250 
251         StateFilter stateFilter = new StateFilter( );
252         stateFilter.setIdWorkflow( nIdWorkflow );
253 
254         Collection<State> listState = _stateService.getListStateByFilter( stateFilter );
255 
256         for ( State state : listState )
257         {
258             Integer nIdState = state.getId( );
259             if ( lListIdWorkflowState == null || lListIdWorkflowState.contains( nIdState ) )
260             {
261                 if ( user != null )
262                 {
263                     if ( RBACService.isAuthorized( state, StateResourceIdService.PERMISSION_VIEW, user ) )
264                     {
265                         lListAutorizedIdSate.add( nIdState );
266                     }
267                 }
268                 else
269                 // WARNING : if content "user!=null" because for the batch the user is null, for the other case the user is not null
270                 {
271                     lListAutorizedIdSate.add( nIdState );
272                 }
273             }
274         }
275 
276         ResourceWorkflowFilter resourceWorkflowFilter = new ResourceWorkflowFilter( );
277         resourceWorkflowFilter.setIdState( ResourceWorkflowFilter.ALL_INT );
278         resourceWorkflowFilter.setIdWorkflow( nIdWorkflow );
279         resourceWorkflowFilter.setResourceType( strResourceType );
280         resourceWorkflowFilter.setExternalParentId( nExternalParentId );
281 
282         if ( user != null )
283         {
284             ReferenceList refWorkgroupKey = getUserWorkgroups( user );
285             resourceWorkflowFilter.setWorkgroupKeyList( refWorkgroupKey.toMap( ) );
286         }
287 
288         return _resourceWorkflowService.getListResourceIdWorkflowByFilter( resourceWorkflowFilter, lListAutorizedIdSate );
289     }
290 
291     /**
292      * {@inheritDoc}
293      */
294     @Override
295     public String getDisplayDocumentHistory( int nIdResource, String strResourceType, int nIdWorkflow, HttpServletRequest request, Locale locale, User user )
296     {
297         return getDisplayDocumentHistory( nIdResource, strResourceType, nIdWorkflow, request, locale, null, TEMPLATE_RESOURCE_HISTORY, user );
298     }
299 
300     /**
301      * Implements IWorkflowProvider of Lutece Core version 5.1
302      * 
303      * @param nIdResource
304      *            The resource
305      * @param strResourceType
306      *            The resource type
307      * @param nIdWorkflow
308      *            the workflow id
309      * @param request
310      *            The request
311      * @param locale
312      *            The locale
313      * @param model
314      *            The model to add to the default model
315      * @param strTemplate
316      *            The template
317      * @return The HTML code to display
318      */
319 
320     // @Override don't declare as Override to be compatible with older Lutece Core version
321     public String getDisplayDocumentHistory( int nIdResource, String strResourceType, int nIdWorkflow, HttpServletRequest request, Locale locale,
322             Map<String, Object> model, String strTemplate, User user )
323     {
324         Map<String, Object> defaultModel = getDefaultModelDocumentHistory( nIdResource, strResourceType, nIdWorkflow, request, locale );
325 
326         if ( model != null )
327         {
328             defaultModel.putAll( model );
329         }
330 
331         HtmlTemplate templateList = AppTemplateService.getTemplate( strTemplate, locale, defaultModel );
332 
333         return templateList.getHtml( );
334     }
335 
336     /**
337      * {@inheritDoc}
338      */
339     @Override
340     public String getDisplayTasksForm( int nIdResource, String strResourceType, int nIdAction, HttpServletRequest request, Locale locale, User user )
341     {
342         List<ITask> listTasks = _taskService.getListTaskByIdAction( nIdAction, locale );
343         List<String> listFormEntry = new ArrayList<>( );
344         String strFormEntry;
345 
346         for ( ITask task : listTasks )
347         {
348             strFormEntry = _taskComponentManager.getDisplayTaskForm( nIdResource, strResourceType, request, locale, task );
349 
350             if ( strFormEntry != null )
351             {
352                 listFormEntry.add( strFormEntry );
353             }
354         }
355 
356         Map<String, Object> model = new HashMap<>( );
357 
358         model.put( MARK_TASK_FORM_ENTRY_LIST, listFormEntry );
359 
360         HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_TASKS_FORM, locale, model );
361 
362         return templateList.getHtml( );
363     }
364 
365     /**
366      * {@inheritDoc}
367      */
368     @Override
369     public ReferenceList getWorkflowsEnabled( User user, Locale locale )
370     {
371         return WorkflowUtils.getRefList( getWorkflowsEnabled( user ), true, locale );
372     }
373 
374     /**
375      * {@inheritDoc}
376      */
377     @Override
378     public String getUserAccessCode( HttpServletRequest request, User user )
379     {
380         String strAccessCode = null;
381         if ( user == null )
382         { /// get user in the httpservletRequest
383             user = getUserInRequest( request );
384         }
385 
386         if ( user != null )
387         {
388             strAccessCode = user.getAccessCode( );
389         }
390         return strAccessCode;
391     }
392 
393     // CHECK
394 
395     /**
396      * {@inheritDoc}
397      */
398     // @Override don't declare as Override to be compatible with older Lutece Core version
399     public boolean canProcessAction( int nIdResource, String strResourceType, int nIdAction, HttpServletRequest request, User user )
400     {
401         if ( user == null )
402         { // get user in the httpservletRequest
403             user = getUserInRequest( request );
404         }
405 
406         if ( user != null )
407         {
408             Action action = _actionService.findByPrimaryKey( nIdAction );
409             return canActionBeProcessed( user, nIdResource, strResourceType, nIdAction )
410                     && RBACService.isAuthorized( action, ActionResourceIdService.PERMISSION_VIEW, user );
411         }
412 
413         return false;
414     }
415 
416     /**
417      * {@inheritDoc}
418      */
419     @Override
420     public boolean isAuthorized( int nIdResource, String strResourceType, int nIdWorkflow, User user )
421     {
422         boolean bReturn = false;
423         State resourceState = null;
424         ResourceWorkflow resourceWorkflow = _resourceWorkflowService.findByPrimaryKey( nIdResource, strResourceType, nIdWorkflow );
425 
426         if ( resourceWorkflow != null )
427         {
428             resourceState = _stateService.findByPrimaryKey( resourceWorkflow.getState( ).getId( ) );
429         }
430         else
431         {
432             // Get initial state
433             StateFilter filter = new StateFilter( );
434             filter.setIsInitialState( StateFilter.FILTER_TRUE );
435             filter.setIdWorkflow( nIdWorkflow );
436 
437             List<State> listState = _stateService.getListStateByFilter( filter );
438 
439             if ( CollectionUtils.isNotEmpty( listState ) )
440             {
441                 resourceState = listState.get( 0 );
442             }
443         }
444 
445         if ( resourceState == null || !RBACService.isAuthorized( resourceState, StateResourceIdService.PERMISSION_VIEW, user ) )
446         {
447             return bReturn;
448         }
449 
450         if ( Boolean.TRUE.equals( resourceState.isRequiredWorkgroupAssigned( ) ) && ( resourceWorkflow != null ) )
451         {
452 
453             for ( String strWorkgroup : resourceWorkflow.getWorkgroups( ) )
454             {
455                 if ( isUserInWorkgroup( user, strWorkgroup )
456                         || RBACService.isAuthorized( resourceState, StateResourceIdService.PERMISSION_VIEW_ALL_WORKGROUP, user ) )
457                 {
458                     bReturn = true;
459 
460                     break;
461                 }
462             }
463         }
464         else
465         {
466             bReturn = true;
467         }
468 
469         return bReturn;
470     }
471 
472     // DO
473 
474     /**
475      * {@inheritDoc}
476      */
477     @Override
478     public String doValidateTasksForm( int nIdResource, String strResourceType, int nIdAction, HttpServletRequest request, Locale locale, User user )
479     {
480         List<ITask> listTasks = _taskService.getListTaskByIdAction( nIdAction, locale );
481         String strError = null;
482 
483         for ( ITask task : listTasks )
484         {
485             strError = _taskComponentManager.doValidateTask( nIdResource, strResourceType, request, locale, task );
486 
487             if ( strError != null )
488             {
489                 return strError;
490             }
491         }
492 
493         return null;
494     }
495 
496     // PRIVATE METHODS
497 
498     /**
499      * Return a collection witch contains a list enabled workflow
500      * 
501      * @param user
502      *            the User
503      * @return a collection witch contains a list enabled workflow
504      */
505     private Collection<Workflow> getWorkflowsEnabled( User user )
506     {
507         WorkflowFilter filter = new WorkflowFilter( );
508         filter.setIsEnabled( WorkflowFilter.FILTER_TRUE );
509 
510         List<Workflow> listWorkflow = _workflowService.getListWorkflowsByFilter( filter );
511 
512         return AdminWorkgroupService.getAuthorizedCollection( listWorkflow, user );
513     }
514 
515     /**
516      * returns the default model to build history performed on a resource.
517      *
518      * @param nIdResource
519      *            the resource id
520      * @param strResourceType
521      *            the resource type
522      * @param nIdWorkflow
523      *            the workflow id
524      * @param request
525      *            the request
526      * @param locale
527      *            the locale
528      * @return the default model
529      */
530     private Map<String, Object> getDefaultModelDocumentHistory( int nIdResource, String strResourceType, int nIdWorkflow, HttpServletRequest request,
531             Locale locale )
532     {
533         List<ResourceHistory> listResourceHistory = _resourceHistoryService.getAllHistoryByResource( nIdResource, strResourceType, nIdWorkflow );
534         List<ITask> listActionTasks;
535         List<String> listTaskInformation;
536         Map<String, Object> model = new HashMap<>( );
537         Map<String, Object> resourceHistoryTaskInformation;
538         List<Map<String, Object>> listResourceHistoryTaskInformation = new ArrayList<>( );
539         String strTaskinformation;
540 
541         for ( ResourceHistory resourceHistory : listResourceHistory )
542         {
543             resourceHistoryTaskInformation = new HashMap<>( );
544             resourceHistoryTaskInformation.put( MARK_RESOURCE_HISTORY, resourceHistory );
545 
546             if ( resourceHistory.getUserAccessCode( ) != null )
547             {
548                 if ( resourceHistory.getResourceUserHistory( ) != null )
549                 {
550                     resourceHistoryTaskInformation.put( MARK_USER_HISTORY, resourceHistory.getResourceUserHistory( ) );
551                 }
552                 else
553                 {
554                     resourceHistoryTaskInformation.put( MARK_USER_HISTORY, getUserByAccessCode( resourceHistory.getUserAccessCode( ) ) );
555                 }
556             }
557 
558             listTaskInformation = new ArrayList<>( );
559             listActionTasks = _taskService.getListTaskByIdAction( resourceHistory.getAction( ).getId( ), locale );
560 
561             for ( ITask task : listActionTasks )
562             {
563                 strTaskinformation = _taskComponentManager.getDisplayTaskInformation( resourceHistory.getId( ), request, locale, task );
564 
565                 if ( strTaskinformation != null )
566                 {
567                     listTaskInformation.add( strTaskinformation );
568                 }
569             }
570 
571             resourceHistoryTaskInformation.put( MARK_TASK_INFORMATION_LIST, listTaskInformation );
572 
573             listResourceHistoryTaskInformation.add( resourceHistoryTaskInformation );
574         }
575 
576         model.put( MARK_HISTORY_INFORMATION_LIST, listResourceHistoryTaskInformation );
577         model.put( MARK_ADMIN_AVATAR, PluginService.isPluginEnable( "adminavatar" ) );
578 
579         return model;
580     }
581 
582     /**
583      * Method used when the user is not provided.
584      * 
585      * @param request
586      *            the httpServletRequest
587      * @return the user in the request
588      */
589     private User getUserInRequest( HttpServletRequest request )
590     {
591         return request != null ? AdminUserService.getAdminUser( request ) : null;
592     }
593 
594     /**
595      * Return a ReferenceList witch contains the user workgoups
596      * 
597      * @param user
598      *            the user
599      * @return a ReferenceList witch contains the user workgoups
600      */
601 
602     private ReferenceList getUserWorkgroups( User user )
603     {
604 
605         ReferenceList refListWorkgroup = new ReferenceList( );
606         if ( user.getUserWorkgroups( ) != null )
607         {
608             user.getUserWorkgroups( ).forEach( x -> refListWorkgroup.addItem( x, x ) );
609         }
610         return refListWorkgroup;
611 
612     }
613 
614     /**
615      * Return true if the user is in the workgoup
616      * 
617      * @param user
618      *            the user
619      * @param strWorkgroup
620      *            the workgroup
621      * @return true if the user is in the workgroup
622      */
623     private boolean isUserInWorkgroup( User user, String strWorkgroup )
624     {
625         if ( user.getUserWorkgroups( ) != null )
626         {
627             return user.getUserWorkgroups( ).stream( ).anyMatch( x -> x.equals( strWorkgroup ) );
628         }
629         return false;
630     }
631 
632     // TODO provide UserInfo depending the User type who made the action
633     /**
634      * get a User by Access Code
635      * 
636      * @param strAccessCode
637      *            the strAccessCode
638      * @return a user by access code
639      */
640     private User getUserByAccessCode( String strAccessCode )
641     {
642         return AdminUserHome.findUserByLogin( strAccessCode );
643     }
644 
645 }