Rev 1554 | Rev 1622 | 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()) |
||
1585 | jmachado | 151 | || ((CourseImpl)getCourse()).isFromCourseCommission(userSession) |
973 | jmachado | 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 | |||
1554 | jmachado | 359 | if(usession.getUser() != null && (usession.getUser().isSuperuserOrAdmin() || usession.getUser().hasRole(Globals.SERVICES_PROGRAMS_ROLE))) |
1326 | jmachado | 360 | { |
1353 | jmachado | 361 | s.addClearance(CourseUnitClearancesOperation.STATISTICS_CAN_VIEW.name(),usession); |
1326 | jmachado | 362 | s.addClearance(CourseUnitClearancesOperation.EVALUATION_ALL.name(),usession); |
1365 | jmachado | 363 | s.addClearance(CourseUnitClearancesOperation.PROGRAM_EDIT_PROGRAM.name(), usession); |
1350 | jmachado | 364 | s.addClearance(CourseUnitClearancesOperation.PROGRAM_CAN_VALIDATE.name(),usession); |
365 | s.addClearance(CourseUnitClearancesOperation.PROGRAM_TEACHER_PART.name(),usession); |
||
366 | s.addClearance(CourseUnitClearancesOperation.PROGRAM_COORDINATOR_PART.name(),usession); |
||
1326 | jmachado | 367 | } |
368 | |||
369 | if(usession.getUser() != null && usession.getUser() instanceof Teacher) |
||
370 | { |
||
1350 | jmachado | 371 | Teacher t = ((Teacher)(usession.getUser())); |
1326 | jmachado | 372 | boolean teacher = ((Teacher)(usession.getUser())).isTeacherOfCourseUnit(c.getId(),true); |
373 | boolean responsable = c.getResponsableTeacher()!=null && usession.getUser().getId() == c.getResponsableTeacher().getId(); |
||
1585 | jmachado | 374 | boolean isCoordinator = ((CourseImpl) DaoFactory.getCourseDaoImpl().narrow(c.getCourse())).isFromCourseCommission(t); |
375 | |||
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 | |||
1406 | jmachado | 514 | public static class TipologiaLoadExeption extends 1.5.0/docs/api/java/lang/Exception.html">Exception |
1313 | jmachado | 515 | { |
1406 | jmachado | 516 | boolean teacherFail = false; |
517 | boolean turmaFail = false; |
||
518 | |||
519 | public TipologiaLoadExeption(boolean teacherFail, boolean turmaFail) { |
||
520 | this.teacherFail = teacherFail; |
||
521 | this.turmaFail = turmaFail; |
||
522 | } |
||
523 | |||
524 | public boolean isTeacherFail() { |
||
525 | return teacherFail; |
||
526 | } |
||
527 | |||
528 | public boolean isTurmaFail() { |
||
529 | return turmaFail; |
||
530 | } |
||
531 | |||
532 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
533 | public 1.5.0/docs/api/java/lang/String.html">String getMessage() { |
||
534 | return "Professor: " + (teacherFail? "Falhou" : "OK") + " Turma: " + (turmaFail? "Falhou" : "OK"); |
||
535 | } |
||
536 | } |
||
537 | /** |
||
538 | * |
||
539 | * @param myTipo |
||
540 | * @return |
||
541 | */ |
||
542 | public TipologiaPersistent loadPersistent(Tipologia myTipo) throws TipologiaLoadExeption |
||
543 | { |
||
1313 | jmachado | 544 | TipologiaPersistent tipologiaPersistent = new TipologiaPersistent(); |
545 | tipologiaPersistent.setHorRef(myTipo.isHorRef()); |
||
546 | tipologiaPersistent.setExtra(myTipo.isExtra()); |
||
547 | tipologiaPersistent.setTeacher(DaoFactory.getTeacherDaoImpl().loadBySigesCode(1.5.0/docs/api/java/lang/Integer.html">Integer.parseInt(myTipo.getCdDocente()))); |
||
548 | tipologiaPersistent.setCdTipologia(myTipo.getCdTipologia()); |
||
549 | tipologiaPersistent.setOcorrencias(myTipo.getOcorrencias()); |
||
1326 | jmachado | 550 | tipologiaPersistent.setMarkWarning(myTipo.isMarkWarning()); |
551 | tipologiaPersistent.setUse(myTipo.isUse()); |
||
1313 | jmachado | 552 | |
553 | tipologiaPersistent.setCourseUnitTurma(findTurma(myTipo.getCdTurma())); |
||
554 | if(tipologiaPersistent.getCourseUnitTurma() == null || tipologiaPersistent.getTeacher() == null) |
||
555 | { |
||
1338 | jmachado | 556 | logger.error("Turma ou professor nao encontrados enquanto fazia uma tipologia persistente: turma:" + myTipo.getCdTurma() + " teacher code: " + myTipo.getCdDocente()); |
1406 | jmachado | 557 | throw new TipologiaLoadExeption(tipologiaPersistent.getTeacher() == null,tipologiaPersistent.getCourseUnitTurma() == null); |
1313 | jmachado | 558 | } |
559 | return tipologiaPersistent; |
||
560 | } |
||
561 | |||
562 | public CourseUnitTurma findTurma(1.5.0/docs/api/java/lang/String.html">String turma) |
||
563 | { |
||
564 | if(getTurmas() == null) |
||
565 | return null; |
||
566 | for(CourseUnitTurma t: getTurmas()) |
||
567 | { |
||
568 | if(t.getTurma().equals(turma)) |
||
569 | return t; |
||
570 | } |
||
571 | return null; |
||
572 | } |
||
573 | |||
574 | |||
575 | public static class TipologiaPersistent |
||
576 | { |
||
577 | private Teacher teacher; |
||
578 | private CourseUnitTurma courseUnitTurma; |
||
579 | private 1.5.0/docs/api/java/lang/String.html">String cdTipologia; |
||
580 | private 1.5.0/docs/api/java/lang/Integer.html">Integer ocorrencias = 0; |
||
581 | protected boolean extra; |
||
582 | protected boolean horRef; |
||
1326 | jmachado | 583 | protected boolean use; //campo auxiliar para marcar se vai ser ou não usada nas afetacoes especificas |
584 | //por omissão apenas as que têm sumários |
||
585 | protected boolean markWarning; //camp |
||
1313 | jmachado | 586 | |
1326 | jmachado | 587 | public boolean isUse() { |
588 | return use; |
||
589 | } |
||
590 | |||
591 | public void setUse(boolean use) { |
||
592 | this.use = use; |
||
593 | } |
||
594 | |||
595 | public boolean isMarkWarning() { |
||
596 | return markWarning; |
||
597 | } |
||
598 | |||
599 | public void setMarkWarning(boolean markWarning) { |
||
600 | this.markWarning = markWarning; |
||
601 | } |
||
602 | |||
1313 | jmachado | 603 | public boolean isExtra() { |
604 | return extra; |
||
605 | } |
||
606 | |||
607 | public boolean isHorRef() { |
||
608 | return horRef; |
||
609 | } |
||
610 | |||
611 | public boolean isSumario() { |
||
612 | return ocorrencias != null && ocorrencias > 0; |
||
613 | } |
||
614 | |||
615 | public void setExtra(boolean extra) { |
||
616 | this.extra = extra; |
||
617 | } |
||
618 | |||
619 | public void setHorRef(boolean horRef) { |
||
620 | this.horRef = horRef; |
||
621 | } |
||
622 | |||
623 | public Teacher getTeacher() { |
||
624 | return teacher; |
||
625 | } |
||
626 | |||
627 | public void setTeacher(Teacher teacher) { |
||
628 | this.teacher = teacher; |
||
629 | } |
||
630 | |||
631 | public CourseUnitTurma getCourseUnitTurma() { |
||
632 | return courseUnitTurma; |
||
633 | } |
||
634 | |||
635 | public void setCourseUnitTurma(CourseUnitTurma courseUnitTurma) { |
||
636 | this.courseUnitTurma = courseUnitTurma; |
||
637 | } |
||
638 | |||
639 | public 1.5.0/docs/api/java/lang/String.html">String getCdTipologia() { |
||
640 | return cdTipologia; |
||
641 | } |
||
642 | |||
643 | public void setCdTipologia(1.5.0/docs/api/java/lang/String.html">String cdTipologia) { |
||
644 | this.cdTipologia = cdTipologia; |
||
645 | } |
||
646 | |||
647 | public 1.5.0/docs/api/java/lang/Integer.html">Integer getOcorrencias() { |
||
1338 | jmachado | 648 | return ocorrencias == null ? 0:ocorrencias; |
1313 | jmachado | 649 | } |
650 | |||
651 | public void setOcorrencias(1.5.0/docs/api/java/lang/Integer.html">Integer ocorrencias) { |
||
652 | this.ocorrencias = ocorrencias; |
||
653 | } |
||
654 | } |
||
1312 | jmachado | 655 | /** |
656 | * Os codigos de tipologia devem ser limitados a T TP OT etc |
||
657 | */ |
||
658 | public static class Tipologia |
||
659 | { |
||
1313 | jmachado | 660 | protected 1.5.0/docs/api/java/lang/String.html">String cdDocente; |
661 | protected 1.5.0/docs/api/java/lang/String.html">String cdTurma; |
||
662 | protected 1.5.0/docs/api/java/lang/String.html">String cdTipologia; |
||
663 | protected 1.5.0/docs/api/java/lang/String.html">String dsTipologia; |
||
1338 | jmachado | 664 | protected 1.5.0/docs/api/java/lang/Integer.html">Integer ocorrencias = 0; // apenas faz sentido nos sumarios. no horario ref nao. |
1312 | jmachado | 665 | |
1325 | jmachado | 666 | protected boolean use; //campo auxiliar para marcar se vai ser ou não usada nas afetacoes especificas |
667 | //por omissão apenas as que têm sumários |
||
668 | protected boolean markWarning; //campo auxiliar para marcar se vai ser ou não usada nas afetacoes especificas |
||
669 | |||
1313 | jmachado | 670 | protected boolean extra; |
671 | protected boolean horRef; |
||
1422 | jmachado | 672 | protected boolean tdocturma = false; |
1313 | jmachado | 673 | |
1422 | jmachado | 674 | public boolean isTdocturma() { |
675 | return tdocturma; |
||
676 | } |
||
677 | |||
678 | public void setTdocturma(boolean tdocturma) { |
||
679 | this.tdocturma = tdocturma; |
||
680 | } |
||
681 | |||
1325 | jmachado | 682 | public boolean isUse() { |
683 | return use; |
||
684 | } |
||
685 | |||
686 | public void setUse(boolean use) { |
||
687 | this.use = use; |
||
688 | } |
||
689 | |||
690 | public boolean isMarkWarning() { |
||
691 | return markWarning; |
||
692 | } |
||
693 | |||
694 | public void setMarkWarning(boolean markWarning) { |
||
695 | this.markWarning = markWarning; |
||
696 | } |
||
697 | |||
1312 | jmachado | 698 | public 1.5.0/docs/api/java/lang/Integer.html">Integer getOcorrencias() { |
1338 | jmachado | 699 | return ocorrencias == null ? 0:ocorrencias; |
1312 | jmachado | 700 | } |
701 | |||
1338 | jmachado | 702 | public boolean hasOcorrencias() { |
703 | return ocorrencias != null && ocorrencias > 0; |
||
704 | } |
||
705 | |||
1312 | jmachado | 706 | public void setOcorrencias(1.5.0/docs/api/java/lang/Integer.html">Integer ocorrencias) { |
707 | this.ocorrencias = ocorrencias; |
||
708 | } |
||
709 | |||
710 | public 1.5.0/docs/api/java/lang/String.html">String getCdDocente() { |
||
711 | return cdDocente; |
||
712 | } |
||
713 | |||
714 | public void setCdDocente(1.5.0/docs/api/java/lang/String.html">String cdDocente) { |
||
715 | this.cdDocente = cdDocente; |
||
716 | } |
||
717 | |||
718 | public 1.5.0/docs/api/java/lang/String.html">String getCdTurma() { |
||
719 | return cdTurma; |
||
720 | } |
||
721 | |||
722 | public void setCdTurma(1.5.0/docs/api/java/lang/String.html">String cdTurma) { |
||
723 | this.cdTurma = cdTurma; |
||
724 | } |
||
725 | |||
726 | public 1.5.0/docs/api/java/lang/String.html">String getCdTipologia() { |
||
727 | return cdTipologia; |
||
728 | } |
||
729 | |||
730 | public void setCdTipologia(1.5.0/docs/api/java/lang/String.html">String cdTipologia) { |
||
731 | this.cdTipologia = cdTipologia; |
||
732 | } |
||
733 | |||
1313 | jmachado | 734 | public 1.5.0/docs/api/java/lang/String.html">String getDsTipologia() { |
735 | return dsTipologia; |
||
736 | } |
||
737 | |||
738 | public void setDsTipologia(1.5.0/docs/api/java/lang/String.html">String dsTipologia) { |
||
739 | this.dsTipologia = dsTipologia; |
||
740 | } |
||
741 | |||
742 | public boolean isExtra() { |
||
743 | return extra; |
||
744 | } |
||
745 | |||
746 | public boolean isSumario() { |
||
747 | return ocorrencias != null && ocorrencias > 0; |
||
748 | } |
||
749 | |||
750 | public boolean isHorRef() { |
||
751 | return horRef; |
||
752 | } |
||
753 | |||
754 | |||
755 | |||
1312 | jmachado | 756 | @1.5.0/docs/api/java/lang/Override.html">Override |
757 | public boolean equals(5+0%2Fdocs%2Fapi+Object">Object o) |
||
758 | { |
||
759 | return o instanceof Tipologia && |
||
760 | ((((Tipologia)o).getCdTurma() == null && getCdTurma() == null) |
||
761 | || |
||
762 | (((Tipologia)o).getCdTurma().equals(getCdTurma()))) |
||
763 | && |
||
764 | |||
765 | ( |
||
766 | (((Tipologia)o).getCdDocente() == null && getCdDocente() == null) |
||
767 | || |
||
768 | (((Tipologia)o).getCdDocente().equals(getCdDocente()))) |
||
769 | && |
||
770 | |||
771 | ( |
||
772 | (((Tipologia)o).getCdTipologia() == null && getCdTipologia() == null) |
||
773 | || |
||
774 | (((Tipologia)o).getCdTipologia().equals(getCdTipologia()))); |
||
775 | } |
||
1313 | jmachado | 776 | |
777 | public boolean equalsIncDsFields(5+0%2Fdocs%2Fapi+Object">Object o) |
||
778 | { |
||
779 | return o instanceof Tipologia && |
||
780 | equals(o) |
||
781 | && |
||
782 | ( |
||
783 | (((Tipologia)o).getDsTipologia() == null && getDsTipologia() == null) |
||
784 | || |
||
785 | (((Tipologia)o).getDsTipologia().equals(getDsTipologia()))) |
||
786 | && |
||
787 | |||
788 | ( |
||
789 | (((Tipologia)o).getOcorrencias() == null && getOcorrencias() == null) |
||
790 | || |
||
791 | (((Tipologia)o).getOcorrencias().equals(getOcorrencias()))) |
||
792 | ; |
||
793 | } |
||
1312 | jmachado | 794 | } |
795 | |||
1326 | jmachado | 796 | public static class MergedTipologias |
797 | { |
||
798 | ArrayList<Tipologia> tipologiasWithMarkedAndUsed = new ArrayList<Tipologia>(); |
||
799 | |||
800 | public ArrayList<Tipologia> getTipologiasWithMarkedAndUsed() { |
||
801 | return tipologiasWithMarkedAndUsed; |
||
802 | } |
||
803 | |||
804 | public void setTipologiasWithMarkedAndUsed(ArrayList<Tipologia> tipologiasWithMarkedAndUsed) { |
||
805 | this.tipologiasWithMarkedAndUsed = tipologiasWithMarkedAndUsed; |
||
806 | } |
||
807 | } |
||
1312 | jmachado | 808 | public static class Tipologias |
809 | { |
||
1313 | jmachado | 810 | ArrayList<Tipologia> tipologiasHorarioReferencia = new ArrayList<Tipologia>(); |
811 | ArrayList<Tipologia> tipologiasSumarios = new ArrayList<Tipologia>(); |
||
812 | ArrayList<Tipologia> tipologiasExtraAdicionadas = new ArrayList<Tipologia>(); |
||
1326 | jmachado | 813 | ArrayList<Tipologia> tipologiasUsadas = new ArrayList<Tipologia>(); |
814 | ArrayList<Tipologia> tipologiasMarcadas = new ArrayList<Tipologia>(); |
||
1422 | jmachado | 815 | ArrayList<Tipologia> tipologiasTdocTurma = new ArrayList<Tipologia>(); |
1312 | jmachado | 816 | |
1422 | jmachado | 817 | public ArrayList<Tipologia> getTipologiasTdocTurma() { |
818 | return tipologiasTdocTurma == null ? new ArrayList<Tipologia>() : tipologiasTdocTurma; |
||
819 | } |
||
820 | |||
821 | public void setTipologiasTdocTurma(ArrayList<Tipologia> tipologiasTdocTurma) { this.tipologiasTdocTurma = tipologiasTdocTurma; } |
||
822 | |||
1312 | jmachado | 823 | public ArrayList<Tipologia> getTipologiasHorarioReferencia() { |
1333 | jmachado | 824 | |
825 | return tipologiasHorarioReferencia == null ? new ArrayList<Tipologia>() : tipologiasHorarioReferencia; |
||
826 | |||
1312 | jmachado | 827 | } |
828 | |||
829 | public void setTipologiasHorarioReferencia(ArrayList<Tipologia> tipologiasHorarioReferencia) { |
||
830 | this.tipologiasHorarioReferencia = tipologiasHorarioReferencia; |
||
831 | } |
||
832 | |||
833 | public ArrayList<Tipologia> getTipologiasSumarios() { |
||
1333 | jmachado | 834 | return tipologiasSumarios == null ? new ArrayList<Tipologia>() : tipologiasSumarios; |
1312 | jmachado | 835 | } |
836 | |||
837 | public void setTipologiasSumarios(ArrayList<Tipologia> tipologiasSumarios) { |
||
838 | this.tipologiasSumarios = tipologiasSumarios; |
||
839 | } |
||
840 | |||
841 | public ArrayList<Tipologia> getTipologiasExtraAdicionadas() { |
||
1333 | jmachado | 842 | return tipologiasExtraAdicionadas == null ? new ArrayList<Tipologia>() : tipologiasExtraAdicionadas; |
1312 | jmachado | 843 | } |
844 | |||
845 | public void setTipologiasExtraAdicionadas(ArrayList<Tipologia> tipologiasExtraAdicionadas) { |
||
846 | this.tipologiasExtraAdicionadas = tipologiasExtraAdicionadas; |
||
847 | } |
||
848 | |||
1333 | jmachado | 849 | public ArrayList<Tipologia> getTipologiasUsadas() { |
850 | return tipologiasUsadas == null ? new ArrayList<Tipologia>() : tipologiasUsadas; |
||
851 | } |
||
1326 | jmachado | 852 | |
853 | public void setTipologiasUsadas(ArrayList<Tipologia> tipologiasUsadas) { this.tipologiasUsadas = tipologiasUsadas; } |
||
854 | |||
1333 | jmachado | 855 | public ArrayList<Tipologia> getTipologiasMarcadas() { |
856 | return tipologiasMarcadas == null ? new ArrayList<Tipologia>() : tipologiasMarcadas; |
||
857 | } |
||
1326 | jmachado | 858 | |
859 | public void setTipologiasMarcadas(ArrayList<Tipologia> tipologiasMarcadas) { this.tipologiasMarcadas = tipologiasMarcadas; } |
||
860 | |||
1312 | jmachado | 861 | private static Genson getGenson(){ |
862 | Genson genson = new Genson.Builder() |
||
863 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
||
864 | .include("tipologiasExtraAdicionadas", Tipologias.class) |
||
865 | .include("tipologiasSumarios", Tipologias.class) |
||
866 | .include("tipologiasHorarioReferencia", Tipologias.class) |
||
1326 | jmachado | 867 | .include("tipologiasUsadas", Tipologias.class) |
868 | .include("tipologiasMarcadas", Tipologias.class) |
||
1422 | jmachado | 869 | .include("tipologiasTdocTurma", Tipologias.class) |
1312 | jmachado | 870 | .include("cdTipologia", Tipologia.class) |
871 | .include("cdDocente", Tipologia.class) |
||
872 | .include("cdTurma", Tipologia.class) |
||
1313 | jmachado | 873 | .include("dsTipologia",Tipologia.class) |
1312 | jmachado | 874 | .include("ocorrencias", Tipologia.class) |
1422 | jmachado | 875 | .include("tdocturma", Tipologia.class) |
1312 | jmachado | 876 | .create(); |
877 | return genson; |
||
878 | } |
||
879 | |||
1326 | jmachado | 880 | private static Genson getGensonMergedTipologiasComplete(){ |
881 | Genson genson = new Genson.Builder() |
||
882 | .exclude(5+0%2Fdocs%2Fapi+Object">Object.class) |
||
883 | |||
884 | .include("tipologiasWithMarkedAndUsed", MergedTipologias.class) |
||
885 | .include("cdTipologia", Tipologia.class) |
||
886 | .include("cdDocente", Tipologia.class) |
||
887 | .include("cdTurma", Tipologia.class) |
||
888 | .include("dsTipologia",Tipologia.class) |
||
889 | .include("ocorrencias", Tipologia.class) |
||
890 | .include("horRef", Tipologia.class) |
||
891 | .include("extra", Tipologia.class) |
||
892 | .include("use", Tipologia.class) |
||
1422 | jmachado | 893 | .include("tdocturma", Tipologia.class) |
1326 | jmachado | 894 | .include("markWarning", Tipologia.class) |
895 | .create(); |
||
896 | return genson; |
||
897 | } |
||
898 | |||
1312 | jmachado | 899 | public 1.5.0/docs/api/java/lang/String.html">String serialize() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException |
900 | { |
||
901 | Genson genson = getGenson(); |
||
902 | try { |
||
903 | return genson.serialize(this); |
||
904 | } catch (TransformationException e) { |
||
905 | throw e; |
||
906 | } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) { |
||
907 | throw e; |
||
908 | } |
||
909 | } |
||
910 | 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 |
||
911 | { |
||
912 | if(serial == null) |
||
1333 | jmachado | 913 | return new Tipologias(); |
1312 | jmachado | 914 | try { |
915 | return getGenson().deserialize(serial, Tipologias.class); |
||
916 | } catch (TransformationException e) { |
||
917 | throw e; |
||
918 | } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) { |
||
919 | throw e; |
||
920 | } |
||
921 | } |
||
922 | |||
923 | public static void main(1.5.0/docs/api/java/lang/String.html">String [] args) |
||
924 | { |
||
925 | new TestCourseUnit().testTipologias(); |
||
926 | } |
||
1313 | jmachado | 927 | |
1326 | jmachado | 928 | 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 | 929 | { |
1326 | jmachado | 930 | MergedTipologias mergedTipologias = new MergedTipologias(); |
1333 | jmachado | 931 | if(tipologias != null) |
932 | { |
||
933 | mergedTipologias.setTipologiasWithMarkedAndUsed(tipologias); |
||
934 | } |
||
1326 | jmachado | 935 | Genson genson = getGensonMergedTipologiasComplete(); |
936 | try { |
||
937 | return genson.serialize(mergedTipologias); |
||
938 | } catch (TransformationException e) { |
||
939 | throw e; |
||
940 | } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) { |
||
941 | throw e; |
||
942 | } |
||
943 | } |
||
944 | 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 |
||
945 | { |
||
946 | if(serial == null) |
||
1333 | jmachado | 947 | return new ArrayList<Tipologia>(); |
1326 | jmachado | 948 | try { |
949 | MergedTipologias mergedTipologias = getGensonMergedTipologiasComplete().deserialize(serial, MergedTipologias.class); |
||
950 | if(mergedTipologias.getTipologiasWithMarkedAndUsed() == null) |
||
951 | return new ArrayList<Tipologia>(); |
||
952 | return mergedTipologias.getTipologiasWithMarkedAndUsed(); |
||
953 | } catch (TransformationException e) { |
||
954 | throw e; |
||
955 | } catch (1.5.0/docs/api/java/io/IOException.html">IOException e) { |
||
956 | throw e; |
||
957 | } |
||
958 | } |
||
1332 | jmachado | 959 | public 1.5.0/docs/api/java/lang/String.html">String obtainMergeTipologiasSerialized() throws 1.5.0/docs/api/java/io/IOException.html">IOException, TransformationException |
960 | { |
||
961 | return serializeMergedList(obtainMergeTipologias()); |
||
962 | } |
||
1337 | jmachado | 963 | |
1387 | jmachado | 964 | |
965 | /** |
||
966 | * Junta todas as tipologias obtidas dos sumarios, horario(ref+trab) + extra |
||
967 | * e coloca todas numa lista de unicas |
||
968 | * Marca-as com isHorario, isSumario, isExtra |
||
969 | * @return |
||
970 | */ |
||
971 | |||
1326 | jmachado | 972 | public ArrayList<Tipologia> obtainMergeTipologias() |
973 | { |
||
974 | ArrayList<Tipologia> merge = new ArrayList<Tipologia>(); |
||
1315 | jmachado | 975 | if(getTipologiasSumarios() != null) |
976 | merge.addAll(getTipologiasSumarios()); |
||
1313 | jmachado | 977 | |
1315 | jmachado | 978 | if(getTipologiasHorarioReferencia() != null) |
979 | for(Tipologia tipo: getTipologiasHorarioReferencia()) |
||
1313 | jmachado | 980 | { |
1315 | jmachado | 981 | if(!merge.contains(tipo)) |
982 | { |
||
983 | merge.add(tipo); |
||
984 | } |
||
1313 | jmachado | 985 | } |
1315 | jmachado | 986 | if(getTipologiasExtraAdicionadas() != null) |
987 | for(Tipologia tipo: getTipologiasExtraAdicionadas()) |
||
1313 | jmachado | 988 | { |
1315 | jmachado | 989 | if(!merge.contains(tipo)) |
990 | { |
||
991 | merge.add(tipo); |
||
992 | } |
||
1313 | jmachado | 993 | } |
994 | for(Tipologia tipo: merge) |
||
995 | { |
||
1326 | jmachado | 996 | tipo.setMarkWarning(false); |
997 | tipo.setUse(false); |
||
1315 | jmachado | 998 | if(getTipologiasHorarioReferencia() != null && getTipologiasHorarioReferencia().contains(tipo)) |
1313 | jmachado | 999 | { |
1000 | tipo.horRef = true; |
||
1001 | } |
||
1002 | |||
1315 | jmachado | 1003 | if(getTipologiasExtraAdicionadas() != null && getTipologiasExtraAdicionadas().contains(tipo)) |
1313 | jmachado | 1004 | { |
1005 | tipo.extra = true; |
||
1006 | } |
||
1007 | } |
||
1326 | jmachado | 1008 | |
1009 | if(getTipologiasMarcadas() != null) |
||
1010 | for(Tipologia t: getTipologiasMarcadas()) |
||
1011 | { |
||
1012 | for(Tipologia tMerge: merge) |
||
1013 | { |
||
1014 | if(tMerge.equals(t)) |
||
1015 | { |
||
1016 | tMerge.setMarkWarning(true); |
||
1017 | break; |
||
1018 | } |
||
1019 | } |
||
1020 | } |
||
1021 | if(getTipologiasUsadas() != null) |
||
1022 | for(Tipologia t: getTipologiasUsadas()) |
||
1023 | { |
||
1024 | for(Tipologia tMerge: merge) |
||
1025 | { |
||
1026 | if(tMerge.equals(t)) |
||
1027 | { |
||
1028 | tMerge.setUse(true); |
||
1029 | break; |
||
1030 | } |
||
1031 | } |
||
1032 | } |
||
1422 | jmachado | 1033 | if(getTipologiasTdocTurma() != null) |
1034 | for(Tipologia t: getTipologiasTdocTurma()) |
||
1035 | { |
||
1036 | for(Tipologia tMerge: merge) |
||
1037 | { |
||
1038 | if(tMerge.equals(t)) |
||
1039 | { |
||
1040 | tMerge.setUse(true); |
||
1041 | break; |
||
1042 | } |
||
1043 | } |
||
1044 | } |
||
1313 | jmachado | 1045 | return merge; |
1046 | } |
||
1047 | |||
1387 | jmachado | 1048 | /** |
1049 | * |
||
1050 | * |
||
1051 | * @param courseUnit |
||
1052 | * @return |
||
1053 | */ |
||
1337 | jmachado | 1054 | public ArrayList<Tipologia> obtainTipologiasSimples(CourseUnit courseUnit) |
1055 | { |
||
1056 | ArrayList<Tipologia> merge = new ArrayList<Tipologia>(); |
||
1057 | |||
1058 | Map<String,Map<String,Tipologia>> docenteTurmas = new HashMap<String,Map<String,Tipologia>>(); |
||
1059 | |||
1060 | fullfillTipologiasSimples(getTipologiasSumarios(), docenteTurmas); |
||
1061 | fullfillTipologiasSimples(getTipologiasExtraAdicionadas(), docenteTurmas); |
||
1062 | fullfillTipologiasSimples(getTipologiasHorarioReferencia(), docenteTurmas); |
||
1063 | fullfillTipologiasSimples(getTipologiasMarcadas(), docenteTurmas); |
||
1064 | fullfillTipologiasSimples(getTipologiasUsadas(), docenteTurmas); |
||
1422 | jmachado | 1065 | fullfillTipologiasSimples(getTipologiasTdocTurma(), docenteTurmas); |
1337 | jmachado | 1066 | |
1067 | |||
1068 | if(docenteTurmas.size() == 0) |
||
1069 | { |
||
1070 | //NAO Há sumários vamos associar todos os docentes a todas as turmas |
||
1071 | if(courseUnit.getTurmas() != null && courseUnit.getTeachers() != null) |
||
1072 | { |
||
1073 | for(CourseUnitTurma turma: courseUnit.getTurmas()) |
||
1074 | { |
||
1075 | for(Teacher t : courseUnit.getTeachers()) |
||
1076 | { |
||
1077 | Tipologia simples = new Tipologia(); |
||
1078 | simples.setMarkWarning(true); |
||
1387 | jmachado | 1079 | //simples.setUse(true); |
1337 | jmachado | 1080 | simples.setCdDocente(""+t.getSigesCode()); |
1081 | simples.setCdTurma(turma.getTurma()); |
||
1082 | simples.setCdTipologia(Globals.BACO_TIPOLOGIA_SIMPLES_VIRTUAL_CODE); |
||
1083 | simples.setDsTipologia(Globals.BACO_TIPOLOGIA_SIMPLES_DS); |
||
1084 | merge.add(simples); |
||
1085 | } |
||
1086 | } |
||
1087 | } |
||
1088 | } |
||
1089 | else |
||
1090 | { |
||
1091 | for(1.5.0/docs/api/java/util/Map.html">Map.Entry<String,Map<String,Tipologia>> docentes: docenteTurmas.entrySet()) |
||
1092 | { |
||
1093 | for(Tipologia tipologia: docentes.getValue().values()) |
||
1094 | { |
||
1095 | merge.add(tipologia); |
||
1096 | } |
||
1097 | } |
||
1098 | } |
||
1099 | return merge; |
||
1100 | } |
||
1101 | |||
1387 | jmachado | 1102 | /** |
1103 | * Cria uma tipologia Simples para cada par Docente-Turma nesta cadeira olhando para |
||
1104 | * todas as tipologias existentes, uma vez que o Baco não guarda associações entre |
||
1105 | * Docentes e Turmas isso será retirado das tipologias importadas |
||
1106 | * |
||
1107 | * @param tipologias |
||
1108 | * @param docenteTurmas |
||
1109 | */ |
||
1337 | jmachado | 1110 | private void fullfillTipologiasSimples(ArrayList<Tipologia> tipologias, Map<String, Map<String, Tipologia>> docenteTurmas) { |
1111 | if(tipologias != null) |
||
1112 | for(Tipologia tipo: tipologias) |
||
1113 | { |
||
1114 | Map<String,Tipologia> turmasDocente = docenteTurmas.get(tipo.getCdDocente()); |
||
1115 | if(turmasDocente == null) |
||
1116 | turmasDocente = new HashMap<String,Tipologia>(); |
||
1117 | docenteTurmas.put(tipo.getCdDocente(),turmasDocente); |
||
1118 | Tipologia simples = turmasDocente.get(tipo.getCdTurma()); |
||
1119 | if(simples==null) |
||
1120 | { |
||
1121 | simples = new Tipologia(); |
||
1122 | simples.setCdDocente(tipo.getCdDocente()); |
||
1123 | simples.setCdTurma(tipo.getCdTurma()); |
||
1124 | simples.setCdTipologia(Globals.BACO_TIPOLOGIA_SIMPLES_VIRTUAL_CODE); |
||
1125 | simples.setDsTipologia(Globals.BACO_TIPOLOGIA_SIMPLES_DS); |
||
1387 | jmachado | 1126 | //simples.setUse(true);//TODAS USADAS |
1338 | jmachado | 1127 | if(tipo.hasOcorrencias()) |
1337 | jmachado | 1128 | { |
1129 | simples.setOcorrencias(tipo.getOcorrencias()); |
||
1130 | } |
||
1131 | turmasDocente.put(tipo.getCdTurma(),simples); |
||
1422 | jmachado | 1132 | if(tipo.isTdocturma()) |
1133 | simples.setTdocturma(true); |
||
1337 | jmachado | 1134 | } |
1387 | jmachado | 1135 | else if(tipo.hasOcorrencias()) |
1337 | jmachado | 1136 | { |
1338 | jmachado | 1137 | if(simples.getOcorrencias() == null) |
1138 | simples.setOcorrencias(0); |
||
1337 | jmachado | 1139 | simples.setOcorrencias(simples.getOcorrencias()+tipo.getOcorrencias()); |
1422 | jmachado | 1140 | if(tipo.isTdocturma()) |
1141 | simples.setTdocturma(true); |
||
1337 | jmachado | 1142 | } |
1143 | |||
1144 | } |
||
1145 | } |
||
1146 | |||
1147 | |||
1312 | jmachado | 1148 | } |
1149 | |||
1150 | |||
1546 | jmachado | 1151 | /**Services**/ |
1312 | jmachado | 1152 | |
1546 | jmachado | 1153 | /** |
1154 | * Require Open Transaction |
||
1155 | * @return 1, 2, 3, 4 |
||
1156 | */ |
||
1157 | public int getAnoPlanoFromStudiesPlan() |
||
1158 | { |
||
1159 | CourseImpl courseImpl = (CourseImpl) DaoFactory.getCourseDaoImpl().narrow(getCourse()); |
||
1160 | return courseImpl.getUnidadeAnoPlano(getSemestre(),getCode()); |
||
1161 | } |
||
1312 | jmachado | 1162 | |
1546 | jmachado | 1163 | /** |
1164 | * Require Open Transaction |
||
1165 | * @return S1, .., S8, T1 .. T8, A1 .. A4 |
||
1166 | */ |
||
1167 | public 1.5.0/docs/api/java/lang/String.html">String getPeriodoPlanoFromStudiesPlan() |
||
1168 | { |
||
1169 | CourseImpl courseImpl = (CourseImpl) DaoFactory.getCourseDaoImpl().narrow(getCourse()); |
||
1547 | jmachado | 1170 | return courseImpl.getUnidadePeriodoPlano(getSemestre(), getCode()); |
1546 | jmachado | 1171 | } |
1312 | jmachado | 1172 | |
1546 | jmachado | 1173 | /** |
1174 | * Require Open Transaction |
||
1175 | * @return S1 = 1, S2 = 2,S3 = 3,S4 = 4 ...T1 e T2 = 1, T2 e T3 = 2, T4 e T5 = 3 ... |
||
1176 | */ |
||
1177 | public int getSemestrePlanoConvertido() |
||
1178 | { |
||
1179 | CourseImpl courseImpl = (CourseImpl) DaoFactory.getCourseDaoImpl().narrow(getCourse()); |
||
1547 | jmachado | 1180 | return courseImpl.getUnidadeSemestrePlanoConvertido(getSemestre(), getCode()); |
1546 | jmachado | 1181 | } |
1182 | |||
1183 | /** |
||
1184 | * Require Open Transaction |
||
1185 | * @return S1 = 1, S2 = 2, S3 = 1, S4 = 2 ... T1 e T2 = 1, T2 e T3 = 2, T4 e T5 = 1, T6 e T7 = 2 |
||
1186 | */ |
||
1187 | public int getSemestrePlanoAbsoluto() |
||
1188 | { |
||
1547 | jmachado | 1189 | 1.5.0/docs/api/java/lang/String.html">String id = getSemestre(); |
1190 | if(id.equals("S1")) |
||
1191 | return 1; |
||
1192 | else if(id.equals("S2")) |
||
1193 | return 2; |
||
1194 | else if(id.equals("A")) |
||
1195 | return -1; |
||
1546 | jmachado | 1196 | |
1547 | jmachado | 1197 | else if(id.equals("T1")) |
1198 | return 1; |
||
1199 | else if(id.equals("T2")) |
||
1200 | return 1; |
||
1201 | else if(id.equals("T3")) |
||
1202 | return 2; |
||
1203 | else if(id.equals("T4")) |
||
1204 | return 2; |
||
1546 | jmachado | 1205 | |
1206 | |||
1547 | jmachado | 1207 | return -1; |
1546 | jmachado | 1208 | |
1547 | jmachado | 1209 | } |
1546 | jmachado | 1210 | |
1547 | jmachado | 1211 | |
112 | jmachado | 1212 | } |