Subversion Repositories bacoAlunos

Rev

Rev 1935 | Rev 1992 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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