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.Component; |
37 | |
import fr.paris.lutece.plugins.releaser.business.Site; |
38 | |
import fr.paris.lutece.plugins.releaser.business.WorkflowReleaseContext; |
39 | |
import fr.paris.lutece.plugins.releaser.service.SiteService; |
40 | |
import fr.paris.lutece.plugins.releaser.service.WorkflowReleaseContextService; |
41 | |
import fr.paris.lutece.plugins.releaser.util.ReleaserUtils; |
42 | |
import fr.paris.lutece.portal.service.template.AppTemplateService; |
43 | |
import fr.paris.lutece.portal.util.mvc.admin.MVCAdminJspBean; |
44 | |
import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller; |
45 | |
import fr.paris.lutece.portal.util.mvc.commons.annotations.Action; |
46 | |
import fr.paris.lutece.portal.util.mvc.commons.annotations.View; |
47 | |
import fr.paris.lutece.util.html.HtmlTemplate; |
48 | |
import fr.paris.lutece.util.json.AbstractJsonResponse; |
49 | |
import fr.paris.lutece.util.json.ErrorJsonResponse; |
50 | |
import fr.paris.lutece.util.json.JsonResponse; |
51 | |
import fr.paris.lutece.util.json.JsonUtil; |
52 | |
|
53 | |
import java.util.HashMap; |
54 | |
import java.util.List; |
55 | |
import java.util.Map; |
56 | |
import javax.servlet.http.HttpServletRequest; |
57 | |
|
58 | |
import org.apache.commons.lang.StringUtils; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
@Controller( controllerJsp = "ManageSiteRelease.jsp", controllerPath = "jsp/admin/plugins/releaser/", right = "RELEASER_MANAGEMENT" ) |
64 | 0 | public class ManageSiteReleaseJspBean extends MVCAdminJspBean |
65 | |
{ |
66 | |
|
67 | |
private static final String PARAMETER_SITE_ID = "id_site"; |
68 | |
private static final String PARAMETER_ARTIFACT_ID = "artifact_id"; |
69 | |
private static final String PARAMETER_ID_CONTEXT = "id_context"; |
70 | |
private static final String PARAMETER_TAG_INFORMATION = "tag_information"; |
71 | |
private static final String PARAMETER_OPEN_SITE_VERSION = "open_site_version"; |
72 | |
private static final String VALID_RELEASE_MODIF = "valid_release_modif_"; |
73 | |
|
74 | |
|
75 | |
private static final String VIEW_MANAGE_SITE_RELEASE = "siteRelease"; |
76 | |
private static final String VIEW_CONFIRM_RELEASE_SITE = "confirmReleaseSite"; |
77 | |
|
78 | |
private static final String VIEW_RELEASE_SITE_RESULT = "releaseSiteResult"; |
79 | |
|
80 | |
private static final String VIEW_RELEASE_INFO_JSON = "releaseInfoJson"; |
81 | |
private static final String VIEW_RELEASE_COMPONENT_HISTORY = "releaseComponentHistory"; |
82 | |
|
83 | |
|
84 | |
private static final String ACTION_RELEASE_SITE = "releaseSite"; |
85 | |
private static final String ACTION_DO_CONFIRM_RELEASE_SITE = "doConfirmReleaseSite"; |
86 | |
|
87 | |
private static final String ACTION_RELEASE_COMPONENT = "releaseComponent"; |
88 | |
private static final String ACTION_UPGRADE_COMPONENT = "upgradeComponent"; |
89 | |
private static final String ACTION_DOWNGRADE_COMPONENT = "downgradeComponent"; |
90 | |
private static final String ACTION_CANCEL_DOWNGRADE_COMPONENT = "cancelDowngradeComponent"; |
91 | |
private static final String ACTION_CANCEL_UPGRADE_COMPONENT = "cancelUpgradeComponent"; |
92 | |
|
93 | |
|
94 | |
private static final String ACTION_PROJECT_COMPONENT = "projectComponent"; |
95 | |
private static final String ACTION_CHANGE_COMPONENT_NEXT_RELEASE_VERSION = "versionComponent"; |
96 | |
private static final String ACTION_CHANGE_SITE_NEXT_RELEASE_VERSION = "versionSite"; |
97 | |
|
98 | |
private static final String TEMPLATE_PREPARE_SITE_RELEASE = "/admin/plugins/releaser/prepare_site_release.html"; |
99 | |
private static final String TEMPLATE_CONFIRM_RELEASE_SITE = "/admin/plugins/releaser/confirm_release_site.html"; |
100 | |
|
101 | |
private static final String TEMPLATE_RELEASE_SITE_RESULT = "/admin/plugins/releaser/release_site_result.html"; |
102 | |
|
103 | |
private static final String TEMPLATE_RELEASE_COMPONENT_HISTORY = "/admin/plugins/releaser/release_component_history.html"; |
104 | |
|
105 | |
private static final String MARK_SITE = "site"; |
106 | |
private static final String MARK_MODIF_VALIDATED = "modif_validated"; |
107 | |
|
108 | |
private static final String MARK_RELEASE_CTX_RESULT = "release_ctx_result"; |
109 | |
private static final String MARK_OPEN_SITE_VERSION = "open_site_version"; |
110 | |
|
111 | |
private static final String MARK_RELEASE_COMPONENT_HISTORY_LIST = "release_component_history_list"; |
112 | |
|
113 | |
private static final String JSP_MANAGE_CLUSTERS = "ManageClusters.jsp"; |
114 | |
private static final String JSP_MANAGE_RELEASE_SITE = "ManageSiteRelease.jsp"; |
115 | |
|
116 | |
private static final String JSON_ERROR_RELEASE_CONTEXT_NOT_EXIST = "RELEASE_CONTEXT_NOT_EXIST"; |
117 | |
|
118 | |
private static final String MESSAGE_ERROR_INFORMATION = "releaser.message.errorInfomationReleaseNotChecked"; |
119 | |
|
120 | |
private Site _site; |
121 | |
private Map<String, Integer> _mapReleaseSiteContext; |
122 | |
private Map<String, Boolean> _modifValidated; |
123 | |
|
124 | |
|
125 | |
@View( value = VIEW_MANAGE_SITE_RELEASE, defaultView = true ) |
126 | |
public String getPrepareSiteRelease( HttpServletRequest request ) |
127 | |
{ |
128 | 0 | _modifValidated=null; |
129 | 0 | String strSiteId = request.getParameter( PARAMETER_SITE_ID ); |
130 | 0 | if ( ReleaserUtils.getReleaserUser( request, getLocale( ) ) == null ) |
131 | |
{ |
132 | 0 | return redirect( request, JSP_MANAGE_CLUSTERS ); |
133 | |
} |
134 | 0 | if ( ( _site == null ) || ( strSiteId != null ) ) |
135 | |
{ |
136 | |
try |
137 | |
{ |
138 | 0 | int nSiteId = 0; |
139 | 0 | nSiteId = Integer.parseInt( strSiteId ); |
140 | 0 | _site = SiteService.getSite( nSiteId, request, getLocale( ) ); |
141 | |
} |
142 | 0 | catch( NumberFormatException e ) |
143 | |
{ |
144 | 0 | return redirect( request, JSP_MANAGE_CLUSTERS ); |
145 | 0 | } |
146 | |
} |
147 | |
|
148 | 0 | SiteService.buildComments( _site, getLocale( ) ); |
149 | 0 | Map<String, Object> model = getModel( ); |
150 | 0 | model.put( MARK_SITE, _site ); |
151 | 0 | model.put( MARK_OPEN_SITE_VERSION, request.getParameter( PARAMETER_OPEN_SITE_VERSION ) ); |
152 | 0 | HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PREPARE_SITE_RELEASE, getLocale( ), model ); |
153 | 0 | return template.getHtml( ); |
154 | |
} |
155 | |
|
156 | |
@View( value = VIEW_CONFIRM_RELEASE_SITE ) |
157 | |
public String getConfirmReleaseSite( HttpServletRequest request ) |
158 | |
{ |
159 | |
|
160 | |
|
161 | 0 | if(_modifValidated == null) |
162 | |
{ |
163 | 0 | _modifValidated=new HashMap<String, Boolean>(); |
164 | |
|
165 | |
} |
166 | 0 | if ( ReleaserUtils.getReleaserUser( request, getLocale( ) ) == null ) |
167 | |
{ |
168 | 0 | return redirect( request, JSP_MANAGE_CLUSTERS ); |
169 | |
} |
170 | 0 | if ( _site == null ) |
171 | |
{ |
172 | 0 | return redirect( request, JSP_MANAGE_CLUSTERS ); |
173 | |
|
174 | |
} |
175 | |
|
176 | 0 | Map<String, Object> model = getModel( ); |
177 | 0 | model.put( MARK_SITE, _site ); |
178 | 0 | model.put( MARK_MODIF_VALIDATED, _modifValidated ); |
179 | |
|
180 | |
|
181 | 0 | HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CONFIRM_RELEASE_SITE, getLocale( ), model ); |
182 | |
|
183 | 0 | return template.getHtml( ); |
184 | |
} |
185 | |
|
186 | |
@View( value = VIEW_RELEASE_COMPONENT_HISTORY ) |
187 | |
public String getReleaseComponentHistory( HttpServletRequest request ) |
188 | |
{ |
189 | |
|
190 | 0 | String strArtifactId = request.getParameter( PARAMETER_ARTIFACT_ID ); |
191 | 0 | List<WorkflowReleaseContext> listReleaseComponentHistory = null; |
192 | 0 | if ( !StringUtils.isEmpty( strArtifactId ) ) |
193 | |
{ |
194 | |
|
195 | 0 | listReleaseComponentHistory = WorkflowReleaseContextService.getService( ).getListWorkflowReleaseContextHistory( strArtifactId ); |
196 | |
|
197 | |
} |
198 | |
|
199 | 0 | Map<String, Object> model = getModel( ); |
200 | 0 | model.put( MARK_RELEASE_COMPONENT_HISTORY_LIST, listReleaseComponentHistory ); |
201 | 0 | HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_RELEASE_COMPONENT_HISTORY, getLocale( ), model ); |
202 | 0 | return template.getHtml( ); |
203 | |
|
204 | |
} |
205 | |
|
206 | |
@View( value = VIEW_RELEASE_INFO_JSON ) |
207 | |
public String getReleaseInfoJson( HttpServletRequest request ) |
208 | |
{ |
209 | |
|
210 | 0 | AbstractJsonResponse jsonResponse = null; |
211 | |
|
212 | 0 | String strIdReleaseContext = request.getParameter( PARAMETER_ID_CONTEXT ); |
213 | |
|
214 | 0 | if ( !StringUtils.isEmpty( strIdReleaseContext ) ) |
215 | |
{ |
216 | 0 | WorkflowReleaseContext context = WorkflowReleaseContextService.getService( ).getWorkflowReleaseContext( |
217 | 0 | ReleaserUtils.convertStringToInt( strIdReleaseContext ) ); |
218 | 0 | if ( context != null ) |
219 | |
{ |
220 | 0 | jsonResponse = new JsonResponse( context ); |
221 | |
|
222 | |
} |
223 | |
else |
224 | |
{ |
225 | 0 | jsonResponse = new ErrorJsonResponse( JSON_ERROR_RELEASE_CONTEXT_NOT_EXIST ); |
226 | |
|
227 | |
} |
228 | 0 | } |
229 | |
else |
230 | |
{ |
231 | 0 | jsonResponse = new ErrorJsonResponse( JSON_ERROR_RELEASE_CONTEXT_NOT_EXIST ); |
232 | |
|
233 | |
} |
234 | 0 | return JsonUtil.buildJsonResponse( jsonResponse ); |
235 | |
|
236 | |
} |
237 | |
|
238 | |
@Action( ACTION_DOWNGRADE_COMPONENT ) |
239 | |
public String doDowngradeComponent( HttpServletRequest request ) |
240 | |
{ |
241 | 0 | String strArtifactId = request.getParameter( PARAMETER_ARTIFACT_ID ); |
242 | 0 | SiteService.downgradeComponent( _site, strArtifactId ); |
243 | |
|
244 | 0 | return redirectView( request, VIEW_MANAGE_SITE_RELEASE ); |
245 | |
} |
246 | |
|
247 | |
@Action( ACTION_CANCEL_DOWNGRADE_COMPONENT ) |
248 | |
public String doCancelDowngradeComponent( HttpServletRequest request ) |
249 | |
{ |
250 | 0 | String strArtifactId = request.getParameter( PARAMETER_ARTIFACT_ID ); |
251 | 0 | SiteService.cancelDowngradeComponent( _site, strArtifactId ); |
252 | |
|
253 | 0 | return redirectView( request, VIEW_MANAGE_SITE_RELEASE ); |
254 | |
} |
255 | |
|
256 | |
@Action( ACTION_UPGRADE_COMPONENT ) |
257 | |
public String doUpgradeComponent( HttpServletRequest request ) |
258 | |
{ |
259 | 0 | String strArtifactId = request.getParameter( PARAMETER_ARTIFACT_ID ); |
260 | 0 | SiteService.upgradeComponent( _site, strArtifactId ); |
261 | |
|
262 | 0 | return redirectView( request, VIEW_MANAGE_SITE_RELEASE ); |
263 | |
} |
264 | |
|
265 | |
@Action( ACTION_CANCEL_UPGRADE_COMPONENT ) |
266 | |
public String doCancelUpgradeComponent( HttpServletRequest request ) |
267 | |
{ |
268 | |
|
269 | 0 | String strArtifactId = request.getParameter( PARAMETER_ARTIFACT_ID ); |
270 | 0 | SiteService.cancelUpgradeComponent( _site, strArtifactId ); |
271 | |
|
272 | 0 | return redirectView( request, VIEW_MANAGE_SITE_RELEASE ); |
273 | |
} |
274 | |
|
275 | |
@Action( ACTION_RELEASE_COMPONENT ) |
276 | |
public String doReleaseComponent( HttpServletRequest request ) |
277 | |
{ |
278 | 0 | String strArtifactId = request.getParameter( PARAMETER_ARTIFACT_ID ); |
279 | 0 | AbstractJsonResponse jsonResponse = null; |
280 | 0 | Integer nidContext = SiteService.releaseComponent( _site, strArtifactId, getLocale( ), getUser( ), request ); |
281 | 0 | jsonResponse = new JsonResponse( nidContext ); |
282 | 0 | if ( ReleaserUtils.getReleaserUser( request, getLocale( ) ) == null ) |
283 | |
{ |
284 | 0 | return redirect( request, JSP_MANAGE_CLUSTERS ); |
285 | |
} |
286 | |
|
287 | 0 | return JsonUtil.buildJsonResponse( jsonResponse ); |
288 | |
} |
289 | |
|
290 | |
@Action( ACTION_DO_CONFIRM_RELEASE_SITE ) |
291 | |
public String doConfirmReleaseSite( HttpServletRequest request ) |
292 | |
{ |
293 | |
|
294 | 0 | if ( ReleaserUtils.getReleaserUser( request, getLocale( ) ) == null ) |
295 | |
{ |
296 | 0 | return redirect( request, JSP_MANAGE_CLUSTERS ); |
297 | |
} |
298 | |
|
299 | 0 | String strCheckedReleaseInfo = null; |
300 | 0 | if ( _site != null && _site.getComponents( ) != null ) |
301 | |
{ |
302 | |
|
303 | 0 | if(_modifValidated==null) |
304 | |
{ |
305 | 0 | _modifValidated=new HashMap<String, Boolean>(); |
306 | |
|
307 | |
} |
308 | 0 | for ( Component component : _site.getComponents( ) ) |
309 | |
{ |
310 | |
|
311 | 0 | strCheckedReleaseInfo = request.getParameter( VALID_RELEASE_MODIF + component.getArtifactId( ) ); |
312 | |
|
313 | 0 | _modifValidated.put( component.getArtifactId( ), strCheckedReleaseInfo != null && strCheckedReleaseInfo.equals( Boolean.TRUE.toString( ) ) ); |
314 | |
|
315 | 0 | } |
316 | |
|
317 | |
|
318 | 0 | for ( Component component : _site.getComponents( ) ) |
319 | |
{ |
320 | |
|
321 | 0 | if (Boolean.TRUE!=_modifValidated.get( component.getArtifactId( ) ) ) |
322 | |
{ |
323 | 0 | addError( MESSAGE_ERROR_INFORMATION, getLocale( ) ); |
324 | 0 | return redirectView( request, VIEW_CONFIRM_RELEASE_SITE ); |
325 | |
} |
326 | 0 | } |
327 | |
|
328 | |
} |
329 | 0 | _mapReleaseSiteContext = SiteService.releaseSite( _site, getLocale( ), getUser( ), request ); |
330 | |
|
331 | 0 | return redirectView( request, VIEW_RELEASE_SITE_RESULT ); |
332 | |
} |
333 | |
|
334 | |
@Action( ACTION_RELEASE_SITE ) |
335 | |
public String doReleaseSite( HttpServletRequest request ) |
336 | |
{ |
337 | |
|
338 | 0 | if ( ReleaserUtils.getReleaserUser( request, getLocale( ) ) == null ) |
339 | |
{ |
340 | 0 | return redirect( request, JSP_MANAGE_CLUSTERS ); |
341 | |
} |
342 | |
|
343 | 0 | String strTagInformation = request.getParameter( PARAMETER_TAG_INFORMATION ); |
344 | 0 | _site.setTagInformation( strTagInformation ); |
345 | 0 | return redirectView( request, VIEW_CONFIRM_RELEASE_SITE ); |
346 | |
} |
347 | |
|
348 | |
@View( value = VIEW_RELEASE_SITE_RESULT ) |
349 | |
public String getReleaseSiteResult( HttpServletRequest request ) |
350 | |
{ |
351 | 0 | if ( _mapReleaseSiteContext == null || _site == null ) |
352 | |
{ |
353 | 0 | return redirectView( request, VIEW_MANAGE_SITE_RELEASE ); |
354 | |
} |
355 | 0 | Map<String, Object> model = getModel( ); |
356 | 0 | model.put( MARK_SITE, _site ); |
357 | 0 | model.put( MARK_RELEASE_CTX_RESULT, _mapReleaseSiteContext ); |
358 | 0 | HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_RELEASE_SITE_RESULT, getLocale( ), model ); |
359 | 0 | String strTemplate = template.getHtml( ); |
360 | |
|
361 | 0 | return strTemplate; |
362 | |
|
363 | |
} |
364 | |
|
365 | |
@Action( ACTION_PROJECT_COMPONENT ) |
366 | |
public String doProjectComponent( HttpServletRequest request ) |
367 | |
{ |
368 | 0 | String strArtifactId = request.getParameter( PARAMETER_ARTIFACT_ID ); |
369 | 0 | SiteService.toggleProjectComponent( _site, strArtifactId ); |
370 | |
|
371 | 0 | return redirectView( request, VIEW_MANAGE_SITE_RELEASE ); |
372 | |
} |
373 | |
|
374 | |
@Action( ACTION_CHANGE_COMPONENT_NEXT_RELEASE_VERSION ) |
375 | |
public String doChangeComponentNextReleaseVersion( HttpServletRequest request ) |
376 | |
{ |
377 | 0 | String strArtifactId = request.getParameter( PARAMETER_ARTIFACT_ID ); |
378 | 0 | SiteService.changeNextReleaseVersion( _site, strArtifactId ); |
379 | |
|
380 | 0 | return redirectView( request, VIEW_MANAGE_SITE_RELEASE ); |
381 | |
} |
382 | |
|
383 | |
@Action( ACTION_CHANGE_SITE_NEXT_RELEASE_VERSION ) |
384 | |
public String doChangeSiteNextReleaseVersion( HttpServletRequest request ) |
385 | |
{ |
386 | 0 | SiteService.changeNextReleaseVersion( _site ); |
387 | |
|
388 | 0 | return redirect( request, JSP_MANAGE_RELEASE_SITE, PARAMETER_OPEN_SITE_VERSION, 1 ); |
389 | |
} |
390 | |
|
391 | |
} |