Rev 1821 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
114 | jmachado | 1 | package pt.estgp.estgweb.domain; |
2 | |||
728 | jmachado | 3 | import jomm.utils.StringsUtils; |
4 | import org.apache.log4j.Logger; |
||
1817 | jmachado | 5 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
1814 | jmachado | 6 | import pt.estgp.estgweb.utils.Globals; |
223 | jmachado | 7 | import pt.estgp.estgweb.utils.RoleManager; |
202 | jmachado | 8 | import pt.utl.ist.berserk.logic.serviceManager.IServiceManager; |
9 | import pt.utl.ist.berserk.logic.serviceManager.ServiceManager; |
||
114 | jmachado | 10 | |
728 | jmachado | 11 | import java.util.ArrayList; |
1780 | jmachado | 12 | import java.util.HashMap; |
214 | jmachado | 13 | import java.util.List; |
787 | jmachado | 14 | import java.util.Map; |
202 | jmachado | 15 | |
114 | jmachado | 16 | /** |
17 | * @author Jorge Machado |
||
18 | * @date 28/Fev/2008 |
||
19 | * @time 12:51:32 |
||
20 | * @see pt.estgp.estgweb |
||
21 | */ |
||
22 | public class TeacherImpl extends Teacher |
||
23 | { |
||
24 | |||
25 | public static final 1.5.0/docs/api/java/lang/String.html">String TEACHER_ROLE = Globals.TEACHER_ROLE; |
||
26 | |||
202 | jmachado | 27 | public 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(TeacherImpl.class); |
114 | jmachado | 28 | |
214 | jmachado | 29 | private List<CourseUnit> teachedUnitsView = null; |
253 | jmachado | 30 | private List<CourseUnit> teachedUnitsCurrentYearView = null; |
215 | jmachado | 31 | private List<Course> teachedCoursesView = null; |
253 | jmachado | 32 | private List<Course> teachedCoursesCurrentYearView = null; |
202 | jmachado | 33 | |
215 | jmachado | 34 | public TeacherImpl() |
35 | { |
||
36 | setScholarDegree(Globals.PROFILE_SCHOLAR_DEGREE_SUPERIOR); |
||
37 | } |
||
38 | |||
343 | jmachado | 39 | public 1.5.0/docs/api/java/lang/String.html">String getManagedRole() |
40 | { |
||
41 | List<String> roles = new ArrayList<String>(); |
||
42 | if(getDirectorCourses() != null && getDirectorCourses().size() > 0) |
||
43 | roles.add(Globals.COURSE_DIRECTOR_ROLE); |
||
44 | if(getCoordinatorCourses() != null && getCoordinatorCourses().size() > 0) |
||
45 | roles.add(Globals.COURSE_COORDINATOR_ROLE); |
||
46 | roles.add(TEACHER_ROLE); |
||
47 | return RoleManager.getSerialRoles(roles); |
||
114 | jmachado | 48 | } |
146 | jmachado | 49 | |
215 | jmachado | 50 | public List<Course> getTeachedCoursesView() |
51 | { |
||
52 | getTeachedUnitsView(); |
||
53 | return teachedCoursesView; |
||
54 | } |
||
254 | jmachado | 55 | |
56 | public List<Course> getTeachedCoursesCurrenYearView() |
||
57 | { |
||
58 | getTeachedUnitsCurrentYearView(); |
||
59 | return teachedCoursesCurrentYearView; |
||
60 | } |
||
266 | jmachado | 61 | |
62 | public List<CourseUnit> getTeachedUnitsViewS1() |
||
63 | { |
||
64 | return getUnitsSemestre("S1",getTeachedUnitsView()); |
||
65 | } |
||
66 | public List<CourseUnit> getTeachedUnitsViewS2() |
||
67 | { |
||
68 | return getUnitsSemestre("S2",getTeachedUnitsView()); |
||
69 | } |
||
728 | jmachado | 70 | public List<CourseUnit> getTeachedUnitsViewA() |
71 | { |
||
72 | return getUnitsSemestre("A",getTeachedUnitsView()); |
||
73 | } |
||
1040 | jmachado | 74 | |
75 | public List<CourseUnit> getTeachedUnitsViewT1() |
||
76 | { |
||
77 | return getUnitsSemestre("T1",getTeachedUnitsView()); |
||
78 | } |
||
79 | |||
80 | public List<CourseUnit> getTeachedUnitsViewT2() |
||
81 | { |
||
82 | return getUnitsSemestre("T2",getTeachedUnitsView()); |
||
83 | } |
||
84 | |||
85 | public List<CourseUnit> getTeachedUnitsViewT3() |
||
86 | { |
||
87 | return getUnitsSemestre("T3",getTeachedUnitsView()); |
||
88 | } |
||
89 | |||
90 | public List<CourseUnit> getTeachedUnitsViewT4() |
||
91 | { |
||
92 | return getUnitsSemestre("T4",getTeachedUnitsView()); |
||
93 | } |
||
94 | |||
214 | jmachado | 95 | public List<CourseUnit> getTeachedUnitsView() |
202 | jmachado | 96 | { |
97 | if(teachedUnitsView == null) |
||
98 | { |
||
215 | jmachado | 99 | teachedCoursesView = new ArrayList<Course>(); |
202 | jmachado | 100 | try |
101 | { |
||
102 | IServiceManager sm = ServiceManager.getInstance(); |
||
103 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"}; |
||
104 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()}; |
||
214 | jmachado | 105 | teachedUnitsView = (List<CourseUnit>) sm.execute(null, "LoadTeachedUnits", args, names); |
202 | jmachado | 106 | if(teachedUnitsView == null) |
214 | jmachado | 107 | teachedUnitsView = new ArrayList<CourseUnit>(); |
215 | jmachado | 108 | for(CourseUnit c: teachedUnitsView) |
109 | { |
||
110 | if(!teachedCoursesView.contains(c.getCourse())) |
||
111 | { |
||
112 | teachedCoursesView.add(c.getCourse()); |
||
113 | } |
||
114 | } |
||
202 | jmachado | 115 | } |
116 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
117 | { |
||
118 | logger.error(e,e); |
||
119 | } |
||
120 | } |
||
121 | return teachedUnitsView; |
||
122 | } |
||
123 | |||
266 | jmachado | 124 | public List<CourseUnit> getTeachedUnitsCurrentYearViewS1() |
125 | { |
||
126 | return getUnitsSemestre("S1",getTeachedUnitsCurrentYearView()); |
||
127 | } |
||
128 | public List<CourseUnit> getTeachedUnitsCurrentYearViewS2() |
||
129 | { |
||
130 | return getUnitsSemestre("S2",getTeachedUnitsCurrentYearView()); |
||
131 | } |
||
728 | jmachado | 132 | public List<CourseUnit> getTeachedUnitsCurrentYearViewA() |
133 | { |
||
134 | return getUnitsSemestre("A",getTeachedUnitsCurrentYearView()); |
||
135 | } |
||
787 | jmachado | 136 | |
1040 | jmachado | 137 | public List<CourseUnit> getTeachedUnitsCurrentYearViewT1() |
138 | { |
||
139 | return getUnitsSemestre("T1",getTeachedUnitsCurrentYearView()); |
||
140 | } |
||
787 | jmachado | 141 | |
1040 | jmachado | 142 | public List<CourseUnit> getTeachedUnitsCurrentYearViewT2() |
143 | { |
||
144 | return getUnitsSemestre("T2",getTeachedUnitsCurrentYearView()); |
||
145 | } |
||
787 | jmachado | 146 | |
1040 | jmachado | 147 | public List<CourseUnit> getTeachedUnitsCurrentYearViewT3() |
148 | { |
||
149 | return getUnitsSemestre("T3",getTeachedUnitsCurrentYearView()); |
||
150 | } |
||
151 | |||
152 | public List<CourseUnit> getTeachedUnitsCurrentYearViewT4() |
||
153 | { |
||
154 | return getUnitsSemestre("T4",getTeachedUnitsCurrentYearView()); |
||
155 | } |
||
156 | |||
157 | |||
158 | |||
787 | jmachado | 159 | public List<CourseUnit> getTeachedUnitsViewS1(1.5.0/docs/api/java/lang/String.html">String year) |
160 | { |
||
161 | return getUnitsSemestre("S1",getTeachedUnitsView(year)); |
||
162 | } |
||
163 | public List<CourseUnit> getTeachedUnitsViewS2(1.5.0/docs/api/java/lang/String.html">String year) |
||
164 | { |
||
165 | return getUnitsSemestre("S2",getTeachedUnitsView(year)); |
||
166 | } |
||
167 | public List<CourseUnit> getTeachedUnitsViewA(1.5.0/docs/api/java/lang/String.html">String year) |
||
168 | { |
||
169 | return getUnitsSemestre("A",getTeachedUnitsView(year)); |
||
170 | } |
||
171 | |||
1040 | jmachado | 172 | public List<CourseUnit> getTeachedUnitsViewT1(1.5.0/docs/api/java/lang/String.html">String year) |
173 | { |
||
174 | return getUnitsSemestre("T1",getTeachedUnitsView(year)); |
||
175 | } |
||
176 | |||
177 | public List<CourseUnit> getTeachedUnitsViewT2(1.5.0/docs/api/java/lang/String.html">String year) |
||
178 | { |
||
179 | return getUnitsSemestre("T2",getTeachedUnitsView(year)); |
||
180 | } |
||
181 | |||
182 | public List<CourseUnit> getTeachedUnitsViewT3(1.5.0/docs/api/java/lang/String.html">String year) |
||
183 | { |
||
184 | return getUnitsSemestre("T3",getTeachedUnitsView(year)); |
||
185 | } |
||
186 | |||
187 | public List<CourseUnit> getTeachedUnitsViewT4(1.5.0/docs/api/java/lang/String.html">String year) |
||
188 | { |
||
189 | return getUnitsSemestre("T4",getTeachedUnitsView(year)); |
||
190 | } |
||
191 | |||
787 | jmachado | 192 | Map<String,List<CourseUnit>> teachedUnitsYear = new HashMap<String,List<CourseUnit>>(); |
193 | Map<String,List<Course>> teachedCourseYear = new HashMap<String,List<Course>>(); |
||
194 | |||
195 | public List<CourseUnit> getTeachedUnitsView(1.5.0/docs/api/java/lang/String.html">String year) |
||
196 | { |
||
197 | List<CourseUnit> cuYear = teachedUnitsYear.get(year); |
||
198 | if(cuYear == null) |
||
199 | { |
||
200 | List<Course> lc = new ArrayList<Course>(); |
||
201 | teachedCourseYear.put(year,lc); |
||
202 | try |
||
203 | { |
||
204 | IServiceManager sm = ServiceManager.getInstance(); |
||
205 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable","year"}; |
||
206 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId(),year}; |
||
207 | cuYear = (List<CourseUnit>) sm.execute(null, "LoadTeachedUnitsYear", args, names); |
||
208 | |||
209 | if(cuYear == null) |
||
210 | cuYear = new ArrayList<CourseUnit>(); |
||
211 | for(CourseUnit c: cuYear) |
||
212 | { |
||
213 | if(!lc.contains(c.getCourse())) |
||
214 | { |
||
215 | lc.add(c.getCourse()); |
||
216 | } |
||
217 | } |
||
218 | teachedUnitsYear.put(year,cuYear); |
||
219 | } |
||
220 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
221 | { |
||
222 | logger.error(e,e); |
||
223 | } |
||
224 | } |
||
788 | jmachado | 225 | return cuYear; |
787 | jmachado | 226 | } |
227 | |||
228 | |||
253 | jmachado | 229 | public List<CourseUnit> getTeachedUnitsCurrentYearView() |
230 | { |
||
231 | if(teachedUnitsCurrentYearView == null) |
||
232 | { |
||
233 | teachedCoursesCurrentYearView = new ArrayList<Course>(); |
||
234 | try |
||
235 | { |
||
236 | IServiceManager sm = ServiceManager.getInstance(); |
||
237 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"}; |
||
238 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()}; |
||
239 | teachedUnitsCurrentYearView = (List<CourseUnit>) sm.execute(null, "LoadTeachedUnitsCurrentYear", args, names); |
||
240 | if(teachedUnitsCurrentYearView == null) |
||
241 | teachedUnitsCurrentYearView = new ArrayList<CourseUnit>(); |
||
242 | for(CourseUnit c: teachedUnitsCurrentYearView) |
||
243 | { |
||
244 | if(!teachedCoursesCurrentYearView.contains(c.getCourse())) |
||
245 | { |
||
246 | teachedCoursesCurrentYearView.add(c.getCourse()); |
||
247 | } |
||
248 | } |
||
249 | } |
||
250 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
251 | { |
||
252 | logger.error(e,e); |
||
253 | } |
||
254 | } |
||
255 | return teachedUnitsCurrentYearView; |
||
256 | } |
||
257 | |||
204 | jmachado | 258 | public boolean hasCourseUnit(long id) |
259 | { |
||
260 | return hasCourseUnit(id,false); |
||
261 | } |
||
262 | |||
146 | jmachado | 263 | public boolean hasCourseUnit(CourseUnit courseUnit) |
264 | { |
||
204 | jmachado | 265 | return hasCourseUnit(courseUnit.getId(),false); |
202 | jmachado | 266 | } |
267 | |||
1670 | jmachado | 268 | |
204 | jmachado | 269 | public boolean hasCourseUnit(long id, boolean transaction) |
202 | jmachado | 270 | { |
214 | jmachado | 271 | List<CourseUnit> cUnits; |
202 | jmachado | 272 | if(transaction) |
214 | jmachado | 273 | cUnits = new ArrayList<CourseUnit>(getTeachedUnits()); |
202 | jmachado | 274 | else |
275 | cUnits = getTeachedUnitsView(); |
||
276 | if(cUnits == null) |
||
146 | jmachado | 277 | return false; |
202 | jmachado | 278 | for(CourseUnit c: cUnits) |
146 | jmachado | 279 | { |
204 | jmachado | 280 | if(c.getId() == id) |
146 | jmachado | 281 | return true; |
282 | } |
||
283 | return false; |
||
284 | } |
||
223 | jmachado | 285 | |
225 | jmachado | 286 | public void removeUnitLocaly(CourseUnit unit) |
223 | jmachado | 287 | { |
225 | jmachado | 288 | setLocalRemovedTeachedUnits(StringsUtils.addElement(getLocalRemovedTeachedUnits(),"" + unit.getId(),",")); |
996 | jmachado | 289 | |
290 | //todo novo |
||
291 | setLocalTeachedUnits(StringsUtils.removeElement(getLocalTeachedUnits(),"" + unit.getId(),",")); |
||
223 | jmachado | 292 | } |
293 | |||
225 | jmachado | 294 | public void addUnitLocaly(CourseUnit unit) |
223 | jmachado | 295 | { |
225 | jmachado | 296 | setLocalRemovedTeachedUnits(StringsUtils.removeElement(getLocalRemovedTeachedUnits(),"" + unit.getId(),",")); |
996 | jmachado | 297 | |
298 | //todo novo |
||
299 | setLocalTeachedUnits(StringsUtils.removeElement(getLocalTeachedUnits(),"" + unit.getId(),",")); |
||
300 | setLocalTeachedUnits(StringsUtils.addElement(getLocalTeachedUnits(),"" + unit.getId(),",")); |
||
223 | jmachado | 301 | } |
302 | |||
225 | jmachado | 303 | public boolean isLocalRemovedUnit(CourseUnit unit) |
223 | jmachado | 304 | { |
225 | jmachado | 305 | return StringsUtils.hasElement(getLocalRemovedTeachedUnits(),"" + unit.getId(),","); |
223 | jmachado | 306 | } |
996 | jmachado | 307 | |
308 | public boolean isLocalUnit(CourseUnit unit) |
||
309 | { |
||
310 | return StringsUtils.hasElement(getLocalTeachedUnits(),""+unit.getId(),","); |
||
311 | } |
||
1699 | jmachado | 312 | |
1817 | jmachado | 313 | /** |
314 | * |
||
315 | * @return all roles type course comission from user roles and validationRoles from coordinated courses |
||
316 | * where user is main coordinator |
||
1821 | jmachado | 317 | * APENAS CURSOS ATIVOS STATUS = TRUE |
1817 | jmachado | 318 | */ |
1699 | jmachado | 319 | public List<String> obtainCourseComissionsAndCoordinationsRoles() |
320 | { |
||
321 | List<String> comissionsRoles = new ArrayList<String>(); |
||
322 | for(1.5.0/docs/api/java/lang/String.html">String role: getRolesList()) |
||
323 | { |
||
324 | if(role.startsWith(Globals.COURSE_COMMISSION_PROGRAMS_ROLES_PREFIX)) |
||
325 | comissionsRoles.add(role); |
||
326 | } |
||
327 | for(Course coordinated : getCoordinatorCourses()) |
||
328 | { |
||
1821 | jmachado | 329 | if(coordinated.isStatus() && coordinated.getValidationRole() != null && coordinated.getValidationRole().trim().length() > 0) |
1699 | jmachado | 330 | { |
331 | if(!comissionsRoles.contains(coordinated.getValidationRole())) |
||
332 | comissionsRoles.add(coordinated.getValidationRole()); |
||
333 | } |
||
334 | } |
||
1821 | jmachado | 335 | //System.out.println("Roles for: " + getName()); |
336 | /*for(String role: comissionsRoles) |
||
1818 | jmachado | 337 | { |
338 | System.out.println(role); |
||
1821 | jmachado | 339 | }*/ |
1699 | jmachado | 340 | return comissionsRoles; |
341 | } |
||
1701 | jmachado | 342 | |
1817 | jmachado | 343 | |
344 | /** |
||
345 | * |
||
346 | * @return all courses comission from user roles and validationRoles from coordinated courses |
||
347 | * where user is main coordinator |
||
348 | * @require opened transaction |
||
349 | * todo usar isto para obter coordenações |
||
350 | */ |
||
351 | public List<Course> obtainCourseComissionsAndCoordinations() |
||
352 | { |
||
353 | return DaoFactory.getCourseDaoImpl().findActiveCoursesCoordinationsOrCommissions(this); |
||
354 | } |
||
355 | |||
1701 | jmachado | 356 | public boolean hasCoordinationsOrBelongToCourseCommissions() |
357 | { |
||
358 | return obtainCourseComissionsAndCoordinationsRoles().size() > 0; |
||
359 | } |
||
1780 | jmachado | 360 | |
361 | private List<String> excludedGenericJsonMethodsWithOpenTransactions = null; |
||
362 | |||
363 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
364 | public synchronized List<String> getJsonExcludedProperties() { |
||
365 | if(excludedGenericJsonMethodsWithOpenTransactions == null) |
||
366 | { |
||
367 | excludedGenericJsonMethodsWithOpenTransactions = new ArrayList<String>(); |
||
368 | searchMyMethodsStartingWith("teachedUnits",excludedGenericJsonMethodsWithOpenTransactions); |
||
369 | } |
||
370 | return excludedGenericJsonMethodsWithOpenTransactions; |
||
371 | } |
||
372 | |||
373 | |||
114 | jmachado | 374 | } |