Rev 1312 | 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.services.courseunits; |
2 | |||
749 | jmachado | 3 | import org.apache.log4j.Logger; |
1312 | jmachado | 4 | import pt.estgp.estgweb.domain.*; |
749 | jmachado | 5 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
6 | import pt.estgp.estgweb.domain.views.AnnouncementView; |
||
7 | import pt.estgp.estgweb.domain.views.CourseUnitSummaryView; |
||
8 | import pt.estgp.estgweb.domain.views.CourseUnitView; |
||
9 | import pt.estgp.estgweb.domain.views.CourseView; |
||
10 | import pt.estgp.estgweb.services.data.RepositoryService; |
||
11 | import pt.estgp.estgweb.services.expceptions.ServiceException; |
||
203 | jmachado | 12 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
13 | |||
749 | jmachado | 14 | import java.util.ArrayList; |
203 | jmachado | 15 | import java.util.List; |
1312 | jmachado | 16 | import java.util.Set; |
203 | jmachado | 17 | |
18 | /* |
||
19 | * @author Goncalo Luiz gedl [AT] rnl [DOT] ist [DOT] utl [DOT] pt |
||
20 | * |
||
21 | * |
||
22 | * Created at 17/Out/2003 , 23:45:24 |
||
23 | * |
||
24 | */ |
||
25 | /** |
||
26 | * @author Jorge Machado |
||
27 | * |
||
28 | * |
||
29 | * Created at 17/Out/2003 , 23:45:24 |
||
30 | * |
||
31 | */ |
||
32 | public class LoadCourseUnitService implements IService |
||
33 | { |
||
34 | |||
204 | jmachado | 35 | RepositoryService repositoryService = new RepositoryService(); |
209 | jmachado | 36 | LoadCourseUnitAnnouncements loadCourseUnitAnnouncements = new LoadCourseUnitAnnouncements(); |
204 | jmachado | 37 | |
203 | jmachado | 38 | 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(LoadCourseUnitService.class); |
39 | |||
208 | jmachado | 40 | public CourseUnitView run(long id, boolean initTeachers, boolean initStudents, boolean initBlog, UserSession userSession) throws ServiceException |
203 | jmachado | 41 | { |
42 | CourseUnit c = DaoFactory.getCourseUnitDaoImpl().get(id); |
||
1350 | jmachado | 43 | return runCleared(id,initTeachers,initStudents,initBlog,userSession,DaoFactory.getCourseUnitDaoImpl().narrow(c)); |
44 | } |
||
45 | |||
46 | public CourseUnitView runCleared(long id, boolean initTeachers, boolean initStudents, boolean initBlog, UserSession userSession,CourseUnit c) throws ServiceException |
||
47 | { |
||
942 | jmachado | 48 | c.setCourseUnitEvaluation(DaoFactory.getCourseUnitEvaluationDaoImpl().narrow(c.getCourseUnitEvaluation())); |
49 | c.setCourseUnitProgram(DaoFactory.getCourseUnitProgramDaoImpl().narrow(c.getCourseUnitProgram())); |
||
206 | jmachado | 50 | |
203 | jmachado | 51 | if(c == null) |
52 | return null; |
||
969 | jmachado | 53 | |
208 | jmachado | 54 | CourseUnitView cV = new CourseUnitView(c,initTeachers,initStudents,initBlog); |
206 | jmachado | 55 | |
204 | jmachado | 56 | if(c.getProgramStreamId()!= null) |
57 | { |
||
58 | RepositoryFile repositoryFile = repositoryService.loadView(c.getProgramStreamId()); |
||
59 | if(repositoryFile != null) |
||
60 | { |
||
61 | cV.setProgramSize(repositoryFile.getLastVersion().getSize()/1024); |
||
62 | cV.setExtension(repositoryFile.getLastVersion().getExtension()); |
||
63 | } |
||
64 | } |
||
209 | jmachado | 65 | |
66 | if(initTeachers) |
||
67 | { |
||
68 | List<AnnouncementView> announcementViews = loadCourseUnitAnnouncements.run(id,userSession); |
||
69 | cV.setAnnouncements(announcementViews); |
||
358 | jmachado | 70 | |
71 | List<CourseUnitSummaryView> summaryViews = new ArrayList<CourseUnitSummaryView>(); |
||
72 | if(c.getSummaries() != null) |
||
73 | { |
||
74 | for(CourseUnitSummary summary: c.getSummaries()) |
||
75 | { |
||
76 | summaryViews.add(new CourseUnitSummaryView(summary)); |
||
77 | } |
||
78 | } |
||
79 | cV.setSummaries(summaryViews); |
||
209 | jmachado | 80 | } |
203 | jmachado | 81 | return cV; |
82 | } |
||
749 | jmachado | 83 | |
84 | |||
1350 | jmachado | 85 | public CourseUnitView loadCourseUnitViewAndCourse(long id, boolean initTeachers, boolean initStudents, boolean initBlog, boolean initCourseView, UserSession userSession,CourseUnitImpl clearedUnit) throws ServiceException |
749 | jmachado | 86 | { |
87 | |||
1350 | jmachado | 88 | CourseUnitView cV = runCleared(id, initTeachers, initStudents, initBlog, userSession, clearedUnit); |
749 | jmachado | 89 | if(initCourseView) |
90 | { |
||
91 | CourseView coV = new CourseView(cV.getCourseUnit().getCourse()); |
||
92 | cV.setCourseView(coV); |
||
93 | } |
||
94 | return cV; |
||
95 | } |
||
1148 | jmachado | 96 | |
1312 | jmachado | 97 | public Set<StudentImpl> loadStudents(long id, UserSession userSession) throws ServiceException |
98 | { |
||
99 | CourseUnit c = DaoFactory.getCourseUnitDaoImpl().get(id); |
||
1148 | jmachado | 100 | |
1312 | jmachado | 101 | Set<StudentImpl> students = c.getStudents(); |
102 | if(students != null) |
||
103 | for(Student s: students) |
||
104 | { |
||
105 | s.getName(); |
||
106 | } |
||
107 | return students; |
||
108 | } |
||
109 | |||
110 | public Set<TeacherImpl> loadTeachers(long id, UserSession userSession) throws ServiceException |
||
111 | { |
||
112 | CourseUnit c = DaoFactory.getCourseUnitDaoImpl().get(id); |
||
113 | |||
114 | Set<TeacherImpl> teachers = c.getTeachers(); |
||
115 | if(teachers != null) |
||
116 | for(TeacherImpl t: teachers) |
||
117 | { |
||
118 | t.getName(); |
||
119 | } |
||
120 | return teachers; |
||
121 | } |
||
122 | |||
123 | public Teacher loadResponsibleTeacher(long id, UserSession userSession) throws ServiceException |
||
124 | { |
||
125 | CourseUnit c = DaoFactory.getCourseUnitDaoImpl().get(id); |
||
126 | |||
127 | if(c.getResponsableTeacher() != null) |
||
128 | c.getResponsableTeacher().getName(); |
||
129 | |||
130 | return c.getResponsableTeacher(); |
||
131 | } |
||
132 | |||
203 | jmachado | 133 | } |