Rev 1844 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1814 | jmachado | 1 | package pt.estgp.estgweb.services.courses; |
2 | |||
1830 | jmachado | 3 | |
1848 | jmachado | 4 | import jomm.dao.impl.AbstractDao; |
1830 | jmachado | 5 | import jomm.utils.StreamsUtils; |
1814 | jmachado | 6 | import org.apache.log4j.Logger; |
1830 | jmachado | 7 | import org.json.JSONArray; |
8 | import org.json.JSONException; |
||
9 | import org.json.JSONObject; |
||
1814 | jmachado | 10 | import pt.estgp.estgweb.domain.CourseUnit; |
1841 | jmachado | 11 | import pt.estgp.estgweb.domain.CourseUnitEvaluationImpl; |
1830 | jmachado | 12 | import pt.estgp.estgweb.domain.CourseUnitImpl; |
1841 | jmachado | 13 | import pt.estgp.estgweb.domain.DomainObjectFactory; |
1814 | jmachado | 14 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
1830 | jmachado | 15 | import pt.estgp.estgweb.services.courses.coursereport.CourseReportUtils; |
16 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.*; |
||
17 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.courseunitreport.CourseUnitSection; |
||
18 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components.UnitsLearningResultSemester; |
||
19 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components.UnitsLearningResultUc; |
||
20 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components.UnitsLearningResultYear; |
||
21 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components.UnitsLearningResultsTable; |
||
22 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.reportucsummary.CourseUnitDtpStat; |
||
23 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.reportucsummary.UnitDtpSemester; |
||
24 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.reportucsummary.UnitsDtpTable; |
||
25 | import pt.estgp.estgweb.services.courses.coursereport.documentmodel.surveys.SurveysResultsSection; |
||
26 | import pt.estgp.estgweb.services.questionarios.QuestionariosReportsService; |
||
27 | import pt.estgp.estgweb.services.questionarios.pedagogico.reportprocessors.utils.DataTable; |
||
28 | import pt.estgp.estgweb.utils.Globals; |
||
29 | import pt.estgp.estgweb.utils.documentBuilder.DocumentSection; |
||
30 | import pt.estgp.estgweb.utils.documentBuilder.QuestionariosDataTableComponent; |
||
1814 | jmachado | 31 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
32 | |||
1830 | jmachado | 33 | import java.io.IOException; |
34 | import java.io.InputStream; |
||
35 | import java.net.URL; |
||
1848 | jmachado | 36 | import java.net.URLConnection; |
1830 | jmachado | 37 | import java.util.*; |
1814 | jmachado | 38 | |
39 | /** |
||
40 | * Created by jorgemachado on 14/10/17. |
||
41 | */ |
||
42 | public class CourseReportServices implements IService |
||
43 | { |
||
44 | 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(CourseReportServices.class); |
||
45 | |||
1830 | jmachado | 46 | |
47 | |||
48 | |||
49 | |||
50 | |||
51 | |||
52 | /****************************************************************************/ |
||
53 | /* SERVICOS CORE DOS REPORTS |
||
54 | /****************************************************************************/ |
||
55 | |||
56 | |||
57 | |||
58 | |||
59 | /** |
||
60 | * |
||
61 | * @param courseCode |
||
62 | * @param year |
||
63 | * @return |
||
64 | * @throws IOException |
||
65 | * @throws JSONException |
||
66 | */ |
||
1848 | jmachado | 67 | public CourseReportDocument createNewCourseReportDocument(1.5.0/docs/api/java/lang/String.html">String courseCode,1.5.0/docs/api/java/lang/String.html">String year) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException |
1830 | jmachado | 68 | { |
1848 | jmachado | 69 | CourseReportDocument reportCourseDocument = new CourseReportDocument(); |
1830 | jmachado | 70 | reportCourseDocument.init(); |
71 | |||
72 | |||
73 | //FIRST SERVICE TO CALL TO OBTAIN UNITS AND EVALUATIONS |
||
74 | //THIS IS THE BASE FOR THE REMAIN SERVICE CALLS |
||
1841 | jmachado | 75 | List<DocumentSection> courseUnitSections = updateCleanCourseUnitSections(courseCode, year, reportCourseDocument); |
1830 | jmachado | 76 | |
77 | //A tabela de resultados globais não vai ser utilizada |
||
1841 | jmachado | 78 | //PARA CORRER ESTE SERVICO A PARTIR DA INTERFACE É PRECISO |
79 | //PERCEBER QUE DEPENDE DO SERVICO DE UPDATE DAS SECOES DAS COURSEUNITS |
||
1830 | jmachado | 80 | UnitsLearningResultsTable unitsLearningResultsTable = updateCleanLearningResultsFromCourseUnitsSections(reportCourseDocument); |
81 | |||
82 | |||
83 | //Atualiza no DOC a tabela de analise DTP |
||
84 | UnitsDtpTable unitsDtpTable = updateDtpStatsTable4Course(reportCourseDocument, courseCode, year); |
||
85 | |||
86 | |||
87 | //Atualiza as tabelas dos Quesitonários pedagogicos |
||
88 | SurveysResultsSection surveysResultsSection = updateSurveysDataTables(courseCode, year, reportCourseDocument); |
||
89 | |||
90 | |||
91 | return reportCourseDocument; |
||
92 | } |
||
93 | |||
1848 | jmachado | 94 | public SurveysResultsSection updateSurveysDataTables(1.5.0/docs/api/java/lang/String.html">String courseCode, 1.5.0/docs/api/java/lang/String.html">String year, CourseReportDocument reportCourseDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException { |
1830 | jmachado | 95 | SurveysSection surveysSection = (SurveysSection) reportCourseDocument.findDocumentSection(SurveysSection.class); |
1848 | jmachado | 96 | SurveysResultsSection surveysResultsSection = (SurveysResultsSection) surveysSection.findSection(SurveysResultsSection.class); |
1830 | jmachado | 97 | QuestionariosDataTableComponent dataTableComponentS1 = (QuestionariosDataTableComponent) surveysResultsSection.getComponents().get(0); |
98 | QuestionariosDataTableComponent dataTableComponentS2 = (QuestionariosDataTableComponent) surveysResultsSection.getComponents().get(1); |
||
99 | |||
100 | QuestionariosReportsService questionariosReportsService = new QuestionariosReportsService(); |
||
101 | 1.5.0/docs/api/java/lang/String.html">String jsonDataTableS1 = questionariosReportsService.loadReportUnidadesSalasJson(courseCode,year,"S1"); |
||
102 | 1.5.0/docs/api/java/lang/String.html">String jsonDataTableS2 = questionariosReportsService.loadReportUnidadesSalasJson(courseCode,year,"S2"); |
||
103 | DataTable dataTableS1 = DataTable.fromJson(jsonDataTableS1); |
||
104 | DataTable dataTableS2 = DataTable.fromJson(jsonDataTableS2); |
||
105 | dataTableComponentS1.setDataTable(dataTableS1); |
||
106 | dataTableComponentS2.setDataTable(dataTableS2); |
||
107 | return surveysResultsSection; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Este serviço atualiza a tabela de resultados de aprendizagem com base nas courseunitssections |
||
112 | * @param reportCourseDocument |
||
113 | * @return UnitsLearningResultsTable |
||
114 | */ |
||
1848 | jmachado | 115 | public UnitsLearningResultsTable updateCleanLearningResultsFromCourseUnitsSections(CourseReportDocument reportCourseDocument) |
1841 | jmachado | 116 | { |
1830 | jmachado | 117 | CourseUnitsReportsSection unitReportsSection = (CourseUnitsReportsSection) reportCourseDocument.findDocumentSection(CourseUnitsReportsSection.class); |
118 | |||
119 | LearningResultsSection learningResultsSection = (LearningResultsSection) reportCourseDocument.findDocumentSection(LearningResultsSection.class); |
||
120 | UnitsLearningResultsTable learningResultsTable = (UnitsLearningResultsTable) learningResultsSection.findDocComponent(UnitsLearningResultsTable.class); |
||
121 | |||
122 | Map<Integer,UnitsLearningResultYear> anosPlano = new HashMap<Integer, UnitsLearningResultYear>(); |
||
123 | Map<String,UnitsLearningResultSemester> anoSemestre = new HashMap<String, UnitsLearningResultSemester>(); |
||
1848 | jmachado | 124 | for(DocumentSection subSection : unitReportsSection.getSections()) |
1830 | jmachado | 125 | { |
126 | CourseUnitSection unitSection = (CourseUnitSection) subSection; |
||
127 | int anoPlano = unitSection.getAnoPlano(); |
||
128 | UnitsLearningResultYear anoFound = anosPlano.get(anoPlano); |
||
129 | if(anoFound == null) |
||
1814 | jmachado | 130 | { |
1830 | jmachado | 131 | anoFound = new UnitsLearningResultYear(anoPlano); |
132 | anosPlano.put(anoPlano,anoFound); |
||
133 | learningResultsTable.getYears().add(anoFound); |
||
1814 | jmachado | 134 | } |
135 | |||
1830 | jmachado | 136 | 1.5.0/docs/api/java/lang/String.html">String semestreCode = ((CourseUnitSection) subSection).getPeriod(); |
137 | UnitsLearningResultSemester semestreFound = anoSemestre.get(anoPlano + "$" + semestreCode); |
||
138 | if(semestreFound == null) |
||
1814 | jmachado | 139 | { |
1830 | jmachado | 140 | semestreFound = new UnitsLearningResultSemester(semestreCode); |
141 | anoSemestre.put(anoPlano + "$" + semestreCode,semestreFound); |
||
142 | anoFound.getSemesters().add(semestreFound); |
||
1814 | jmachado | 143 | } |
1830 | jmachado | 144 | |
145 | UnitsLearningResultUc uc = new UnitsLearningResultUc(); |
||
146 | uc.setPeriod(semestreCode); |
||
147 | uc.setName(unitSection.getName()); |
||
148 | uc.setSigesCode(unitSection.getSigesCode()); |
||
149 | if(unitSection.getCourseUnitEvaluation() != null) |
||
150 | { |
||
151 | |||
1843 | jmachado | 152 | uc.setCumprimentoProgramaPercent(unitSection.getCourseUnitEvaluation().getCumprimentoProgramaPercent()); |
1841 | jmachado | 153 | uc.setAlunosInscritos(unitSection.getCourseUnitEvaluation().getNumAlunosInscritos()); |
154 | |||
1830 | jmachado | 155 | uc.setAprovados1013(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1013()); |
156 | uc.setAprovados1416(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1416()); |
||
157 | uc.setAprovados1720(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1720()); |
||
158 | uc.setSemElementos(unitSection.getCourseUnitEvaluation().getNumAlunosSemElementosAvaliacao()); |
||
159 | uc.setAprovados(unitSection.getCourseUnitEvaluation().getNumAlunosAprovTotal()); |
||
160 | uc.setReprovados(unitSection.getCourseUnitEvaluation().getNumAlunosReprovados()); |
||
161 | |||
162 | if(uc.getAlunosInscritos() > 0) |
||
163 | { |
||
164 | uc.setAprovadosPercent((float) (uc.getAprovados() * 100.0 / uc.getAlunosInscritos())); |
||
165 | uc.setReprovadosPercent((float) (uc.getReprovados() * 100.0 / uc.getAlunosInscritos())); |
||
166 | uc.setSemElementosPercent((float) (uc.getSemElementos() * 100.0 / uc.getAlunosInscritos())); |
||
167 | } |
||
168 | |||
169 | if(uc.getAprovados() > 0) |
||
170 | { |
||
171 | uc.setAprovados1013Percent((float) (uc.getAprovados1013() * 100.0 / uc.getAprovados())); |
||
172 | uc.setAprovados1416Percent((float) (uc.getAprovados1416() * 100.0 / uc.getAprovados())); |
||
173 | uc.setAprovados1720Percent((float) (uc.getAprovados1720() * 100.0 / uc.getAprovados())); |
||
174 | } |
||
175 | } |
||
176 | semestreFound.getUcs().add(uc); |
||
1814 | jmachado | 177 | } |
1830 | jmachado | 178 | |
179 | 1.5.0/docs/api/java/util/Collections.html">Collections.sort(learningResultsTable.getYears(), new Comparator<UnitsLearningResultYear>() { |
||
180 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
181 | public int compare(UnitsLearningResultYear o1, UnitsLearningResultYear o2) { |
||
182 | return o1.getAno() - o2.getAno(); |
||
183 | } |
||
184 | }); |
||
185 | |||
186 | for(UnitsLearningResultYear learningYearLine: learningResultsTable.getYears()) |
||
187 | { |
||
188 | 1.5.0/docs/api/java/util/Collections.html">Collections.sort(learningYearLine.getSemesters(),new Comparator<UnitsLearningResultSemester>() { |
||
189 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
190 | public int compare(UnitsLearningResultSemester o1, UnitsLearningResultSemester o2) { |
||
191 | return o1.getSemestre().compareTo(o2.getSemestre()); |
||
192 | } |
||
193 | }); |
||
194 | } |
||
195 | |||
1841 | jmachado | 196 | |
197 | //UPDATE TOTAIS DE SEMESTRES E DE ANOS |
||
1830 | jmachado | 198 | float totalCumProgPercentGlobal = 0; |
199 | int totalInscritosGlobal = 0; |
||
200 | float totalReprovadosPercentGlobal = 0; |
||
201 | float totalAprovadosPercentGlobal = 0; |
||
202 | float totalSemElementosPercentGlobal = 0; |
||
203 | int totalAprovados1013PercentGlobal = 0; |
||
204 | float totalAprovados1416PercentGlobal = 0; |
||
205 | float totalAprovados1720PercentGlobal = 0; |
||
206 | for(UnitsLearningResultYear learningYearLine: learningResultsTable.getYears()) |
||
207 | { |
||
208 | float totalCumProgPercentAno = 0; |
||
209 | int totalInscritosAno = 0; |
||
210 | float totalReprovadosPercentAno = 0; |
||
211 | float totalAprovadosPercentAno = 0; |
||
212 | float totalSemElementosPercentAno = 0; |
||
213 | int totalAprovados1013PercentAno = 0; |
||
214 | float totalAprovados1416PercentAno = 0; |
||
215 | float totalAprovados1720PercentAno = 0; |
||
216 | |||
217 | for(UnitsLearningResultSemester semester: learningYearLine.getSemesters()) |
||
218 | { |
||
219 | float totalCumProgPercent = 0; |
||
220 | int totalInscritos = 0; |
||
221 | float totalReprovadosPercent = 0; |
||
222 | float totalAprovadosPercent = 0; |
||
223 | float totalSemElementosPercent = 0; |
||
224 | int totalAprovados1013Percent = 0; |
||
225 | float totalAprovados1416Percent = 0; |
||
226 | float totalAprovados1720Percent = 0; |
||
227 | for(UnitsLearningResultUc uc: semester.getUcs()) |
||
228 | { |
||
229 | totalCumProgPercent += uc.getCumprimentoProgramaPercent(); |
||
230 | totalInscritos += uc.getAlunosInscritos(); |
||
231 | totalAprovadosPercent += uc.getAprovadosPercent(); |
||
232 | totalReprovadosPercent += uc.getReprovadosPercent(); |
||
233 | totalSemElementosPercent += uc.getSemElementosPercent(); |
||
234 | totalAprovados1013Percent += uc.getAprovados1013(); |
||
235 | totalAprovados1416Percent += uc.getAprovados1416(); |
||
236 | totalAprovados1720Percent += uc.getAprovados1720(); |
||
237 | } |
||
238 | //media de inscritos |
||
239 | if(semester.getUcs().size() > 0) |
||
240 | { |
||
241 | semester.setCumprimentoProgramaPercent( totalCumProgPercent / ((float)semester.getUcs().size())); |
||
242 | semester.setAlunosInscritos( totalInscritos / (semester.getUcs().size())); |
||
243 | semester.setAprovadosPercent( totalAprovadosPercent / ((float)semester.getUcs().size())); |
||
244 | semester.setReprovadosPercent( totalReprovadosPercent / ((float)semester.getUcs().size())); |
||
245 | semester.setSemElementosPercent( totalSemElementosPercent / ((float)semester.getUcs().size())); |
||
246 | semester.setAprovados1013Percent( totalAprovados1013Percent / ((float)semester.getUcs().size())); |
||
247 | semester.setAprovados1416Percent( totalAprovados1416Percent / ((float)semester.getUcs().size())); |
||
248 | semester.setAprovados1720Percent( totalAprovados1720Percent / ((float)semester.getUcs().size())); |
||
249 | } |
||
250 | totalCumProgPercentAno += semester.getCumprimentoProgramaPercent(); |
||
251 | totalInscritosAno += semester.getAlunosInscritos(); |
||
252 | totalAprovadosPercentAno += semester.getAprovadosPercent(); |
||
253 | totalReprovadosPercentAno += semester.getReprovadosPercent(); |
||
254 | totalSemElementosPercentAno += semester.getSemElementosPercent(); |
||
255 | totalAprovados1013PercentAno += semester.getAprovados1013(); |
||
256 | totalAprovados1416PercentAno += semester.getAprovados1416(); |
||
257 | totalAprovados1720PercentAno += semester.getAprovados1720(); |
||
258 | } |
||
259 | //media de inscritos |
||
260 | if(learningYearLine.getSemesters().size() > 0) |
||
261 | { |
||
262 | learningYearLine.setCumprimentoProgramaPercent( totalCumProgPercentAno / ((float)learningYearLine.getSemesters().size())); |
||
263 | learningYearLine.setAlunosInscritos( totalInscritosAno / (learningYearLine.getSemesters().size())); |
||
264 | learningYearLine.setAprovadosPercent( totalAprovadosPercentAno / ((float)learningYearLine.getSemesters().size())); |
||
265 | learningYearLine.setReprovadosPercent( totalReprovadosPercentAno / ((float)learningYearLine.getSemesters().size())); |
||
266 | learningYearLine.setSemElementosPercent( totalSemElementosPercentAno / ((float)learningYearLine.getSemesters().size())); |
||
267 | learningYearLine.setAprovados1013Percent( totalAprovados1013PercentAno / ((float)learningYearLine.getSemesters().size())); |
||
268 | learningYearLine.setAprovados1416Percent( totalAprovados1416PercentAno / ((float)learningYearLine.getSemesters().size())); |
||
269 | learningYearLine.setAprovados1720Percent( totalAprovados1720PercentAno / ((float)learningYearLine.getSemesters().size())); |
||
270 | } |
||
271 | totalCumProgPercentGlobal += learningYearLine.getCumprimentoProgramaPercent(); |
||
272 | totalInscritosGlobal += learningYearLine.getAlunosInscritos(); |
||
273 | totalAprovadosPercentGlobal += learningYearLine.getAprovadosPercent(); |
||
274 | totalReprovadosPercentGlobal += learningYearLine.getReprovadosPercent(); |
||
275 | totalSemElementosPercentGlobal += learningYearLine.getSemElementosPercent(); |
||
276 | totalAprovados1013PercentGlobal += learningYearLine.getAprovados1013(); |
||
277 | totalAprovados1416PercentGlobal += learningYearLine.getAprovados1416(); |
||
278 | totalAprovados1720PercentGlobal += learningYearLine.getAprovados1720(); |
||
279 | } |
||
280 | |||
281 | if(learningResultsTable.getYears().size() > 0) |
||
282 | { |
||
283 | learningResultsTable.setCumprimentoProgramaPercent( totalCumProgPercentGlobal / ((float)learningResultsTable.getYears().size())); |
||
284 | learningResultsTable.setAlunosInscritos( totalInscritosGlobal / (learningResultsTable.getYears().size())); |
||
285 | learningResultsTable.setAprovadosPercent( totalAprovadosPercentGlobal / ((float)learningResultsTable.getYears().size())); |
||
286 | learningResultsTable.setReprovadosPercent( totalReprovadosPercentGlobal / ((float)learningResultsTable.getYears().size())); |
||
287 | learningResultsTable.setSemElementosPercent( totalSemElementosPercentGlobal / ((float)learningResultsTable.getYears().size())); |
||
288 | learningResultsTable.setAprovados1013Percent( totalAprovados1013PercentGlobal / ((float)learningResultsTable.getYears().size())); |
||
289 | learningResultsTable.setAprovados1416Percent( totalAprovados1416PercentGlobal / ((float)learningResultsTable.getYears().size())); |
||
290 | learningResultsTable.setAprovados1720Percent( totalAprovados1720PercentGlobal / ((float)learningResultsTable.getYears().size())); |
||
291 | } |
||
292 | |||
293 | |||
294 | |||
295 | |||
296 | return learningResultsTable; |
||
297 | //CRIAR A TABELA DE RESUTLADOS GLOBAIS GERAIS COMO UM RESUMO DA ANTERIOR |
||
298 | /*for(UnitsLearningResultYear learningYearLine: learningResultsTable.getYears()) |
||
299 | { |
||
300 | |||
301 | }*/ |
||
1814 | jmachado | 302 | } |
303 | |||
1830 | jmachado | 304 | |
305 | /** |
||
1848 | jmachado | 306 | * Gera uma tabela de estatisticas dos DTP recorrendo ao servico WS de |
307 | * load de tabelas DTP, caso o serviço nao devolva unidades são criadas novas |
||
308 | * com os valores a falso. |
||
309 | * |
||
310 | * @param courseCode |
||
311 | * @param year |
||
312 | * @return UnitsDtpTable |
||
313 | * @throws IOException |
||
314 | * @throws JSONException |
||
315 | */ |
||
316 | public UnitsDtpTable updateDtpStatsTable4Course(CourseReportDocument reportCourseDocument, 1.5.0/docs/api/java/lang/String.html">String courseCode, 1.5.0/docs/api/java/lang/String.html">String year) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException |
||
317 | { |
||
318 | |||
319 | ReportsUcSummarySection reportsUcSummarySection = (ReportsUcSummarySection) reportCourseDocument.findDocumentSection(ReportsUcSummarySection.class); |
||
320 | UnitsDtpTable unitsDtpTable = (UnitsDtpTable) reportsUcSummarySection.findDocComponent(UnitsDtpTable.class); |
||
321 | UnitDtpSemester semester1 = new UnitDtpSemester(); |
||
322 | UnitDtpSemester semester2 = new UnitDtpSemester(); |
||
323 | unitsDtpTable.setSemester1(semester1); |
||
324 | unitsDtpTable.setSemester2(semester2); |
||
325 | |||
326 | List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
||
327 | |||
328 | CourseUnitDtpStat[] statsLoaded; |
||
329 | try |
||
330 | { |
||
331 | 1.5.0/docs/api/java/lang/String.html">String json = loadCourseUnitDtpStats(courseCode,year); |
||
332 | JSONObject response = new JSONObject(json); |
||
333 | JSONArray stats = (JSONArray) response.get("dtpstats"); |
||
334 | statsLoaded = CourseUnitDtpStat.fromJson(stats); |
||
335 | } |
||
336 | catch(1.5.0/docs/api/java/lang/Exception.html">Exception e) |
||
337 | { |
||
338 | logger.error(e,e); |
||
339 | statsLoaded = new CourseUnitDtpStat[0]; |
||
340 | } |
||
341 | |||
342 | |||
343 | for(CourseUnit cu :units) |
||
344 | { |
||
345 | CourseUnitDtpStat statFound = CourseReportUtils.findCourseUnitDtpStat(statsLoaded, (CourseUnitImpl) cu); |
||
346 | if(statFound == null) |
||
347 | { |
||
348 | statFound = CourseReportUtils.createCourseUnitDtpStat(cu); |
||
349 | } |
||
350 | |||
351 | if(((CourseUnitImpl) cu).getSemestreAbsolutoS1S2().equals("S1")) |
||
352 | semester1.getCourseUnitDtpStats().add(statFound); |
||
353 | else |
||
354 | semester2.getCourseUnitDtpStats().add(statFound); |
||
355 | } |
||
356 | |||
357 | return unitsDtpTable; |
||
358 | |||
359 | } |
||
360 | |||
361 | /** |
||
1830 | jmachado | 362 | * Update course unit sections with reports, this method dows not change learning results table |
363 | * values from learning results stays in unit but does not change learning results Table |
||
364 | * @param courseCode |
||
365 | * @param year |
||
366 | * @param reportCourseDocument |
||
367 | * @throws JSONException |
||
368 | * @throws IOException |
||
369 | * @return a list of CourseUnitSection |
||
370 | */ |
||
1848 | jmachado | 371 | public List<DocumentSection> updateCleanCourseUnitSections(1.5.0/docs/api/java/lang/String.html">String courseCode, 1.5.0/docs/api/java/lang/String.html">String year, CourseReportDocument reportCourseDocument) throws JSONException, 1.5.0/docs/api/java/io/IOException.html">IOException { |
1841 | jmachado | 372 | |
373 | List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
||
374 | |||
1848 | jmachado | 375 | CourseUnitsReportsSection unitReportsSection = (CourseUnitsReportsSection) reportCourseDocument.findDocumentSection(CourseUnitsReportsSection.class); |
376 | CourseUnitSection[] courseUnitSections = null; |
||
377 | try{ |
||
378 | 1.5.0/docs/api/java/lang/String.html">String courseUnitSectionsJson = loadCourseEvaluationSections(courseCode,year); |
||
379 | JSONObject object = new JSONObject(courseUnitSectionsJson); |
||
380 | JSONArray evaluations = object.getJSONArray("evaluations"); |
||
381 | courseUnitSections = CourseUnitSection.fromJsonArray(evaluations.toString()); |
||
382 | } |
||
383 | catch(1.5.0/docs/api/java/lang/Exception.html">Exception e) |
||
384 | { |
||
385 | logger.error(e,e); |
||
386 | courseUnitSections = new CourseUnitSection[0]; |
||
387 | } |
||
1830 | jmachado | 388 | |
1848 | jmachado | 389 | |
1830 | jmachado | 390 | List<DocumentSection> subSections = new ArrayList<DocumentSection>(); |
1848 | jmachado | 391 | unitReportsSection.setSections(subSections); |
1830 | jmachado | 392 | for(CourseUnit cu :units) |
393 | { |
||
394 | CourseUnitSection sectionFound = CourseReportUtils.findCourseUnitSection(courseUnitSections, (CourseUnitImpl) cu); |
||
395 | if(sectionFound == null) |
||
396 | { |
||
397 | sectionFound = CourseReportUtils.createCourseUnitEvaluationSection((CourseUnitImpl) cu); |
||
398 | } |
||
1841 | jmachado | 399 | if(sectionFound.getCourseUnitEvaluation() == null) |
400 | { |
||
401 | CourseUnitEvaluationImpl courseUnitEvaluation = DomainObjectFactory.createCourseUnitEvaluationImpl(); |
||
402 | courseUnitEvaluation.setAutoGeneratedCourseReport(true); |
||
403 | DaoFactory.getCourseUnitEvaluationDaoImpl().save(courseUnitEvaluation); |
||
404 | cu.setCourseUnitEvaluation(courseUnitEvaluation); |
||
405 | sectionFound.setCourseUnitEvaluation(courseUnitEvaluation); |
||
406 | } |
||
1848 | jmachado | 407 | unitReportsSection.getSections().add(sectionFound); |
1830 | jmachado | 408 | } |
409 | return subSections; |
||
410 | } |
||
411 | |||
412 | |||
413 | |||
414 | public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException { |
||
1848 | jmachado | 415 | AbstractDao.getCurrentSession().beginTransaction(); |
1830 | jmachado | 416 | |
1848 | jmachado | 417 | CourseReportDocument reportCourseDocument = new CourseReportServices().createNewCourseReportDocument("44","201617"); |
1830 | jmachado | 418 | 1.5.0/docs/api/java/lang/System.html">System.out.println(reportCourseDocument.toJson()); |
1848 | jmachado | 419 | AbstractDao.getCurrentSession().getTransaction().commit(); |
1844 | jmachado | 420 | |
421 | //System.setProperty("javax.net.ssl.trustStore", "/JORGE/COPIAS/.keystore"); |
||
422 | //System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); |
||
423 | |||
1848 | jmachado | 424 | /*URL url = new URL("http://pae.ipportalegre.pt/wsjson/api/app/ws-course-pedagogic-results-list?code=44&year=201617&period=S1"); |
1844 | jmachado | 425 | |
426 | |||
427 | |||
1848 | jmachado | 428 | System.out.println(StreamsUtils.readString(url.openStream()));*/ |
1830 | jmachado | 429 | } |
430 | |||
431 | /* |
||
432 | |||
433 | public String loadUnitsAndCreateLearningResultsTables4Course(String courseCode, String year) throws IOException, JSONException |
||
434 | { |
||
435 | |||
436 | } |
||
437 | */ |
||
438 | //TODO loadUnitsAndCreateLearningResultsTables4Course |
||
439 | //HIPOTESE DEVOLVER DOIS OBJECTOS |
||
440 | //SERVICO DE ARRANQUE |
||
441 | //DEVOLVE UM REPORT DOCUMENT E O CHAMADOR USA O QUE QUISER |
||
442 | //A GERACAO DE GRAFICOS FAZ-SE APENAS A PEDIDO |
||
443 | |||
444 | // SE ELE PEDIR PARA ATUALIZAR TUDO CARREGA-SE UNIDADES E TABELAS NU DOC NOVO |
||
445 | // E NO BROWSER SUBSTITUI-SE ESSES ELEMENTOS NOS ANTIGOS a seccao das unidades |
||
446 | // e as as tabelas |
||
447 | |||
448 | |||
449 | |||
450 | |||
451 | |||
452 | |||
453 | |||
454 | |||
455 | |||
456 | /****************************************************************************/ |
||
457 | /* SERVICOS WS-API |
||
458 | /****************************************************************************/ |
||
459 | |||
460 | |||
461 | /** |
||
462 | * This service loads a list of course units given course code and year |
||
463 | * with dtp stats codes pre-filled |
||
464 | * @param courseCode |
||
465 | * @param year |
||
466 | * @return |
||
467 | * @throws JSONException |
||
468 | * @throws IOException |
||
469 | */ |
||
470 | public 1.5.0/docs/api/java/lang/String.html">String loadCourseUnitDtpStats(1.5.0/docs/api/java/lang/String.html">String courseCode,1.5.0/docs/api/java/lang/String.html">String year) throws JSONException, 1.5.0/docs/api/java/io/IOException.html">IOException { |
||
471 | |||
472 | |||
473 | if(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_DTP_STATS.indexOf("localhost")>=0) |
||
474 | { |
||
475 | JSONArray array = new JSONArray(); |
||
476 | List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
||
477 | for(CourseUnit cu: units) |
||
478 | { |
||
479 | CourseUnitDtpStat stat = CourseReportUtils.createCourseUnitDtpStat(cu); |
||
480 | //sections.add(courseUnitSection); |
||
481 | array.put(stat.toJsonObject()); |
||
482 | } |
||
483 | |||
484 | JSONObject obj = new JSONObject(); |
||
485 | obj.put("dtpstats",array); |
||
486 | |||
487 | return obj.toString(); |
||
488 | } |
||
489 | else |
||
490 | { |
||
1848 | jmachado | 491 | 1.5.0/docs/api/java/lang/String.html">String serviceUrl = Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_DTP_STATS + "?code=" + courseCode + "&year=" + year; |
492 | 1.5.0/docs/api/java/lang/String.html">String json = "{ dtpstats : [] }"; |
||
493 | try{ |
||
494 | 1.5.0/docs/api/java/net/URL.html">URL url = new 1.5.0/docs/api/java/net/URL.html">URL(serviceUrl); |
||
1830 | jmachado | 495 | |
1848 | jmachado | 496 | 1.5.0/docs/api/java/net/URLConnection.html">URLConnection conn = url.openConnection(); |
497 | 5+0%2Fdocs%2Fapi+InputStream">InputStream is = conn.getInputStream(); |
||
498 | |||
499 | json = StreamsUtils.readString(is); |
||
500 | is.close(); |
||
501 | }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
502 | { |
||
503 | logger.error("Connecting " + serviceUrl,e); |
||
504 | return json; |
||
505 | } |
||
1830 | jmachado | 506 | JSONObject jsonObject = new JSONObject(json); |
1837 | jmachado | 507 | return jsonObject.get("response").toString(); |
1830 | jmachado | 508 | } |
509 | } |
||
510 | |||
511 | |||
512 | |||
513 | |||
514 | /** |
||
515 | * |
||
516 | * Para um determinado curso e ano o serviço faz uma listagem de todas as suas unidades curriculares |
||
517 | * e lista a sua informação básica juntamente com o relatório de avaliação disponivel |
||
518 | * O serviço adiciona ainda o Ano de cada unidade por inspeção do Plano de Estudos |
||
519 | * caso a unidade não seja encontrada no Plano de estudos o ano irá ser preenchido com -1 |
||
520 | * |
||
521 | * @param courseCode codigo Siges na base de dados |
||
522 | * @param year 201617, 201718 |
||
523 | * @return String JSONObject with a JSON ARRAY of List<CourseUnitSection> |
||
524 | */ |
||
525 | public 1.5.0/docs/api/java/lang/String.html">String loadCourseEvaluationSections(1.5.0/docs/api/java/lang/String.html">String courseCode,1.5.0/docs/api/java/lang/String.html">String year) throws JSONException, 1.5.0/docs/api/java/io/IOException.html">IOException { |
||
526 | |||
527 | |||
1848 | jmachado | 528 | if(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_EVALUATION_REPORT.indexOf("localhost")>=0) |
1830 | jmachado | 529 | { |
530 | JSONArray array = new JSONArray(); |
||
531 | List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
||
532 | for(CourseUnit cu: units) |
||
533 | { |
||
534 | CourseUnitSection courseUnitSection = CourseReportUtils.createCourseUnitEvaluationSection((CourseUnitImpl) cu); |
||
535 | array.put(courseUnitSection.toJsonObject()); |
||
536 | } |
||
537 | |||
538 | JSONObject obj = new JSONObject(); |
||
539 | obj.put("evaluations",array); |
||
540 | |||
541 | return obj.toString(); |
||
542 | } |
||
543 | else |
||
544 | { |
||
1848 | jmachado | 545 | 1.5.0/docs/api/java/lang/String.html">String json = "{ evaluations : [] }"; |
546 | 1.5.0/docs/api/java/lang/String.html">String serviceUrl = Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_EVALUATION_REPORT + "?code=" + courseCode + "&year=" + year; |
||
547 | try{ |
||
548 | 1.5.0/docs/api/java/net/URL.html">URL url = new 1.5.0/docs/api/java/net/URL.html">URL(serviceUrl); |
||
1830 | jmachado | 549 | |
1848 | jmachado | 550 | 1.5.0/docs/api/java/net/URLConnection.html">URLConnection conn = url.openConnection(); |
551 | 5+0%2Fdocs%2Fapi+InputStream">InputStream is = conn.getInputStream(); |
||
552 | |||
553 | json = StreamsUtils.readString(is); |
||
554 | is.close(); |
||
555 | }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
556 | { |
||
557 | logger.error("Connecting " + serviceUrl,e); |
||
558 | return json; |
||
559 | } |
||
560 | |||
1830 | jmachado | 561 | JSONObject jsonObject = new JSONObject(json); |
1837 | jmachado | 562 | return jsonObject.get("response").toString(); |
1830 | jmachado | 563 | } |
564 | } |
||
565 | |||
566 | |||
1814 | jmachado | 567 | } |