package net.sourceforge.fenixedu.domain.student; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.ListIterator; import java.util.Locale; import java.util.ResourceBundle; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import net.sourceforge.fenixedu.applicationTier.IUserView; import net.sourceforge.fenixedu.dataTransferObject.student.RegistrationConclusionBean; import net.sourceforge.fenixedu.domain.Attends; import net.sourceforge.fenixedu.domain.CurricularCourse; import net.sourceforge.fenixedu.domain.Degree; import net.sourceforge.fenixedu.domain.DegreeCurricularPlan; import net.sourceforge.fenixedu.domain.DegreeCurricularPlanEquivalencePlan; import net.sourceforge.fenixedu.domain.Enrolment; import net.sourceforge.fenixedu.domain.EnrolmentEvaluation; import net.sourceforge.fenixedu.domain.Evaluation; import net.sourceforge.fenixedu.domain.Exam; import net.sourceforge.fenixedu.domain.ExecutionCourse; import net.sourceforge.fenixedu.domain.ExecutionDegree; import net.sourceforge.fenixedu.domain.ExecutionSemester; import net.sourceforge.fenixedu.domain.ExecutionYear; import net.sourceforge.fenixedu.domain.Grade; import net.sourceforge.fenixedu.domain.GratuitySituation; import net.sourceforge.fenixedu.domain.GratuityValues; import net.sourceforge.fenixedu.domain.GuideEntry; import net.sourceforge.fenixedu.domain.IEnrolment; import net.sourceforge.fenixedu.domain.MasterDegreeThesis; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.Project; import net.sourceforge.fenixedu.domain.RootDomainObject; import net.sourceforge.fenixedu.domain.SchoolClass; import net.sourceforge.fenixedu.domain.SchoolLevelType; import net.sourceforge.fenixedu.domain.Shift; import net.sourceforge.fenixedu.domain.ShiftType; import net.sourceforge.fenixedu.domain.SpecialSeasonCode; import net.sourceforge.fenixedu.domain.SpecialSituationCode; import net.sourceforge.fenixedu.domain.StudentCurricularPlan; import net.sourceforge.fenixedu.domain.Teacher; import net.sourceforge.fenixedu.domain.Tutorship; import net.sourceforge.fenixedu.domain.WrittenEvaluation; import net.sourceforge.fenixedu.domain.WrittenEvaluationEnrolment; import net.sourceforge.fenixedu.domain.WrittenTest; import net.sourceforge.fenixedu.domain.YearStudentSpecialSeasonCode; import net.sourceforge.fenixedu.domain.YearStudentSpecialSituationCode; import net.sourceforge.fenixedu.domain.accessControl.PermissionType; import net.sourceforge.fenixedu.domain.accessControl.academicAdminOffice.AdministrativeOfficePermission; import net.sourceforge.fenixedu.domain.accounting.events.AdministrativeOfficeFeeAndInsuranceEvent; import net.sourceforge.fenixedu.domain.accounting.events.EnrolmentOutOfPeriodEvent; import net.sourceforge.fenixedu.domain.accounting.events.gratuity.GratuityEvent; import net.sourceforge.fenixedu.domain.accounting.events.insurance.InsuranceEvent; import net.sourceforge.fenixedu.domain.administrativeOffice.AdministrativeOffice; import net.sourceforge.fenixedu.domain.administrativeOffice.AdministrativeOfficeType; import net.sourceforge.fenixedu.domain.candidacy.CandidacyInformationBean; import net.sourceforge.fenixedu.domain.candidacy.Ingression; import net.sourceforge.fenixedu.domain.candidacy.StudentCandidacy; import net.sourceforge.fenixedu.domain.curriculum.EnrollmentCondition; import net.sourceforge.fenixedu.domain.degree.DegreeType; import net.sourceforge.fenixedu.domain.degreeStructure.CycleType; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.finalDegreeWork.FinalDegreeWorkGroup; import net.sourceforge.fenixedu.domain.finalDegreeWork.GroupStudent; import net.sourceforge.fenixedu.domain.finalDegreeWork.Proposal; import net.sourceforge.fenixedu.domain.finalDegreeWork.Scheduleing; import net.sourceforge.fenixedu.domain.gratuity.ReimbursementGuideState; import net.sourceforge.fenixedu.domain.inquiries.InquiriesRegistry; import net.sourceforge.fenixedu.domain.log.CurriculumLineLog; import net.sourceforge.fenixedu.domain.organizationalStructure.Unit; import net.sourceforge.fenixedu.domain.person.IDDocumentType; import net.sourceforge.fenixedu.domain.person.RoleType; import net.sourceforge.fenixedu.domain.reimbursementGuide.ReimbursementGuideEntry; import net.sourceforge.fenixedu.domain.serviceRequests.AcademicServiceRequest; import net.sourceforge.fenixedu.domain.serviceRequests.AcademicServiceRequestSituationType; import net.sourceforge.fenixedu.domain.serviceRequests.documentRequests.DiplomaRequest; import net.sourceforge.fenixedu.domain.serviceRequests.documentRequests.DocumentRequest; import net.sourceforge.fenixedu.domain.serviceRequests.documentRequests.DocumentRequestType; import net.sourceforge.fenixedu.domain.space.AllocatableSpace; import net.sourceforge.fenixedu.domain.space.Campus; import net.sourceforge.fenixedu.domain.student.curriculum.AverageType; import net.sourceforge.fenixedu.domain.student.curriculum.Curriculum; import net.sourceforge.fenixedu.domain.student.curriculum.ICurriculum; import net.sourceforge.fenixedu.domain.student.curriculum.RegistrationConclusionProcess; import net.sourceforge.fenixedu.domain.student.registrationStates.RegistrationState; import net.sourceforge.fenixedu.domain.student.registrationStates.RegistrationStateType; import net.sourceforge.fenixedu.domain.student.registrationStates.RegistrationState.RegistrationStateCreator; import net.sourceforge.fenixedu.domain.studentCurricularPlan.Specialization; import net.sourceforge.fenixedu.domain.studentCurriculum.CurriculumGroup; import net.sourceforge.fenixedu.domain.studentCurriculum.CurriculumLine; import net.sourceforge.fenixedu.domain.studentCurriculum.CurriculumModule; import net.sourceforge.fenixedu.domain.studentCurriculum.CycleCurriculumGroup; import net.sourceforge.fenixedu.domain.studentCurriculum.Dismissal; import net.sourceforge.fenixedu.domain.studentCurriculum.ExternalEnrolment; import net.sourceforge.fenixedu.domain.teacher.Advise; import net.sourceforge.fenixedu.domain.teacher.AdviseType; import net.sourceforge.fenixedu.domain.tests.NewTestGroup; import net.sourceforge.fenixedu.domain.thesis.Thesis; import net.sourceforge.fenixedu.domain.transactions.InsuranceTransaction; import net.sourceforge.fenixedu.injectionCode.AccessControl; import net.sourceforge.fenixedu.util.PeriodState; import net.sourceforge.fenixedu.util.StringUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; import org.joda.time.DateTime; import org.joda.time.LocalDate; import org.joda.time.ReadableInstant; import org.joda.time.YearMonthDay; import pt.ist.fenixWebFramework.security.accessControl.Checked; import pt.ist.fenixWebFramework.services.Service; import pt.utl.ist.fenix.tools.util.i18n.Language; import com.linkare.commons.metainfo.Linkare; import com.linkare.commons.utils.EqualityUtils; public class Registration extends Registration_Base { static private final List DEGREE_TYPES_TO_ENROL_BY_STUDENT = Arrays.asList(new DegreeType[] { DegreeType.BOLONHA_DEGREE, DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE, DegreeType.BOLONHA_MASTER_DEGREE }); static final public Comparator NUMBER_COMPARATOR = new Comparator() { public int compare(Registration o1, Registration o2) { return o1.getNumber().compareTo(o2.getNumber()); } }; static final public Comparator COMPARATOR_BY_START_DATE = new Comparator() { public int compare(Registration o1, Registration o2) { final int comparationResult = o1.getStartDate().compareTo(o2.getStartDate()); return comparationResult == 0 ? o1.getIdInternal().compareTo(o2.getIdInternal()) : comparationResult; } }; private transient Double approvationRatio; private transient Double arithmeticMean; private transient Integer approvedEnrollmentsNumber = 0; private Registration() { super(); setRootDomainObject(RootDomainObject.getInstance()); } private Registration(final DateTime start) { this(); setStartDate(start.toYearMonthDay()); RegistrationStateCreator.createState(this, AccessControl.getPerson(), start, RegistrationStateType.REGISTERED); } public Registration(final Person person, final StudentCandidacy studentCandidacy) { this(person, null, RegistrationAgreement.NORMAL, null, studentCandidacy); } public Registration(final Person person, final Integer studentNumber) { this(person, studentNumber, RegistrationAgreement.NORMAL, null); } public Registration(final Person person, final DegreeCurricularPlan degreeCurricularPlan) { this(person, degreeCurricularPlan, RegistrationAgreement.NORMAL, null, null); } public Registration(final Person person, final DegreeCurricularPlan degreeCurricularPlan, final CycleType cycleType) { this(person, degreeCurricularPlan, RegistrationAgreement.NORMAL, cycleType, null); } public Registration(final Person person, final DegreeCurricularPlan degreeCurricularPlan, final RegistrationAgreement agreement, final CycleType cycleType, final ExecutionYear executionYear) { this(person, null, agreement, executionYear); setDegree((degreeCurricularPlan != null) ? degreeCurricularPlan.getDegree() : null); createStudentCurricularPlan(person, degreeCurricularPlan, cycleType, executionYear); } public Registration(final Person person, final DegreeCurricularPlan degreeCurricularPlan, final StudentCandidacy candidacy, final RegistrationAgreement agreement, final CycleType cycleType) { this(person, degreeCurricularPlan, candidacy, agreement, cycleType, null); } public Registration(final Person person, final DegreeCurricularPlan degreeCurricularPlan, final StudentCandidacy studentCandidacy, final RegistrationAgreement agreement, final CycleType cycleType, final ExecutionYear executionYear) { this(person, degreeCurricularPlan, agreement, cycleType, executionYear); setStudentCandidacyInformation(studentCandidacy); } private Registration(final Person person, final Integer registrationNumber, final RegistrationAgreement agreement, final ExecutionYear executionYear, final StudentCandidacy studentCandidacy) { this(person, registrationNumber, agreement, executionYear); setStudentCandidacyInformation(studentCandidacy); } private Registration(final Person person, final Integer registrationNumber, final RegistrationAgreement agreement, final ExecutionYear executionYear) { this(calculateStartDate(executionYear)); setStudent(person.hasStudent() ? person.getStudent() : new Student(person, registrationNumber)); setNumber(registrationNumber == null ? getStudent().getNumber() : registrationNumber); setRegistrationYear(executionYear == null ? ExecutionYear.readCurrentExecutionYear() : executionYear); setRequestedChangeDegree(false); setRequestedChangeBranch(false); setRegistrationAgreement(agreement == null ? RegistrationAgreement.NORMAL : agreement); } private void setStudentCandidacyInformation(final StudentCandidacy studentCandidacy) { setStudentCandidacy(studentCandidacy); if (studentCandidacy != null) { super.setDegree(studentCandidacy.getExecutionDegree().getDegree()); super.setEntryPhase(studentCandidacy.getEntryPhase()); super.setIngression(studentCandidacy.getIngression()); if (studentCandidacy.getIngression() == Ingression.RI) { final Degree sourceDegree = studentCandidacy.getDegreeCurricularPlan().getEquivalencePlan().getSourceDegree(); Registration registration = getStudent().readRegistrationByDegree(sourceDegree); if (registration == null) { final Collection registrations = getStudent().getRegistrationsByDegreeType(DegreeType.DEGREE); registrations.remove(this); registration = registrations.size() == 1 ? registrations.iterator().next() : null; } setSourceRegistration(registration); } } } private void createStudentCurricularPlan(final Person person, final DegreeCurricularPlan degreeCurricularPlan, final CycleType cycleType, final ExecutionYear executionYear) { final YearMonthDay startDay; final ExecutionSemester executionSemester; if (executionYear == null || executionYear.isCurrent()) { startDay = new YearMonthDay(); executionSemester = ExecutionSemester.readActualExecutionSemester(); } else { startDay = executionYear.getBeginDateYearMonthDay(); executionSemester = executionYear.getFirstExecutionPeriod(); } final StudentCurricularPlan scp = StudentCurricularPlan.createBolonhaStudentCurricularPlan(this, degreeCurricularPlan, startDay, executionSemester, cycleType); EventGenerator.generateNecessaryEvents(scp, person, executionYear); } private static DateTime calculateStartDate(final ExecutionYear executionYear) { return executionYear == null || executionYear.isCurrent() ? new DateTime() : executionYear.getBeginDateYearMonthDay() .toDateTimeAtMidnight(); } @Override final public void setNumber(Integer number) { super.setNumber(number); if (number == null && hasRegistrationNumber()) { getRegistrationNumber().delete(); } else if (number != null) { if (hasRegistrationNumber()) { getRegistrationNumber().setNumber(number); } else { new RegistrationNumber(this); } } } @Deprecated public void delete() { checkRulesToDelete(); for (; hasAnyRegistrationStates(); getRegistrationStates().get(0).delete()) ; for (; hasAnyStudentCurricularPlans(); getStudentCurricularPlans().get(0).delete()) ; for (; hasAnyAssociatedAttends(); getAssociatedAttends().get(0).delete()) ; for (; hasAnyExternalEnrolments(); getExternalEnrolments().get(0).delete()) ; for (; hasAnyRegistrationDataByExecutionYear(); getRegistrationDataByExecutionYear().get(0).delete()) ; for (; hasAnyAcademicServiceRequests(); getAcademicServiceRequests().get(0).delete()) ; for (; hasAnyRegistrationRegimes(); getRegistrationRegimes().get(0).delete()) ; for (; hasAnyCurriculumLineLogs(); getCurriculumLineLogs().get(0).delete()) ; if (hasRegistrationNumber()) { getRegistrationNumber().delete(); } if (hasExternalRegistrationData()) { getExternalRegistrationData().delete(); } if (hasSenior()) { getSenior().delete(); } if (hasStudentCandidacy()) { getStudentCandidacy().delete(); } removeIndividualCandidacy(); removeSourceRegistration(); removeRegistrationYear(); removeDegree(); removeStudent(); removeRootDomainObject(); getDestinyRegistrations().clear(); getShiftsSet().clear(); super.deleteDomainObject(); } private void checkRulesToDelete() { if (hasDfaRegistrationEvent()) { throw new DomainException("error.student.Registration.cannot.delete.because.is.associated.to.dfa.registration.event"); } } public StudentCurricularPlan getActiveStudentCurricularPlan() { return isActive() ? getLastStudentCurricularPlan() : null; } public StudentCurricularPlan getLastStudentCurricularPlan() { final Set studentCurricularPlans = getStudentCurricularPlansSet(); if (studentCurricularPlans.isEmpty()) { return null; } return Collections.max(studentCurricularPlans, StudentCurricularPlan.STUDENT_CURRICULAR_PLAN_COMPARATOR_BY_START_DATE); } public StudentCurricularPlan getFirstStudentCurricularPlan() { return hasAnyStudentCurricularPlans() ? (StudentCurricularPlan) Collections.min(getStudentCurricularPlans(), StudentCurricularPlan.STUDENT_CURRICULAR_PLAN_COMPARATOR_BY_START_DATE) : null; } public List getSortedStudentCurricularPlans() { final ArrayList sortedStudentCurricularPlans = new ArrayList(super .getStudentCurricularPlans()); Collections.sort(sortedStudentCurricularPlans, StudentCurricularPlan.STUDENT_CURRICULAR_PLAN_COMPARATOR_BY_START_DATE); return sortedStudentCurricularPlans; } final public List getStudentCurricularPlansExceptPast() { List result = new ArrayList(); for (StudentCurricularPlan studentCurricularPlan : super.getStudentCurricularPlans()) { if (!studentCurricularPlan.isPast()) { result.add(studentCurricularPlan); } } return result; } public boolean attends(final ExecutionCourse executionCourse) { for (final Attends attends : getAssociatedAttends()) { if (attends.isFor(executionCourse)) { return true; } } return false; } final public List getWrittenEvaluations(final ExecutionSemester executionSemester) { final List result = new ArrayList(); for (final Attends attend : this.getAssociatedAttends()) { if (attend.isFor(executionSemester)) { for (final Evaluation evaluation : attend.getExecutionCourse().getAssociatedEvaluations()) { if (evaluation instanceof WrittenEvaluation && !result.contains(evaluation)) { result.add((WrittenEvaluation) evaluation); } } } } return result; } final public List getEnroledExams(final ExecutionSemester executionSemester) { final List result = new ArrayList(); for (final WrittenEvaluationEnrolment writtenEvaluationEnrolment : this.getWrittenEvaluationEnrolments()) { if (writtenEvaluationEnrolment.getWrittenEvaluation() instanceof Exam && writtenEvaluationEnrolment.isForExecutionPeriod(executionSemester)) { result.add((Exam) writtenEvaluationEnrolment.getWrittenEvaluation()); } } return result; } final public List getUnenroledExams(final ExecutionSemester executionSemester) { final List result = new ArrayList(); for (final Attends attend : this.getAssociatedAttends()) { if (attend.isFor(executionSemester)) { for (final Evaluation evaluation : attend.getExecutionCourse().getAssociatedEvaluations()) { if (evaluation instanceof Exam && !this.isEnroledIn(evaluation)) { result.add((Exam) evaluation); } } } } return result; } final public List getEnroledWrittenTests(final ExecutionSemester executionSemester) { final List result = new ArrayList(); for (final WrittenEvaluationEnrolment writtenEvaluationEnrolment : this.getWrittenEvaluationEnrolments()) { if (writtenEvaluationEnrolment.getWrittenEvaluation() instanceof WrittenTest && writtenEvaluationEnrolment.isForExecutionPeriod(executionSemester)) { result.add((WrittenTest) writtenEvaluationEnrolment.getWrittenEvaluation()); } } return result; } final public List getUnenroledWrittenTests(final ExecutionSemester executionSemester) { final List result = new ArrayList(); for (final Attends attend : this.getAssociatedAttends()) { if (attend.getExecutionCourse().getExecutionPeriod() == executionSemester) { for (final Evaluation evaluation : attend.getExecutionCourse().getAssociatedEvaluations()) { if (evaluation instanceof WrittenTest && !this.isEnroledIn(evaluation)) { result.add((WrittenTest) evaluation); } } } } return result; } public List getProjects(final ExecutionSemester executionSemester) { final List result = new ArrayList(); for (final Attends attend : this.getAssociatedAttends()) { if (attend.isFor(executionSemester)) { for (final Evaluation evaluation : attend.getExecutionCourse().getAssociatedEvaluations()) { if (evaluation instanceof Project) { result.add((Project) evaluation); } } } } return result; } final public boolean isEnroledIn(final Evaluation evaluation) { for (final WrittenEvaluationEnrolment writtenEvaluationEnrolment : this.getWrittenEvaluationEnrolments()) { if (writtenEvaluationEnrolment.getWrittenEvaluation() == evaluation) { return true; } } return false; } final public AllocatableSpace getRoomFor(final WrittenEvaluation writtenEvaluation) { for (final WrittenEvaluationEnrolment writtenEvaluationEnrolment : this.getWrittenEvaluationEnrolments()) { if (writtenEvaluationEnrolment.getWrittenEvaluation() == writtenEvaluation) { return writtenEvaluationEnrolment.getRoom(); } } return null; } /** * @Deprecated Use Curriculum algorithm instead */ @Deprecated final public void calculateApprovationRatioAndArithmeticMeanIfActive(boolean onlyPreviousExecutionYear) { int enrollmentsNumber = 0; int approvedEnrollmentsNumber = 0; int actualApprovedEnrollmentsNumber = 0; int totalGrade = 0; ExecutionYear currentExecutionYear = ExecutionYear.readCurrentExecutionYear(); ExecutionYear previousExecutionYear = currentExecutionYear.getPreviousExecutionYear(); for (StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlans()) { for (Enrolment enrolment : studentCurricularPlan.getEnrolments()) { if (enrolment.getEnrolmentCondition() == EnrollmentCondition.INVISIBLE) { continue; } ExecutionYear enrolmentExecutionYear = enrolment.getExecutionPeriod().getExecutionYear(); if (onlyPreviousExecutionYear && (previousExecutionYear != enrolmentExecutionYear)) { continue; } if (enrolmentExecutionYear != currentExecutionYear) { enrollmentsNumber++; if (enrolment.isApproved()) { actualApprovedEnrollmentsNumber++; Integer finalGrade = enrolment.getFinalGrade(); if (finalGrade != null) { approvedEnrollmentsNumber++; totalGrade += finalGrade; } else { enrollmentsNumber--; } } } } } setApprovedEnrollmentsNumber(Integer.valueOf(actualApprovedEnrollmentsNumber)); setApprovationRatio((enrollmentsNumber == 0) ? 0 : (double) approvedEnrollmentsNumber / enrollmentsNumber); setArithmeticMean((approvedEnrollmentsNumber == 0) ? 0 : (double) totalGrade / approvedEnrollmentsNumber); } /** * @Deprecated Use Curriculum algorithm instead */ @Deprecated private void setApprovationRatio(Double approvationRatio) { this.approvationRatio = approvationRatio; } /** * @Deprecated Use Curriculum algorithm instead */ @Deprecated private void setArithmeticMean(Double arithmeticMean) { this.arithmeticMean = arithmeticMean; } /** * @Deprecated Use Curriculum algorithm instead */ @Deprecated final public Integer getApprovedEnrollmentsNumber() { if (this.approvedEnrollmentsNumber == null) { calculateApprovationRatioAndArithmeticMeanIfActive(true); } return approvedEnrollmentsNumber; } /** * @Deprecated Use Curriculum algorithm instead */ @Deprecated private void setApprovedEnrollmentsNumber(Integer approvedEnrollmentsNumber) { this.approvedEnrollmentsNumber = approvedEnrollmentsNumber; } /** * @Deprecated Use Curriculum algorithm instead */ @Deprecated final public Double getApprovationRatio() { if (this.approvationRatio == null) { calculateApprovationRatioAndArithmeticMeanIfActive(true); } return this.approvationRatio; } /** * @Deprecated Use Curriculum algorithm instead */ @Deprecated final public Double getArithmeticMean() { if (this.arithmeticMean == null) { calculateApprovationRatioAndArithmeticMeanIfActive(true); } return Double.valueOf(Math.round(this.arithmeticMean * 100) / 100.0); } final public ICurriculum getCurriculum() { return getCurriculum(new DateTime(), (ExecutionYear) null, (CycleType) null); } final public ICurriculum getCurriculum(final DateTime when) { return getCurriculum(when, (ExecutionYear) null, (CycleType) null); } final public ICurriculum getCurriculum(final ExecutionYear executionYear) { return getCurriculum(new DateTime(), executionYear, (CycleType) null); } final public ICurriculum getCurriculum(final CycleType cycleType) { return getCurriculum(new DateTime(), (ExecutionYear) null, cycleType); } final public ICurriculum getCurriculum(final ExecutionYear executionYear, final CycleType cycleType) { return getCurriculum(new DateTime(), executionYear, cycleType); } final public ICurriculum getCurriculum(final DateTime when, final ExecutionYear executionYear, final CycleType cycleType) { if (!hasAnyStudentCurricularPlans()) { return Curriculum.createEmpty(executionYear); } if (getDegreeType().isBolonhaType()) { final StudentCurricularPlan studentCurricularPlan = getLastStudentCurricularPlan(); if (studentCurricularPlan == null) { return Curriculum.createEmpty(executionYear); } if (cycleType == null) { return studentCurricularPlan.getCurriculum(when, executionYear); } final CycleCurriculumGroup cycleCurriculumGroup = studentCurricularPlan.getCycle(cycleType); if (cycleCurriculumGroup == null) { return Curriculum.createEmpty(executionYear); } return cycleCurriculumGroup.getCurriculum(when, executionYear); } else { final List sortedSCPs = getSortedStudentCurricularPlans(); final ListIterator sortedSCPsIterator = sortedSCPs.listIterator(sortedSCPs.size()); final StudentCurricularPlan lastStudentCurricularPlan = sortedSCPsIterator.previous(); final ICurriculum curriculum; if (lastStudentCurricularPlan.isBoxStructure()) { curriculum = lastStudentCurricularPlan.getCurriculum(when, executionYear); for (; sortedSCPsIterator.hasPrevious();) { final StudentCurricularPlan studentCurricularPlan = sortedSCPsIterator.previous(); if (executionYear == null || studentCurricularPlan.getStartExecutionYear().isBeforeOrEquals(executionYear)) { ((Curriculum) curriculum).add(studentCurricularPlan.getCurriculum(when, executionYear)); } } return curriculum; } else { curriculum = new StudentCurriculum(this, executionYear); } return curriculum; } } public int getNumberOfCurriculumEntries() { return getCurriculum().getCurriculumEntries().size(); } final public BigDecimal getSumPiCi(final ExecutionYear executionYear) { return getCurriculum(executionYear).getSumPiCi(); } final public BigDecimal getSumPi(final ExecutionYear executionYear) { return getCurriculum(executionYear).getSumPi(); } final public BigDecimal getAverage() { if (!isBolonha() && isRegistrationConclusionProcessed()) { return getConclusionProcess().getAverage(); } return getAverage((ExecutionYear) null, (CycleType) null); } final public BigDecimal getAverage(final ExecutionYear executionYear) { return getAverage(executionYear, (CycleType) null); } final public BigDecimal getAverage(final CycleType cycleType) { return getAverage((ExecutionYear) null, cycleType); } final public BigDecimal getAverage(final ExecutionYear executionYear, final CycleType cycleType) { return executionYear == null && cycleType == null && isConcluded() && isRegistrationConclusionProcessed() ? BigDecimal .valueOf(getFinalAverage()) : getCurriculum(executionYear, cycleType).getAverage(); } final public BigDecimal getEctsCredits(final ExecutionYear executionYear, final CycleType cycleType) { return getCurriculum(executionYear, cycleType).getSumEctsCredits(); } final public AverageType getAverageType() { if (getDegreeType() == DegreeType.MASTER_DEGREE) { return getLastStudentCurricularPlan().getAverageType(); } else { return AverageType.WEIGHTED; } } final public BigDecimal calculateAverage() { final ICurriculum curriculum = getCurriculum(); final BigDecimal weighted = curriculum.getAverage(); switch (getAverageType()) { case SIMPLE: curriculum.setAverageType(AverageType.SIMPLE); return curriculum.getAverage(); case BEST: curriculum.setAverageType(AverageType.SIMPLE); final BigDecimal simple = curriculum.getAverage(); return weighted.max(simple); default: return weighted; } } @Linkare(author = "Paulo Zenida", comments = "Changed the logic to check if the degree has any cycle instead of checking for bolonha and non bolonha") public Integer calculateRoundedAverage() { if (getDegreeType().hasAnyCycleTypes()) { throw new DomainException("error.Registration.for.cannot.calculate.final.average.in.registration.for.bolonha"); } return Curriculum.getRoundedAverage(calculateAverage()); } @Linkare(author = "Paulo Zenida", comments = "Changed the logic to check if the degree has any cycle instead of checking for bolonha and non bolonha") final public Integer getFinalAverage() { if (getDegreeType().hasAnyCycleTypes()) { final List internalCycleCurriculumGrops = getLastStudentCurricularPlan() .getInternalCycleCurriculumGrops(); if (internalCycleCurriculumGrops.size() == 1) { return internalCycleCurriculumGrops.iterator().next().getFinalAverage(); } else { throw new DomainException("error.bolonha.Registration.must.get.final.average.from.cycle.curriculum.groups"); } } return isRegistrationConclusionProcessed() ? getConclusionProcess().getFinalAverage() : null; } final public Integer getFinalAverage(final CycleType cycleType) { if (cycleType == null) { return getFinalAverage(); } if (getDegreeType().getCycleTypes().isEmpty()) { throw new DomainException("Registration.has.no.cycle.type"); } if (!getDegreeType().hasCycleTypes(cycleType)) { throw new DomainException("Registration.doesnt.have.such.cycle.type"); } return getLastStudentCurricularPlan().getCycle(cycleType).getFinalAverage(); } final public String getFinalAverageDescription() { return getFinalAverageDescription((CycleType) null); } final public String getFinalAverageDescription(final CycleType cycleType) { final Integer finalAverage = getFinalAverage(cycleType); return finalAverage == null ? null : ResourceBundle.getBundle("resources.EnumerationResources").getString( finalAverage.toString()); } final public String getFinalAverageQualified() { return getFinalAverageQualified((CycleType) null); } final public String getFinalAverageQualified(final CycleType cycleType) { final Integer finalAverage = getFinalAverage(cycleType); return finalAverage == null ? null : getDegreeType().getGradeScale().getQualifiedName(finalAverage.toString()); } @Linkare(author = "Paulo Zenida", comments = "Delegated the invocation of getYears() on degree") final public boolean isInFinalDegreeYear() { return getCurricularYear() == getDegree().getYears(); } final public boolean isQualifiedForSeniority() { return isDegreeOrBolonhaDegreeOrBolonhaIntegratedMasterDegree() && (isConcluded() || (isActive() && isInFinalDegreeForSeniority())); } @Linkare(author = "Ricardo Espírito Santo", comments = "getYears from the degree and not degreeType") public boolean isInFinalDegreeForSeniority() { int years = 0; final StudentCurricularPlan studentCurricularPlan = getLastStudentCurricularPlan(); for (final CycleType type : getDegreeType().getCycleTypes()) { if (studentCurricularPlan.hasCycleCurriculumGroup(type)) { years += getDegree().getYears(type); } } return getCurricularYear() == years; } public Grade findGradeForCurricularCourse(final CurricularCourse curricularCourse) { final SortedSet enrolments = new TreeSet(Enrolment.REVERSE_COMPARATOR_BY_EXECUTION_PERIOD_AND_ID); for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { for (final Enrolment enrolment : studentCurricularPlan.getEnrolmentsSet()) { final CurricularCourse enrolmentCurricularCourse = enrolment.getCurricularCourse(); if (enrolmentCurricularCourse == curricularCourse || (enrolmentCurricularCourse.getCompetenceCourse() != null && enrolmentCurricularCourse .getCompetenceCourse() == curricularCourse.getCompetenceCourse()) || hasGlobalEquivalence(curricularCourse, enrolmentCurricularCourse)) { enrolments.add(enrolment); } } } for (final Enrolment enrolment : enrolments) { final EnrolmentEvaluation enrolmentEvaluation = enrolment.getLatestEnrolmentEvaluation(); if (enrolmentEvaluation != null && enrolmentEvaluation.isApproved()) { return enrolmentEvaluation.getGrade(); } } return null; } private boolean hasGlobalEquivalence(final CurricularCourse curricularCourse, final CurricularCourse enrolmentCurricularCourse) { return false; } final public Collection getCurricularCoursesApprovedByEnrolment() { final Collection result = new HashSet(); for (final Enrolment enrolment : getApprovedEnrolments()) { result.add(enrolment.getCurricularCourse()); } return result; } final public Collection getLatestCurricularCoursesEnrolments(final ExecutionYear executionYear) { return getStudentCurricularPlan(executionYear).getLatestCurricularCoursesEnrolments(executionYear); } final public boolean hasEnrolments(final Enrolment enrolment) { if (enrolment == null) { return false; } for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { if (studentCurricularPlan.hasEnrolments(enrolment)) { return true; } } return false; } final public boolean hasAnyEnrolments() { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { if (studentCurricularPlan.hasAnyEnrolments()) { return true; } } return false; } final public boolean hasAnyCurriculumLines() { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { if (studentCurricularPlan.hasAnyCurriculumLines()) { return true; } } return false; } final public boolean hasAnyCurriculumLines(final ExecutionYear executionYear) { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { if (studentCurricularPlan.hasAnyCurriculumLines(executionYear)) { return true; } } return false; } final public boolean hasAnyCurriculumLines(final ExecutionSemester executionSemester) { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { if (studentCurricularPlan.hasAnyCurriculumLines(executionSemester)) { return true; } } return false; } final public Collection getEnrolments(final ExecutionYear executionYear) { final StudentCurricularPlan studentCurricularPlan = getStudentCurricularPlan(executionYear); return studentCurricularPlan != null ? studentCurricularPlan.getEnrolmentsByExecutionYear(executionYear) : Collections.EMPTY_LIST; } final public Collection getEnrolments(final ExecutionSemester executionSemester) { final StudentCurricularPlan studentCurricularPlan = getStudentCurricularPlan(executionSemester.getExecutionYear()); return studentCurricularPlan != null ? studentCurricularPlan.getEnrolmentsByExecutionPeriod(executionSemester) : Collections.EMPTY_LIST; } final public void addApprovedEnrolments(final Collection enrolments) { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { studentCurricularPlan.addApprovedEnrolments(enrolments); } } final public Collection getApprovedEnrolments() { final Collection result = new HashSet(); for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { result.addAll(studentCurricularPlan.getAprovedEnrolments()); } return result; } final public Collection getApprovedExternalEnrolments() { final Collection result = new HashSet(); for (final ExternalEnrolment externalEnrolment : getExternalEnrolments()) { if (externalEnrolment.isApproved()) { result.add(externalEnrolment); } } return result; } final public Collection getExtraCurricularCurriculumLines() { final Collection result = new HashSet(); final Collection toInspect = (isBolonha() ? Collections.singleton(getLastStudentCurricularPlan()) : getStudentCurricularPlansSet()); for (final StudentCurricularPlan studentCurricularPlan : toInspect) { result.addAll(studentCurricularPlan.getExtraCurricularCurriculumLines()); } return result; } public void assertConclusionDate(final Collection result) { for (final CurriculumLine curriculumLine : getApprovedCurriculumLines()) { if (curriculumLine.calculateConclusionDate() == null) { result.add(curriculumLine); } } } final public Collection getPropaedeuticEnrolments() { final Collection result = new HashSet(); final Collection toInspect = (isBolonha() ? Collections.singleton(getLastStudentCurricularPlan()) : getStudentCurricularPlansSet()); for (final StudentCurricularPlan studentCurricularPlan : toInspect) { result.addAll(studentCurricularPlan.getPropaedeuticEnrolments()); } return result; } final public Collection getPropaedeuticCurriculumLines() { final Collection result = new HashSet(); final Collection toInspect = (isBolonha() ? Collections.singleton(getLastStudentCurricularPlan()) : getStudentCurricularPlansSet()); for (final StudentCurricularPlan studentCurricularPlan : toInspect) { result.addAll(studentCurricularPlan.getPropaedeuticCurriculumLines()); } return result; } public YearMonthDay getLastExternalApprovedEnrolmentEvaluationDate() { if (getExternalEnrolments().isEmpty()) { return null; } ExternalEnrolment externalEnrolment = Collections.max(getExternalEnrolments(), ExternalEnrolment.COMPARATOR_BY_EXECUTION_PERIOD_AND_EVALUATION_DATE); return externalEnrolment.getApprovementDate() != null ? externalEnrolment.getApprovementDate() : externalEnrolment .hasExecutionPeriod() ? externalEnrolment.getExecutionPeriod().getEndDateYearMonthDay() : null; } final public YearMonthDay getLastApprovedEnrolmentEvaluationDate() { final SortedSet enrolments = new TreeSet(Enrolment.COMPARATOR_BY_LATEST_ENROLMENT_EVALUATION_AND_ID); enrolments.addAll(getApprovedEnrolments()); YearMonthDay internalEnrolmentExamDate = enrolments.isEmpty() ? null : enrolments.last().getLatestEnrolmentEvaluation() .getExamDateYearMonthDay(); YearMonthDay externalEnrolmentExamDate = getExternalEnrolments().isEmpty() ? null : getLastExternalApprovedEnrolmentEvaluationDate(); if (internalEnrolmentExamDate == null && externalEnrolmentExamDate == null) { return null; } if (internalEnrolmentExamDate == null) { return externalEnrolmentExamDate; } if (externalEnrolmentExamDate == null) { return internalEnrolmentExamDate; } return internalEnrolmentExamDate.compareTo(externalEnrolmentExamDate) > 1 ? internalEnrolmentExamDate : externalEnrolmentExamDate; } final public Collection getApprovedCurriculumLines() { if (isBolonha()) { return getLastStudentCurricularPlan().getApprovedCurriculumLines(); } else { final Collection result = new HashSet(); for (final StudentCurricularPlan plan : getStudentCurricularPlansSet()) { result.addAll(plan.getApprovedCurriculumLines()); } return result; } } final public boolean hasAnyApprovedCurriculumLines() { return getLastStudentCurricularPlan().hasAnyApprovedCurriculumLines(); } final public Collection getApprovedIEnrolments() { final Collection result = new HashSet(); for (final CurriculumLine curriculumLine : getApprovedCurriculumLines()) { if (curriculumLine.isEnrolment()) { result.add((Enrolment) curriculumLine); } else if (curriculumLine.isDismissal()) { result.addAll(((Dismissal) curriculumLine).getSourceIEnrolments()); } } result.addAll(getExternalEnrolments()); return result; } final public boolean hasAnyApprovedEnrolment() { return getLastStudentCurricularPlan().hasAnyApprovedEnrolment() || hasAnyExternalApprovedEnrolment(); } final public boolean hasAnyApprovedEnrolments(final ExecutionYear executionYear) { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { for (final Enrolment enrolment : studentCurricularPlan.getEnrolmentsSet()) { if (enrolment.isApproved() && enrolment.getExecutionPeriod().getExecutionYear() == executionYear) { return true; } } } return false; } final public boolean hasAnyEnrolmentsIn(final ExecutionYear executionYear) { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { for (final Enrolment enrolment : studentCurricularPlan.getEnrolmentsSet()) { if (enrolment.getExecutionPeriod().getExecutionYear() == executionYear) { return true; } } } return false; } final public boolean hasAnyEnrolmentsIn(final ExecutionSemester executionSemester) { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { for (final Enrolment enrolment : studentCurricularPlan.getEnrolmentsSet()) { if (enrolment.getExecutionPeriod() == executionSemester) { return true; } } } return false; } final public boolean hasAnyExternalApprovedEnrolment() { for (final ExternalEnrolment externalEnrolment : this.getExternalEnrolments()) { if (externalEnrolment.isApproved()) { return true; } } return false; } final public Double getDismissalsEctsCredits() { return getLastStudentCurricularPlan().getDismissalsEctsCredits(); } final public boolean getHasExternalEnrolments() { return hasAnyExternalEnrolments(); } final public Collection getEnrolmentsExecutionYears() { final Set result = new HashSet(); for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { for (final Enrolment enrolment : studentCurricularPlan.getEnrolmentsSet()) { result.add(enrolment.getExecutionPeriod().getExecutionYear()); } } return result; } final public SortedSet getSortedEnrolmentsExecutionYears() { final SortedSet result = new TreeSet(ExecutionYear.COMPARATOR_BY_YEAR); result.addAll(getEnrolmentsExecutionYears()); return result; } public Set getAllRelatedRegistrationsEnrolmentsExecutionYears(Set result) { if (result == null) { result = new HashSet(); } result.addAll(getEnrolmentsExecutionYears()); if (this.isBolonha()) { Registration source = hasSourceRegistration() ? getSourceRegistration() : getSourceRegistrationForTransition(); if (source != null) { source.getAllRelatedRegistrationsEnrolmentsExecutionYears(result); } } else { List registrations = getStudent().getRegistrations(); for (Registration registration : registrations) { if (registration != this && !registration.isBolonha()) { if (!registration.isConcluded()) { result.addAll(registration.getEnrolmentsExecutionYears()); } } } } return result; } public Collection getCurriculumLinesExecutionYears() { final Collection result = new ArrayList(); for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { for (final CurriculumLine curriculumLine : studentCurricularPlan.getAllCurriculumLines()) { if (curriculumLine.hasExecutionPeriod()) { result.add(curriculumLine.getExecutionYear()); } } } return result; } public SortedSet getSortedCurriculumLinesExecutionYears() { final SortedSet result = new TreeSet(ExecutionYear.COMPARATOR_BY_YEAR); result.addAll(getCurriculumLinesExecutionYears()); return result; } final public ExecutionYear getFirstEnrolmentExecutionYear() { final SortedSet sortedEnrolmentsExecutionYears = getSortedEnrolmentsExecutionYears(); return sortedEnrolmentsExecutionYears.isEmpty() ? null : sortedEnrolmentsExecutionYears.first(); } public ExecutionYear getFirstCurriculumLineExecutionYear() { final SortedSet executionYears = getSortedCurriculumLinesExecutionYears(); return executionYears.isEmpty() ? null : executionYears.first(); } final public ExecutionYear getLastEnrolmentExecutionYear() { SortedSet sorted = getSortedEnrolmentsExecutionYears(); if (!sorted.isEmpty()) { return sorted.last(); } else { return null; } } public ExecutionYear getLastApprovementExecutionYear() { if (isBolonha()) { return getLastStudentCurricularPlan().getLastApprovementExecutionYear(); } else { ExecutionYear result = null; for (final StudentCurricularPlan plan : getStudentCurricularPlansSet()) { final ExecutionYear year = plan.getLastApprovementExecutionYear(); if (year != null && (result == null || result.isBefore(year))) { result = year; } } return result; } } final public Collection getEnrolmentsExecutionPeriods() { final Collection result = new ArrayList(); for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { for (final Enrolment enrolment : studentCurricularPlan.getEnrolmentsSet()) { result.add(enrolment.getExecutionPeriod()); } } return result; } final public SortedSet getSortedEnrolmentsExecutionPeriods() { final SortedSet result = new TreeSet( ExecutionSemester.EXECUTION_PERIOD_COMPARATOR_BY_SEMESTER_AND_YEAR); result.addAll(getEnrolmentsExecutionPeriods()); return result; } final public List getAdvisesByTeacher(final Teacher teacher) { return (List) CollectionUtils.select(getAdvises(), new Predicate() { final public boolean evaluate(Object arg0) { Advise advise = (Advise) arg0; return advise.getTeacher() == teacher; } }); } final public List getAdvisesByType(final AdviseType adviseType) { return (List) CollectionUtils.select(getAdvises(), new Predicate() { final public boolean evaluate(Object arg0) { Advise advise = (Advise) arg0; return advise.getAdviseType().equals(adviseType); } }); } final public Set getOrderedAttends() { final Set result = new TreeSet(Attends.ATTENDS_COMPARATOR); result.addAll(getAssociatedAttends()); return result; } final public int countCompletedCoursesForActiveUndergraduateCurricularPlan() { return getActiveStudentCurricularPlan().getAprovedEnrolments().size(); } public List getStudentCurricularPlansBySpecialization(Specialization specialization) { List result = new ArrayList(); for (StudentCurricularPlan studentCurricularPlan : this.getStudentCurricularPlans()) { if (studentCurricularPlan.getSpecialization() != null && studentCurricularPlan.getSpecialization().equals(specialization)) { result.add(studentCurricularPlan); } } return result; } final public List getStudentCurricularPlansByDegree(Degree degree) { final List result = new ArrayList(); for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlans()) { if (studentCurricularPlan.getDegree() == degree) { result.add(studentCurricularPlan); } } return result; } final public StudentCurricularPlan getPastStudentCurricularPlanByDegree(Degree degree) { for (StudentCurricularPlan studentCurricularPlan : this.getStudentCurricularPlans()) { if (studentCurricularPlan.getDegree() == degree && studentCurricularPlan.isPast()) { return studentCurricularPlan; } } return null; } public List readAttendsInCurrentExecutionPeriod() { final List attends = new ArrayList(); for (final Attends attend : this.getAssociatedAttendsSet()) { if (attend.getExecutionCourse().getExecutionPeriod().getState().equals(PeriodState.CURRENT)) { attends.add(attend); } } return attends; } public List readAttendsByExecutionPeriod(final ExecutionSemester executionSemester) { final List attends = new ArrayList(); for (final Attends attend : this.getAssociatedAttends()) { if (attend.isFor(executionSemester)) { attends.add(attend); } } return attends; } @Deprecated final public static Registration readByUsername(String username) { final Person person = Person.readPersonByUsername(username); if (person != null) { for (final Registration registration : person.getStudentsSet()) { return registration; } } return null; } @Deprecated final public static Registration readStudentByNumberAndDegreeType(Integer number, DegreeType degreeType) { Registration nonActiveRegistration = null; for (Registration registration : RootDomainObject.getInstance().getRegistrations()) { if (registration.getNumber().intValue() == number.intValue() && registration.getDegreeType().equals(degreeType)) { if (registration.isActive()) { return registration; } nonActiveRegistration = registration; } } return nonActiveRegistration; } final public static Registration readByNumberAndDegreeCurricularPlan(Integer number, DegreeCurricularPlan degreeCurricularPlan) { Registration nonActiveRegistration = null; for (Registration registration : RootDomainObject.getInstance().getRegistrations()) { if (registration.getNumber().intValue() == number.intValue() && registration.getDegreeCurricularPlans().contains(degreeCurricularPlan)) { if (registration.isActive()) { return registration; } nonActiveRegistration = registration; } } return nonActiveRegistration; } final public static Registration readRegisteredRegistrationByNumberAndDegreeType(Integer number, DegreeType degreeType) { for (Registration registration : RootDomainObject.getInstance().getRegistrations()) { if (registration.getNumber().intValue() == number.intValue() && registration.getDegreeType().equals(degreeType) && registration.isInRegisteredState()) { return registration; } } return null; } @Deprecated final public static Registration readRegistrationByNumberAndDegreeTypes(Integer number, DegreeType... degreeTypes) { final List degreeTypesList = Arrays.asList(degreeTypes); for (RegistrationNumber registrationNumber : RootDomainObject.getInstance().getRegistrationNumbersSet()) { if (registrationNumber.getNumber().intValue() == number.intValue()) { final Registration registration = registrationNumber.getRegistration(); if (degreeTypesList.contains(registration.getDegreeType())) { return registration; } } } return null; } final public static Collection readRegistrationsByNumberAndDegreeTypes(Integer number, DegreeType... degreeTypes) { List result = new ArrayList(); final List degreeTypesList = Arrays.asList(degreeTypes); for (RegistrationNumber registrationNumber : RootDomainObject.getInstance().getRegistrationNumbersSet()) { if (registrationNumber.getNumber().intValue() == number.intValue()) { final Registration registration = registrationNumber.getRegistration(); if (degreeTypesList.contains(registration.getDegreeType())) { result.add(registration); } } } return result; } final public static List readByNumber(Integer number) { final List registrations = new ArrayList(); for (RegistrationNumber registrationNumber : RootDomainObject.getInstance().getRegistrationNumbersSet()) { if (registrationNumber.getNumber().intValue() == number.intValue()) { registrations.add(registrationNumber.getRegistration()); } } return registrations; } final public static List readByNumberAndDegreeType(Integer number, DegreeType degreeType) { final List registrations = new ArrayList(); for (RegistrationNumber registrationNumber : RootDomainObject.getInstance().getRegistrationNumbersSet()) { if (registrationNumber.getNumber().intValue() == number.intValue() && registrationNumber.getRegistration().getDegreeType() == degreeType) { registrations.add(registrationNumber.getRegistration()); } } return registrations; } final public static List readByNumberAndDegreeTypeAndAgreement(Integer number, DegreeType degreeType, boolean normalAgreement) { final List registrations = new ArrayList(); for (RegistrationNumber registrationNumber : RootDomainObject.getInstance().getRegistrationNumbersSet()) { if (registrationNumber.getNumber().intValue() == number.intValue() && registrationNumber.getRegistration().getDegreeType() == degreeType && registrationNumber.getRegistration().getRegistrationAgreement().isNormal() == normalAgreement) { registrations.add(registrationNumber.getRegistration()); } } return registrations; } final public static void readMasterDegreeStudentsByNameDocIDNumberIDTypeAndStudentNumber( final Collection result, String studentName, String docIdNumber, IDDocumentType idType, Integer studentNumber) { if (studentNumber != null && studentNumber > 0) { result.addAll(Registration.readRegistrationsByNumberAndDegreeTypes(studentNumber, DegreeType.MASTER_DEGREE, DegreeType.BOLONHA_ADVANCED_FORMATION_DIPLOMA)); } if (!StringUtils.isEmpty(studentName)) { for (Person person : Person.readPersonsByName(studentName)) { if (person.hasStudent()) { result.addAll(person.getStudent().getRegistrationsByDegreeTypes(DegreeType.MASTER_DEGREE, DegreeType.BOLONHA_ADVANCED_FORMATION_DIPLOMA)); } } } if (!StringUtils.isEmpty(docIdNumber)) { for (Person person : Person.readByDocumentIdNumber(docIdNumber)) { if (person.hasStudent()) { result.addAll(person.getStudent().getRegistrationsByDegreeTypes(DegreeType.MASTER_DEGREE, DegreeType.BOLONHA_ADVANCED_FORMATION_DIPLOMA)); } } } } final public static List readAllStudentsBetweenNumbers(Integer fromNumber, Integer toNumber) { int fromNumberInt = fromNumber.intValue(); int toNumberInt = toNumber.intValue(); final List students = new ArrayList(); for (final Registration registration : RootDomainObject.getInstance().getRegistrationsSet()) { int studentNumberInt = registration.getNumber().intValue(); if (studentNumberInt >= fromNumberInt && studentNumberInt <= toNumberInt) { students.add(registration); } } return students; } @Deprecated final public static List readStudentsByDegreeType(DegreeType degreeType) { return readRegistrationsByDegreeType(degreeType); } final public static List readRegistrationsByDegreeType(DegreeType degreeType) { final List students = new ArrayList(); for (final Registration registration : RootDomainObject.getInstance().getRegistrationsSet()) { if (registration.getDegreeType().equals(degreeType)) { students.add(registration); } } return students; } final public GratuitySituation readGratuitySituationByExecutionDegree(ExecutionDegree executionDegree) { GratuityValues gratuityValues = executionDegree.getGratuityValues(); for (StudentCurricularPlan studentCurricularPlan : this.getStudentCurricularPlans()) { GratuitySituation gratuitySituation = studentCurricularPlan.getGratuitySituationByGratuityValues(gratuityValues); if (gratuitySituation != null) { return gratuitySituation; } } return null; } final public FinalDegreeWorkGroup findFinalDegreeWorkGroupForExecutionYear(final ExecutionYear executionYear) { for (final GroupStudent groupStudent : getAssociatedGroupStudents()) { final FinalDegreeWorkGroup group = groupStudent.getFinalDegreeDegreeWorkGroup(); final ExecutionDegree executionDegree = group.getExecutionDegree(); final ExecutionYear executionYearFromGroup = executionDegree.getExecutionYear(); if (executionYearFromGroup == executionYear) { return group; } } return null; } final public List readAllInsuranceTransactionByExecutionYear(ExecutionYear executionYear) { List insuranceTransactions = new ArrayList(); for (InsuranceTransaction insuranceTransaction : this.getInsuranceTransactions()) { if (insuranceTransaction.getExecutionYear().equals(executionYear)) { insuranceTransactions.add(insuranceTransaction); } } return insuranceTransactions; } final public List readAllNonReimbursedInsuranceTransactionsByExecutionYear(ExecutionYear executionYear) { List nonReimbursedInsuranceTransactions = new ArrayList(); for (InsuranceTransaction insuranceTransaction : this.getInsuranceTransactions()) { if (insuranceTransaction.getExecutionYear().equals(executionYear)) { GuideEntry guideEntry = insuranceTransaction.getGuideEntry(); if (guideEntry == null || guideEntry.getReimbursementGuideEntries().isEmpty()) { nonReimbursedInsuranceTransactions.add(insuranceTransaction); } else { boolean isReimbursed = false; for (ReimbursementGuideEntry reimbursementGuideEntry : guideEntry.getReimbursementGuideEntries()) { if (reimbursementGuideEntry.getReimbursementGuide().getActiveReimbursementGuideSituation() .getReimbursementGuideState().equals(ReimbursementGuideState.PAYED)) { isReimbursed = true; break; } } if (!isReimbursed) { nonReimbursedInsuranceTransactions.add(insuranceTransaction); } } } } return nonReimbursedInsuranceTransactions; } // TODO: to remove as soon as possible boolean hasToPayMasterDegreeInsurance(final ExecutionYear executionYear) { final StudentCurricularPlan activeStudentCurricularPlan = getActiveStudentCurricularPlan(); final boolean isSpecialization = (activeStudentCurricularPlan.getSpecialization() == Specialization.STUDENT_CURRICULAR_PLAN_SPECIALIZATION); if (isSpecialization) { if (!getEnrolments(executionYear).isEmpty()) { return true; } final ExecutionDegree executionDegreeByYear = getActiveDegreeCurricularPlan().getExecutionDegreeByYear(executionYear); if (executionDegreeByYear != null && executionDegreeByYear.isFirstYear()) { return true; } return false; } return readAllNonReimbursedInsuranceTransactionsByExecutionYear(executionYear).isEmpty(); } final public Enrolment findEnrolmentByEnrolmentID(final Integer enrolmentID) { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { final Enrolment enrolment = studentCurricularPlan.findEnrolmentByEnrolmentID(enrolmentID); if (enrolment != null) { return enrolment; } } return null; } // Special Season final public SpecialSeasonCode getSpecialSeasonCodeByExecutionYear(ExecutionYear executionYear) { for (YearStudentSpecialSeasonCode yearStudentSpecialSeasonCode : getYearStudentSpecialSeasonCodesSet()) { if (yearStudentSpecialSeasonCode.getExecutionYear() == executionYear) { return yearStudentSpecialSeasonCode.getSpecialSeasonCode(); } } return null; } final public void setSpecialSeasonCode(ExecutionYear executionYear, SpecialSeasonCode specialSeasonCode) { if (specialSeasonCode == null) { if (!getLastStudentCurricularPlan().getSpecialSeasonEnrolments(executionYear).isEmpty()) { throw new DomainException("error.cannot.change.specialSeasonCode"); } else { deleteYearSpecialSeasonCode(executionYear); } } else { if (specialSeasonCode.getMaxEcts().compareTo(getLastStudentCurricularPlan().getSpecialSeasonEcts(executionYear)) < 0) { throw new DomainException("error.cannot.change.specialSeasonCode"); } else { changeYearSpecialSeasonCode(executionYear, specialSeasonCode); } } } private void changeYearSpecialSeasonCode(ExecutionYear executionYear, SpecialSeasonCode specialSeasonCode) { YearStudentSpecialSeasonCode yearStudentSpecialSeasonCode = getYearStudentSpecialSeasonCodeByExecutionYear(executionYear); if (yearStudentSpecialSeasonCode != null) { yearStudentSpecialSeasonCode.setSpecialSeasonCode(specialSeasonCode); } else { new YearStudentSpecialSeasonCode(this, executionYear, specialSeasonCode); } } private YearStudentSpecialSeasonCode getYearStudentSpecialSeasonCodeByExecutionYear(ExecutionYear executionYear) { for (YearStudentSpecialSeasonCode yearStudentSpecialSeasonCode : getYearStudentSpecialSeasonCodesSet()) { if (yearStudentSpecialSeasonCode.getExecutionYear() == executionYear) { return yearStudentSpecialSeasonCode; } } return null; } private void deleteYearSpecialSeasonCode(ExecutionYear executionYear) { for (YearStudentSpecialSeasonCode yearStudentSpecialSeasonCode : getYearStudentSpecialSeasonCodesSet()) { if (yearStudentSpecialSeasonCode.getExecutionYear() == executionYear) { yearStudentSpecialSeasonCode.delete(); } } } // end Special Season // Special situation @Linkare(author = "Paulo Zenida") public final SpecialSituationCode getSpecialSituationCodeByExecutionYear(ExecutionYear executionYear) { for (YearStudentSpecialSituationCode yearStudentSpecialSituationCode : getYearStudentSpecialSituationCodesSet()) { if (yearStudentSpecialSituationCode.getExecutionYear() == executionYear) { return yearStudentSpecialSituationCode.getSpecialSituationCode(); } } return null; } @Linkare(author = "Paulo Zenida") public final void setSpecialSituationCode(ExecutionYear executionYear, SpecialSituationCode specialSituationCode) { if (specialSituationCode == null) { if (!getLastStudentCurricularPlan().getSpecialSituationEnrolments(executionYear).isEmpty()) { throw new DomainException("error.cannot.change.specialSituationCode"); } else { deleteYearSpecialSituationCode(executionYear); } } else { if (specialSituationCode.getMaxEcts() .compareTo(getLastStudentCurricularPlan().getSpecialSituationEcts(executionYear)) < 0) { throw new DomainException("error.cannot.change.specialSituationCode"); } else { changeYearSpecialSituationCode(executionYear, specialSituationCode); } } } @Linkare(author = "Paulo Zenida") private void changeYearSpecialSituationCode(ExecutionYear executionYear, SpecialSituationCode specialSituationCode) { YearStudentSpecialSituationCode yearStudentSpecialSituationCode = getYearStudentSpecialSituationCodeByExecutionYear(executionYear); if (yearStudentSpecialSituationCode != null) { yearStudentSpecialSituationCode.setSpecialSituationCode(specialSituationCode); } else { new YearStudentSpecialSituationCode(this, executionYear, specialSituationCode); } } @Linkare(author = "Paulo Zenida") private YearStudentSpecialSituationCode getYearStudentSpecialSituationCodeByExecutionYear(ExecutionYear executionYear) { for (YearStudentSpecialSituationCode yearStudentSpecialSituationCode : getYearStudentSpecialSituationCodesSet()) { if (yearStudentSpecialSituationCode.getExecutionYear() == executionYear) { return yearStudentSpecialSituationCode; } } return null; } @Linkare(author = "Paulo Zenida") private void deleteYearSpecialSituationCode(ExecutionYear executionYear) { for (YearStudentSpecialSituationCode yearStudentSpecialSituationCode : getYearStudentSpecialSituationCodesSet()) { if (yearStudentSpecialSituationCode.getExecutionYear() == executionYear) { yearStudentSpecialSituationCode.delete(); } } } // end Special Situation final public List getEnroledImprovements() { final List enroledImprovements = new ArrayList(); for (final StudentCurricularPlan scp : getStudentCurricularPlans()) { if (!scp.isBoxStructure() && scp.getDegreeCurricularPlan().getDegree().getDegreeType().equals(DegreeType.DEGREE)) { enroledImprovements.addAll(scp.getEnroledImprovements()); } } return enroledImprovements; } final public List getAttendingExecutionCoursesForCurrentExecutionPeriod() { final List result = new ArrayList(); for (final Attends attends : getAssociatedAttendsSet()) { if (attends.getExecutionCourse().getExecutionPeriod().getState().equals(PeriodState.CURRENT)) { result.add(attends.getExecutionCourse()); } } return result; } final public Set getAttendingExecutionCoursesFor() { final Set result = new HashSet(); for (final Attends attends : getAssociatedAttendsSet()) { result.add(attends.getExecutionCourse()); } return result; } final public List getAttendingExecutionCoursesFor(final ExecutionSemester executionSemester) { final List result = new ArrayList(); for (final Attends attends : getAssociatedAttendsSet()) { if (attends.isFor(executionSemester)) { result.add(attends.getExecutionCourse()); } } return result; } final public List getAttendingExecutionCoursesFor(final ExecutionYear executionYear) { final List result = new ArrayList(); for (final Attends attends : getAssociatedAttendsSet()) { if (attends.isFor(executionYear)) { result.add(attends.getExecutionCourse()); } } return result; } final public List getAttendsForExecutionPeriod(final ExecutionSemester executionSemester) { final List result = new ArrayList(); for (final Attends attends : getAssociatedAttendsSet()) { if (attends.isFor(executionSemester)) { result.add(attends); } } return result; } final public List getShiftsForCurrentExecutionPeriod() { final List result = new ArrayList(); for (final Shift shift : getShiftsSet()) { if (shift.getExecutionCourse().getExecutionPeriod().getState().equals(PeriodState.CURRENT)) { result.add(shift); } } return result; } final public List getShiftsFor(final ExecutionSemester executionSemester) { final List result = new ArrayList(); for (final Shift shift : getShiftsSet()) { if (shift.getExecutionCourse().getExecutionPeriod() == executionSemester) { result.add(shift); } } return result; } final public List getShiftsFor(final ExecutionCourse executionCourse) { final List result = new ArrayList(); for (final Shift shift : getShiftsSet()) { if (shift.getExecutionCourse() == executionCourse) { result.add(shift); } } return result; } final public Shift getShiftFor(final ExecutionCourse executionCourse, final ShiftType shiftType) { for (final Shift shift : getShiftsSet()) { if (shift.getExecutionCourse() == executionCourse && shift.hasShiftType(shiftType)) { return shift; } } return null; } private int countNumberOfDistinctExecutionCoursesOfShiftsFor(final ExecutionSemester executionSemester) { final Set result = new HashSet(); for (final Shift shift : getShiftsSet()) { if (shift.getExecutionCourse().getExecutionPeriod() == executionSemester) { result.add(shift.getExecutionCourse()); } } return result.size(); } final public Integer getNumberOfExecutionCoursesWithEnroledShiftsFor(final ExecutionSemester executionSemester) { return getAttendingExecutionCoursesFor(executionSemester).size() - countNumberOfDistinctExecutionCoursesOfShiftsFor(executionSemester); } final public Integer getNumberOfExecutionCoursesHavingNotEnroledShiftsFor(final ExecutionSemester executionSemester) { int result = 0; final List enroledShifts = getShiftsFor(executionSemester); for (final ExecutionCourse executionCourse : getAttendingExecutionCoursesFor(executionSemester)) { for (final ShiftType shiftType : executionCourse.getOldShiftTypesToEnrol()) { if (!enroledShiftsContainsShiftWithSameExecutionCourseAndShiftType(enroledShifts, executionCourse, shiftType)) { result++; break; } } } return Integer.valueOf(result); } private boolean enroledShiftsContainsShiftWithSameExecutionCourseAndShiftType(final List enroledShifts, final ExecutionCourse executionCourse, final ShiftType shiftType) { return CollectionUtils.exists(enroledShifts, new Predicate() { final public boolean evaluate(Object object) { Shift enroledShift = (Shift) object; return enroledShift.getExecutionCourse() == executionCourse && enroledShift.containsType(shiftType); } }); } final public Set getSchoolClassesToEnrol() { final Set result = new HashSet(); for (final Attends attends : getAssociatedAttendsSet()) { final ExecutionCourse executionCourse = attends.getExecutionCourse(); if (executionCourse.getExecutionPeriod().getState().equals(PeriodState.CURRENT)) { result.addAll(getSchoolClassesToEnrolBy(executionCourse)); } } return result; } final public Set getSchoolClassesToEnrolBy(final ExecutionCourse executionCourse) { Set schoolClasses = executionCourse.getSchoolClassesBy(getActiveStudentCurricularPlan() .getDegreeCurricularPlan()); return schoolClasses.isEmpty() ? executionCourse.getSchoolClasses() : schoolClasses; } public void addAttendsTo(final ExecutionCourse executionCourse) { checkIfReachedAttendsLimit(); if (getStudent().readAttendByExecutionCourse(executionCourse) == null) { final Enrolment enrolment = findEnrolment(getActiveStudentCurricularPlan(), executionCourse, executionCourse .getExecutionPeriod()); if (enrolment != null) { enrolment.createAttends(this, executionCourse); } else { Attends attends = getAttendsForExecutionCourse(executionCourse); if (attends != null) { attends.delete(); } new Attends(this, executionCourse); } } } private Attends getAttendsForExecutionCourse(ExecutionCourse executionCourse) { List attendsInExecutionPeriod = getAttendsForExecutionPeriod(executionCourse.getExecutionPeriod()); for (Attends attends : attendsInExecutionPeriod) { for (CurricularCourse curricularCourse : attends.getExecutionCourse().getAssociatedCurricularCoursesSet()) { if (executionCourse.getAssociatedCurricularCoursesSet().contains(curricularCourse)) { return attends; } } } return null; } private Enrolment findEnrolment(final StudentCurricularPlan studentCurricularPlan, final ExecutionCourse executionCourse, final ExecutionSemester executionSemester) { for (final CurricularCourse curricularCourse : executionCourse.getAssociatedCurricularCoursesSet()) { final Enrolment enrolment = studentCurricularPlan.getEnrolmentByCurricularCourseAndExecutionPeriod(curricularCourse, executionSemester); if (enrolment != null) { return enrolment; } } return null; } private static final int MAXIMUM_STUDENT_ATTENDS_PER_EXECUTION_PERIOD = 10; // ; private void checkIfReachedAttendsLimit() { final IUserView userView = AccessControl.getUserView(); if (userView == null || !userView.hasRoleType(RoleType.ACADEMIC_ADMINISTRATIVE_OFFICE)) { if (readAttendsInCurrentExecutionPeriod().size() >= MAXIMUM_STUDENT_ATTENDS_PER_EXECUTION_PERIOD) { throw new DomainException("error.student.reached.attends.limit", String .valueOf(MAXIMUM_STUDENT_ATTENDS_PER_EXECUTION_PERIOD)); } } } final public void removeAttendFor(final ExecutionCourse executionCourse) { final Attends attend = readRegistrationAttendByExecutionCourse(executionCourse); if (attend != null) { checkIfHasEnrolmentFor(attend); checkIfHasShiftsFor(executionCourse); attend.delete(); } } private void checkIfHasEnrolmentFor(final Attends attend) { if (attend.hasEnrolment()) { throw new DomainException("errors.student.already.enroled"); } } private void checkIfHasShiftsFor(final ExecutionCourse executionCourse) { if (!getShiftsFor(executionCourse).isEmpty()) { throw new DomainException("errors.student.already.enroled.in.shift"); } } public Tutorship getActiveTutorship() { return getLastStudentCurricularPlan().getActiveTutorship(); } @Override final public Integer getNumber() { return (super.getNumber() != null) ? super.getNumber() : getStudent().getNumber(); } final public Person getPerson() { return getStudent().getPerson(); } final public String getName() { return getPerson().getName(); } final public String getEmail() { return getPerson().getEmail(); } final public Double getEntryGrade() { return hasStudentCandidacy() ? getStudentCandidacy().getEntryGrade() : null; } final public void setEntryGrade(Double entryGrade) { if (hasStudentCandidacy()) { getStudentCandidacy().setEntryGrade(entryGrade); } else { throw new DomainException("error.registration.withou.student.candidacy"); } } final public String getPrecedentDegreeConclusionGrade(final SchoolLevelType levelType) { return hasPrecedentDegreeInformation(levelType) ? getPrecedentDegreeInformation(levelType).getConclusionGrade() : null; } public boolean hasPrecedentDegreeInformation(SchoolLevelType levelType) { return getPrecedentDegreeInformation(levelType) != null; } public PrecedentDegreeInformation getPrecedentDegreeInformation(final SchoolLevelType levelType) { return (super.hasPrecedentDegreeInformation() && super.getPrecedentDegreeInformation().getSchoolLevel() == levelType) ? super .getPrecedentDegreeInformation() : null; } public boolean isFirstCycleAtributionIngression() { return getIngression() == Ingression.AG1C; } public boolean isSecondCycleInternalCandidacyIngression() { return getIngression() == Ingression.CIA2C; } @Override public void setIngression(Ingression ingression) { checkIngression(ingression); super.setIngression(ingression); } private void checkIngression(final Ingression ingression) { checkIngression(ingression, getPerson(), getFirstStudentCurricularPlan().getDegreeCurricularPlan()); } public static void checkIngression(Ingression ingression, Person person, DegreeCurricularPlan degreeCurricularPlan) { if (ingression == Ingression.RI) { if (person == null || !person.hasStudent()) { throw new DomainException("error.registration.preBolonhaSourceDegreeNotFound"); } if (degreeCurricularPlan.hasEquivalencePlan()) { final Student student = person.getStudent(); final Degree sourceDegree = degreeCurricularPlan.getEquivalencePlan().getSourceDegreeCurricularPlan().getDegree(); Registration sourceRegistration = person.getStudent().readRegistrationByDegree(sourceDegree); if (sourceRegistration == null) { final Collection registrations = student.getRegistrationsByDegreeType(DegreeType.DEGREE); registrations.removeAll(student.getRegistrationsFor(degreeCurricularPlan)); sourceRegistration = registrations.size() == 1 ? registrations.iterator().next() : null; } if (sourceRegistration == null) { throw new DomainException("error.registration.preBolonhaSourceDegreeNotFound"); } else if (!sourceRegistration.getActiveStateType().canReingress()) { throw new DomainException("error.registration.preBolonhaSourceRegistrationCannotReingress"); } } } } final public ExecutionYear getIngressionYear() { if (!isBolonha() && isRegistrationConclusionProcessed()) { return getConclusionProcess().getIngressionYear(); } return calculateIngressionYear(); } public ExecutionYear calculateIngressionYear() { return inspectIngressionYear(this); } private ExecutionYear inspectIngressionYear(final Registration registration) { if (!registration.hasSourceRegistration()) { return registration.getStartExecutionYear(); } return inspectIngressionYear(registration.getSourceRegistration()); } final public String getContigent() { return hasStudentCandidacy() ? getStudentCandidacy().getContigent() : null; } public String getDegreeNameWithDegreeCurricularPlanName() { final StudentCurricularPlan toAsk = getStudentCurricularPlan(getStartExecutionYear()) == null ? getFirstStudentCurricularPlan() : getStudentCurricularPlan(getStartExecutionYear()); if (toAsk == null) { return StringUtils.EMPTY; } return toAsk.getPresentationName(getStartExecutionYear()); } public String getDegreeNameWithDescription() { return getDegree().getPresentationName(getStartExecutionYear()); } public String getDegreeName() { return getDegree().getNameFor(getStartExecutionYear()).getContent(); } final public String getDegreeDescription() { final DegreeType degreeType = getDegreeType(); return getDegreeDescription(degreeType.hasExactlyOneCycleType() ? degreeType.getCycleType() : getLastConcludedCycleType()); } final public String getDegreeDescription(final CycleType cycleType) { return getDegreeDescription(cycleType, Language.getLocale()); } final public String getDegreeDescription(final CycleType cycleType, final Locale locale) { final StringBuilder res = new StringBuilder(); final ResourceBundle bundle = ResourceBundle.getBundle("resources.AcademicAdminOffice", locale); final Degree degree = getDegree(); final DegreeType degreeType = degree.getDegreeType(); if (getDegreeType() != DegreeType.BOLONHA_ADVANCED_FORMATION_DIPLOMA && cycleType != null) { res.append(cycleType.getDescription(locale)).append(","); res.append(StringUtils.SINGLE_SPACE).append(bundle.getString("label.of.the.male")).append(StringUtils.SINGLE_SPACE); } if (!isEmptyDegree()) { res.append(degreeType.getPrefix(locale)); res.append(degreeType.getFilteredName(locale).toUpperCase()); if (getDegreeType() == DegreeType.BOLONHA_ADVANCED_FORMATION_DIPLOMA && cycleType != null) { res.append(" (").append(cycleType.getDescription(locale)).append(")"); } res.append(StringUtils.SINGLE_SPACE).append(bundle.getString("label.in")).append(StringUtils.SINGLE_SPACE); } res.append(degree.getFilteredName(this.getStartExecutionYear(), locale).toUpperCase()); return res.toString(); } @Linkare(author = "Paulo Zenida", comments = "Added this method to deal with the situation where the degee has no cycle types") final public String getDegreeDescription(final DegreeType degreeType, final Locale locale) { if (degreeType.hasAnyCycleTypes()) { throw new DomainException("error.degreeType.has.cycleTypes.use.method.with.cycleType.instead"); } final StringBuilder res = new StringBuilder(); final ResourceBundle bundle = ResourceBundle.getBundle("resources.AcademicAdminOffice", locale); final Degree degree = getDegree(); if (degreeType != DegreeType.BOLONHA_ADVANCED_FORMATION_DIPLOMA) { res.append(degreeType.getLocalizedName(locale)).append(","); res.append(StringUtils.SINGLE_SPACE).append(bundle.getString("label.of.the.male")).append(StringUtils.SINGLE_SPACE); } if (!isEmptyDegree()) { res.append(degreeType.getPrefix(locale)); res.append(degreeType.getFilteredName(locale).toUpperCase()); if (degreeType == DegreeType.BOLONHA_ADVANCED_FORMATION_DIPLOMA) { res.append(" (").append(degreeType.getLocalizedName(locale)).append(")"); } res.append(StringUtils.SINGLE_SPACE).append(bundle.getString("label.in")).append(StringUtils.SINGLE_SPACE); } res.append(degree.getFilteredName(this.getStartExecutionYear(), locale).toUpperCase()); return res.toString(); } public String getDegreeCurricularPlanName() { return getLastDegreeCurricularPlan().getName(); } @Override final public Degree getDegree() { return super.getDegree() != null ? super.getDegree() : (hasAnyStudentCurricularPlans() ? getLastStudentCurricularPlan() .getDegree() : null); } final public DegreeType getDegreeType() { return getDegree().getDegreeType(); } final public boolean isBolonha() { return getDegreeType().isBolonhaType(); } @Linkare(author = "Paulo Zenida") final public boolean isOldDegree() { return getDegreeType().isOldDegree(); } final public boolean isActiveForOffice(Unit office) { return isActive() && isForOffice(office.getAdministrativeOffice()); } public boolean isDegreeAdministrativeOffice() { return getDegreeType().getAdministrativeOfficeType() == AdministrativeOfficeType.DEGREE; } final public boolean isForOffice(final AdministrativeOffice administrativeOffice) { return getDegreeType().getAdministrativeOfficeType().equals(administrativeOffice.getAdministrativeOfficeType()); } final public boolean getIsForOffice() { final AdministrativeOffice administrativeOffice = AccessControl.getPerson().getEmployee().getAdministrativeOffice(); return isForOffice(administrativeOffice); } final public List getPublishedTestGroups() { List testGroups = new ArrayList(); for (ExecutionCourse executionCourse : this.getAttendingExecutionCoursesForCurrentExecutionPeriod()) { testGroups.addAll(executionCourse.getPublishedTestGroups()); } return testGroups; } final public List getFinishedTestGroups() { List testGroups = new ArrayList(); for (ExecutionCourse executionCourse : this.getAttendingExecutionCoursesForCurrentExecutionPeriod()) { testGroups.addAll(executionCourse.getFinishedTestGroups()); } return testGroups; } public boolean isCurricularCourseApproved(final CurricularCourse curricularCourse) { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { if (studentCurricularPlan.isCurricularCourseApproved(curricularCourse)) { return true; } } return false; } final public Set getRegistrationStatesTypes(final ExecutionYear executionYear) { final Set result = new HashSet(); for (final RegistrationState registrationState : getRegistrationStates(executionYear)) { result.add(registrationState.getStateType()); } return result; } final public Set getRegistrationStatesTypes(final ExecutionSemester executionSemester) { final Set result = new HashSet(); for (final RegistrationState registrationState : getRegistrationStates(executionSemester)) { result.add(registrationState.getStateType()); } return result; } public boolean isRegistered(final DateTime when) { final RegistrationState stateInDate = getStateInDate(when); return (stateInDate != null && stateInDate.isActive()) || hasAnyEnrolmentsIn(ExecutionSemester.readByDateTime(when)); } public boolean isRegistered(final ExecutionSemester executionSemester) { return hasAnyActiveState(executionSemester) || hasAnyEnrolmentsIn(executionSemester); } final public boolean isRegistered(final ExecutionYear executionYear) { return hasAnyActiveState(executionYear) || hasAnyEnrolmentsIn(executionYear); } final public RegistrationState getActiveState() { return hasAnyRegistrationStates() ? Collections.max(getRegistrationStates(), RegistrationState.DATE_COMPARATOR) : null; } final public RegistrationState getFirstState() { return getFirstRegistrationState(); } final public RegistrationStateType getActiveStateType() { final RegistrationState activeState = getActiveState(); return activeState != null ? activeState.getStateType() : RegistrationStateType.REGISTERED; } final public boolean isActive() { return getActiveStateType().isActive(); } public boolean hasAnyActiveState(final ExecutionSemester executionSemester) { for (RegistrationState registrationState : getRegistrationStates(executionSemester)) { if (registrationState.isActive()) { return true; } } return false; } public boolean hasAnyActiveState(final ExecutionYear executionYear) { for (RegistrationState registrationState : getRegistrationStates(executionYear)) { if (registrationState.isActive()) { return true; } } return false; } public boolean hasActiveFirstState(final ExecutionYear period) { final Set states = getRegistrationStates(period); return states.isEmpty() ? false : Collections.min(states, RegistrationState.DATE_COMPARATOR).isActive(); } public boolean hasActiveLastState(final ExecutionSemester executionSemester) { final Set states = getRegistrationStates(executionSemester); return states.isEmpty() ? false : Collections.max(states, RegistrationState.DATE_COMPARATOR).isActive(); } public boolean hasRegistrationState(final RegistrationStateType stateType) { for (final RegistrationState state : getRegistrationStatesSet()) { if (state.getStateType() == stateType) { return true; } } return false; } final public boolean isInRegisteredState() { return getActiveStateType() == RegistrationStateType.REGISTERED; } final public boolean isInternalAbandon() { return getActiveStateType() == RegistrationStateType.INTERNAL_ABANDON; } final public boolean getInterruptedStudies() { return isInterrupted(); } public boolean isInterrupted() { return getActiveStateType() == RegistrationStateType.INTERRUPTED; } final public boolean getFlunked() { return isFlunked(); } public boolean isFlunked() { return getActiveStateType() == RegistrationStateType.FLUNKED; } final public boolean isInMobilityState() { return getActiveStateType() == RegistrationStateType.MOBILITY; } public boolean isSchoolPartConcluded() { return getActiveStateType() == RegistrationStateType.SCHOOLPARTCONCLUDED; } public boolean isConcluded() { return getActiveStateType() == RegistrationStateType.CONCLUDED; } public boolean isTransited() { return getActiveStateType() == RegistrationStateType.TRANSITED; } public boolean isCanceled() { return getActiveStateType() == RegistrationStateType.CANCELED; } final public boolean isTransited(final DateTime when) { final RegistrationState stateInDate = getStateInDate(when); return stateInDate != null && stateInDate.getStateType() == RegistrationStateType.TRANSITED; } final public boolean isTransition() { return getActiveStateType() == RegistrationStateType.TRANSITION; } final public boolean isTransition(final ExecutionYear executionYear) { return hasStateType(executionYear, RegistrationStateType.TRANSITION); } final public boolean getWasTransition() { return hasState(RegistrationStateType.TRANSITION); } final public RegistrationState getStateInDate(DateTime dateTime) { List sortedRegistrationStates = new ArrayList(getRegistrationStates()); Collections.sort(sortedRegistrationStates, RegistrationState.DATE_COMPARATOR); for (ListIterator iterator = sortedRegistrationStates.listIterator(sortedRegistrationStates.size()); iterator .hasPrevious();) { RegistrationState registrationState = iterator.previous(); if (!dateTime.isBefore(registrationState.getStateDate())) { return registrationState; } } return null; } final public RegistrationState getStateInDate(final LocalDate localDate) { final List sortedRegistrationStates = new ArrayList(getRegistrationStates()); Collections.sort(sortedRegistrationStates, RegistrationState.DATE_COMPARATOR); for (ListIterator iterator = sortedRegistrationStates.listIterator(sortedRegistrationStates.size()); iterator .hasPrevious();) { RegistrationState registrationState = iterator.previous(); if (!localDate.isBefore(registrationState.getStateDate().toLocalDate())) { return registrationState; } } return null; } public Set getRegistrationStates(final ExecutionYear executionYear) { return getRegistrationStates(executionYear.getBeginDateYearMonthDay().toDateTimeAtMidnight(), executionYear .getEndDateYearMonthDay().toDateTimeAtMidnight()); } public Set getRegistrationStates(final ExecutionSemester executionSemester) { return getRegistrationStates(executionSemester.getBeginDateYearMonthDay().toDateTimeAtMidnight(), executionSemester .getEndDateYearMonthDay().toDateTimeAtMidnight()); } public Set getRegistrationStates(final ReadableInstant beginDateTime, final ReadableInstant endDateTime) { final Set result = new HashSet(); populateRegistrationStates(beginDateTime, endDateTime, result); return result; } public List getRegistrationStatesList(final ExecutionYear executionYear) { return getRegistrationStatesList(executionYear.getBeginDateYearMonthDay().toDateTimeAtMidnight(), executionYear .getEndDateYearMonthDay().toDateTimeAtMidnight()); } public List getRegistrationStatesList(final ExecutionSemester executionSemester) { return getRegistrationStatesList(executionSemester.getBeginDateYearMonthDay().toDateTimeAtMidnight(), executionSemester .getEndDateYearMonthDay().toDateTimeAtMidnight()); } public List getRegistrationStatesList(final ReadableInstant beginDateTime, final ReadableInstant endDateTime) { final List result = new ArrayList(); populateRegistrationStates(beginDateTime, endDateTime, result); return result; } private void populateRegistrationStates(final ReadableInstant beginDateTime, final ReadableInstant endDateTime, final Collection result) { List sortedRegistrationsStates = new ArrayList(getRegistrationStates()); Collections.sort(sortedRegistrationsStates, RegistrationState.DATE_COMPARATOR); for (ListIterator iter = sortedRegistrationsStates.listIterator(sortedRegistrationsStates.size()); iter .hasPrevious();) { RegistrationState state = iter.previous(); if (state.getStateDate().isAfter(endDateTime)) { continue; } result.add(state); if (!state.getStateDate().isAfter(beginDateTime)) { break; } } } public RegistrationState getFirstRegistrationState() { return hasAnyRegistrationStates() ? Collections.min(getRegistrationStates(), RegistrationState.DATE_COMPARATOR) : null; } final public RegistrationState getLastRegistrationState(final ExecutionYear executionYear) { List sortedRegistrationsStates = new ArrayList(getRegistrationStates()); Collections.sort(sortedRegistrationsStates, RegistrationState.DATE_COMPARATOR); for (ListIterator iter = sortedRegistrationsStates.listIterator(sortedRegistrationsStates.size()); iter .hasPrevious();) { RegistrationState state = iter.previous(); if (state.getStateDate().isAfter(executionYear.getEndDateYearMonthDay().toDateTimeAtMidnight())) { continue; } return state; } return null; } public boolean hasState(final RegistrationStateType stateType) { return hasAnyState(Collections.singletonList(stateType)); } public boolean hasAnyState(final Collection stateTypes) { for (final RegistrationState registrationState : getRegistrationStates()) { if (stateTypes.contains(registrationState.getStateType())) { return true; } } return false; } final public boolean hasStateType(final ExecutionSemester executionSemester, final RegistrationStateType registrationStateType) { return getRegistrationStatesTypes(executionSemester).contains(registrationStateType); } final public boolean hasStateType(final ExecutionYear executionYear, final RegistrationStateType registrationStateType) { return getRegistrationStatesTypes(executionYear).contains(registrationStateType); } public boolean hasFlunkedState(final ExecutionYear executionYear) { return hasStateType(executionYear, RegistrationStateType.FLUNKED); } public boolean hasRegisteredActiveState() { return getActiveStateType() == RegistrationStateType.REGISTERED; } public Collection getRegistrationStates(final RegistrationStateType registrationStateType) { return getRegistrationStates(Collections.singletonList(registrationStateType)); } public Collection getRegistrationStates(final Collection registrationStateTypes) { final Collection result = new HashSet(); for (final RegistrationState registrationState : getRegistrationStates()) { if (registrationStateTypes.contains(registrationState.getStateType())) { result.add(registrationState); } } return result; } final public double getEctsCredits() { if (!isBolonha() && isRegistrationConclusionProcessed()) { return getConclusionProcess().getCredits().doubleValue(); } return calculateCredits(); } public double calculateCredits() { return getTotalEctsCredits((ExecutionYear) null).doubleValue(); } final public BigDecimal getTotalEctsCredits(final ExecutionYear executionYear) { return getCurriculum(executionYear).getSumEctsCredits(); } public double getEnrolmentsEcts(final ExecutionYear executionYear) { return getLastStudentCurricularPlan().getEnrolmentsEctsCredits(executionYear); } final public int getCurricularYear() { return getCurricularYear(ExecutionYear.readCurrentExecutionYear()); } final public int getCurricularYear(ExecutionYear executionYear) { return getCurriculum(executionYear).getCurricularYear(); } final public int getCurricularYear(final DateTime when, final ExecutionYear executionYear) { return getCurriculum(when, executionYear, (CycleType) null).getCurricularYear(); } final public Person getConclusionProcessResponsible() { return isRegistrationConclusionProcessed() ? getConclusionProcess().getResponsible() : null; } final public Person getConclusionProcessLastResponsible() { return isRegistrationConclusionProcessed() ? getConclusionProcess().getLastResponsible() : null; } @Linkare(author = "Paulo Zenida", comments = "Changed the logic to check if the degree has any cycle instead of checking for bolonha and non bolonha") public boolean isRegistrationConclusionProcessed() { if (getDegreeType().hasAnyCycleTypes()) { return getLastStudentCurricularPlan().isConclusionProcessed(); } else { return hasConclusionProcess(); } } public boolean isRegistrationConclusionProcessed(final CycleType cycleType) { if (cycleType == null) { return isRegistrationConclusionProcessed(); } else if (getDegreeType().isBolonhaType() && getDegreeType().hasCycleTypes(cycleType)) { return getLastStudentCurricularPlan().isConclusionProcessed(cycleType); } throw new DomainException("Registration.degree.type.has.no.such.cycle.type"); } public boolean isQualifiedToRegistrationConclusionProcess() { return isActive() || isConcluded(); } public ExecutionYear getConclusionYear() { return isRegistrationConclusionProcessed() ? getConclusionProcess().getConclusionYear() : null; } public ExecutionYear calculateConclusionYear() { ExecutionYear result = getLastApprovementExecutionYear(); if (result == null && hasState(RegistrationStateType.CONCLUDED)) { final SortedSet states = new TreeSet(RegistrationState.DATE_COMPARATOR); states.addAll(getRegistrationStates(RegistrationStateType.CONCLUDED)); return states.first().getExecutionYear(); } return result; } @Linkare(author = "Paulo Zenida", comments = "Changed the logic to check if the degree has any cycle instead of checking for bolonha and non bolonha") public YearMonthDay getConclusionDate() { if (getDegreeType().hasAnyCycleTypes()) { throw new DomainException("error.Registration.for.cannot.get.conclusion.date.in.registration.for.bolonha"); } return isRegistrationConclusionProcessed() ? getConclusionProcess().getConclusionYearMonthDay() : null; } public YearMonthDay getConclusionDateForBolonha() { if (isBolonha()) { if (hasConcluded()) { final SortedSet concludeCycles = new TreeSet( CycleCurriculumGroup.COMPARATOR_BY_CYCLE_TYPE_AND_ID); concludeCycles.addAll(getLastStudentCurricularPlan().getInternalCycleCurriculumGrops()); final CycleCurriculumGroup lastConcludedCycle = concludeCycles.last(); return (lastConcludedCycle.isConclusionProcessed() ? lastConcludedCycle.getConclusionDate() : lastConcludedCycle .calculateConclusionDate()); } } else { return getConclusionDate(); } return null; } final public YearMonthDay getConclusionDate(final CycleType cycleType) { if (!getDegreeType().hasAnyCycleTypes()) { return getConclusionDate(); } if (!hasConcludedCycle(cycleType)) { throw new DomainException("Registration.hasnt.finished.given.cycle"); } final StudentCurricularPlan lastStudentCurricularPlan = getLastStudentCurricularPlan(); if (lastStudentCurricularPlan == null) { throw new DomainException("Registration.has.no.student.curricular.plan"); } return lastStudentCurricularPlan.getConclusionDate(cycleType); } public YearMonthDay calculateConclusionDate() { if (isBolonha()) { return getLastStudentCurricularPlan().getLastApprovementDate(); } else { YearMonthDay result = null; for (final StudentCurricularPlan plan : getStudentCurricularPlansSet()) { final YearMonthDay date = plan.getLastApprovementDate(); if (date != null && (result == null || result.isBefore(date))) { result = date; } } if (getDegreeType() == DegreeType.MASTER_DEGREE) { final LocalDate date = getDissertationThesisDiscussedDate(); if (date != null && (result == null || result.isBefore(date))) { result = new YearMonthDay(date); } } if (result == null && hasState(RegistrationStateType.CONCLUDED)) { final SortedSet states = new TreeSet(RegistrationState.DATE_COMPARATOR); states.addAll(getRegistrationStates(RegistrationStateType.CONCLUDED)); return states.last().getStateDate().toYearMonthDay(); } return result; } } public YearMonthDay calculateConclusionDate(final CycleType cycleType) { if (!getDegreeType().hasAnyCycleTypes()) { return calculateConclusionDate(); } if (!hasConcludedCycle(cycleType)) { throw new DomainException("Registration.hasnt.finished.given.cycle"); } final StudentCurricularPlan lastStudentCurricularPlan = getLastStudentCurricularPlan(); if (lastStudentCurricularPlan == null) { throw new DomainException("Registration.has.no.student.curricular.plan"); } return lastStudentCurricularPlan.calculateConclusionDate(cycleType); } final public String getConclusionProcessNotes() { return isRegistrationConclusionProcessed() ? getConclusionProcess().getNotes() : null; } final public DateTime getConclusionProcessCreationDateTime() { return isRegistrationConclusionProcessed() ? getConclusionProcess().getCreationDateTime() : null; } final public DateTime getConclusionProcessLastModificationDateTime() { return isRegistrationConclusionProcessed() ? getConclusionProcess().getLastModificationDateTime() : null; } final public String getGraduateTitle() { return getGraduateTitle((CycleType) null, Language.getLocale()); } final public String getGraduateTitle(final CycleType cycleType, final Locale locale) { if (cycleType == null) { if (isRegistrationConclusionProcessed()) { return getLastDegreeCurricularPlan().getGraduateTitle(getStartExecutionYear(), locale); } throw new DomainException("Registration.is.not.concluded"); } if (hasConcludedCycle(cycleType)) { return getLastDegreeCurricularPlan().getGraduateTitle(getStartExecutionYear(), cycleType, locale); } throw new DomainException("Registration.hasnt.concluded.requested.cycle"); } final public boolean hasConcludedFirstCycle() { return hasConcludedCycle(CycleType.FIRST_CYCLE); } final public boolean hasConcludedSecondCycle() { return hasConcludedCycle(CycleType.SECOND_CYCLE); } final public boolean hasConcludedCycle(final CycleType cycleType) { return getLastStudentCurricularPlan().hasConcludedCycle(cycleType); } final public boolean hasConcludedCycle(final CycleType cycleType, final ExecutionYear executionYear) { return getLastStudentCurricularPlan().hasConcludedCycle(cycleType, executionYear); } public boolean hasConcluded() { final StudentCurricularPlan lastStudentCurricularPlan = getLastStudentCurricularPlan(); if (lastStudentCurricularPlan == null || !lastStudentCurricularPlan.isBolonhaDegree()) { return true; } for (final CycleCurriculumGroup cycleCurriculumGroup : lastStudentCurricularPlan.getInternalCycleCurriculumGrops()) { if (!cycleCurriculumGroup.isConcluded()) { return false; } } return !lastStudentCurricularPlan.getCycleCurriculumGroups().isEmpty(); } public boolean getHasConcluded() { return hasConcluded(); } final public Collection getConcludedCycles() { if (!getDegreeType().hasAnyCycleTypes()) { return Collections.EMPTY_SET; } final Collection result = new TreeSet(CycleType.COMPARATOR_BY_LESS_WEIGHT); for (final CycleType cycleType : getDegreeType().getCycleTypes()) { if (hasConcludedCycle(cycleType)) { result.add(cycleType); } } return result; } final public Collection getConclusionProcessedCycles(final ExecutionYear executionYear) { final Collection result = new HashSet(); for (final CycleCurriculumGroup group : getLastStudentCurricularPlan().getInternalCycleCurriculumGrops()) { if (group.isConclusionProcessed() && group.getConclusionYear() == executionYear) { result.add(group); } } return result; } final public Collection getConcludedCycles(final ExecutionYear executionYear) { if (!getDegreeType().hasAnyCycleTypes()) { return Collections.emptySet(); } final Collection result = new TreeSet(CycleType.COMPARATOR_BY_LESS_WEIGHT); for (final CycleType cycleType : getDegreeType().getCycleTypes()) { if (hasConcludedCycle(cycleType, executionYear)) { result.add(cycleType); } } return result; } final public CycleType getCurrentCycleType() { return getCycleType(ExecutionYear.readCurrentExecutionYear()); } final public CycleType getCycleType(final ExecutionYear executionYear) { if (!isBolonha() || isEmptyDegree()) { return null; } final SortedSet concludedCycles = new TreeSet(getConcludedCycles(executionYear)); if (concludedCycles.isEmpty()) { return getLastStudentCurricularPlan().getFirstOrderedCycleCurriculumGroup().getCycleType(); } else { CycleType result = null; for (CycleType cycleType : concludedCycles) { final CycleCurriculumGroup group = getLastStudentCurricularPlan().getCycle(cycleType); if (group.hasEnrolment(executionYear)) { result = cycleType; } } if (result != null) { return result; } final CycleType last = concludedCycles.last(); return last.hasNext() && getDegreeType().hasCycleTypes(last.getNext()) ? last.getNext() : last; } } private boolean isEmptyDegree() { return getLastDegreeCurricularPlan().isEmpty(); } final public CycleType getLastConcludedCycleType() { final SortedSet concludedCycles = new TreeSet(getConcludedCycles()); return concludedCycles.isEmpty() ? null : concludedCycles.last(); } @Checked("RegistrationPredicates.MANAGE_CONCLUSION_PROCESS") public void conclude() { if (isBolonha()) { throw new DomainException("error.Registration.cannot.apply.to.bolonha"); } if (isRegistrationConclusionProcessed()) { if (!canRepeatConclusionProcess(AccessControl.getPerson())) { throw new DomainException("error.Registration.already.concluded"); } } if (hasConclusionProcess()) { getConclusionProcess().update(new RegistrationConclusionBean(this)); } else { RegistrationConclusionProcess.conclude(new RegistrationConclusionBean(this)); } } public boolean canRepeatConclusionProcess(Person person) { final AdministrativeOfficePermission permission = person.getEmployeeAdministrativeOffice().getPermission( PermissionType.REPEAT_CONCLUSION_PROCESS, person.getEmployeeCampus()); return permission != null && permission.isAppliable(this) && permission.isMember(person); } @Checked("RolePredicates.MANAGER_PREDICATE") public void editConclusionInformation(final Integer finalAverage, final YearMonthDay conclusion, final String notes) { editConclusionInformation(AccessControl.getPerson(), finalAverage, conclusion, notes); } @Checked("RolePredicates.MANAGER_PREDICATE") public void editConclusionInformation(final Person editor, final Integer finalAverage, final YearMonthDay conclusion, final String notes) { if (!isRegistrationConclusionProcessed()) { throw new DomainException("error.Registration.its.only.possible.to.edit.after.conclusion.process.has.been.performed"); } check(finalAverage, "error.Registration.argument.must.not.be.null"); check(conclusion, "error.Registration.argument.must.not.be.null"); getConclusionProcess().update(editor, finalAverage, conclusion.toLocalDate(), notes); } @Checked("RegistrationPredicates.MANAGE_CONCLUSION_PROCESS") public void conclude(final CycleCurriculumGroup cycleCurriculumGroup) { if (!isBolonha()) { throw new DomainException("error.Registration.cannot.apply.to.preBolonha"); } if (cycleCurriculumGroup == null || !getLastStudentCurricularPlan().hasCurriculumModule(cycleCurriculumGroup)) { throw new DomainException("error.Registration.invalid.cycleCurriculumGroup"); } cycleCurriculumGroup.conclude(); if (!isConcluded() && isRegistrationConclusionProcessed()) { RegistrationStateCreator .createState(this, AccessControl.getPerson(), new DateTime(), RegistrationStateType.CONCLUDED); } } final public boolean hasApprovement(ExecutionYear executionYear) { int curricularYearInTheBegin = getCurricularYear(executionYear); int curricularYearAtTheEnd = getCurricularYear(executionYear.getNextExecutionYear()); if (curricularYearInTheBegin > curricularYearAtTheEnd) { throw new DomainException("Registration.curricular.year.has.decreased"); } return curricularYearAtTheEnd > curricularYearInTheBegin; } final public boolean isDegreeOrBolonhaDegreeOrBolonhaIntegratedMasterDegree() { return getDegreeType().isDegreeOrBolonhaDegreeOrBolonhaIntegratedMasterDegree(); } final public boolean isMasterDegreeOrBolonhaMasterDegree() { final DegreeType degreeType = getDegreeType(); return (degreeType == DegreeType.MASTER_DEGREE || degreeType == DegreeType.BOLONHA_MASTER_DEGREE); } final public boolean isDEA() { return getDegreeType() == DegreeType.BOLONHA_ADVANCED_SPECIALIZATION_DIPLOMA; } final public EnrolmentModel getEnrolmentModelForCurrentExecutionYear() { return getEnrolmentModelForExecutionYear(ExecutionYear.readCurrentExecutionYear()); } final public EnrolmentModel getEnrolmentModelForExecutionYear(ExecutionYear year) { RegistrationDataByExecutionYear registrationData = getRegistrationDataByExecutionYear(year); return registrationData != null ? registrationData.getEnrolmentModel() : null; } final public void setEnrolmentModelForCurrentExecutionYear(EnrolmentModel model) { setEnrolmentModelForExecutionYear(ExecutionYear.readCurrentExecutionYear(), model); } final public void setEnrolmentModelForExecutionYear(ExecutionYear year, EnrolmentModel model) { RegistrationDataByExecutionYear registrationData = getRegistrationDataByExecutionYear(year); if (registrationData == null) { registrationData = new RegistrationDataByExecutionYear(this, year); } registrationData.setEnrolmentModel(model); } private RegistrationDataByExecutionYear getRegistrationDataByExecutionYear(ExecutionYear year) { for (RegistrationDataByExecutionYear registrationData : getRegistrationDataByExecutionYearSet()) { if (registrationData.getExecutionYear().equals(year)) { return registrationData; } } return null; } @Override final public ExecutionYear getRegistrationYear() { return super.getRegistrationYear() == null ? getFirstEnrolmentExecutionYear() : super.getRegistrationYear(); } final public boolean isFirstTime(ExecutionYear executionYear) { return getRegistrationYear() == executionYear; } final public boolean isFirstTime() { return isFirstTime(ExecutionYear.readCurrentExecutionYear()); } final public StudentCurricularPlan getStudentCurricularPlan(final ExecutionYear executionYear) { return executionYear == null ? getStudentCurricularPlan(new YearMonthDay()) : getStudentCurricularPlan(executionYear .getEndDateYearMonthDay()); } final public StudentCurricularPlan getStudentCurricularPlan(final ExecutionSemester executionSemester) { return executionSemester == null ? getStudentCurricularPlan(new YearMonthDay()) : getStudentCurricularPlan(executionSemester.getEndDateYearMonthDay()); } final public StudentCurricularPlan getStudentCurricularPlan(final YearMonthDay date) { StudentCurricularPlan result = null; for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { final YearMonthDay startDate = studentCurricularPlan.getStartDateYearMonthDay(); if (!startDate.isAfter(date) && (result == null || startDate.isAfter(result.getStartDateYearMonthDay()))) { result = studentCurricularPlan; } } return result; } final public StudentCurricularPlan getStudentCurricularPlan(final DegreeCurricularPlan degreeCurricularPlan) { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { if (studentCurricularPlan.getDegreeCurricularPlan().equals(degreeCurricularPlan)) { return studentCurricularPlan; } } return null; } final public Set getDegreeCurricularPlans() { Set result = new HashSet(); for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { result.add(studentCurricularPlan.getDegreeCurricularPlan()); } return result; } @Override final public YearMonthDay getStartDate() { if (super.getStartDate() != null) { return super.getStartDate(); } if (hasStudentCandidacy()) { return getStudentCandidacy().getActiveCandidacySituation().getSituationDate().toYearMonthDay(); } if (getRegistrationYear() != null) { return getRegistrationYear().getBeginDateYearMonthDay(); } return null; } @Linkare(author = "Paulo Zenida", comments = "Added the logic to return the registration year in case the year through the date is null") final public ExecutionYear getStartExecutionYear() { return ExecutionYear.readByDateTime(getStartDate().toDateTimeAtMidnight()) == null ? getRegistrationYear() : ExecutionYear.readByDateTime(getStartDate().toDateTimeAtMidnight()); } final public boolean hasStartedBeforeFirstBolonhaExecutionYear() { return getStartExecutionYear().isBefore(ExecutionYear.readFirstBolonhaExecutionYear()); } final public boolean hasStudentCurricularPlanInExecutionPeriod(ExecutionSemester executionSemester) { return getStudentCurricularPlan(executionSemester) != null; } final public boolean isCustomEnrolmentModel(final ExecutionYear executionYear) { return getEnrolmentModelForExecutionYear(executionYear) == EnrolmentModel.CUSTOM; } final public boolean isCustomEnrolmentModel() { return isCustomEnrolmentModel(ExecutionYear.readCurrentExecutionYear()); } final public boolean isCompleteEnrolmentModel(final ExecutionYear executionYear) { return getEnrolmentModelForExecutionYear(executionYear) == EnrolmentModel.COMPLETE; } final public boolean isCompleteEnrolmentModel() { return isCompleteEnrolmentModel(ExecutionYear.readCurrentExecutionYear()); } final public DegreeCurricularPlan getActiveDegreeCurricularPlan() { return (getActiveStudentCurricularPlan() != null ? getActiveStudentCurricularPlan().getDegreeCurricularPlan() : null); } final public DegreeCurricularPlan getLastDegreeCurricularPlan() { return (getLastStudentCurricularPlan() != null ? getLastStudentCurricularPlan().getDegreeCurricularPlan() : null); } public Degree getLastDegree() { return getLastDegreeCurricularPlan().getDegree(); } private boolean hasAnyNotPayedGratuityEvents() { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { if (studentCurricularPlan.hasAnyNotPayedGratuityEvents()) { return true; } } return false; } private boolean hasAnyNotPayedInsuranceEvents() { for (final InsuranceEvent event : getPerson().getNotCancelledInsuranceEvents()) { if (event.isInDebt()) { return true; } } return false; } private boolean hasAnyNotPayedAdministrativeOfficeFeeAndInsuranceEvents(final AdministrativeOffice office) { for (final AdministrativeOfficeFeeAndInsuranceEvent event : getPerson() .getNotCancelledAdministrativeOfficeFeeAndInsuranceEvents(office)) { if (event.isInDebt()) { return true; } } return false; } private boolean hasAnyNotPayedGratuityEventUntil(final ExecutionYear executionYear) { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { if (studentCurricularPlan.hasAnyNotPayedGratuityEventsUntil(executionYear)) { return true; } } return false; } private boolean hasAnyNotPayedInsuranceEventUntil(final ExecutionYear executionYear) { for (final InsuranceEvent event : getPerson().getNotCancelledInsuranceEventsUntil(executionYear)) { if (event.isInDebt()) { return true; } } return false; } private boolean hasAnyNotPayedAdministrativeOfficeFeeAndInsuranceEventUntil(final AdministrativeOffice office, final ExecutionYear executionYear) { for (final AdministrativeOfficeFeeAndInsuranceEvent event : getPerson() .getNotCancelledAdministrativeOfficeFeeAndInsuranceEventsUntil(office, executionYear)) { if (event.isInDebt()) { return true; } } return false; } private boolean hasAnyNotPayedGratuityEventsForPreviousYears() { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { if (studentCurricularPlan.hasAnyNotPayedGratuityEventsForPreviousYears()) { return true; } } return false; } final public boolean hasToPayGratuityOrInsurance() { return getInterruptedStudies() ? false : getRegistrationAgreement().isToPayGratuity(); } final public DiplomaRequest getDiplomaRequest(final CycleType cycleType) { for (final DocumentRequest documentRequest : getDocumentRequests()) { if (documentRequest.isDiploma() && !documentRequest.finishedUnsuccessfully()) { final DiplomaRequest diplomaRequest = (DiplomaRequest) documentRequest; if (cycleType == null || cycleType == diplomaRequest.getWhatShouldBeRequestedCycle()) { return diplomaRequest; } } } return null; } final public Collection getDocumentRequests() { final Set result = new HashSet(); for (AcademicServiceRequest academicServiceRequest : getAcademicServiceRequestsSet()) { if (academicServiceRequest.isDocumentRequest()) { result.add((DocumentRequest) academicServiceRequest); } } return result; } final public Set getDocumentRequests(DocumentRequestType documentRequestType, AcademicServiceRequestSituationType academicServiceRequestSituationType, ExecutionYear executionYear, boolean collectDocumentsMarkedAsFreeProcessed) { final Set result = new HashSet(); for (final DocumentRequest documentRequest : getDocumentRequests()) { if (documentRequest.getDocumentRequestType() == documentRequestType && documentRequest.getAcademicServiceRequestSituationType() == academicServiceRequestSituationType && executionYear.containsDate(documentRequest.getCreationDate()) && (!collectDocumentsMarkedAsFreeProcessed || documentRequest.isFreeProcessed())) { result.add(documentRequest); } } return result; } final public Set getSucessfullyFinishedDocumentRequestsBy(ExecutionYear executionYear, DocumentRequestType documentRequestType, boolean collectDocumentsMarkedAsFreeProcessed) { final Set result = new HashSet(); for (final AcademicServiceRequest academicServiceRequest : getAcademicServiceRequestsSet()) { if (academicServiceRequest instanceof DocumentRequest) { final DocumentRequest documentRequest = (DocumentRequest) academicServiceRequest; if (documentRequest.getDocumentRequestType() == documentRequestType && documentRequest.finishedSuccessfully() && executionYear.containsDate(documentRequest.getCreationDate()) && (!collectDocumentsMarkedAsFreeProcessed || documentRequest.isFreeProcessed())) { result.add((DocumentRequest) academicServiceRequest); } } } return result; } final public Collection getSucessfullyFinishedDocumentRequests(final DocumentRequestType documentRequestType) { final Collection result = new HashSet(); for (final AcademicServiceRequest academicServiceRequest : getAcademicServiceRequestsSet()) { if (academicServiceRequest instanceof DocumentRequest) { final DocumentRequest documentRequest = (DocumentRequest) academicServiceRequest; if (documentRequest.getDocumentRequestType() == documentRequestType && documentRequest.finishedSuccessfully()) { result.add((DocumentRequest) academicServiceRequest); } } } return result; } final public Collection getAcademicServiceRequests( final Class clazz) { final Set result = new HashSet(); for (final AcademicServiceRequest academicServiceRequest : getAcademicServiceRequestsSet()) { if (clazz != null && academicServiceRequest.getClass().equals(clazz)) { result.add(academicServiceRequest); } } return result; } public Collection getAcademicServiceRequests( final Class clazz, final ExecutionYear executionYear) { final Set result = new HashSet(); for (final AcademicServiceRequest academicServiceRequest : getAcademicServiceRequestsSet()) { if (clazz != null && academicServiceRequest.getClass().equals(clazz) && academicServiceRequest.isFor(executionYear)) { result.add(academicServiceRequest); } } return result; } final public Collection getAcademicServiceRequests( final AcademicServiceRequestSituationType academicServiceRequestSituationType) { final Set result = new HashSet(); for (final AcademicServiceRequest academicServiceRequest : getAcademicServiceRequestsSet()) { if ((academicServiceRequestSituationType == null && academicServiceRequest.isNewRequest()) || academicServiceRequest.getAcademicServiceRequestSituationType() == academicServiceRequestSituationType) { result.add(academicServiceRequest); } } return result; } final public Collection getNewAcademicServiceRequests() { return (Collection) getAcademicServiceRequests(AcademicServiceRequestSituationType.NEW); } final public Collection getProcessingAcademicServiceRequests() { return (Collection) getAcademicServiceRequests(AcademicServiceRequestSituationType.PROCESSING); } final public Collection getConcludedAcademicServiceRequests() { return (Collection) getAcademicServiceRequests(AcademicServiceRequestSituationType.CONCLUDED); } public Collection getToConcludeAcademicServiceRequests() { final Collection result = new HashSet(); for (final AcademicServiceRequest academicServiceRequest : getAcademicServiceRequestsSet()) { if (academicServiceRequest.isConcludedSituationAccepted() || (academicServiceRequest.isSentToExternalEntity() && academicServiceRequest.hasProcessed() && !academicServiceRequest .hasConcluded())) { result.add(academicServiceRequest); } } return result; } public Collection getToDeliverAcademicServiceRequests() { final Collection result = new HashSet(); for (final AcademicServiceRequest academicServiceRequest : getAcademicServiceRequestsSet()) { if (academicServiceRequest.isDeliveredSituationAccepted() || (academicServiceRequest.isSentToExternalEntity() && academicServiceRequest.hasConcluded())) { result.add(academicServiceRequest); } } return result; } final public Collection getHistoricalAcademicServiceRequests() { final Set result = new HashSet(); for (final AcademicServiceRequest academicServiceRequest : getAcademicServiceRequestsSet()) { if (academicServiceRequest.isHistorical()) { result.add(academicServiceRequest); } } return result; } final public boolean isInactive() { return getActiveStateType().isInactive(); } public Campus getCampus() { return getLastStudentCurricularPlan().getLastCampus(); } public Campus getCampus(final ExecutionYear executionYear) { final StudentCurricularPlan scp = getStudentCurricularPlan(executionYear); return scp == null ? getLastStudentCurricularPlan().getCampus(executionYear) : scp.getCampus(executionYear); } final public String getIstUniversity() { return getCampus().getName(); } @Override final public void setStudentCandidacy(StudentCandidacy studentCandidacy) { if (hasStudentCandidacy()) { throw new DomainException( "error.net.sourceforge.fenixedu.domain.student.Registration.studentCandidacy.cannot.be.modified"); } super.setStudentCandidacy(studentCandidacy); } @Override final public void removeStudentCandidacy() { super.removeStudentCandidacy(); } final public Boolean getPayedTuition() { return !hasAnyNotPayedGratuityEventsForPreviousYears(); } // Linkare - Commented by Paulo Zenida (it still is necessary for migration // purposes // @Deprecated // public void setPayedTuition(Boolean value) { // throw new UnsupportedOperationException(); // } final public boolean getHasGratuityDebtsCurrently() { return hasGratuityDebtsCurrently(); } final public boolean hasGratuityDebtsCurrently() { return hasAnyNotPayedGratuityEvents(); } final public boolean hasInsuranceDebtsCurrently() { return hasAnyNotPayedInsuranceEvents(); } final public boolean hasAdministrativeOfficeFeeAndInsuranceDebtsCurrently(final AdministrativeOffice administrativeOffice) { return hasAnyNotPayedAdministrativeOfficeFeeAndInsuranceEvents(administrativeOffice); } final public boolean hasGratuityDebts(final ExecutionYear executionYear) { return hasAnyNotPayedGratuityEventUntil(executionYear); } final public boolean hasInsuranceDebts(final ExecutionYear executionYear) { return hasAnyNotPayedInsuranceEventUntil(executionYear); } final public boolean hasAdministrativeOfficeFeeAndInsuranceDebts(final AdministrativeOffice office, final ExecutionYear executionYear) { return hasAnyNotPayedAdministrativeOfficeFeeAndInsuranceEventUntil(office, executionYear); } final public Attends readAttendByExecutionCourse(ExecutionCourse executionCourse) { return getStudent().readAttendByExecutionCourse(executionCourse); } final public Attends readRegistrationAttendByExecutionCourse(final ExecutionCourse executionCourse) { for (final Attends attend : this.getAssociatedAttends()) { if (attend.isFor(executionCourse)) { return attend; } } return null; } @Override final public void setRegistrationAgreement(RegistrationAgreement registrationAgreement) { super.setRegistrationAgreement(registrationAgreement == null ? RegistrationAgreement.NORMAL : registrationAgreement); if (registrationAgreement != null && !registrationAgreement.isNormal() && !hasExternalRegistrationData()) { new ExternalRegistrationData(this); } } final public boolean hasGratuityEvent(final ExecutionYear executionYear, final Class type) { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlans()) { if (studentCurricularPlan.hasGratuityEvent(executionYear, type)) { return true; } } return false; } final public boolean hasDissertationThesis() { if (getDegreeType() == DegreeType.MASTER_DEGREE) { return getLastStudentCurricularPlan().hasMasterDegreeThesis(); } else { return getDissertationEnrolment() != null && getDissertationEnrolment().getThesis() != null; } } final public String getDissertationThesisTitle() { String result = null; if (hasDissertationThesis()) { if (getDegreeType() == DegreeType.MASTER_DEGREE) { result = getMasterDegreeThesis().getDissertationTitle(); } else { result = getDissertationEnrolment().getThesis().getFinalFullTitle().getContent(); } result = result.trim(); } return result; } final public LocalDate getDissertationThesisDiscussedDate() { if (hasDissertationThesis()) { if (getDegreeType() == DegreeType.MASTER_DEGREE) { return getMasterDegreeThesis().getProofDateYearMonthDay().toLocalDate(); } else { final Thesis thesis = getDissertationEnrolment().getThesis(); return thesis.hasCurrentDiscussedDate() ? thesis.getCurrentDiscussedDate().toLocalDate() : null; } } return null; } public MasterDegreeThesis getMasterDegreeThesis() { MasterDegreeThesis result = null; for (final StudentCurricularPlan plan : getSortedStudentCurricularPlans()) { final MasterDegreeThesis thesis = plan.getMasterDegreeThesis(); if (result != null && result.isConcluded() && thesis.isConcluded()) { throw new DomainException("error.Registration.more.than.one.concluded.thesis"); } if (result == null || !result.isConcluded()) { result = thesis; } } return result; } final public Enrolment getDissertationEnrolment() { return getDissertationEnrolment(null); } final public Enrolment getDissertationEnrolment(DegreeCurricularPlan degreeCurricularPlan) { for (StudentCurricularPlan scp : getStudentCurricularPlans()) { if (degreeCurricularPlan != null && scp.getDegreeCurricularPlan() != degreeCurricularPlan) { continue; } Enrolment enrolment = scp.getLatestDissertationEnrolment(); if (enrolment != null) { return enrolment; } } return null; } final public Proposal getDissertationProposal(final ExecutionYear executionYear) { for (final GroupStudent groupStudent : getAssociatedGroupStudents()) { final FinalDegreeWorkGroup group = groupStudent.getFinalDegreeDegreeWorkGroup(); final Proposal proposalAttributedByCoordinator = group.getProposalAttributed(); if (proposalAttributedByCoordinator != null && isProposalForExecutionYear(proposalAttributedByCoordinator, executionYear)) { return proposalAttributedByCoordinator; } final Proposal proposalAttributedByTeacher = group.getProposalAttributedByTeacher(); if (proposalAttributedByTeacher != null && isProposalForExecutionYear(proposalAttributedByTeacher, executionYear)) { if (proposalAttributedByTeacher.isProposalConfirmedByTeacherAndStudents(group)) { return proposalAttributedByTeacher; } } } return null; } private boolean isProposalForExecutionYear(final Proposal proposal, final ExecutionYear executionYear) { final Scheduleing scheduleing = proposal.getScheduleing(); for (final ExecutionDegree executionDegree : scheduleing.getExecutionDegreesSet()) { if (executionDegree.getExecutionYear() == executionYear) { return true; } } return false; } final public boolean isAvailableDegreeTypeForInquiries() { final DegreeType degreeType = getDegreeType(); return degreeType == DegreeType.BOLONHA_DEGREE || degreeType == DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE || degreeType == DegreeType.BOLONHA_MASTER_DEGREE; } final public boolean hasInquiriesToRespond() { for (final Attends attends : getAssociatedAttendsSet()) { final ExecutionCourse executionCourse = attends.getExecutionCourse(); final ExecutionSemester executionSemester = executionCourse.getExecutionPeriod(); if (executionCourse.getAvailableForInquiries().booleanValue() && executionSemester.getState().equals(PeriodState.CURRENT) && !hasInquiryResponseFor(executionCourse)) { return true; } } return false; } final public boolean hasInquiryResponseFor(final ExecutionCourse executionCourse) { for (final InquiriesRegistry inquiriesRegistry : getAssociatedInquiriesRegistries()) { if (inquiriesRegistry.getExecutionCourse() == executionCourse) { return true; } } return false; } final public StudentCurricularPlan getLastStudentDegreeCurricularPlansByDegree(Degree degree) { final SortedSet result = new TreeSet(StudentCurricularPlan.DATE_COMPARATOR); for (DegreeCurricularPlan degreeCurricularPlan : this.getDegreeCurricularPlans()) { if (degreeCurricularPlan.getDegree() == degree) { result.add(this.getStudentCurricularPlan(degreeCurricularPlan)); } } return result.last(); } final public ExternalEnrolment findExternalEnrolment(Unit university, ExecutionSemester period, String code) { for (final ExternalEnrolment externalEnrolment : this.getExternalEnrolments()) { if (externalEnrolment.getExecutionPeriod() == period && externalEnrolment.getExternalCurricularCourse().getCode().equals(code) && externalEnrolment.getExternalCurricularCourse().getUnit() == university) { return externalEnrolment; } } return null; } final public SortedSet getSortedExternalEnrolments() { final SortedSet result = new TreeSet(ExternalEnrolment.COMPARATOR_BY_NAME); result.addAll(getExternalEnrolmentsSet()); return result; } @Override public RegistrationAgreement getRegistrationAgreement() { return super.getRegistrationAgreement() == null ? RegistrationAgreement.NORMAL : super.getRegistrationAgreement(); } public Registration getSourceRegistrationForTransition() { if (!getLastDegreeCurricularPlan().hasEquivalencePlan()) { return null; } final DegreeCurricularPlanEquivalencePlan equivalencePlan = getLastDegreeCurricularPlan().getEquivalencePlan(); final List registrations = getStudent() .getRegistrationsFor(equivalencePlan.getSourceDegreeCurricularPlan()); return registrations.isEmpty() ? null : registrations.iterator().next(); } public List getTargetTransitionRegistrations() { final List result = new ArrayList(); for (final DegreeCurricularPlanEquivalencePlan equivalencePlan : getLastDegreeCurricularPlan() .getTargetEquivalencePlans()) { final Registration transitionRegistration = getStudent().getTransitionRegistrationFor( equivalencePlan.getDegreeCurricularPlan()); if (transitionRegistration != null) { result.add(transitionRegistration); } } return result; } @Checked("RegistrationPredicates.TRANSIT_TO_BOLONHA") public void transitToBolonha(final Person person, final DateTime when) { if (!isActive()) { throw new DomainException("error.student.Registration.cannot.transit.non.active.registrations"); } RegistrationStateCreator.createState(this, person, when, RegistrationStateType.TRANSITED); for (final Registration registration : getTargetTransitionRegistrations()) { if (registration.getDegreeType() == DegreeType.BOLONHA_DEGREE) { RegistrationStateCreator.createState(registration, person, when, registration.hasConcluded() ? RegistrationStateType.CONCLUDED : RegistrationStateType.REGISTERED); } else { RegistrationStateCreator.createState(registration, person, when, RegistrationStateType.REGISTERED); } registration.setRegistrationAgreement(getRegistrationAgreement()); registration.setSourceRegistration(this); changeAttends(registration, when); } if (!getTargetTransitionRegistrations().isEmpty()) { // change remaining attends to any target transition registration changeAttends(getTargetTransitionRegistrations().iterator().next(), when); } } private void changeAttends(final Registration newRegistration, final DateTime when) { final ExecutionSemester executionSemester = ExecutionSemester.readByDateTime(when); if (executionSemester == null) { throw new DomainException("error.Registration.invalid.when.date"); } for (final Attends attends : getAssociatedAttendsSet()) { if (attends.getExecutionPeriod().isAfterOrEquals(executionSemester)) { for (final CurricularCourse curricularCourse : attends.getExecutionCourse().getAssociatedCurricularCoursesSet()) { if (curricularCourse.getDegreeCurricularPlan() == newRegistration.getLastDegreeCurricularPlan()) { attends.setRegistration(newRegistration); break; } } } } } public boolean isEnrolmentByStudentAllowed() { return isActive() && getRegistrationAgreement().isEnrolmentByStudentAllowed() && getDegreeTypesToEnrolByStudent().contains(getDegreeType()); } private List getDegreeTypesToEnrolByStudent() { return DEGREE_TYPES_TO_ENROL_BY_STUDENT; } public boolean isEnrolmentByStudentInShiftsAllowed() { return isActive(); } final public boolean getIsForDegreeOffice() { return isForOffice(AdministrativeOffice.readByAdministrativeOfficeType(AdministrativeOfficeType.DEGREE)); } public void editStartDates(final YearMonthDay startDate, final YearMonthDay homologationDate, final YearMonthDay studiesStartDate) { if (startDate == null) { throw new DomainException("error.Registration.null.startDate"); } setStartDate(startDate); final RegistrationState firstRegistrationState = getFirstRegistrationState(); firstRegistrationState.setStateDate(startDate); if (firstRegistrationState != getFirstRegistrationState()) { throw new DomainException("error.Registration.startDate.changes.first.registration.state"); } getLastStudentCurricularPlan().setStartDate(startDate); setHomologationDate(homologationDate); setStudiesStartDate(studiesStartDate); } @Checked("RolePredicates.ACADEMIC_ADMINISTRATIVE_OFFICE_PREDICATE") public void deleteActualInfo() { final ExecutionYear executionYear = ExecutionYear.readCurrentExecutionYear(); deleteExecutionYearAttends(executionYear); for (StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlansSet()) { studentCurricularPlan.deleteExecutionYearEnrolments(executionYear); } } @Checked("RolePredicates.ACADEMIC_ADMINISTRATIVE_OFFICE_PREDICATE") private void deleteExecutionYearAttends(final ExecutionYear executionYear) { for (final Attends attends : getAssociatedAttends()) { if (attends.isFor(executionYear) && !attends.hasAnyAssociatedMarkSheetOrFinalGrade()) { deleteAllAttendsInfo(attends); } } } @Checked("RolePredicates.ACADEMIC_ADMINISTRATIVE_OFFICE_PREDICATE") private void deleteAllAttendsInfo(Attends attends) { for (; attends.hasAnyAssociatedMarks(); attends.getAssociatedMarks().get(0).delete()) ; for (; attends.hasAnyWeeklyWorkLoads(); attends.getWeeklyWorkLoads().get(0).delete()) ; for (; attends.hasAnyProjectSubmissions(); attends.getProjectSubmissions().get(0).delete()) ; attends.getStudentGroups().clear(); attends.removeShifts(); attends.delete(); } public Collection getCurriculumLineLogs(final ExecutionSemester executionSemester) { final Collection res = new HashSet(); for (final CurriculumLineLog curriculumLineLog : getCurriculumLineLogsSet()) { if (curriculumLineLog.isFor(executionSemester)) { res.add(curriculumLineLog); } } return res; } public boolean containsEnrolmentOutOfPeriodEventFor(ExecutionSemester executionSemester) { for (final StudentCurricularPlan studentCurricularPlan : getStudentCurricularPlans()) { for (final EnrolmentOutOfPeriodEvent event : studentCurricularPlan.getEnrolmentOutOfPeriodEvents()) { if (event.getExecutionPeriod() == executionSemester) { return true; } } } return false; } public boolean hasStartedBetween(final ExecutionYear firstExecutionYear, final ExecutionYear finalExecutionYear) { return getStartExecutionYear().isAfterOrEquals(firstExecutionYear) && getStartExecutionYear().isBeforeOrEquals((finalExecutionYear)); } public boolean hasRegistrationRegime(final ExecutionYear executionYear, final RegistrationRegimeType type) { for (final RegistrationRegime regime : getRegistrationRegimesSet()) { if (regime.isFor(executionYear) && regime.hasRegime(type)) { return true; } } return false; } public RegistrationRegimeType getRegimeType(final ExecutionYear executionYear) { for (final RegistrationRegime regime : getRegistrationRegimesSet()) { if (regime.isFor(executionYear)) { return regime.getRegimeType(); } } // if not specified, use the default regime return RegistrationRegimeType.defaultType(); } public boolean isPartialRegime(final ExecutionYear executionYear) { return getRegimeType(executionYear) == RegistrationRegimeType.PARTIAL_TIME; } public String getUniversityCode(final ExecutionYear executionYear) { return Campus.getUniversityCode(getCampus(executionYear)) + getDegree().getMinistryCode(); } public void changeShifts(final Attends attend, final Registration newRegistration) { for (final Shift shift : getShiftsSet()) { if (attend.isFor(shift)) { shift.removeStudents(this); shift.addStudents(newRegistration); } } } public boolean hasMissingCandidacyInformation(final ExecutionYear executionYear) { if (getCandidacyInformationBean().isValid()) { return false; } final YearMonthDay startDate = getStartDate(); if (startDate == null) { return false; } final ExecutionYear previousExecutionYear = executionYear.getPreviousExecutionYear(); if (getStartExecutionYear() == executionYear) { return getLastDegreeCurricularPlan().hasExecutionDegreeFor(executionYear); } else if (getDegreeType() == DegreeType.BOLONHA_ADVANCED_SPECIALIZATION_DIPLOMA) { return startDate.getYear() == executionYear.getBeginCivilYear(); } else if (getDegreeType() == DegreeType.BOLONHA_MASTER_DEGREE && previousExecutionYear.getLastExecutionPeriod().containsDay(startDate)) { return true; } else if (getDegreeType() == DegreeType.BOLONHA_INTEGRATED_MASTER_DEGREE) { final CycleCurriculumGroup secondCycle = getLastStudentCurricularPlan().getSecondCycle(); if (secondCycle != null && !secondCycle.isExternal() && getLastStudentCurricularPlan().getFirstCycle() == null) { return previousExecutionYear.getLastExecutionPeriod().containsDay(startDate); } } return false; } public boolean isReingression(final ExecutionYear executionYear) { final SortedSet states = new TreeSet(RegistrationState.DATE_COMPARATOR); states.addAll(getRegistrationStates()); Registration sourceRegistration = getSourceRegistration(); while (sourceRegistration != null) { states.addAll(sourceRegistration.getRegistrationStates()); sourceRegistration = sourceRegistration.getSourceRegistration(); } if (states.size() == 0) { return false; } RegistrationState previous = null; for (final RegistrationState registrationState : states) { if (previous != null) { if (registrationState.getExecutionYear() == executionYear && (registrationState.isActive() || registrationState.getStateType() == RegistrationStateType.TRANSITED) && (previous.getStateType() == RegistrationStateType.EXTERNAL_ABANDON || previous.getStateType() == RegistrationStateType.INTERRUPTED || previous.getStateType() == RegistrationStateType.FLUNKED)) { return true; } } previous = registrationState; } return false; } public CandidacyInformationBean getCandidacyInformationBean() { if (hasStudentCandidacy()) { return getStudentCandidacy().getCandidacyInformationBean(); } else if (hasIndividualCandidacy()) { return getIndividualCandidacy().getCandidacyInformationBean(); } else { return new CandidacyInformationBean(this); } } public int getNumberEnroledCurricularCoursesInCurrentYear() { return getLastStudentCurricularPlan().countEnrolments(ExecutionYear.readCurrentExecutionYear()); } @Service @Checked("RegistrationPredicates.EDIT_CANDIDACY_INFORMATION") public void editCandidacyInformation(final CandidacyInformationBean bean) { if (hasStudentCandidacy()) { getStudentCandidacy().editCandidacyInformation(bean); } else if (hasIndividualCandidacy()) { getIndividualCandidacy().editCandidacyInformation(bean); } else { final StudentCandidacy studentCandidacy = StudentCandidacy.createStudentCandidacy(getLastDegreeCurricularPlan() .getExecutionDegreeByYear(getStartExecutionYear()), AccessControl.getPerson()); studentCandidacy.setRegistration(this); studentCandidacy.editCandidacyInformation(bean); } } @Service @Checked("RegistrationPredicates.EDIT_MISSING_CANDIDACY_INFORMATION") public void editMissingCandidacyInformation(final CandidacyInformationBean bean) { if (hasStudentCandidacy()) { getStudentCandidacy().editMissingCandidacyInformation(bean); } else if (hasIndividualCandidacy()) { getIndividualCandidacy().editMissingCandidacyInformation(bean); } else { final StudentCandidacy studentCandidacy = StudentCandidacy.createStudentCandidacy(getLastDegreeCurricularPlan() .getExecutionDegreeByYear(getStartExecutionYear()), AccessControl.getPerson()); studentCandidacy.setRegistration(this); studentCandidacy.editCandidacyInformation(bean); } } public List getInternalCycleCurriculumGrops() { return getLastStudentCurricularPlan().getInternalCycleCurriculumGrops(); } public Collection getAllCurriculumGroups() { Collection result = new TreeSet(CurriculumGroup.COMPARATOR_BY_NAME_AND_ID); for (final StudentCurricularPlan plan : getStudentCurricularPlans()) { result.addAll(plan.getAllCurriculumGroups()); } return result; } public Collection getAllCurriculumGroupsWithoutNoCourseGroupCurriculumGroups() { Collection result = new TreeSet(CurriculumGroup.COMPARATOR_BY_NAME_AND_ID); for (final StudentCurricularPlan plan : getStudentCurricularPlans()) { result.addAll(plan.getAllCurriculumGroupsWithoutNoCourseGroupCurriculumGroups()); } return result; } public Boolean hasIndividualCandidacyFor(final ExecutionYear executionYear) { return hasIndividualCandidacy() && getIndividualCandidacy().getCandidacyProcess().getCandidacyExecutionInterval().equals(executionYear); } @Linkare(author = "Paulo Zenida") public RegistrationState getRegistrationStateBy(final RegistrationStateType stateType, final DateTime dateTime) { for (final RegistrationState registrationState : getRegistrationStates(Collections.singleton(stateType))) { if (EqualityUtils.equals(dateTime, registrationState.getStateDate())) { return registrationState; } } return null; } @Linkare(author = "Paulo Zenida") public void deleteAllRegistrationStates() { while (!getRegistrationStates().isEmpty()) { getRegistrationStates().get(0).forceDelete(); } } @Linkare(author = "Paulo Zenida") @Override public String getShortDescription() { return getNumber() + " - " + getDegree().getShortDescription(); } }