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.participatorybudget.web.vote;
35
36 import java.io.IOException;
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.participatorybudget.business.vote.VotePerLocation;
45 import fr.paris.lutece.plugins.participatorybudget.business.vote.VotePerLocationHome;
46 import fr.paris.lutece.portal.service.security.UserNotSignedException;
47 import fr.paris.lutece.portal.util.mvc.admin.MVCAdminJspBean;
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
52
53
54
55
56 @Controller( controllerJsp = "VoteParArrandissement.jsp", controllerPath = "jsp/admin/plugins/participatorybudget/", right = "VOTE_PAR_ARRANDISSEMENT" )
57 public class VoteParArrandJspBean extends MVCAdminJspBean
58 {
59
60
61
62 private static final long serialVersionUID = 1L;
63
64
65
66
67
68 public static final String RIGHT_INDEXER = "/";
69 private static final String TEMPLATE_MANAGE_VOTES_PAR_ARRAND = "admin/plugins/participatorybudget/vote_par_arrandissement.html";
70
71
72 private static final String PROPERTY_PAGE_TITLE_VOTE_PAR_ARRAND = "participatorybudget.vote_par_arrd.pageTitle";
73
74
75 private static final String PARAMETER_NB = "nb_";
76
77
78 private static final String MARK_LIST_VOTES = "listVotes";
79
80
81 private static final String VIEW_MANAGE_VOTE_PAR_ARRAND = "manageVoteParArrand";
82
83
84 private static final String ACTION_DO_UPDATE = "update";
85
86
87
88
89
90
91
92
93
94 @View( value = VIEW_MANAGE_VOTE_PAR_ARRAND, defaultView = true )
95 public String getManageVoteParArrand( HttpServletRequest request ) throws UserNotSignedException
96 {
97
98 List<VotePerLocation> listVotes = VotePerLocationHome.getListVotesPerLocation( );
99
100 Map<String, Object> model = getModel( );
101
102 model.put( MARK_LIST_VOTES, listVotes );
103
104 return getPage( PROPERTY_PAGE_TITLE_VOTE_PAR_ARRAND, TEMPLATE_MANAGE_VOTES_PAR_ARRAND, model );
105 }
106
107
108
109
110
111
112
113
114
115 @Action( ACTION_DO_UPDATE )
116 public String doUpdate( HttpServletRequest request ) throws IOException
117 {
118 List<VotePerLocation> listVotes = VotePerLocationHome.getListVotesPerLocation( );
119
120 for ( int i = 1; i <= listVotes.size( ); i++ )
121 {
122 VotePerLocation vote = null;
123 String strVal = request.getParameter( PARAMETER_NB + i ) == null ? StringUtils.EMPTY : request.getParameter( PARAMETER_NB + i );
124 if ( StringUtils.isEmpty( strVal ) || !StringUtils.isNumeric( strVal ) )
125 {
126 if ( i == 21 )
127 {
128 addError( "Champs Tout Paris n'est pas remplis" );
129 return redirectView( request, VIEW_MANAGE_VOTE_PAR_ARRAND );
130 }
131 else
132 {
133 addError( "Champs Paris " + i + " Arrandissement n'est pas remplis" );
134 return redirectView( request, VIEW_MANAGE_VOTE_PAR_ARRAND );
135 }
136 }
137 vote = listVotes.get( i - 1 );
138 vote.setNbVotes( Integer.parseInt( strVal ) );
139 }
140
141 for ( VotePerLocation vpl : listVotes )
142 {
143 VotePerLocationHome.updateVotesPerLocation( vpl );
144 }
145 addInfo( "Votes par Arrandissemente modifié" );
146 return redirectView( request, VIEW_MANAGE_VOTE_PAR_ARRAND );
147 }
148 }