Subversion Repositories bacoAlunos

Rev

Rev 1843 | Rev 1848 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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