Rev 1675 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
847 | jmachado | 1 | package pt.estgp.estgweb.web.controllers.courseunits; |
2 | |||
3 | import org.apache.log4j.Logger; |
||
4 | import org.apache.struts.action.ActionForm; |
||
5 | import org.apache.struts.action.ActionForward; |
||
6 | import org.apache.struts.action.ActionMapping; |
||
7 | import pt.estgp.estgweb.domain.CourseUnitProgram; |
||
8 | import pt.estgp.estgweb.domain.CourseUnitProgramImpl; |
||
9 | import pt.estgp.estgweb.domain.CourseUnitProgramPart2Impl; |
||
1312 | jmachado | 10 | import pt.estgp.estgweb.domain.views.CourseUnitProgramView; |
11 | import pt.estgp.estgweb.domain.views.CourseUnitView; |
||
847 | jmachado | 12 | import pt.estgp.estgweb.filters.exceptions.NotFoundException; |
13 | import pt.estgp.estgweb.web.form.courseunits.CourseUnitProgramForm; |
||
14 | import pt.estgp.estgweb.web.utils.RequestUtils; |
||
15 | import pt.utl.ist.berserk.logic.serviceManager.IServiceManager; |
||
16 | import pt.utl.ist.berserk.logic.serviceManager.ServiceManager; |
||
17 | import pt.utl.ist.berserk.logic.serviceManager.exceptions.FilterChainFailedException; |
||
18 | |||
19 | import javax.servlet.ServletException; |
||
20 | import javax.servlet.http.HttpServletRequest; |
||
21 | import javax.servlet.http.HttpServletResponse; |
||
22 | |||
23 | |||
24 | /** |
||
25 | * @author Jorge Machado |
||
26 | * @author Fabio Velez |
||
27 | * @date 26/Fev/2008 |
||
28 | * @time 18:01:54 |
||
29 | * @see pt.estgp.estgweb.web |
||
30 | */ |
||
31 | public class CourseUnitsProgramController extends CourseUnitsController |
||
32 | { |
||
33 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(CourseUnitsProgramController.class); |
||
34 | |||
35 | |||
36 | |||
37 | |||
1350 | jmachado | 38 | public ActionForward validateProgram(ActionMapping mapping, |
39 | ActionForm form, |
||
40 | HttpServletRequest request, |
||
41 | HttpServletResponse response) |
||
42 | throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
||
43 | |||
1686 | jmachado | 44 | |
1350 | jmachado | 45 | CourseUnitProgramForm cUF = (CourseUnitProgramForm) form; |
46 | |||
47 | long id = cUF.getCourseUnitId(); |
||
48 | if(id <= 0) |
||
49 | id = cUF.getCourseUnitView().getId(); |
||
50 | |||
51 | IServiceManager sm = ServiceManager.getInstance(); |
||
52 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id}; |
||
53 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"unitId"}; |
||
54 | sm.execute(RequestUtils.getRequester(request, response), "ValidateCourseUnitProgram", args,names); |
||
55 | |||
56 | return saveProgram(mapping, |
||
57 | form, |
||
58 | request, |
||
59 | response); |
||
60 | |||
1686 | jmachado | 61 | |
1350 | jmachado | 62 | } |
63 | |||
64 | public ActionForward invalidateProgram(ActionMapping mapping, |
||
65 | ActionForm form, |
||
66 | HttpServletRequest request, |
||
67 | HttpServletResponse response) |
||
68 | throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
||
69 | |||
70 | |||
1686 | jmachado | 71 | CourseUnitProgramForm cUF = (CourseUnitProgramForm) form; |
1350 | jmachado | 72 | |
1686 | jmachado | 73 | long id = cUF.getCourseUnitId(); |
74 | if(id <= 0) |
||
75 | id = cUF.getCourseUnitView().getId(); |
||
1350 | jmachado | 76 | |
1686 | jmachado | 77 | IServiceManager sm = ServiceManager.getInstance(); |
78 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id}; |
||
79 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"unitId"}; |
||
80 | sm.execute(RequestUtils.getRequester(request, response), "InvalidateCourseUnitProgram", args,names); |
||
1350 | jmachado | 81 | |
1686 | jmachado | 82 | return editProgram(mapping, |
83 | form, |
||
84 | request, |
||
85 | response); |
||
86 | |||
87 | |||
88 | |||
1350 | jmachado | 89 | } |
90 | |||
847 | jmachado | 91 | public ActionForward editProgram(ActionMapping mapping, |
92 | ActionForm form, |
||
93 | HttpServletRequest request, |
||
94 | HttpServletResponse response) |
||
95 | throws ServletException |
||
96 | { |
||
97 | try |
||
98 | { |
||
99 | CourseUnitProgramForm cUF = (CourseUnitProgramForm) form; |
||
100 | |||
101 | long id = cUF.getCourseUnitId(); |
||
102 | if(id <= 0) |
||
103 | id = cUF.getCourseUnitView().getId(); |
||
104 | |||
105 | |||
106 | CourseUnitView cV = loadCourseUnitViewAndCourse(id,true,false, mapping, request, response); |
||
107 | |||
108 | cUF.setCourseUnitView(cV); |
||
109 | request.setAttribute("CourseUnitView", cV); |
||
110 | CourseUnitProgramView cpv; |
||
111 | if(cV.getCourseUnit().getCourseUnitProgram() == null) |
||
112 | cpv = new CourseUnitProgramView(new CourseUnitProgramImpl()); |
||
113 | else |
||
114 | cpv = new CourseUnitProgramView(cV.getCourseUnit().getCourseUnitProgram()); |
||
115 | // request.setAttribute("CourseUnitProgramView", cpv); |
||
116 | |||
117 | if(cpv.getCourseUnitProgram().getCourseUnitProgramPart2() == null) |
||
118 | cpv.getCourseUnitProgram().setCourseUnitProgramPart2(new CourseUnitProgramPart2Impl()); |
||
119 | |||
120 | |||
121 | cUF.setCourseUnitProgramView(cpv); |
||
122 | cUF.setCourseUnitView(cV); |
||
123 | return mapping.findForward("edit.program"); |
||
124 | } |
||
125 | catch (FilterChainFailedException e) |
||
126 | { |
||
127 | return mapping.findForward("error401"); |
||
128 | } |
||
129 | catch (NotFoundException e) |
||
130 | { |
||
131 | return mapping.findForward("error404"); |
||
132 | } |
||
133 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
134 | { |
||
135 | logger.error(e, e); |
||
136 | return mapping.findForward("error500"); |
||
137 | } |
||
138 | } |
||
139 | |||
140 | public ActionForward saveProgram(ActionMapping mapping, |
||
141 | ActionForm form, |
||
142 | HttpServletRequest request, |
||
143 | HttpServletResponse response) |
||
144 | throws ServletException |
||
145 | { |
||
146 | try |
||
147 | { |
||
148 | CourseUnitProgramForm cUF = (CourseUnitProgramForm) form; |
||
149 | |||
150 | long id = cUF.getCourseUnitView().getId(); |
||
151 | CourseUnitProgramView cuV = cUF.getCourseUnitProgramView(); |
||
152 | cuV.setResponsableId(cUF.getCourseUnitView().getResponsableId()); |
||
153 | |||
154 | IServiceManager sm = ServiceManager.getInstance(); |
||
155 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cuV, id}; |
||
1312 | jmachado | 156 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"programView", "unitId"}; |
157 | sm.execute(RequestUtils.getRequester(request, response), "SaveCourseUnitProgram", args,names); |
||
847 | jmachado | 158 | CourseUnitView cV = loadCourseUnitView(id,true,false, mapping, request, response); |
159 | cUF.setCourseUnitView(cV); |
||
160 | request.setAttribute("CourseUnitView", cV); |
||
1686 | jmachado | 161 | |
162 | if(request.getParameter("json")!=null && request.getParameter("json").equals("true")) |
||
163 | { |
||
164 | return mapping.findForward("jsonOk"); |
||
165 | } |
||
166 | else |
||
167 | return mapping.findForward("load"); |
||
847 | jmachado | 168 | } |
169 | catch (FilterChainFailedException e) |
||
170 | { |
||
171 | return mapping.findForward("error401"); |
||
172 | } |
||
173 | catch (NotFoundException e) |
||
174 | { |
||
175 | return mapping.findForward("error404"); |
||
176 | } |
||
177 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
178 | { |
||
179 | logger.error(e, e); |
||
180 | return mapping.findForward("error500"); |
||
181 | } |
||
182 | } |
||
183 | |||
184 | public ActionForward cloneProgram(ActionMapping mapping, |
||
185 | ActionForm form, |
||
186 | HttpServletRequest request, |
||
187 | HttpServletResponse response) |
||
188 | throws ServletException |
||
189 | { |
||
190 | try |
||
191 | { |
||
192 | CourseUnitProgramForm cUF = (CourseUnitProgramForm) form; |
||
193 | |||
194 | long id = cUF.getCourseUnitView().getId(); |
||
195 | long idFrom = cUF.getCloneFromUnitId(); |
||
196 | |||
197 | IServiceManager sm = ServiceManager.getInstance(); |
||
198 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{idFrom, id}; |
||
199 | CourseUnitProgram cP = (CourseUnitProgram) sm.execute(RequestUtils.getRequester(request, response), "CloneCourseUnitProgram", args); |
||
200 | |||
201 | CourseUnitView cV = loadCourseUnitViewAndCourse(id,true,false, mapping, request, response); |
||
202 | |||
203 | cUF.setCourseUnitView(cV); |
||
204 | request.setAttribute("CourseUnitView", cV); |
||
205 | CourseUnitProgramView cpv; |
||
206 | if(cV.getCourseUnit().getCourseUnitProgram() == null) |
||
207 | cpv = new CourseUnitProgramView(new CourseUnitProgramImpl()); |
||
208 | else |
||
209 | cpv = new CourseUnitProgramView(cV.getCourseUnit().getCourseUnitProgram()); |
||
210 | // request.setAttribute("CourseUnitProgramView", cpv); |
||
211 | |||
212 | if(cpv.getCourseUnitProgram().getCourseUnitProgramPart2() == null) |
||
213 | cpv.getCourseUnitProgram().setCourseUnitProgramPart2(new CourseUnitProgramPart2Impl()); |
||
214 | |||
215 | |||
216 | cUF.setCourseUnitProgramView(cpv); |
||
217 | cUF.setCourseUnitView(cV); |
||
218 | return mapping.findForward("edit.program"); |
||
219 | |||
220 | |||
221 | } |
||
222 | catch (FilterChainFailedException e) |
||
223 | { |
||
224 | return mapping.findForward("error401"); |
||
225 | } |
||
226 | catch (NotFoundException e) |
||
227 | { |
||
228 | return mapping.findForward("error404"); |
||
229 | } |
||
230 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
231 | { |
||
232 | logger.error(e, e); |
||
233 | return mapping.findForward("error500"); |
||
234 | } |
||
235 | |||
236 | } |
||
237 | |||
238 | |||
1675 | jmachado | 239 | //TODO meter aqui a navegacao respectiva de adicionar teacher e ir para o programa de novo |
847 | jmachado | 240 | public ActionForward addTeacher(ActionMapping mapping, |
241 | ActionForm form, |
||
242 | HttpServletRequest request, |
||
243 | HttpServletResponse response) |
||
244 | throws ServletException |
||
245 | { |
||
246 | try |
||
247 | { |
||
248 | CourseUnitProgramForm cUF = (CourseUnitProgramForm) form; |
||
249 | long teacherId = cUF.getTeacherId(); |
||
250 | long courseUnitId = cUF.getCourseUnitView().getId(); |
||
251 | |||
252 | IServiceManager sm = ServiceManager.getInstance(); |
||
253 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
||
254 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{teacherId,courseUnitId}; |
||
255 | |||
256 | CourseUnitView cV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), "AddTeacherCourseUnit", args, names); |
||
257 | if(cV.isNotFound()) |
||
258 | addError(request,"error.courseunit.teacher.not.found"); |
||
259 | |||
260 | return editProgram(mapping,form,request,response); |
||
261 | } |
||
262 | catch (FilterChainFailedException e) |
||
263 | { |
||
264 | return mapping.findForward("error401"); |
||
265 | } |
||
266 | catch (NotFoundException e) |
||
267 | { |
||
268 | return mapping.findForward("error404"); |
||
269 | } |
||
270 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
271 | { |
||
272 | logger.error(e, e); |
||
273 | return mapping.findForward("error500"); |
||
274 | } |
||
275 | } |
||
276 | |||
277 | |||
278 | public ActionForward removeTeacher(ActionMapping mapping, |
||
279 | ActionForm form, |
||
280 | HttpServletRequest request, |
||
281 | HttpServletResponse response) |
||
282 | throws ServletException |
||
283 | { |
||
284 | try |
||
285 | { |
||
286 | CourseUnitProgramForm cUF = (CourseUnitProgramForm) form; |
||
287 | long teacherId = cUF.getId(); //can't come in SELECT BOX because is for choose |
||
288 | long courseUnitId = cUF.getCourseUnitView().getId(); |
||
289 | |||
290 | IServiceManager sm = ServiceManager.getInstance(); |
||
291 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
||
292 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{teacherId,courseUnitId}; |
||
293 | |||
294 | sm.execute(RequestUtils.getRequester(request, response), "RemoveTeacherCourseUnit", args, names); |
||
295 | return editProgram(mapping,form,request,response); |
||
296 | } |
||
297 | catch (FilterChainFailedException e) |
||
298 | { |
||
299 | return mapping.findForward("error401"); |
||
300 | } |
||
301 | catch (NotFoundException e) |
||
302 | { |
||
303 | return mapping.findForward("error404"); |
||
304 | } |
||
305 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
306 | { |
||
307 | logger.error(e, e); |
||
308 | return mapping.findForward("error500"); |
||
309 | } |
||
310 | } |
||
311 | |||
312 | |||
313 | |||
314 | } |