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