Rev 1967 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1814 | jmachado | 1 | package pt.estgp.estgweb.services.courses.coursereport.documentmodel; |
2 | |||
3 | import com.owlike.genson.Genson; |
||
4 | import com.owlike.genson.GensonBuilder; |
||
1877 | jmachado | 5 | import jomm.dao.impl.AbstractDao; |
1814 | jmachado | 6 | import org.apache.log4j.Logger; |
7 | import org.json.JSONException; |
||
8 | import org.json.JSONObject; |
||
1871 | jmachado | 9 | import pt.estgp.estgweb.domain.Course; |
1877 | jmachado | 10 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
1814 | jmachado | 11 | import pt.estgp.estgweb.domain.utils.JsonView; |
1830 | jmachado | 12 | import pt.estgp.estgweb.utils.documentBuilder.Document; |
13 | import pt.estgp.estgweb.utils.documentBuilder.DocumentSection; |
||
1814 | jmachado | 14 | |
15 | import java.util.Date; |
||
16 | import java.util.List; |
||
17 | |||
18 | /** |
||
19 | * Created by jorgemachado on 14/10/17. |
||
20 | */ |
||
1848 | jmachado | 21 | public class CourseReportDocument extends 5+0%2Fdocs%2Fapi+Document">Document implements JsonView |
1814 | jmachado | 22 | { |
1830 | jmachado | 23 | |
1848 | jmachado | 24 | 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(CourseReportDocument.class); |
1814 | jmachado | 25 | |
1871 | jmachado | 26 | private 1.5.0/docs/api/java/lang/String.html">String courseCode; |
27 | private 1.5.0/docs/api/java/lang/String.html">String courseName; |
||
28 | private 1.5.0/docs/api/java/lang/String.html">String year; |
||
29 | |||
1989 | grupo1 | 30 | private 1.5.0/docs/api/java/lang/String.html">String grau; |
1871 | jmachado | 31 | |
1989 | grupo1 | 32 | private 1.5.0/docs/api/java/lang/String.html">String nomeEscola; |
1871 | jmachado | 33 | |
1989 | grupo1 | 34 | public 1.5.0/docs/api/java/lang/String.html">String getGrau() { |
35 | return grau; |
||
36 | } |
||
37 | |||
38 | public void setGrau(1.5.0/docs/api/java/lang/String.html">String grau) { |
||
39 | this.grau = grau; |
||
40 | } |
||
41 | |||
42 | public 1.5.0/docs/api/java/lang/String.html">String getNomeEscola() { |
||
43 | return nomeEscola; |
||
44 | } |
||
45 | |||
46 | public void setNomeEscola(1.5.0/docs/api/java/lang/String.html">String nomeEscola) { |
||
47 | this.nomeEscola = nomeEscola; |
||
48 | } |
||
49 | |||
50 | |||
51 | |||
52 | |||
53 | |||
1848 | jmachado | 54 | public CourseReportDocument() |
1830 | jmachado | 55 | { |
1814 | jmachado | 56 | |
57 | } |
||
58 | |||
1871 | jmachado | 59 | public 1.5.0/docs/api/java/lang/String.html">String getCourseCode() { |
60 | return courseCode; |
||
61 | } |
||
62 | |||
63 | public void setCourseCode(1.5.0/docs/api/java/lang/String.html">String courseCode) { |
||
64 | this.courseCode = courseCode; |
||
65 | } |
||
66 | |||
67 | public 1.5.0/docs/api/java/lang/String.html">String getCourseName() { |
||
68 | return courseName; |
||
69 | } |
||
70 | |||
71 | public void setCourseName(1.5.0/docs/api/java/lang/String.html">String courseName) { |
||
72 | this.courseName = courseName; |
||
73 | } |
||
74 | |||
75 | public 1.5.0/docs/api/java/lang/String.html">String getYear() { |
||
76 | return year; |
||
77 | } |
||
78 | |||
79 | public void setYear(1.5.0/docs/api/java/lang/String.html">String year) { |
||
80 | this.year = year; |
||
81 | } |
||
82 | |||
83 | public void init(Course c,1.5.0/docs/api/java/lang/String.html">String year) |
||
1830 | jmachado | 84 | { |
1871 | jmachado | 85 | setYear(year); |
86 | setCourseCode(c.getCode()); |
||
87 | setCourseName(c.getName()); |
||
1989 | grupo1 | 88 | setNomeEscola(c.getDepartment().getCourseSchool().getName()); |
89 | setGrau(c.getDegree()); |
||
1830 | jmachado | 90 | |
91 | //1 - Introducao |
||
92 | IntroSection introSection = new IntroSection(); |
||
93 | introSection.init(); |
||
1877 | jmachado | 94 | |
1830 | jmachado | 95 | getSections().add(introSection); |
96 | |||
97 | //2 - Mapa Sintese dos Relatórios dos Responsáveis das UC's |
||
98 | ReportsUcSummarySection reportsUcSummarySection = new ReportsUcSummarySection(); |
||
99 | reportsUcSummarySection.init(); |
||
100 | getSections().add(reportsUcSummarySection); |
||
101 | |||
102 | //3 - Resultados da Aprendizagem |
||
103 | LearningResultsSection learningResultsSection = new LearningResultsSection(); |
||
104 | learningResultsSection.init(); |
||
105 | getSections().add(learningResultsSection); |
||
106 | |||
107 | //4 - Inquéritos |
||
108 | SurveysSection surveysSection = new SurveysSection(); |
||
109 | surveysSection.init(); |
||
110 | getSections().add(surveysSection); |
||
111 | |||
112 | //5 - Conclusões |
||
113 | ConclusionsSection conclusionsSection = new ConclusionsSection(); |
||
114 | conclusionsSection.init(); |
||
115 | getSections().add(conclusionsSection); |
||
116 | |||
117 | //5 - Unidades Curriculares |
||
118 | CourseUnitsReportsSection courseUnitsReportsSection = new CourseUnitsReportsSection(); |
||
119 | courseUnitsReportsSection.init(); |
||
120 | getSections().add(courseUnitsReportsSection); |
||
1814 | jmachado | 121 | } |
122 | |||
123 | |||
1830 | jmachado | 124 | |
125 | public DocumentSection findDocumentSection(1.5.0/docs/api/java/lang/Class.html">Class sectionClass) |
||
126 | { |
||
127 | if(getSections() != null) |
||
128 | for(DocumentSection section: getSections()) |
||
129 | { |
||
130 | if(section.getClass().equals(sectionClass)) |
||
131 | { |
||
132 | return section; |
||
133 | } |
||
134 | } |
||
135 | return null; |
||
136 | } |
||
137 | |||
138 | |||
139 | |||
140 | |||
141 | |||
1814 | jmachado | 142 | private static Genson gensonGenericLoad; |
143 | static{ |
||
144 | gensonGenericLoad = new GensonBuilder() |
||
1830 | jmachado | 145 | .useMethods(true) |
146 | .useFields(true) |
||
147 | .useRuntimeType(true) //para ignorar a CGLIB do courseUnitEvaluation |
||
1814 | jmachado | 148 | .useClassMetadata(true) |
149 | .useDateAsTimestamp(true) |
||
1830 | jmachado | 150 | .exclude(1.5.0/docs/api/java/lang/Class.html">Class.class) |
1814 | jmachado | 151 | .exclude(5+0%2Fdocs%2Fapi+Date">Date.class) |
152 | .exclude(java.sql.5+0%2Fdocs%2Fapi+Timestamp">Timestamp.class) |
||
153 | .exclude(java.sql.5+0%2Fdocs%2Fapi+Date">Date.class) |
||
154 | .create(); |
||
155 | } |
||
156 | |||
1848 | jmachado | 157 | public static CourseReportDocument fromJson(1.5.0/docs/api/java/lang/String.html">String json) |
1814 | jmachado | 158 | { |
1848 | jmachado | 159 | return gensonGenericLoad.deserialize(json,CourseReportDocument.class); |
1814 | jmachado | 160 | } |
161 | |||
162 | |||
163 | |||
164 | public List<String> getJsonExcludedProperties() { |
||
165 | return null; |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * Generic Json Object only for local class methods |
||
170 | * @return |
||
1830 | jmachado | 171 | * @throws org.json.JSONException |
1814 | jmachado | 172 | */ |
173 | public JSONObject toJsonObject() throws JSONException |
||
174 | { |
||
175 | return new JSONObject(toJson()); |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * * Generic Json Object only for local class methods |
||
180 | * @return |
||
181 | * @throws java.io.IOException |
||
182 | */ |
||
183 | public 1.5.0/docs/api/java/lang/String.html">String toJson() |
||
184 | { |
||
185 | return gensonGenericLoad.serialize(this); |
||
186 | } |
||
187 | |||
1877 | jmachado | 188 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) |
189 | { |
||
190 | CourseReportDocument d = new CourseReportDocument(); |
||
1830 | jmachado | 191 | |
1877 | jmachado | 192 | AbstractDao.getCurrentSession().beginTransaction(); |
1830 | jmachado | 193 | |
1877 | jmachado | 194 | List<Course> cursos = DaoFactory.getCourseDaoImpl().findAll(); |
195 | |||
196 | |||
197 | d.init(cursos.get(0),"201718"); |
||
198 | |||
199 | 1.5.0/docs/api/java/lang/String.html">String json = d.toJson(); |
||
200 | 1.5.0/docs/api/java/lang/System.html">System.out.println(json); |
||
201 | CourseReportDocument d2 = CourseReportDocument.fromJson(json); |
||
202 | 1.5.0/docs/api/java/lang/System.html">System.out.println(d2.toJson()); |
||
203 | |||
204 | AbstractDao.getCurrentSession().getTransaction().commit(); |
||
205 | } |
||
206 | |||
207 | |||
208 | |||
1814 | jmachado | 209 | } |