Subversion Repositories bacoAlunos

Rev

Rev 1860 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1860 Rev 1876
Line 5... Line 5...
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.CourseUnit;
10
import pt.estgp.estgweb.domain.*;
11
import pt.estgp.estgweb.domain.CourseUnitEvaluationImpl;
-
 
12
import pt.estgp.estgweb.domain.CourseUnitImpl;
-
 
13
import pt.estgp.estgweb.domain.DomainObjectFactory;
-
 
14
import pt.estgp.estgweb.domain.dao.DaoFactory;
11
import pt.estgp.estgweb.domain.dao.DaoFactory;
-
 
12
import pt.estgp.estgweb.filters.chains.ResourceAccessControlEnum;
15
import pt.estgp.estgweb.services.courses.coursereport.CourseReportUtils;
13
import pt.estgp.estgweb.services.courses.coursereport.CourseReportUtils;
16
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.*;
14
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.*;
17
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.courseunitreport.CourseUnitSection;
15
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.courseunitreport.CourseUnitSection;
18
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components.UnitsLearningResultSemester;
-
 
19
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components.UnitsLearningResultUc;
16
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.LearningGlobalAnalysisSection;
20
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components.UnitsLearningResultYear;
17
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components.*;
21
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.learningresults.components.UnitsLearningResultsTable;
-
 
22
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.reportucsummary.CourseUnitDtpStat;
18
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.reportucsummary.CourseUnitDtpStat;
23
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.reportucsummary.UnitDtpSemester;
19
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.reportucsummary.UnitDtpSemester;
24
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.reportucsummary.UnitsDtpTable;
20
import pt.estgp.estgweb.services.courses.coursereport.documentmodel.reportucsummary.UnitsDtpTable;
25
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;
-
 
23
import pt.estgp.estgweb.services.data.RepositoryService;
26
import pt.estgp.estgweb.services.questionarios.QuestionariosReportsService;
24
import pt.estgp.estgweb.services.questionarios.QuestionariosReportsService;
27
import pt.estgp.estgweb.services.questionarios.pedagogico.reportprocessors.utils.DataTable;
25
import pt.estgp.estgweb.services.questionarios.pedagogico.reportprocessors.utils.DataTable;
28
import pt.estgp.estgweb.utils.Globals;
26
import pt.estgp.estgweb.utils.Globals;
29
import pt.estgp.estgweb.utils.documentBuilder.DocumentSection;
27
import pt.estgp.estgweb.utils.documentBuilder.DocumentSection;
30
import pt.estgp.estgweb.utils.documentBuilder.QuestionariosDataTableComponent;
28
import pt.estgp.estgweb.utils.documentBuilder.QuestionariosDataTableComponent;
-
 
29
import pt.estgp.estgweb.web.controllers.utils.FileUploaded;
31
import pt.utl.ist.berserk.logic.serviceManager.IService;
30
import pt.utl.ist.berserk.logic.serviceManager.IService;
32
 
31
 
33
import java.io.IOException;
32
import java.io.IOException;
34
import java.io.InputStream;
33
import java.io.InputStream;
35
import java.net.URL;
34
import java.net.URL;
Line 64... Line 63...
64
     * @throws IOException
63
     * @throws IOException
65
     * @throws JSONException
64
     * @throws JSONException
66
     */
65
     */
67
    public CourseReportDocument createNewCourseReportDocument(1.5.0/docs/api/java/lang/String.html">String courseCode,1.5.0/docs/api/java/lang/String.html">String year) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException
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
68
    {
67
    {
-
 
68
 
-
 
69
        Course course = DaoFactory.getCourseDaoImpl().findCourseByCode(courseCode);
-
 
70
 
69
        CourseReportDocument reportCourseDocument = new CourseReportDocument();
71
        CourseReportDocument reportCourseDocument = new CourseReportDocument();
70
        reportCourseDocument.init();
72
        reportCourseDocument.init(course,year);
-
 
73
 
71
 
74
 
72
 
75
 
73
        //FIRST SERVICE TO CALL TO OBTAIN UNITS AND EVALUATIONS
76
        //FIRST SERVICE TO CALL TO OBTAIN UNITS AND EVALUATIONS
74
        //THIS IS THE BASE FOR THE REMAIN SERVICE CALLS
77
        //THIS IS THE BASE FOR THE REMAIN SERVICE CALLS
75
        List<DocumentSection> courseUnitSections = updateCleanCourseUnitSections(courseCode, year, reportCourseDocument);
78
        List<DocumentSection> courseUnitSections = updateCleanCourseUnitSections(courseCode, year, reportCourseDocument);
76
 
79
 
77
        //A tabela de resultados globais não vai ser utilizada
80
        //A tabela de resultados globais não vai ser utilizada
78
        //PARA CORRER ESTE SERVICO A PARTIR DA INTERFACE É PRECISO
81
        //PARA CORRER ESTE SERVICO A PARTIR DA INTERFACE É PRECISO
79
        //PERCEBER QUE DEPENDE DO SERVICO DE UPDATE DAS SECOES DAS COURSEUNITS
82
        //PERCEBER QUE DEPENDE DO SERVICO DE UPDATE DAS SECOES DAS COURSEUNITS
80
        UnitsLearningResultsTable unitsLearningResultsTable = updateCleanLearningResultsFromCourseUnitsSections(reportCourseDocument);
83
        UnitsLearningResultsTable unitsLearningResultsTable = updateCleanLearningResultsFromCourseUnitsSections(reportCourseDocument);
81
 
84
 
82
 
85
 
83
        //Atualiza no DOC a tabela de analise DTP
86
        //Atualiza no DOC a tabela de analise DTP
84
        UnitsDtpTable unitsDtpTable = updateDtpStatsTable4Course(reportCourseDocument, courseCode, year);
87
        UnitsDtpTable unitsDtpTable = updateDtpStatsTable4Course(reportCourseDocument, courseCode, year);
85
 
88
 
86
 
89
 
87
        //Atualiza as tabelas dos Quesitonários pedagogicos
90
        //Atualiza as tabelas dos Quesitonários pedagogicos
88
        SurveysResultsSection surveysResultsSection = updateSurveysDataTables(courseCode, year, reportCourseDocument);
91
        SurveysResultsSection surveysResultsSection = updateSurveysDataTables(courseCode, year, reportCourseDocument);
89
 
92
 
90
 
93
 
91
        return reportCourseDocument;
94
        return reportCourseDocument;
92
    }
95
    }
Line 106... Line 109...
106
        dataTableComponentS2.setDataTable(dataTableS2);
109
        dataTableComponentS2.setDataTable(dataTableS2);
107
        return surveysResultsSection;
110
        return surveysResultsSection;
108
    }
111
    }
109
 
112
 
110
    /**
113
    /**
111
     * 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
112
     * @param reportCourseDocument
115
     * @param reportCourseDocument
113
     * @return UnitsLearningResultsTable
116
     * @return UnitsLearningResultsTable
114
     */
117
     */
115
    public UnitsLearningResultsTable updateCleanLearningResultsFromCourseUnitsSections(CourseReportDocument reportCourseDocument)
118
    public UnitsLearningResultsTable updateCleanLearningResultsFromCourseUnitsSections(CourseReportDocument reportCourseDocument)
116
    {
119
    {
Line 155... Line 158...
155
                uc.setAprovados1013(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1013());
158
                uc.setAprovados1013(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1013());
156
                uc.setAprovados1416(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1416());
159
                uc.setAprovados1416(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1416());
157
                uc.setAprovados1720(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1720());
160
                uc.setAprovados1720(unitSection.getCourseUnitEvaluation().getNumAlunosAprov1720());
158
                uc.setSemElementos(unitSection.getCourseUnitEvaluation().getNumAlunosSemElementosAvaliacao());
161
                uc.setSemElementos(unitSection.getCourseUnitEvaluation().getNumAlunosSemElementosAvaliacao());
159
                uc.setAprovados(unitSection.getCourseUnitEvaluation().getNumAlunosAprovTotal());
162
                uc.setAprovados(unitSection.getCourseUnitEvaluation().getNumAlunosAprovTotal());
160
                uc.setReprovados(unitSection.getCourseUnitEvaluation().getNumAlunosReprovados());
163
                uc.setReprovados(unitSection.getCourseUnitEvaluation().getNumAlunosInscritos() - unitSection.getCourseUnitEvaluation().getNumAlunosAprovTotal() - unitSection.getCourseUnitEvaluation().getNumAlunosSemElementosAvaliacao());
161
 
164
 
162
                if(uc.getAlunosInscritos() > 0)
165
                if(uc.getAlunosInscritos() > 0)
163
                {
166
                {
164
                    uc.setAprovadosPercent((float) (uc.getAprovados() * 100.0 / uc.getAlunosInscritos()));
167
                    uc.setAprovadosPercent((float) (uc.getAprovados() * 100.0 / uc.getAlunosInscritos()));
165
                    uc.setReprovadosPercent((float) (uc.getReprovados() * 100.0 / uc.getAlunosInscritos()));
168
                    uc.setReprovadosPercent((float) (uc.getReprovados() * 100.0 / uc.getAlunosInscritos()));
Line 194... Line 197...
194
        }
197
        }
195
 
198
 
196
 
199
 
197
        //UPDATE TOTAIS DE SEMESTRES E DE ANOS
200
        //UPDATE TOTAIS DE SEMESTRES E DE ANOS
198
        float totalCumProgPercentGlobal = 0;
201
        float totalCumProgPercentGlobal = 0;
199
        int totalInscritosGlobal = 0;
202
        float totalInscritosGlobal = 0;
200
        float totalReprovadosPercentGlobal = 0;
203
        float totalReprovadosPercentGlobal = 0;
201
        float totalAprovadosPercentGlobal = 0;
204
        float totalAprovadosPercentGlobal = 0;
202
        float totalSemElementosPercentGlobal = 0;
205
        float totalSemElementosPercentGlobal = 0;
203
        int totalAprovados1013PercentGlobal = 0;
206
        float totalAprovados1013PercentGlobal = 0;
204
        float totalAprovados1416PercentGlobal = 0;
207
        float totalAprovados1416PercentGlobal = 0;
205
        float totalAprovados1720PercentGlobal = 0;
208
        float totalAprovados1720PercentGlobal = 0;
206
        for(UnitsLearningResultYear learningYearLine: learningResultsTable.getYears())
209
        for(UnitsLearningResultYear learningYearLine: learningResultsTable.getYears())
207
        {
210
        {
208
            float totalCumProgPercentAno = 0;
211
            float totalCumProgPercentAno = 0;
209
            int totalInscritosAno = 0;
212
            float totalInscritosAno = 0;
210
            float totalReprovadosPercentAno = 0;
213
            float totalReprovadosPercentAno = 0;
211
            float totalAprovadosPercentAno = 0;
214
            float totalAprovadosPercentAno = 0;
212
            float totalSemElementosPercentAno = 0;
215
            float totalSemElementosPercentAno = 0;
213
            int totalAprovados1013PercentAno = 0;
216
            float totalAprovados1013PercentAno = 0;
214
            float totalAprovados1416PercentAno = 0;
217
            float totalAprovados1416PercentAno = 0;
215
            float totalAprovados1720PercentAno = 0;
218
            float totalAprovados1720PercentAno = 0;
216
 
219
 
217
            for(UnitsLearningResultSemester semester: learningYearLine.getSemesters())
220
            for(UnitsLearningResultSemester semester: learningYearLine.getSemesters())
218
            {
221
            {
219
                float totalCumProgPercent = 0;
222
                float totalCumProgPercent = 0;
220
                int totalInscritos = 0;
223
                float totalInscritos = 0;
221
                float totalReprovadosPercent = 0;
224
                float totalReprovadosPercent = 0;
222
                float totalAprovadosPercent = 0;
225
                float totalAprovadosPercent = 0;
223
                float totalSemElementosPercent = 0;
226
                float totalSemElementosPercent = 0;
224
                int totalAprovados1013Percent = 0;
227
                float totalAprovados1013Percent = 0;
225
                float totalAprovados1416Percent = 0;
228
                float totalAprovados1416Percent = 0;
226
                float totalAprovados1720Percent = 0;
229
                float totalAprovados1720Percent = 0;
227
                for(UnitsLearningResultUc uc: semester.getUcs())
230
                for(UnitsLearningResultUc uc: semester.getUcs())
228
                {
231
                {
229
                    totalCumProgPercent += uc.getCumprimentoProgramaPercent();
232
                    totalCumProgPercent += uc.getCumprimentoProgramaPercent();
Line 237... Line 240...
237
                }
240
                }
238
                //media de inscritos
241
                //media de inscritos
239
                if(semester.getUcs().size() > 0)
242
                if(semester.getUcs().size() > 0)
240
                {
243
                {
241
                    semester.setCumprimentoProgramaPercent( totalCumProgPercent / ((float)semester.getUcs().size()));
244
                    semester.setCumprimentoProgramaPercent( totalCumProgPercent / ((float)semester.getUcs().size()));
242
                    semester.setAlunosInscritos( totalInscritos  / (semester.getUcs().size()));
245
                    semester.setAlunosInscritos( totalInscritos  / ((float)semester.getUcs().size()));
243
                    semester.setAprovadosPercent( totalAprovadosPercent  / ((float)semester.getUcs().size()));
246
                    semester.setAprovadosPercent( totalAprovadosPercent  / ((float)semester.getUcs().size()));
244
                    semester.setReprovadosPercent( totalReprovadosPercent  / ((float)semester.getUcs().size()));
247
                    semester.setReprovadosPercent( totalReprovadosPercent  / ((float)semester.getUcs().size()));
245
                    semester.setSemElementosPercent( totalSemElementosPercent / ((float)semester.getUcs().size()));
248
                    semester.setSemElementosPercent( totalSemElementosPercent / ((float)semester.getUcs().size()));
246
                    semester.setAprovados1013Percent( totalAprovados1013Percent / ((float)semester.getUcs().size()));
249
                    semester.setAprovados1013Percent( totalAprovados1013Percent / ((float)semester.getUcs().size()));
247
                    semester.setAprovados1416Percent( totalAprovados1416Percent / ((float)semester.getUcs().size()));
250
                    semester.setAprovados1416Percent( totalAprovados1416Percent / ((float)semester.getUcs().size()));
Line 258... Line 261...
258
            }
261
            }
259
            //media de inscritos
262
            //media de inscritos
260
            if(learningYearLine.getSemesters().size() > 0)
263
            if(learningYearLine.getSemesters().size() > 0)
261
            {
264
            {
262
                learningYearLine.setCumprimentoProgramaPercent( totalCumProgPercentAno / ((float)learningYearLine.getSemesters().size()));
265
                learningYearLine.setCumprimentoProgramaPercent( totalCumProgPercentAno / ((float)learningYearLine.getSemesters().size()));
263
                learningYearLine.setAlunosInscritos( totalInscritosAno  / (learningYearLine.getSemesters().size()));
266
                learningYearLine.setAlunosInscritos( totalInscritosAno  / ((float)learningYearLine.getSemesters().size()));
264
                learningYearLine.setAprovadosPercent( totalAprovadosPercentAno  / ((float)learningYearLine.getSemesters().size()));
267
                learningYearLine.setAprovadosPercent( totalAprovadosPercentAno  / ((float)learningYearLine.getSemesters().size()));
265
                learningYearLine.setReprovadosPercent( totalReprovadosPercentAno  / ((float)learningYearLine.getSemesters().size()));
268
                learningYearLine.setReprovadosPercent( totalReprovadosPercentAno  / ((float)learningYearLine.getSemesters().size()));
266
                learningYearLine.setSemElementosPercent( totalSemElementosPercentAno / ((float)learningYearLine.getSemesters().size()));
269
                learningYearLine.setSemElementosPercent( totalSemElementosPercentAno / ((float)learningYearLine.getSemesters().size()));
267
                learningYearLine.setAprovados1013Percent( totalAprovados1013PercentAno / ((float)learningYearLine.getSemesters().size()));
270
                learningYearLine.setAprovados1013Percent( totalAprovados1013PercentAno / ((float)learningYearLine.getSemesters().size()));
268
                learningYearLine.setAprovados1416Percent( totalAprovados1416PercentAno / ((float)learningYearLine.getSemesters().size()));
271
                learningYearLine.setAprovados1416Percent( totalAprovados1416PercentAno / ((float)learningYearLine.getSemesters().size()));
Line 287... Line 290...
287
            learningResultsTable.setSemElementosPercent( totalSemElementosPercentGlobal / ((float)learningResultsTable.getYears().size()));
290
            learningResultsTable.setSemElementosPercent( totalSemElementosPercentGlobal / ((float)learningResultsTable.getYears().size()));
288
            learningResultsTable.setAprovados1013Percent( totalAprovados1013PercentGlobal / ((float)learningResultsTable.getYears().size()));
291
            learningResultsTable.setAprovados1013Percent( totalAprovados1013PercentGlobal / ((float)learningResultsTable.getYears().size()));
289
            learningResultsTable.setAprovados1416Percent( totalAprovados1416PercentGlobal / ((float)learningResultsTable.getYears().size()));
292
            learningResultsTable.setAprovados1416Percent( totalAprovados1416PercentGlobal / ((float)learningResultsTable.getYears().size()));
290
            learningResultsTable.setAprovados1720Percent( totalAprovados1720PercentGlobal / ((float)learningResultsTable.getYears().size()));
293
            learningResultsTable.setAprovados1720Percent( totalAprovados1720PercentGlobal / ((float)learningResultsTable.getYears().size()));
291
        }
294
        }
292
 
-
 
293
 
-
 
294
 
-
 
295
 
-
 
296
        return learningResultsTable;
295
        return learningResultsTable;
297
        //CRIAR A TABELA DE RESUTLADOS GLOBAIS GERAIS COMO UM RESUMO DA ANTERIOR
-
 
298
        /*for(UnitsLearningResultYear learningYearLine: learningResultsTable.getYears())
-
 
299
        {
-
 
300
 
-
 
301
        }*/
-
 
302
    }
296
    }
303
 
297
 
304
 
298
 
305
    /**
299
    /**
306
     * 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
307
     * 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
308
     * com os valores a falso.
302
     * com os valores a falso.
309
     *
303
     *
310
     * @param courseCode
304
     * @param courseCode
311
     * @param year
305
     * @param year
312
     * @return UnitsDtpTable
306
     * @return UnitsDtpTable
Line 409... Line 403...
409
        return subSections;
403
        return subSections;
410
    }
404
    }
411
 
405
 
412
 
406
 
413
 
407
 
-
 
408
    /**
414
    public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException {
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
-
 
411
     * widget do grafico
415
        AbstractDao.getCurrentSession().beginTransaction();
412
     * @param reportDocumentJson
-
 
413
     * @param session
-
 
414
     * @return
-
 
415
     * @throws IOException
-
 
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 {
416
 
418
 
417
        CourseReportDocument reportCourseDocument = new CourseReportServices().createNewCourseReportDocument("44","201617");
419
        CourseReportDocument reportDocument =  CourseReportDocument.fromJson(reportDocumentJson);
418
        1.5.0/docs/api/java/lang/System.html">System.out.println(reportCourseDocument.toJson());
420
        LearningResultsSection learningResultsSection = (LearningResultsSection) reportDocument.findDocumentSection(LearningResultsSection.class);
-
 
421
        LearningGlobalAnalysisSection learningGlobalAnalysisSection = (LearningGlobalAnalysisSection) learningResultsSection.findSection(LearningGlobalAnalysisSection.class);
419
        AbstractDao.getCurrentSession().getTransaction().commit();
422
        GlobalLearningResultsChartImg chartImg = (GlobalLearningResultsChartImg) learningGlobalAnalysisSection.findDocComponent(GlobalLearningResultsChartImg.class);
420
 
423
 
421
        //System.setProperty("javax.net.ssl.trustStore", "/JORGE/COPIAS/.keystore");
424
        UnitsLearningResultsTable table = (UnitsLearningResultsTable) learningResultsSection.findDocComponent(UnitsLearningResultsTable.class);
422
        //System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
-
 
423
 
425
 
424
        /*URL url = new URL("http://pae.ipportalegre.pt/wsjson/api/app/ws-course-pedagogic-results-list?code=44&year=201617&period=S1");
426
        FileUploaded fileUploaded = chartImg.generateChart2tmp(table,reportDocument);
425
 
427
 
-
 
428
        RepositoryService repositoryService = new RepositoryService();
426
 
429
 
-
 
430
        boolean imageInitialized = chartImg.getImage() != null
-
 
431
                &&
-
 
432
                chartImg.getImage().getIdentifier() != null;
427
 
433
 
-
 
434
        RepositoryFile4JsonView view;
-
 
435
        if(imageInitialized)
-
 
436
        {
428
        System.out.println(StreamsUtils.readString(url.openStream()));*/
437
            1.5.0/docs/api/java/lang/String.html">String identifier = chartImg.getImage().getIdentifier();
-
 
438
            view = repositoryService.replaceRepositoryFileFromFileUpload(identifier, fileUploaded, ResourceAccessControlEnum.privateDomain, session);
-
 
439
        }
-
 
440
        else
-
 
441
        {
-
 
442
            view = repositoryService.storeRepositoryFileFromFileUpload(fileUploaded,ResourceAccessControlEnum.privateDomain,session);
-
 
443
        }
-
 
444
        chartImg.setImage(view);
-
 
445
        //TODO FALTA GUARDAR O JSON NO CURSO
-
 
446
        return view.toJson();
429
    }
447
    }
430
 
448
 
431
    /*
-
 
432
 
-
 
433
    public String loadUnitsAndCreateLearningResultsTables4Course(String courseCode, String year) throws IOException, JSONException
-
 
434
    {
-
 
435
 
449
 
436
    }
-
 
437
    */
-
 
438
    //TODO loadUnitsAndCreateLearningResultsTables4Course
-
 
439
    //HIPOTESE DEVOLVER DOIS OBJECTOS
-
 
440
    //SERVICO DE ARRANQUE
-
 
441
    //DEVOLVE UM REPORT DOCUMENT E O CHAMADOR USA O QUE QUISER
-
 
442
    //A GERACAO DE GRAFICOS FAZ-SE APENAS A PEDIDO
-
 
443
 
450
 
444
    // SE ELE PEDIR PARA ATUALIZAR TUDO CARREGA-SE UNIDADES E TABELAS NU DOC NOVO
-
 
445
    // E NO BROWSER SUBSTITUI-SE ESSES ELEMENTOS NOS ANTIGOS a seccao das unidades
-
 
446
    // e as as tabelas
-
 
447
 
451
 
448
 
452
 
449
 
453
 
-
 
454
    /****************************************************************************/
-
 
455
    /*
450
 
456
 
451
 
457
 
452
 
458
 
-
 
459
                                    SERVICOS WS-API
453
 
460
 
454
 
461
 
455
 
462
 
456
    /****************************************************************************/
-
 
457
    /* SERVICOS WS-API
463
     */
458
    /****************************************************************************/
464
    /****************************************************************************/
459
 
465
 
460
 
466
 
461
    /**
467
    /**
462
     * This service loads a list of course units given course code and year
468
     * This service loads a list of course units given course code and year
Line 502... Line 508...
502
            {
508
            {
503
                logger.error("Connecting " + serviceUrl,e);
509
                logger.error("Connecting " + serviceUrl,e);
504
                return json;
510
                return json;
505
            }
511
            }
506
            JSONObject jsonObject = new JSONObject(json);
512
            JSONObject jsonObject = new JSONObject(json);
-
 
513
            if(jsonObject.get("service").equals("ok"))
507
            return jsonObject.get("response").toString();
514
                return jsonObject.get("response").toString();
-
 
515
            else
-
 
516
                return json;
508
        }
517
        }
509
    }
518
    }
510
 
519
 
511
 
520
 
512
 
521
 
513
 
522
 
514
    /**
523
    /**
515
     *
524
     *
516
     * Para um determinado curso e ano o serviço faz uma listagem de todas as suas unidades curriculares
525
     * Para um determinado curso e ano o serviço faz uma listagem de todas as suas unidades curriculares
517
     * e lista a sua informação básica juntamente com o relatório de avaliação disponivel
526
     * e lista a sua informação básica juntamente com o relatório de avaliação disponivel
518
     * O serviço adiciona ainda o Ano de cada unidade por inspeção do Plano de Estudos
527
     * O serviço adiciona ainda o Ano de cada unidade por inspeção do Plano de Estudos
519
     * caso a unidade não seja encontrada no Plano de estudos o ano irá ser preenchido com -1
528
     * caso a unidade não seja encontrada no Plano de estudos o ano irá ser preenchido com -1
520
     *
529
     *
521
     * @param courseCode codigo Siges na base de dados
530
     * @param courseCode codigo Siges na base de dados
522
     * @param year  201617, 201718
531
     * @param year  201617, 201718
523
     * @return String JSONObject with a JSON ARRAY of List<CourseUnitSection>
532
     * @return String JSONObject with a JSON ARRAY of List<CourseUnitSection>
524
     */
533
     */
Line 530... Line 539...
530
            JSONArray array = new JSONArray();
539
            JSONArray array = new JSONArray();
531
            List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year);
540
            List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year);
532
            for(CourseUnit cu: units)
541
            for(CourseUnit cu: units)
533
            {
542
            {
534
                CourseUnitSection courseUnitSection = CourseReportUtils.createCourseUnitEvaluationSection((CourseUnitImpl) cu);
543
                CourseUnitSection courseUnitSection = CourseReportUtils.createCourseUnitEvaluationSection((CourseUnitImpl) cu);
-
 
544
                if(courseUnitSection.getAnoPlano() < 0)
-
 
545
                {
-
 
546
                    logger.info("Ano do Plano not available from courseUnitsEvaluation Service, will read from API loadPlanYearForCourseUnitCode");
-
 
547
                    try{
-
 
548
                        1.5.0/docs/api/java/lang/String.html">String json = loadPlanYearForCourseUnitCode(courseCode,cu.getCode(),cu.getSemestre());
-
 
549
                        int ano = new JSONObject(json).getInt("year");
-
 
550
                        courseUnitSection.setAnoPlano(ano);
-
 
551
                    }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e )
-
 
552
                    {
-
 
553
                        logger.error("Nao conseguiu obter o ano do plano da API: " + e.toString(),e);
-
 
554
                    }
-
 
555
                }
535
                array.put(courseUnitSection.toJsonObject());
556
                array.put(courseUnitSection.toJsonObject());
536
            }
557
            }
537
 
558
 
538
            JSONObject obj = new JSONObject();
559
            JSONObject obj = new JSONObject();
539
            obj.put("evaluations",array);
560
            obj.put("evaluations",array);
Line 557... Line 578...
557
                logger.error("Connecting " + serviceUrl,e);
578
                logger.error("Connecting " + serviceUrl,e);
558
                return json;
579
                return json;
559
            }
580
            }
560
 
581
 
561
            JSONObject jsonObject = new JSONObject(json);
582
            JSONObject jsonObject = new JSONObject(json);
-
 
583
            if(jsonObject.get("service").equals("ok"))
562
            return jsonObject.get("response").toString();
584
                return jsonObject.get("response").toString();
-
 
585
            else
-
 
586
                return json;
563
        }
587
        }
564
    }
588
    }
565
 
589
 
566
 
590
 
-
 
591
    /**
-
 
592
     *
-
 
593
     *
-
 
594
     * @param courseCode codigo Siges na base de dados
-
 
595
     * @param unitCode
-
 
596
     * @return Json com o ano do plano exemplo: { year : 1 }
-
 
597
     * ou -1 se não for encontrado
-
 
598
     */
-
 
599
    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 {
-
 
600
 
-
 
601
 
-
 
602
        if(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNIT_PLAN_YEAR.indexOf("localhost")>=0)
-
 
603
        {
-
 
604
            CourseImpl c = DaoFactory.getCourseDaoImpl().findCourseByCode(courseCode);
-
 
605
            int year = c.getUnidadeAnoPlano(period,unitCode);
-
 
606
            return "{ year : " + year + " }";
-
 
607
 
-
 
608
        }
-
 
609
        else
-
 
610
        {
-
 
611
            1.5.0/docs/api/java/lang/String.html">String json = "{ year : -1 }";
-
 
612
            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;
-
 
613
            try{
-
 
614
                1.5.0/docs/api/java/net/URL.html">URL url = new 1.5.0/docs/api/java/net/URL.html">URL(serviceUrl);
-
 
615
 
-
 
616
                1.5.0/docs/api/java/net/URLConnection.html">URLConnection conn = url.openConnection();
-
 
617
                5+0%2Fdocs%2Fapi+InputStream">InputStream is = conn.getInputStream();
-
 
618
 
-
 
619
                json = StreamsUtils.readString(is);
-
 
620
                is.close();
-
 
621
            }catch(1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
-
 
622
            {
-
 
623
                logger.error("Connecting " + serviceUrl,e);
-
 
624
                return json;
-
 
625
            }
-
 
626
 
-
 
627
            JSONObject jsonObject = new JSONObject(json);
-
 
628
            if(jsonObject.get("service").equals("ok"))
-
 
629
                return jsonObject.get("response").toString();
-
 
630
            else
-
 
631
                return json;
-
 
632
        }
-
 
633
    }
-
 
634
 
-
 
635
 
-
 
636
 
-
 
637
 
-
 
638
 
-
 
639
 
-
 
640
 
-
 
641
 
-
 
642
 
-
 
643
 
-
 
644
 
-
 
645
 
-
 
646
 
-
 
647
    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 {
-
 
648
        AbstractDao.getCurrentSession().beginTransaction();
-
 
649
 
-
 
650
        CourseReportDocument reportCourseDocument = new CourseReportServices().createNewCourseReportDocument("44","201617");
-
 
651
        1.5.0/docs/api/java/lang/System.html">System.out.println(reportCourseDocument.toJson());
-
 
652
        AbstractDao.getCurrentSession().getTransaction().commit();
-
 
653
 
-
 
654
        //System.setProperty("javax.net.ssl.trustStore", "/JORGE/COPIAS/.keystore");
-
 
655
        //System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
-
 
656
 
-
 
657
        /*URL url = new URL("http://pae.ipportalegre.pt/wsjson/api/app/ws-course-pedagogic-results-list?code=44&year=201617&period=S1");
-
 
658
 
-
 
659
 
-
 
660
 
-
 
661
        System.out.println(StreamsUtils.readString(url.openStream()));*/
-
 
662
    }
-
 
663
 
-
 
664
    /*
-
 
665
 
-
 
666
    public String loadUnitsAndCreateLearningResultsTables4Course(String courseCode, String year) throws IOException, JSONException
-
 
667
    {
-
 
668
 
-
 
669
    }
-
 
670
    */
-
 
671
    //TODO loadUnitsAndCreateLearningResultsTables4Course
-
 
672
    //HIPOTESE DEVOLVER DOIS OBJECTOS
-
 
673
    //SERVICO DE ARRANQUE
-
 
674
    //DEVOLVE UM REPORT DOCUMENT E O CHAMADOR USA O QUE QUISER
-
 
675
    //A GERACAO DE GRAFICOS FAZ-SE APENAS A PEDIDO
-
 
676
 
-
 
677
    // SE ELE PEDIR PARA ATUALIZAR TUDO CARREGA-SE UNIDADES E TABELAS NU DOC NOVO
-
 
678
    // E NO BROWSER SUBSTITUI-SE ESSES ELEMENTOS NOS ANTIGOS a seccao das unidades
-
 
679
    // e as as tabelas
-
 
680
 
-
 
681
 
-
 
682
 
567
}
683
}
568
 
684