Rev 255 | Rev 358 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
203 | jmachado | 1 | package pt.estgp.estgweb.domain.views; |
2 | |||
3 | import org.apache.log4j.Logger; |
||
4 | import pt.estgp.estgweb.domain.*; |
||
214 | jmachado | 5 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
6 | import pt.estgp.estgweb.services.courseunits.LoadCourseUnitAnnouncements; |
||
7 | import pt.estgp.estgweb.services.expceptions.ServiceException; |
||
203 | jmachado | 8 | |
9 | import java.io.Serializable; |
||
10 | import java.util.Set; |
||
204 | jmachado | 11 | import java.util.List; |
206 | jmachado | 12 | import java.util.ArrayList; |
13 | import java.util.HashSet; |
||
203 | jmachado | 14 | |
15 | /** |
||
16 | * @author Jorge Machado |
||
17 | * @date 2/Mar/2008 |
||
18 | * @time 19:34:49 |
||
19 | * @see pt.estgp.estgweb.domain.views |
||
20 | */ |
||
204 | jmachado | 21 | public class CourseUnitView extends DomainObjectView implements ICanManage |
203 | jmachado | 22 | { |
23 | 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(CourseUnitView.class); |
||
24 | |||
214 | jmachado | 25 | |
26 | LoadCourseUnitAnnouncements loadCourseUnitAnnouncements = new LoadCourseUnitAnnouncements(); |
||
27 | |||
203 | jmachado | 28 | private long id; |
29 | private 1.5.0/docs/api/java/lang/String.html">String name; |
||
30 | private 1.5.0/docs/api/java/lang/String.html">String code; |
||
214 | jmachado | 31 | private long courseId; |
203 | jmachado | 32 | private 1.5.0/docs/api/java/lang/String.html">String courseCode; |
33 | private 1.5.0/docs/api/java/lang/String.html">String courseName; |
||
206 | jmachado | 34 | private 1.5.0/docs/api/java/lang/String.html">String semestre; |
35 | private 1.5.0/docs/api/java/lang/String.html">String importYear; |
||
203 | jmachado | 36 | private BlogView blog; |
223 | jmachado | 37 | private 1.5.0/docs/api/java/lang/String.html">String pathIntranet; |
38 | private 1.5.0/docs/api/java/lang/String.html">String normalizedName; |
||
209 | jmachado | 39 | private List<AnnouncementView> announcements; |
40 | |||
203 | jmachado | 41 | private CourseUnit courseUnit; |
206 | jmachado | 42 | private Set<UserView> teachers; |
43 | private Set<UserView> students; |
||
44 | |||
203 | jmachado | 45 | private 1.5.0/docs/api/java/lang/String.html">String objectives; |
204 | jmachado | 46 | private 1.5.0/docs/api/java/lang/String.html">String programStreamId; |
343 | jmachado | 47 | private boolean validProgram; |
48 | private UserView validatorUser; |
||
204 | jmachado | 49 | private int programSize; |
50 | private 1.5.0/docs/api/java/lang/String.html">String extension; |
||
207 | jmachado | 51 | private List<CourseUnitAssignementView> courseUnitAssignements; |
203 | jmachado | 52 | |
214 | jmachado | 53 | private boolean notFound = false; |
54 | |||
55 | private CourseView courseView; |
||
56 | |||
203 | jmachado | 57 | public 1.5.0/docs/api/java/lang/Class.html">Class getReferenceClass() |
58 | { |
||
59 | return CourseUnitImpl.class; |
||
60 | } |
||
61 | |||
62 | public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() |
||
63 | { |
||
64 | return id; |
||
65 | } |
||
66 | |||
67 | public CourseUnitView() |
||
68 | { |
||
69 | } |
||
206 | jmachado | 70 | public CourseUnitView(CourseUnit courseUnit, boolean initTeachers, boolean initStudents ) |
71 | { |
||
72 | super(courseUnit); |
||
343 | jmachado | 73 | init(courseUnit, initTeachers, initStudents,false,false); |
206 | jmachado | 74 | } |
209 | jmachado | 75 | |
208 | jmachado | 76 | public CourseUnitView(CourseUnit courseUnit, boolean initTeachers, boolean initStudents, boolean initBlog ) |
77 | { |
||
78 | super(courseUnit); |
||
343 | jmachado | 79 | init(courseUnit, initTeachers, initStudents, initBlog,false); |
208 | jmachado | 80 | } |
203 | jmachado | 81 | |
343 | jmachado | 82 | public CourseUnitView(CourseUnit courseUnit, boolean initTeachers, boolean initStudents, boolean initBlog, boolean validatorPerson ) |
83 | { |
||
84 | super(courseUnit); |
||
85 | init(courseUnit, initTeachers, initStudents, initBlog, validatorPerson); |
||
86 | } |
||
87 | |||
203 | jmachado | 88 | public CourseUnitView(CourseUnit courseUnit) |
89 | { |
||
90 | super(courseUnit); |
||
343 | jmachado | 91 | init(courseUnit, false,false,false,false); |
206 | jmachado | 92 | } |
208 | jmachado | 93 | |
94 | public CourseUnitView(CourseUnit courseUnit, BlogView b) |
||
206 | jmachado | 95 | { |
208 | jmachado | 96 | super(courseUnit); |
97 | this.blog = b; |
||
343 | jmachado | 98 | init(courseUnit, false,false,false,false); |
208 | jmachado | 99 | } |
214 | jmachado | 100 | |
343 | jmachado | 101 | private void init(CourseUnit courseUnit, boolean initTeachers, boolean initStudents, boolean initBlog, boolean validatorUser) |
208 | jmachado | 102 | { |
223 | jmachado | 103 | this.pathIntranet = courseUnit.getPathIntranet(); |
104 | this.normalizedName = courseUnit.getNormalizedName(); |
||
203 | jmachado | 105 | this.courseUnit = courseUnit; |
106 | this.courseName = courseUnit.getCourseName(); |
||
107 | this.name = courseUnit.getName(); |
||
108 | this.code = courseUnit.getCode(); |
||
206 | jmachado | 109 | this.importYear = courseUnit.getImportYear(); |
110 | this.semestre = courseUnit.getSemestre(); |
||
203 | jmachado | 111 | this.courseCode = courseUnit.getCourseCode(); |
209 | jmachado | 112 | this.objectives = courseUnit.getObjectives(); |
113 | if(courseUnit.getProgramStreamId() != null) |
||
343 | jmachado | 114 | { |
209 | jmachado | 115 | programStreamId = courseUnit.getProgramStreamId(); |
343 | jmachado | 116 | validProgram = courseUnit.isValidProgram(); |
117 | if(validatorUser) |
||
118 | { |
||
119 | if(courseUnit.getValidatorUser() != null) |
||
120 | this.validatorUser = new UserView(courseUnit.getValidatorUser()); |
||
121 | } |
||
122 | } |
||
123 | |||
203 | jmachado | 124 | // if(courseUnit.getBlog() != null) |
125 | // this.blog = new BlogView(courseUnit.getBlog()); |
||
126 | this.id = courseUnit.getId(); |
||
206 | jmachado | 127 | teachers = new HashSet<UserView>(); |
128 | students = new HashSet<UserView>(); |
||
129 | if(initTeachers && courseUnit.getTeachers() != null) |
||
130 | { |
||
131 | for(TeacherImpl t: courseUnit.getTeachers()) |
||
132 | { |
||
133 | UserView u = new UserView(t); |
||
134 | teachers.add(u); |
||
135 | } |
||
136 | } |
||
137 | if(initStudents && courseUnit.getStudents() != null) |
||
138 | { |
||
139 | for(StudentImpl s: courseUnit.getStudents()) |
||
140 | { |
||
141 | UserView u = new UserView(s); |
||
142 | students.add(u); |
||
143 | } |
||
144 | } |
||
208 | jmachado | 145 | if(initBlog) |
146 | { |
||
147 | blog = new BlogView(((CourseUnitImpl)courseUnit).getUnitBlog(),this); |
||
148 | } |
||
214 | jmachado | 149 | if(courseUnit.getCourse() != null) |
150 | { |
||
151 | courseId = courseUnit.getCourse().getId(); |
||
152 | } |
||
343 | jmachado | 153 | |
203 | jmachado | 154 | } |
155 | |||
214 | jmachado | 156 | public long getCourseId() |
157 | { |
||
158 | return courseId; |
||
159 | } |
||
160 | |||
161 | public void setCourseId(long courseId) |
||
162 | { |
||
163 | this.courseId = courseId; |
||
164 | } |
||
165 | |||
166 | public CourseView getCourseView() |
||
167 | { |
||
168 | return courseView; |
||
169 | } |
||
170 | |||
223 | jmachado | 171 | public 1.5.0/docs/api/java/lang/String.html">String getNormalizedName() |
172 | { |
||
173 | return normalizedName; |
||
174 | } |
||
175 | |||
176 | public void setNormalizedName(1.5.0/docs/api/java/lang/String.html">String normalizedName) |
||
177 | { |
||
178 | this.normalizedName = normalizedName; |
||
179 | } |
||
180 | |||
181 | public 1.5.0/docs/api/java/lang/String.html">String getPathIntranet() |
||
182 | { |
||
183 | return pathIntranet; |
||
184 | } |
||
185 | |||
186 | public void setPathIntranet(1.5.0/docs/api/java/lang/String.html">String pathIntranet) |
||
187 | { |
||
188 | this.pathIntranet = pathIntranet; |
||
189 | } |
||
190 | |||
214 | jmachado | 191 | public void setCourseView(CourseView courseView) |
192 | { |
||
193 | this.courseView = courseView; |
||
194 | } |
||
195 | |||
196 | public void setNotFound(boolean notFound) |
||
197 | { |
||
198 | this.notFound = notFound; |
||
199 | } |
||
200 | |||
201 | public boolean isNotFound() |
||
202 | { |
||
203 | return notFound; |
||
204 | } |
||
205 | |||
209 | jmachado | 206 | public void setAnnouncements(List<AnnouncementView> announcements) |
207 | { |
||
208 | this.announcements = announcements; |
||
209 | } |
||
210 | |||
206 | jmachado | 211 | public int getTeachersSize() |
212 | { |
||
213 | if(teachers != null) |
||
214 | return teachers.size(); |
||
215 | return 0; |
||
216 | } |
||
205 | jmachado | 217 | |
206 | jmachado | 218 | public int getStudentsSize() |
219 | { |
||
220 | if(students != null) |
||
221 | return students.size(); |
||
222 | return 0; |
||
223 | } |
||
214 | jmachado | 224 | |
207 | jmachado | 225 | public void setCourseUnitAssignements(List<CourseUnitAssignementView> courseUnitAssignements) |
205 | jmachado | 226 | { |
227 | this.courseUnitAssignements = courseUnitAssignements; |
||
228 | } |
||
229 | |||
207 | jmachado | 230 | public List<CourseUnitAssignementView> getCourseUnitAssignements() |
205 | jmachado | 231 | { |
232 | return courseUnitAssignements; |
||
233 | } |
||
234 | |||
204 | jmachado | 235 | public void setId(long id) |
203 | jmachado | 236 | { |
204 | jmachado | 237 | this.id = id; |
238 | } |
||
203 | jmachado | 239 | |
204 | jmachado | 240 | public void setName(1.5.0/docs/api/java/lang/String.html">String name) |
241 | { |
||
242 | this.name = name; |
||
203 | jmachado | 243 | } |
244 | |||
204 | jmachado | 245 | public void setCode(1.5.0/docs/api/java/lang/String.html">String code) |
246 | { |
||
247 | this.code = code; |
||
248 | } |
||
249 | |||
250 | public void setCourseCode(1.5.0/docs/api/java/lang/String.html">String courseCode) |
||
251 | { |
||
252 | this.courseCode = courseCode; |
||
253 | } |
||
254 | |||
255 | public void setCourseName(1.5.0/docs/api/java/lang/String.html">String courseName) |
||
256 | { |
||
257 | this.courseName = courseName; |
||
258 | } |
||
259 | |||
260 | public void persistViewInObject(CourseUnit c) |
||
261 | { |
||
262 | c.setObjectives(objectives); |
||
263 | } |
||
264 | |||
206 | jmachado | 265 | public void persistViewAdminInObject(CourseUnit c) |
266 | { |
||
267 | c.setImportYear(importYear); |
||
268 | c.setName(name); |
||
269 | c.setCode(code); |
||
270 | c.setSemestre(semestre); |
||
214 | jmachado | 271 | if(courseId > 0) |
272 | { |
||
273 | c.setCourse(DaoFactory.getCourseDaoImpl().load(courseId)); |
||
274 | } |
||
206 | jmachado | 275 | } |
276 | |||
203 | jmachado | 277 | public 1.5.0/docs/api/java/lang/String.html">String getObjectives() |
278 | { |
||
279 | return objectives; |
||
280 | } |
||
281 | |||
282 | public void setObjectives(1.5.0/docs/api/java/lang/String.html">String objectives) |
||
283 | { |
||
284 | this.objectives = objectives; |
||
285 | } |
||
286 | |||
204 | jmachado | 287 | public 1.5.0/docs/api/java/lang/String.html">String getProgramStreamId() |
203 | jmachado | 288 | { |
204 | jmachado | 289 | return programStreamId; |
203 | jmachado | 290 | } |
291 | |||
204 | jmachado | 292 | public void setProgramStreamId(1.5.0/docs/api/java/lang/String.html">String programStreamId) |
203 | jmachado | 293 | { |
204 | jmachado | 294 | this.programStreamId = programStreamId; |
203 | jmachado | 295 | } |
296 | |||
297 | public long getId() |
||
298 | { |
||
299 | return id; |
||
300 | } |
||
301 | |||
302 | public 1.5.0/docs/api/java/lang/String.html">String getName() |
||
303 | { |
||
304 | return name; |
||
305 | } |
||
306 | |||
307 | public 1.5.0/docs/api/java/lang/String.html">String getCode() |
||
308 | { |
||
309 | return code; |
||
310 | } |
||
311 | |||
206 | jmachado | 312 | public 1.5.0/docs/api/java/lang/String.html">String getSemestre() |
313 | { |
||
343 | jmachado | 314 | if(semestre == null) |
315 | { |
||
316 | logger.error("Unit" + getId() + " " + getName() + "" + " - " + getCourseName() + " " + getImportYear() + " with no SEMESTRE SET, returning S1"); |
||
317 | return "S1"; |
||
318 | } |
||
206 | jmachado | 319 | return semestre; |
320 | } |
||
321 | |||
322 | public void setSemestre(1.5.0/docs/api/java/lang/String.html">String semestre) |
||
323 | { |
||
324 | this.semestre = semestre; |
||
325 | } |
||
326 | |||
327 | public 1.5.0/docs/api/java/lang/String.html">String getImportYear() |
||
328 | { |
||
329 | return importYear; |
||
330 | } |
||
331 | |||
332 | public void setImportYear(1.5.0/docs/api/java/lang/String.html">String importYear) |
||
333 | { |
||
334 | this.importYear = importYear; |
||
335 | } |
||
336 | |||
203 | jmachado | 337 | public 1.5.0/docs/api/java/lang/String.html">String getCourseCode() |
338 | { |
||
339 | return courseCode; |
||
340 | } |
||
341 | |||
342 | public 1.5.0/docs/api/java/lang/String.html">String getCourseName() |
||
343 | { |
||
344 | return courseName; |
||
345 | } |
||
346 | |||
347 | public BlogView getBlog() |
||
348 | { |
||
349 | return blog; |
||
350 | } |
||
351 | |||
352 | |||
204 | jmachado | 353 | public int getProgramSize() |
354 | { |
||
355 | return programSize; |
||
356 | } |
||
357 | |||
358 | public void setProgramSize(int programSize) |
||
359 | { |
||
360 | this.programSize = programSize; |
||
361 | } |
||
362 | |||
363 | |||
364 | public 1.5.0/docs/api/java/lang/String.html">String getExtension() |
||
365 | { |
||
366 | return extension; |
||
367 | } |
||
368 | |||
369 | public void setExtension(1.5.0/docs/api/java/lang/String.html">String extension) |
||
370 | { |
||
371 | this.extension = extension; |
||
372 | } |
||
373 | |||
209 | jmachado | 374 | public List<AnnouncementView> getAnnouncements() |
203 | jmachado | 375 | { |
376 | return announcements; |
||
377 | } |
||
378 | |||
206 | jmachado | 379 | public Set<UserView> getTeachers() |
203 | jmachado | 380 | { |
381 | return teachers; |
||
382 | } |
||
383 | |||
206 | jmachado | 384 | public Set<UserView> getStudents() |
203 | jmachado | 385 | { |
386 | return students; |
||
387 | } |
||
204 | jmachado | 388 | |
389 | public boolean isOwnedBy(GenericUser u) |
||
390 | { |
||
208 | jmachado | 391 | return isOwnedBy(u, false); |
204 | jmachado | 392 | } |
214 | jmachado | 393 | |
208 | jmachado | 394 | public boolean isOwnedBy(GenericUser u, boolean transaction) |
395 | { |
||
396 | return u != null && u instanceof TeacherImpl && ((TeacherImpl)u).hasCourseUnit(getId(), transaction); |
||
397 | } |
||
204 | jmachado | 398 | |
399 | /** |
||
400 | * Not implemented can be variuous teachers |
||
401 | * @return null |
||
402 | * use isOwnedBy in this class |
||
403 | */ |
||
404 | public GenericUser getOwner() |
||
405 | { |
||
406 | return null; |
||
407 | } |
||
408 | |||
409 | /** |
||
410 | * Not implemented |
||
411 | * @return |
||
412 | */ |
||
413 | public List<String> getOwnerRoles() |
||
414 | { |
||
415 | return null; |
||
416 | } |
||
206 | jmachado | 417 | |
204 | jmachado | 418 | /** |
419 | * Not implemented |
||
420 | * @return |
||
421 | */ |
||
422 | public 1.5.0/docs/api/java/lang/String.html">String getChoosedOwnerRole() |
||
423 | { |
||
424 | return null; |
||
425 | } |
||
426 | |||
427 | public boolean isInternal() |
||
428 | { |
||
429 | return true; |
||
430 | } |
||
431 | |||
432 | public boolean isValid() |
||
433 | { |
||
434 | return true; |
||
435 | } |
||
206 | jmachado | 436 | |
437 | |||
343 | jmachado | 438 | public boolean isValidProgram() |
439 | { |
||
440 | return validProgram; |
||
441 | } |
||
206 | jmachado | 442 | |
343 | jmachado | 443 | public void setValidProgram(boolean validProgram) |
444 | { |
||
445 | this.validProgram = validProgram; |
||
446 | } |
||
447 | |||
448 | public UserView getValidatorUser() |
||
449 | { |
||
450 | return validatorUser; |
||
451 | } |
||
452 | |||
453 | public void setValidatorUser(UserView validatorUser) |
||
454 | { |
||
455 | this.validatorUser = validatorUser; |
||
456 | } |
||
457 | |||
458 | public 1.5.0/docs/api/java/lang/String.html">String getTeachersSnipet() |
||
459 | { |
||
460 | 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder strBuilder = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder(); |
||
461 | if(teachers != null && teachers.size() > 0) |
||
462 | { |
||
463 | for(UserView userView: teachers) |
||
464 | { |
||
465 | strBuilder |
||
466 | .append(" <a href=\"mailto:") |
||
467 | .append(userView.getEmail()) |
||
468 | .append("\">") |
||
469 | .append(userView.getName()) |
||
470 | .append("</a>") |
||
471 | .append(" "); |
||
472 | |||
473 | } |
||
474 | } |
||
475 | return strBuilder.toString(); |
||
476 | } |
||
203 | jmachado | 477 | } |