Subversion Repositories bacoAlunos

Rev

Rev 1870 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package pt.estgp.estgweb.services.courses.coursereport.documentmodel;

import com.owlike.genson.Genson;
import com.owlike.genson.GensonBuilder;
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.json.JSONObject;
import pt.estgp.estgweb.domain.Course;
import pt.estgp.estgweb.domain.utils.JsonView;
import pt.estgp.estgweb.utils.documentBuilder.Document;
import pt.estgp.estgweb.utils.documentBuilder.DocumentSection;

import java.util.Date;
import java.util.List;

/**
 * Created by jorgemachado on 14/10/17.
 */

public class CourseReportDocument extends 5+0%2Fdocs%2Fapi+Document">Document implements JsonView
{

    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(CourseReportDocument.class);

    private 1.5.0/docs/api/java/lang/String.html">String courseCode;
    private 1.5.0/docs/api/java/lang/String.html">String courseName;
    private 1.5.0/docs/api/java/lang/String.html">String year;



    public CourseReportDocument()
    {

    }

    public 1.5.0/docs/api/java/lang/String.html">String getCourseCode() {
        return courseCode;
    }

    public void setCourseCode(1.5.0/docs/api/java/lang/String.html">String courseCode) {
        this.courseCode = courseCode;
    }

    public 1.5.0/docs/api/java/lang/String.html">String getCourseName() {
        return courseName;
    }

    public void setCourseName(1.5.0/docs/api/java/lang/String.html">String courseName) {
        this.courseName = courseName;
    }

    public 1.5.0/docs/api/java/lang/String.html">String getYear() {
        return year;
    }

    public void setYear(1.5.0/docs/api/java/lang/String.html">String year) {
        this.year = year;
    }

    public void init(Course c,1.5.0/docs/api/java/lang/String.html">String year)
    {
        setYear(year);
        setCourseCode(c.getCode());
        setCourseName(c.getName());

        //1 - Introducao
        IntroSection introSection = new IntroSection();
        introSection.init();
        getSections().add(introSection);

        //2 - Mapa Sintese dos Relatórios dos Responsáveis das UC's
        ReportsUcSummarySection reportsUcSummarySection = new ReportsUcSummarySection();
        reportsUcSummarySection.init();
        getSections().add(reportsUcSummarySection);

        //3 - Resultados da Aprendizagem
        LearningResultsSection learningResultsSection = new LearningResultsSection();
        learningResultsSection.init();
        getSections().add(learningResultsSection);

        //4 - Inquéritos
        SurveysSection surveysSection = new SurveysSection();
        surveysSection.init();
        getSections().add(surveysSection);

        //5 - Conclusões
        ConclusionsSection conclusionsSection = new ConclusionsSection();
        conclusionsSection.init();
        getSections().add(conclusionsSection);

        //5 - Unidades Curriculares
        CourseUnitsReportsSection courseUnitsReportsSection = new CourseUnitsReportsSection();
        courseUnitsReportsSection.init();
        getSections().add(courseUnitsReportsSection);
    }



    public DocumentSection findDocumentSection(1.5.0/docs/api/java/lang/Class.html">Class sectionClass)
    {
        if(getSections() != null)
            for(DocumentSection section: getSections())
            {
                if(section.getClass().equals(sectionClass))
                {
                    return section;
                }
            }
        return null;
    }





    private static Genson gensonGenericLoad;
    static{
        gensonGenericLoad = new GensonBuilder()
                .useMethods(true)
                .useFields(true)
                .useRuntimeType(true) //para ignorar a CGLIB do courseUnitEvaluation
                .useClassMetadata(true)
                .useDateAsTimestamp(true)
                .exclude(1.5.0/docs/api/java/lang/Class.html">Class.class)
                .exclude(5+0%2Fdocs%2Fapi+Date">Date.class)
                .exclude(java.sql.5+0%2Fdocs%2Fapi+Timestamp">Timestamp.class)
                .exclude(java.sql.5+0%2Fdocs%2Fapi+Date">Date.class)
                .create();
    }

    public static CourseReportDocument fromJson(1.5.0/docs/api/java/lang/String.html">String json)
    {
        return gensonGenericLoad.deserialize(json,CourseReportDocument.class);
    }



    public List<String> getJsonExcludedProperties() {
        return null;
    }

    /**
     * Generic Json Object only for local class methods
     * @return
     * @throws org.json.JSONException
     */

    public JSONObject toJsonObject() throws JSONException
    {
        return new JSONObject(toJson());
    }

    /**
     * * Generic Json Object only for local class methods
     * @return
     * @throws java.io.IOException
     */

    public 1.5.0/docs/api/java/lang/String.html">String toJson()
    {
        return gensonGenericLoad.serialize(this);
    }



}