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.identitystore.web;
35
36 import fr.paris.lutece.plugins.identitystore.business.attribute.AttributeKeyHome;
37 import fr.paris.lutece.plugins.identitystore.business.referentiel.RefAttributeCertificationLevel;
38 import fr.paris.lutece.plugins.identitystore.business.referentiel.RefAttributeCertificationProcessus;
39 import fr.paris.lutece.plugins.identitystore.business.referentiel.RefAttributeCertificationProcessusHome;
40 import fr.paris.lutece.plugins.identitystore.business.referentiel.RefCertificationLevel;
41 import fr.paris.lutece.plugins.identitystore.business.referentiel.RefCertificationLevelHome;
42 import fr.paris.lutece.plugins.identitystore.service.contract.AttributeCertificationDefinitionService;
43 import fr.paris.lutece.portal.service.admin.AccessDeniedException;
44 import fr.paris.lutece.portal.service.message.AdminMessage;
45 import fr.paris.lutece.portal.service.message.AdminMessageService;
46 import fr.paris.lutece.portal.service.security.SecurityTokenService;
47 import fr.paris.lutece.portal.service.util.AppException;
48 import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
49 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
50 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
51 import fr.paris.lutece.util.url.UrlItem;
52
53 import javax.servlet.http.HttpServletRequest;
54 import java.util.ArrayList;
55 import java.util.Comparator;
56 import java.util.HashMap;
57 import java.util.List;
58 import java.util.Map;
59 import java.util.stream.Collectors;
60
61
62
63
64 @Controller( controllerJsp = "ManageRefAttributeCertificationProcessuss.jsp", controllerPath = "jsp/admin/plugins/identitystore/", right = "IDENTITYSTORE_REF_MANAGEMENT" )
65 public class RefAttributeCertificationProcessusJspBean extends AbstractManageProcessusRefJspBean<Integer, RefAttributeCertificationProcessus>
66 {
67
68 private static final String TEMPLATE_MANAGE_REFATTRIBUTECERTIFICATIONPROCESSUSS = "/admin/plugins/identitystore/manage_refattributecertificationprocessuss.html";
69 private static final String TEMPLATE_CREATE_REFATTRIBUTECERTIFICATIONPROCESSUS = "/admin/plugins/identitystore/create_refattributecertificationprocessus.html";
70 private static final String TEMPLATE_MODIFY_REFATTRIBUTECERTIFICATIONPROCESSUS = "/admin/plugins/identitystore/modify_refattributecertificationprocessus.html";
71
72
73 private static final String PARAMETER_ID_REFATTRIBUTECERTIFICATIONPROCESSUS = "id";
74
75 private static final String PARAMETER_CERTICATION_LEVEL = "certification_level";
76
77
78 private static final String PROPERTY_PAGE_TITLE_MANAGE_REFATTRIBUTECERTIFICATIONPROCESSUSS = "identitystore.manage_refattributecertificationprocessuss.pageTitle";
79 private static final String PROPERTY_PAGE_TITLE_MODIFY_REFATTRIBUTECERTIFICATIONPROCESSUS = "identitystore.modify_refattributecertificationprocessus.pageTitle";
80 private static final String PROPERTY_PAGE_TITLE_CREATE_REFATTRIBUTECERTIFICATIONPROCESSUS = "identitystore.create_refattributecertificationprocessus.pageTitle";
81
82
83 private static final String MARK_REFATTRIBUTECERTIFICATIONPROCESSUS_LIST = "refattributecertificationprocessus_list";
84 private static final String MARK_REFATTRIBUTECERTIFICATIONPROCESSUS = "refattributecertificationprocessus";
85
86 private static final String MARK_ATTRIBUTE_LEVELS_LIST = "refattributecertificationlevels_attribute_list";
87 private static final String MARK_AVAILAIBLE_LEVELS_LIST = "availaible_certification_levels_list";
88
89 private static final String JSP_MANAGE_REFATTRIBUTECERTIFICATIONPROCESSUSS = "jsp/admin/plugins/identitystore/ManageRefAttributeCertificationProcessuss.jsp";
90
91
92 private static final String MESSAGE_CONFIRM_REMOVE_REFATTRIBUTECERTIFICATIONPROCESSUS = "identitystore.message.confirmRemoveRefAttributeCertificationProcessus";
93
94
95 private static final String VALIDATION_ATTRIBUTES_PREFIX = "identitystore.model.entity.refattributecertificationprocessus.attribute.";
96
97
98 private static final String VIEW_MANAGE_REFATTRIBUTECERTIFICATIONPROCESSUSS = "manageRefAttributeCertificationProcessuss";
99 private static final String VIEW_CREATE_REFATTRIBUTECERTIFICATIONPROCESSUS = "createRefAttributeCertificationProcessus";
100 private static final String VIEW_MODIFY_REFATTRIBUTECERTIFICATIONPROCESSUS = "modifyRefAttributeCertificationProcessus";
101
102
103 private static final String ACTION_CREATE_REFATTRIBUTECERTIFICATIONPROCESSUS = "createRefAttributeCertificationProcessus";
104 private static final String ACTION_MODIFY_REFATTRIBUTECERTIFICATIONPROCESSUS = "modifyRefAttributeCertificationProcessus";
105 private static final String ACTION_REMOVE_REFATTRIBUTECERTIFICATIONPROCESSUS = "removeRefAttributeCertificationProcessus";
106 private static final String ACTION_CONFIRM_REMOVE_REFATTRIBUTECERTIFICATIONPROCESSUS = "confirmRemoveRefAttributeCertificationProcessus";
107
108
109 private static final String INFO_REFATTRIBUTECERTIFICATIONPROCESSUS_CREATED = "identitystore.info.refattributecertificationprocessus.created";
110 private static final String INFO_REFATTRIBUTECERTIFICATIONPROCESSUS_UPDATED = "identitystore.info.refattributecertificationprocessus.updated";
111 private static final String INFO_REFATTRIBUTECERTIFICATIONPROCESSUS_REMOVED = "identitystore.info.refattributecertificationprocessus.removed";
112
113
114 private static final String ERROR_RESOURCE_NOT_FOUND = "Resource not found";
115
116
117 private RefAttributeCertificationProcessus _refattributecertificationprocessus;
118
119
120
121
122
123
124
125
126 @View( value = VIEW_MANAGE_REFATTRIBUTECERTIFICATIONPROCESSUSS, defaultView = true )
127 public String getManageRefAttributeCertificationProcessuss( HttpServletRequest request )
128 {
129 List<RefAttributeCertificationProcessus> refAttributeCertificationProcessussList = RefAttributeCertificationProcessusHome
130 .getRefAttributeCertificationProcessussList( );
131 refAttributeCertificationProcessussList.sort( Comparator.comparing( RefAttributeCertificationProcessus::getCode ) );
132
133 Map<String, Object> model = getPaginatedListModel( request, MARK_REFATTRIBUTECERTIFICATIONPROCESSUS_LIST, refAttributeCertificationProcessussList,
134 JSP_MANAGE_REFATTRIBUTECERTIFICATIONPROCESSUSS );
135
136 return getPage( PROPERTY_PAGE_TITLE_MANAGE_REFATTRIBUTECERTIFICATIONPROCESSUSS, TEMPLATE_MANAGE_REFATTRIBUTECERTIFICATIONPROCESSUSS, model );
137 }
138
139
140
141
142
143
144
145 @Override
146 List<RefAttributeCertificationProcessus> getItemsFromIds( List<Integer> listIds )
147 {
148 List<RefAttributeCertificationProcessus> listRefAttributeCertificationProcessus = RefAttributeCertificationProcessusHome
149 .getRefAttributeCertificationProcessussListByIds( listIds );
150
151
152 return listRefAttributeCertificationProcessus.stream( ).sorted( Comparator.comparingInt( notif -> listIds.indexOf( notif.getId( ) ) ) )
153 .collect( Collectors.toList( ) );
154 }
155
156
157
158
159
160
161
162
163 @View( VIEW_CREATE_REFATTRIBUTECERTIFICATIONPROCESSUS )
164 public String getCreateRefAttributeCertificationProcessus( HttpServletRequest request )
165 {
166 _refattributecertificationprocessus = new RefAttributeCertificationProcessus( );
167
168 Map<String, Object> model = getModel( );
169 model.put( MARK_REFATTRIBUTECERTIFICATIONPROCESSUS, _refattributecertificationprocessus );
170 model.put( MARK_ATTRIBUTE_LEVELS_LIST, RefAttributeCertificationProcessusHome.selectAttributeLevels( _refattributecertificationprocessus ) );
171 model.put( MARK_AVAILAIBLE_LEVELS_LIST, RefAttributeCertificationProcessusHome.selectCertificationLevels( ).stream( )
172 .sorted( Comparator.comparing( RefCertificationLevel::getLevel ) ).collect( Collectors.toList( ) ) );
173 model.put( SecurityTokenService.MARK_TOKEN, SecurityTokenService.getInstance( ).getToken( request, ACTION_CREATE_REFATTRIBUTECERTIFICATIONPROCESSUS ) );
174
175 return getPage( PROPERTY_PAGE_TITLE_CREATE_REFATTRIBUTECERTIFICATIONPROCESSUS, TEMPLATE_CREATE_REFATTRIBUTECERTIFICATIONPROCESSUS, model );
176 }
177
178
179
180
181
182
183
184
185
186 @Action( ACTION_CREATE_REFATTRIBUTECERTIFICATIONPROCESSUS )
187 public String doCreateRefAttributeCertificationProcessus( HttpServletRequest request ) throws AccessDeniedException
188 {
189 populate( _refattributecertificationprocessus, request, getLocale( ) );
190
191 if ( !SecurityTokenService.getInstance( ).validate( request, ACTION_CREATE_REFATTRIBUTECERTIFICATIONPROCESSUS ) )
192 {
193 throw new AccessDeniedException( "Invalid security token" );
194 }
195
196
197 if ( !validateBean( _refattributecertificationprocessus, VALIDATION_ATTRIBUTES_PREFIX ) )
198 {
199 return redirectView( request, VIEW_CREATE_REFATTRIBUTECERTIFICATIONPROCESSUS );
200 }
201
202 RefAttributeCertificationProcessusHome.create( _refattributecertificationprocessus );
203
204
205 List<RefAttributeCertificationLevel> refAttributeCertificationLevelList = new ArrayList<>(
206 getRefAttributeCertificationLevelsFromRequest( request ).values( ) );
207 AttributeCertificationDefinitionService.instance( ).addRefAttributeCertificationLevels(
208 refAttributeCertificationLevelList.stream( ).filter( certif -> certif.getRefCertificationLevel( ) != null ).collect( Collectors.toList( ) ) );
209
210 addInfo( INFO_REFATTRIBUTECERTIFICATIONPROCESSUS_CREATED, getLocale( ) );
211
212 return redirectView( request, VIEW_MANAGE_REFATTRIBUTECERTIFICATIONPROCESSUSS );
213 }
214
215
216
217
218
219
220
221
222 @Action( ACTION_CONFIRM_REMOVE_REFATTRIBUTECERTIFICATIONPROCESSUS )
223 public String getConfirmRemoveRefAttributeCertificationProcessus( HttpServletRequest request )
224 {
225 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_REFATTRIBUTECERTIFICATIONPROCESSUS ) );
226 UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_REFATTRIBUTECERTIFICATIONPROCESSUS ) );
227 url.addParameter( PARAMETER_ID_REFATTRIBUTECERTIFICATIONPROCESSUS, nId );
228
229 String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_REFATTRIBUTECERTIFICATIONPROCESSUS, url.getUrl( ),
230 AdminMessage.TYPE_CONFIRMATION );
231
232 return redirect( request, strMessageUrl );
233 }
234
235
236
237
238
239
240
241
242 @Action( ACTION_REMOVE_REFATTRIBUTECERTIFICATIONPROCESSUS )
243 public String doRemoveRefAttributeCertificationProcessus( HttpServletRequest request )
244 {
245 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_REFATTRIBUTECERTIFICATIONPROCESSUS ) );
246
247 final RefAttributeCertificationProcessus processus = RefAttributeCertificationProcessusHome.findByPrimaryKey( nId );
248 AttributeCertificationDefinitionService.instance( ).removeRefAttributeCertificationLevels( processus );
249 RefAttributeCertificationProcessusHome.remove( nId );
250 addInfo( INFO_REFATTRIBUTECERTIFICATIONPROCESSUS_REMOVED, getLocale( ) );
251
252 return redirectView( request, VIEW_MANAGE_REFATTRIBUTECERTIFICATIONPROCESSUSS );
253 }
254
255
256
257
258
259
260
261
262 @View( VIEW_MODIFY_REFATTRIBUTECERTIFICATIONPROCESSUS )
263 public String getModifyRefAttributeCertificationProcessus( HttpServletRequest request )
264 {
265 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_REFATTRIBUTECERTIFICATIONPROCESSUS ) );
266
267 if ( _refattributecertificationprocessus == null || ( _refattributecertificationprocessus.getId( ) != nId ) )
268 {
269 _refattributecertificationprocessus = RefAttributeCertificationProcessusHome.findByPrimaryKey( nId );
270 if ( _refattributecertificationprocessus == null )
271 {
272 throw new AppException( ERROR_RESOURCE_NOT_FOUND );
273 }
274
275 }
276
277 Map<String, Object> model = getModel( );
278 model.put( MARK_REFATTRIBUTECERTIFICATIONPROCESSUS, _refattributecertificationprocessus );
279 model.put( MARK_ATTRIBUTE_LEVELS_LIST, RefAttributeCertificationProcessusHome.selectAttributeLevels( _refattributecertificationprocessus ) );
280 model.put( MARK_AVAILAIBLE_LEVELS_LIST, RefAttributeCertificationProcessusHome.selectCertificationLevels( ).stream( )
281 .sorted( Comparator.comparing( RefCertificationLevel::getLevel ) ).collect( Collectors.toList( ) ) );
282 model.put( SecurityTokenService.MARK_TOKEN, SecurityTokenService.getInstance( ).getToken( request, ACTION_MODIFY_REFATTRIBUTECERTIFICATIONPROCESSUS ) );
283
284 return getPage( PROPERTY_PAGE_TITLE_MODIFY_REFATTRIBUTECERTIFICATIONPROCESSUS, TEMPLATE_MODIFY_REFATTRIBUTECERTIFICATIONPROCESSUS, model );
285 }
286
287
288
289
290
291
292
293
294
295 @Action( ACTION_MODIFY_REFATTRIBUTECERTIFICATIONPROCESSUS )
296 public String doModifyRefAttributeCertificationProcessus( HttpServletRequest request ) throws AccessDeniedException
297 {
298 populate( _refattributecertificationprocessus, request, getLocale( ) );
299
300 if ( !SecurityTokenService.getInstance( ).validate( request, ACTION_MODIFY_REFATTRIBUTECERTIFICATIONPROCESSUS ) )
301 {
302 throw new AccessDeniedException( "Invalid security token" );
303 }
304
305
306 if ( !validateBean( _refattributecertificationprocessus, VALIDATION_ATTRIBUTES_PREFIX ) )
307 {
308 return redirect( request, VIEW_MODIFY_REFATTRIBUTECERTIFICATIONPROCESSUS, PARAMETER_ID_REFATTRIBUTECERTIFICATIONPROCESSUS,
309 _refattributecertificationprocessus.getId( ) );
310 }
311
312 RefAttributeCertificationProcessusHome.update( _refattributecertificationprocessus );
313
314
315 AttributeCertificationDefinitionService.instance( ).removeRefAttributeCertificationLevels( _refattributecertificationprocessus );
316 List<RefAttributeCertificationLevel> refAttributeCertificationLevelList = new ArrayList<>(
317 getRefAttributeCertificationLevelsFromRequest( request ).values( ) );
318 AttributeCertificationDefinitionService.instance( ).addRefAttributeCertificationLevels(
319 refAttributeCertificationLevelList.stream( ).filter( certif -> certif.getRefCertificationLevel( ) != null ).collect( Collectors.toList( ) ) );
320
321 addInfo( INFO_REFATTRIBUTECERTIFICATIONPROCESSUS_UPDATED, getLocale( ) );
322
323 return redirectView( request, VIEW_MANAGE_REFATTRIBUTECERTIFICATIONPROCESSUSS );
324 }
325
326
327
328
329
330
331
332
333 private Map<String, RefAttributeCertificationLevel> getRefAttributeCertificationLevelsFromRequest( HttpServletRequest request )
334 {
335 Map<String, RefAttributeCertificationLevel> mapAttributesRights = new HashMap<String, RefAttributeCertificationLevel>( );
336 String [ ] tabIdCertificationLevels = request.getParameterValues( PARAMETER_CERTICATION_LEVEL );
337
338 for ( int nCpt = 0; ( tabIdCertificationLevels != null ) && ( nCpt < tabIdCertificationLevels.length ); nCpt++ )
339 {
340 String strIdAttribute = tabIdCertificationLevels [nCpt];
341 RefAttributeCertificationLeveleCertificationLevel.html#RefAttributeCertificationLevel">RefAttributeCertificationLevel refAttributeCertificationLevel = new RefAttributeCertificationLevel( );
342 refAttributeCertificationLevel.setRefAttributeCertificationProcessus( _refattributecertificationprocessus );
343 if ( strIdAttribute != null && strIdAttribute.contains( "," ) )
344 {
345 String [ ] keyAndLevel = strIdAttribute.split( "," );
346 refAttributeCertificationLevel.setAttributeKey( AttributeKeyHome.findByPrimaryKey( Integer.parseInt( keyAndLevel [0] ), false ) );
347 refAttributeCertificationLevel.setRefCertificationLevel( RefCertificationLevelHome.findByPrimaryKey( Integer.parseInt( keyAndLevel [1] ) ) );
348 }
349 mapAttributesRights.put( strIdAttribute, refAttributeCertificationLevel );
350 }
351
352 return mapAttributesRights;
353 }
354 }