Rev 1780 | 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 | |||
726 | jmachado | 3 | import jomm.utils.StringsUtils; |
4 | import org.apache.log4j.Logger; |
||
114 | jmachado | 5 | import pt.estgp.estgweb.Globals; |
1414 | 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 | |
726 | jmachado | 10 | import java.util.ArrayList; |
1040 | jmachado | 11 | import java.util.HashMap; |
726 | jmachado | 12 | import java.util.List; |
1040 | jmachado | 13 | import java.util.Map; |
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 StudentImpl extends Student |
||
22 | { |
||
23 | |||
24 | public static final 1.5.0/docs/api/java/lang/String.html">String STUDENT_ROLE = Globals.STUDENT_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(StudentImpl.class); |
114 | jmachado | 27 | |
214 | jmachado | 28 | private List<CourseUnit> subscribedUnitsView = null; |
255 | jmachado | 29 | private List<CourseUnit> subscribedUnitsCurrentYearView = null; |
30 | private List<CourseUnit> subscribedUnitsOldYearsView = null; |
||
214 | jmachado | 31 | private List<CourseUnitAnnouncementImpl> courseUnitAnnouncementsView = null; |
215 | jmachado | 32 | private List<Course> subscribedCoursesView = null; |
255 | jmachado | 33 | private List<Course> subscribedCoursesCurrentYearView = null; |
34 | private List<Course> subscribedCoursesOldYearsView = null; |
||
202 | jmachado | 35 | |
215 | jmachado | 36 | public List<Course> getSubscribedCoursesView() |
37 | { |
||
38 | getSubscribedUnitsView(); |
||
39 | return subscribedCoursesView; |
||
40 | } |
||
41 | |||
255 | jmachado | 42 | public List<Course> getSubscribedCoursesCurrentYearView() |
43 | { |
||
44 | getSubscribedUnitsCurrentYearView(); |
||
45 | return subscribedCoursesCurrentYearView; |
||
46 | } |
||
47 | |||
48 | public List<Course> getSubscribedCoursesOldYearsView() |
||
49 | { |
||
50 | getSubscribedUnitsOldYearsView(); |
||
51 | return subscribedCoursesOldYearsView; |
||
52 | } |
||
53 | |||
1414 | jmachado | 54 | public 1.5.0/docs/api/java/lang/String.html">String getManagedRole() |
55 | { |
||
56 | List<String> roles = new ArrayList<String>(); |
||
57 | roles.add(STUDENT_ROLE); |
||
58 | return RoleManager.getSerialRoles(roles); |
||
114 | jmachado | 59 | } |
146 | jmachado | 60 | |
265 | jmachado | 61 | public List<CourseUnit> getSubscribedUnitsViewS1() |
62 | { |
||
63 | return getUnitsSemestre("S1",getSubscribedUnitsView()); |
||
64 | } |
||
65 | public List<CourseUnit> getSubscribedUnitsViewS2() |
||
66 | { |
||
67 | return getUnitsSemestre("S2",getSubscribedUnitsView()); |
||
68 | } |
||
728 | jmachado | 69 | |
70 | public List<CourseUnit> getSubscribedUnitsViewA() |
||
71 | { |
||
72 | return getUnitsSemestre("A",getSubscribedUnitsView()); |
||
73 | } |
||
74 | |||
1040 | jmachado | 75 | public List<CourseUnit> getSubscribedUnitsViewT1() |
76 | { |
||
77 | return getUnitsSemestre("T1",getSubscribedUnitsView()); |
||
78 | } |
||
79 | |||
80 | public List<CourseUnit> getSubscribedUnitsViewT2() |
||
81 | { |
||
82 | return getUnitsSemestre("T2",getSubscribedUnitsView()); |
||
83 | } |
||
84 | |||
85 | public List<CourseUnit> getSubscribedUnitsViewT3() |
||
86 | { |
||
87 | return getUnitsSemestre("T3",getSubscribedUnitsView()); |
||
88 | } |
||
89 | |||
90 | public List<CourseUnit> getSubscribedUnitsViewT4() |
||
91 | { |
||
92 | return getUnitsSemestre("T4",getSubscribedUnitsView()); |
||
93 | } |
||
94 | |||
214 | jmachado | 95 | public List<CourseUnit> getSubscribedUnitsView() |
202 | jmachado | 96 | { |
97 | if(subscribedUnitsView == null) |
||
98 | { |
||
215 | jmachado | 99 | subscribedCoursesView = 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 | subscribedUnitsView = (List<CourseUnit>) sm.execute(null, "LoadSubscribedUnits", args, names); |
202 | jmachado | 106 | if(subscribedUnitsView == null) |
214 | jmachado | 107 | subscribedUnitsView = new ArrayList<CourseUnit>(); |
215 | jmachado | 108 | for(CourseUnit c: subscribedUnitsView) |
109 | { |
||
110 | if(!subscribedCoursesView.contains(c.getCourse())) |
||
111 | { |
||
112 | subscribedCoursesView.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 subscribedUnitsView; |
||
122 | } |
||
123 | |||
1040 | jmachado | 124 | public List<CourseUnit> getSubscribedUnitsCurrentYearViewT1() |
125 | { |
||
126 | return getUnitsSemestre("T1",getSubscribedUnitsCurrentYearView()); |
||
127 | } |
||
128 | public List<CourseUnit> getSubscribedUnitsCurrentYearViewT2() |
||
129 | { |
||
130 | return getUnitsSemestre("T2",getSubscribedUnitsCurrentYearView()); |
||
131 | } |
||
132 | public List<CourseUnit> getSubscribedUnitsCurrentYearViewT3() |
||
133 | { |
||
134 | return getUnitsSemestre("T3",getSubscribedUnitsCurrentYearView()); |
||
135 | } |
||
136 | public List<CourseUnit> getSubscribedUnitsCurrentYearViewT4() |
||
137 | { |
||
138 | return getUnitsSemestre("T4",getSubscribedUnitsCurrentYearView()); |
||
139 | } |
||
140 | |||
265 | jmachado | 141 | public List<CourseUnit> getSubscribedUnitsCurrentYearViewS1() |
142 | { |
||
143 | return getUnitsSemestre("S1",getSubscribedUnitsCurrentYearView()); |
||
144 | } |
||
145 | public List<CourseUnit> getSubscribedUnitsCurrentYearViewS2() |
||
146 | { |
||
147 | return getUnitsSemestre("S2",getSubscribedUnitsCurrentYearView()); |
||
148 | } |
||
728 | jmachado | 149 | public List<CourseUnit> getSubscribedUnitsCurrentYearViewA() |
150 | { |
||
151 | return getUnitsSemestre("A",getSubscribedUnitsCurrentYearView()); |
||
152 | } |
||
153 | |||
255 | jmachado | 154 | public List<CourseUnit> getSubscribedUnitsCurrentYearView() |
155 | { |
||
156 | if(subscribedUnitsCurrentYearView == null) |
||
157 | { |
||
158 | subscribedCoursesCurrentYearView = new ArrayList<Course>(); |
||
159 | try |
||
160 | { |
||
161 | IServiceManager sm = ServiceManager.getInstance(); |
||
162 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"}; |
||
163 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()}; |
||
164 | subscribedUnitsCurrentYearView = (List<CourseUnit>) sm.execute(null, "LoadSubscribedUnitsCurrentYear", args, names); |
||
165 | if(subscribedUnitsCurrentYearView == null) |
||
166 | subscribedUnitsCurrentYearView = new ArrayList<CourseUnit>(); |
||
167 | for(CourseUnit c: subscribedUnitsCurrentYearView) |
||
168 | { |
||
169 | if(!subscribedCoursesCurrentYearView.contains(c.getCourse())) |
||
170 | { |
||
171 | subscribedCoursesCurrentYearView.add(c.getCourse()); |
||
172 | } |
||
173 | } |
||
174 | } |
||
175 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
176 | { |
||
177 | logger.error(e,e); |
||
178 | } |
||
179 | } |
||
180 | return subscribedUnitsCurrentYearView; |
||
181 | } |
||
202 | jmachado | 182 | |
1040 | jmachado | 183 | Map<String,List<CourseUnit>> subscribedUnitsYear = new HashMap<String,List<CourseUnit>>(); |
184 | |||
185 | public List<CourseUnit> getSubscribedUnitsView(1.5.0/docs/api/java/lang/String.html">String year) |
||
186 | { |
||
187 | List<CourseUnit> cuYear = subscribedUnitsYear.get(year); |
||
188 | if(cuYear == null) |
||
189 | { |
||
190 | try |
||
191 | { |
||
192 | IServiceManager sm = ServiceManager.getInstance(); |
||
193 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable","year"}; |
||
194 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId(),year}; |
||
195 | cuYear = (List<CourseUnit>) sm.execute(null, "LoadSubscribedUnitsGivenYear", args, names); |
||
196 | |||
1072 | jmachado | 197 | if(cuYear != null) |
198 | subscribedUnitsYear.put(year,cuYear); |
||
199 | else |
||
200 | subscribedUnitsYear.put(year,new ArrayList<CourseUnit>()); |
||
1040 | jmachado | 201 | } |
202 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
203 | { |
||
204 | logger.error(e,e); |
||
205 | } |
||
206 | } |
||
207 | return cuYear; |
||
208 | } |
||
209 | public List<CourseUnit> getSubscribedUnitsViewA(1.5.0/docs/api/java/lang/String.html">String year) |
||
210 | { |
||
211 | return getUnitsSemestre("A", getSubscribedUnitsView(year)); |
||
212 | } |
||
213 | public List<CourseUnit> getSubscribedUnitsViewS1(1.5.0/docs/api/java/lang/String.html">String year) |
||
214 | { |
||
215 | return getUnitsSemestre("S1",getSubscribedUnitsView(year)); |
||
216 | } |
||
217 | public List<CourseUnit> getSubscribedUnitsViewS2(1.5.0/docs/api/java/lang/String.html">String year) |
||
218 | { |
||
219 | return getUnitsSemestre("S2",getSubscribedUnitsView(year)); |
||
220 | } |
||
221 | public List<CourseUnit> getSubscribedUnitsViewT1(1.5.0/docs/api/java/lang/String.html">String year) |
||
222 | { |
||
223 | return getUnitsSemestre("T1",getSubscribedUnitsView(year)); |
||
224 | } |
||
225 | public List<CourseUnit> getSubscribedUnitsViewT2(1.5.0/docs/api/java/lang/String.html">String year) |
||
226 | { |
||
227 | return getUnitsSemestre("T2",getSubscribedUnitsView(year)); |
||
228 | } |
||
229 | public List<CourseUnit> getSubscribedUnitsViewT3(1.5.0/docs/api/java/lang/String.html">String year) |
||
230 | { |
||
231 | return getUnitsSemestre("T3",getSubscribedUnitsView(year)); |
||
232 | } |
||
233 | public List<CourseUnit> getSubscribedUnitsViewT4(1.5.0/docs/api/java/lang/String.html">String year) |
||
234 | { |
||
235 | return getUnitsSemestre("T4",getSubscribedUnitsView(year)); |
||
236 | } |
||
237 | |||
265 | jmachado | 238 | public List<CourseUnit> getSubscribedUnitsOldYearsViewS1() |
239 | { |
||
240 | return getUnitsSemestre("S1",getSubscribedUnitsOldYearsView()); |
||
241 | } |
||
242 | public List<CourseUnit> getSubscribedUnitsOldYearsViewS2() |
||
243 | { |
||
244 | return getUnitsSemestre("S2",getSubscribedUnitsOldYearsView()); |
||
245 | } |
||
255 | jmachado | 246 | public List<CourseUnit> getSubscribedUnitsOldYearsView() |
247 | { |
||
248 | if(subscribedUnitsOldYearsView == null) |
||
249 | { |
||
250 | subscribedCoursesOldYearsView = new ArrayList<Course>(); |
||
251 | try |
||
252 | { |
||
253 | IServiceManager sm = ServiceManager.getInstance(); |
||
254 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"}; |
||
255 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()}; |
||
256 | subscribedUnitsOldYearsView = (List<CourseUnit>) sm.execute(null, "LoadSubscribedUnitsOldYears", args, names); |
||
257 | if(subscribedUnitsOldYearsView == null) |
||
258 | subscribedUnitsOldYearsView = new ArrayList<CourseUnit>(); |
||
259 | for(CourseUnit c: subscribedUnitsOldYearsView) |
||
260 | { |
||
261 | if(!subscribedCoursesOldYearsView.contains(c.getCourse())) |
||
262 | { |
||
263 | subscribedCoursesOldYearsView.add(c.getCourse()); |
||
264 | } |
||
265 | } |
||
266 | } |
||
267 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
268 | { |
||
269 | logger.error(e,e); |
||
270 | } |
||
271 | } |
||
272 | return subscribedUnitsOldYearsView; |
||
273 | } |
||
274 | |||
275 | |||
265 | jmachado | 276 | |
214 | jmachado | 277 | public List<CourseUnitAnnouncementImpl> getCourseUnitAnnouncementsView() |
202 | jmachado | 278 | { |
279 | if(courseUnitAnnouncementsView == null) |
||
280 | { |
||
281 | try |
||
282 | { |
||
283 | IServiceManager sm = ServiceManager.getInstance(); |
||
284 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"}; |
||
285 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()}; |
||
214 | jmachado | 286 | courseUnitAnnouncementsView = (List<CourseUnitAnnouncementImpl>) sm.execute(null, "LoadSubscribedUnitsAnnouncements", args, names); |
202 | jmachado | 287 | if(courseUnitAnnouncementsView == null) |
214 | jmachado | 288 | courseUnitAnnouncementsView = new ArrayList<CourseUnitAnnouncementImpl>(); |
202 | jmachado | 289 | } |
290 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
291 | { |
||
292 | logger.error(e,e); |
||
293 | } |
||
294 | } |
||
295 | return courseUnitAnnouncementsView; |
||
296 | } |
||
297 | |||
265 | jmachado | 298 | |
299 | |||
300 | |||
301 | |||
266 | jmachado | 302 | |
146 | jmachado | 303 | public boolean hasCourseUnit(CourseUnit courseUnit) |
304 | { |
||
204 | jmachado | 305 | return hasCourseUnit(courseUnit.getId(),false); |
202 | jmachado | 306 | } |
307 | |||
225 | jmachado | 308 | public boolean hasCourseUnit(long unitId, boolean transaction) |
202 | jmachado | 309 | { |
214 | jmachado | 310 | List<CourseUnit> cUnits; |
202 | jmachado | 311 | if(transaction) |
214 | jmachado | 312 | cUnits = new ArrayList<CourseUnit>(getSubscribedUnits()); |
202 | jmachado | 313 | else |
314 | cUnits = getSubscribedUnitsView(); |
||
315 | if(cUnits == null) |
||
146 | jmachado | 316 | return false; |
202 | jmachado | 317 | for(CourseUnit c: cUnits) |
146 | jmachado | 318 | { |
225 | jmachado | 319 | if(c.getId() == unitId) |
146 | jmachado | 320 | return true; |
321 | } |
||
322 | return false; |
||
323 | } |
||
223 | jmachado | 324 | |
225 | jmachado | 325 | public void removeUnitLocaly(CourseUnit unit) |
223 | jmachado | 326 | { |
225 | jmachado | 327 | setLocalRemovedSubscribedUnits(StringsUtils.addElement(getLocalRemovedSubscribedUnits(),"" + unit.getId(),",")); |
566 | jmachado | 328 | setLocalSubscribedUnits(StringsUtils.removeElement(getLocalSubscribedUnits(),"" + unit.getId(),",")); |
223 | jmachado | 329 | } |
330 | |||
225 | jmachado | 331 | public void addUnitLocaly(CourseUnit unit) |
223 | jmachado | 332 | { |
225 | jmachado | 333 | setLocalRemovedSubscribedUnits(StringsUtils.removeElement(getLocalRemovedSubscribedUnits(),"" + unit.getId(),",")); |
566 | jmachado | 334 | setLocalSubscribedUnits(StringsUtils.removeElement(getLocalSubscribedUnits(),"" + unit.getId(),",")); |
335 | setLocalSubscribedUnits(StringsUtils.addElement(getLocalSubscribedUnits(),"" + unit.getId(),",")); |
||
223 | jmachado | 336 | } |
337 | |||
225 | jmachado | 338 | public boolean isLocalRemovedUnit(CourseUnit unit) |
223 | jmachado | 339 | { |
225 | jmachado | 340 | return StringsUtils.hasElement(getLocalRemovedSubscribedUnits(),"" + unit.getId(),","); |
223 | jmachado | 341 | } |
568 | jmachado | 342 | |
343 | |||
344 | public boolean isLocalUnit(CourseUnit unit) |
||
345 | { |
||
346 | return StringsUtils.hasElement(getLocalSubscribedUnits(),""+unit.getId(),","); |
||
347 | } |
||
348 | |||
349 | |||
995 | jmachado | 350 | |
1780 | jmachado | 351 | private List<String> excludedGenericJsonMethodsWithOpenTransactions = null; |
995 | jmachado | 352 | |
1780 | jmachado | 353 | @1.5.0/docs/api/java/lang/Override.html">Override |
354 | public synchronized List<String> getJsonExcludedProperties() { |
||
355 | if(excludedGenericJsonMethodsWithOpenTransactions == null) |
||
356 | { |
||
357 | excludedGenericJsonMethodsWithOpenTransactions = new ArrayList<String>(); |
||
358 | searchMyMethodsStartingWith("subscribedUnits",excludedGenericJsonMethodsWithOpenTransactions); |
||
1781 | jmachado | 359 | //searchMyMethodsStartingWith("subscribedCourses",excludedGenericJsonMethodsWithOpenTransactions); |
1780 | jmachado | 360 | excludedGenericJsonMethodsWithOpenTransactions.add("courseUnitAnnouncementsView"); |
361 | } |
||
362 | return excludedGenericJsonMethodsWithOpenTransactions; |
||
363 | } |
||
364 | |||
114 | jmachado | 365 | } |