Subversion Repositories bacoAlunos

Rev

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

Rev 1967 Rev 1989
Line 41... Line 41...
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
 
-
 
47
 
-
 
48
 
-
 
49
 
-
 
50
 
-
 
51
    /****************************************************************************/
46
    /****************************************************************************/
52
    /* SERVICOS CORE DOS REPORTS
47
    /* SERVICOS CORE DOS REPORTS
53
    /****************************************************************************/
48
    /****************************************************************************/
54
 
49
 
55
 
-
 
56
 
-
 
57
 
-
 
58
    /**
50
    /**
59
     *
51
     *
60
     * @param courseCode
52
     * @param courseCode
61
     * @param year
53
     * @param year
62
     * @return
54
     * @return
Line 447... Line 439...
447
        //TODO FALTA GUARDAR O JSON NO CURSO
439
        //TODO FALTA GUARDAR O JSON NO CURSO
448
        return view.toJson();
440
        return view.toJson();
449
    }
441
    }
450
 
442
 
451
 
443
 
-
 
444
    /**
-
 
445
     * Este servico gera um grafico com a taxa global de aproveitamento e grava-o no repositorio digital
-
 
446
     * devolvendo o respectivo RepositoryFile4JsonView em json para poder ser anexado ao objecto imagem do
-
 
447
     * widget do grafico
-
 
448
     * @param reportDocumentJson
-
 
449
     * @param session
-
 
450
     * @return
-
 
451
     * @throws java.io.IOException
-
 
452
     */
-
 
453
    public 1.5.0/docs/api/java/lang/String.html">String generateGlobalLearningResultsChartYearImg(1.5.0/docs/api/java/lang/String.html">String reportDocumentJson,UserSession session) throws 1.5.0/docs/api/java/io/IOException.html">IOException {
-
 
454
 
-
 
455
        CourseReportDocument reportDocument =  CourseReportDocument.fromJson(reportDocumentJson);
-
 
456
        LearningResultsSection learningResultsSection = (LearningResultsSection) reportDocument.findDocumentSection(LearningResultsSection.class);
-
 
457
        LearningGlobalAnalysisSection learningGlobalAnalysisSection = (LearningGlobalAnalysisSection) learningResultsSection.findSection(LearningGlobalAnalysisSection.class);
-
 
458
        GlobalLearningResultsChartYearImg chartImg = (GlobalLearningResultsChartYearImg) learningGlobalAnalysisSection.findDocComponent(GlobalLearningResultsChartYearImg.class);
-
 
459
 
-
 
460
 
-
 
461
        UnitsLearningResultsTable table = (UnitsLearningResultsTable) learningResultsSection.findDocComponent(UnitsLearningResultsTable.class);
-
 
462
 
-
 
463
 
-
 
464
        FileUploaded fileUploaded = chartImg.generateChart2tmp(table,reportDocument);
-
 
465
 
-
 
466
        RepositoryService repositoryService = new RepositoryService();
-
 
467
 
-
 
468
        boolean imageInitialized = chartImg.getImage() != null
-
 
469
                &&
-
 
470
                chartImg.getImage().getIdentifier() != null;
-
 
471
 
-
 
472
        RepositoryFile4JsonView view;
-
 
473
        if(imageInitialized)
-
 
474
        {
-
 
475
            1.5.0/docs/api/java/lang/String.html">String identifier = chartImg.getImage().getIdentifier();
-
 
476
            view = repositoryService.replaceRepositoryFileFromFileUpload(identifier, fileUploaded, ResourceAccessControlEnum.privateDomain, session);
-
 
477
        }
-
 
478
        else
-
 
479
        {
-
 
480
            view = repositoryService.storeRepositoryFileFromFileUpload(fileUploaded,ResourceAccessControlEnum.privateDomain,session);
-
 
481
        }
-
 
482
        chartImg.setImage(view);
-
 
483
        //TODO FALTA GUARDAR O JSON NO CURSO
-
 
484
        return view.toJson();
-
 
485
    }
452
 
486
 
453
 
487
 
454
 
488
 
455
 
489
 
456
    /****************************************************************************/
490
    /****************************************************************************/
Line 632... Line 666...
632
            else
666
            else
633
                return json;
667
                return json;
634
        }
668
        }
635
    }
669
    }
636
 
670
 
-
 
671
    /** Req2
-
 
672
     * Método para guardar um courseReportDocument na base de dados e volta a retornar o mesmo em Json
-
 
673
     * @param reportDocumentJson ReportDocument em Json para save
-
 
674
     * */
-
 
675
    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 {
-
 
676
 
-
 
677
        //Recebe o Conteudo do reportDocument em Json e deserializa para um objecto do tipo CourseReportDocument
-
 
678
        CourseReportDocument courseReportDocument = CourseReportDocument.fromJson(reportDocumentJson);
-
 
679
 
-
 
680
        1.5.0/docs/api/java/lang/String.html">String courseCode = courseReportDocument.getCourseCode();
-
 
681
        1.5.0/docs/api/java/lang/String.html">String courseYear = courseReportDocument.getYear();
-
 
682
 
-
 
683
        //Vai à base de dados buscar o curso e as informações relativas a esse curso através do courseCode
-
 
684
        //E transforma num object do tipo Course (Class que mapeia a tabela Course)
-
 
685
        Course course = DaoFactory.getCourseDaoImpl().findCourseByCode(courseCode);
-
 
686
        List<CourseYear> courseYearList = DaoFactory.getCourseYearDaoImpl().findCourseYear(courseCode, courseYear);
637
 
687
 
-
 
688
        CourseYear cy;
638
 
689
 
-
 
690
        if (courseYearList.isEmpty()){
-
 
691
            cy = DomainObjectFactory.createCourseYearImpl();
-
 
692
            cy.setCourse(course);
-
 
693
            course.getCourseYears().add(cy);
-
 
694
            cy.setImportYear(courseYear);
-
 
695
            DaoFactory.getCourseYearDaoImpl().save(cy);
-
 
696
        }else{
-
 
697
            //Vai buscar o primeiro index da lista
-
 
698
            cy = courseYearList.get(0);
639
 
699
 
-
 
700
        }
640
 
701
 
-
 
702
        cy.setCourseReportDocument(reportDocumentJson);
641
 
703
 
-
 
704
        return reportDocumentJson;
-
 
705
    }
642
 
706
 
-
 
707
    /**
-
 
708
     * Metodo que dá load ao json da tabela
-
 
709
     */
-
 
710
    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 {
-
 
711
 
-
 
712
        List<CourseYear> courseYearList = DaoFactory.getCourseYearDaoImpl().findCourseYear(courseCode, year);
-
 
713
 
-
 
714
        CourseYear cy;
-
 
715
        //Cria a string para onde se vai fazer load e atribuir
-
 
716
        1.5.0/docs/api/java/lang/String.html">String courseReportJson = null;
-
 
717
 
-
 
718
        if (courseYearList.isEmpty()){
-
 
719
            cy = null;
-
 
720
        }else{
-
 
721
            cy = courseYearList.get(0);
-
 
722
        }
-
 
723
        if (cy != null) {
-
 
724
            courseReportJson = cy.getCourseReportDocument();
-
 
725
        }
-
 
726
 
-
 
727
        if (courseReportJson == null) {
-
 
728
            try {
-
 
729
                CourseReportDocument courseReport = createNewCourseReportDocument(courseCode, year);
-
 
730
                courseReportJson = courseReport.toJson();
-
 
731
                saveCourseReportDocument(courseReportJson, session);
-
 
732
            } catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) {
-
 
733
                1.5.0/docs/api/java/lang/System.html">System.out.println(e);
-
 
734
                e.printStackTrace();
-
 
735
            }
-
 
736
        }
-
 
737
        return courseReportJson;
-
 
738
    }
643
 
739
 
644
 
740
 
645
 
741
 
646
 
742
 
647
 
743
 
Line 659... Line 755...
659
        /*URL url = new URL("http://pae.ipportalegre.pt/wsjson/api/app/ws-course-pedagogic-results-list?code=44&year=201617&period=S1");
755
        /*URL url = new URL("http://pae.ipportalegre.pt/wsjson/api/app/ws-course-pedagogic-results-list?code=44&year=201617&period=S1");
660
 
756
 
661
 
757
 
662
 
758
 
663
        System.out.println(StreamsUtils.readString(url.openStream()));*/
759
        System.out.println(StreamsUtils.readString(url.openStream()));*/
-
 
760
 
-
 
761
 
664
    }
762
    }
665
 
763
 
666
    /*
764
    /*
667
 
765
 
668
    public String loadUnitsAndCreateLearningResultsTables4Course(String courseCode, String year) throws IOException, JSONException
766
    public String loadUnitsAndCreateLearningResultsTables4Course(String courseCode, String year) throws IOException, JSONException
669
    {
767
    {
670
 
-
 
671
    }
768
    }
672
    */
769
    */
673
    //TODO loadUnitsAndCreateLearningResultsTables4Course
770
    //TODO loadUnitsAndCreateLearningResultsTables4Course
674
    //HIPOTESE DEVOLVER DOIS OBJECTOS
771
    //HIPOTESE DEVOLVER DOIS OBJECTOS
675
    //SERVICO DE ARRANQUE
772
    //SERVICO DE ARRANQUE