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 java.util.HashMap; |
37 | |
import java.util.List; |
38 | |
import java.util.Map; |
39 | |
|
40 | |
import javax.servlet.http.HttpServletRequest; |
41 | |
|
42 | |
import org.apache.commons.lang.StringUtils; |
43 | |
|
44 | |
import fr.paris.lutece.plugins.releaser.business.Component; |
45 | |
import fr.paris.lutece.plugins.releaser.business.ReleaserUser; |
46 | |
import fr.paris.lutece.plugins.releaser.service.ComponentService; |
47 | |
import fr.paris.lutece.plugins.releaser.service.SiteService; |
48 | |
import fr.paris.lutece.plugins.releaser.util.ReleaserUtils; |
49 | |
import fr.paris.lutece.portal.service.template.AppTemplateService; |
50 | |
import fr.paris.lutece.portal.util.mvc.admin.MVCAdminJspBean; |
51 | |
import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller; |
52 | |
import fr.paris.lutece.portal.util.mvc.commons.annotations.Action; |
53 | |
import fr.paris.lutece.portal.util.mvc.commons.annotations.View; |
54 | |
import fr.paris.lutece.util.ReferenceList; |
55 | |
import fr.paris.lutece.util.html.HtmlTemplate; |
56 | |
import fr.paris.lutece.util.html.Paginator; |
57 | |
import fr.paris.lutece.util.json.AbstractJsonResponse; |
58 | |
import fr.paris.lutece.util.json.JsonResponse; |
59 | |
import fr.paris.lutece.util.json.JsonUtil; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
@Controller( controllerJsp = "ManageComponent.jsp", controllerPath = "jsp/admin/plugins/releaser/", right = "RELEASER_MANAGEMENT" ) |
65 | 0 | public class ManageComponentReleaseJspBean extends MVCAdminJspBean |
66 | |
{ |
67 | |
|
68 | |
|
69 | |
private static final String PARAMETER_SEARCH = "search"; |
70 | |
|
71 | |
|
72 | |
private static final String VIEW_MANAGE_COMPONENT = "manageComponent"; |
73 | |
|
74 | |
|
75 | |
private static final String TEMPLATE_MANAGE_COMPONENT = "/admin/plugins/releaser/manage_component.html"; |
76 | |
|
77 | |
private static final String MARK_LIST_COMPONENT = "list_component"; |
78 | |
private static final String MARK_PAGINATOR = "paginator"; |
79 | |
|
80 | |
private static final String MARK_SEARCH = "search"; |
81 | |
private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page"; |
82 | |
|
83 | |
private static final String JSP_MANAGE_COMPONENT = "jsp/admin/plugins/releaser/ManageComponent.jsp"; |
84 | |
private static final String JSP_MANAGE_CLUSTERS = "ManageClusters.jsp"; |
85 | |
|
86 | |
private static final String ACTION_CHANGE_COMPONENT_NEXT_RELEASE_VERSION = "versionComponent"; |
87 | |
private static final String ACTION_RELEASE_COMPONENT = "releaseComponent"; |
88 | |
|
89 | |
private static final String PARAMETER_ARTIFACT_ID = "artifact_id"; |
90 | |
|
91 | |
private String _strSearch; |
92 | |
private String _strCurrentPageIndex; |
93 | |
Paginator<Component> _paginatorComponents; |
94 | |
|
95 | |
@View( value = VIEW_MANAGE_COMPONENT, defaultView = true ) |
96 | |
public String getManageComponent( HttpServletRequest request ) |
97 | |
{ |
98 | |
|
99 | 0 | _strSearch = request.getParameter( PARAMETER_SEARCH )!=null?request.getParameter( PARAMETER_SEARCH ):_strSearch; |
100 | 0 | String stCurrentPageIndexOld = _strCurrentPageIndex; |
101 | 0 | _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex ); |
102 | |
|
103 | 0 | if ( ReleaserUtils.getReleaserUser( request, getLocale( ) ) == null ) |
104 | |
{ |
105 | 0 | return redirect( request, JSP_MANAGE_CLUSTERS ); |
106 | |
} |
107 | |
|
108 | 0 | if ( !StringUtils.isEmpty( request.getParameter( PARAMETER_SEARCH )) || (_strCurrentPageIndex!=null && !_strCurrentPageIndex.equals( stCurrentPageIndexOld )) ) |
109 | |
{ |
110 | |
|
111 | 0 | _paginatorComponents = ComponentService.getService( ).getSearchComponent( _strSearch, request, getLocale( ), JSP_MANAGE_COMPONENT, |
112 | |
_strCurrentPageIndex ); |
113 | |
|
114 | |
} |
115 | |
|
116 | 0 | Map<String, Object> model = getModel( ); |
117 | 0 | model.put( MARK_SEARCH, _strSearch ); |
118 | 0 | model.put( MARK_LIST_COMPONENT, _paginatorComponents!=null?_paginatorComponents.getPageItems( ):null ); |
119 | 0 | model.put( MARK_PAGINATOR, _paginatorComponents ); |
120 | 0 | model.put( MARK_NB_ITEMS_PER_PAGE,_paginatorComponents!=null?_paginatorComponents.getItemsPerPage( ):null ); |
121 | |
|
122 | 0 | HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_COMPONENT, getLocale( ), model ); |
123 | 0 | return template.getHtml( ); |
124 | |
} |
125 | |
|
126 | |
@Action( ACTION_CHANGE_COMPONENT_NEXT_RELEASE_VERSION ) |
127 | |
public String doChangeComponentNextReleaseVersion( HttpServletRequest request ) |
128 | |
{ |
129 | 0 | String strArtifactId = request.getParameter( PARAMETER_ARTIFACT_ID ); |
130 | |
|
131 | 0 | if ( strArtifactId != null && _paginatorComponents != null ) |
132 | |
{ |
133 | |
|
134 | 0 | for ( Component component : _paginatorComponents.getPageItems( ) ) |
135 | |
{ |
136 | |
|
137 | 0 | if ( component.getArtifactId( ).equals( strArtifactId ) ) |
138 | |
{ |
139 | |
|
140 | 0 | ComponentService.getService( ).changeNextReleaseVersion( component ); |
141 | 0 | break; |
142 | |
} |
143 | 0 | } |
144 | |
|
145 | |
} |
146 | |
|
147 | 0 | return redirectView( request, VIEW_MANAGE_COMPONENT ); |
148 | |
} |
149 | |
|
150 | |
@Action( ACTION_RELEASE_COMPONENT ) |
151 | |
public String doReleaseComponent( HttpServletRequest request ) |
152 | |
{ |
153 | 0 | String strArtifactId = request.getParameter( PARAMETER_ARTIFACT_ID ); |
154 | 0 | AbstractJsonResponse jsonResponse = null; |
155 | 0 | Integer nIdContext = null; |
156 | |
|
157 | 0 | if ( strArtifactId != null && _paginatorComponents != null ) |
158 | |
{ |
159 | |
|
160 | 0 | for ( Component component : _paginatorComponents.getPageItems( ) ) |
161 | |
{ |
162 | 0 | if ( component.getArtifactId( ).equals( strArtifactId ) ) |
163 | |
{ |
164 | 0 | nIdContext = ComponentService.getService( ).release( component, getLocale( ), getUser( ), request,true ); |
165 | 0 | break; |
166 | |
} |
167 | 0 | } |
168 | |
} |
169 | 0 | jsonResponse = new JsonResponse( nIdContext ); |
170 | |
|
171 | 0 | return JsonUtil.buildJsonResponse( jsonResponse ); |
172 | |
} |
173 | |
|
174 | |
} |