1 package fr.paris.lutece.plugins.workflow.modules.unittreeuserassignment.util;
2
3 import java.util.List;
4
5 import javax.inject.Inject;
6
7 import org.springframework.context.ApplicationListener;
8
9 import fr.paris.lutece.plugins.unittree.business.assignment.UnitAssignment;
10 import fr.paris.lutece.plugins.unittree.business.unit.UnitHome;
11 import fr.paris.lutece.plugins.userassignment.business.IResourceUserDAO;
12 import fr.paris.lutece.plugins.workflow.modules.unittree.util.ChangeUnitEvent;
13 import fr.paris.lutece.plugins.workflow.service.WorkflowPlugin;
14 import fr.paris.lutece.portal.business.user.AdminUser;
15 import fr.paris.lutece.portal.service.plugin.Plugin;
16 import fr.paris.lutece.portal.service.plugin.PluginService;
17
18
19
20
21 public class ChangeUnitEventHandler implements ApplicationListener<ChangeUnitEvent>
22 {
23
24 @Inject
25 private IResourceUserDAO _resourceUserDAO;
26
27 @Override
28 public void onApplicationEvent( ChangeUnitEvent event )
29 {
30 final Plugin plugin = PluginService.getPlugin( WorkflowPlugin.PLUGIN_NAME );
31 for ( UnitAssignment assignment : event.getOldAssignmentList( ) )
32 {
33 List<AdminUser> userList = _resourceUserDAO.selectUserListByResource( assignment.getIdResource( ), assignment.getResourceType( ), plugin );
34
35 List<Integer> userIdList = UnitHome.findIdsUser( assignment.getIdAssignedUnit( ) );
36
37 for ( AdminUser user : userList )
38 {
39 if ( userIdList.contains( user.getUserId( ) ) )
40 {
41 _resourceUserDAO.deactivateByUserResource( user.getUserId( ), assignment.getIdResource( ), assignment.getResourceType( ), plugin );
42 }
43 }
44
45 }
46 }
47
48 }