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.releaser.web; |
35 | |
|
36 | |
import fr.paris.lutece.plugins.releaser.business.Cluster; |
37 | |
import fr.paris.lutece.plugins.releaser.business.ClusterHome; |
38 | |
import fr.paris.lutece.plugins.releaser.business.ReleaserUser; |
39 | |
import fr.paris.lutece.plugins.releaser.business.Site; |
40 | |
import fr.paris.lutece.plugins.releaser.business.SiteHome; |
41 | |
import fr.paris.lutece.plugins.releaser.service.SiteService; |
42 | |
import fr.paris.lutece.plugins.releaser.util.ReleaserUtils; |
43 | |
import fr.paris.lutece.portal.service.message.AdminMessage; |
44 | |
import fr.paris.lutece.portal.service.message.AdminMessageService; |
45 | |
import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller; |
46 | |
import fr.paris.lutece.portal.util.mvc.commons.annotations.Action; |
47 | |
import fr.paris.lutece.portal.util.mvc.commons.annotations.View; |
48 | |
import fr.paris.lutece.util.url.UrlItem; |
49 | |
|
50 | |
import java.util.List; |
51 | |
import java.util.Map; |
52 | |
import javax.servlet.http.HttpServletRequest; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
@Controller( controllerJsp = "ManageClusters.jsp", controllerPath = "jsp/admin/plugins/releaser/", right = "RELEASER_MANAGEMENT" ) |
58 | 0 | public class ClusterJspBean extends ManageSitesJspBean |
59 | |
{ |
60 | |
|
61 | |
private static final String TEMPLATE_MANAGE_CLUSTERS = "/admin/plugins/releaser/manage_clusters.html"; |
62 | |
private static final String TEMPLATE_CREATE_CLUSTER = "/admin/plugins/releaser/create_cluster.html"; |
63 | |
private static final String TEMPLATE_MODIFY_CLUSTER = "/admin/plugins/releaser/modify_cluster.html"; |
64 | |
private static final String TEMPLATE_CREATE_SITE = "/admin/plugins/releaser/create_site.html"; |
65 | |
private static final String TEMPLATE_MODIFY_SITE = "/admin/plugins/releaser/modify_site.html"; |
66 | |
|
67 | |
|
68 | |
private static final String PARAMETER_ID_CLUSTER = "id"; |
69 | |
private static final String PARAMETER_ID_SITE = "id"; |
70 | |
|
71 | |
|
72 | |
private static final String PROPERTY_PAGE_TITLE_MANAGE_CLUSTERS = "releaser.manage_clusters.pageTitle"; |
73 | |
private static final String PROPERTY_PAGE_TITLE_MODIFY_CLUSTER = "releaser.modify_cluster.pageTitle"; |
74 | |
private static final String PROPERTY_PAGE_TITLE_CREATE_CLUSTER = "releaser.create_cluster.pageTitle"; |
75 | |
private static final String PROPERTY_PAGE_TITLE_MODIFY_SITE = "releaser.modify_site.pageTitle"; |
76 | |
private static final String PROPERTY_PAGE_TITLE_CREATE_SITE = "releaser.create_site.pageTitle"; |
77 | |
|
78 | |
|
79 | |
private static final String MESSAGE_CONFIRM_REMOVE_SITE = "releaser.message.confirmRemoveSite"; |
80 | |
|
81 | |
|
82 | |
private static final String MARK_CLUSTER_LIST = "cluster_list"; |
83 | |
private static final String MARK_CLUSTER = "cluster"; |
84 | |
private static final String MARK_CLUSTERS_LIST = "clusters_list"; |
85 | |
private static final String MARK_SITE = "site"; |
86 | |
private static final String MARK_USER = "user"; |
87 | |
private static final String MARK_IS_APPLICATION_ACCOUNT = "is_application_account"; |
88 | |
|
89 | |
|
90 | |
|
91 | |
private static final String JSP_MANAGE_CLUSTERS = "jsp/admin/plugins/releaser/ManageClusters.jsp"; |
92 | |
private static final String JSP_MANAGE_SITE_RELEASE = "ManageSiteRelease.jsp"; |
93 | |
private static final String JSP_MANAGE_COMPONENT = "ManageComponent.jsp"; |
94 | |
|
95 | |
|
96 | |
private static final String MESSAGE_CONFIRM_REMOVE_CLUSTER = "releaser.message.confirmRemoveCluster"; |
97 | |
|
98 | |
|
99 | |
private static final String VALIDATION_ATTRIBUTES_PREFIX = "releaser.model.entity.cluster.attribute."; |
100 | |
private static final String VALIDATION_ATTRIBUTES_SITE_PREFIX = "releaser.model.entity.site.attribute."; |
101 | |
private static final String VALIDATION_ATTRIBUTES_USER_PREFIX = "releaser.model.entity.user.attribute."; |
102 | |
|
103 | |
|
104 | |
|
105 | |
private static final String VIEW_MANAGE_CLUSTERS = "manageClusters"; |
106 | |
private static final String VIEW_CREATE_CLUSTER = "createCluster"; |
107 | |
private static final String VIEW_MODIFY_CLUSTER = "modifyCluster"; |
108 | |
private static final String VIEW_MANAGE_SITES = "manageSites"; |
109 | |
private static final String VIEW_CREATE_SITE = "createSite"; |
110 | |
private static final String VIEW_MODIFY_SITE = "modifySite"; |
111 | |
|
112 | |
|
113 | |
private static final String ACTION_CREATE_CLUSTER = "createCluster"; |
114 | |
private static final String ACTION_RELEASE_SITE = "releaseSite"; |
115 | |
private static final String ACTION_RELEASE_COMPONENT = "releaseComponent"; |
116 | |
|
117 | |
|
118 | |
private static final String ACTION_MODIFY_CLUSTER = "modifyCluster"; |
119 | |
private static final String ACTION_REMOVE_CLUSTER = "removeCluster"; |
120 | |
private static final String ACTION_CONFIRM_REMOVE_CLUSTER = "confirmRemoveCluster"; |
121 | |
private static final String ACTION_CREATE_SITE = "createSite"; |
122 | |
private static final String ACTION_MODIFY_SITE = "modifySite"; |
123 | |
private static final String ACTION_REMOVE_SITE = "removeSite"; |
124 | |
private static final String ACTION_CONFIRM_REMOVE_SITE = "confirmRemoveSite"; |
125 | |
|
126 | |
|
127 | |
private static final String INFO_CLUSTER_CREATED = "releaser.info.cluster.created"; |
128 | |
private static final String INFO_CLUSTER_UPDATED = "releaser.info.cluster.updated"; |
129 | |
private static final String INFO_CLUSTER_REMOVED = "releaser.info.cluster.removed"; |
130 | |
private static final String INFO_SITE_CREATED = "releaser.info.site.created"; |
131 | |
private static final String INFO_SITE_UPDATED = "releaser.info.site.updated"; |
132 | |
private static final String INFO_SITE_REMOVED = "releaser.info.site.removed"; |
133 | |
|
134 | |
|
135 | |
private Cluster _cluster; |
136 | |
private Site _site; |
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
@View( value = VIEW_MANAGE_CLUSTERS, defaultView = true ) |
146 | |
public String getManageClusters( HttpServletRequest request ) |
147 | |
{ |
148 | 0 | _cluster = null; |
149 | 0 | _site = null; |
150 | 0 | List<Cluster> listClusters = ClusterHome.getClustersList( ); |
151 | 0 | Map<String, Object> model = getPaginatedListModel( request, MARK_CLUSTER_LIST, listClusters, JSP_MANAGE_CLUSTERS ); |
152 | 0 | model.put( MARK_USER, ReleaserUtils.getReleaserUser( request, getLocale( ) )); |
153 | 0 | model.put( MARK_IS_APPLICATION_ACCOUNT, ReleaserUtils.isApplicationAccountEnable( )); |
154 | |
|
155 | 0 | return getPage( PROPERTY_PAGE_TITLE_MANAGE_CLUSTERS, TEMPLATE_MANAGE_CLUSTERS, model ); |
156 | |
} |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
@View( VIEW_CREATE_CLUSTER ) |
166 | |
public String getCreateCluster( HttpServletRequest request ) |
167 | |
{ |
168 | 0 | _cluster = ( _cluster != null ) ? _cluster : new Cluster( ); |
169 | |
|
170 | 0 | Map<String, Object> model = getModel( ); |
171 | 0 | model.put( MARK_CLUSTER, _cluster ); |
172 | |
|
173 | 0 | return getPage( PROPERTY_PAGE_TITLE_CREATE_CLUSTER, TEMPLATE_CREATE_CLUSTER, model ); |
174 | |
} |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
@Action( ACTION_CREATE_CLUSTER ) |
185 | |
public String doCreateCluster( HttpServletRequest request ) |
186 | |
{ |
187 | 0 | populate( _cluster, request ); |
188 | |
|
189 | |
|
190 | 0 | if ( !validateBean( _cluster, VALIDATION_ATTRIBUTES_PREFIX ) ) |
191 | |
{ |
192 | 0 | return redirectView( request, VIEW_CREATE_CLUSTER ); |
193 | |
} |
194 | |
|
195 | 0 | ClusterHome.create( _cluster ); |
196 | 0 | addInfo( INFO_CLUSTER_CREATED, getLocale( ) ); |
197 | |
|
198 | 0 | return redirectView( request, VIEW_MANAGE_CLUSTERS ); |
199 | |
} |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
@Action( ACTION_RELEASE_COMPONENT ) |
209 | |
public String doReleaseComponent( HttpServletRequest request ) |
210 | |
{ |
211 | 0 | ReleaserUser user=ReleaserUtils.getReleaserUser( request, getLocale( ) ); |
212 | 0 | if(user==null) |
213 | |
{ |
214 | 0 | user=new ReleaserUser( ); |
215 | |
|
216 | |
} |
217 | 0 | populate( user, request ); |
218 | |
|
219 | |
|
220 | |
|
221 | 0 | if ( !validateBean( user, VALIDATION_ATTRIBUTES_USER_PREFIX ) ) |
222 | |
{ |
223 | |
|
224 | 0 | redirectView( request, VIEW_MANAGE_CLUSTERS ); |
225 | |
} |
226 | |
|
227 | 0 | ReleaserUtils.setReleaserUser( request, user ); |
228 | |
|
229 | 0 | return redirect( request, JSP_MANAGE_COMPONENT ); |
230 | |
} |
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
@Action( ACTION_RELEASE_SITE ) |
240 | |
public String doReleaseSite( HttpServletRequest request ) |
241 | |
{ |
242 | 0 | ReleaserUser user=ReleaserUtils.getReleaserUser( request, getLocale( ) ); |
243 | 0 | String strIdSite=request.getParameter( PARAMETER_ID_SITE ); |
244 | 0 | if(user==null) |
245 | |
{ |
246 | 0 | user=new ReleaserUser( ); |
247 | |
|
248 | |
} |
249 | 0 | populate( user, request ); |
250 | |
|
251 | |
|
252 | |
|
253 | 0 | if ( !validateBean( user, VALIDATION_ATTRIBUTES_USER_PREFIX ) ) |
254 | |
{ |
255 | |
|
256 | 0 | redirectView( request, VIEW_MANAGE_CLUSTERS ); |
257 | |
} |
258 | |
|
259 | 0 | user.setSvnComponentAccountLogin( user.getSvnSiteAccountLogin( ) ); |
260 | 0 | user.setSvnComponentAccountPassword( user.getSvnSiteAccountPassword( ) ); |
261 | |
|
262 | 0 | ReleaserUtils.setReleaserUser( request, user ); |
263 | |
|
264 | 0 | return redirect( request, JSP_MANAGE_SITE_RELEASE+"?id_site="+strIdSite ); |
265 | |
} |
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
@Action( ACTION_CONFIRM_REMOVE_CLUSTER ) |
275 | |
public String getConfirmRemoveCluster( HttpServletRequest request ) |
276 | |
{ |
277 | 0 | int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CLUSTER ) ); |
278 | 0 | UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_CLUSTER ) ); |
279 | 0 | url.addParameter( PARAMETER_ID_CLUSTER, nId ); |
280 | |
|
281 | 0 | String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_CLUSTER, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION ); |
282 | |
|
283 | 0 | return redirect( request, strMessageUrl ); |
284 | |
} |
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
@Action( ACTION_REMOVE_CLUSTER ) |
294 | |
public String doRemoveCluster( HttpServletRequest request ) |
295 | |
{ |
296 | 0 | int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CLUSTER ) ); |
297 | 0 | ClusterHome.remove( nId ); |
298 | 0 | addInfo( INFO_CLUSTER_REMOVED, getLocale( ) ); |
299 | |
|
300 | 0 | return redirectView( request, VIEW_MANAGE_CLUSTERS ); |
301 | |
} |
302 | |
|
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | |
@View( VIEW_MODIFY_CLUSTER ) |
311 | |
public String getModifyCluster( HttpServletRequest request ) |
312 | |
{ |
313 | 0 | int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CLUSTER ) ); |
314 | |
|
315 | 0 | if ( _cluster == null || ( _cluster.getId( ) != nId ) ) |
316 | |
{ |
317 | 0 | _cluster = ClusterHome.findByPrimaryKey( nId ); |
318 | |
} |
319 | |
|
320 | 0 | Map<String, Object> model = getModel( ); |
321 | 0 | model.put( MARK_CLUSTER, _cluster ); |
322 | |
|
323 | 0 | return getPage( PROPERTY_PAGE_TITLE_MODIFY_CLUSTER, TEMPLATE_MODIFY_CLUSTER, model ); |
324 | |
} |
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
@Action( ACTION_MODIFY_CLUSTER ) |
334 | |
public String doModifyCluster( HttpServletRequest request ) |
335 | |
{ |
336 | 0 | populate( _cluster, request ); |
337 | |
|
338 | |
|
339 | 0 | if ( !validateBean( _cluster, VALIDATION_ATTRIBUTES_PREFIX ) ) |
340 | |
{ |
341 | 0 | return redirect( request, VIEW_MODIFY_CLUSTER, PARAMETER_ID_CLUSTER, _cluster.getId( ) ); |
342 | |
} |
343 | |
|
344 | 0 | ClusterHome.update( _cluster ); |
345 | 0 | addInfo( INFO_CLUSTER_UPDATED, getLocale( ) ); |
346 | |
|
347 | 0 | return redirectView( request, VIEW_MANAGE_CLUSTERS ); |
348 | |
} |
349 | |
|
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | |
@View( VIEW_CREATE_SITE ) |
358 | |
public String getCreateSite( HttpServletRequest request ) |
359 | |
{ |
360 | 0 | _site = ( _site != null ) ? _site : new Site( ); |
361 | |
|
362 | 0 | Map<String, Object> model = getModel( ); |
363 | 0 | model.put( MARK_SITE, _site ); |
364 | 0 | model.put( MARK_CLUSTERS_LIST, ClusterHome.getClustersReferenceList( ) ); |
365 | |
|
366 | 0 | return getPage( PROPERTY_PAGE_TITLE_CREATE_SITE, TEMPLATE_CREATE_SITE, model ); |
367 | |
} |
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
|
376 | |
@Action( ACTION_CREATE_SITE ) |
377 | |
public String doCreateSite( HttpServletRequest request ) |
378 | |
{ |
379 | 0 | populate( _site, request ); |
380 | |
|
381 | |
|
382 | 0 | if ( !validateBean( _site, VALIDATION_ATTRIBUTES_SITE_PREFIX ) ) |
383 | |
{ |
384 | 0 | return redirectView( request, VIEW_CREATE_SITE ); |
385 | |
} |
386 | |
|
387 | 0 | SiteHome.create( _site ); |
388 | 0 | addInfo( INFO_SITE_CREATED, getLocale( ) ); |
389 | |
|
390 | 0 | return redirectView( request, VIEW_MANAGE_SITES ); |
391 | |
} |
392 | |
|
393 | |
|
394 | |
|
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
@Action( ACTION_CONFIRM_REMOVE_SITE ) |
401 | |
public String getConfirmRemoveSite( HttpServletRequest request ) |
402 | |
{ |
403 | 0 | int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_SITE ) ); |
404 | 0 | UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_SITE ) ); |
405 | 0 | url.addParameter( PARAMETER_ID_SITE, nId ); |
406 | |
|
407 | 0 | String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_SITE, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION ); |
408 | |
|
409 | 0 | return redirect( request, strMessageUrl ); |
410 | |
} |
411 | |
|
412 | |
|
413 | |
|
414 | |
|
415 | |
|
416 | |
|
417 | |
|
418 | |
|
419 | |
@Action( ACTION_REMOVE_SITE ) |
420 | |
public String doRemoveSite( HttpServletRequest request ) |
421 | |
{ |
422 | 0 | int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_SITE ) ); |
423 | 0 | SiteHome.remove( nId ); |
424 | 0 | SiteService.removeComponentAsProjectBySite( nId ); |
425 | 0 | addInfo( INFO_SITE_REMOVED, getLocale( ) ); |
426 | |
|
427 | 0 | return redirectView( request, VIEW_MANAGE_SITES ); |
428 | |
} |
429 | |
|
430 | |
|
431 | |
|
432 | |
|
433 | |
|
434 | |
|
435 | |
|
436 | |
|
437 | |
@View( VIEW_MODIFY_SITE ) |
438 | |
public String getModifySite( HttpServletRequest request ) |
439 | |
{ |
440 | 0 | int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_SITE ) ); |
441 | |
|
442 | 0 | if ( _site == null || ( _site.getId( ) != nId ) ) |
443 | |
{ |
444 | 0 | _site = SiteHome.findByPrimaryKey( nId ); |
445 | |
} |
446 | |
|
447 | 0 | Map<String, Object> model = getModel( ); |
448 | 0 | model.put( MARK_SITE, _site ); |
449 | |
|
450 | 0 | return getPage( PROPERTY_PAGE_TITLE_MODIFY_SITE, TEMPLATE_MODIFY_SITE, model ); |
451 | |
} |
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | |
@Action( ACTION_MODIFY_SITE ) |
461 | |
public String doModifySite( HttpServletRequest request ) |
462 | |
{ |
463 | 0 | populate( _site, request ); |
464 | |
|
465 | |
|
466 | 0 | if ( !validateBean( _site, VALIDATION_ATTRIBUTES_SITE_PREFIX ) ) |
467 | |
{ |
468 | 0 | return redirect( request, VIEW_MODIFY_SITE, PARAMETER_ID_SITE, _site.getId( ) ); |
469 | |
} |
470 | |
|
471 | 0 | SiteHome.update( _site ); |
472 | 0 | addInfo( INFO_SITE_UPDATED, getLocale( ) ); |
473 | |
|
474 | 0 | return redirectView( request, VIEW_MANAGE_SITES ); |
475 | |
} |
476 | |
|
477 | |
} |