Subversion Repositories bacoAlunos

Rev

Rev 1667 | Rev 1744 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
203 jmachado 1
package pt.estgp.estgweb.web.controllers.courseunits;
2
 
205 jmachado 3
import org.apache.log4j.Logger;
885 jmachado 4
import org.apache.struts.action.*;
207 jmachado 5
import org.apache.struts.upload.FormFile;
205 jmachado 6
import org.hibernate.ObjectNotFoundException;
749 jmachado 7
import pt.estgp.estgweb.Globals;
901 jmachado 8
import pt.estgp.estgweb.domain.views.BlogView;
9
import pt.estgp.estgweb.domain.views.CourseUnitAssignementView;
10
import pt.estgp.estgweb.domain.views.CourseUnitView;
11
import pt.estgp.estgweb.domain.views.UserView;
205 jmachado 12
import pt.estgp.estgweb.filters.exceptions.NotFoundException;
749 jmachado 13
import pt.estgp.estgweb.web.controllers.blogs.BlogsController;
215 jmachado 14
import pt.estgp.estgweb.web.controllers.profile.ProfileController;
1667 jmachado 15
import pt.estgp.estgweb.web.controllers.utils.AbstractWidgetAjaxController;
205 jmachado 16
import pt.estgp.estgweb.web.exceptions.NoCookiesException;
749 jmachado 17
import pt.estgp.estgweb.web.form.blogs.BlogForm;
204 jmachado 18
import pt.estgp.estgweb.web.form.courseunits.CourseUnitsForm;
215 jmachado 19
import pt.estgp.estgweb.web.form.profile.ProfileForm;
203 jmachado 20
import pt.estgp.estgweb.web.utils.RequestUtils;
205 jmachado 21
import pt.utl.ist.berserk.logic.filterManager.exceptions.FilterRetrieveException;
22
import pt.utl.ist.berserk.logic.filterManager.exceptions.IncompatibleFilterException;
23
import pt.utl.ist.berserk.logic.filterManager.exceptions.InvalidFilterException;
24
import pt.utl.ist.berserk.logic.filterManager.exceptions.InvalidFilterExpressionException;
203 jmachado 25
import pt.utl.ist.berserk.logic.serviceManager.IServiceManager;
26
import pt.utl.ist.berserk.logic.serviceManager.ServiceManager;
205 jmachado 27
import pt.utl.ist.berserk.logic.serviceManager.exceptions.ExecutedFilterException;
203 jmachado 28
import pt.utl.ist.berserk.logic.serviceManager.exceptions.FilterChainFailedException;
29
import pt.utl.ist.berserk.logic.serviceManager.exceptions.ServiceManagerException;
30
 
205 jmachado 31
import javax.servlet.ServletException;
203 jmachado 32
import javax.servlet.http.HttpServletRequest;
33
import javax.servlet.http.HttpServletResponse;
34
 
35
 
36
/**
37
 * @author Jorge Machado
38
 * @author Fabio Velez
39
 * @date 26/Fev/2008
40
 * @time 18:01:54
41
 * @see pt.estgp.estgweb.web
42
 */
1667 jmachado 43
public class CourseUnitsController extends AbstractWidgetAjaxController
203 jmachado 44
{
45
    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(CourseUnitsController.class);
46
 
847 jmachado 47
    protected ActionForward createBackup(1.5.0/docs/api/java/lang/String.html">String service,
345 jmachado 48
                                       5+0%2Fdocs%2Fapi+Object">Object[] args,
218 jmachado 49
                                       ActionMapping mapping,
50
                                       ActionForm form,
51
                                       HttpServletRequest request,
52
                                       HttpServletResponse response)
53
            throws ServletException
54
    {
55
        try
56
        {
57
            IServiceManager sm = ServiceManager.getInstance();
58
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{};
59
            1.5.0/docs/api/java/lang/String.html">String tmpFile = (1.5.0/docs/api/java/lang/String.html">String) sm.execute(RequestUtils.getRequester(request, response), service, args, names);
60
            request.getRequestDispatcher("/tmpStream/" + tmpFile).forward(request,response);
61
            return null;
62
        }
63
        catch (FilterChainFailedException e)
64
        {
65
            return mapping.findForward("error401");
66
        }
67
        catch (NotFoundException e)
68
        {
69
            return mapping.findForward("error404");
70
        }
71
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
72
        {
73
            logger.error(e, e);
74
            return mapping.findForward("error500");
75
        }
76
    }
223 jmachado 77
    public ActionForward createUserAllCourseUnitWorksBackup(ActionMapping mapping,
749 jmachado 78
                                                            ActionForm form,
79
                                                            HttpServletRequest request,
80
                                                            HttpServletResponse response)
218 jmachado 81
            throws ServletException
82
    {
749 jmachado 83
        1.5.0/docs/api/java/lang/String.html">String[] args = new 1.5.0/docs/api/java/lang/String.html">String[]{};
345 jmachado 84
        return createBackup("CreateUserAllCourseUnitWorksBackup",args,mapping,form,request,response);
218 jmachado 85
    }
749 jmachado 86
 
859 jmachado 87
 
88
    public ActionForward createUserAllCourseUnitProgramsBackup(ActionMapping mapping,
89
                                                            ActionForm form,
90
                                                            HttpServletRequest request,
91
                                                            HttpServletResponse response)
92
            throws ServletException
93
    {
94
        1.5.0/docs/api/java/lang/String.html">String[] args = new 1.5.0/docs/api/java/lang/String.html">String[]{};
95
        return createBackup("CreateUserAllCourseUnitProgramsBackup",args,mapping,form,request,response);
96
    }
97
 
223 jmachado 98
    public ActionForward createUserCourseUnitActualYearWorksBackup(ActionMapping mapping,
749 jmachado 99
                                                                   ActionForm form,
100
                                                                   HttpServletRequest request,
101
                                                                   HttpServletResponse response)
218 jmachado 102
            throws ServletException
103
    {
345 jmachado 104
        1.5.0/docs/api/java/lang/String.html">String importYear = request.getParameter("importYear");
749 jmachado 105
        1.5.0/docs/api/java/lang/String.html">String[] args = new 1.5.0/docs/api/java/lang/String.html">String[]{importYear};
345 jmachado 106
        return createBackup("CreateUserImportYearCourseUnitWorksBackup",args,mapping,form,request,response);
218 jmachado 107
    }
108
 
847 jmachado 109
    protected ActionForward loadCourseUnitAndForward(CourseUnitsForm cUF, long id, boolean initTeachers, boolean initStudents, ActionMapping mapping, HttpServletRequest request, HttpServletResponse response)
203 jmachado 110
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, InvalidFilterException, ServiceManagerException, InvalidFilterExpressionException, IncompatibleFilterException, FilterRetrieveException, NoCookiesException
111
    {
208 jmachado 112
        CourseUnitView cV = loadCourseUnitView(id,initTeachers,initStudents, mapping, request, response);
204 jmachado 113
        cUF.setCourseUnitView(cV);
203 jmachado 114
        request.setAttribute("CourseUnitView", cV);
115
        return mapping.findForward("load");
116
    }
117
 
847 jmachado 118
    protected CourseUnitView loadCourseUnitView(long id, boolean initTeachers, boolean initStudents, ActionMapping mapping, HttpServletRequest request, HttpServletResponse response)
203 jmachado 119
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, InvalidFilterException, ServiceManagerException, InvalidFilterExpressionException, IncompatibleFilterException, FilterRetrieveException, NoCookiesException
120
    {
121
        IServiceManager sm = ServiceManager.getInstance();
122
        1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
208 jmachado 123
        5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id,initTeachers,initStudents,false};
203 jmachado 124
        try
125
        {
126
            CourseUnitView cV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), "LoadCourseUnit", args, names);
127
            return cV;
128
        }
129
        catch (ExecutedFilterException e)
130
        {
131
            if (e.getCause() instanceof ObjectNotFoundException)
132
            {
133
                throw new NotFoundException(e.getCause().toString());
134
            }
135
            throw e;
136
        }
137
    }
1354 jmachado 138
    protected CourseUnitView loadCourseUnitViewCleared(long id, boolean initTeachers, boolean initStudents, ActionMapping mapping, HttpServletRequest request, HttpServletResponse response)
139
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, InvalidFilterException, ServiceManagerException, InvalidFilterExpressionException, IncompatibleFilterException, FilterRetrieveException, NoCookiesException
140
    {
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[]{"serializable"};
143
        5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id,initTeachers,initStudents,false};
144
        try
145
        {
146
            CourseUnitView cV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), "LoadCourseUnitCleared", args, names);
147
            return cV;
148
        }
149
        catch (ExecutedFilterException e)
150
        {
151
            if (e.getCause() instanceof ObjectNotFoundException)
152
            {
153
                throw new NotFoundException(e.getCause().toString());
154
            }
155
            throw e;
156
        }
157
    }
203 jmachado 158
 
847 jmachado 159
    protected CourseUnitView loadCourseUnitViewAndCourse(long id, boolean initTeachers, boolean initStudents, ActionMapping mapping, HttpServletRequest request, HttpServletResponse response)
749 jmachado 160
                throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, InvalidFilterException, ServiceManagerException, InvalidFilterExpressionException, IncompatibleFilterException, FilterRetrieveException, NoCookiesException
161
        {
162
            IServiceManager sm = ServiceManager.getInstance();
163
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
164
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id,initTeachers,initStudents,false,true};
165
            try
166
            {
167
                CourseUnitView cV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), "LoadCourseUnitViewAndCourse", args, names);
168
                return cV;
169
            }
170
            catch (ExecutedFilterException e)
171
            {
172
                if (e.getCause() instanceof ObjectNotFoundException)
173
                {
174
                    throw new NotFoundException(e.getCause().toString());
175
                }
176
                throw e;
177
            }
178
        }
208 jmachado 179
 
749 jmachado 180
 
1353 jmachado 181
    public ActionForward loadStats(ActionMapping mapping,
182
                              ActionForm form,
183
                              HttpServletRequest request,
184
                              HttpServletResponse response)
185
            throws ServletException
186
    {
187
        try
188
        {
189
            CourseUnitsForm cUF = (CourseUnitsForm) form;
190
            long id;
191
            if(cUF.getCourseUnitView() != null && cUF.getCourseUnitView().getId() > 0)
192
                id = cUF.getCourseUnitView().getId();
193
            else
194
                id = 1.5.0/docs/api/java/lang/Long.html">Long.parseLong(request.getParameter("id"));
195
 
1354 jmachado 196
            CourseUnitView cV = loadCourseUnitViewCleared(id,false,false, mapping, request, response);
1353 jmachado 197
            cUF.setCourseUnitView(cV);
198
            request.setAttribute("CourseUnitView", cV);
199
            return mapping.findForward("loadStats");
200
 
201
        }
202
        catch (FilterChainFailedException e)
203
        {
204
            return mapping.findForward("error401");
205
        }
206
        catch (NotFoundException e)
207
        {
208
            return mapping.findForward("error404");
209
        }
210
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
211
        {
212
            logger.error(e, e);
213
            return mapping.findForward("error500");
214
        }
215
    }
216
 
203 jmachado 217
    public ActionForward load(ActionMapping mapping,
218
                              ActionForm form,
219
                              HttpServletRequest request,
220
                              HttpServletResponse response)
221
            throws ServletException
222
    {
223
        try
224
        {
204 jmachado 225
            CourseUnitsForm cUF = (CourseUnitsForm) form;
208 jmachado 226
            long id;
214 jmachado 227
            if(cUF.getCourseUnitView() != null && cUF.getCourseUnitView().getId() > 0)
228
                id = cUF.getCourseUnitView().getId();
229
            else
208 jmachado 230
                id = 1.5.0/docs/api/java/lang/Long.html">Long.parseLong(request.getParameter("id"));
214 jmachado 231
 
208 jmachado 232
            return loadCourseUnitAndForward(cUF,id ,true,false, mapping, request, response);
203 jmachado 233
        }
234
        catch (FilterChainFailedException e)
235
        {
236
            return mapping.findForward("error401");
237
        }
238
        catch (NotFoundException e)
239
        {
240
            return mapping.findForward("error404");
241
        }
242
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
243
        {
244
            logger.error(e, e);
245
            return mapping.findForward("error500");
246
        }
247
    }
248
 
883 jmachado 249
 
250
    public ActionForward loadCourseUnitWebSiteBySigesCodes(ActionMapping mapping,
251
                                            ActionForm form,
252
                                            HttpServletRequest request,
253
                                            HttpServletResponse response)
254
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
255
    {
256
        try
257
        {
258
            CourseUnitsForm cUF = (CourseUnitsForm) form;
259
            1.5.0/docs/api/java/lang/String.html">String unitCode = request.getParameter("unitCode");
260
            1.5.0/docs/api/java/lang/String.html">String courseCode = request.getParameter("courseCode");
261
            1.5.0/docs/api/java/lang/String.html">String semestre = request.getParameter("semestre");
262
 
263
 
264
            IServiceManager sm = ServiceManager.getInstance();
265
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{};
266
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{unitCode,courseCode,semestre};
1555 jmachado 267
            CourseUnitView cUV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), "LoadCourseUnitsBySigesCodesSemestreLastYearProgram", args, names);
883 jmachado 268
            return loadCourseUnitAndForward(cUF,cUV.getId() ,true,false, mapping, request, response);
269
 
270
        }
271
        catch (FilterChainFailedException e)
272
        {
273
            return mapping.findForward("error401");
274
        }
275
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
276
        {
277
            logger.error(e, e);
278
            throw e;
279
        }
280
    }
281
 
885 jmachado 282
 
283
    public ActionForward loadCourseUnitProgramBySigesCodes(ActionMapping mapping,
284
                                                           ActionForm form,
285
                                                           HttpServletRequest request,
286
                                                           HttpServletResponse response)
287
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
288
    {
289
        try
290
        {
291
            1.5.0/docs/api/java/lang/String.html">String unitCode = request.getParameter("unitCode");
292
            1.5.0/docs/api/java/lang/String.html">String courseCode = request.getParameter("courseCode");
293
            1.5.0/docs/api/java/lang/String.html">String semestre = request.getParameter("semestre");
294
 
295
 
296
            IServiceManager sm = ServiceManager.getInstance();
297
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{};
298
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{unitCode,courseCode,semestre};
1555 jmachado 299
            CourseUnitView cUV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), "LoadCourseUnitsBySigesCodesSemestreLastYearProgram", args, names);
1743 jmachado 300
            if(cUV == null)
301
            {
302
                return mapping.findForward("error404");
303
            }
304
            else
305
            {
306
                ActionRedirect forward = new ActionRedirect();
307
                forward.setPath("/repositoryStream/" + cUV.getProgramStreamId());
308
                return forward;
309
            }
885 jmachado 310
 
311
        }
312
        catch (FilterChainFailedException e)
313
        {
314
            return mapping.findForward("error401");
315
        }
316
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
317
        {
318
            logger.error(e, e);
319
            throw e;
320
        }
321
    }
322
 
208 jmachado 323
    public ActionForward loadStudents(ActionMapping mapping,
209 jmachado 324
                                      ActionForm form,
325
                                      HttpServletRequest request,
326
                                      HttpServletResponse response)
208 jmachado 327
            throws ServletException
328
    {
329
        try
330
        {
331
            CourseUnitsForm cUF = (CourseUnitsForm) form;
332
            long id;
333
            if(request.getParameter("id")!=null)
334
                id = 1.5.0/docs/api/java/lang/Long.html">Long.parseLong(request.getParameter("id"));
335
            else
336
                id = cUF.getCourseUnitView().getId();
337
            CourseUnitView cV = loadCourseUnitView(id,false,true, mapping, request, response);
209 jmachado 338
            cUF.setCourseUnitView(cV);
339
            request.setAttribute("CourseUnitView", cV);
340
            return mapping.findForward("load.students");
208 jmachado 341
        }
342
        catch (FilterChainFailedException e)
343
        {
344
            return mapping.findForward("error401");
345
        }
346
        catch (NotFoundException e)
347
        {
348
            return mapping.findForward("error404");
349
        }
350
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
351
        {
352
            logger.error(e, e);
353
            return mapping.findForward("error500");
354
        }
355
    }
356
 
215 jmachado 357
 
901 jmachado 358
    public ActionForward loadDossier(ActionMapping mapping,
359
                                      ActionForm form,
360
                                      HttpServletRequest request,
361
                                      HttpServletResponse response)
362
            throws ServletException
363
    {
364
        try
365
        {
366
            CourseUnitsForm cUF = (CourseUnitsForm) form;
367
            long id;
368
            if(request.getParameter("id")!=null)
369
                id = 1.5.0/docs/api/java/lang/Long.html">Long.parseLong(request.getParameter("id"));
370
            else
371
                id = cUF.getCourseUnitView().getId();
372
            CourseUnitView cV = loadCourseUnitView(id,false,false, mapping, request, response);
373
            cUF.setCourseUnitView(cV);
374
            request.setAttribute("CourseUnitView", cV);
375
            return mapping.findForward("load.dossier");
376
        }
377
        catch (FilterChainFailedException e)
378
        {
379
            return mapping.findForward("error401");
380
        }
381
        catch (NotFoundException e)
382
        {
383
            return mapping.findForward("error404");
384
        }
385
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
386
        {
387
            logger.error(e, e);
388
            return mapping.findForward("error500");
389
        }
390
    }
215 jmachado 391
 
901 jmachado 392
 
393
 
215 jmachado 394
    public ActionForward loadTeacher(ActionMapping mapping,
395
                                     ActionForm form,
396
                                     HttpServletRequest request,
397
                                     HttpServletResponse response)
398
            throws ServletException
399
    {
400
        try
401
        {
402
            CourseUnitsForm cUF = (CourseUnitsForm) form;
403
            int id;
404
 
406 jmachado 405
            if(request.getParameter("code") != null)
215 jmachado 406
            {
407
                id = 1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(request.getParameter("code"));
408
                UserView userView = new ProfileController().loadUserWithRecordsCode(id,request,response);
409
                ProfileForm profileForm = new ProfileForm();
410
                profileForm.setUserView(userView);
411
                request.setAttribute("ProfileForm",profileForm);
412
            }
413
            CourseUnitView cV = loadCourseUnitView(cUF.getCourseUnitView().getId(),false,false, mapping, request, response);
414
            cUF.setCourseUnitView(cV);
415
            request.setAttribute("CourseUnitView", cV);
416
            return mapping.findForward("load.teacher");
417
        }
418
        catch (FilterChainFailedException e)
419
        {
420
            return mapping.findForward("error401");
421
        }
422
        catch (NotFoundException e)
423
        {
424
            return mapping.findForward("error404");
425
        }
426
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
427
        {
428
            logger.error(e, e);
429
            return mapping.findForward("error500");
430
        }
431
    }
432
    public ActionForward loadStudent(ActionMapping mapping,
433
                                     ActionForm form,
434
                                     HttpServletRequest request,
435
                                     HttpServletResponse response)
436
            throws ServletException
437
    {
438
        ActionForward forward = loadTeacher(mapping,form,request,response);
439
        if(forward.getName().equals("load.teacher"))
440
            return mapping.findForward("load.student");
441
        else
442
            return forward;
443
    }
444
 
205 jmachado 445
    public ActionForward loadWorks(ActionMapping mapping,
446
                                   ActionForm form,
447
                                   HttpServletRequest request,
448
                                   HttpServletResponse response)
449
            throws ServletException
450
    {
451
        try
452
        {
453
            CourseUnitsForm cUF = (CourseUnitsForm) form;
207 jmachado 454
            long id = cUF.getCourseUnitView().getId();
205 jmachado 455
            IServiceManager sm = ServiceManager.getInstance();
456
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
457
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id};
458
            try
459
            {
460
                CourseUnitView cV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), "LoadCourseUnitWorks", args, names);
461
                cUF.setCourseUnitView(cV);
462
                request.setAttribute("CourseUnitView", cV);
463
                return mapping.findForward("load.works");
464
            }
465
            catch (ExecutedFilterException e)
466
            {
467
                if (e.getCause() instanceof ObjectNotFoundException)
468
                {
469
                    throw new NotFoundException(e.getCause().toString());
470
                }
471
                throw e;
472
            }
473
        }
474
        catch (FilterChainFailedException e)
475
        {
476
            return mapping.findForward("error401");
477
        }
478
        catch (NotFoundException e)
479
        {
480
            return mapping.findForward("error404");
481
        }
482
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
483
        {
484
            logger.error(e, e);
485
            return mapping.findForward("error500");
486
        }
487
    }
488
 
489
 
490
    public ActionForward createAssignement(ActionMapping mapping,
207 jmachado 491
                                           ActionForm form,
492
                                           HttpServletRequest request,
493
                                           HttpServletResponse response)
205 jmachado 494
            throws ServletException
495
    {
496
        try
497
        {
498
            CourseUnitsForm cUF = (CourseUnitsForm) form;
207 jmachado 499
            ActionErrors errors = cUF.validateCreateAssignement(mapping,request);
500
            if(!errors.isEmpty())
501
            {
502
                saveErrors(request, errors);
503
                cUF.setShowNewWorkForm(true);
504
                return loadWorks(mapping,form,request,response);
505
            }
205 jmachado 506
            long id = cUF.getCourseUnitView().getId();
507
            IServiceManager sm = ServiceManager.getInstance();
207 jmachado 508
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"object","serializable"};
208 jmachado 509
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cUF.getCourseUnitAssignementView(), id, cUF.getUploadFile().getInputStream(),cUF.getUploadFile().getFileName(),cUF.getUploadFile().getFileSize(),cUF.getUploadFile().getContentType()};
205 jmachado 510
            try
511
            {
207 jmachado 512
                1.5.0/docs/api/java/lang/String.html">String service;
513
                if(cUF.getCourseUnitAssignementView().getId() <= 0)
514
                    service = "CreateCourseUnitWork";
515
                else
516
                    service = "EditCourseUnitWork";
517
 
518
                CourseUnitView cV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), service, args, names);
205 jmachado 519
                cUF.setCourseUnitView(cV);
520
                request.setAttribute("CourseUnitView", cV);
207 jmachado 521
                cUF.setCourseUnitAssignementView(new CourseUnitAssignementView());
205 jmachado 522
                return mapping.findForward("load.works");
523
            }
524
            catch (ExecutedFilterException e)
525
            {
526
                if (e.getCause() instanceof ObjectNotFoundException)
527
                {
528
                    throw new NotFoundException(e.getCause().toString());
529
                }
530
                throw e;
531
            }
532
        }
533
        catch (FilterChainFailedException e)
534
        {
535
            return mapping.findForward("error401");
536
        }
537
        catch (NotFoundException e)
538
        {
539
            return mapping.findForward("error404");
540
        }
541
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
542
        {
543
            logger.error(e, e);
544
            return mapping.findForward("error500");
545
        }
546
    }
547
 
749 jmachado 548
 
549
 
550
 
207 jmachado 551
    public ActionForward validateInvalidateAssignement(ActionMapping mapping,
552
                                                       ActionForm form,
553
                                                       HttpServletRequest request,
554
                                                       HttpServletResponse response)
555
            throws ServletException
556
    {
557
        try
558
        {
559
            CourseUnitsForm cUF = (CourseUnitsForm) form;
560
            IServiceManager sm = ServiceManager.getInstance();
561
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
562
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cUF.getCourseUnitAssignementView().getId()};
563
            try
564
            {
565
                CourseUnitView cV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), "ValidateInvalidateCourseUnitWork", args, names);
566
                cUF.setCourseUnitView(cV);
567
                request.setAttribute("CourseUnitView", cV);
568
                cUF.setCourseUnitAssignementView(new CourseUnitAssignementView());
569
                return mapping.findForward("load.works");
570
            }
571
            catch (ExecutedFilterException e)
572
            {
573
                if (e.getCause() instanceof ObjectNotFoundException)
574
                {
575
                    throw new NotFoundException(e.getCause().toString());
576
                }
577
                throw e;
578
            }
579
        }
580
        catch (FilterChainFailedException e)
581
        {
582
            return mapping.findForward("error401");
583
        }
584
        catch (NotFoundException e)
585
        {
586
            return mapping.findForward("error404");
587
        }
588
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
589
        {
590
            logger.error(e, e);
591
            return mapping.findForward("error500");
592
        }
593
    }
594
 
595
    public ActionForward deleteAssignement(ActionMapping mapping,
596
                                           ActionForm form,
597
                                           HttpServletRequest request,
598
                                           HttpServletResponse response)
599
            throws ServletException
600
    {
601
        try
602
        {
603
            CourseUnitsForm cUF = (CourseUnitsForm) form;
604
            IServiceManager sm = ServiceManager.getInstance();
605
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
606
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cUF.getCourseUnitAssignementView().getId()};
607
            try
608
            {
609
                CourseUnitView cV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), "DeleteCourseUnitWork", args, names);
610
                cUF.setCourseUnitView(cV);
611
                request.setAttribute("CourseUnitView", cV);
612
                cUF.setCourseUnitAssignementView(new CourseUnitAssignementView());
613
                return mapping.findForward("load.works");
614
            }
615
            catch (ExecutedFilterException e)
616
            {
617
                if (e.getCause() instanceof ObjectNotFoundException)
618
                {
619
                    throw new NotFoundException(e.getCause().toString());
620
                }
621
                throw e;
622
            }
623
        }
624
        catch (FilterChainFailedException e)
625
        {
626
            return mapping.findForward("error401");
627
        }
628
        catch (NotFoundException e)
629
        {
630
            return mapping.findForward("error404");
631
        }
632
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
633
        {
634
            logger.error(e, e);
635
            return mapping.findForward("error500");
636
        }
637
    }
638
 
639
    public ActionForward editAssignement(ActionMapping mapping,
640
                                         ActionForm form,
641
                                         HttpServletRequest request,
642
                                         HttpServletResponse response)
643
            throws ServletException
644
    {
645
 
646
        try
647
        {
648
            CourseUnitsForm cUF = (CourseUnitsForm) form;
649
            long id = cUF.getCourseUnitView().getId();
650
            IServiceManager sm = ServiceManager.getInstance();
651
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
652
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id};
653
            try
654
            {
655
                CourseUnitView cV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), "LoadCourseUnitWorks", args, names);
656
                cUF.setCourseUnitView(cV);
657
                cUF.setShowNewWorkForm(true);
658
                for(CourseUnitAssignementView aV: cV.getCourseUnitAssignements())
659
                {
660
                    if(cUF.getCourseUnitAssignementView().getId() == aV.getId())
661
                    {
662
                        cUF.setCourseUnitAssignementView(aV);
663
                    }
664
                }
665
                request.setAttribute("CourseUnitView", cV);
666
                return mapping.findForward("load.works");
667
            }
668
            catch (ExecutedFilterException e)
669
            {
670
                if (e.getCause() instanceof ObjectNotFoundException)
671
                {
672
                    throw new NotFoundException(e.getCause().toString());
673
                }
674
                throw e;
675
            }
676
        }
677
        catch (FilterChainFailedException e)
678
        {
679
            return mapping.findForward("error401");
680
        }
681
        catch (NotFoundException e)
682
        {
683
            return mapping.findForward("error404");
684
        }
685
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
686
        {
687
            logger.error(e, e);
688
            return mapping.findForward("error500");
689
        }
690
    }
691
 
204 jmachado 692
    public ActionForward update(ActionMapping mapping,
205 jmachado 693
                                ActionForm form,
694
                                HttpServletRequest request,
695
                                HttpServletResponse response)
204 jmachado 696
            throws ServletException
697
    {
698
        try
699
        {
700
            CourseUnitsForm cUF = (CourseUnitsForm) form;
701
            IServiceManager sm = ServiceManager.getInstance();
702
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"object"};
703
            5+0%2Fdocs%2Fapi+Object">Object[] args;
203 jmachado 704
 
209 jmachado 705
            if(cUF.getProgramFile() == null || cUF.getProgramFile().getFileSize() <= 0)
204 jmachado 706
                args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cUF.getCourseUnitView(),null,null,0,null};
707
            else                              //ring name, int size, String contentType, String extensio
708
                args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cUF.getCourseUnitView(),cUF.getProgramFile().getInputStream(),cUF.getProgramFile().getFileName(),cUF.getProgramFile().getFileSize(),cUF.getProgramFile().getContentType()};
203 jmachado 709
 
204 jmachado 710
            CourseUnitView cV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), "UpdateCourseUnit", args, names);
711
            request.setAttribute("CourseUnitView",cV);
712
            cUF.setCourseUnitView(cV);
713
            return mapping.findForward("load");
714
        }
715
        catch (FilterChainFailedException e)
716
        {
717
            return mapping.findForward("error401");
718
        }
719
        catch (NotFoundException e)
720
        {
721
            return mapping.findForward("error404");
722
        }
723
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
724
        {
725
            logger.error(e, e);
726
            return mapping.findForward("error500");
727
        }
728
    }
729
 
730
 
207 jmachado 731
    public ActionForward deliverWork(ActionMapping mapping,
208 jmachado 732
                                     ActionForm form,
733
                                     HttpServletRequest request,
734
                                     HttpServletResponse response)
207 jmachado 735
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
736
    {
737
        try
738
        {
739
            CourseUnitsForm cUF = (CourseUnitsForm) form;
740
            ActionErrors errors = cUF.validateDeliverWork(mapping, request);
741
            if (!errors.isEmpty())
742
            {
743
                saveErrors(request, errors);
744
                return loadWorks(mapping,form,request,response);
745
            }
204 jmachado 746
 
207 jmachado 747
            IServiceManager sm = ServiceManager.getInstance();
748
            FormFile work = cUF.getUploadFile();
749
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
750
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cUF.getCourseUnitAssignementView().getId(),work.getInputStream(),work.getFileName(),work.getContentType(),work.getFileSize()};
751
            CourseUnitView cV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), "DeliverCourseUnitWork", args, names);
752
            cUF.setCourseUnitView(cV);
753
            request.setAttribute("CourseUnitView", cV);
754
            cUF.setCourseUnitAssignementView(new CourseUnitAssignementView());
755
            addMessage(request,"courseunit.assignement.deliver.sucess",work.getFileName());
756
            return mapping.findForward("load.works");
757
 
758
        }
759
        catch (FilterChainFailedException e)
760
        {
761
            return mapping.findForward("error401");
762
        }
763
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
764
        {
765
            logger.error(e, e);
766
            throw e;
767
        }
768
    }
769
 
208 jmachado 770
    public ActionForward updateDeliverables(ActionMapping mapping,
771
                                            ActionForm form,
772
                                            HttpServletRequest request,
773
                                            HttpServletResponse response)
774
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
775
    {
776
        try
777
        {
778
            CourseUnitsForm cUF = (CourseUnitsForm) form;
779
            cUF.validateUpdateDeliverables();
780
 
781
            IServiceManager sm = ServiceManager.getInstance();
782
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable","deliverables"};
783
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cUF.getCourseUnitView().getId(),cUF.getCourseUnitAssignementView().getId(), cUF.getCourseUnitAssignementView().getDeliverables()};
784
            CourseUnitAssignementView cAV = (CourseUnitAssignementView) sm.execute(RequestUtils.getRequester(request, response), "UpdateCourseUnitDeliverables", args, names);
785
            cUF.setCourseUnitView(cAV.getCourseUnitView());
786
            cUF.setCourseUnitAssignementView(cAV);
787
            request.setAttribute("CourseUnitView", cAV.getCourseUnitView());
788
            request.setAttribute("CourseUnitAssignementView", cAV);
789
            return mapping.findForward("load.assignement");
790
 
791
        }
792
        catch (FilterChainFailedException e)
793
        {
794
            return mapping.findForward("error401");
795
        }
796
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
797
        {
798
            logger.error(e, e);
799
            throw e;
800
        }
801
    }
802
 
803
 
207 jmachado 804
    public ActionForward loadAssignement(ActionMapping mapping,
208 jmachado 805
                                         ActionForm form,
806
                                         HttpServletRequest request,
807
                                         HttpServletResponse response)
207 jmachado 808
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
809
    {
810
        try
811
        {
812
            CourseUnitsForm cUF = (CourseUnitsForm) form;
208 jmachado 813
 
207 jmachado 814
            IServiceManager sm = ServiceManager.getInstance();
815
            FormFile work = cUF.getUploadFile();
816
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
817
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cUF.getCourseUnitAssignementView().getId()};
818
            CourseUnitAssignementView cAV = (CourseUnitAssignementView) sm.execute(RequestUtils.getRequester(request, response), "LoadCourseUnitWorkAssignement", args, names);
819
            cUF.setCourseUnitView(cAV.getCourseUnitView());
820
            cUF.setCourseUnitAssignementView(cAV);
821
            request.setAttribute("CourseUnitView", cAV.getCourseUnitView());
822
            request.setAttribute("CourseUnitAssignementView", cAV);
823
            return mapping.findForward("load.assignement");
824
        }
825
        catch (FilterChainFailedException e)
826
        {
827
            return mapping.findForward("error401");
828
        }
829
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
830
        {
831
            logger.error(e, e);
832
            throw e;
833
        }
834
    }
835
 
208 jmachado 836
    public ActionForward startBlog(ActionMapping mapping,
837
                                   ActionForm form,
838
                                   HttpServletRequest request,
839
                                   HttpServletResponse response)
840
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
841
    {
842
        try
843
        {
844
            CourseUnitsForm cUF = (CourseUnitsForm) form;
845
            IServiceManager sm = ServiceManager.getInstance();
846
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
847
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{cUF.getCourseUnitView().getId()};
848
            CourseUnitView cUV = (CourseUnitView) sm.execute(RequestUtils.getRequester(request, response), "StartCourseUnitBlog", args, names);
849
            cUF.setCourseUnitView(cUV);
850
            request.setAttribute("CourseUnitView", cUV);
851
            BlogForm bForm = new BlogForm();
852
            bForm.setBlogView(new BlogView());
853
            bForm.getBlogView().setId(cUV.getBlog().getId());
214 jmachado 854
            ActionForward forward = new BlogsController().load(mapping,bForm,request,response);
855
            if(forward.getName().equals("load"))
856
                return mapping.findForward("load.blog");
857
            else
858
                return forward;
208 jmachado 859
        }
860
        catch (FilterChainFailedException e)
861
        {
862
            return mapping.findForward("error401");
863
        }
864
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
865
        {
866
            logger.error(e, e);
867
            throw e;
868
        }
869
    }
207 jmachado 870
 
871
 
223 jmachado 872
    public ActionForward loadCourseUnitIntranet(    1.5.0/docs/api/java/lang/String.html">String path,
873
                                                    1.5.0/docs/api/java/lang/String.html">String layout,
874
                                                    ActionMapping mapping,
875
                                                    ActionForm form,
876
                                                    HttpServletRequest request,
877
                                                    HttpServletResponse response)
878
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
879
    {
880
        try
881
        {
882
            CourseUnitsForm cUF = (CourseUnitsForm) form;
883
            CourseUnitView cV = loadCourseUnitView(cUF.getCourseUnitView().getId(),false,false, mapping, request, response);
884
            cUF.setCourseUnitView(cV);
885
            request.setAttribute("CourseUnitView", cV);
208 jmachado 886
 
887
 
223 jmachado 888
            ActionForward forward = new ActionForward();
889
            forward.setName("intranetCourseUnit");
558 jmachado 890
            if(path.length() > 0)
891
                path = "/" + path;
892
            forward.setPath("/courseunitproxy/" + layout + "/ionline" + path + "/?courseUnitView.id="+ cV.getId() + "&startPath=" + cV.getPathIntranet() + "&from=" + request.getParameter("from"));
223 jmachado 893
            forward.setRedirect(true);
894
            return forward;
895
        }
896
        catch (FilterChainFailedException e)
897
        {
898
            return mapping.findForward("error401");
899
        }
900
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
901
        {
902
            logger.error(e, e);
903
            throw e;
904
        }
905
    }
906
    public ActionForward loadContents(
749 jmachado 907
            ActionMapping mapping,
908
            ActionForm form,
909
            HttpServletRequest request,
910
            HttpServletResponse response)
223 jmachado 911
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
912
    {
913
        return loadCourseUnitIntranet(Globals.INTRANET_CONTENTS,"courseLayoutIOnlineContents",mapping,form,request,response);
914
    }
558 jmachado 915
 
916
    public ActionForward loadRoot(
749 jmachado 917
            ActionMapping mapping,
918
            ActionForm form,
919
            HttpServletRequest request,
920
            HttpServletResponse response)
558 jmachado 921
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
922
    {
923
        return loadCourseUnitIntranet(Globals.INTRANET_ROOT,"courseLayoutIOnlineContents",mapping,form,request,response);
924
    }
925
 
223 jmachado 926
    public ActionForward loadGrades(
749 jmachado 927
            ActionMapping mapping,
928
            ActionForm form,
929
            HttpServletRequest request,
930
            HttpServletResponse response)
223 jmachado 931
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
932
    {
933
        return loadCourseUnitIntranet(Globals.INTRANET_GRADES,"courseLayoutIOnlineGrades",mapping,form,request,response);
934
    }
935
    public ActionForward loadPresences(
749 jmachado 936
            ActionMapping mapping,
937
            ActionForm form,
938
            HttpServletRequest request,
939
            HttpServletResponse response)
223 jmachado 940
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
941
    {
942
        return loadCourseUnitIntranet(Globals.INTRANET_PRESENCES,"courseLayoutIOnlinePresences",mapping,form,request,response);
943
    }
901 jmachado 944
    public ActionForward loadDtp(
945
            ActionMapping mapping,
946
            ActionForm form,
947
            HttpServletRequest request,
948
            HttpServletResponse response)
949
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
950
    {
951
        return loadCourseUnitIntranet(Globals.INTRANET_DTP,"courseLayoutIOnlineDtp",mapping,form,request,response);
952
    }
223 jmachado 953
 
954
 
955
 
956
 
957
 
847 jmachado 958
 
203 jmachado 959
}