1 |
|
package be.dvw.administration.mvc.actions; |
2 |
|
|
3 |
|
import be.dvw.administration.Constants; |
4 |
|
import be.dvw.administration.model.Score; |
5 |
|
import be.dvw.administration.model.Instrument; |
6 |
|
import be.dvw.administration.services.scores.ScoreService; |
7 |
|
import be.dvw.administration.services.scores.ScoreServiceCastorImpl; |
8 |
|
import org.apache.commons.logging.Log; |
9 |
|
import org.apache.commons.logging.LogFactory; |
10 |
|
import org.apache.struts.action.ActionForm; |
11 |
|
import org.apache.struts.action.ActionForward; |
12 |
|
import org.apache.struts.action.ActionMapping; |
13 |
|
import org.apache.struts.action.DynaActionForm; |
14 |
|
import org.apache.struts.actions.MappingDispatchAction; |
15 |
|
|
16 |
|
import javax.servlet.http.HttpServletRequest; |
17 |
|
import javax.servlet.http.HttpServletResponse; |
18 |
|
import java.util.List; |
19 |
|
|
20 |
|
|
21 |
0 |
public final class ScoreAction extends MappingDispatchAction { |
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
0 |
private static Log LOG = LogFactory.getLog(ScoreAction.class); |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
0 |
private ScoreService scoreService = new ScoreServiceCastorImpl(); |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
public ActionForward create(ActionMapping mapping, |
45 |
|
ActionForm form, |
46 |
|
HttpServletRequest request, |
47 |
|
HttpServletResponse response) |
48 |
|
throws Exception { |
49 |
0 |
request.getSession().setAttribute(Constants.NAVIGATION_CONTEXT, "create"); |
50 |
0 |
request.getSession().setAttribute(Constants.ACTION, "create"); |
51 |
0 |
return mapping.findForward("success"); |
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
public ActionForward edit(ActionMapping mapping, |
65 |
|
ActionForm form, |
66 |
|
HttpServletRequest request, |
67 |
|
HttpServletResponse response) |
68 |
|
throws Exception { |
69 |
|
|
70 |
|
try |
71 |
|
{ |
72 |
|
|
73 |
0 |
if (request.getParameter("id") == null || "".equals( request.getParameter("id" ))) |
74 |
|
{ |
75 |
0 |
request.setAttribute("error","error-noselection"); |
76 |
0 |
List list = scoreService.getAll(); |
77 |
0 |
request.setAttribute("list", list); |
78 |
0 |
return mapping.findForward("error-noselection"); |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
|
Score p; |
83 |
0 |
p = scoreService.load(Integer.parseInt(request.getParameter("id"))); |
84 |
0 |
DynaActionForm dynForm = (DynaActionForm) form; |
85 |
|
|
86 |
0 |
dynForm.set("id", Integer.toString( p.getId()) ) ; |
87 |
0 |
dynForm.set("name", p.getName() ); |
88 |
0 |
dynForm.set("composer", p.getComposer() ); |
89 |
0 |
dynForm.set("arranger", p.getArranger() ); |
90 |
0 |
dynForm.set("price", Float.toString( p.getPrice() ) ); |
91 |
0 |
dynForm.set("boxnumber", Integer.toString( p.getBoxNumber() ) ) ; |
92 |
0 |
dynForm.set("description", p.getDescription()); |
93 |
|
|
94 |
|
|
95 |
0 |
request.getSession().setAttribute(Constants.ACTION, "edit"); |
96 |
|
|
97 |
0 |
return mapping.findForward("success"); |
98 |
|
} |
99 |
0 |
catch (Exception e) |
100 |
|
{ |
101 |
0 |
LOG.error("Edit form failed to load ", e); |
102 |
0 |
return mapping.findForward("error-partituur"); |
103 |
|
} |
104 |
|
|
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
public ActionForward save(ActionMapping mapping, |
118 |
|
ActionForm form, |
119 |
|
HttpServletRequest request, |
120 |
|
HttpServletResponse response) |
121 |
|
throws Exception { |
122 |
|
|
123 |
0 |
Score p = new Score(); |
124 |
0 |
boolean newScore = true; |
125 |
|
|
126 |
0 |
DynaActionForm dynForm = (DynaActionForm) form; |
127 |
|
|
128 |
0 |
if ( dynForm.get("id") != null && |
129 |
|
!"".equals( dynForm.get("id") ) && |
130 |
|
!"0".equals( (String) dynForm.get("id") ) ) |
131 |
|
{ |
132 |
0 |
p.setId( Integer.parseInt((String) dynForm.get( "id")) ); |
133 |
0 |
newScore = false; |
134 |
|
} |
135 |
|
|
136 |
0 |
p.setName( (String)dynForm.get("name") ); |
137 |
0 |
p.setComposer( (String)dynForm.get( "composer") ); |
138 |
0 |
p.setArranger( (String)dynForm.get( "arranger") ); |
139 |
0 |
p.setBoxNumber( Integer.parseInt( (String) dynForm.get( "boxnumber") ) ) ; |
140 |
0 |
p.setPrice( Float.parseFloat ( (String) dynForm.get( "price") ) ); |
141 |
0 |
p.setDescription( (String)dynForm.get( "description") ); |
142 |
|
|
143 |
0 |
p = scoreService.save(p, newScore); |
144 |
|
|
145 |
0 |
request.setAttribute( Constants.SCORE_CURRENT, p); |
146 |
0 |
return mapping.findForward("success"); |
147 |
|
} |
148 |
|
|
149 |
|
public ActionForward delete(ActionMapping mapping, |
150 |
|
ActionForm form, |
151 |
|
HttpServletRequest request, |
152 |
|
HttpServletResponse response) |
153 |
|
throws Exception { |
154 |
|
|
155 |
0 |
scoreService.delete( Integer.parseInt(request.getParameter("id")) ); |
156 |
0 |
request.getSession().setAttribute(Constants.ACTION, "delete"); |
157 |
0 |
return mapping.findForward("success"); |
158 |
|
|
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
public ActionForward inventory(ActionMapping mapping, |
173 |
|
ActionForm form, |
174 |
|
HttpServletRequest request, |
175 |
|
HttpServletResponse response) |
176 |
|
throws Exception { |
177 |
|
|
178 |
0 |
List list = scoreService.getAll(); |
179 |
0 |
request.setAttribute("list", list); |
180 |
0 |
request.getSession().setAttribute(Constants.NAVIGATION_CONTEXT, "inventory"); |
181 |
0 |
request.getSession().setAttribute(Constants.ACTION, "inventory"); |
182 |
0 |
return mapping.findForward("success"); |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
|
196 |
|
public ActionForward search (ActionMapping mapping, |
197 |
|
ActionForm form, |
198 |
|
HttpServletRequest request, |
199 |
|
HttpServletResponse response) |
200 |
|
throws Exception |
201 |
|
{ |
202 |
|
|
203 |
0 |
List list = scoreService.search(""); |
204 |
0 |
request.setAttribute("list", list); |
205 |
0 |
return mapping.findForward("success"); |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
public ActionForward searchForm (ActionMapping mapping, |
219 |
|
ActionForm form, |
220 |
|
HttpServletRequest request, |
221 |
|
HttpServletResponse response) |
222 |
|
throws Exception |
223 |
|
{ |
224 |
0 |
request.getSession().setAttribute(Constants.NAVIGATION_CONTEXT, "search"); |
225 |
0 |
request.getSession().setAttribute(Constants.ACTION, "search"); |
226 |
0 |
return mapping.findForward("success"); |
227 |
|
} |
228 |
|
|
229 |
|
public ActionForward details (ActionMapping mapping, |
230 |
|
ActionForm form, |
231 |
|
HttpServletRequest request, |
232 |
|
HttpServletResponse response) |
233 |
|
throws Exception |
234 |
|
{ |
235 |
|
try |
236 |
|
{ |
237 |
|
|
238 |
0 |
if (request.getParameter("id") == null || "".equals( request.getParameter("id" ))) |
239 |
|
{ |
240 |
0 |
request.setAttribute("error","error-noselection"); |
241 |
0 |
List list = scoreService.getAll(); |
242 |
0 |
request.setAttribute("list", list); |
243 |
0 |
return mapping.findForward("error-noselection"); |
244 |
|
} |
245 |
|
|
246 |
0 |
Score i = scoreService.load(Integer.parseInt( request.getParameter("id") )); |
247 |
0 |
request.setAttribute( Constants.SCORE_CURRENT, i); |
248 |
0 |
request.getSession().setAttribute(Constants.ACTION, "details"); |
249 |
0 |
return mapping.findForward("success"); |
250 |
|
} |
251 |
0 |
catch (Exception e) |
252 |
|
{ |
253 |
0 |
LOG.error("Score failed to load ", e); |
254 |
0 |
return mapping.findForward("error-instrument"); |
255 |
|
} |
256 |
|
} |
257 |
|
|
258 |
|
} |