Rev 787 | Rev 996 | 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; |
||
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 | } |
||
214 | jmachado | 73 | public List<CourseUnit> getTeachedUnitsView() |
202 | jmachado | 74 | { |
75 | if(teachedUnitsView == null) |
||
76 | { |
||
215 | jmachado | 77 | teachedCoursesView = new ArrayList<Course>(); |
202 | jmachado | 78 | try |
79 | { |
||
80 | IServiceManager sm = ServiceManager.getInstance(); |
||
81 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"}; |
||
82 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()}; |
||
214 | jmachado | 83 | teachedUnitsView = (List<CourseUnit>) sm.execute(null, "LoadTeachedUnits", args, names); |
202 | jmachado | 84 | if(teachedUnitsView == null) |
214 | jmachado | 85 | teachedUnitsView = new ArrayList<CourseUnit>(); |
215 | jmachado | 86 | for(CourseUnit c: teachedUnitsView) |
87 | { |
||
88 | if(!teachedCoursesView.contains(c.getCourse())) |
||
89 | { |
||
90 | teachedCoursesView.add(c.getCourse()); |
||
91 | } |
||
92 | } |
||
202 | jmachado | 93 | } |
94 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
95 | { |
||
96 | logger.error(e,e); |
||
97 | } |
||
98 | } |
||
99 | return teachedUnitsView; |
||
100 | } |
||
101 | |||
266 | jmachado | 102 | public List<CourseUnit> getTeachedUnitsCurrentYearViewS1() |
103 | { |
||
104 | return getUnitsSemestre("S1",getTeachedUnitsCurrentYearView()); |
||
105 | } |
||
106 | public List<CourseUnit> getTeachedUnitsCurrentYearViewS2() |
||
107 | { |
||
108 | return getUnitsSemestre("S2",getTeachedUnitsCurrentYearView()); |
||
109 | } |
||
728 | jmachado | 110 | public List<CourseUnit> getTeachedUnitsCurrentYearViewA() |
111 | { |
||
112 | return getUnitsSemestre("A",getTeachedUnitsCurrentYearView()); |
||
113 | } |
||
787 | jmachado | 114 | |
115 | |||
116 | |||
117 | public List<CourseUnit> getTeachedUnitsViewS1(1.5.0/docs/api/java/lang/String.html">String year) |
||
118 | { |
||
119 | return getUnitsSemestre("S1",getTeachedUnitsView(year)); |
||
120 | } |
||
121 | public List<CourseUnit> getTeachedUnitsViewS2(1.5.0/docs/api/java/lang/String.html">String year) |
||
122 | { |
||
123 | return getUnitsSemestre("S2",getTeachedUnitsView(year)); |
||
124 | } |
||
125 | public List<CourseUnit> getTeachedUnitsViewA(1.5.0/docs/api/java/lang/String.html">String year) |
||
126 | { |
||
127 | return getUnitsSemestre("A",getTeachedUnitsView(year)); |
||
128 | } |
||
129 | |||
130 | Map<String,List<CourseUnit>> teachedUnitsYear = new HashMap<String,List<CourseUnit>>(); |
||
131 | Map<String,List<Course>> teachedCourseYear = new HashMap<String,List<Course>>(); |
||
132 | |||
133 | public List<CourseUnit> getTeachedUnitsView(1.5.0/docs/api/java/lang/String.html">String year) |
||
134 | { |
||
135 | List<CourseUnit> cuYear = teachedUnitsYear.get(year); |
||
136 | if(cuYear == null) |
||
137 | { |
||
138 | List<Course> lc = new ArrayList<Course>(); |
||
139 | teachedCourseYear.put(year,lc); |
||
140 | try |
||
141 | { |
||
142 | IServiceManager sm = ServiceManager.getInstance(); |
||
143 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable","year"}; |
||
144 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId(),year}; |
||
145 | cuYear = (List<CourseUnit>) sm.execute(null, "LoadTeachedUnitsYear", args, names); |
||
146 | |||
147 | if(cuYear == null) |
||
148 | cuYear = new ArrayList<CourseUnit>(); |
||
149 | for(CourseUnit c: cuYear) |
||
150 | { |
||
151 | if(!lc.contains(c.getCourse())) |
||
152 | { |
||
153 | lc.add(c.getCourse()); |
||
154 | } |
||
155 | } |
||
156 | teachedUnitsYear.put(year,cuYear); |
||
157 | } |
||
158 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
159 | { |
||
160 | logger.error(e,e); |
||
161 | } |
||
162 | } |
||
788 | jmachado | 163 | return cuYear; |
787 | jmachado | 164 | } |
165 | |||
166 | |||
253 | jmachado | 167 | public List<CourseUnit> getTeachedUnitsCurrentYearView() |
168 | { |
||
169 | if(teachedUnitsCurrentYearView == null) |
||
170 | { |
||
171 | teachedCoursesCurrentYearView = new ArrayList<Course>(); |
||
172 | try |
||
173 | { |
||
174 | IServiceManager sm = ServiceManager.getInstance(); |
||
175 | 1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"}; |
||
176 | 5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()}; |
||
177 | teachedUnitsCurrentYearView = (List<CourseUnit>) sm.execute(null, "LoadTeachedUnitsCurrentYear", args, names); |
||
178 | if(teachedUnitsCurrentYearView == null) |
||
179 | teachedUnitsCurrentYearView = new ArrayList<CourseUnit>(); |
||
180 | for(CourseUnit c: teachedUnitsCurrentYearView) |
||
181 | { |
||
182 | if(!teachedCoursesCurrentYearView.contains(c.getCourse())) |
||
183 | { |
||
184 | teachedCoursesCurrentYearView.add(c.getCourse()); |
||
185 | } |
||
186 | } |
||
187 | } |
||
188 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
189 | { |
||
190 | logger.error(e,e); |
||
191 | } |
||
192 | } |
||
193 | return teachedUnitsCurrentYearView; |
||
194 | } |
||
195 | |||
204 | jmachado | 196 | public boolean hasCourseUnit(long id) |
197 | { |
||
198 | return hasCourseUnit(id,false); |
||
199 | } |
||
200 | |||
146 | jmachado | 201 | public boolean hasCourseUnit(CourseUnit courseUnit) |
202 | { |
||
204 | jmachado | 203 | return hasCourseUnit(courseUnit.getId(),false); |
202 | jmachado | 204 | } |
205 | |||
204 | jmachado | 206 | public boolean hasCourseUnit(long id, boolean transaction) |
202 | jmachado | 207 | { |
214 | jmachado | 208 | List<CourseUnit> cUnits; |
202 | jmachado | 209 | if(transaction) |
214 | jmachado | 210 | cUnits = new ArrayList<CourseUnit>(getTeachedUnits()); |
202 | jmachado | 211 | else |
212 | cUnits = getTeachedUnitsView(); |
||
213 | if(cUnits == null) |
||
146 | jmachado | 214 | return false; |
202 | jmachado | 215 | for(CourseUnit c: cUnits) |
146 | jmachado | 216 | { |
204 | jmachado | 217 | if(c.getId() == id) |
146 | jmachado | 218 | return true; |
219 | } |
||
220 | return false; |
||
221 | } |
||
223 | jmachado | 222 | |
225 | jmachado | 223 | public void removeUnitLocaly(CourseUnit unit) |
223 | jmachado | 224 | { |
225 | jmachado | 225 | setLocalRemovedTeachedUnits(StringsUtils.addElement(getLocalRemovedTeachedUnits(),"" + unit.getId(),",")); |
223 | jmachado | 226 | } |
227 | |||
225 | jmachado | 228 | public void addUnitLocaly(CourseUnit unit) |
223 | jmachado | 229 | { |
225 | jmachado | 230 | setLocalRemovedTeachedUnits(StringsUtils.removeElement(getLocalRemovedTeachedUnits(),"" + unit.getId(),",")); |
223 | jmachado | 231 | } |
232 | |||
225 | jmachado | 233 | public boolean isLocalRemovedUnit(CourseUnit unit) |
223 | jmachado | 234 | { |
225 | jmachado | 235 | return StringsUtils.hasElement(getLocalRemovedTeachedUnits(),"" + unit.getId(),","); |
223 | jmachado | 236 | } |
114 | jmachado | 237 | } |