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.web.features;
35
36 import java.util.HashMap;
37 import java.util.Map;
38
39 import javax.servlet.http.HttpServletRequest;
40
41 import fr.paris.lutece.portal.business.right.Level;
42 import fr.paris.lutece.portal.business.right.LevelHome;
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.template.AppTemplateService;
48 import fr.paris.lutece.portal.web.admin.AdminFeaturesPageJspBean;
49 import fr.paris.lutece.portal.web.constants.Messages;
50 import fr.paris.lutece.portal.web.constants.Parameters;
51 import fr.paris.lutece.portal.web.dashboard.AdminDashboardJspBean;
52 import fr.paris.lutece.util.html.HtmlTemplate;
53
54
55
56
57 public class LevelsJspBean extends AdminFeaturesPageJspBean
58 {
59 private static final long serialVersionUID = 5513182604869973362L;
60
61
62 public static final String RIGHT_MANAGE_LEVELS = "CORE_LEVEL_RIGHT_MANAGEMENT";
63
64
65 private static final String PROPERTY_PAGE_TITLE_CREATE_LEVEL = "portal.features.create_level.pageTitle";
66 private static final String PROPERTY_PAGE_TITLE_MODIFY_LEVEL = "portal.features.modify_level.pageTitle";
67
68
69 private static final String MARK_LEVEL = "level";
70
71
72 private static final String TEMPLATE_CREATE_LEVEL = "admin/features/create_level.html";
73 private static final String TEMPLATE_MODIFY_LEVEL = "admin/features/modify_level.html";
74
75 private static final String ANCHOR_RIGHT_LEVELS = "right_levels";
76
77
78
79
80
81
82
83
84 public String getCreateLevel( HttpServletRequest request )
85 {
86 setPageTitleProperty( PROPERTY_PAGE_TITLE_CREATE_LEVEL );
87
88 Map<String, Object> model = new HashMap<>( );
89 model.put( SecurityTokenService.MARK_TOKEN, SecurityTokenService.getInstance( ).getToken( request, TEMPLATE_CREATE_LEVEL ) );
90 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_LEVEL, getLocale( ), model );
91
92 return getAdminPage( template.getHtml( ) );
93 }
94
95
96
97
98
99
100
101
102
103
104 public String doCreateLevel( HttpServletRequest request ) throws AccessDeniedException
105 {
106 String strName = request.getParameter( Parameters.LEVEL_NAME );
107
108
109 if ( strName.equals( "" ) )
110 {
111 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
112 }
113 if ( !SecurityTokenService.getInstance( ).validate( request, TEMPLATE_CREATE_LEVEL ) )
114 {
115 throw new AccessDeniedException( ERROR_INVALID_TOKEN );
116 }
117 Levelal/business/right/Level.html#Level">Level level = new Level( );
118 level.setName( strName );
119 LevelHome.create( level );
120
121
122 return getAdminDashboardsUrl( request, ANCHOR_RIGHT_LEVELS );
123 }
124
125
126
127
128
129
130
131
132 public String getModifyLevel( HttpServletRequest request )
133 {
134 setPageTitleProperty( PROPERTY_PAGE_TITLE_MODIFY_LEVEL );
135
136 String strId = request.getParameter( Parameters.LEVEL_ID );
137
138 Level level = LevelHome.findByPrimaryKey( Integer.parseInt( strId ) );
139
140 if ( level == null )
141 {
142 return getAdminDashboardsUrl( request, ANCHOR_RIGHT_LEVELS );
143 }
144
145 HashMap<String, Object> model = new HashMap<>( );
146 model.put( MARK_LEVEL, level );
147 model.put( SecurityTokenService.MARK_TOKEN, SecurityTokenService.getInstance( ).getToken( request, TEMPLATE_MODIFY_LEVEL ) );
148
149 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_LEVEL, getLocale( ), model );
150
151 return getAdminPage( template.getHtml( ) );
152 }
153
154
155
156
157
158
159
160
161
162
163 public String doModifyLevel( HttpServletRequest request ) throws AccessDeniedException
164 {
165 String strId = request.getParameter( Parameters.LEVEL_ID );
166 String strName = request.getParameter( Parameters.LEVEL_NAME );
167
168
169 if ( strName.equals( "" ) )
170 {
171 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
172 }
173 if ( !SecurityTokenService.getInstance( ).validate( request, TEMPLATE_MODIFY_LEVEL ) )
174 {
175 throw new AccessDeniedException( ERROR_INVALID_TOKEN );
176 }
177
178 Level level = LevelHome.findByPrimaryKey( Integer.parseInt( strId ) );
179 level.setName( strName );
180 LevelHome.update( level );
181
182
183 return getAdminDashboardsUrl( request, ANCHOR_RIGHT_LEVELS );
184 }
185 }