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