Rev 248 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
214 | jmachado | 1 | package pt.estgp.estgweb.services.courses; |
2 | |||
3 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
||
4 | import pt.estgp.estgweb.services.data.RepositoryService; |
||
5 | import pt.estgp.estgweb.services.courseunits.LoadCourseUnitAnnouncements; |
||
6 | import pt.estgp.estgweb.services.courseunits.LoadCourseUnitService; |
||
7 | import pt.estgp.estgweb.services.expceptions.ServiceException; |
||
8 | import pt.estgp.estgweb.domain.views.CourseUnitView; |
||
9 | import pt.estgp.estgweb.domain.views.AnnouncementView; |
||
10 | import pt.estgp.estgweb.domain.views.CourseView; |
||
11 | import pt.estgp.estgweb.domain.*; |
||
12 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
||
13 | import pt.estgp.estgweb.filters.chains.ResourceAccessControlEnum; |
||
248 | jmachado | 14 | import pt.estgp.estgweb.utils.Dom4jUtil; |
249 | jmachado | 15 | import pt.estgp.estgweb.utils.DatesUtils; |
248 | jmachado | 16 | import pt.estgp.estgweb.Globals; |
214 | jmachado | 17 | import org.apache.log4j.Logger; |
248 | jmachado | 18 | import org.dom4j.Document; |
19 | import org.dom4j.DocumentException; |
||
214 | jmachado | 20 | |
21 | import java.util.List; |
||
22 | import java.util.ArrayList; |
||
23 | import java.io.InputStream; |
||
248 | jmachado | 24 | import java.io.PrintWriter; |
25 | import java.io.StringWriter; |
||
26 | import java.net.MalformedURLException; |
||
214 | jmachado | 27 | |
28 | import jomm.utils.FilesUtils; |
||
29 | |||
30 | /* |
||
31 | * @author Goncalo Luiz gedl [AT] rnl [DOT] ist [DOT] utl [DOT] pt |
||
32 | * |
||
33 | * |
||
34 | * Created at 17/Out/2003 , 23:45:24 |
||
35 | * |
||
36 | */ |
||
37 | /** |
||
38 | * @author Jorge Machado |
||
39 | * |
||
40 | * |
||
41 | * Created at 17/Out/2003 , 23:45:24 |
||
42 | * |
||
43 | */ |
||
44 | public class CoursesService implements IService |
||
45 | { |
||
46 | 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(CoursesService.class); |
||
47 | |||
48 | RepositoryService repositoryService = new RepositoryService(); |
||
49 | |||
50 | |||
51 | public CourseView loadCourse(long id, boolean initUnits) throws ServiceException |
||
52 | { |
||
53 | Course c = DaoFactory.getCourseDaoImpl().get(id); |
||
54 | |||
55 | if(c != null) |
||
56 | { |
||
57 | CourseView cV = new CourseView(c,initUnits); |
||
58 | if(c.getStudiesPlan() != null) |
||
59 | { |
||
60 | RepositoryFileImpl repositoryFile = repositoryService.loadView(c.getStudiesPlan()); |
||
61 | cV.setStudiesPlan(repositoryFile); |
||
62 | } |
||
63 | |||
64 | return cV; |
||
65 | } |
||
66 | return null; |
||
67 | } |
||
68 | |||
69 | public CourseView loadCourseByCode(1.5.0/docs/api/java/lang/String.html">String code, boolean initUnits) throws ServiceException |
||
70 | { |
||
71 | Course c = DaoFactory.getCourseDaoImpl().findCourseByCode(code); |
||
72 | if(c != null) |
||
73 | { |
||
74 | CourseView cV = new CourseView(c,initUnits); |
||
75 | if(c.getStudiesPlan() != null) |
||
76 | { |
||
77 | RepositoryFileImpl repositoryFile = repositoryService.loadView(c.getStudiesPlan()); |
||
78 | cV.setStudiesPlan(repositoryFile); |
||
79 | } |
||
80 | return cV; |
||
81 | } |
||
82 | return null; |
||
83 | } |
||
84 | |||
85 | public CourseView submitCourse(CourseView courseView, |
||
86 | 5+0%2Fdocs%2Fapi+InputStream">InputStream stream, |
||
87 | 1.5.0/docs/api/java/lang/String.html">String name, |
||
88 | int size, |
||
89 | 1.5.0/docs/api/java/lang/String.html">String contentType, |
||
90 | UserSession userSession) throws ServiceException |
||
91 | { |
||
92 | Course c; |
||
93 | if(courseView.getId() > 0) |
||
94 | c = DaoFactory.getCourseDaoImpl().get(courseView.getId()); |
||
95 | else |
||
96 | { |
||
97 | c = DomainObjectFactory.createCourseImpl(); |
||
98 | DaoFactory.getCourseDaoImpl().save(c); |
||
99 | } |
||
100 | |||
248 | jmachado | 101 | 1.5.0/docs/api/java/lang/String.html">String htmlTrasformationResult = null; |
102 | |||
214 | jmachado | 103 | if(stream != null && size > 0) |
104 | { |
||
248 | jmachado | 105 | try |
106 | { |
||
107 | 5+0%2Fdocs%2Fapi+Document">Document dom = Dom4jUtil.parse(stream); |
||
108 | 1.5.0/docs/api/java/lang/String.html">String html = Dom4jUtil.styleDocument(dom, Globals.TEMPLATE_COURSE_XSL_PATH); |
||
109 | c.setCacheWebDocument(html); |
||
110 | } |
||
111 | catch (1.5.0/docs/api/java/lang/Exception.html">Exception e) |
||
112 | { |
||
113 | 1.5.0/docs/api/java/io/StringWriter.html">StringWriter writer = new 1.5.0/docs/api/java/io/StringWriter.html">StringWriter(); |
||
114 | 1.5.0/docs/api/java/io/PrintWriter.html">PrintWriter printWriter = new 1.5.0/docs/api/java/io/PrintWriter.html">PrintWriter(writer); |
||
115 | e.printStackTrace(printWriter); |
||
116 | htmlTrasformationResult = "<div class=\"error\"><pre>" + e.toString() + "\n" + printWriter.toString() + "</pre></div>"; |
||
117 | printWriter.close(); |
||
118 | } |
||
214 | jmachado | 119 | 1.5.0/docs/api/java/lang/String.html">String extension = FilesUtils.getExtension(name); |
120 | if(c.getStudiesPlan() == null) |
||
121 | { |
||
122 | 1.5.0/docs/api/java/lang/String.html">String identifier = repositoryService.storeRepositoryFile(stream, contentType, extension, size, name, "course.studies.plan" + c.getName(), ResourceAccessControlEnum.publicDomain,userSession); |
||
123 | c.setStudiesPlan(identifier); |
||
124 | } |
||
125 | else |
||
126 | { |
||
127 | repositoryService.updateRepositoryFile(c.getStudiesPlan(), stream, contentType, extension, size, name, "course.studies.plan " + c.getName(), ResourceAccessControlEnum.publicDomain); |
||
128 | } |
||
129 | } |
||
130 | courseView.persistViewInObject(c); |
||
248 | jmachado | 131 | CourseView cv = loadCourse(c.getId(),false); |
132 | cv.setHtmlResult(htmlTrasformationResult); |
||
133 | return cv; |
||
214 | jmachado | 134 | } |
135 | |||
136 | public List<CourseView> loadCourses() throws ServiceException |
||
137 | { |
||
138 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAllOrderByName(); |
||
139 | List<CourseView> courseViews = new ArrayList<CourseView>(); |
||
140 | for(Course c: courses) |
||
141 | { |
||
142 | CourseView courseView = new CourseView(c); |
||
143 | courseViews.add(courseView); |
||
144 | } |
||
145 | return courseViews; |
||
146 | } |
||
147 | |||
249 | jmachado | 148 | public List<CourseView> loadCoursesImportYear() throws ServiceException |
149 | { |
||
150 | 1.5.0/docs/api/java/lang/String.html">String importYearIntranet = DatesUtils.getImportYear(); |
||
151 | List<Course> courses = DaoFactory.getCourseDaoImpl().findAllOrderByName(importYearIntranet); |
||
152 | List<CourseView> courseViews = new ArrayList<CourseView>(); |
||
153 | for(Course c: courses) |
||
154 | { |
||
155 | CourseView courseView = new CourseView(c); |
||
156 | courseViews.add(courseView); |
||
157 | } |
||
158 | return courseViews; |
||
159 | } |
||
214 | jmachado | 160 | |
249 | jmachado | 161 | |
162 | |||
214 | jmachado | 163 | } |