Rev 1312 | Go to most recent revision | 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 | |||
44 | CourseUnitProgramForm cUF = (CourseUnitProgramForm) form; |
||
45 | |||
46 | long id = cUF.getCourseUnitId(); |
||
47 | if(id <= 0) |
||
48 | id = cUF.getCourseUnitView().getId(); |
||
49 | |||
50 | IServiceManager sm = ServiceManager.getInstance(); |
||
51 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id}; |
||
52 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"unitId"}; |
||
53 | sm.execute(RequestUtils.getRequester(request, response), "ValidateCourseUnitProgram", args,names); |
||
54 | |||
55 | return saveProgram(mapping, |
||
56 | form, |
||
57 | request, |
||
58 | response); |
||
59 | |||
60 | } |
||
61 | |||
62 | public ActionForward invalidateProgram(ActionMapping mapping, |
||
63 | ActionForm form, |
||
64 | HttpServletRequest request, |
||
65 | HttpServletResponse response) |
||
66 | throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable { |
||
67 | |||
68 | CourseUnitProgramForm cUF = (CourseUnitProgramForm) form; |
||
69 | |||
70 | long id = cUF.getCourseUnitId(); |
||
71 | if(id <= 0) |
||
72 | id = cUF.getCourseUnitView().getId(); |
||
73 | |||
74 | IServiceManager sm = ServiceManager.getInstance(); |
||
75 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id}; |
||
76 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"unitId"}; |
||
77 | sm.execute(RequestUtils.getRequester(request, response), "InvalidateCourseUnitProgram", args,names); |
||
78 | |||
79 | return editProgram(mapping, |
||
80 | form, |
||
81 | request, |
||
82 | response); |
||
83 | |||
84 | } |
||
85 | |||
847 | jmachado | 86 | public ActionForward editProgram(ActionMapping mapping, |
87 | ActionForm form, |
||
88 | HttpServletRequest request, |
||
89 | HttpServletResponse response) |
||
90 | throws ServletException |
||
91 | { |
||
92 | try |
||
93 | { |
||
94 | CourseUnitProgramForm cUF = (CourseUnitProgramForm) form; |
||
95 | |||
96 | long id = cUF.getCourseUnitId(); |
||
97 | if(id <= 0) |
||
98 | id = cUF.getCourseUnitView().getId(); |
||
99 | |||
100 | |||
101 | CourseUnitView cV = loadCourseUnitViewAndCourse(id,true,false, mapping, request, response); |
||
102 | |||
103 | cUF.setCourseUnitView(cV); |
||
104 | request.setAttribute("CourseUnitView", cV); |
||
105 | CourseUnitProgramView cpv; |
||
106 | if(cV.getCourseUnit().getCourseUnitProgram() == null) |
||
107 | cpv = new CourseUnitProgramView(new CourseUnitProgramImpl()); |
||
108 | else |
||
109 | cpv = new CourseUnitProgramView(cV.getCourseUnit().getCourseUnitProgram()); |
||
110 | // request.setAttribute("CourseUnitProgramView", cpv); |
||
111 | |||
112 | if(cpv.getCourseUnitProgram().getCourseUnitProgramPart2() == null) |
||
113 | cpv.getCourseUnitProgram().setCourseUnitProgramPart2(new CourseUnitProgramPart2Impl()); |
||
114 | |||
115 | |||
116 | cUF.setCourseUnitProgramView(cpv); |
||
117 | cUF.setCourseUnitView(cV); |
||
118 | return mapping.findForward("edit.program"); |
||
119 | } |
||
120 | catch (FilterChainFailedException e) |
||
121 | { |
||
122 | return mapping.findForward("error401"); |
||
123 | } |
||
124 | catch (NotFoundException e) |
||
125 | { |
||
126 | return mapping.findForward("error404"); |
||
127 | } |
||
128 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
129 | { |
||
130 | logger.error(e, e); |
||
131 | return mapping.findForward("error500"); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | public ActionForward saveProgram(ActionMapping mapping, |
||
136 | ActionForm form, |
||
137 | HttpServletRequest request, |
||
138 | HttpServletResponse response) |
||
139 | throws ServletException |
||
140 | { |
||
141 | try |
||
142 | { |
||
143 | CourseUnitProgramForm cUF = (CourseUnitProgramForm) form; |
||
144 | |||
145 | long id = cUF.getCourseUnitView().getId(); |
||
146 | CourseUnitProgramView cuV = cUF.getCourseUnitProgramView(); |
||
147 | cuV.setResponsableId(cUF.getCourseUnitView().getResponsableId()); |
||
148 | |||
149 | IServiceManager sm = ServiceManager.getInstance(); |
||
150 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cuV, id}; |
||
1312 | jmachado | 151 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"programView", "unitId"}; |
152 | sm.execute(RequestUtils.getRequester(request, response), "SaveCourseUnitProgram", args,names); |
||
847 | jmachado | 153 | CourseUnitView cV = loadCourseUnitView(id,true,false, mapping, request, response); |
154 | cUF.setCourseUnitView(cV); |
||
155 | request.setAttribute("CourseUnitView", cV); |
||
156 | return mapping.findForward("load"); |
||
157 | } |
||
158 | catch (FilterChainFailedException e) |
||
159 | { |
||
160 | return mapping.findForward("error401"); |
||
161 | } |
||
162 | catch (NotFoundException e) |
||
163 | { |
||
164 | return mapping.findForward("error404"); |
||
165 | } |
||
166 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
167 | { |
||
168 | logger.error(e, e); |
||
169 | return mapping.findForward("error500"); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | public ActionForward cloneProgram(ActionMapping mapping, |
||
174 | ActionForm form, |
||
175 | HttpServletRequest request, |
||
176 | HttpServletResponse response) |
||
177 | throws ServletException |
||
178 | { |
||
179 | try |
||
180 | { |
||
181 | CourseUnitProgramForm cUF = (CourseUnitProgramForm) form; |
||
182 | |||
183 | long id = cUF.getCourseUnitView().getId(); |
||
184 | long idFrom = cUF.getCloneFromUnitId(); |
||
185 | |||
186 | IServiceManager sm = ServiceManager.getInstance(); |
||
187 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{idFrom, id}; |
||
188 | CourseUnitProgram cP = (CourseUnitProgram) sm.execute(RequestUtils.getRequester(request, response), "CloneCourseUnitProgram", args); |
||
189 | |||
190 | CourseUnitView cV = loadCourseUnitViewAndCourse(id,true,false, mapping, request, response); |
||
191 | |||
192 | cUF.setCourseUnitView(cV); |
||
193 | request.setAttribute("CourseUnitView", cV); |
||
194 | CourseUnitProgramView cpv; |
||
195 | if(cV.getCourseUnit().getCourseUnitProgram() == null) |
||
196 | cpv = new CourseUnitProgramView(new CourseUnitProgramImpl()); |
||
197 | else |
||
198 | cpv = new CourseUnitProgramView(cV.getCourseUnit().getCourseUnitProgram()); |
||
199 | // request.setAttribute("CourseUnitProgramView", cpv); |
||
200 | |||
201 | if(cpv.getCourseUnitProgram().getCourseUnitProgramPart2() == null) |
||
202 | cpv.getCourseUnitProgram().setCourseUnitProgramPart2(new CourseUnitProgramPart2Impl()); |
||
203 | |||
204 | |||
205 | cUF.setCourseUnitProgramView(cpv); |
||
206 | cUF.setCourseUnitView(cV); |
||
207 | return mapping.findForward("edit.program"); |
||
208 | |||
209 | |||
210 | } |
||
211 | catch (FilterChainFailedException e) |
||
212 | { |
||
213 | return mapping.findForward("error401"); |
||
214 | } |
||
215 | catch (NotFoundException e) |
||
216 | { |
||
217 | return mapping.findForward("error404"); |
||
218 | } |
||
219 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
220 | { |
||
221 | logger.error(e, e); |
||
222 | return mapping.findForward("error500"); |
||
223 | } |
||
224 | |||
225 | } |
||
226 | |||
227 | |||
1312 | jmachado | 228 | //TODO meter aqui a navega��o respectiva de adicionar teacher e ir para o programa de novo |
847 | jmachado | 229 | public ActionForward addTeacher(ActionMapping mapping, |
230 | ActionForm form, |
||
231 | HttpServletRequest request, |
||
232 | HttpServletResponse response) |
||
233 | throws ServletException |
||
234 | { |
||
235 | try |
||
236 | { |
||
237 | CourseUnitProgramForm cUF = (CourseUnitProgramForm) form; |
||
238 | long teacherId = cUF.getTeacherId(); |
||
239 | long courseUnitId = cUF.getCourseUnitView().getId(); |
||
240 | |||
241 | IServiceManager sm = ServiceManager.getInstance(); |
||
242 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
||
243 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{teacherId,courseUnitId}; |
||
244 | |||
245 | CourseUnitView cV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), "AddTeacherCourseUnit", args, names); |
||
246 | if(cV.isNotFound()) |
||
247 | addError(request,"error.courseunit.teacher.not.found"); |
||
248 | |||
249 | return editProgram(mapping,form,request,response); |
||
250 | } |
||
251 | catch (FilterChainFailedException e) |
||
252 | { |
||
253 | return mapping.findForward("error401"); |
||
254 | } |
||
255 | catch (NotFoundException e) |
||
256 | { |
||
257 | return mapping.findForward("error404"); |
||
258 | } |
||
259 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
260 | { |
||
261 | logger.error(e, e); |
||
262 | return mapping.findForward("error500"); |
||
263 | } |
||
264 | } |
||
265 | |||
266 | |||
267 | public ActionForward removeTeacher(ActionMapping mapping, |
||
268 | ActionForm form, |
||
269 | HttpServletRequest request, |
||
270 | HttpServletResponse response) |
||
271 | throws ServletException |
||
272 | { |
||
273 | try |
||
274 | { |
||
275 | CourseUnitProgramForm cUF = (CourseUnitProgramForm) form; |
||
276 | long teacherId = cUF.getId(); //can't come in SELECT BOX because is for choose |
||
277 | long courseUnitId = cUF.getCourseUnitView().getId(); |
||
278 | |||
279 | IServiceManager sm = ServiceManager.getInstance(); |
||
280 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
||
281 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{teacherId,courseUnitId}; |
||
282 | |||
283 | sm.execute(RequestUtils.getRequester(request, response), "RemoveTeacherCourseUnit", args, names); |
||
284 | return editProgram(mapping,form,request,response); |
||
285 | } |
||
286 | catch (FilterChainFailedException e) |
||
287 | { |
||
288 | return mapping.findForward("error401"); |
||
289 | } |
||
290 | catch (NotFoundException e) |
||
291 | { |
||
292 | return mapping.findForward("error404"); |
||
293 | } |
||
294 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
295 | { |
||
296 | logger.error(e, e); |
||
297 | return mapping.findForward("error500"); |
||
298 | } |
||
299 | } |
||
300 | |||
301 | |||
302 | |||
303 | } |