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