1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.resource.modules.adminuser.service.provider;
35
36 import fr.paris.lutece.plugins.resource.business.IResource;
37 import fr.paris.lutece.plugins.resource.business.IResourceType;
38 import fr.paris.lutece.plugins.resource.business.ResourceTypeDefaultImplementation;
39 import fr.paris.lutece.plugins.resource.modules.adminuser.business.AdminUserResource;
40 import fr.paris.lutece.plugins.resource.service.ResourceCacheService;
41 import fr.paris.lutece.plugins.resource.service.provider.IResourceProvider;
42 import fr.paris.lutece.portal.business.user.AdminUser;
43 import fr.paris.lutece.portal.business.user.AdminUserHome;
44 import fr.paris.lutece.portal.service.i18n.I18nService;
45
46 import org.apache.commons.lang3.StringUtils;
47
48 import java.util.ArrayList;
49 import java.util.Collection;
50 import java.util.List;
51 import java.util.Locale;
52
53
54
55
56 public class AdminUserResourceProvider implements IResourceProvider
57 {
58 private static final String MESSAGE_ADMIN_USER_RESOURCE_TYPE_DESCRIPTION = "module.resource.adminuser.labelAdminUserResourceType";
59 private List<IResourceType> _listResourceTypes;
60
61
62
63
64 public AdminUserResourceProvider( )
65 {
66 _listResourceTypes = new ArrayList<>( 1 );
67 _listResourceTypes.add( new ResourceTypeDefaultImplementation( AdminUser.RESOURCE_TYPE,
68 I18nService.getLocalizedString( MESSAGE_ADMIN_USER_RESOURCE_TYPE_DESCRIPTION, Locale.getDefault( ) ) ) );
69 }
70
71
72
73
74 @Override
75 public List<IResourceType> getResourceTypeList( )
76 {
77 return _listResourceTypes;
78 }
79
80
81
82
83 @Override
84 public boolean isResourceTypeManaged( String strResourceTypeName )
85 {
86 return AdminUser.RESOURCE_TYPE.equals( strResourceTypeName );
87 }
88
89
90
91
92 @Override
93 public IResource getResource( String strIdResource, String strResourceTypeName )
94 {
95 String strCacheKey = ResourceCacheService.getResourceCacheKey( strIdResource, strResourceTypeName );
96 AdminUserResource../../../../../../fr/paris/lutece/plugins/resource/modules/adminuser/business/AdminUserResource.html#AdminUserResource">AdminUserResource user = (AdminUserResource) ResourceCacheService.getInstance( ).getFromCache( strCacheKey );
97
98 if ( user == null )
99 {
100 if ( StringUtils.isNotEmpty( strIdResource ) && StringUtils.isNumeric( strIdResource ) )
101 {
102 int nIdAdminUser = Integer.parseInt( strIdResource );
103 user = new AdminUserResource( AdminUserHome.findByPrimaryKey( nIdAdminUser ) );
104 ResourceCacheService.getInstance( ).putInCache( strCacheKey, user );
105 }
106 }
107
108 return user;
109 }
110
111
112
113
114 @Override
115 public List<IResource> getListResources( String strResourceTypeName )
116 {
117 if ( AdminUser.RESOURCE_TYPE.equals( strResourceTypeName ) )
118 {
119 Collection<AdminUser> listAdminUser = AdminUserHome.findUserList( );
120 List<IResource> listResource = new ArrayList<>( listAdminUser.size( ) );
121
122 for ( AdminUser adminUser : listAdminUser )
123 {
124 listResource.add( new AdminUserResource( adminUser ) );
125 }
126
127 return listResource;
128 }
129
130 return new ArrayList<>( );
131 }
132 }