Rev 1040 | 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; |
||
114 | jmachado | 5 | import pt.estgp.estgweb.Globals; |
223 | jmachado | 6 | import pt.estgp.estgweb.utils.RoleManager; |
202 | jmachado | 7 | import pt.utl.ist.berserk.logic.serviceManager.IServiceManager; |
8 | import pt.utl.ist.berserk.logic.serviceManager.ServiceManager; |
||
114 | jmachado | 9 | |
728 | jmachado | 10 | import java.util.ArrayList; |
214 | jmachado | 11 | import java.util.List; |
787 | jmachado | 12 | import java.util.Map; |
13 | import java.util.HashMap; |
||
202 | jmachado | 14 | |
114 | jmachado | 15 | /** |
16 | * @author Jorge Machado |
||
17 | * @date 28/Fev/2008 |
||
18 | * @time 12:51:32 |
||
19 | * @see pt.estgp.estgweb |
||
20 | */ |
||
21 | public class TeacherImpl extends Teacher |
||
22 | { |
||
23 | |||
24 | public static final 1.5.0/docs/api/java/lang/String.html">String TEACHER_ROLE = Globals.TEACHER_ROLE; |
||
25 | |||
202 | jmachado | 26 | 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 | 27 | |
214 | jmachado | 28 | private List<CourseUnit> teachedUnitsView = null; |
253 | jmachado | 29 | private List<CourseUnit> teachedUnitsCurrentYearView = null; |
215 | jmachado | 30 | private List<Course> teachedCoursesView = null; |
253 | jmachado | 31 | private List<Course> teachedCoursesCurrentYearView = null; |
202 | jmachado | 32 | |
215 | jmachado | 33 | public TeacherImpl() |
34 | { |
||
35 | setScholarDegree(Globals.PROFILE_SCHOLAR_DEGREE_SUPERIOR); |
||
36 | } |
||
37 | |||
343 | jmachado | 38 | public 1.5.0/docs/api/java/lang/String.html">String getManagedRole() |
39 | { |
||
40 | List<String> roles = new ArrayList<String>(); |
||
41 | if(getDirectorCourses() != null && getDirectorCourses().size() > 0) |
||
42 | roles.add(Globals.COURSE_DIRECTOR_ROLE); |
||
43 | if(getCoordinatorCourses() != null && getCoordinatorCourses().size() > 0) |
||
44 | roles.add(Globals.COURSE_COORDINATOR_ROLE); |
||
45 | roles.add(TEACHER_ROLE); |
||
46 | return RoleManager.getSerialRoles(roles); |
||
114 | jmachado | 47 | } |
146 | jmachado | 48 | |
215 | jmachado | 49 | public List<Course> getTeachedCoursesView() |
50 | { |
||
51 | getTeachedUnitsView(); |
||
52 | return teachedCoursesView; |
||
53 | } |
||
254 | jmachado | 54 | |
55 | public List<Course> getTeachedCoursesCurrenYearView() |
||
56 | { |
||
57 | getTeachedUnitsCurrentYearView(); |
||
58 | return teachedCoursesCurrentYearView; |
||
59 | } |
||
266 | jmachado | 60 | |
61 | public List<CourseUnit> getTeachedUnitsViewS1() |
||
62 | { |
||
63 | return getUnitsSemestre("S1",getTeachedUnitsView()); |
||
64 | } |
||
65 | public List<CourseUnit> getTeachedUnitsViewS2() |
||
66 | { |
||
67 | return getUnitsSemestre("S2",getTeachedUnitsView()); |
||
68 | } |
||
728 | jmachado | 69 | public List<CourseUnit> getTeachedUnitsViewA() |
70 | { |
||
71 | return getUnitsSemestre("A",getTeachedUnitsView()); |
||
72 | } |
||
1040 | jmachado | 73 | |
74 | public List<CourseUnit> getTeachedUnitsViewT1() |
||
75 | { |
||
76 | return getUnitsSemestre("T1",getTeachedUnitsView()); |
||
77 | } |
||
78 | |||
79 | public List<CourseUnit> getTeachedUnitsViewT2() |
||
80 | { |
||
81 | return getUnitsSemestre("T2",getTeachedUnitsView()); |
||
82 | } |
||
83 | |||
84 | public List<CourseUnit> getTeachedUnitsViewT3() |
||
85 | { |
||
86 | return getUnitsSemestre("T3",getTeachedUnitsView()); |
||
87 | } |
||
88 | |||
89 | public List<CourseUnit> getTeachedUnitsViewT4() |
||
90 | { |
||
91 | return getUnitsSemestre("T4",getTeachedUnitsView()); |
||
92 | } |
||
93 | |||
214 | jmachado | 94 | public List<CourseUnit> getTeachedUnitsView() |
202 | jmachado | 95 | { |
96 | if(teachedUnitsView == null) |
||
97 | { |
||
215 | jmachado | 98 | teachedCoursesView = new ArrayList<Course>(); |
202 | jmachado | 99 | try |
100 | { |
||
101 | IServiceManager sm = ServiceManager.getInstance(); |
||
102 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"}; |
||
103 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()}; |
||
214 | jmachado | 104 | teachedUnitsView = (List<CourseUnit>) sm.execute(null, "LoadTeachedUnits", args, names); |
202 | jmachado | 105 | if(teachedUnitsView == null) |
214 | jmachado | 106 | teachedUnitsView = new ArrayList<CourseUnit>(); |
215 | jmachado | 107 | for(CourseUnit c: teachedUnitsView) |
108 | { |
||
109 | if(!teachedCoursesView.contains(c.getCourse())) |
||
110 | { |
||
111 | teachedCoursesView.add(c.getCourse()); |
||
112 | } |
||
113 | } |
||
202 | jmachado | 114 | } |
115 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
116 | { |
||
117 | logger.error(e,e); |
||
118 | } |
||
119 | } |
||
120 | return teachedUnitsView; |
||
121 | } |
||
122 | |||
266 | jmachado | 123 | public List<CourseUnit> getTeachedUnitsCurrentYearViewS1() |
124 | { |
||
125 | return getUnitsSemestre("S1",getTeachedUnitsCurrentYearView()); |
||
126 | } |
||
127 | public List<CourseUnit> getTeachedUnitsCurrentYearViewS2() |
||
128 | { |
||
129 | return getUnitsSemestre("S2",getTeachedUnitsCurrentYearView()); |
||
130 | } |
||
728 | jmachado | 131 | public List<CourseUnit> getTeachedUnitsCurrentYearViewA() |
132 | { |
||
133 | return getUnitsSemestre("A",getTeachedUnitsCurrentYearView()); |
||
134 | } |
||
787 | jmachado | 135 | |
1040 | jmachado | 136 | public List<CourseUnit> getTeachedUnitsCurrentYearViewT1() |
137 | { |
||
138 | return getUnitsSemestre("T1",getTeachedUnitsCurrentYearView()); |
||
139 | } |
||
787 | jmachado | 140 | |
1040 | jmachado | 141 | public List<CourseUnit> getTeachedUnitsCurrentYearViewT2() |
142 | { |
||
143 | return getUnitsSemestre("T2",getTeachedUnitsCurrentYearView()); |
||
144 | } |
||
787 | jmachado | 145 | |
1040 | jmachado | 146 | public List<CourseUnit> getTeachedUnitsCurrentYearViewT3() |
147 | { |
||
148 | return getUnitsSemestre("T3",getTeachedUnitsCurrentYearView()); |
||
149 | } |
||
150 | |||
151 | public List<CourseUnit> getTeachedUnitsCurrentYearViewT4() |
||
152 | { |
||
153 | return getUnitsSemestre("T4",getTeachedUnitsCurrentYearView()); |
||
154 | } |
||
155 | |||
156 | |||
157 | |||
787 | jmachado | 158 | public List<CourseUnit> getTeachedUnitsViewS1(1.5.0/docs/api/java/lang/String.html">String year) |
159 | { |
||
160 | return getUnitsSemestre("S1",getTeachedUnitsView(year)); |
||
161 | } |
||
162 | public List<CourseUnit> getTeachedUnitsViewS2(1.5.0/docs/api/java/lang/String.html">String year) |
||
163 | { |
||
164 | return getUnitsSemestre("S2",getTeachedUnitsView(year)); |
||
165 | } |
||
166 | public List<CourseUnit> getTeachedUnitsViewA(1.5.0/docs/api/java/lang/String.html">String year) |
||
167 | { |
||
168 | return getUnitsSemestre("A",getTeachedUnitsView(year)); |
||
169 | } |
||
170 | |||
1040 | jmachado | 171 | public List<CourseUnit> getTeachedUnitsViewT1(1.5.0/docs/api/java/lang/String.html">String year) |
172 | { |
||
173 | return getUnitsSemestre("T1",getTeachedUnitsView(year)); |
||
174 | } |
||
175 | |||
176 | public List<CourseUnit> getTeachedUnitsViewT2(1.5.0/docs/api/java/lang/String.html">String year) |
||
177 | { |
||
178 | return getUnitsSemestre("T2",getTeachedUnitsView(year)); |
||
179 | } |
||
180 | |||
181 | public List<CourseUnit> getTeachedUnitsViewT3(1.5.0/docs/api/java/lang/String.html">String year) |
||
182 | { |
||
183 | return getUnitsSemestre("T3",getTeachedUnitsView(year)); |
||
184 | } |
||
185 | |||
186 | public List<CourseUnit> getTeachedUnitsViewT4(1.5.0/docs/api/java/lang/String.html">String year) |
||
187 | { |
||
188 | return getUnitsSemestre("T4",getTeachedUnitsView(year)); |
||
189 | } |
||
190 | |||
787 | jmachado | 191 | Map<String,List<CourseUnit>> teachedUnitsYear = new HashMap<String,List<CourseUnit>>(); |
192 | Map<String,List<Course>> teachedCourseYear = new HashMap<String,List<Course>>(); |
||
193 | |||
194 | public List<CourseUnit> getTeachedUnitsView(1.5.0/docs/api/java/lang/String.html">String year) |
||
195 | { |
||
196 | List<CourseUnit> cuYear = teachedUnitsYear.get(year); |
||
197 | if(cuYear == null) |
||
198 | { |
||
199 | List<Course> lc = new ArrayList<Course>(); |
||
200 | teachedCourseYear.put(year,lc); |
||
201 | try |
||
202 | { |
||
203 | IServiceManager sm = ServiceManager.getInstance(); |
||
204 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable","year"}; |
||
205 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId(),year}; |
||
206 | cuYear = (List<CourseUnit>) sm.execute(null, "LoadTeachedUnitsYear", args, names); |
||
207 | |||
208 | if(cuYear == null) |
||
209 | cuYear = new ArrayList<CourseUnit>(); |
||
210 | for(CourseUnit c: cuYear) |
||
211 | { |
||
212 | if(!lc.contains(c.getCourse())) |
||
213 | { |
||
214 | lc.add(c.getCourse()); |
||
215 | } |
||
216 | } |
||
217 | teachedUnitsYear.put(year,cuYear); |
||
218 | } |
||
219 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
220 | { |
||
221 | logger.error(e,e); |
||
222 | } |
||
223 | } |
||
788 | jmachado | 224 | return cuYear; |
787 | jmachado | 225 | } |
226 | |||
227 | |||
253 | jmachado | 228 | public List<CourseUnit> getTeachedUnitsCurrentYearView() |
229 | { |
||
230 | if(teachedUnitsCurrentYearView == null) |
||
231 | { |
||
232 | teachedCoursesCurrentYearView = new ArrayList<Course>(); |
||
233 | try |
||
234 | { |
||
235 | IServiceManager sm = ServiceManager.getInstance(); |
||
236 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"}; |
||
237 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()}; |
||
238 | teachedUnitsCurrentYearView = (List<CourseUnit>) sm.execute(null, "LoadTeachedUnitsCurrentYear", args, names); |
||
239 | if(teachedUnitsCurrentYearView == null) |
||
240 | teachedUnitsCurrentYearView = new ArrayList<CourseUnit>(); |
||
241 | for(CourseUnit c: teachedUnitsCurrentYearView) |
||
242 | { |
||
243 | if(!teachedCoursesCurrentYearView.contains(c.getCourse())) |
||
244 | { |
||
245 | teachedCoursesCurrentYearView.add(c.getCourse()); |
||
246 | } |
||
247 | } |
||
248 | } |
||
249 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
250 | { |
||
251 | logger.error(e,e); |
||
252 | } |
||
253 | } |
||
254 | return teachedUnitsCurrentYearView; |
||
255 | } |
||
256 | |||
204 | jmachado | 257 | public boolean hasCourseUnit(long id) |
258 | { |
||
259 | return hasCourseUnit(id,false); |
||
260 | } |
||
261 | |||
146 | jmachado | 262 | public boolean hasCourseUnit(CourseUnit courseUnit) |
263 | { |
||
204 | jmachado | 264 | return hasCourseUnit(courseUnit.getId(),false); |
202 | jmachado | 265 | } |
266 | |||
204 | jmachado | 267 | public boolean hasCourseUnit(long id, boolean transaction) |
202 | jmachado | 268 | { |
214 | jmachado | 269 | List<CourseUnit> cUnits; |
202 | jmachado | 270 | if(transaction) |
214 | jmachado | 271 | cUnits = new ArrayList<CourseUnit>(getTeachedUnits()); |
202 | jmachado | 272 | else |
273 | cUnits = getTeachedUnitsView(); |
||
274 | if(cUnits == null) |
||
146 | jmachado | 275 | return false; |
202 | jmachado | 276 | for(CourseUnit c: cUnits) |
146 | jmachado | 277 | { |
204 | jmachado | 278 | if(c.getId() == id) |
146 | jmachado | 279 | return true; |
280 | } |
||
281 | return false; |
||
282 | } |
||
223 | jmachado | 283 | |
225 | jmachado | 284 | public void removeUnitLocaly(CourseUnit unit) |
223 | jmachado | 285 | { |
225 | jmachado | 286 | setLocalRemovedTeachedUnits(StringsUtils.addElement(getLocalRemovedTeachedUnits(),"" + unit.getId(),",")); |
996 | jmachado | 287 | |
288 | //todo novo |
||
289 | setLocalTeachedUnits(StringsUtils.removeElement(getLocalTeachedUnits(),"" + unit.getId(),",")); |
||
223 | jmachado | 290 | } |
291 | |||
225 | jmachado | 292 | public void addUnitLocaly(CourseUnit unit) |
223 | jmachado | 293 | { |
225 | jmachado | 294 | setLocalRemovedTeachedUnits(StringsUtils.removeElement(getLocalRemovedTeachedUnits(),"" + unit.getId(),",")); |
996 | jmachado | 295 | |
296 | //todo novo |
||
297 | setLocalTeachedUnits(StringsUtils.removeElement(getLocalTeachedUnits(),"" + unit.getId(),",")); |
||
298 | setLocalTeachedUnits(StringsUtils.addElement(getLocalTeachedUnits(),"" + unit.getId(),",")); |
||
223 | jmachado | 299 | } |
300 | |||
225 | jmachado | 301 | public boolean isLocalRemovedUnit(CourseUnit unit) |
223 | jmachado | 302 | { |
225 | jmachado | 303 | return StringsUtils.hasElement(getLocalRemovedTeachedUnits(),"" + unit.getId(),","); |
223 | jmachado | 304 | } |
996 | jmachado | 305 | |
306 | public boolean isLocalUnit(CourseUnit unit) |
||
307 | { |
||
308 | return StringsUtils.hasElement(getLocalTeachedUnits(),""+unit.getId(),","); |
||
309 | } |
||
114 | jmachado | 310 | } |