Subversion Repositories bacoAlunos

Rev

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

Rev Author Line No. Line
343 jmachado 1
package pt.estgp.estgweb.services.courseunits;
2
 
751 jmachado 3
import org.apache.fop.apps.FOPException;
4
import org.apache.log4j.Logger;
376 jmachado 5
import pt.estgp.estgweb.domain.*;
343 jmachado 6
import pt.estgp.estgweb.domain.dao.DaoFactory;
751 jmachado 7
import pt.estgp.estgweb.domain.enums.LangEnum;
343 jmachado 8
import pt.estgp.estgweb.domain.views.CourseUnitView;
9
import pt.estgp.estgweb.domain.views.CourseView;
751 jmachado 10
import pt.estgp.estgweb.services.email.EMAILJob;
11
import pt.estgp.estgweb.services.email.SendEmailService;
12
import pt.estgp.estgweb.services.jobs.JobScheduleService;
13
import pt.estgp.estgweb.utils.AreasBelongUtils;
343 jmachado 14
import pt.estgp.estgweb.utils.CourseViewComparator;
751 jmachado 15
import pt.estgp.estgweb.web.exceptions.NotAuthorizedException;
343 jmachado 16
import pt.utl.ist.berserk.logic.serviceManager.IService;
17
 
751 jmachado 18
import javax.xml.transform.TransformerException;
19
import java.io.IOException;
343 jmachado 20
import java.util.ArrayList;
21
import java.util.HashMap;
22
import java.util.List;
23
 
24
/**
25
 * @author Jorge Machado
26
 * @date 2/Jun/2008
27
 * @see pt.estgp.estgweb.services.courseunits
28
 */
29
public class DirectedCoordinatedUnitsService implements IService
30
{
751 jmachado 31
    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(DirectedCoordinatedUnitsService.class);
32
 
345 jmachado 33
    public DirectedCoordinatedCourses loadForUserSession(1.5.0/docs/api/java/lang/String.html">String importYear, UserSession userSession)
343 jmachado 34
    {
345 jmachado 35
        return loadForUser(userSession.getUser().getId(),importYear, userSession);
343 jmachado 36
    }
37
 
345 jmachado 38
    public DirectedCoordinatedCourses loadForUser(long teacherId, 1.5.0/docs/api/java/lang/String.html">String importYear, UserSession userSession)
343 jmachado 39
    {
345 jmachado 40
        if(importYear == null)
995 jmachado 41
            importYear = DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear();
345 jmachado 42
        List<Course> directorCourses = DaoFactory.getCourseDaoImpl().loadDirectorCourses(teacherId,importYear);
43
        List<Course> coordinatorCourses = DaoFactory.getCourseDaoImpl().loadCoordinatedCourses(teacherId,importYear);
343 jmachado 44
 
45
        HashMap<Course, Boolean> map = new HashMap<Course, Boolean>();
46
 
47
        DirectedCoordinatedCourses directedCoordinatedCourses = new DirectedCoordinatedCourses();
48
        directedCoordinatedCourses.setCoordinatedCourses(new ArrayList<CourseView>());
49
        directedCoordinatedCourses.setDirectedCourses(new ArrayList<CourseView>());
50
        directedCoordinatedCourses.setMerge(new ArrayList<CourseView>());
51
        for (Course c : directorCourses)
52
        {
53
            CourseView cV = new CourseView(c, true);
54
            directedCoordinatedCourses.getDirectedCourses().add(cV);
55
            if (map.get(c) == null)
56
            {
57
                directedCoordinatedCourses.getMerge().add(cV);
58
                map.put(c, true);
59
            }
60
        }
61
        for (Course c : coordinatorCourses)
62
        {
63
            CourseView cV = new CourseView(c, true);
64
            directedCoordinatedCourses.getCoordinatedCourses().add(cV);
65
            if (map.get(c) == null)
66
            {
67
                directedCoordinatedCourses.getMerge().add(cV);
68
                map.put(c, true);
69
            }
70
        }
71
        java.util.1.5.0/docs/api/java/util/Collections.html">Collections.sort(directedCoordinatedCourses.getMerge(), CourseViewComparator.getInstance());
344 jmachado 72
        fill(directedCoordinatedCourses.getMerge());
73
        return directedCoordinatedCourses;
74
    }
75
 
376 jmachado 76
//    public DirectedCoordinatedCourses loadForServices(String importYear, UserSession userSession)
77
//    {
78
//        if(importYear == null)
79
//            importYear = DatesUtils.getImportYear();
80
//        List<Course> courses = DaoFactory.getCourseDaoImpl().findAllOrderByName(importYear);
81
//
82
//        List<CourseView> courseViews = new ArrayList<CourseView>();
83
//        for(Course c : courses)
84
//        {
85
//            CourseView cV = new CourseView(c, true);
86
//            courseViews.add(cV);
87
//        }
88
//        fill(courseViews);
89
//        DirectedCoordinatedCourses directedCoordinatedCourses = new DirectedCoordinatedCourses();
90
//        directedCoordinatedCourses.setMerge(courseViews);
91
//        return directedCoordinatedCourses;
92
//    }
93
 
1312 jmachado 94
    public DirectedCoordinatedCourses loadForServices(1.5.0/docs/api/java/lang/String.html">String importYear, long courseId, 1.5.0/docs/api/java/lang/String.html">String semestre, 1.5.0/docs/api/java/lang/String.html">String area, TeachersSituationEnum teachersSituationEnum, 1.5.0/docs/api/java/lang/String.html">String institutionCode, UserSession userSession)
344 jmachado 95
    {
345 jmachado 96
        if(importYear == null)
995 jmachado 97
            importYear = DaoFactory.getConfigurationDaoImpl().getInterfaceImportYear();
344 jmachado 98
 
1039 jmachado 99
        DirectedCoordinatedCourses directedCoordinatedCourses;
100
        if(courseId <= 0)
101
        {
102
            directedCoordinatedCourses = new DirectedCoordinatedCourses();
103
            return directedCoordinatedCourses;
104
        }
105
 
376 jmachado 106
        /**
107
         * Area and Course Initialization
108
         */
109
        if (area == null && userSession.getUser() != null && userSession.getUser() instanceof Teacher)
110
        {
111
            SigesUser sigesUser = (SigesUser) userSession.getUser();
112
            if (sigesUser.getAreasBelong() != null && sigesUser.getAreasBelong().length() > 0)
113
            {
114
                area = AreasBelongUtils.getAreasFromSerial(sigesUser.getAreasBelong()).get(0);
115
            }
116
        }
117
        /**
118
         * If is a student can see only his course
751 jmachado 119
         // ALTERACAO PARA TODOS VEREM TODOS OS PROGRAMAS
722 jmachado 120
 
751 jmachado 121
         if (userSession.getUser() != null && userSession.getUser() instanceof Student)
122
         {
123
         StudentImpl sigesUser = (StudentImpl) userSession.getUser();
124
         if (sigesUser.getSubscribedUnits() != null && sigesUser.getSubscribedUnits().size() > 0)
125
         {
126
         Course course = sigesUser.getSubscribedUnits().iterator().next().getCourse();
127
         courseId = course.getId();
128
         }
129
         }
722 jmachado 130
         */
376 jmachado 131
 
132
        List<Course> courses;
133
 
722 jmachado 134
 
376 jmachado 135
        if(courseId > 0)
136
        {
137
            courses = new ArrayList<Course>();
138
            courses.add(DaoFactory.getCourseDaoImpl().get(courseId));
139
        }
140
        else
141
        {
417 jmachado 142
            courses = DaoFactory.getCourseDaoImpl().findAllOrderByName(importYear,area,null);
376 jmachado 143
        }
144
 
344 jmachado 145
        List<CourseView> courseViews = new ArrayList<CourseView>();
146
        for(Course c : courses)
343 jmachado 147
        {
376 jmachado 148
            CourseView cV = new CourseView(c, false);
344 jmachado 149
            courseViews.add(cV);
150
        }
1312 jmachado 151
        fill(courseViews, semestre, importYear, teachersSituationEnum,institutionCode);
1039 jmachado 152
        directedCoordinatedCourses = new DirectedCoordinatedCourses();
344 jmachado 153
        directedCoordinatedCourses.setMerge(courseViews);
376 jmachado 154
        directedCoordinatedCourses.setArea(area);
155
        directedCoordinatedCourses.setCourseId(courseId);
1312 jmachado 156
 
344 jmachado 157
        return directedCoordinatedCourses;
158
    }
159
 
160
    private void fill(List<CourseView> courseViews)
161
    {
162
        for (CourseView cV : courseViews)
163
        {
343 jmachado 164
            cV.setCourseUnitsWithNoProgramS1(new ArrayList<CourseUnitView>());
165
            cV.setCourseUnitsWithNoProgramS2(new ArrayList<CourseUnitView>());
166
            cV.setCourseUnitsWithProgramCheckedS1(new ArrayList<CourseUnitView>());
167
            cV.setCourseUnitsWithProgramCheckedS2(new ArrayList<CourseUnitView>());
168
            cV.setCourseUnitsWithProgramNotCheckedS1(new ArrayList<CourseUnitView>());
169
            cV.setCourseUnitsWithProgramNotCheckedS2(new ArrayList<CourseUnitView>());
170
            for (CourseUnitView cUV : cV.getCourseUnits())
171
            {
1040 jmachado 172
 
173
 
343 jmachado 174
                if (cUV.getProgramStreamId() == null)
1040 jmachado 175
                {
176
                    try {
177
                        ((List<CourseUnitView>)
178
                                (cV.getClass()
179
                                        .getMethod("getCourseUnitsWithNoProgram" + cUV.getSemestre())
180
                                        .invoke(cV)))
181
                                .add(cUV);
182
                    } catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) {
183
                        logger.error(e,e);
184
                    }
185
                }
186
                    /*if (cUV.getSemestre().equals("S1"))
343 jmachado 187
                        cV.getCourseUnitsWithNoProgramS1().add(cUV);
188
                    else
1040 jmachado 189
                        cV.getCourseUnitsWithNoProgramS2().add(cUV);*/
343 jmachado 190
                else if (cUV.isValidProgram())
1040 jmachado 191
                {
192
                    try {
193
                        ((List<CourseUnitView>)
194
                                (cV.getClass()
195
                                        .getMethod("getCourseUnitsWithProgramChecked" + cUV.getSemestre())
196
                                        .invoke(cV)))
197
                                .add(cUV);
198
                    } catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) {
199
                        logger.error(e,e);
200
                    }
201
                }
202
                    /*if (cUV.getSemestre().equals("S1"))
343 jmachado 203
                        cV.getCourseUnitsWithProgramCheckedS1().add(cUV);
204
                    else
1040 jmachado 205
                        cV.getCourseUnitsWithProgramCheckedS2().add(cUV);*/
206
                else
207
                    try {
208
                        ((List<CourseUnitView>)
209
                                (cV.getClass()
210
                                        .getMethod("getCourseUnitsWithProgramNotChecked" + cUV.getSemestre())
211
                                        .invoke(cV)))
212
                                .add(cUV);
213
                    } catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) {
214
                        logger.error(e,e);
215
                    }
216
 
217
                /*if (cUV.getSemestre().equals("S1"))
343 jmachado 218
                    cV.getCourseUnitsWithProgramNotCheckedS1().add(cUV);
219
                else
1040 jmachado 220
                    cV.getCourseUnitsWithProgramNotCheckedS2().add(cUV);*/
343 jmachado 221
            }
222
        }
223
    }
224
 
1312 jmachado 225
    private void fill(List<CourseView> courseViews, 1.5.0/docs/api/java/lang/String.html">String  semestre, 1.5.0/docs/api/java/lang/String.html">String importYear, TeachersSituationEnum teachersSituationEnum,1.5.0/docs/api/java/lang/String.html">String institutionCode)
376 jmachado 226
    {
227
        boolean withTeacher = true;
228
        boolean withNoTeacher = true;
229
 
230
        if(teachersSituationEnum == TeachersSituationEnum.withNoTeachers)
231
            withTeacher = false;
232
        else if(teachersSituationEnum == TeachersSituationEnum.withTeachers)
233
            withNoTeacher = false;
234
 
235
        for (CourseView cV : courseViews)
236
        {
1040 jmachado 237
            cV.setCourseUnitsWithNoProgramA(new ArrayList<CourseUnitView>());
376 jmachado 238
            cV.setCourseUnitsWithNoProgramS1(new ArrayList<CourseUnitView>());
239
            cV.setCourseUnitsWithNoProgramS2(new ArrayList<CourseUnitView>());
1040 jmachado 240
            cV.setCourseUnitsWithNoProgramT1(new ArrayList<CourseUnitView>());
241
            cV.setCourseUnitsWithNoProgramT2(new ArrayList<CourseUnitView>());
242
            cV.setCourseUnitsWithNoProgramT3(new ArrayList<CourseUnitView>());
243
            cV.setCourseUnitsWithNoProgramT4(new ArrayList<CourseUnitView>());
244
            cV.setCourseUnitsWithProgramCheckedA(new ArrayList<CourseUnitView>());
376 jmachado 245
            cV.setCourseUnitsWithProgramCheckedS1(new ArrayList<CourseUnitView>());
246
            cV.setCourseUnitsWithProgramCheckedS2(new ArrayList<CourseUnitView>());
1040 jmachado 247
            cV.setCourseUnitsWithProgramCheckedT1(new ArrayList<CourseUnitView>());
248
            cV.setCourseUnitsWithProgramCheckedT2(new ArrayList<CourseUnitView>());
249
            cV.setCourseUnitsWithProgramCheckedT3(new ArrayList<CourseUnitView>());
250
            cV.setCourseUnitsWithProgramCheckedT4(new ArrayList<CourseUnitView>());
251
            cV.setCourseUnitsWithProgramNotCheckedA(new ArrayList<CourseUnitView>());
376 jmachado 252
            cV.setCourseUnitsWithProgramNotCheckedS1(new ArrayList<CourseUnitView>());
253
            cV.setCourseUnitsWithProgramNotCheckedS2(new ArrayList<CourseUnitView>());
1040 jmachado 254
            cV.setCourseUnitsWithProgramNotCheckedT1(new ArrayList<CourseUnitView>());
255
            cV.setCourseUnitsWithProgramNotCheckedT2(new ArrayList<CourseUnitView>());
256
            cV.setCourseUnitsWithProgramNotCheckedT3(new ArrayList<CourseUnitView>());
257
            cV.setCourseUnitsWithProgramNotCheckedT4(new ArrayList<CourseUnitView>());
376 jmachado 258
 
259
 
1312 jmachado 260
            List<CourseUnit> courseUnits = DaoFactory.getCourseUnitDaoImpl().loadCourseUnits(cV.getId(),semestre,importYear,withTeacher,withNoTeacher,institutionCode);
376 jmachado 261
            for (CourseUnit cU : courseUnits)
262
            {
263
                CourseUnitView cUV = new CourseUnitView(cU,true,false,false,false);
264
                if (cUV.getProgramStreamId() == null)
1040 jmachado 265
                    try {
266
                        ((List<CourseUnitView>)
267
                                (cV.getClass()
268
                                        .getMethod("getCourseUnitsWithNoProgram" + cUV.getSemestre())
269
                                        .invoke(cV)))
270
                                .add(cUV);
271
                    } catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) {
272
                        logger.error(e,e);
273
                    }
274
                    /*if (cUV.getSemestre().equals("S1"))
376 jmachado 275
                        cV.getCourseUnitsWithNoProgramS1().add(cUV);
276
                    else
1040 jmachado 277
                        cV.getCourseUnitsWithNoProgramS2().add(cUV);*/
376 jmachado 278
                else if (cUV.isValidProgram())
1040 jmachado 279
                    try {
280
                        ((List<CourseUnitView>)
281
                                (cV.getClass()
282
                                        .getMethod("getCourseUnitsWithProgramChecked" + cUV.getSemestre())
283
                                        .invoke(cV)))
284
                                .add(cUV);
285
                    } catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) {
286
                        logger.error(e,e);
287
                    }
288
                    /*
376 jmachado 289
                    if (cUV.getSemestre().equals("S1"))
290
                        cV.getCourseUnitsWithProgramCheckedS1().add(cUV);
291
                    else
1040 jmachado 292
                        cV.getCourseUnitsWithProgramCheckedS2().add(cUV);*/
293
                else
294
                    try {
295
                        ((List<CourseUnitView>)
296
                                (cV.getClass()
297
                                        .getMethod("getCourseUnitsWithProgramNotChecked" + cUV.getSemestre())
298
                                        .invoke(cV)))
299
                                .add(cUV);
300
                    } catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) {
301
                        logger.error(e,e);
302
                    }
303
                /*if (cUV.getSemestre().equals("S1"))
376 jmachado 304
                    cV.getCourseUnitsWithProgramNotCheckedS1().add(cUV);
305
                else
1040 jmachado 306
                    cV.getCourseUnitsWithProgramNotCheckedS2().add(cUV);*/
376 jmachado 307
            }
308
        }
309
    }
310
 
751 jmachado 311
    public DirectedCoordinatedCourses update(DirectedCoordinatedCourses directedCoordinatedCourses, UserSession userSession) throws NotAuthorizedException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, 1.5.0/docs/api/java/io/IOException.html">IOException, FOPException {
343 jmachado 312
        int counter = 0;
313
        for(CourseView courseView: directedCoordinatedCourses.getMerge())
314
        {
315
            if(courseView.getId()>0)
316
            {
317
                Course c = DaoFactory.getCourseDaoImpl().load(courseView.getId());
507 jmachado 318
//                if(userSession.getUser().getId() == c.getCoordinator().getId())
319
                if(courseView.getId() == 2)
320
                    1.5.0/docs/api/java/lang/System.html">System.out.println(courseView.getValidationRole());
751 jmachado 321
 
322
                if(userSession.getUser().isAdmin() ||  userSession.getUser().hasRole("courseValidatePrograms") || userSession.getUser().hasRole(c.getValidationRole())) //NOVO para validação por programas
343 jmachado 323
                {
1040 jmachado 324
                    counter+=updateList(courseView.getCourseUnitsWithProgramCheckedA(),userSession);
751 jmachado 325
                    counter+=updateList(courseView.getCourseUnitsWithProgramCheckedS1(),userSession);
326
                    counter+=updateList(courseView.getCourseUnitsWithProgramCheckedS2(),userSession);
1040 jmachado 327
                    counter+=updateList(courseView.getCourseUnitsWithProgramCheckedT1(),userSession);
328
                    counter+=updateList(courseView.getCourseUnitsWithProgramCheckedT2(),userSession);
329
                    counter+=updateList(courseView.getCourseUnitsWithProgramCheckedT3(),userSession);
330
                    counter+=updateList(courseView.getCourseUnitsWithProgramCheckedT4(),userSession);
331
                    counter+=updateList(courseView.getCourseUnitsWithProgramNotCheckedA(),userSession);
751 jmachado 332
                    counter+=updateList(courseView.getCourseUnitsWithProgramNotCheckedS1(),userSession);
333
                    counter+=updateList(courseView.getCourseUnitsWithProgramNotCheckedS2(),userSession);
1040 jmachado 334
                    counter+=updateList(courseView.getCourseUnitsWithProgramNotCheckedT1(),userSession);
335
                    counter+=updateList(courseView.getCourseUnitsWithProgramNotCheckedT2(),userSession);
336
                    counter+=updateList(courseView.getCourseUnitsWithProgramNotCheckedT3(),userSession);
337
                    counter+=updateList(courseView.getCourseUnitsWithProgramNotCheckedT4(),userSession);
343 jmachado 338
                }
339
            }
340
        }
341
        directedCoordinatedCourses.setUpdated(counter);
342
        return directedCoordinatedCourses;
343
    }
344
 
751 jmachado 345
    private int updateList(List<CourseUnitView> views, UserSession usession) throws NotAuthorizedException, 1.5.0/docs/api/javax/xml/transform/TransformerException.html">TransformerException, 1.5.0/docs/api/java/io/IOException.html">IOException, FOPException {
343 jmachado 346
        int counter = 0;
347
        for(CourseUnitView courseUnitView: views)
348
        {
1350 jmachado 349
            if(courseUnitView != null && courseUnitView.getId()>0)
350
            {
351
                CourseUnit courseUnit = DaoFactory.getCourseUnitDaoImpl().load(courseUnitView.getId());
751 jmachado 352
 
1350 jmachado 353
                //EVALUATION OPEN BY ADMIN
354
                if(courseUnitView.isEvaluationOpenByAdmin() != courseUnit.isEvaluationOpenByAdmin())
355
                    courseUnit.setEvaluationOpenByAdmin(courseUnitView.isEvaluationOpenByAdmin());
751 jmachado 356
 
343 jmachado 357
                if(courseUnitView.getProgramStreamId() != null && courseUnitView.getProgramStreamId().length() > 0)
358
                {
1350 jmachado 359
 
751 jmachado 360
                    if(usession.getUser().isAdmin() ||  usession.getUser().hasRole("courseValidatePrograms") || usession.getUser().hasRole(courseUnit.getCourse().getValidationRole()))
343 jmachado 361
                    {
751 jmachado 362
                        if(courseUnit.isValidProgram() != courseUnitView.isValidProgram())
363
                        {
364
                            courseUnit.setValidProgram(courseUnitView.isValidProgram());
999 jmachado 365
                            courseUnit.setValidatorUser(usession.getUser());
751 jmachado 366
                            counter++;
759 jmachado 367
                            new SaveCourseUnitProgram().createPdf(courseUnit,null,usession);
751 jmachado 368
 
369
 
370
                            if(courseUnitView.isValidProgram())
371
                                sendNotificationsValidadaInterestedPeople(courseUnit,usession);
372
                            else
373
                                sendNotificationsEditionInterestedPeople(courseUnit,usession);
374
 
375
                        }
343 jmachado 376
                    }
751 jmachado 377
                    else
378
                    {
379
                        throw new NotAuthorizedException("Não pode editar estado da unidade " + courseUnit.getCode());
380
                    }
343 jmachado 381
                }
382
            }
383
        }
384
        return counter;
385
    }
376 jmachado 386
 
751 jmachado 387
    public static void sendNotificationsValidadaInterestedPeople(CourseUnit courseUnit,UserSession u)
388
    {
389
        try{
390
            SendEmailService sendEmailService = new SendEmailService();
391
            List<String> emails = getEmailJobNotifications(courseUnit);
392
            EMAILJob emailJob = new EMAILJob(sendEmailService.getUnidadeValidadaEmail(emails,courseUnit,LangEnum.PORTUGUESE));
393
            JobScheduleService.getInstance().scheduleNow(emailJob,"New Notification EMAIL unit state changed to courseComission and teachers " ,u);
394
        }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable t)
395
        {
396
            logger.error(t,t);
397
        }
398
    }
399
 
400
    public static void sendNotificationsEditionInterestedPeople(CourseUnit courseUnit,UserSession u)
401
    {
402
        try{
403
            SendEmailService sendEmailService = new SendEmailService();
404
            List<String> emails = getEmailJobNotifications(courseUnit);
405
            EMAILJob emailJob = new EMAILJob(sendEmailService.getUnidadeEdicaoEmail(emails,courseUnit,LangEnum.PORTUGUESE));
406
            JobScheduleService.getInstance().scheduleNow(emailJob,"New Notification EMAIL unit state changed to courseComission and teachers " ,u);
407
        }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable t)
408
        {
409
            logger.error(t,t);
410
        }
411
    }
412
    public static void sendNotificationsEditedInterestedPeople(CourseUnit courseUnit,UserSession u)
413
    {
414
        try{
415
            SendEmailService sendEmailService = new SendEmailService();
416
            List<String> emails = getEmailJobNotifications(courseUnit);
417
            EMAILJob emailJob = new EMAILJob(sendEmailService.getUnidadeEditadaEmail(emails,courseUnit,LangEnum.PORTUGUESE));
418
            JobScheduleService.getInstance().scheduleNow(emailJob,"New Notification EMAIL unit state changed to courseComission and teachers " ,u);
419
        }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable t)
420
        {
421
            logger.error(t,t);
422
        }
423
    }
424
 
1033 jmachado 425
    public static void sendNotificationsCourseUnitEvaluationEditedInterestedPeople(CourseUnit courseUnit,1.5.0/docs/api/java/lang/String.html">String estado,UserSession u)
426
    {
427
        try{
428
            SendEmailService sendEmailService = new SendEmailService();
429
            List<String> emails = getEmailJobNotifications(courseUnit);
430
            EMAILJob emailJob = new EMAILJob(sendEmailService.getRelatorioAvaliacaoUnidadeEditadaEmail(emails,courseUnit,LangEnum.PORTUGUESE,estado));
431
            JobScheduleService.getInstance().scheduleNow(emailJob,"New Notification EMAIL unit state changed to courseComission and teachers " ,u);
432
        }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable t)
433
        {
434
            logger.error(t,t);
435
        }
436
    }
437
 
751 jmachado 438
    public static List<String> getEmailJobNotifications(CourseUnit courseUnit) {
1029 jmachado 439
 
440
        List<String> emails = new ArrayList<String>();
441
        for(Teacher t: courseUnit.getTeachers())
442
        {
443
            if(t.getEmail() != null)
444
                emails.add(t.getEmail());
445
        }
751 jmachado 446
        if(emails == null)
447
            emails = new ArrayList<String>();
448
        if(courseUnit.getCourse().getCoordinator() != null && courseUnit.getCourse().getCoordinator().getEmail()!=null)
449
            emails.add(courseUnit.getCourse().getCoordinator().getEmail());
450
        if(courseUnit.getResponsableTeacher() != null && courseUnit.getResponsableTeacher().getEmail() != null && !emails.contains(courseUnit.getResponsableTeacher().getEmail()))
451
        {
452
            emails.add(courseUnit.getResponsableTeacher().getEmail());
453
        }
454
        List<User> courseComission = DaoFactory.getUserDaoImpl().loadRoleUsers(courseUnit.getCourse().getValidationRole());
455
        for(User cc: courseComission)
456
        {
457
            if(cc.getEmail() != null)
458
                emails.add(cc.getEmail());
459
        }
460
        return emails;
461
    }
462
 
376 jmachado 463
    public static enum TeachersSituationEnum
464
    {
465
        withTeachers,
466
        withNoTeachers,
467
        all;
468
 
469
        public static TeachersSituationEnum parse(1.5.0/docs/api/java/lang/String.html">String situation)
470
        {
471
            if(situation == null)
472
                return all;
473
            else if(situation.equals("withTeachers"))
474
                return withTeachers;
475
            else if(situation.equals("withNoTeachers"))
476
                return withNoTeachers;
477
            else
478
                return all;
479
        }
480
    }
343 jmachado 481
}