Rev 1844 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1844 | Rev 1848 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | package pt.estgp.estgweb.services.courses; |
1 | package pt.estgp.estgweb.services.courses; |
2 | 2 | ||
3 | 3 | ||
- | 4 | import jomm.dao.impl.AbstractDao; |
|
4 | import jomm.utils.StreamsUtils; |
5 | import jomm.utils.StreamsUtils; |
5 | import org.apache.log4j.Logger; |
6 | import org.apache.log4j.Logger; |
6 | import org.json.JSONArray; |
7 | import org.json.JSONArray; |
7 | import org.json.JSONException; |
8 | import org.json.JSONException; |
8 | import org.json.JSONObject; |
9 | import org.json.JSONObject; |
Line 30... | Line 31... | ||
30 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
31 | import pt.utl.ist.berserk.logic.serviceManager.IService; |
31 | 32 | ||
32 | import java.io.IOException; |
33 | import java.io.IOException; |
33 | import java.io.InputStream; |
34 | import java.io.InputStream; |
34 | import java.net.URL; |
35 | import java.net.URL; |
- | 36 | import java.net.URLConnection; |
|
35 | import java.util.*; |
37 | import java.util.*; |
36 | 38 | ||
37 | /** |
39 | /** |
38 | * Created by jorgemachado on 14/10/17. |
40 | * Created by jorgemachado on 14/10/17. |
39 | */ |
41 | */ |
Line 50... | Line 52... | ||
50 | /****************************************************************************/ |
52 | /****************************************************************************/ |
51 | /* SERVICOS CORE DOS REPORTS |
53 | /* SERVICOS CORE DOS REPORTS |
52 | /****************************************************************************/ |
54 | /****************************************************************************/ |
53 | 55 | ||
54 | 56 | ||
55 | /** |
- | |
56 | * Gera uma tabela de estatisticas dos DTP recorrendo ao servico WS de |
- | |
57 | * load de tabelas DTP, caso o serviço nao devolva unidades são criadas novas |
- | |
58 | * com os valores a falso. |
- | |
59 | * |
- | |
60 | * @param courseCode |
- | |
61 | * @param year |
- | |
62 | * @return UnitsDtpTable |
- | |
63 | * @throws IOException |
- | |
64 | * @throws JSONException |
- | |
65 | */ |
- | |
66 | public UnitsDtpTable updateDtpStatsTable4Course(ReportCourseDocument 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 |
- | |
67 | { |
- | |
68 | - | ||
69 | ReportsUcSummarySection reportsUcSummarySection = (ReportsUcSummarySection) reportCourseDocument.findDocumentSection(ReportsUcSummarySection.class); |
- | |
70 | UnitsDtpTable unitsDtpTable = (UnitsDtpTable) reportsUcSummarySection.findDocComponent(UnitsDtpTable.class); |
- | |
71 | UnitDtpSemester semester1 = new UnitDtpSemester(); |
- | |
72 | UnitDtpSemester semester2 = new UnitDtpSemester(); |
- | |
73 | unitsDtpTable.setSemester1(semester1); |
- | |
74 | unitsDtpTable.setSemester2(semester2); |
- | |
75 | - | ||
76 | List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
- | |
77 | - | ||
78 | 1.5.0/docs/api/java/lang/String.html">String json = loadCourseUnitDtpStats(courseCode,year); |
- | |
79 | JSONObject response = new JSONObject(json); |
- | |
80 | JSONArray stats = (JSONArray) response.get("dtpstats"); |
- | |
81 | CourseUnitDtpStat[] statsLoaded = CourseUnitDtpStat.fromJson(stats); |
- | |
82 | - | ||
83 | for(CourseUnit cu :units) |
- | |
84 | { |
- | |
85 | CourseUnitDtpStat statFound = CourseReportUtils.findCourseUnitDtpStat(statsLoaded, (CourseUnitImpl) cu); |
- | |
86 | if(statFound == null) |
- | |
87 | { |
- | |
88 | statFound = CourseReportUtils.createCourseUnitDtpStat(cu); |
- | |
89 | } |
- | |
90 | - | ||
91 | if(((CourseUnitImpl) cu).getSemestreAbsolutoS1S2().equals("S1")) |
- | |
92 | semester1.getCourseUnitDtpStats().add(statFound); |
- | |
93 | else |
- | |
94 | semester2.getCourseUnitDtpStats().add(statFound); |
- | |
95 | } |
- | |
96 | 57 | ||
97 | return unitsDtpTable; |
- | |
98 | - | ||
99 | } |
- | |
100 | 58 | ||
101 | /** |
59 | /** |
102 | * |
60 | * |
103 | * @param courseCode |
61 | * @param courseCode |
104 | * @param year |
62 | * @param year |
105 | * @return |
63 | * @return |
106 | * @throws IOException |
64 | * @throws IOException |
107 | * @throws JSONException |
65 | * @throws JSONException |
108 | */ |
66 | */ |
109 | public ReportCourseDocument 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 |
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 |
110 | { |
68 | { |
111 | ReportCourseDocument reportCourseDocument = new ReportCourseDocument(); |
69 | CourseReportDocument reportCourseDocument = new CourseReportDocument(); |
112 | reportCourseDocument.init(); |
70 | reportCourseDocument.init(); |
113 | 71 | ||
114 | 72 | ||
115 | //FIRST SERVICE TO CALL TO OBTAIN UNITS AND EVALUATIONS |
73 | //FIRST SERVICE TO CALL TO OBTAIN UNITS AND EVALUATIONS |
116 | //THIS IS THE BASE FOR THE REMAIN SERVICE CALLS |
74 | //THIS IS THE BASE FOR THE REMAIN SERVICE CALLS |
Line 131... | Line 89... | ||
131 | 89 | ||
132 | 90 | ||
133 | return reportCourseDocument; |
91 | return reportCourseDocument; |
134 | } |
92 | } |
135 | 93 | ||
136 | 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, ReportCourseDocument reportCourseDocument) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException { |
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 { |
137 | SurveysSection surveysSection = (SurveysSection) reportCourseDocument.findDocumentSection(SurveysSection.class); |
95 | SurveysSection surveysSection = (SurveysSection) reportCourseDocument.findDocumentSection(SurveysSection.class); |
138 | SurveysResultsSection surveysResultsSection = (SurveysResultsSection) surveysSection.findSubSection(SurveysResultsSection.class); |
96 | SurveysResultsSection surveysResultsSection = (SurveysResultsSection) surveysSection.findSection(SurveysResultsSection.class); |
139 | QuestionariosDataTableComponent dataTableComponentS1 = (QuestionariosDataTableComponent) surveysResultsSection.getComponents().get(0); |
97 | QuestionariosDataTableComponent dataTableComponentS1 = (QuestionariosDataTableComponent) surveysResultsSection.getComponents().get(0); |
140 | QuestionariosDataTableComponent dataTableComponentS2 = (QuestionariosDataTableComponent) surveysResultsSection.getComponents().get(1); |
98 | QuestionariosDataTableComponent dataTableComponentS2 = (QuestionariosDataTableComponent) surveysResultsSection.getComponents().get(1); |
141 | 99 | ||
142 | QuestionariosReportsService questionariosReportsService = new QuestionariosReportsService(); |
100 | QuestionariosReportsService questionariosReportsService = new QuestionariosReportsService(); |
143 | 1.5.0/docs/api/java/lang/String.html">String jsonDataTableS1 = questionariosReportsService.loadReportUnidadesSalasJson(courseCode,year,"S1"); |
101 | 1.5.0/docs/api/java/lang/String.html">String jsonDataTableS1 = questionariosReportsService.loadReportUnidadesSalasJson(courseCode,year,"S1"); |
Line 152... | Line 110... | ||
152 | /** |
110 | /** |
153 | * Este serviço atualiza a tabela de resultados de aprendizagem com base nas courseunitssections |
111 | * Este serviço atualiza a tabela de resultados de aprendizagem com base nas courseunitssections |
154 | * @param reportCourseDocument |
112 | * @param reportCourseDocument |
155 | * @return UnitsLearningResultsTable |
113 | * @return UnitsLearningResultsTable |
156 | */ |
114 | */ |
157 | public UnitsLearningResultsTable updateCleanLearningResultsFromCourseUnitsSections(ReportCourseDocument reportCourseDocument) |
115 | public UnitsLearningResultsTable updateCleanLearningResultsFromCourseUnitsSections(CourseReportDocument reportCourseDocument) |
158 | { |
116 | { |
159 | CourseUnitsReportsSection unitReportsSection = (CourseUnitsReportsSection) reportCourseDocument.findDocumentSection(CourseUnitsReportsSection.class); |
117 | CourseUnitsReportsSection unitReportsSection = (CourseUnitsReportsSection) reportCourseDocument.findDocumentSection(CourseUnitsReportsSection.class); |
160 | 118 | ||
161 | LearningResultsSection learningResultsSection = (LearningResultsSection) reportCourseDocument.findDocumentSection(LearningResultsSection.class); |
119 | LearningResultsSection learningResultsSection = (LearningResultsSection) reportCourseDocument.findDocumentSection(LearningResultsSection.class); |
162 | UnitsLearningResultsTable learningResultsTable = (UnitsLearningResultsTable) learningResultsSection.findDocComponent(UnitsLearningResultsTable.class); |
120 | UnitsLearningResultsTable learningResultsTable = (UnitsLearningResultsTable) learningResultsSection.findDocComponent(UnitsLearningResultsTable.class); |
163 | 121 | ||
164 | Map<Integer,UnitsLearningResultYear> anosPlano = new HashMap<Integer, UnitsLearningResultYear>(); |
122 | Map<Integer,UnitsLearningResultYear> anosPlano = new HashMap<Integer, UnitsLearningResultYear>(); |
165 | Map<String,UnitsLearningResultSemester> anoSemestre = new HashMap<String, UnitsLearningResultSemester>(); |
123 | Map<String,UnitsLearningResultSemester> anoSemestre = new HashMap<String, UnitsLearningResultSemester>(); |
166 | for(DocumentSection subSection : unitReportsSection.getSubSections()) |
124 | for(DocumentSection subSection : unitReportsSection.getSections()) |
167 | { |
125 | { |
168 | CourseUnitSection unitSection = (CourseUnitSection) subSection; |
126 | CourseUnitSection unitSection = (CourseUnitSection) subSection; |
169 | int anoPlano = unitSection.getAnoPlano(); |
127 | int anoPlano = unitSection.getAnoPlano(); |
170 | UnitsLearningResultYear anoFound = anosPlano.get(anoPlano); |
128 | UnitsLearningResultYear anoFound = anosPlano.get(anoPlano); |
171 | if(anoFound == null) |
129 | if(anoFound == null) |
Line 343... | Line 301... | ||
343 | }*/ |
301 | }*/ |
344 | } |
302 | } |
345 | 303 | ||
346 | 304 | ||
347 | /** |
305 | /** |
- | 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 | /** |
|
348 | * Update course unit sections with reports, this method dows not change learning results table |
362 | * Update course unit sections with reports, this method dows not change learning results table |
349 | * values from learning results stays in unit but does not change learning results Table |
363 | * values from learning results stays in unit but does not change learning results Table |
350 | * @param courseCode |
364 | * @param courseCode |
351 | * @param year |
365 | * @param year |
352 | * @param reportCourseDocument |
366 | * @param reportCourseDocument |
353 | * @throws JSONException |
367 | * @throws JSONException |
354 | * @throws IOException |
368 | * @throws IOException |
355 | * @return a list of CourseUnitSection |
369 | * @return a list of CourseUnitSection |
356 | */ |
370 | */ |
357 | 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, ReportCourseDocument reportCourseDocument) throws JSONException, 1.5.0/docs/api/java/io/IOException.html">IOException { |
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 { |
358 | 372 | ||
359 | List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
373 | List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
360 | 374 | ||
361 | 1.5.0/docs/api/java/lang/String.html">String courseUnitSectionsJson = loadCourseEvaluationSections(courseCode,year); |
- | |
362 | JSONObject object = new JSONObject(courseUnitSectionsJson); |
- | |
363 | JSONArray evaluations = object.getJSONArray("evaluations"); |
- | |
364 | CourseUnitSection[] courseUnitSections = CourseUnitSection.fromJsonArray(evaluations.toString()); |
- | |
365 | - | ||
366 | CourseUnitsReportsSection unitReportsSection = (CourseUnitsReportsSection) reportCourseDocument.findDocumentSection(CourseUnitsReportsSection.class); |
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 | } |
|
- | 388 | ||
- | 389 | ||
367 | List<DocumentSection> subSections = new ArrayList<DocumentSection>(); |
390 | List<DocumentSection> subSections = new ArrayList<DocumentSection>(); |
368 | unitReportsSection.setSubSections(subSections); |
391 | unitReportsSection.setSections(subSections); |
369 | for(CourseUnit cu :units) |
392 | for(CourseUnit cu :units) |
370 | { |
393 | { |
371 | CourseUnitSection sectionFound = CourseReportUtils.findCourseUnitSection(courseUnitSections, (CourseUnitImpl) cu); |
394 | CourseUnitSection sectionFound = CourseReportUtils.findCourseUnitSection(courseUnitSections, (CourseUnitImpl) cu); |
372 | if(sectionFound == null) |
395 | if(sectionFound == null) |
373 | { |
396 | { |
Line 379... | Line 402... | ||
379 | courseUnitEvaluation.setAutoGeneratedCourseReport(true); |
402 | courseUnitEvaluation.setAutoGeneratedCourseReport(true); |
380 | DaoFactory.getCourseUnitEvaluationDaoImpl().save(courseUnitEvaluation); |
403 | DaoFactory.getCourseUnitEvaluationDaoImpl().save(courseUnitEvaluation); |
381 | cu.setCourseUnitEvaluation(courseUnitEvaluation); |
404 | cu.setCourseUnitEvaluation(courseUnitEvaluation); |
382 | sectionFound.setCourseUnitEvaluation(courseUnitEvaluation); |
405 | sectionFound.setCourseUnitEvaluation(courseUnitEvaluation); |
383 | } |
406 | } |
384 | unitReportsSection.getSubSections().add(sectionFound); |
407 | unitReportsSection.getSections().add(sectionFound); |
385 | } |
408 | } |
386 | return subSections; |
409 | return subSections; |
387 | } |
410 | } |
388 | 411 | ||
389 | 412 | ||
390 | 413 | ||
391 | 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 { |
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 { |
392 | /*AbstractDao.getCurrentSession().beginTransaction(); |
415 | AbstractDao.getCurrentSession().beginTransaction(); |
393 | 416 | ||
394 | ReportCourseDocument reportCourseDocument = new CourseReportServices().createNewCourseReportDocument("44","201617"); |
417 | CourseReportDocument reportCourseDocument = new CourseReportServices().createNewCourseReportDocument("44","201617"); |
395 | System.out.println(reportCourseDocument.toJson()); |
418 | 1.5.0/docs/api/java/lang/System.html">System.out.println(reportCourseDocument.toJson()); |
396 | AbstractDao.getCurrentSession().getTransaction().commit();*/ |
419 | AbstractDao.getCurrentSession().getTransaction().commit(); |
397 | 420 | ||
398 | //System.setProperty("javax.net.ssl.trustStore", "/JORGE/COPIAS/.keystore"); |
421 | //System.setProperty("javax.net.ssl.trustStore", "/JORGE/COPIAS/.keystore"); |
399 | //System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); |
422 | //System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); |
400 | 423 | ||
401 | 1.5.0/docs/api/java/net/URL.html">URL url = new 1.5.0/docs/api/java/net/URL.html">URL("http://pae.ipportalegre.pt/wsjson/api/app/ws-course-pedagogic-results-list?code=44&year=201617&period=S1"); |
424 | /*URL url = new URL("http://pae.ipportalegre.pt/wsjson/api/app/ws-course-pedagogic-results-list?code=44&year=201617&period=S1"); |
402 | 425 | ||
403 | 426 | ||
404 | 427 | ||
405 | 1.5.0/docs/api/java/lang/System.html">System.out.println(StreamsUtils.readString(url.openStream())); |
428 | System.out.println(StreamsUtils.readString(url.openStream()));*/ |
406 | } |
429 | } |
407 | 430 | ||
408 | /* |
431 | /* |
409 | 432 | ||
410 | public String loadUnitsAndCreateLearningResultsTables4Course(String courseCode, String year) throws IOException, JSONException |
433 | public String loadUnitsAndCreateLearningResultsTables4Course(String courseCode, String year) throws IOException, JSONException |
Line 463... | Line 486... | ||
463 | 486 | ||
464 | return obj.toString(); |
487 | return obj.toString(); |
465 | } |
488 | } |
466 | else |
489 | else |
467 | { |
490 | { |
468 | 1.5.0/docs/api/java/net/URL.html">URL url = new 1.5.0/docs/api/java/net/URL.html">URL(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_DTP_STATS + "?code=" + courseCode + "&year=" + year); |
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); |
|
- | 495 | ||
- | 496 | 1.5.0/docs/api/java/net/URLConnection.html">URLConnection conn = url.openConnection(); |
|
469 | 5+0%2Fdocs%2Fapi+InputStream">InputStream is = url.openStream(); |
497 | 5+0%2Fdocs%2Fapi+InputStream">InputStream is = conn.getInputStream(); |
470 | 498 | ||
471 | 1.5.0/docs/api/java/lang/String.html">String json = StreamsUtils.readString(is); |
499 | json = StreamsUtils.readString(is); |
472 | is.close(); |
500 | is.close(); |
- | 501 | }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
|
- | 502 | { |
|
473 | //TODO temos de extrair o resultado do RESPONSE |
503 | logger.error("Connecting " + serviceUrl,e); |
- | 504 | return json; |
|
- | 505 | } |
|
474 | JSONObject jsonObject = new JSONObject(json); |
506 | JSONObject jsonObject = new JSONObject(json); |
475 | return jsonObject.get("response").toString(); |
507 | return jsonObject.get("response").toString(); |
476 | } |
508 | } |
477 | } |
509 | } |
478 | 510 | ||
Line 491... | Line 523... | ||
491 | * @return String JSONObject with a JSON ARRAY of List<CourseUnitSection> |
523 | * @return String JSONObject with a JSON ARRAY of List<CourseUnitSection> |
492 | */ |
524 | */ |
493 | 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 { |
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 { |
494 | 526 | ||
495 | 527 | ||
496 | if(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_EVALUATION.indexOf("localhost")>=0) |
528 | if(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_EVALUATION_REPORT.indexOf("localhost")>=0) |
497 | { |
529 | { |
498 | JSONArray array = new JSONArray(); |
530 | JSONArray array = new JSONArray(); |
499 | List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
531 | List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
500 | for(CourseUnit cu: units) |
532 | for(CourseUnit cu: units) |
501 | { |
533 | { |
Line 508... | Line 540... | ||
508 | 540 | ||
509 | return obj.toString(); |
541 | return obj.toString(); |
510 | } |
542 | } |
511 | else |
543 | else |
512 | { |
544 | { |
- | 545 | 1.5.0/docs/api/java/lang/String.html">String json = "{ evaluations : [] }"; |
|
513 | 1.5.0/docs/api/java/net/URL.html">URL url = new 1.5.0/docs/api/java/net/URL.html">URL(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_EVALUATION + "?code=" + courseCode + "&year=" + year); |
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); |
|
- | 549 | ||
- | 550 | 1.5.0/docs/api/java/net/URLConnection.html">URLConnection conn = url.openConnection(); |
|
514 | 5+0%2Fdocs%2Fapi+InputStream">InputStream is = url.openStream(); |
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 | } |
|
515 | 560 | ||
516 | 1.5.0/docs/api/java/lang/String.html">String json = StreamsUtils.readString(is); |
- | |
517 | is.close(); |
- | |
518 | JSONObject jsonObject = new JSONObject(json); |
561 | JSONObject jsonObject = new JSONObject(json); |
519 | return jsonObject.get("response").toString(); |
562 | return jsonObject.get("response").toString(); |
520 | } |
563 | } |
521 | } |
564 | } |
522 | 565 |