Rev 343 | Rev 345 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
214 | jmachado | 1 | package pt.estgp.estgweb.web.controllers.courses; |
2 | |||
3 | import pt.estgp.estgweb.web.controllers.courseunits.CourseUnitsController; |
||
4 | import pt.estgp.estgweb.web.controllers.courseunits.CourseUnitsAdminController; |
||
5 | import pt.estgp.estgweb.web.form.courseunits.CourseUnitsForm; |
||
6 | import pt.estgp.estgweb.web.form.courses.CourseForm; |
||
7 | import pt.estgp.estgweb.web.utils.RequestUtils; |
||
8 | import pt.estgp.estgweb.web.exceptions.NoCookiesException; |
||
9 | import pt.estgp.estgweb.domain.views.CourseUnitView; |
||
10 | import pt.estgp.estgweb.domain.views.CourseView; |
||
11 | import pt.estgp.estgweb.filters.exceptions.NotFoundException; |
||
12 | import pt.estgp.estgweb.Globals; |
||
13 | import pt.estgp.estgweb.services.common.ISearchResults; |
||
343 | jmachado | 14 | import pt.estgp.estgweb.services.courseunits.DirectedCoordinatedCourses; |
214 | jmachado | 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 | import pt.utl.ist.berserk.logic.serviceManager.exceptions.ServiceManagerException; |
||
19 | import pt.utl.ist.berserk.logic.filterManager.exceptions.*; |
||
20 | import org.apache.log4j.Logger; |
||
21 | import org.apache.struts.action.ActionForward; |
||
22 | import org.apache.struts.action.ActionMapping; |
||
23 | import org.apache.struts.action.ActionForm; |
||
24 | |||
25 | import javax.servlet.http.HttpServletRequest; |
||
26 | import javax.servlet.http.HttpServletResponse; |
||
27 | import javax.servlet.ServletException; |
||
28 | |||
29 | /** |
||
30 | * @author Jorge Machado |
||
31 | * @author Fabio Velez |
||
32 | * @date 26/Fev/2008 |
||
33 | * @time 18:01:54 |
||
34 | * @see pt.estgp.estgweb.web |
||
35 | */ |
||
36 | public class CoursesController extends CourseUnitsController |
||
37 | { |
||
38 | |||
39 | 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(CoursesController.class); |
||
40 | |||
41 | |||
42 | public ActionForward startNew(ActionMapping mapping, |
||
43 | ActionForm form, |
||
44 | HttpServletRequest request, |
||
45 | HttpServletResponse response) |
||
46 | throws ServletException |
||
47 | { |
||
48 | CourseForm cF = (CourseForm) form; |
||
49 | CourseView cV = cF.getCourseView(); |
||
50 | request.setAttribute("CourseView",cV); |
||
51 | cF.setCourseView(cV); |
||
52 | return mapping.findForward("submit"); |
||
53 | } |
||
54 | |||
55 | private void load(CourseForm cF, HttpServletRequest request, HttpServletResponse response) |
||
56 | throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, InvalidFilterException, ServiceManagerException, InvalidFilterExpressionException, IncompatibleFilterException, FilterRetrieveException, NoCookiesException |
||
57 | { |
||
58 | 1.5.0/docs/api/java/lang/String.html">String code = cF.getCourseView().getCode(); |
||
59 | long id = cF.getCourseView().getId(); |
||
248 | jmachado | 60 | |
214 | jmachado | 61 | IServiceManager sm = ServiceManager.getInstance(); |
62 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"}; |
||
63 | 5+0%2Fdocs%2Fapi+Object">Object[] args; |
||
64 | 1.5.0/docs/api/java/lang/String.html">String serviceName; |
||
65 | if(code != null) |
||
66 | { |
||
67 | args = new 5+0%2Fdocs%2Fapi+Object">Object[]{code,true}; |
||
68 | serviceName = "LoadCourseByCode"; |
||
69 | } |
||
70 | else |
||
71 | { |
||
72 | args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id,true}; |
||
73 | serviceName = "LoadCourse"; |
||
74 | } |
||
75 | CourseView cV = (CourseView) sm.execute(RequestUtils.getRequester(request, response), serviceName, args, names); |
||
76 | request.setAttribute("CourseView",cV); |
||
77 | cF.setCourseView(cV); |
||
78 | } |
||
79 | |||
80 | public ActionForward load(ActionMapping mapping, |
||
81 | ActionForm form, |
||
82 | HttpServletRequest request, |
||
83 | HttpServletResponse response) |
||
84 | throws ServletException |
||
85 | { |
||
86 | try |
||
87 | { |
||
88 | load((CourseForm) form,request,response); |
||
89 | return mapping.findForward("load"); |
||
90 | } |
||
91 | catch (FilterChainFailedException e) |
||
92 | { |
||
93 | return mapping.findForward("error401"); |
||
94 | } |
||
95 | catch (NotFoundException e) |
||
96 | { |
||
97 | return mapping.findForward("error404"); |
||
98 | } |
||
99 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
100 | { |
||
101 | logger.error(e, e); |
||
102 | return mapping.findForward("error500"); |
||
103 | } |
||
104 | } |
||
105 | |||
106 | public ActionForward edit(ActionMapping mapping, |
||
107 | ActionForm form, |
||
108 | HttpServletRequest request, |
||
109 | HttpServletResponse response) |
||
110 | throws ServletException |
||
111 | { |
||
112 | try |
||
113 | { |
||
114 | load((CourseForm) form,request,response); |
||
115 | return mapping.findForward("submit"); |
||
116 | } |
||
117 | catch (FilterChainFailedException e) |
||
118 | { |
||
119 | return mapping.findForward("error401"); |
||
120 | } |
||
121 | catch (NotFoundException e) |
||
122 | { |
||
123 | return mapping.findForward("error404"); |
||
124 | } |
||
125 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
126 | { |
||
127 | logger.error(e, e); |
||
128 | return mapping.findForward("error500"); |
||
129 | } |
||
130 | } |
||
131 | |||
132 | public ActionForward submit(ActionMapping mapping, |
||
133 | ActionForm form, |
||
134 | HttpServletRequest request, |
||
135 | HttpServletResponse response) |
||
136 | throws ServletException |
||
137 | { |
||
138 | try |
||
139 | { |
||
140 | CourseForm cF = (CourseForm) form; |
||
141 | IServiceManager sm = ServiceManager.getInstance(); |
||
142 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"object"}; |
||
143 | 5+0%2Fdocs%2Fapi+Object">Object[] args; |
||
144 | |||
145 | if(cF.getStudiesPlan() == null || cF.getStudiesPlan().getFileSize() <= 0) |
||
146 | args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cF.getCourseView(),null,null,0,null}; |
||
147 | else //ring name, int size, String contentType, String extensio |
||
148 | args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cF.getCourseView(),cF.getStudiesPlan().getInputStream(),cF.getStudiesPlan().getFileName(),cF.getStudiesPlan().getFileSize(),cF.getStudiesPlan().getContentType()}; |
||
149 | |||
150 | long id = cF.getCourseView().getId(); |
||
151 | CourseView cV = (CourseView) sm.execute(RequestUtils.getRequester(request, response), "SubmitCourse", args, names); |
||
152 | request.setAttribute("CourseView",cV); |
||
248 | jmachado | 153 | if(cV.getHtmlResult() != null) |
154 | { |
||
155 | return mapping.findForward("submit"); |
||
156 | } |
||
157 | |||
214 | jmachado | 158 | cF.setCourseView(cV); |
159 | if(id > 0) |
||
160 | addMessage(request,"course.updated.success","" + cV.getCode()); |
||
161 | else |
||
162 | addMessage(request,"course.created.success","" + cV.getCode()); |
||
163 | return mapping.getInputForward(); |
||
164 | } |
||
165 | catch (FilterChainFailedException e) |
||
166 | { |
||
167 | return mapping.findForward("error401"); |
||
168 | } |
||
169 | catch (NotFoundException e) |
||
170 | { |
||
171 | return mapping.findForward("error404"); |
||
172 | } |
||
173 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
174 | { |
||
175 | logger.error(e, e); |
||
176 | return mapping.findForward("error500"); |
||
177 | } |
||
178 | } |
||
343 | jmachado | 179 | |
180 | |||
344 | jmachado | 181 | public ActionForward loadCoursesPrograms(ActionMapping mapping, |
182 | ActionForm form, |
||
183 | HttpServletRequest request, |
||
184 | HttpServletResponse response) |
||
185 | throws ServletException |
||
186 | { |
||
187 | try |
||
188 | { |
||
189 | CourseForm cF = (CourseForm) form; |
||
190 | IServiceManager sm = ServiceManager.getInstance(); |
||
191 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
||
192 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
||
193 | DirectedCoordinatedCourses directedCoordinatedCourses = (DirectedCoordinatedCourses) sm.execute(RequestUtils.getRequester(request, response), "LoadCoursesProgramsForServices", args, names); |
||
194 | cF.setDirectedCoordinatedCourses(directedCoordinatedCourses); |
||
195 | return mapping.findForward("load.courses.programs"); |
||
196 | } |
||
197 | catch (FilterChainFailedException e) |
||
198 | { |
||
199 | return mapping.findForward("error401"); |
||
200 | } |
||
201 | catch (NotFoundException e) |
||
202 | { |
||
203 | return mapping.findForward("error404"); |
||
204 | } |
||
205 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
206 | { |
||
207 | logger.error(e, e); |
||
208 | return mapping.findForward("error500"); |
||
209 | } |
||
210 | } |
||
211 | |||
343 | jmachado | 212 | public ActionForward loadDirectedCoordininatedCourses(ActionMapping mapping, |
213 | ActionForm form, |
||
214 | HttpServletRequest request, |
||
215 | HttpServletResponse response) |
||
216 | throws ServletException |
||
217 | { |
||
218 | try |
||
219 | { |
||
220 | CourseForm cF = (CourseForm) form; |
||
221 | IServiceManager sm = ServiceManager.getInstance(); |
||
222 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
||
223 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 1.5.0/docs/api/java/lang/String.html">String[]{}; |
||
224 | DirectedCoordinatedCourses directedCoordinatedCourses = (DirectedCoordinatedCourses) sm.execute(RequestUtils.getRequester(request, response), "LoadDirectedCoordinatedCoursesForUserInSession", args, names); |
||
225 | cF.setDirectedCoordinatedCourses(directedCoordinatedCourses); |
||
226 | return mapping.findForward("load.directed.coordinated.courses"); |
||
227 | } |
||
228 | catch (FilterChainFailedException e) |
||
229 | { |
||
230 | return mapping.findForward("error401"); |
||
231 | } |
||
232 | catch (NotFoundException e) |
||
233 | { |
||
234 | return mapping.findForward("error404"); |
||
235 | } |
||
236 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
237 | { |
||
238 | logger.error(e, e); |
||
239 | return mapping.findForward("error500"); |
||
240 | } |
||
241 | } |
||
242 | |||
243 | public ActionForward updateDirectedCoordininatedCourses(ActionMapping mapping, |
||
244 | ActionForm form, |
||
245 | HttpServletRequest request, |
||
246 | HttpServletResponse response) |
||
247 | throws ServletException |
||
248 | { |
||
249 | try |
||
250 | { |
||
251 | CourseForm cF = (CourseForm) form; |
||
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[]{"directedCoordinatedCourses"}; |
||
254 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cF.getDirectedCoordinatedCourses()}; |
||
255 | DirectedCoordinatedCourses directedCoordinatedCourses = (DirectedCoordinatedCourses) sm.execute(RequestUtils.getRequester(request, response), "UpdateDirectedCoordinatedCoursesForUserInSession", args, names); |
||
256 | cF.setDirectedCoordinatedCourses(directedCoordinatedCourses); |
||
257 | addMessage(request,"course.directed.coordinated.courses.updated.success",""+directedCoordinatedCourses.getUpdated()); |
||
258 | return mapping.findForward("home"); |
||
259 | } |
||
260 | catch (FilterChainFailedException e) |
||
261 | { |
||
262 | return mapping.findForward("error401"); |
||
263 | } |
||
264 | catch (NotFoundException e) |
||
265 | { |
||
266 | return mapping.findForward("error404"); |
||
267 | } |
||
268 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
269 | { |
||
270 | logger.error(e, e); |
||
271 | return mapping.findForward("error500"); |
||
272 | } |
||
273 | } |
||
214 | jmachado | 274 | } |