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