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.portal.business.role;
35
36 import fr.paris.lutece.portal.business.user.AdminUser;
37 import fr.paris.lutece.portal.service.spring.SpringContextService;
38 import fr.paris.lutece.portal.service.util.AppPropertiesService;
39 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
40 import fr.paris.lutece.util.ReferenceList;
41
42 import java.util.Collection;
43
44
45
46
47
48
49
50 public final class RoleHome
51 {
52
53 private static final String PROPERTY_DEFAULT_ROLE_CODE = "defaultRole.code";
54 private static final String PROPERTY_DEFAULT_ROLE_DESCRIPTION = "defaultRole.description";
55
56
57 private static IRoleDAO _dao = (IRoleDAO) SpringContextService.getBean( "roleDAO" );
58
59
60
61
62 private RoleHome( )
63 {
64 }
65
66
67
68
69
70
71
72 public static Role create( Role role )
73 {
74 if ( !role.getRole( ).equals( getDefaultRole( ).getRole( ) ) )
75 {
76 _dao.insert( role );
77 }
78
79 return role;
80 }
81
82
83
84
85
86
87
88 public static Role update( Role role )
89 {
90 if ( !role.getRole( ).equals( getDefaultRole( ).getRole( ) ) )
91 {
92 _dao.store( role );
93 }
94
95 return role;
96 }
97
98
99
100
101
102
103 public static void remove( String strRole )
104 {
105 _dao.delete( strRole );
106 }
107
108
109
110
111
112
113
114
115
116
117 public static Role findByPrimaryKey( String strRole )
118 {
119 Role role = getDefaultRole( );
120
121 if ( !strRole.equals( role.getRole( ) ) )
122 {
123 return _dao.load( strRole );
124 }
125
126 return role;
127 }
128
129
130
131
132
133
134 public static ReferenceList getRolesList( )
135 {
136 ReferenceList roleList = _dao.selectRolesList( );
137 Role defaultRole = getDefaultRole( );
138 roleList.addItem( defaultRole.getRole( ), defaultRole.getRoleDescription( ) );
139
140 return roleList;
141 }
142
143
144
145
146
147
148 public static Collection<Role> findAll( )
149 {
150 Collection<Role> roleList = _dao.selectAll( );
151 roleList.add( getDefaultRole( ) );
152
153 return roleList;
154 }
155
156
157
158
159
160
161 public static boolean findExistRole( String strRole )
162 {
163 if ( strRole.equals( getDefaultRole( ).getRole( ) ) )
164 {
165 return true;
166 }
167
168 return ( findByPrimaryKey( strRole ) == null ) ? false : true;
169 }
170
171
172
173
174
175
176 private static Role getDefaultRole( )
177 {
178 Role role = new Role( );
179 role.setRole( AppPropertiesService.getProperty( PROPERTY_DEFAULT_ROLE_CODE ) );
180 role.setRoleDescription( AppPropertiesService.getProperty( PROPERTY_DEFAULT_ROLE_DESCRIPTION ) );
181
182 return role;
183 }
184
185
186
187
188
189
190 public static ReferenceList getRolesList( AdminUser user )
191 {
192 Collection<Role> listRoles = RoleHome.findAll( );
193 listRoles = AdminWorkgroupService.getAuthorizedCollection( listRoles, user );
194
195 ReferenceList roleList = new ReferenceList( );
196
197 for ( Role role : listRoles )
198 {
199 roleList.addItem( role.getRole( ), role.getRoleDescription( ) );
200 }
201
202 return roleList;
203 }
204 }