Subversion Repositories bacoAlunos

Rev

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

Rev Author Line No. Line
112 jmachado 1
package pt.estgp.estgweb.domain;
2
 
1312 jmachado 3
import com.owlike.genson.Genson;
4
import com.owlike.genson.TransformationException;
5
import org.apache.log4j.Logger;
995 jmachado 6
import pt.estgp.estgweb.Globals;
1313 jmachado 7
import pt.estgp.estgweb.domain.dao.DaoFactory;
489 jmachado 8
import pt.estgp.estgweb.domain.enums.CourseUnitContentsGrants;
1312 jmachado 9
import pt.estgp.estgweb.domain.test.TestCourseUnit;
10
import pt.estgp.estgweb.domain.utils.SimpleClearanceRuledSupport;
11
import pt.utl.ist.berserk.logic.serviceManager.IServiceManager;
12
import pt.utl.ist.berserk.logic.serviceManager.ServiceManager;
489 jmachado 13
 
1312 jmachado 14
import java.io.IOException;
146 jmachado 15
import java.io.Serializable;
1337 jmachado 16
import java.util.*;
146 jmachado 17
 
112 jmachado 18
/**
19
 * Created by IntelliJ IDEA.
20
 * User: Jorge Machado
21
 * Date: 7/Mai/2008
22
 * Time: 20:21:15
23
 * To change this template use File | Settings | File Templates.
24
 */
1312 jmachado 25
public class CourseUnitImpl extends CourseUnit implements ICanManage, ClearanceRuled
146 jmachado 26
{
489 jmachado 27
 
1312 jmachado 28
    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(CourseUnitImpl.class);
29
 
489 jmachado 30
    CourseUnitContentsGrants courseUnitContentsGrants = null;
31
 
146 jmachado 32
    public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable()
33
    {
34
        return getId();
35
    }
204 jmachado 36
 
489 jmachado 37
 
38
    public CourseUnitContentsGrants getCourseUnitContentsGrants() {
39
        if(courseUnitContentsGrants == null)
40
            courseUnitContentsGrants = CourseUnitContentsGrants.parse(super.getContentsGrants());
41
        return courseUnitContentsGrants;
42
    }
43
 
44
    public void setCourseUnitContentsGrants(CourseUnitContentsGrants courseUnitContentsGrants) {
45
        super.setContentsGrants(courseUnitContentsGrants.name());
46
        this.courseUnitContentsGrants = courseUnitContentsGrants;
47
    }
48
 
204 jmachado 49
    public boolean isValid()
50
    {
51
        return true;  //To change body of implemented methods use File | Settings | File Templates.
52
    }
53
 
54
    public boolean isOwnedBy(GenericUser u)
55
    {
208 jmachado 56
        return isOwnedBy(u, false);
204 jmachado 57
    }
58
 
208 jmachado 59
    public boolean isOwnedBy(GenericUser u, boolean transaction)
60
    {
61
        return u != null && u instanceof TeacherImpl && ((TeacherImpl)u).hasCourseUnit(getId(),transaction);
62
    }
63
 
204 jmachado 64
    /**
65
     * Not implemented can be variuous teachers
66
     * @return null
67
     * use isOwnedBy in this class
68
     */
69
    public GenericUser getOwner()
70
    {
71
        return null;
72
    }
73
    /**
74
     * Not implemented
75
     * @return
76
     */
77
    public List<String> getOwnerRoles()
78
    {
79
        return null;
80
    }
81
 
82
    /**
83
     * Not implemented
84
     * @return
85
     */
86
    public 1.5.0/docs/api/java/lang/String.html">String getChoosedOwnerRole()
87
    {
88
        return null;
89
    }
90
 
91
    public boolean isInternal()
92
    {
251 jmachado 93
        return true;
204 jmachado 94
    }
208 jmachado 95
 
96
    public CourseUnitBlogImpl getUnitBlog()
97
    {
98
        if(getBlogs()!=null && getBlogs().size() > 0)
99
            return (CourseUnitBlogImpl) getBlogs().iterator().next();
100
        return null;
101
    }
251 jmachado 102
 
1315 jmachado 103
 
1312 jmachado 104
    public boolean equalsSiges(5+0%2Fdocs%2Fapi+Object">Object anotherInstance,boolean turmasSeparadas)
251 jmachado 105
    {
106
        if(anotherInstance instanceof CourseUnitImpl)
107
        {
108
            CourseUnitImpl anCourseUnit = (CourseUnitImpl) anotherInstance;
1312 jmachado 109
            if(turmasSeparadas)
110
            {
111
                boolean turmaVazia = getCdTurma() == null || getCdTurma().trim().length() == 0;
112
                boolean anotherTurmaVazia = anCourseUnit.getCdTurma() == null || anCourseUnit.getCdTurma().trim().length() == 0;
113
                boolean turmasIguais = (turmaVazia && anotherTurmaVazia) || (!turmaVazia && !anotherTurmaVazia && getCdTurma().equals(anCourseUnit.getCdTurma()));
114
                return equalsIgnoringTurma(anotherInstance)
115
                &&
116
                turmasIguais;
117
            }
118
            else
119
                return equalsIgnoringTurma(anotherInstance);
251 jmachado 120
        }
121
        return false;
122
 
123
    }
489 jmachado 124
 
1204 jmachado 125
    public boolean equalsIgnoringTurma(5+0%2Fdocs%2Fapi+Object">Object anotherInstance)
126
    {
127
        if(anotherInstance instanceof CourseUnitImpl)
128
        {
129
            CourseUnitImpl anCourseUnit = (CourseUnitImpl) anotherInstance;
130
 
131
            return anCourseUnit.getCode() != null && getCode() != null && getCode().equals(anCourseUnit.getCode()) &&
132
                    anCourseUnit.getCourseCode() != null && getCourseCode() != null && getCourseCode().equals(anCourseUnit.getCourseCode()) &&
133
                    anCourseUnit.getSemestre() != null && getSemestre() != null && getSemestre().equals(anCourseUnit.getSemestre()) &&
134
                    anCourseUnit.getImportYear() != null && getImportYear() != null && getImportYear().equals(anCourseUnit.getImportYear());
135
        }
136
        return false;
137
 
138
    }
139
 
973 jmachado 140
    /**
141
     * Means that is teacher os responsable teacher or from course commission
142
     * Only works in open transaction
143
     *
144
     * Needs Course and Responsable Teacher loaded
145
     */
146
    public boolean isFromCourseUnitCommission(UserSession userSession)
147
    {
148
        return userSession.getUser()!= null &&
149
                (((UserImpl) userSession.getUser()).isTeacherOfCourseUnit(getId(), true)
150
                        || (getResponsableTeacher() != null && getResponsableTeacher().getId() == userSession.getUser().getId())
151
                        || userSession.getUser().hasRole(getCourse().getValidationRole())
152
                );
153
    }
489 jmachado 154
 
1312 jmachado 155
    public boolean isFromCourseCommission(UserSession userSession)
156
    {
157
        return userSession.getUser()!= null &&
158
                userSession.getUser().hasRole(getCourse().getValidationRole());
159
    }
973 jmachado 160
 
1312 jmachado 161
 
995 jmachado 162
    public 1.5.0/docs/api/java/lang/String.html">String getSummariosPathIntranet()
163
    {
164
        return Globals.FTP_IONLINE_START_PATH + "/" + getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_Sumarios;
165
    }
973 jmachado 166
 
1148 jmachado 167
    public 1.5.0/docs/api/java/lang/String.html">String getInqueritosPedagogicosPathIntranet()
168
    {
169
        return Globals.FTP_IONLINE_START_PATH + getPathIntranet() + "/" + Globals.INTRANET_DTP + "/" + Globals.INTRANET_DTP_InqueritoPedagogico;
170
    }
171
 
172
 
995 jmachado 173
    public 1.5.0/docs/api/java/lang/String.html">String getSummariosPathFileIntranet()
174
    {
175
        return getSummariosPathIntranet() + "/" + getSummariosFileNameIntranet();
176
    }
177
 
178
    public 1.5.0/docs/api/java/lang/String.html">String getSummariosFileNameIntranet(){
179
        return getCode() + "_" + getNormalizedName() + "_sumarios.pdf";
180
    }
181
 
182
 
996 jmachado 183
    public 1.5.0/docs/api/java/lang/String.html">String getSigesUniqueIdentifiers()
184
    {
185
        return "SIGES:" + getCode() + ", COURSE: " + getCourseCode() +
1139 jmachado 186
                ", " + getSemestre() + " of " + getImportYear() + " - " + getName() + " Turma - " + getCdTurma();
996 jmachado 187
    }
188
 
1341 jmachado 189
    public int studentsSize()
190
    {
191
        if(getStudents() !=null)
192
            return getStudents().size();
193
        return 0;
194
    }
1312 jmachado 195
 
1341 jmachado 196
    public int studentsTurmaSize()
197
    {
198
        int countTotalStudentsTurmas = 0;
199
        if(getTurmas() == null)
200
            return 0;
201
        for(CourseUnitTurma turma: getTurmas())
202
        {
203
            if(turma.getStudents() != null)
204
                countTotalStudentsTurmas+=turma.getStudents().size();
205
        }
206
        return countTotalStudentsTurmas;
207
    }
208
 
209
 
1312 jmachado 210
    public boolean hasStudent(long studentId, boolean transaction)
211
    {
212
        Set<StudentImpl> students;
213
        if(transaction)
214
            students = getStudents();
215
        else
216
        {
217
            IServiceManager sm;
218
            try {
219
                sm = ServiceManager.getInstance();
220
                1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
221
                5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()};
222
                students = (Set<StudentImpl>) sm.execute(null, "LoadCourseUnitStudents", args, names);
223
            } catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) {
224
                logger.error(e,e);
225
                return false;
226
            }
227
        }
228
        if(students == null)
229
            return false;
230
        for(Student s: students)
231
        {
232
            if(s.getId() == studentId)
233
                return true;
234
        }
235
        return false;
236
    }
237
 
238
    public boolean hasTeacher(long teacherId, boolean transaction)
239
    {
240
        Set<TeacherImpl> teachers;
241
        if(transaction)
242
            teachers = getTeachers();
243
        else
244
        {
245
            IServiceManager sm;
246
            try {
247
                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[]{"serializable"};
249
                5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()};
250
                teachers = (Set<TeacherImpl>) sm.execute(null, "LoadCourseUnitTeachers", args, names);
251
            } catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) {
252
                logger.error(e,e);
253
                return false;
254
            }
255
        }
256
        if(teachers == null)
257
            return false;
258
        for(Teacher t: teachers)
259
        {
260
            if(t.getId() == teacherId)
261
                return true;
262
        }
263
        return false;
264
    }
265
 
266
    public boolean isResponsibleTeacher(long teacherId, boolean transaction)
267
    {
268
        Teacher t;
269
        if(transaction)
270
            t = getResponsableTeacher();
271
        else
272
        {
273
            IServiceManager sm;
274
            try {
275
                sm = ServiceManager.getInstance();
276
                1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
277
                5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()};
278
                t = (Teacher) sm.execute(null, "LoadCourseUnitResponsibleTeacher", args, names);
279
            } catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) {
280
                logger.error(e,e);
281
                return false;
282
            }
283
        }
284
        if(t == null)
285
            return false;
286
        if(t.getId() == teacherId)
287
            return true;
288
        return false;
289
    }
290
 
291
    SimpleClearanceRuledSupport clearanceRuledSupport = null;
292
 
293
    public SimpleClearanceRuledSupport getClearanceRuledSupport() {
294
        return clearanceRuledSupport;
295
    }
296
 
297
    public void setClearanceRuledSupport(SimpleClearanceRuledSupport clearanceRuledSupport) {
298
        this.clearanceRuledSupport = clearanceRuledSupport;
299
    }
300
 
301
    @1.5.0/docs/api/java/lang/Override.html">Override
302
    public boolean isClearanceInitialized(UserSessionImpl u) {
303
        return clearanceRuledSupport == null ? false :
304
         clearanceRuledSupport.isClearanceInitialized(u);
305
    }
306
 
307
    @1.5.0/docs/api/java/lang/Override.html">Override
308
    public boolean isClear(UserSessionImpl u, 1.5.0/docs/api/java/lang/String.html">String OP) {
309
 
310
        if(clearanceRuledSupport == null) return false;
311
        if(OP.startsWith("EVALUATION") && !OP.startsWith("EVALUATION_INFO")
312
                && clearanceRuledSupport.isClear(u,CourseUnitClearancesOperation.EVALUATION_ALL.name()))
313
            return true;
314
        return clearanceRuledSupport.isClear(u, OP);
315
    }
316
 
1326 jmachado 317
    @1.5.0/docs/api/java/lang/Override.html">Override
318
    public void initClearances(UserSessionImpl usession,boolean force)
319
    {
320
        CourseUnitImpl c = this;
321
        1.5.0/docs/api/java/lang/String.html">String activeYear = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveYear();
322
        List<String> activeDegrees = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveDegrees();
323
        List<Long> activeCourseIds = DaoFactory.getConfigurationDaoImpl().getCourseUnitEvaluationActiveCourseIds();
324
 
325
        boolean isActiveYear = activeYear != null && c.getImportYear().equals(activeYear);
326
        boolean isActiveDegree = activeDegrees!=null && activeDegrees.contains(c.getCourse().getDegree());
327
        boolean isActiveCourseId = activeCourseIds!=null && activeCourseIds.contains(c.getCourse().getId());
328
 
329
        boolean activePeriod = (isActiveYear && (isActiveCourseId || isActiveDegree));
330
        boolean active = activePeriod || c.isEvaluationOpenByAdmin();
331
 
332
        boolean isComplete = c.getCourseUnitEvaluation() != null && c.getCourseUnitEvaluation().isTeacherComplete() && !c.getCourseUnitEvaluation().isClosed();
333
        boolean isClosed = c.getCourseUnitEvaluation() != null && c.getCourseUnitEvaluation().isClosed();
334
        boolean isEdit = !isClosed && !isComplete;
335
 
336
 
337
        SimpleClearanceRuledSupport s = new SimpleClearanceRuledSupport();
338
        s.setDirty();
339
 
340
        if(isEdit)
341
            s.addClearance(CourseUnitClearancesOperation.EVALUATION_INFO_STATE_EDIT.name(),usession);
342
        else if(isComplete)
343
            s.addClearance(CourseUnitClearancesOperation.EVALUATION_INFO_STATE_COMPLETE.name(),usession);
344
        else if(isClosed)
345
            s.addClearance(CourseUnitClearancesOperation.EVALUATION_INFO_STATE_CLOSED.name(),usession);
346
 
347
        if(activePeriod)
348
        {
349
            s.addClearance(CourseUnitClearancesOperation.EVALUATION_INFO_ACTIVE.name(),usession);
350
            s.addClearance(CourseUnitClearancesOperation.EVALUATION_INFO_ACTIVE_REGULAR_PERIOD.name(),usession);
351
        }
352
        if(c.isEvaluationOpenByAdmin())
353
        {
354
            s.addClearance(CourseUnitClearancesOperation.EVALUATION_INFO_ACTIVE.name(),usession);
355
            s.addClearance(CourseUnitClearancesOperation.EVALUATION_INFO_ACTIVE_SPECIAL_ADMIN.name(),usession);
356
        }
357
 
358
 
359
        if(usession.getUser() != null && usession.getUser().isSuperuserOrAdmin()
360
                || usession.getUser().hasRole(Globals.SERVICES_PROGRAMS_ROLE))
361
        {
1353 jmachado 362
            s.addClearance(CourseUnitClearancesOperation.STATISTICS_CAN_VIEW.name(),usession);
1326 jmachado 363
            s.addClearance(CourseUnitClearancesOperation.EVALUATION_ALL.name(),usession);
1365 jmachado 364
            s.addClearance(CourseUnitClearancesOperation.PROGRAM_EDIT_PROGRAM.name(), usession);
1350 jmachado 365
            s.addClearance(CourseUnitClearancesOperation.PROGRAM_CAN_VALIDATE.name(),usession);
366
            s.addClearance(CourseUnitClearancesOperation.PROGRAM_TEACHER_PART.name(),usession);
367
            s.addClearance(CourseUnitClearancesOperation.PROGRAM_COORDINATOR_PART.name(),usession);
1326 jmachado 368
        }
369
 
370
        if(usession.getUser() != null && usession.getUser() instanceof Teacher)
371
        {
1350 jmachado 372
            Teacher t = ((Teacher)(usession.getUser()));
1326 jmachado 373
            boolean teacher = ((Teacher)(usession.getUser())).isTeacherOfCourseUnit(c.getId(),true);
374
            boolean responsable = c.getResponsableTeacher()!=null && usession.getUser().getId() == c.getResponsableTeacher().getId();
1350 jmachado 375
            boolean isCoordinator = (c.getCourse().getCoordinator() != null && t.getId() == c.getCourse().getCoordinator().getId()) || (c.getCourse().getValidationRole() != null && t.hasRole(c.getCourse().getValidationRole()));
1326 jmachado 376
            if(teacher)
1350 jmachado 377
            {
1326 jmachado 378
                s.addClearance(CourseUnitClearancesOperation.EVALUATION_INFO_USER_TEACHER.name(), usession);
1350 jmachado 379
            }
1326 jmachado 380
            if(responsable)
1350 jmachado 381
            {
1326 jmachado 382
                s.addClearance(CourseUnitClearancesOperation.EVALUATION_INFO_USER_RESP_TEACHER.name(), usession);
1350 jmachado 383
            }
1326 jmachado 384
            if(teacher || responsable)
385
            {
1353 jmachado 386
                s.addClearance(CourseUnitClearancesOperation.STATISTICS_CAN_VIEW.name(),usession);
1326 jmachado 387
                //s.addClearance(CourseUnitClearancesOperation.EVALUATION_INFO_USER_TEACHER.name(), usession);
388
                s.addClearance(CourseUnitClearancesOperation.EVALUATION_EDITION.name(),usession);
389
                if(active && isEdit)
390
                {
391
                    s.addClearance(CourseUnitClearancesOperation.EVALUATION_EDITSAVE.name(),usession);
392
                    s.addClearance(CourseUnitClearancesOperation.EVALUATION_PERSIST_TEACHER_PART.name(),usession);
393
                    s.addClearance(CourseUnitClearancesOperation.EVALUATION_TRANSITATE_TO_COMPLETE.name(),usession);
394
                }
395
            }
396
 
1350 jmachado 397
            if(isCoordinator)
1326 jmachado 398
            {
1353 jmachado 399
                s.addClearance(CourseUnitClearancesOperation.STATISTICS_CAN_VIEW.name(),usession);
1350 jmachado 400
                s.addClearance(CourseUnitClearancesOperation.PROGRAM_CAN_VALIDATE.name(),usession);
401
                s.addClearance(CourseUnitClearancesOperation.EVALUATION_INFO_USER_COMMISSION.name(), usession);
402
                s.addClearance(CourseUnitClearancesOperation.EVALUATION_EDITION.name(), usession);
403
                if(active && isEdit)
404
                {
405
                    s.addClearance(CourseUnitClearancesOperation.EVALUATION_EDITSAVE.name(),usession);
406
                    s.addClearance(CourseUnitClearancesOperation.EVALUATION_PERSIST_TEACHER_PART.name(),usession);
407
                    s.addClearance(CourseUnitClearancesOperation.EVALUATION_PERSIST_COMISSION_PART.name(),usession);
408
                    s.addClearance(CourseUnitClearancesOperation.EVALUATION_TRANSITATE_TO_COMPLETE.name(),usession);
409
                    s.addClearance(CourseUnitClearancesOperation.EVALUATION_TRANSITATE_TO_CLOSE.name(),usession);
410
                }
411
                else if(active && isComplete)
412
                {
413
                    s.addClearance(CourseUnitClearancesOperation.EVALUATION_EDITSAVE.name(),usession);
414
                    s.addClearance(CourseUnitClearancesOperation.EVALUATION_PERSIST_TEACHER_PART.name(),usession);
415
                    s.addClearance(CourseUnitClearancesOperation.EVALUATION_PERSIST_COMISSION_PART.name(),usession);
416
                    s.addClearance(CourseUnitClearancesOperation.EVALUATION_TRANSITATE_TO_CLOSE.name(),usession);
417
                    s.addClearance(CourseUnitClearancesOperation.EVALUATION_TRANSITATE_TO_EDIT.name(),usession);
418
                }
419
                else if(active && isClosed)
420
                {
421
                    s.addClearance(CourseUnitClearancesOperation.EVALUATION_TRANSITATE_TO_EDIT.name(),usession);
422
                }
1326 jmachado 423
            }
1350 jmachado 424
 
425
 
426
            if(!c.isValidProgram())
1326 jmachado 427
            {
1350 jmachado 428
                if(teacher)
1365 jmachado 429
                {
430
                    s.addClearance(CourseUnitClearancesOperation.PROGRAM_EDIT_PROGRAM.name(), usession);
1350 jmachado 431
                    s.addClearance(CourseUnitClearancesOperation.PROGRAM_TEACHER_PART.name(), usession);
1365 jmachado 432
                }
1350 jmachado 433
                if(isCoordinator)
434
                {
1365 jmachado 435
                    s.addClearance(CourseUnitClearancesOperation.PROGRAM_EDIT_PROGRAM.name(), usession);
1350 jmachado 436
                    s.addClearance(CourseUnitClearancesOperation.PROGRAM_TEACHER_PART.name(), usession);
437
                    s.addClearance(CourseUnitClearancesOperation.PROGRAM_COORDINATOR_PART.name(), usession);
438
                }
1326 jmachado 439
            }
1350 jmachado 440
            else
1326 jmachado 441
            {
1350 jmachado 442
                s.addClearance(CourseUnitClearancesOperation.PROGRAM_INFO_VALID_NOT_ACTIVE.name(), usession);
1326 jmachado 443
            }
1350 jmachado 444
 
1326 jmachado 445
        }
1350 jmachado 446
 
1326 jmachado 447
        c.setClearanceRuledSupport(s);
448
    }
449
 
1312 jmachado 450
    public static enum CourseUnitClearancesOperation
451
    {
452
        EVALUATION_ALL, //SPECIAL OPERATION FOR DENY AND PERMIT REPLACE FULL CONTROL
453
 
454
        //COURSE UNIT EVALUATION
455
        EVALUATION_PERSIST_TEACHER_PART, //SERVICE PERSIST THIS PART
456
        EVALUATION_PERSIST_COMISSION_PART, //SERVICE PERSIST THIS PART
457
 
458
        EVALUATION_EDITION, //CAN SEE EDITION SCREEN
459
        EVALUATION_EDITSAVE, //CAN PRESS SAVE
460
        EVALUATION_TRANSITATE_TO_COMPLETE, //CAN_TRANSITATE
461
        EVALUATION_TRANSITATE_TO_CLOSE, //CAN CLOSE
462
        EVALUATION_TRANSITATE_TO_EDIT, //CAN REVERT
463
 
464
        EVALUATION_INFO_ACTIVE, //INFO CLEARANCE WHEN ACTIVE
465
        EVALUATION_INFO_ACTIVE_SPECIAL_ADMIN, //INFO CLEARANCE REASON OF BEING ACTIVE
466
        EVALUATION_INFO_ACTIVE_REGULAR_PERIOD, //INFO CLEARANCE REASON OF BEING ACTIVE
467
 
468
        EVALUATION_INFO_STATE_EDIT, //INFO CLEARANCE
469
        EVALUATION_INFO_STATE_COMPLETE, //INFO CLEARANCE
470
        EVALUATION_INFO_STATE_CLOSED, //INFO CLEARANCE
471
 
472
        EVALUATION_INFO_USER_TEACHER, //INFO CLEARANCE
473
        EVALUATION_INFO_USER_RESP_TEACHER, //INFO CLEARANCE
474
        EVALUATION_INFO_USER_COMMISSION, //INFO CLEARANCE
475
 
1350 jmachado 476
 
1365 jmachado 477
        PROGRAM_EDIT_PROGRAM,
1350 jmachado 478
        PROGRAM_COORDINATOR_PART,
479
        PROGRAM_TEACHER_PART,
1365 jmachado 480
 
1350 jmachado 481
        PROGRAM_CAN_VALIDATE,
1353 jmachado 482
        PROGRAM_INFO_VALID_NOT_ACTIVE,
1350 jmachado 483
 
1353 jmachado 484
        STATISTICS_CAN_VIEW,
485
 
486
 
1312 jmachado 487
        ;
488
 
489
        public static CourseUnitClearancesOperation parse(1.5.0/docs/api/java/lang/String.html">String clearance)
490
        {
491
            if(clearance == null)
492
                return null;
493
            for(CourseUnitClearancesOperation op: CourseUnitClearancesOperation.values())
494
            {
495
                if(op.name().equals(clearance))
496
                    return op;
497
            }
498
            return null;
499
        }
500
    }
501
 
502
 
503
    public Tipologias getTipologiasClass() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
504
    {
505
        return Tipologias.deserialize(getTipologias());
506
    }
507
 
508
    public void setTipologiasClass(Tipologias tipologias) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
509
    {
510
        if(tipologias != null)
511
            setTipologias(tipologias.serialize());
512
    }
513
 
1313 jmachado 514
    public TipologiaPersistent loadPersistent(Tipologia myTipo)
515
    {
516
        TipologiaPersistent tipologiaPersistent = new TipologiaPersistent();
517
        tipologiaPersistent.setHorRef(myTipo.isHorRef());
518
        tipologiaPersistent.setExtra(myTipo.isExtra());
519
        tipologiaPersistent.setTeacher(DaoFactory.getTeacherDaoImpl().loadBySigesCode(1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(myTipo.getCdDocente())));
520
        tipologiaPersistent.setCdTipologia(myTipo.getCdTipologia());
521
        tipologiaPersistent.setOcorrencias(myTipo.getOcorrencias());
1326 jmachado 522
        tipologiaPersistent.setMarkWarning(myTipo.isMarkWarning());
523
        tipologiaPersistent.setUse(myTipo.isUse());
1313 jmachado 524
 
525
        tipologiaPersistent.setCourseUnitTurma(findTurma(myTipo.getCdTurma()));
526
        if(tipologiaPersistent.getCourseUnitTurma() == null || tipologiaPersistent.getTeacher() == null)
527
        {
1338 jmachado 528
            logger.error("Turma ou professor nao encontrados enquanto fazia uma tipologia persistente: turma:" + myTipo.getCdTurma() + " teacher code: " + myTipo.getCdDocente());
1313 jmachado 529
            return null;
530
        }
531
        return tipologiaPersistent;
532
    }
533
 
534
    public CourseUnitTurma findTurma(1.5.0/docs/api/java/lang/String.html">String turma)
535
    {
536
        if(getTurmas() == null)
537
            return null;
538
        for(CourseUnitTurma t: getTurmas())
539
        {
540
            if(t.getTurma().equals(turma))
541
                return t;
542
        }
543
        return null;
544
    }
545
 
546
 
547
    public static class TipologiaPersistent
548
    {
549
        private Teacher teacher;
550
        private CourseUnitTurma courseUnitTurma;
551
        private 1.5.0/docs/api/java/lang/String.html">String cdTipologia;
552
        private 1.5.0/docs/api/java/lang/Integer.html">Integer ocorrencias = 0;
553
        protected boolean extra;
554
        protected boolean horRef;
1326 jmachado 555
        protected boolean use;   //campo auxiliar para marcar se vai ser ou não usada  nas afetacoes especificas
556
        //por omissão apenas as que têm sumários
557
        protected boolean markWarning; //camp
1313 jmachado 558
 
1326 jmachado 559
        public boolean isUse() {
560
            return use;
561
        }
562
 
563
        public void setUse(boolean use) {
564
            this.use = use;
565
        }
566
 
567
        public boolean isMarkWarning() {
568
            return markWarning;
569
        }
570
 
571
        public void setMarkWarning(boolean markWarning) {
572
            this.markWarning = markWarning;
573
        }
574
 
1313 jmachado 575
        public boolean isExtra() {
576
            return extra;
577
        }
578
 
579
        public boolean isHorRef() {
580
            return horRef;
581
        }
582
 
583
        public boolean isSumario() {
584
            return ocorrencias != null && ocorrencias > 0;
585
        }
586
 
587
        public void setExtra(boolean extra) {
588
            this.extra = extra;
589
        }
590
 
591
        public void setHorRef(boolean horRef) {
592
            this.horRef = horRef;
593
        }
594
 
595
        public Teacher getTeacher() {
596
            return teacher;
597
        }
598
 
599
        public void setTeacher(Teacher teacher) {
600
            this.teacher = teacher;
601
        }
602
 
603
        public CourseUnitTurma getCourseUnitTurma() {
604
            return courseUnitTurma;
605
        }
606
 
607
        public void setCourseUnitTurma(CourseUnitTurma courseUnitTurma) {
608
            this.courseUnitTurma = courseUnitTurma;
609
        }
610
 
611
        public 1.5.0/docs/api/java/lang/String.html">String getCdTipologia() {
612
            return cdTipologia;
613
        }
614
 
615
        public void setCdTipologia(1.5.0/docs/api/java/lang/String.html">String cdTipologia) {
616
            this.cdTipologia = cdTipologia;
617
        }
618
 
619
        public 1.5.0/docs/api/java/lang/Integer.html">Integer getOcorrencias() {
1338 jmachado 620
            return ocorrencias == null ? 0:ocorrencias;
1313 jmachado 621
        }
622
 
623
        public void setOcorrencias(1.5.0/docs/api/java/lang/Integer.html">Integer ocorrencias) {
624
            this.ocorrencias = ocorrencias;
625
        }
626
    }
1312 jmachado 627
    /**
628
     * Os codigos de tipologia devem ser limitados a T TP OT etc
629
     */
630
    public static class Tipologia
631
    {
1313 jmachado 632
        protected 1.5.0/docs/api/java/lang/String.html">String cdDocente;
633
        protected 1.5.0/docs/api/java/lang/String.html">String cdTurma;
634
        protected 1.5.0/docs/api/java/lang/String.html">String cdTipologia;
635
        protected 1.5.0/docs/api/java/lang/String.html">String dsTipologia;
1338 jmachado 636
        protected 1.5.0/docs/api/java/lang/Integer.html">Integer ocorrencias = 0; // apenas faz sentido nos sumarios. no horario ref nao.
1312 jmachado 637
 
1325 jmachado 638
        protected boolean use;   //campo auxiliar para marcar se vai ser ou não usada  nas afetacoes especificas
639
                                //por omissão apenas as que têm sumários
640
        protected boolean markWarning; //campo auxiliar para marcar se vai ser ou não usada  nas afetacoes especificas
641
 
1313 jmachado 642
        protected boolean extra;
643
        protected boolean horRef;
644
 
1325 jmachado 645
        public boolean isUse() {
646
            return use;
647
        }
648
 
649
        public void setUse(boolean use) {
650
            this.use = use;
651
        }
652
 
653
        public boolean isMarkWarning() {
654
            return markWarning;
655
        }
656
 
657
        public void setMarkWarning(boolean markWarning) {
658
            this.markWarning = markWarning;
659
        }
660
 
1312 jmachado 661
        public 1.5.0/docs/api/java/lang/Integer.html">Integer getOcorrencias() {
1338 jmachado 662
            return ocorrencias == null ? 0:ocorrencias;
1312 jmachado 663
        }
664
 
1338 jmachado 665
        public boolean hasOcorrencias() {
666
            return ocorrencias != null && ocorrencias > 0;
667
        }
668
 
1312 jmachado 669
        public void setOcorrencias(1.5.0/docs/api/java/lang/Integer.html">Integer ocorrencias) {
670
            this.ocorrencias = ocorrencias;
671
        }
672
 
673
        public 1.5.0/docs/api/java/lang/String.html">String getCdDocente() {
674
            return cdDocente;
675
        }
676
 
677
        public void setCdDocente(1.5.0/docs/api/java/lang/String.html">String cdDocente) {
678
            this.cdDocente = cdDocente;
679
        }
680
 
681
        public 1.5.0/docs/api/java/lang/String.html">String getCdTurma() {
682
            return cdTurma;
683
        }
684
 
685
        public void setCdTurma(1.5.0/docs/api/java/lang/String.html">String cdTurma) {
686
            this.cdTurma = cdTurma;
687
        }
688
 
689
        public 1.5.0/docs/api/java/lang/String.html">String getCdTipologia() {
690
            return cdTipologia;
691
        }
692
 
693
        public void setCdTipologia(1.5.0/docs/api/java/lang/String.html">String cdTipologia) {
694
            this.cdTipologia = cdTipologia;
695
        }
696
 
1313 jmachado 697
        public 1.5.0/docs/api/java/lang/String.html">String getDsTipologia() {
698
            return dsTipologia;
699
        }
700
 
701
        public void setDsTipologia(1.5.0/docs/api/java/lang/String.html">String dsTipologia) {
702
            this.dsTipologia = dsTipologia;
703
        }
704
 
705
        public boolean isExtra() {
706
            return extra;
707
        }
708
 
709
        public boolean isSumario() {
710
            return ocorrencias != null && ocorrencias > 0;
711
        }
712
 
713
        public boolean isHorRef() {
714
            return horRef;
715
        }
716
 
717
 
718
 
1312 jmachado 719
        @1.5.0/docs/api/java/lang/Override.html">Override
720
        public boolean equals(5+0%2Fdocs%2Fapi+Object">Object o)
721
        {
722
            return o instanceof Tipologia &&
723
                    ((((Tipologia)o).getCdTurma() == null && getCdTurma() == null)
724
                            ||
725
                     (((Tipologia)o).getCdTurma().equals(getCdTurma())))
726
                    &&
727
 
728
                    (
729
                     (((Tipologia)o).getCdDocente() == null && getCdDocente() == null)
730
                            ||
731
                     (((Tipologia)o).getCdDocente().equals(getCdDocente())))
732
                    &&
733
 
734
                    (
735
                     (((Tipologia)o).getCdTipologia() == null && getCdTipologia() == null)
736
                                    ||
737
                     (((Tipologia)o).getCdTipologia().equals(getCdTipologia())));
738
        }
1313 jmachado 739
 
740
        public boolean equalsIncDsFields(5+0%2Fdocs%2Fapi+Object">Object o)
741
        {
742
            return o instanceof Tipologia &&
743
                    equals(o)
744
                    &&
745
                    (
746
                            (((Tipologia)o).getDsTipologia() == null && getDsTipologia() == null)
747
                                    ||
748
                                    (((Tipologia)o).getDsTipologia().equals(getDsTipologia())))
749
                    &&
750
 
751
                    (
752
                            (((Tipologia)o).getOcorrencias() == null && getOcorrencias() == null)
753
                                    ||
754
                                    (((Tipologia)o).getOcorrencias().equals(getOcorrencias())))
755
                    ;
756
        }
1312 jmachado 757
    }
758
 
1326 jmachado 759
    public static class MergedTipologias
760
    {
761
        ArrayList<Tipologia> tipologiasWithMarkedAndUsed = new ArrayList<Tipologia>();
762
 
763
        public ArrayList<Tipologia> getTipologiasWithMarkedAndUsed() {
764
            return tipologiasWithMarkedAndUsed;
765
        }
766
 
767
        public void setTipologiasWithMarkedAndUsed(ArrayList<Tipologia> tipologiasWithMarkedAndUsed) {
768
            this.tipologiasWithMarkedAndUsed = tipologiasWithMarkedAndUsed;
769
        }
770
    }
1312 jmachado 771
    public static class Tipologias
772
    {
1313 jmachado 773
        ArrayList<Tipologia> tipologiasHorarioReferencia = new ArrayList<Tipologia>();
774
        ArrayList<Tipologia> tipologiasSumarios = new ArrayList<Tipologia>();
775
        ArrayList<Tipologia> tipologiasExtraAdicionadas = new ArrayList<Tipologia>();
1326 jmachado 776
        ArrayList<Tipologia> tipologiasUsadas = new ArrayList<Tipologia>();
777
        ArrayList<Tipologia> tipologiasMarcadas = new ArrayList<Tipologia>();
1312 jmachado 778
 
779
        public ArrayList<Tipologia> getTipologiasHorarioReferencia() {
1333 jmachado 780
 
781
            return tipologiasHorarioReferencia == null ? new ArrayList<Tipologia>() : tipologiasHorarioReferencia;
782
 
1312 jmachado 783
        }
784
 
785
        public void setTipologiasHorarioReferencia(ArrayList<Tipologia> tipologiasHorarioReferencia) {
786
            this.tipologiasHorarioReferencia = tipologiasHorarioReferencia;
787
        }
788
 
789
        public ArrayList<Tipologia> getTipologiasSumarios() {
1333 jmachado 790
            return tipologiasSumarios == null ? new ArrayList<Tipologia>() : tipologiasSumarios;
1312 jmachado 791
        }
792
 
793
        public void setTipologiasSumarios(ArrayList<Tipologia> tipologiasSumarios) {
794
            this.tipologiasSumarios = tipologiasSumarios;
795
        }
796
 
797
        public ArrayList<Tipologia> getTipologiasExtraAdicionadas() {
1333 jmachado 798
            return tipologiasExtraAdicionadas == null ? new ArrayList<Tipologia>() : tipologiasExtraAdicionadas;
1312 jmachado 799
        }
800
 
801
        public void setTipologiasExtraAdicionadas(ArrayList<Tipologia> tipologiasExtraAdicionadas) {
802
            this.tipologiasExtraAdicionadas = tipologiasExtraAdicionadas;
803
        }
804
 
1333 jmachado 805
        public ArrayList<Tipologia> getTipologiasUsadas() {
806
            return tipologiasUsadas == null ? new ArrayList<Tipologia>() : tipologiasUsadas;
807
        }
1326 jmachado 808
 
809
        public void setTipologiasUsadas(ArrayList<Tipologia> tipologiasUsadas) { this.tipologiasUsadas = tipologiasUsadas; }
810
 
1333 jmachado 811
        public ArrayList<Tipologia> getTipologiasMarcadas() {
812
            return tipologiasMarcadas == null ? new ArrayList<Tipologia>() : tipologiasMarcadas;
813
        }
1326 jmachado 814
 
815
        public void setTipologiasMarcadas(ArrayList<Tipologia> tipologiasMarcadas) { this.tipologiasMarcadas = tipologiasMarcadas; }
816
 
1312 jmachado 817
        private static Genson getGenson(){
818
            Genson genson = new Genson.Builder()
819
                    .exclude(5+0%2Fdocs%2Fapi+Object">Object.class)
820
                    .include("tipologiasExtraAdicionadas", Tipologias.class)
821
                    .include("tipologiasSumarios", Tipologias.class)
822
                    .include("tipologiasHorarioReferencia", Tipologias.class)
1326 jmachado 823
                    .include("tipologiasUsadas", Tipologias.class)
824
                    .include("tipologiasMarcadas", Tipologias.class)
1312 jmachado 825
                    .include("cdTipologia", Tipologia.class)
826
                    .include("cdDocente", Tipologia.class)
827
                    .include("cdTurma", Tipologia.class)
1313 jmachado 828
                    .include("dsTipologia",Tipologia.class)
1312 jmachado 829
                    .include("ocorrencias", Tipologia.class)
830
                    .create();
831
            return genson;
832
        }
833
 
1326 jmachado 834
        private static Genson getGensonMergedTipologiasComplete(){
835
            Genson genson = new Genson.Builder()
836
                    .exclude(5+0%2Fdocs%2Fapi+Object">Object.class)
837
 
838
                    .include("tipologiasWithMarkedAndUsed", MergedTipologias.class)
839
                    .include("cdTipologia", Tipologia.class)
840
                    .include("cdDocente", Tipologia.class)
841
                    .include("cdTurma", Tipologia.class)
842
                    .include("dsTipologia",Tipologia.class)
843
                    .include("ocorrencias", Tipologia.class)
844
                    .include("horRef", Tipologia.class)
845
                    .include("extra", Tipologia.class)
846
                    .include("use", Tipologia.class)
847
                    .include("markWarning", Tipologia.class)
848
                    .create();
849
            return genson;
850
        }
851
 
1312 jmachado 852
        public 1.5.0/docs/api/java/lang/String.html">String serialize() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
853
        {
854
            Genson genson = getGenson();
855
            try {
856
                return genson.serialize(this);
857
            } catch (TransformationException e) {
858
                throw e;
859
            } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) {
860
                throw e;
861
            }
862
        }
863
        public static Tipologias deserialize(1.5.0/docs/api/java/lang/String.html">String serial) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
864
        {
865
            if(serial == null)
1333 jmachado 866
                return new Tipologias();
1312 jmachado 867
            try {
868
                return getGenson().deserialize(serial, Tipologias.class);
869
            } catch (TransformationException e) {
870
                throw e;
871
            } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) {
872
                throw e;
873
            }
874
        }
875
 
876
        public static void main(1.5.0/docs/api/java/lang/String.html">String [] args)
877
        {
878
            new TestCourseUnit().testTipologias();
879
        }
1313 jmachado 880
 
1326 jmachado 881
        public static 1.5.0/docs/api/java/lang/String.html">String serializeMergedList(ArrayList<Tipologia> tipologias) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
1313 jmachado 882
        {
1326 jmachado 883
            MergedTipologias mergedTipologias = new MergedTipologias();
1333 jmachado 884
            if(tipologias != null)
885
            {
886
                mergedTipologias.setTipologiasWithMarkedAndUsed(tipologias);
887
            }
1326 jmachado 888
            Genson genson = getGensonMergedTipologiasComplete();
889
            try {
890
                return genson.serialize(mergedTipologias);
891
            } catch (TransformationException e) {
892
                throw e;
893
            } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) {
894
                throw e;
895
            }
896
        }
897
        public static ArrayList<Tipologia> deserializeMergedTipologias(1.5.0/docs/api/java/lang/String.html">String serial) throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
898
        {
899
            if(serial == null)
1333 jmachado 900
                return new ArrayList<Tipologia>();
1326 jmachado 901
            try {
902
                MergedTipologias mergedTipologias = getGensonMergedTipologiasComplete().deserialize(serial, MergedTipologias.class);
903
                if(mergedTipologias.getTipologiasWithMarkedAndUsed() == null)
904
                    return new ArrayList<Tipologia>();
905
                return mergedTipologias.getTipologiasWithMarkedAndUsed();
906
            } catch (TransformationException e) {
907
                throw e;
908
            } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) {
909
                throw e;
910
            }
911
        }
1332 jmachado 912
        public 1.5.0/docs/api/java/lang/String.html">String obtainMergeTipologiasSerialized() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException
913
        {
914
            return serializeMergedList(obtainMergeTipologias());
915
        }
1337 jmachado 916
 
1326 jmachado 917
        public ArrayList<Tipologia> obtainMergeTipologias()
918
        {
919
            ArrayList<Tipologia> merge = new ArrayList<Tipologia>();
1315 jmachado 920
            if(getTipologiasSumarios() != null)
921
                merge.addAll(getTipologiasSumarios());
1313 jmachado 922
 
1315 jmachado 923
            if(getTipologiasHorarioReferencia() != null)
924
                for(Tipologia tipo: getTipologiasHorarioReferencia())
1313 jmachado 925
                {
1315 jmachado 926
                    if(!merge.contains(tipo))
927
                    {
928
                        merge.add(tipo);
929
                    }
1313 jmachado 930
                }
1315 jmachado 931
            if(getTipologiasExtraAdicionadas() != null)
932
                for(Tipologia tipo: getTipologiasExtraAdicionadas())
1313 jmachado 933
                {
1315 jmachado 934
                    if(!merge.contains(tipo))
935
                    {
936
                        merge.add(tipo);
937
                    }
1313 jmachado 938
                }
939
            for(Tipologia tipo: merge)
940
            {
1326 jmachado 941
                tipo.setMarkWarning(false);
942
                tipo.setUse(false);
1315 jmachado 943
                if(getTipologiasHorarioReferencia() != null && getTipologiasHorarioReferencia().contains(tipo))
1313 jmachado 944
                {
945
                    tipo.horRef = true;
946
                }
947
 
1315 jmachado 948
                if(getTipologiasExtraAdicionadas() != null && getTipologiasExtraAdicionadas().contains(tipo))
1313 jmachado 949
                {
950
                    tipo.extra = true;
951
                }
952
            }
1326 jmachado 953
 
954
            if(getTipologiasMarcadas() != null)
955
                for(Tipologia t: getTipologiasMarcadas())
956
                {
957
                    for(Tipologia tMerge: merge)
958
                    {
959
                        if(tMerge.equals(t))
960
                        {
961
                            tMerge.setMarkWarning(true);
962
                            break;
963
                        }
964
                    }
965
                }
966
            if(getTipologiasUsadas() != null)
967
                for(Tipologia t: getTipologiasUsadas())
968
                {
969
                    for(Tipologia tMerge: merge)
970
                    {
971
                        if(tMerge.equals(t))
972
                        {
973
                            tMerge.setUse(true);
974
                            break;
975
                        }
976
                    }
977
                }
1313 jmachado 978
            return merge;
979
        }
980
 
981
 
1337 jmachado 982
        public ArrayList<Tipologia> obtainTipologiasSimples(CourseUnit courseUnit)
983
        {
984
            ArrayList<Tipologia> merge = new ArrayList<Tipologia>();
985
 
986
            Map<String,Map<String,Tipologia>> docenteTurmas = new HashMap<String,Map<String,Tipologia>>();
987
 
988
            fullfillTipologiasSimples(getTipologiasSumarios(), docenteTurmas);
989
            fullfillTipologiasSimples(getTipologiasExtraAdicionadas(), docenteTurmas);
990
            fullfillTipologiasSimples(getTipologiasHorarioReferencia(), docenteTurmas);
991
            fullfillTipologiasSimples(getTipologiasMarcadas(), docenteTurmas);
992
            fullfillTipologiasSimples(getTipologiasUsadas(), docenteTurmas);
993
 
994
 
995
            if(docenteTurmas.size() == 0)
996
            {
997
                //NAO Há sumários vamos associar todos os docentes a todas as turmas
998
                if(courseUnit.getTurmas() != null && courseUnit.getTeachers() != null)
999
                {
1000
                    for(CourseUnitTurma turma: courseUnit.getTurmas())
1001
                    {
1002
                        for(Teacher t : courseUnit.getTeachers())
1003
                        {
1004
                            Tipologia simples = new Tipologia();
1005
                            simples.setMarkWarning(true);
1006
                            simples.setCdDocente(""+t.getSigesCode());
1007
                            simples.setCdTurma(turma.getTurma());
1008
                            simples.setCdTipologia(Globals.BACO_TIPOLOGIA_SIMPLES_VIRTUAL_CODE);
1009
                            simples.setDsTipologia(Globals.BACO_TIPOLOGIA_SIMPLES_DS);
1010
                            merge.add(simples);
1011
                        }
1012
                    }
1013
                }
1014
            }
1015
            else
1016
            {
1017
                for(1.5.0/docs/api/java/util/Map.html">Map.Entry<String,Map<String,Tipologia>> docentes: docenteTurmas.entrySet())
1018
                {
1019
                    for(Tipologia tipologia: docentes.getValue().values())
1020
                    {
1021
                        merge.add(tipologia);
1022
                    }
1023
                }
1024
            }
1025
            return merge;
1026
        }
1027
 
1028
        private void fullfillTipologiasSimples(ArrayList<Tipologia> tipologias, Map<String, Map<String, Tipologia>> docenteTurmas) {
1029
            if(tipologias != null)
1030
                for(Tipologia tipo: tipologias)
1031
                {
1032
                    Map<String,Tipologia> turmasDocente = docenteTurmas.get(tipo.getCdDocente());
1033
                    if(turmasDocente == null)
1034
                        turmasDocente = new HashMap<String,Tipologia>();
1035
                    docenteTurmas.put(tipo.getCdDocente(),turmasDocente);
1036
                    Tipologia simples = turmasDocente.get(tipo.getCdTurma());
1037
                    if(simples==null)
1038
                    {
1039
                        simples = new Tipologia();
1040
                        simples.setCdDocente(tipo.getCdDocente());
1041
                        simples.setCdTurma(tipo.getCdTurma());
1042
                        simples.setCdTipologia(Globals.BACO_TIPOLOGIA_SIMPLES_VIRTUAL_CODE);
1043
                        simples.setDsTipologia(Globals.BACO_TIPOLOGIA_SIMPLES_DS);
1338 jmachado 1044
                        if(tipo.hasOcorrencias())
1337 jmachado 1045
                        {
1046
                            simples.setOcorrencias(tipo.getOcorrencias());
1047
                        }
1048
                        turmasDocente.put(tipo.getCdTurma(),simples);
1049
                    }
1338 jmachado 1050
                    if(tipo.hasOcorrencias())
1337 jmachado 1051
                    {
1338 jmachado 1052
                        if(simples.getOcorrencias() == null)
1053
                            simples.setOcorrencias(0);
1337 jmachado 1054
                        simples.setOcorrencias(simples.getOcorrencias()+tipo.getOcorrencias());
1055
                    }
1056
 
1057
                }
1058
        }
1059
 
1060
 
1312 jmachado 1061
    }
1062
 
1063
 
1064
 
1065
 
1066
 
112 jmachado 1067
}