org.fenixedu.academic.domain.reports.RaidesPhdReportFile.java Source code

Java tutorial

Introduction

Here is the source code for org.fenixedu.academic.domain.reports.RaidesPhdReportFile.java

Source

/**
 * Copyright  2002 Instituto Superior Tcnico
 *
 * This file is part of FenixEdu Academic.
 *
 * FenixEdu Academic is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * FenixEdu Academic is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with FenixEdu Academic.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fenixedu.academic.domain.reports;

import java.util.ArrayList;
import java.util.List;

import org.fenixedu.academic.domain.Enrolment;
import org.fenixedu.academic.domain.ExecutionYear;
import org.fenixedu.academic.domain.Person;
import org.fenixedu.academic.domain.candidacy.PersonalInformationBean;
import org.fenixedu.academic.domain.degree.DegreeType;
import org.fenixedu.academic.domain.degreeStructure.CycleType;
import org.fenixedu.academic.domain.phd.ExternalPhdParticipant;
import org.fenixedu.academic.domain.phd.InternalPhdParticipant;
import org.fenixedu.academic.domain.phd.PhdIndividualProgramProcess;
import org.fenixedu.academic.domain.phd.PhdParticipant;
import org.fenixedu.academic.domain.phd.PhdProgram;
import org.fenixedu.academic.domain.phd.PhdProgramProcessState;
import org.fenixedu.academic.domain.student.Registration;
import org.fenixedu.academic.domain.studentCurriculum.Credits;
import org.fenixedu.academic.util.Bundle;
import org.fenixedu.bennu.core.domain.Bennu;
import org.fenixedu.bennu.core.i18n.BundleUtil;
import org.fenixedu.commons.spreadsheet.Spreadsheet;
import org.fenixedu.commons.spreadsheet.Spreadsheet.Row;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.YearMonthDay;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RaidesPhdReportFile extends RaidesPhdReportFile_Base {

    private static final Logger logger = LoggerFactory.getLogger(RaidesPhdReportFile.class);

    public RaidesPhdReportFile() {
        super();
    }

    @Override
    public String getJobName() {
        return "Listagem RAIDES - PHD";
    }

    @Override
    protected String getPrefix() {
        return "phdRAIDES";
    }

    @Override
    public DegreeType getDegreeType() {
        return DegreeType.matching(DegreeType::isAdvancedSpecializationDiploma).get();
    }

    @Override
    public void renderReport(Spreadsheet spreadsheet) throws Exception {

        ExecutionYear executionYear = getExecutionYear();
        int civilYear = executionYear.getBeginCivilYear();
        fillSpreadsheet(spreadsheet);

        logger.info("BEGIN report for " + getDegreeType().getName().getContent());

        List<PhdIndividualProgramProcess> retrieveProcesses = retrieveProcesses(executionYear);

        for (PhdIndividualProgramProcess phdIndividualProgramProcess : retrieveProcesses) {
            if (phdIndividualProgramProcess.isConcluded()) {
                LocalDate conclusionDate = phdIndividualProgramProcess.getThesisProcess().getConclusionDate();

                if (conclusionDate == null
                        || (conclusionDate.getYear() != civilYear && conclusionDate.getYear() != civilYear - 1
                                && conclusionDate.getYear() != civilYear + 1)) {
                    continue;
                }
            }
            if (phdIndividualProgramProcess.isConcluded() || phdIndividualProgramProcess.getHasStartedStudies()) {

                reportRaidesGraduate(spreadsheet, phdIndividualProgramProcess, executionYear);
            }
        }
    }

    private List<PhdIndividualProgramProcess> retrieveProcesses(ExecutionYear executionYear) {
        List<PhdIndividualProgramProcess> phdIndividualProgramProcessList = new ArrayList<PhdIndividualProgramProcess>();

        for (PhdProgram program : Bennu.getInstance().getPhdProgramsSet()) {
            phdIndividualProgramProcessList.addAll(program.getIndividualProgramProcessesSet());
        }

        return phdIndividualProgramProcessList;
    }

    private void fillSpreadsheet(Spreadsheet spreadsheet) {
        spreadsheet.setHeader("Matriculado de acordo com o plano de estudos?");
        spreadsheet.setHeader("ciclo");
        spreadsheet.setHeader("concludo (ano anterior)?");
        spreadsheet.setHeader("mdia do ciclo");
        spreadsheet.setHeader("Data de concluso");
        spreadsheet.setHeader("Data de Incio");
        spreadsheet.setHeader("nmero aluno");
        spreadsheet.setHeader("tipo identificao");
        spreadsheet.setHeader("nmero identificao");
        spreadsheet.setHeader("digitos controlo");
        spreadsheet.setHeader("verso doc identificao");
        spreadsheet.setHeader("nome");
        spreadsheet.setHeader("gnero");
        spreadsheet.setHeader("data nascimento");
        spreadsheet.setHeader("pas nascimento");
        spreadsheet.setHeader("pas nacionalidade");
        spreadsheet.setHeader("sigla programa doutoral");
        spreadsheet.setHeader("programa doutoral");
        spreadsheet.setHeader("tipo curso");
        spreadsheet.setHeader("nome curso");
        spreadsheet.setHeader("sigla curso");
        spreadsheet.setHeader("ramo");
        spreadsheet.setHeader("n. anos lectivos inscrio curso actual");
        spreadsheet.setHeader("ltimo ano inscrito neste curso");
        spreadsheet.setHeader("estabelecimento habl anterior compl");
        spreadsheet.setHeader("curso habl anterior compl");
        spreadsheet.setHeader("estado civil");
        spreadsheet.setHeader("pas residncia permanente");
        spreadsheet.setHeader("distrito residncia permanente");
        spreadsheet.setHeader("concelho residncia permanente");
        spreadsheet.setHeader("deslocado residncia permanente");
        spreadsheet.setHeader("nvel escolaridade pai");
        spreadsheet.setHeader("nvel escolaridade me");
        spreadsheet.setHeader("condio perante profisso pai");
        spreadsheet.setHeader("condio perante profisso me");
        spreadsheet.setHeader("profisso pai");
        spreadsheet.setHeader("profisso me");
        spreadsheet.setHeader("profisso aluno");
        spreadsheet.setHeader("Data preenchimento dados RAIDES");
        spreadsheet.setHeader("estatuto trabalhador estudante introduzido (info. RAIDES)");
        spreadsheet.setHeader("bolseiro (info. RAIDES)");
        spreadsheet.setHeader("bolseiro (info. oficial)");
        spreadsheet.setHeader("Grau Precedente");
        spreadsheet.setHeader("grau habl anterior compl");
        spreadsheet.setHeader("outro grau habl anterior compl");
        spreadsheet.setHeader("pas habilitao anterior");
        spreadsheet.setHeader("pas habilitao 12 ano ou equivalente");
        spreadsheet.setHeader("ano de concluso da habilitao anterior");
        spreadsheet.setHeader("nota da habilitao anterior");
        spreadsheet.setHeader("N inscries no curso preced.");
        spreadsheet.setHeader("Durao programa mobilidade");
        spreadsheet.setHeader("tipo estabelecimento ensino secundrio");
        spreadsheet.setHeader("total ECTS inscritos no ano");
        spreadsheet
                .setHeader("total ECTS concludos fim ano lectivo anterior (1 Semestre do ano lectivo actual)");
        spreadsheet.setHeader("total ECTS equivalncia/substituio/dispensa");
        spreadsheet.setHeader("total ECTS necessrios para a concluso");
        spreadsheet.setHeader("doutoramento: inscrito parte curricular");
        spreadsheet.setHeader("n doutoramento");
        spreadsheet.setHeader("istId orientadores");
        /* Incio - Alteraes Ticket 366904*/

        spreadsheet.setHeader("istId co-orientadores");
        spreadsheet.setHeader("Nome do Orientador Externo");
        spreadsheet.setHeader("Nome do Co-Orientador Externo");

        /* Fim - Alteraes Ticket 366904*/
        spreadsheet.setHeader("estado processo doutoramento");
        spreadsheet.setHeader("Ambito");
        spreadsheet.setHeader("data de candidatura");
        spreadsheet.setHeader("data de homologao");
        spreadsheet.setHeader("data de inicio dos estudos");
        spreadsheet.setHeader("data e hora da prova");
        spreadsheet.setHeader("tipo de acordo");

        // Alteraes Ticket 366904

        spreadsheet.setHeader("Data de Apresentao Pblica da CAT");
    }

    private void reportRaidesGraduate(Spreadsheet spreadsheet, PhdIndividualProgramProcess process,
            ExecutionYear executionYear) {
        final Row row = spreadsheet.addRow();
        final Person graduate = process.getPerson();
        final PersonalInformationBean personalInformationBean = process.getPersonalInformationBean(executionYear);
        final Registration registration = process.getRegistration();
        final boolean concluded = process.isConcluded();
        final LocalDate conclusionDate = process.getConclusionDate();

        if (registration != null && !registration.isBolonha()) {
            return;
        }

        YearMonthDay registrationConclusionDate = registration != null
                ? registration.getLastStudentCurricularPlan().getCycle(CycleType.THIRD_CYCLE).getConclusionDate()
                : null;

        if (registration != null && registrationConclusionDate == null) {
            registrationConclusionDate = registration.getLastStudentCurricularPlan()
                    .calculateConclusionDate(CycleType.THIRD_CYCLE);
        }

        row.setCell(String.valueOf(registration != null && !registration.isCanceled()));

        // Ciclo
        row.setCell(CycleType.THIRD_CYCLE.getDescription());

        // Concludo
        row.setCell(String.valueOf(process.isConcluded()));

        // Mdia do Ciclo
        String grade = concluded ? process.getFinalGrade().getLocalizedName() : "n/a";
        if (concluded && registration != null && registration.isConcluded()) {
            grade += " " + registration.getLastStudentCurricularPlan().getCycle(CycleType.THIRD_CYCLE)
                    .getCurriculum(registrationConclusionDate.toDateTimeAtMidnight()).getRawGrade().getValue();
        }
        row.setCell(grade);

        // Data de concluso
        row.setCell(conclusionDate != null ? conclusionDate.toString("dd-MM-yyyy") : "");

        // Data de Incio
        row.setCell(process.getCandidacyDate().toString("dd-MM-yyyy"));

        // N de aluno
        row.setCell(process.getStudent().getNumber());

        // Tipo Identificao
        row.setCell(graduate.getIdDocumentType().getLocalizedName());

        // N de Identificao
        row.setCell(graduate.getDocumentIdNumber());

        // Dgitos de Controlo
        row.setCell(graduate.getIdentificationDocumentExtraDigitValue());

        // Verso Doc. Identificao
        row.setCell(graduate.getIdentificationDocumentSeriesNumberValue());

        // Nome
        row.setCell(registration != null ? registration.getName()
                : process.getPerson() != null ? process.getPerson().getName() : "n/a");

        // Sexo
        row.setCell(graduate.getGender().toString());

        // Data de Nascimento
        row.setCell(graduate.getDateOfBirthYearMonthDay() != null
                ? graduate.getDateOfBirthYearMonthDay().toString("dd-MM-yyyy")
                : "n/a");

        // Pas de Nascimento
        row.setCell(graduate.getCountryOfBirth() != null ? graduate.getCountryOfBirth().getName() : "n/a");

        // Pas de Nacionalidade
        row.setCell(graduate.getCountry() != null ? graduate.getCountry().getName() : "n/a");

        // Sigla programa doutoral
        row.setCell(process.getPhdProgram().getAcronym());

        // Programa doutoral
        row.setCell(process.getPhdProgram().getName(process.getExecutionYear()).getContent());

        // Tipo Curso
        row.setCell(registration != null ? registration.getDegreeType().getName().getContent() : "n/a");

        // Nome Curso
        row.setCell(registration != null ? registration.getDegree().getNameI18N().getContent() : "n/a");

        // Sigla Curso
        row.setCell(registration != null ? registration.getDegree().getSigla() : "n/a");

        // Ramo (caso se aplique)
        row.setCell("no determinvel");

        if (registration != null) {
            // N de anos lectivos de inscrio no Curso actual
            row.setCell(calculateNumberOfEnrolmentYears(registration, executionYear));

            // ltimo ano em que esteve inscrito
            row.setCell(registration.getLastEnrolmentExecutionYear() != null
                    ? registration.getLastEnrolmentExecutionYear().getName()
                    : "");
        } else {
            row.setCell("n/a");
            row.setCell("n/a");
        }

        // estabelecimento do habl anterior compl (se o aluno ingressou por uma via
        // diferente CNA, e deve ser IST caso o aluno tenha estado matriculado noutro curso do IST)
        row.setCell(personalInformationBean.getInstitution() != null
                ? personalInformationBean.getInstitution().getName()
                : "");

        // curso habl anterior compl (se o aluno ingressou por uma via diferente CNA, e
        // deve ser IST caso o aluno tenha estado matriculado noutro curso do IST)
        row.setCell(personalInformationBean.getDegreeDesignation());

        // Estado Civil
        row.setCell(personalInformationBean.getMaritalStatus() != null
                ? personalInformationBean.getMaritalStatus().toString()
                : process.getPerson().getMaritalStatus().toString());

        // Pas de Residncia Permanente
        if (personalInformationBean.getCountryOfResidence() != null) {
            row.setCell(personalInformationBean.getCountryOfResidence().getName());
        } else {
            row.setCell(process.getStudent().getPerson().getCountryOfResidence() != null
                    ? process.getStudent().getPerson().getCountryOfResidence().getName()
                    : "");
        }

        // Distrito de Residncia Permanente
        if (personalInformationBean.getDistrictSubdivisionOfResidence() != null) {
            row.setCell(personalInformationBean.getDistrictSubdivisionOfResidence().getDistrict().getName());
        } else {
            row.setCell(process.getStudent().getPerson().getDistrictOfResidence());
        }

        // Concelho de Residncia Permanente
        if (personalInformationBean.getDistrictSubdivisionOfResidence() != null) {
            row.setCell(personalInformationBean.getDistrictSubdivisionOfResidence().getName());
        } else {
            row.setCell(process.getStudent().getPerson().getDistrictSubdivisionOfResidence());
        }

        // Deslocado da Residncia Permanente
        if (personalInformationBean.getDislocatedFromPermanentResidence() != null) {
            row.setCell(personalInformationBean.getDislocatedFromPermanentResidence().toString());
        } else {
            row.setCell("");
        }

        // Nvel de Escolaridade do Pai
        if (personalInformationBean.getFatherSchoolLevel() != null) {
            row.setCell(personalInformationBean.getFatherSchoolLevel().getName());
        } else {
            row.setCell("");
        }

        // Nvel de Escolaridade da Me
        if (personalInformationBean.getMotherSchoolLevel() != null) {
            row.setCell(personalInformationBean.getMotherSchoolLevel().getName());
        } else {
            row.setCell("");
        }

        // Condio perante a situao na profisso/Ocupao do Pai
        if (personalInformationBean.getFatherProfessionalCondition() != null) {
            row.setCell(personalInformationBean.getFatherProfessionalCondition().getName());
        } else {
            row.setCell("");
        }

        // Condio perante a situao na profisso/Ocupao da Me
        if (personalInformationBean.getMotherProfessionalCondition() != null) {
            row.setCell(personalInformationBean.getMotherProfessionalCondition().getName());
        } else {
            row.setCell("");
        }

        // Profisso do Pai
        if (personalInformationBean.getFatherProfessionType() != null) {
            row.setCell(personalInformationBean.getFatherProfessionType().getName());
        } else {
            row.setCell("");
        }

        // Profisso da Me
        if (personalInformationBean.getMotherProfessionType() != null) {
            row.setCell(personalInformationBean.getMotherProfessionType().getName());
        } else {
            row.setCell("");
        }

        // Profisso do Aluno
        if (personalInformationBean.getProfessionType() != null) {
            row.setCell(personalInformationBean.getProfessionType().getName());
        } else {
            row.setCell("");
        }

        // Data preenchimento dados RAIDES
        if (personalInformationBean.getLastModifiedDate() != null) {
            DateTime dateTime = personalInformationBean.getLastModifiedDate();
            row.setCell(dateTime.getYear() + "-" + dateTime.getMonthOfYear() + "-" + dateTime.getDayOfMonth());
        } else {
            row.setCell("");
        }

        // Estatuto de Trabalhador Estudante introduzido pelo aluno
        if (personalInformationBean.getProfessionalCondition() != null) {
            row.setCell(personalInformationBean.getProfessionalCondition().getName());
        } else {
            row.setCell("");
        }

        // Bolseiro (info. RAIDES)
        if (personalInformationBean.getGrantOwnerType() != null) {
            row.setCell(personalInformationBean.getGrantOwnerType().getName());
        } else {
            row.setCell("");
        }

        // Bolseiro (info. oficial)
        boolean sasFound = process.getStudent().getStudentStatutesSet().stream()
                .anyMatch(statute -> statute.getType().isGrantOwnerStatute()
                        && statute.isValidInExecutionPeriod(executionYear.getFirstExecutionPeriod()));
        row.setCell(String.valueOf(sasFound));

        // Grau Precedente
        row.setCell(personalInformationBean.getPrecedentSchoolLevel() != null
                ? personalInformationBean.getPrecedentSchoolLevel().getName()
                : "");

        // grau habl anterior compl
        row.setCell(personalInformationBean.getSchoolLevel() != null
                ? personalInformationBean.getSchoolLevel().getName()
                : "");

        // outro grau habl anterior compl
        row.setCell(personalInformationBean.getOtherSchoolLevel() != null
                ? personalInformationBean.getOtherSchoolLevel()
                : "");

        // Pas de Habilitao Anterior Completa
        row.setCell(personalInformationBean.getCountryWhereFinishedPreviousCompleteDegree() != null
                ? personalInformationBean.getCountryWhereFinishedPreviousCompleteDegree().getName()
                : "");

        // Pas de Habilitao do 12 ano ou equivalente
        row.setCell(personalInformationBean.getCountryWhereFinishedHighSchoolLevel() != null
                ? personalInformationBean.getCountryWhereFinishedHighSchoolLevel().getName()
                : "");

        // Ano de concluso da habilitao anterior completa
        row.setCell(personalInformationBean.getConclusionYear());

        // Nota de concluso da habilitao anterior completa
        row.setCell(
                personalInformationBean.getConclusionGrade() != null ? personalInformationBean.getConclusionGrade()
                        : "");

        // N inscries no curso preced. (conta uma por cada ano)
        row.setCell(personalInformationBean.getNumberOfPreviousYearEnrolmentsInPrecedentDegree() != null
                ? personalInformationBean.getNumberOfPreviousYearEnrolmentsInPrecedentDegree().toString()
                : "");

        // Durao do programa de mobilidade
        row.setCell(personalInformationBean.getMobilityProgramDuration() != null ? BundleUtil
                .getString(Bundle.ENUMERATION, personalInformationBean.getMobilityProgramDuration().name()) : "");

        // Tipo de Estabelecimento Frequentado no Ensino Secundrio
        if (personalInformationBean.getHighSchoolType() != null) {
            row.setCell(personalInformationBean.getHighSchoolType().getName());
        } else {
            row.setCell("");
        }

        double totalEctsConcludedUntilPreviousYear = 0d;
        if (registration != null) {

            // Total de ECTS inscritos no total do ano
            double totalCreditsEnrolled = registration.getLastStudentCurricularPlan()
                    .getEnrolmentsByExecutionYear(executionYear).stream().mapToDouble(Enrolment::getEctsCredits)
                    .sum();
            row.setCell(totalCreditsEnrolled);

            // Total de ECTS concludos at ao fim do ano lectivo anterior (1
            // Semestre do ano lectivo actual) ao que se
            // referem os dados (neste caso at ao fim de 2008) no curso actual
            // We can use current year because only the first semester has
            // occured
            totalEctsConcludedUntilPreviousYear = registration.getLastStudentCurricularPlan()
                    .getInternalCycleCurriculumGrops().stream()
                    .mapToDouble(cycleCurriculumGroup -> cycleCurriculumGroup.getCreditsConcluded(executionYear))
                    .sum();
            row.setCell(totalEctsConcludedUntilPreviousYear);

            // N ECTS equivalncia/substituio/dispensa
            double totalCreditsDismissed = registration.getLastStudentCurricularPlan().getCreditsSet().stream()
                    .filter(Credits::isEquivalence).mapToDouble(Credits::getEnrolmentsEcts).sum();
            row.setCell(totalCreditsDismissed);

        } else {
            row.setCell("n/a");
            row.setCell("n/a");
            row.setCell("n/a");
        }

        if (registration != null) {
            // Total de ECTS necessrios para a concluso
            if (concluded) {
                row.setCell(0);
            } else {
                row.setCell(registration.getLastStudentCurricularPlan().getRoot().getDefaultEcts(executionYear)
                        - totalEctsConcludedUntilPreviousYear);
            }
        } else {
            row.setCell("n/a");
        }

        // Se alunos de Doutoramento, inscrito na Parte Curricular?
        if (registration != null && registration.isDEA()) {
            row.setCell(String.valueOf(registration.getLastStudentCurricularPlan().hasEnrolments(executionYear)));
        } else {
            row.setCell("not PhD");
        }

        row.setCell(process.getPhdStudentNumber());

        // ist id dos orientadores
        int count = 0;
        StringBuilder guidings = new StringBuilder();
        for (PhdParticipant phdParticipant : process.getGuidingsSet()) {
            if (phdParticipant.isInternal()) {
                if (count > 0) {
                    guidings.append(";");
                }
                guidings.append(((InternalPhdParticipant) phdParticipant).getPerson().getUsername());
                count++;
            }
        }
        row.setCell(guidings.toString());

        // ist id dos co-orientadores
        int countAssistantGuidings = 0;
        StringBuilder assistantGuidings = new StringBuilder();
        for (PhdParticipant phdParticipant : process.getAssistantGuidingsSet()) {
            if (phdParticipant.isInternal()) {
                if (countAssistantGuidings > 0) {
                    assistantGuidings.append(";");
                }
                assistantGuidings.append(((InternalPhdParticipant) phdParticipant).getPerson().getUsername());
                countAssistantGuidings++;
            }
        }
        row.setCell(assistantGuidings.toString());

        // Nome do Orientador Externo
        int countExternalGuidings = 0;
        StringBuilder externalGuidingNames = new StringBuilder();
        for (PhdParticipant phdParticipant : process.getGuidingsSet()) {
            if (!phdParticipant.isInternal()) {
                if (countExternalGuidings > 0) {
                    externalGuidingNames.append(";");
                }
                externalGuidingNames.append(((ExternalPhdParticipant) phdParticipant).getName());
                externalGuidingNames.append(" (");
                externalGuidingNames.append(((ExternalPhdParticipant) phdParticipant).getInstitution());
                externalGuidingNames.append(")");
                countExternalGuidings++;
            }
        }
        row.setCell(externalGuidingNames.toString());

        // Nome do Co-Orientador Externo
        int countExternalAssistantGuidings = 0;
        StringBuilder externalAssistantGuidingNames = new StringBuilder();
        for (PhdParticipant phdParticipant : process.getAssistantGuidingsSet()) {
            if (!phdParticipant.isInternal()) {
                if (countExternalAssistantGuidings > 0) {
                    externalAssistantGuidingNames.append(";");
                }
                externalAssistantGuidingNames.append(((ExternalPhdParticipant) phdParticipant).getName());
                externalAssistantGuidingNames.append(" (");
                externalAssistantGuidingNames.append(((ExternalPhdParticipant) phdParticipant).getInstitution());
                externalAssistantGuidingNames.append(")");
                countExternalAssistantGuidings++;
            }
        }
        row.setCell(externalAssistantGuidingNames.toString());

        PhdProgramProcessState lastActiveState = process.getMostRecentState();
        row.setCell(lastActiveState != null ? lastActiveState.getType().getLocalizedName() : "n/a");

        if (process.getCollaborationType() != null) {
            row.setCell(process.getCollaborationType().getLocalizedName());
        } else {
            row.setCell("n/a");
        }

        if (process.getCandidacyDate() != null) {
            row.setCell(process.getCandidacyDate().toString("dd/MM/yyyy"));
        } else {
            row.setCell("n/a");
        }

        if (process.getCandidacyProcess().getWhenRatified() != null) {
            row.setCell(process.getCandidacyDate().toString("dd/MM/yyyy"));
        } else {
            row.setCell("n/a");
        }

        if (process.getWhenStartedStudies() != null) {
            row.setCell(process.getWhenStartedStudies().toString("dd/MM/yyyy"));
        } else {
            row.setCell("n/a");
        }

        if (process.getThesisProcess() != null && process.getThesisProcess().getDiscussionDate() != null) {
            row.setCell(process.getThesisProcess().getDiscussionDate().toString("dd/MM/yyyy"));
        } else {
            row.setCell("n/a");
        }

        // Tipo de Acordo (AFA, AM, ERASMUS, etc)
        row.setCell(registration != null
                ? registration.getRegistrationProtocol() != null ? registration.getRegistrationProtocol().getCode()
                        : ""
                : "");

        // Data de Apresentao Pblica da CAT
        if (process.getSeminarProcess() != null && process.getSeminarProcess().getPresentationDate() != null) {
            row.setCell(process.getSeminarProcess().getPresentationDate().toString("dd/MM/yyyy"));
        } else {
            row.setCell("n/a");
        }
    }

    private int calculateNumberOfEnrolmentYears(Registration registration, ExecutionYear executionYear) {
        return registration.getNumberOfYearsEnrolledUntil(executionYear);
    }

}