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