Rev 214 | Rev 343 | 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; |
||
14 | import pt.utl.ist.berserk.logic.serviceManager.IServiceManager; |
||
15 | import pt.utl.ist.berserk.logic.serviceManager.ServiceManager; |
||
16 | import pt.utl.ist.berserk.logic.serviceManager.exceptions.FilterChainFailedException; |
||
17 | import pt.utl.ist.berserk.logic.serviceManager.exceptions.ServiceManagerException; |
||
18 | import pt.utl.ist.berserk.logic.filterManager.exceptions.*; |
||
19 | import org.apache.log4j.Logger; |
||
20 | import org.apache.struts.action.ActionForward; |
||
21 | import org.apache.struts.action.ActionMapping; |
||
22 | import org.apache.struts.action.ActionForm; |
||
23 | |||
24 | import javax.servlet.http.HttpServletRequest; |
||
25 | import javax.servlet.http.HttpServletResponse; |
||
26 | import javax.servlet.ServletException; |
||
27 | |||
28 | /** |
||
29 | * @author Jorge Machado |
||
30 | * @author Fabio Velez |
||
31 | * @date 26/Fev/2008 |
||
32 | * @time 18:01:54 |
||
33 | * @see pt.estgp.estgweb.web |
||
34 | */ |
||
35 | public class CoursesController extends CourseUnitsController |
||
36 | { |
||
37 | |||
38 | 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); |
||
39 | |||
40 | |||
41 | public ActionForward startNew(ActionMapping mapping, |
||
42 | ActionForm form, |
||
43 | HttpServletRequest request, |
||
44 | HttpServletResponse response) |
||
45 | throws ServletException |
||
46 | { |
||
47 | CourseForm cF = (CourseForm) form; |
||
48 | CourseView cV = cF.getCourseView(); |
||
49 | request.setAttribute("CourseView",cV); |
||
50 | cF.setCourseView(cV); |
||
51 | return mapping.findForward("submit"); |
||
52 | } |
||
53 | |||
54 | private void load(CourseForm cF, HttpServletRequest request, HttpServletResponse response) |
||
55 | throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, InvalidFilterException, ServiceManagerException, InvalidFilterExpressionException, IncompatibleFilterException, FilterRetrieveException, NoCookiesException |
||
56 | { |
||
57 | 1.5.0/docs/api/java/lang/String.html">String code = cF.getCourseView().getCode(); |
||
58 | long id = cF.getCourseView().getId(); |
||
248 | jmachado | 59 | |
214 | jmachado | 60 | IServiceManager sm = ServiceManager.getInstance(); |
61 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"}; |
||
62 | 5+0%2Fdocs%2Fapi+Object">Object[] args; |
||
63 | 1.5.0/docs/api/java/lang/String.html">String serviceName; |
||
64 | if(code != null) |
||
65 | { |
||
66 | args = new 5+0%2Fdocs%2Fapi+Object">Object[]{code,true}; |
||
67 | serviceName = "LoadCourseByCode"; |
||
68 | } |
||
69 | else |
||
70 | { |
||
71 | args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id,true}; |
||
72 | serviceName = "LoadCourse"; |
||
73 | } |
||
74 | CourseView cV = (CourseView) sm.execute(RequestUtils.getRequester(request, response), serviceName, args, names); |
||
75 | request.setAttribute("CourseView",cV); |
||
76 | cF.setCourseView(cV); |
||
77 | } |
||
78 | |||
79 | public ActionForward load(ActionMapping mapping, |
||
80 | ActionForm form, |
||
81 | HttpServletRequest request, |
||
82 | HttpServletResponse response) |
||
83 | throws ServletException |
||
84 | { |
||
85 | try |
||
86 | { |
||
87 | load((CourseForm) form,request,response); |
||
88 | return mapping.findForward("load"); |
||
89 | } |
||
90 | catch (FilterChainFailedException e) |
||
91 | { |
||
92 | return mapping.findForward("error401"); |
||
93 | } |
||
94 | catch (NotFoundException e) |
||
95 | { |
||
96 | return mapping.findForward("error404"); |
||
97 | } |
||
98 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
99 | { |
||
100 | logger.error(e, e); |
||
101 | return mapping.findForward("error500"); |
||
102 | } |
||
103 | } |
||
104 | |||
105 | public ActionForward edit(ActionMapping mapping, |
||
106 | ActionForm form, |
||
107 | HttpServletRequest request, |
||
108 | HttpServletResponse response) |
||
109 | throws ServletException |
||
110 | { |
||
111 | try |
||
112 | { |
||
113 | load((CourseForm) form,request,response); |
||
114 | return mapping.findForward("submit"); |
||
115 | } |
||
116 | catch (FilterChainFailedException e) |
||
117 | { |
||
118 | return mapping.findForward("error401"); |
||
119 | } |
||
120 | catch (NotFoundException e) |
||
121 | { |
||
122 | return mapping.findForward("error404"); |
||
123 | } |
||
124 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
125 | { |
||
126 | logger.error(e, e); |
||
127 | return mapping.findForward("error500"); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | public ActionForward submit(ActionMapping mapping, |
||
132 | ActionForm form, |
||
133 | HttpServletRequest request, |
||
134 | HttpServletResponse response) |
||
135 | throws ServletException |
||
136 | { |
||
137 | try |
||
138 | { |
||
139 | CourseForm cF = (CourseForm) form; |
||
140 | IServiceManager sm = ServiceManager.getInstance(); |
||
141 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"object"}; |
||
142 | 5+0%2Fdocs%2Fapi+Object">Object[] args; |
||
143 | |||
144 | if(cF.getStudiesPlan() == null || cF.getStudiesPlan().getFileSize() <= 0) |
||
145 | args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cF.getCourseView(),null,null,0,null}; |
||
146 | else //ring name, int size, String contentType, String extensio |
||
147 | args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cF.getCourseView(),cF.getStudiesPlan().getInputStream(),cF.getStudiesPlan().getFileName(),cF.getStudiesPlan().getFileSize(),cF.getStudiesPlan().getContentType()}; |
||
148 | |||
149 | long id = cF.getCourseView().getId(); |
||
150 | CourseView cV = (CourseView) sm.execute(RequestUtils.getRequester(request, response), "SubmitCourse", args, names); |
||
151 | request.setAttribute("CourseView",cV); |
||
248 | jmachado | 152 | if(cV.getHtmlResult() != null) |
153 | { |
||
154 | return mapping.findForward("submit"); |
||
155 | } |
||
156 | |||
214 | jmachado | 157 | cF.setCourseView(cV); |
158 | if(id > 0) |
||
159 | addMessage(request,"course.updated.success","" + cV.getCode()); |
||
160 | else |
||
161 | addMessage(request,"course.created.success","" + cV.getCode()); |
||
162 | return mapping.getInputForward(); |
||
163 | } |
||
164 | catch (FilterChainFailedException e) |
||
165 | { |
||
166 | return mapping.findForward("error401"); |
||
167 | } |
||
168 | catch (NotFoundException e) |
||
169 | { |
||
170 | return mapping.findForward("error404"); |
||
171 | } |
||
172 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
173 | { |
||
174 | logger.error(e, e); |
||
175 | return mapping.findForward("error500"); |
||
176 | } |
||
177 | } |
||
178 | } |