Subversion Repositories bacoAlunos

Rev

Rev 1486 | Rev 1505 | 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
 
376 jmachado 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.views.CourseView;
8
import pt.estgp.estgweb.filters.exceptions.NotFoundException;
9
import pt.estgp.estgweb.services.courseunits.DirectedCoordinatedCourses;
10
import pt.estgp.estgweb.services.courseunits.DirectedCoordinatedUnitsService;
444 jmachado 11
import pt.estgp.estgweb.services.expceptions.AlreadyExistsException;
214 jmachado 12
import pt.estgp.estgweb.web.controllers.courseunits.CourseUnitsController;
376 jmachado 13
import pt.estgp.estgweb.web.exceptions.NoCookiesException;
214 jmachado 14
import pt.estgp.estgweb.web.form.courses.CourseForm;
15
import pt.estgp.estgweb.web.utils.RequestUtils;
376 jmachado 16
import pt.utl.ist.berserk.logic.filterManager.exceptions.FilterRetrieveException;
17
import pt.utl.ist.berserk.logic.filterManager.exceptions.IncompatibleFilterException;
18
import pt.utl.ist.berserk.logic.filterManager.exceptions.InvalidFilterException;
19
import pt.utl.ist.berserk.logic.filterManager.exceptions.InvalidFilterExpressionException;
214 jmachado 20
import pt.utl.ist.berserk.logic.serviceManager.IServiceManager;
21
import pt.utl.ist.berserk.logic.serviceManager.ServiceManager;
22
import pt.utl.ist.berserk.logic.serviceManager.exceptions.FilterChainFailedException;
23
import pt.utl.ist.berserk.logic.serviceManager.exceptions.ServiceManagerException;
24
 
376 jmachado 25
import javax.servlet.ServletException;
214 jmachado 26
import javax.servlet.http.HttpServletRequest;
27
import javax.servlet.http.HttpServletResponse;
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();
376 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
 
1486 jmachado 80
    private void loadForPublic(CourseForm cF, HttpServletRequest request, HttpServletResponse response)
81
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, InvalidFilterException, ServiceManagerException, InvalidFilterExpressionException, IncompatibleFilterException, FilterRetrieveException, NoCookiesException
82
    {
83
        1.5.0/docs/api/java/lang/String.html">String code = cF.getCourseView().getCode();
84
        long id = cF.getCourseView().getId();
85
 
86
        IServiceManager sm = ServiceManager.getInstance();
87
        1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
88
        5+0%2Fdocs%2Fapi+Object">Object[] args;
89
        1.5.0/docs/api/java/lang/String.html">String serviceName;
90
        if(code != null)
91
        {
92
            args = new 5+0%2Fdocs%2Fapi+Object">Object[]{code,false};
93
            serviceName = "LoadCourseByCode";
94
        }
95
        else
96
        {
1487 jmachado 97
            args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id,false};
1486 jmachado 98
            serviceName = "LoadCourse";
99
        }
100
        CourseView cV = (CourseView) sm.execute(RequestUtils.getRequester(request, response), serviceName, args, names);
101
        request.setAttribute("CourseView",cV);
102
        cF.setCourseView(cV);
103
    }
104
 
649 jmachado 105
    public ActionForward loadPlan(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("loadPlan");
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
 
214 jmachado 131
    public ActionForward load(ActionMapping mapping,
132
                              ActionForm form,
133
                              HttpServletRequest request,
134
                              HttpServletResponse response)
135
            throws ServletException
136
    {
137
        try
138
        {
139
            load((CourseForm) form,request,response);
140
            return mapping.findForward("load");
141
        }
142
        catch (FilterChainFailedException e)
143
        {
144
            return mapping.findForward("error401");
145
        }
146
        catch (NotFoundException e)
147
        {
148
            return mapping.findForward("error404");
149
        }
150
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
151
        {
152
            logger.error(e, e);
153
            return mapping.findForward("error500");
154
        }
155
    }
156
 
641 jmachado 157
 
158
      public ActionForward loadSeparators(ActionMapping mapping,
159
                              ActionForm form,
160
                              HttpServletRequest request,
161
                              HttpServletResponse response)
162
            throws ServletException
163
    {
164
        try
165
        {
1486 jmachado 166
            loadForPublic((CourseForm) form,request,response);
641 jmachado 167
            return mapping.findForward("loadSeparators");
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
 
649 jmachado 184
 
185
    public ActionForward loadMenu(ActionMapping mapping,
186
                                 ActionForm form,
187
                                 HttpServletRequest request,
188
                                 HttpServletResponse response)
189
               throws ServletException
190
       {
191
           try
192
           {
193
               load((CourseForm) form,request,response);
194
               return mapping.findForward("loadMenu");
195
           }
196
           catch (FilterChainFailedException e)
197
           {
198
               return mapping.findForward("error401");
199
           }
200
           catch (NotFoundException e)
201
           {
202
               return mapping.findForward("error404");
203
           }
204
           catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
205
           {
206
               logger.error(e, e);
207
               return mapping.findForward("error500");
208
           }
209
       }
210
 
211
 
214 jmachado 212
    public ActionForward edit(ActionMapping mapping,
213
                              ActionForm form,
214
                              HttpServletRequest request,
215
                              HttpServletResponse response)
216
            throws ServletException
217
    {
218
        try
219
        {
220
            load((CourseForm) form,request,response);
221
            return mapping.findForward("submit");
222
        }
223
        catch (FilterChainFailedException e)
224
        {
225
            return mapping.findForward("error401");
226
        }
227
        catch (NotFoundException e)
228
        {
229
            return mapping.findForward("error404");
230
        }
231
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
232
        {
233
            logger.error(e, e);
234
            return mapping.findForward("error500");
235
        }
236
    }
237
 
238
    public ActionForward submit(ActionMapping mapping,
239
                                ActionForm form,
240
                                HttpServletRequest request,
241
                                HttpServletResponse response)
242
            throws ServletException
243
    {
244
        try
245
        {
246
            CourseForm cF = (CourseForm) form;
247
            IServiceManager sm = ServiceManager.getInstance();
248
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"object"};
249
            5+0%2Fdocs%2Fapi+Object">Object[] args;
250
 
251
            if(cF.getStudiesPlan() == null || cF.getStudiesPlan().getFileSize() <= 0)
252
                args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cF.getCourseView(),null,null,0,null};
253
            else                              //ring name, int size, String contentType, String extensio
254
                args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cF.getCourseView(),cF.getStudiesPlan().getInputStream(),cF.getStudiesPlan().getFileName(),cF.getStudiesPlan().getFileSize(),cF.getStudiesPlan().getContentType()};
255
 
256
            long id = cF.getCourseView().getId();
257
            CourseView cV = (CourseView) sm.execute(RequestUtils.getRequester(request, response), "SubmitCourse", args, names);
258
            request.setAttribute("CourseView",cV);
248 jmachado 259
            if(cV.getHtmlResult() != null)
260
            {
376 jmachado 261
                return mapping.findForward("submit");
248 jmachado 262
            }
263
 
214 jmachado 264
            cF.setCourseView(cV);
265
            if(id > 0)
266
                addMessage(request,"course.updated.success","" + cV.getCode());
267
            else
268
                addMessage(request,"course.created.success","" + cV.getCode());
269
            return mapping.getInputForward();
270
        }
444 jmachado 271
        catch (AlreadyExistsException e)
272
        {
273
            addErrorWithKeys(request,"course.exists",e.getMessage());
274
            try
275
            {
276
                load((CourseForm) form,request,response);
277
                return mapping.findForward("submit");
278
            }
279
            catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable throwable)
280
            {
281
                logger.error(e, e);
282
                return mapping.findForward("error500");
283
            }
284
        }
214 jmachado 285
        catch (FilterChainFailedException e)
286
        {
287
            return mapping.findForward("error401");
288
        }
289
        catch (NotFoundException e)
290
        {
291
            return mapping.findForward("error404");
292
        }
293
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
294
        {
295
            logger.error(e, e);
296
            return mapping.findForward("error500");
297
        }
298
    }
343 jmachado 299
 
300
 
344 jmachado 301
    public ActionForward loadCoursesPrograms(ActionMapping mapping,
376 jmachado 302
                                             ActionForm form,
303
                                             HttpServletRequest request,
304
                                             HttpServletResponse response)
344 jmachado 305
            throws ServletException
306
    {
307
        try
308
        {
309
            CourseForm cF = (CourseForm) form;
345 jmachado 310
            1.5.0/docs/api/java/lang/String.html">String importYear = cF.getImportYear();
376 jmachado 311
            long courseId = cF.getCourseId();
1039 jmachado 312
            if(courseId <= 0)
313
            {
314
                addError(request,"courses.fill.course");
315
                return mapping.findForward("load.courses.programs");
316
            }
376 jmachado 317
            1.5.0/docs/api/java/lang/String.html">String semestre = cF.getSemestre();
318
            1.5.0/docs/api/java/lang/String.html">String area = cF.getArea();
319
            DirectedCoordinatedUnitsService.TeachersSituationEnum teachersSituationEnum = cF.getTeacherSituationEnum();
1312 jmachado 320
            1.5.0/docs/api/java/lang/String.html">String institutionCode = cF.getInstitutionCode();
376 jmachado 321
 
344 jmachado 322
            IServiceManager sm = ServiceManager.getInstance();
1312 jmachado 323
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"importYear","courseId","semestre","area","teachersSituationEnum","institutionCode"};
324
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{importYear,courseId,semestre,area,teachersSituationEnum,institutionCode};
344 jmachado 325
            DirectedCoordinatedCourses directedCoordinatedCourses = (DirectedCoordinatedCourses) sm.execute(RequestUtils.getRequester(request, response), "LoadCoursesProgramsForServices", args, names);
326
            cF.setDirectedCoordinatedCourses(directedCoordinatedCourses);
376 jmachado 327
            cF.setArea(directedCoordinatedCourses.getArea());
328
            cF.setCourseId(directedCoordinatedCourses.getCourseId());
344 jmachado 329
            return mapping.findForward("load.courses.programs");
330
        }
331
        catch (FilterChainFailedException e)
332
        {
333
            return mapping.findForward("error401");
334
        }
335
        catch (NotFoundException e)
336
        {
337
            return mapping.findForward("error404");
338
        }
339
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
340
        {
341
            logger.error(e, e);
342
            return mapping.findForward("error500");
343
        }
344
    }
345
 
343 jmachado 346
    public ActionForward loadDirectedCoordininatedCourses(ActionMapping mapping,
376 jmachado 347
                                                          ActionForm form,
348
                                                          HttpServletRequest request,
349
                                                          HttpServletResponse response)
343 jmachado 350
            throws ServletException
351
    {
352
        try
353
        {
345 jmachado 354
 
343 jmachado 355
            CourseForm cF = (CourseForm) form;
345 jmachado 356
            1.5.0/docs/api/java/lang/String.html">String importYear = cF.getImportYear();
343 jmachado 357
            IServiceManager sm = ServiceManager.getInstance();
345 jmachado 358
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"importYear"};
359
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 1.5.0/docs/api/java/lang/String.html">String[]{importYear};
343 jmachado 360
            DirectedCoordinatedCourses directedCoordinatedCourses = (DirectedCoordinatedCourses) sm.execute(RequestUtils.getRequester(request, response), "LoadDirectedCoordinatedCoursesForUserInSession", args, names);
361
            cF.setDirectedCoordinatedCourses(directedCoordinatedCourses);
362
            return mapping.findForward("load.directed.coordinated.courses");
363
        }
364
        catch (FilterChainFailedException e)
365
        {
366
            return mapping.findForward("error401");
367
        }
368
        catch (NotFoundException e)
369
        {
370
            return mapping.findForward("error404");
371
        }
372
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
373
        {
374
            logger.error(e, e);
375
            return mapping.findForward("error500");
376
        }
377
    }
378
 
379
    public ActionForward updateDirectedCoordininatedCourses(ActionMapping mapping,
376 jmachado 380
                                                            ActionForm form,
381
                                                            HttpServletRequest request,
382
                                                            HttpServletResponse response)
343 jmachado 383
            throws ServletException
384
    {
385
        try
386
        {
387
            CourseForm cF = (CourseForm) form;
388
            IServiceManager sm = ServiceManager.getInstance();
389
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"directedCoordinatedCourses"};
390
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cF.getDirectedCoordinatedCourses()};
391
            DirectedCoordinatedCourses directedCoordinatedCourses = (DirectedCoordinatedCourses) sm.execute(RequestUtils.getRequester(request, response), "UpdateDirectedCoordinatedCoursesForUserInSession", args, names);
392
            cF.setDirectedCoordinatedCourses(directedCoordinatedCourses);
393
            addMessage(request,"course.directed.coordinated.courses.updated.success",""+directedCoordinatedCourses.getUpdated());
345 jmachado 394
            return mapping.findForward("confirm.courses.programs");
343 jmachado 395
        }
396
        catch (FilterChainFailedException e)
397
        {
398
            return mapping.findForward("error401");
399
        }
400
        catch (NotFoundException e)
401
        {
402
            return mapping.findForward("error404");
403
        }
404
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
405
        {
406
            logger.error(e, e);
407
            return mapping.findForward("error500");
408
        }
409
    }
214 jmachado 410
}