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