package net.sourceforge.fenixedu.domain; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import net.sourceforge.fenixedu._development.LogLevel; import net.sourceforge.fenixedu.applicationTier.Servico.exceptions.BothAreasAreTheSameServiceException; import net.sourceforge.fenixedu.applicationTier.Servico.exceptions.InvalidArgumentsServiceException; import net.sourceforge.fenixedu.applicationTier.Servico.exceptions.NotAuthorizedBranchChangeException; import net.sourceforge.fenixedu.dataTransferObject.administrativeOffice.dismissal.DismissalBean.SelectedCurricularCourse; import net.sourceforge.fenixedu.domain.accessControl.PermissionType; import net.sourceforge.fenixedu.domain.accessControl.academicAdminOffice.AdministrativeOfficePermission; import net.sourceforge.fenixedu.domain.accounting.events.EnrolmentInAppealSeasonEvent; import net.sourceforge.fenixedu.domain.accounting.events.EnrolmentOutOfPeriodEvent; import net.sourceforge.fenixedu.domain.accounting.events.ImprovementOfApprovedEnrolmentEvent; import net.sourceforge.fenixedu.domain.accounting.events.gratuity.GratuityEvent; import net.sourceforge.fenixedu.domain.administrativeOffice.AdministrativeOffice; import net.sourceforge.fenixedu.domain.curricularPeriod.CurricularPeriod; import net.sourceforge.fenixedu.domain.curricularRules.MaximumNumberOfCreditsForEnrolmentPeriod; import net.sourceforge.fenixedu.domain.curricularRules.executors.RuleResult; import net.sourceforge.fenixedu.domain.curricularRules.executors.ruleExecutors.CurricularRuleLevel; import net.sourceforge.fenixedu.domain.curriculum.EnrollmentCondition; import net.sourceforge.fenixedu.domain.curriculum.EnrollmentState; import net.sourceforge.fenixedu.domain.curriculum.EnrolmentEvaluationType; import net.sourceforge.fenixedu.domain.degree.DegreeType; import net.sourceforge.fenixedu.domain.degree.enrollment.CurricularCourse2Enroll; import net.sourceforge.fenixedu.domain.degree.enrollment.NotNeedToEnrollInCurricularCourse; import net.sourceforge.fenixedu.domain.degreeStructure.Context; import net.sourceforge.fenixedu.domain.degreeStructure.CourseGroup; import net.sourceforge.fenixedu.domain.degreeStructure.CycleCourseGroup; import net.sourceforge.fenixedu.domain.degreeStructure.CycleType; import net.sourceforge.fenixedu.domain.degreeStructure.DegreeModule; import net.sourceforge.fenixedu.domain.degreeStructure.OptionalCurricularCourse; import net.sourceforge.fenixedu.domain.enrolment.DegreeModuleToEnrol; import net.sourceforge.fenixedu.domain.enrolment.EnrolmentContext; import net.sourceforge.fenixedu.domain.enrolment.IDegreeModuleToEvaluate; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.gratuity.GratuitySituationType; import net.sourceforge.fenixedu.domain.space.Campus; import net.sourceforge.fenixedu.domain.student.Registration; import net.sourceforge.fenixedu.domain.student.RegistrationAgreement; import net.sourceforge.fenixedu.domain.student.Student; import net.sourceforge.fenixedu.domain.student.curriculum.AverageType; import net.sourceforge.fenixedu.domain.student.curriculum.Curriculum; import net.sourceforge.fenixedu.domain.studentCurricularPlan.Specialization; import net.sourceforge.fenixedu.domain.studentCurricularPlan.StudentCurricularPlanState; import net.sourceforge.fenixedu.domain.studentCurriculum.Credits; 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.Equivalence; import net.sourceforge.fenixedu.domain.studentCurriculum.ExternalCurriculumGroup; import net.sourceforge.fenixedu.domain.studentCurriculum.ExtraCurriculumGroup; import net.sourceforge.fenixedu.domain.studentCurriculum.NoCourseGroupCurriculumGroup; import net.sourceforge.fenixedu.domain.studentCurriculum.NoCourseGroupCurriculumGroupType; import net.sourceforge.fenixedu.domain.studentCurriculum.PropaedeuticsCurriculumGroup; import net.sourceforge.fenixedu.domain.studentCurriculum.RootCurriculumGroup; import net.sourceforge.fenixedu.domain.studentCurriculum.StandaloneCurriculumGroup; import net.sourceforge.fenixedu.domain.studentCurriculum.Substitution; import net.sourceforge.fenixedu.domain.studentCurriculum.CurriculumModule.CurriculumModulePredicateByApproval; import net.sourceforge.fenixedu.domain.studentCurriculum.CurriculumModule.CurriculumModulePredicateByExecutionSemester; import net.sourceforge.fenixedu.domain.studentCurriculum.CurriculumModule.CurriculumModulePredicateByExecutionYear; import net.sourceforge.fenixedu.domain.studentCurriculum.CurriculumModule.CurriculumModulePredicateByType; import net.sourceforge.fenixedu.domain.studentCurriculum.curriculumLine.CurriculumLineLocationBean; import net.sourceforge.fenixedu.domain.studentCurriculum.curriculumLine.MoveCurriculumLinesBean; import net.sourceforge.fenixedu.injectionCode.AccessControl; import net.sourceforge.fenixedu.util.State; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Transformer; import org.apache.commons.collections.comparators.ReverseComparator; import org.joda.time.DateTime; import org.joda.time.YearMonthDay; import pt.ist.fenixWebFramework.security.accessControl.Checked; import pt.ist.fenixWebFramework.services.Service; import pt.utl.ist.fenix.tools.predicates.AndPredicate; import pt.utl.ist.fenix.tools.predicates.Predicate; import pt.utl.ist.fenix.tools.predicates.ResultCollection; import com.linkare.commons.metainfo.Linkare; /** * @author David Santos in Jun 24, 2004 */ public class StudentCurricularPlan extends StudentCurricularPlan_Base { public static final Comparator COMPARATOR_BY_STUDENT_NUMBER = new Comparator() { @Override public int compare(StudentCurricularPlan o1, StudentCurricularPlan o2) { return o1.getStudent().getNumber().compareTo(o2.getStudent().getNumber()); } }; static final public Comparator STUDENT_CURRICULAR_PLAN_COMPARATOR_BY_DEGREE_TYPE_AND_DEGREE_NAME = new Comparator() { @Override public int compare(StudentCurricularPlan o1, StudentCurricularPlan o2) { final Degree degree1 = o1.getDegree(); final Degree degree2 = o2.getDegree(); final int ct = degree1.getDegreeType().compareTo(degree2.getDegreeType()); return ct == 0 ? degree1.getName().compareTo(degree2.getName()) : ct; } }; static final public Comparator STUDENT_CURRICULAR_PLAN_COMPARATOR_BY_DEGREE_DEGREE_NAME_AND_STUDENT_NUMBER_AND_NAME = new Comparator() { @Override public int compare(StudentCurricularPlan o1, StudentCurricularPlan o2) { final int cd = o1.getDegree().getName().compareTo(o2.getDegree().getName()); if (cd != 0) { return cd; } final int cn = o1.getStudent().getNumber().compareTo(o2.getStudent().getNumber()); return cn == 0 ? o1.getPerson().getName().compareTo(o2.getPerson().getName()) : cn; } }; public static final Comparator COMPARATOR_BY_DEGREE_TYPE = new Comparator() { public int compare(final StudentCurricularPlan studentCurricularPlan1, final StudentCurricularPlan studentCurricularPlan2) { final DegreeType degreeType1 = studentCurricularPlan1.getDegreeType(); final DegreeType degreeType2 = studentCurricularPlan2.getDegreeType(); return degreeType1.compareTo(degreeType2); } }; static final public Comparator STUDENT_CURRICULAR_PLAN_COMPARATOR_BY_START_DATE = new Comparator() { @Override public int compare(final StudentCurricularPlan o1, final StudentCurricularPlan o2) { return o1.getStartDateYearMonthDay().compareTo(o2.getStartDateYearMonthDay()); } }; static final public Comparator DATE_COMPARATOR = new Comparator() { public int compare(StudentCurricularPlan leftState, StudentCurricularPlan rightState) { int comparationResult = leftState.getStartDateYearMonthDay().compareTo(rightState.getStartDateYearMonthDay()); return (comparationResult == 0) ? leftState.getIdInternal().compareTo(rightState.getIdInternal()) : comparationResult; } }; private StudentCurricularPlan() { super(); setCurrentState(StudentCurricularPlanState.ACTIVE); setRootDomainObject(RootDomainObject.getInstance()); setWhenDateTime(new DateTime()); setGivenCredits(Double.valueOf(0)); } static public StudentCurricularPlan createPreBolonhaMasterDegree(Registration registration, DegreeCurricularPlan degreeCurricularPlan, YearMonthDay startDate, Branch branch, Double givenCredits, Specialization specialization) { return new StudentCurricularPlan(registration, degreeCurricularPlan, startDate, branch, givenCredits, specialization); } private StudentCurricularPlan(Registration registration, DegreeCurricularPlan degreeCurricularPlan, YearMonthDay startDate, Branch branch, Double givenCredits, Specialization specialization) { this(registration, degreeCurricularPlan, startDate); setBranch(branch); setGivenCredits(givenCredits); setSpecialization(specialization); } private StudentCurricularPlan(Registration registration, DegreeCurricularPlan degreeCurricularPlan, YearMonthDay startDate) { this(); init(registration, degreeCurricularPlan, startDate); } static public StudentCurricularPlan createWithEmptyStructure(final Registration registration, final DegreeCurricularPlan degreeCurricularPlan, final YearMonthDay startDate) { final StudentCurricularPlan result = new StudentCurricularPlan(registration, degreeCurricularPlan, startDate); if (degreeCurricularPlan.isBoxStructure()) { new RootCurriculumGroup(result, degreeCurricularPlan.getRoot(), null); } return result; } static public StudentCurricularPlan createBolonhaStudentCurricularPlan(Registration registration, DegreeCurricularPlan degreeCurricularPlan, YearMonthDay startDate, ExecutionSemester executionSemester) { return createBolonhaStudentCurricularPlan(registration, degreeCurricularPlan, startDate, executionSemester, (CycleType) null); } static public StudentCurricularPlan createBolonhaStudentCurricularPlan(Registration registration, DegreeCurricularPlan degreeCurricularPlan, YearMonthDay startDate, ExecutionSemester executionSemester, CycleType cycleType) { return new StudentCurricularPlan(registration, degreeCurricularPlan, startDate, executionSemester, cycleType); } private StudentCurricularPlan(Registration registration, DegreeCurricularPlan degreeCurricularPlan, YearMonthDay startDate, ExecutionSemester executionSemester, CycleType cycleType) { this(registration, degreeCurricularPlan, startDate); createStructure(executionSemester, cycleType); } private void createStructure(final ExecutionSemester executionSemester, CycleType cycleType) { if (getDegreeCurricularPlan().isBoxStructure()) { new RootCurriculumGroup(this, getDegreeCurricularPlan().getRoot(), executionSemester, cycleType); } } private void init(Registration registration, DegreeCurricularPlan degreeCurricularPlan, YearMonthDay startDate) { checkParameters(registration, degreeCurricularPlan, startDate); setDegreeCurricularPlan(degreeCurricularPlan); setRegistration(registration); setStartDateYearMonthDay(startDate); } private void checkParameters(Registration registration, DegreeCurricularPlan degreeCurricularPlan, YearMonthDay startDate) { if (registration == null) { throw new DomainException("error.studentCurricularPlan.registration.cannot.be.null"); } if (degreeCurricularPlan == null) { throw new DomainException("error.studentCurricularPlan.degreeCurricularPlan.cannot.be.null"); } if (startDate == null) { throw new DomainException("error.studentCurricularPlan.startDate.cannot.be.null"); } } public void delete() throws DomainException { checkRulesToDelete(); removeDegreeCurricularPlan(); removeBranch(); removeEmployee(); removeMasterDegreeThesis(); for (; !getEnrolmentsSet().isEmpty(); getEnrolments().get(0).delete()) ; if (getRoot() != null) { getRoot().delete(); } for (Iterator iter = getNotNeedToEnrollCurricularCoursesIterator(); iter.hasNext();) { NotNeedToEnrollInCurricularCourse notNeedToEnrollInCurricularCourse = iter.next(); iter.remove(); notNeedToEnrollInCurricularCourse.removeStudentCurricularPlan(); notNeedToEnrollInCurricularCourse.delete(); } for (; !getCreditsInAnySecundaryAreas().isEmpty(); getCreditsInAnySecundaryAreas().get(0).delete()) ; for (Iterator iter = getCreditsInScientificAreasIterator(); iter.hasNext();) { CreditsInScientificArea creditsInScientificArea = iter.next(); iter.remove(); creditsInScientificArea.removeStudentCurricularPlan(); creditsInScientificArea.delete(); } for (; hasAnyCredits(); getCredits().get(0).delete()) ; for (; hasAnyTutorships(); getTutorships().get(0).delete()) ; removeStudent(); removeRootDomainObject(); deleteDomainObject(); } private void checkRulesToDelete() { if (hasAnyGratuityEvents()) { throw new DomainException("error.StudentCurricularPlan.cannot.delete.because.already.has.gratuity.events"); } if (hasAnyGratuitySituations()) { throw new DomainException("error.StudentCurricularPlan.cannot.delete.because.already.has.gratuity.situations"); } } final public String print() { if (hasRoot()) { final StringBuilder result = new StringBuilder(); result.append("[SCP ").append(this.getIdInternal()).append("] ").append(this.getName()).append("\n"); result.append(getRoot().print("")); return result.toString(); } else { return ""; } } final public boolean isFirstCycle() { return getDegreeType().isFirstCycle(); } final public boolean isSecondCycle() { return getDegreeType().isSecondCycle(); } final public boolean hasConcludedCycle(CycleType cycleType) { return hasRoot() ? getRoot().hasConcludedCycle(cycleType) : null; } final public boolean hasConcludedCycle(CycleType cycleType, final ExecutionYear executionYear) { return hasRoot() ? getRoot().hasConcludedCycle(cycleType, executionYear) : null; } public boolean hasConcludedAnyInternalCycle() { for (final CycleCurriculumGroup cycleCurriculumGroup : getInternalCycleCurriculumGrops()) { if (cycleCurriculumGroup.isConcluded()) { return true; } } return false; } final public YearMonthDay getConclusionDate(final CycleType cycleType) { if (getDegreeType().getCycleTypes().isEmpty()) { throw new DomainException("StudentCurricularPlan.has.no.cycle.type"); } if (!getDegreeType().hasCycleTypes(cycleType)) { throw new DomainException("StudentCurricularPlan.doesnt.have.such.cycle.type"); } return getCycle(cycleType).getConclusionDate(); } public Integer getFinalAverage(final CycleType cycleType) { if (getDegreeType().getCycleTypes().isEmpty()) { throw new DomainException("StudentCurricularPlan.has.no.cycle.type"); } if (!getDegreeType().hasCycleTypes(cycleType)) { throw new DomainException("StudentCurricularPlan.doesnt.have.such.cycle.type"); } return getCycle(cycleType).getFinalAverage(); } public YearMonthDay calculateConclusionDate(final CycleType cycleType) { if (cycleType == null) { return getLastApprovementDate(); } if (getDegreeType().getCycleTypes().isEmpty()) { throw new DomainException("StudentCurricularPlan.has.no.cycle.type"); } if (!getDegreeType().hasCycleTypes(cycleType)) { throw new DomainException("StudentCurricularPlan.doesnt.have.such.cycle.type"); } return getCycle(cycleType).calculateConclusionDate(); } final public boolean isConclusionProcessed() { if (!isBolonhaDegree()) { return getRegistration().hasConclusionProcess(); } for (final CycleCurriculumGroup cycleCurriculumGroup : getInternalCycleCurriculumGrops()) { if (!cycleCurriculumGroup.isConclusionProcessed()) { return false; } } return true; } final public boolean isConclusionProcessed(final CycleType cycleType) { final CycleCurriculumGroup cycleCurriculumGroup = getCycle(cycleType); return cycleCurriculumGroup != null && cycleCurriculumGroup.isConclusionProcessed(); } final public Curriculum getCurriculum(final DateTime when, final ExecutionYear executionYear) { final RootCurriculumGroup rootCurriculumGroup = getRoot(); if (rootCurriculumGroup == null) { return Curriculum.createEmpty(executionYear); } else { return rootCurriculumGroup.getCurriculum(when, executionYear); } } final public AverageType getAverageType() { return getDegreeCurricularPlan().getAverageType(); } final public boolean isActive() { return isLastStudentCurricularPlanFromRegistration() && getRegistration().isActive(); } final public boolean isPast() { return getDegreeCurricularPlan().isPast(); } public boolean hasIncompleteState() { return getCurrentState().equals(StudentCurricularPlanState.INCOMPLETE); } public boolean isTransition() { return getRegistration().isTransition(); } final public boolean isBolonhaDegree() { return getDegreeCurricularPlan().isBolonhaDegree(); } /** * Temporary method, after all degrees migration this is no longer necessary * */ final public boolean isBoxStructure() { return hasRoot(); } final public boolean isEnrolable() { return isBoxStructure() && getRegistration().isActive() && getRegistration().getLastStudentCurricularPlan().equals(this); } final public Person getPerson() { return getRegistration().getPerson(); } final public Department getDepartment() { return getDegree().getUnit().getDepartment(); } final public Degree getDegree() { return getDegreeCurricularPlan().getDegree(); } final public DegreeType getDegreeType() { return getDegree().getDegreeType(); } final public Integer getDegreeDuration() { return getDegreeCurricularPlan().getDegreeDuration(); } final public boolean hasClassification() { return getClassification() != null && getClassification().doubleValue() != 0d; } @Override @Deprecated final public Registration getStudent() { return this.getRegistration(); } public void setStartDate(YearMonthDay startDate) { super.setStartDateYearMonthDay(startDate); } @Override @Deprecated public void setStudent(final Registration registration) { this.setRegistration(registration); } public Registration getRegistration() { return super.getStudent(); } public void setRegistration(final Registration registration) { if (registration != null) { if (registration.hasDegree()) { if (!registration.getDegree().hasDegreeCurricularPlans(getDegreeCurricularPlan())) { throw new DomainException("error.StudentCurricularPlan.setting.registration.with.different.degree"); } } else { registration.setDegree(getDegree()); } } super.setStudent(registration); } public boolean hasRegistration() { return super.hasStudent(); } public Set getAllCurriculumLines() { return isBoxStructure() ? getRoot().getAllCurriculumLines() : new HashSet(super.getEnrolmentsSet()); } public Set getAllCurriculumGroups() { return isBoxStructure() ? getRoot().getAllCurriculumGroups() : Collections.EMPTY_SET; } public Set getAllCurriculumGroupsWithoutNoCourseGroupCurriculumGroups() { return isBoxStructure() ? getRoot().getAllCurriculumGroupsWithoutNoCourseGroupCurriculumGroups() : Collections.EMPTY_SET; } @Override final public List getEnrolments() { return hasRoot() ? getRoot().getEnrolments() : super.getEnrolments(); } @Override final public Set getEnrolmentsSet() { return hasRoot() ? getRoot().getEnrolmentsSet() : super.getEnrolmentsSet(); } @Override final public boolean hasAnyEnrolments() { return hasRoot() ? getRoot().hasAnyEnrolments() : super.hasAnyEnrolments(); } final public boolean hasAnyCurriculumLines() { return hasRoot() ? hasAnyCurriculumModules(new CurriculumModulePredicateByType(CurriculumLine.class)) : hasAnyEnrolments(); } final public boolean hasAnyCurriculumLines(final ExecutionYear executionYear) { if (hasRoot()) { final AndPredicate andPredicate = new AndPredicate(); andPredicate.add(new CurriculumModulePredicateByType(CurriculumLine.class)); andPredicate.add(new CurriculumModulePredicateByExecutionYear(executionYear)); return hasAnyCurriculumModules(andPredicate); } return hasEnrolments(executionYear); } final public boolean hasAnyCurriculumLines(final ExecutionSemester executionSemester) { if (hasRoot()) { final AndPredicate andPredicate = new AndPredicate(); andPredicate.add(new CurriculumModulePredicateByType(CurriculumLine.class)); andPredicate.add(new CurriculumModulePredicateByExecutionSemester(executionSemester)); return hasAnyCurriculumModules(andPredicate); } return hasEnrolments(executionSemester); } @Override final public boolean hasEnrolments(final Enrolment enrolment) { return hasRoot() ? getRoot().hasCurriculumModule(enrolment) : super.hasEnrolments(enrolment); } final public boolean hasEnrolments(final ExecutionYear executionYear) { if (hasRoot()) { return getRoot().hasEnrolment(executionYear); } else { for (final Enrolment enrolment : super.getEnrolmentsSet()) { final ExecutionSemester executionSemester = enrolment.getExecutionPeriod(); if (executionSemester.getExecutionYear() == executionYear) { return true; } } } return false; } final public boolean hasEnrolments(final ExecutionSemester executionSemester) { if (hasRoot()) { return getRoot().hasEnrolment(executionSemester); } else { for (final Enrolment enrolment : super.getEnrolmentsSet()) { if (enrolment.getExecutionPeriod() == executionSemester) { return true; } } } return false; } @Override final public int getEnrolmentsCount() { return hasRoot() ? getEnrolmentsSet().size() : super.getEnrolmentsCount(); } final public int countCurrentEnrolments() { int result = 0; for (final Enrolment enrolment : getEnrolmentsSet()) { final ExecutionYear executionYear = enrolment.getExecutionPeriod().getExecutionYear(); if (executionYear.isCurrent() && enrolment.isEnroled()) { result++; } } return result; } final public int getCountCurrentEnrolments() { return countCurrentEnrolments(); } final public List getEnrolments(final CurricularCourse curricularCourse) { final List results = new ArrayList(); for (final Enrolment enrollment : this.getEnrolmentsSet()) { if (enrollment.getCurricularCourse() == curricularCourse) { results.add(enrollment); } } return results; } final public int countEnrolmentsByCurricularCourse(final CurricularCourse curricularCourse) { int count = 0; for (Enrolment enrolment : this.getEnrolmentsSet()) { if (enrolment.getCurricularCourse() == curricularCourse) { count++; } } return count; } final public int countEnrolmentsByCurricularCourse(final CurricularCourse curricularCourse, final ExecutionSemester untilExecutionPeriod) { int count = 0; for (Enrolment enrolment : getEnrolments(curricularCourse)) { if (enrolment.getExecutionPeriod().isBeforeOrEquals(untilExecutionPeriod)) { count++; } } return count; } final public List getEnrolmentsByState(final EnrollmentState state) { List results = new ArrayList(); for (Enrolment enrolment : this.getEnrolmentsSet()) { if (enrolment.getEnrollmentState().equals(state)) { results.add(enrolment); } } return results; } final public List getEnrolmentsByExecutionPeriod(final ExecutionSemester executionSemester) { List results = new ArrayList(); for (Enrolment enrolment : this.getEnrolmentsSet()) { if (enrolment.getExecutionPeriod() == executionSemester) { results.add(enrolment); } } return results; } final public Collection getStudentEnrollmentsWithEnrolledState() { final List result = new ArrayList(); for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.isEnroled() && !enrolment.isInvisible()) { result.add(enrolment); } } return result; } final public int getNumberOfEnrolledCurricularCourses() { return getStudentEnrollmentsWithEnrolledState().size(); } private Collection getVisibleEnroledEnrolments(final ExecutionSemester executionSemester) { final Collection result = new ArrayList(); for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.isEnroled() && !enrolment.isInvisible() && (executionSemester == null || enrolment.isValid(executionSemester))) { result.add(enrolment); } } return result; } final public int countEnrolments(final ExecutionSemester executionSemester) { int numberEnrolments = 0; for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.getExecutionPeriod() == executionSemester) { numberEnrolments++; } } return numberEnrolments; } final public boolean hasAnyEnrolmentForExecutionPeriod(final ExecutionSemester executionSemester) { for (final Enrolment enrolment : this.getEnrolmentsSet()) { if (enrolment.getExecutionPeriod() == executionSemester) { return true; } } return false; } final public List getEnrolmentsByExecutionYear(final ExecutionYear executionYear) { final List result = new ArrayList(); for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.getExecutionPeriod().getExecutionYear() == executionYear) { result.add(enrolment); } } return result; } final public int countEnrolments(final ExecutionYear executionYear) { int numberEnrolments = 0; for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.getExecutionPeriod().getExecutionYear() == executionYear) { numberEnrolments++; } } return numberEnrolments; } final public boolean hasAnyEnrolmentForExecutionYear(final ExecutionYear executionYear) { for (final Enrolment enrolment : this.getEnrolmentsSet()) { if (enrolment.getExecutionPeriod().getExecutionYear().equals(executionYear)) { return true; } } return false; } final public boolean hasAnyEnrolmentForCurrentExecutionYear() { return hasAnyEnrolmentForExecutionYear(ExecutionYear.readCurrentExecutionYear()); } final public Collection getLatestCurricularCoursesEnrolments(final ExecutionYear executionYear) { final Map result = new HashMap(); for (final Enrolment enrolment : getEnrolmentsByExecutionYear(executionYear)) { if (!result.containsKey(enrolment.getCurricularCourse()) || result.get(enrolment.getCurricularCourse()).isBefore(enrolment)) { result.put(enrolment.getCurricularCourse(), enrolment); } } return result.values(); } public void addApprovedEnrolments(final Collection enrolments) { for (final Enrolment enrolment : getEnrolmentsSet()) { if (!enrolment.isInvisible() && enrolment.isApproved()) { enrolments.add(enrolment); } } } public Set getDismissalApprovedEnrolments() { Set aprovedEnrolments = new HashSet(); for (final Enrolment enrolment : getEnrolmentsSet()) { if (!enrolment.isInvisible() && enrolment.isApproved()) { aprovedEnrolments.add(enrolment); } } return aprovedEnrolments; } public Collection getCurriculumModules(final ResultCollection collection) { if (hasRoot()) { getRoot().getCurriculumModules(collection); return collection.getResult(); } else { throw new DomainException("not.supported"); } } public boolean hasAnyCurriculumModules(final Predicate predicate) { if (hasRoot()) { return getRoot().hasAnyCurriculumModules(predicate); } else { throw new DomainException("not.supported"); } } final public Collection getApprovedCurriculumLines() { if (hasRoot()) { final Collection result = new HashSet(); getRoot().addApprovedCurriculumLines(result); return result; } else { return new HashSet(getAprovedEnrolments()); } } public Collection getApprovedCurriculumLines(final ExecutionSemester executionSemester) { final AndPredicate andPredicate = new AndPredicate(); andPredicate.add(new CurriculumModulePredicateByType(CurriculumLine.class)); andPredicate.add(new CurriculumModulePredicateByExecutionSemester(executionSemester)); andPredicate.add(new CurriculumModulePredicateByApproval()); return (Collection) getCurriculumModules(new ResultCollection(andPredicate)); } public Collection getApprovedCurriculumLines(final ExecutionYear executionYear) { final AndPredicate andPredicate = new AndPredicate(); andPredicate.add(new CurriculumModulePredicateByType(CurriculumLine.class)); andPredicate.add(new CurriculumModulePredicateByExecutionYear(executionYear)); andPredicate.add(new CurriculumModulePredicateByApproval()); return (Collection) getCurriculumModules(new ResultCollection(andPredicate)); } final public ExecutionYear getApprovedCurriculumLinesLastExecutionYear() { if (hasRoot()) { return getRoot().getApprovedCurriculumLinesLastExecutionYear(); } else { final SortedSet executionYears = new TreeSet(ExecutionYear.COMPARATOR_BY_YEAR); for (final CurriculumLine curriculumLine : getAprovedEnrolments()) { if (curriculumLine.hasExecutionPeriod()) { executionYears.add(curriculumLine.getExecutionPeriod().getExecutionYear()); } } return executionYears.isEmpty() ? ExecutionYear.readCurrentExecutionYear() : executionYears.last(); } } final public CurriculumLine getLastApprovement() { final SortedSet curriculumLines = new TreeSet( CurriculumLine.COMPARATOR_BY_APPROVEMENT_DATE_AND_ID); if (hasRoot()) { for (final CurriculumGroup group : getRoot().getChildCurriculumGroups()) { if (!group.isNoCourseGroupCurriculumGroup()) { group.addApprovedCurriculumLines(curriculumLines); } } } else { curriculumLines.addAll(getAprovedEnrolments()); } return curriculumLines.isEmpty() ? null : curriculumLines.last(); } final public YearMonthDay getLastApprovementDate() { final CurriculumLine lastApprovement = getLastApprovement(); return lastApprovement == null ? null : lastApprovement.getApprovementDate(); } final public ExecutionYear getLastApprovementExecutionYear() { return hasAnyApprovedCurriculumLines() ? getApprovedCurriculumLinesLastExecutionYear() : null; } final public boolean hasAnyApprovedCurriculumLines() { return hasRoot() ? getRoot().hasAnyApprovedCurriculumLines() : hasAnyApprovedEnrolment(); } final public List getAprovedEnrolments() { final List result = new ArrayList(); addApprovedEnrolments(result); return result; } public boolean hasAnyApprovedEnrolment() { for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.isApproved()) { return true; } } return false; } final public List getAprovedEnrolmentsInExecutionPeriod(final ExecutionSemester executionSemester) { final List result = new ArrayList(); for (final Enrolment enrolment : getEnrolmentsByExecutionPeriod(executionSemester)) { if (enrolment.isApproved()) { result.add(enrolment); } } return result; } final public Collection getDissertationEnrolments() { final Collection result = new HashSet(); for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.getCurricularCourse().isDissertation()) { result.add(enrolment); } } for (Dismissal dismissal : getDismissals()) { for (IEnrolment enrolment : dismissal.getSourceIEnrolments()) { if (!enrolment.isEnrolment()) { continue; } Enrolment realEnrolment = (Enrolment) enrolment; if (realEnrolment.getCurricularCourse().isDissertation()) { result.add(realEnrolment); } } } return result; } final public Enrolment getLatestDissertationEnrolment() { final TreeSet result = new TreeSet(Enrolment.COMPARATOR_BY_EXECUTION_PERIOD_AND_ID); result.addAll(getDissertationEnrolments()); return result.isEmpty() ? null : result.last(); } final public Enrolment getEnrolment(String executionYear, Integer semester, String code) { for (Enrolment enrolment : this.getEnrolmentsSet()) { if (enrolment.getCurricularCourse().getCode().equals(code) && enrolment.getExecutionPeriod().getSemester().equals(semester) && enrolment.getExecutionPeriod().getExecutionYear().getYear().equals(executionYear)) { return enrolment; } } return null; } final public Enrolment getEnrolment(ExecutionSemester executionSemester, String code) { for (Enrolment enrolment : this.getEnrolmentsSet()) { if (enrolment.getCurricularCourse().getCode().equals(code) && enrolment.getExecutionPeriod() == executionSemester) { return enrolment; } } return null; } final public Enrolment findEnrolmentByEnrolmentID(final Integer enrolmentID) { for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.getIdInternal().equals(enrolmentID)) { return enrolment; } } return null; } final public Enrolment findEnrolmentFor(final CurricularCourse curricularCourse, final ExecutionSemester executionSemester) { return isBoxStructure() ? getRoot().findEnrolmentFor(curricularCourse, executionSemester) : getEnrolmentByCurricularCourseAndExecutionPeriod(curricularCourse, executionSemester); } final public Enrolment getEnrolmentByCurricularCourseAndExecutionPeriod(final CurricularCourse curricularCourse, final ExecutionSemester executionSemester) { for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.getCurricularCourse().equals(curricularCourse) && enrolment.isValid(executionSemester)) { return enrolment; } } return null; } final public Set getEnrolmentsExecutionPeriods() { final Set result = new HashSet(); for (final Enrolment enrolment : this.getEnrolmentsSet()) { result.add(enrolment.getExecutionPeriod()); } return result; } final public Set getEnrolmentsExecutionYears() { final Set result = new TreeSet(ExecutionYear.REVERSE_COMPARATOR_BY_YEAR); for (final Enrolment enrolment : this.getEnrolmentsSet()) { result.add(enrolment.getExecutionPeriod().getExecutionYear()); } return result; } final public ExecutionYear getStartExecutionYear() { return ExecutionYear.getExecutionYearByDate(getStartDateYearMonthDay()); } public ExecutionSemester getStartExecutionPeriod() { ExecutionSemester result = null; final YearMonthDay startDate = getStartDateYearMonthDay(); if (startDate != null) { result = ExecutionSemester.readByDateTime(startDate.toDateTimeAtMidnight()); if (result == null) { result = ExecutionYear.readByDateTime(startDate.toDateTimeAtMidnight()).getFirstExecutionPeriod(); } } return result != null ? result : getFirstExecutionPeriod(); } final public ExecutionSemester getFirstExecutionPeriod() { ExecutionSemester result = null; for (final CurriculumLine curriculumLine : this.getAllCurriculumLines()) { final ExecutionSemester executionSemester = curriculumLine.getExecutionPeriod(); if (result == null || (executionSemester != null && result.isAfter(executionSemester))) { result = executionSemester; } } return result; } public YearMonthDay getEndDate() { final StudentCurricularPlan nextStudentCurricularPlan = getNextStudentCurricularPlan(); if (nextStudentCurricularPlan != null) { return nextStudentCurricularPlan.getStartDateYearMonthDay().minusDays(1); } else if (getRegistration() != null && !getRegistration().isActive()) { return getRegistration().getActiveState().getStateDate().toYearMonthDay(); } return null; } private StudentCurricularPlan getNextStudentCurricularPlan() { if (getRegistration() != null) { for (Iterator iter = getRegistration().getSortedStudentCurricularPlans().iterator(); iter .hasNext();) { if (iter.next() == this) { return iter.hasNext() ? iter.next() : null; } } } return null; } public boolean isActive(ExecutionYear executionYear) { return !getStartDateYearMonthDay().isAfter(executionYear.getEndDateYearMonthDay()) && (getEndDate() == null || !getEndDate().isBefore(executionYear.getBeginDateYearMonthDay())); } final public ExecutionYear getLastExecutionYear() { ExecutionYear result = null; for (final CurriculumLine curriculumLine : this.getAllCurriculumLines()) { final ExecutionSemester executionSemester = curriculumLine.getExecutionPeriod(); if (result == null || (executionSemester != null && result.isBefore(executionSemester.getExecutionYear()))) { result = executionSemester.getExecutionYear(); } } return result; } public boolean hasGivenCredits() { return getGivenCredits() != null && getGivenCredits().doubleValue() != Double.valueOf(0).doubleValue(); } protected Integer creditsInSecundaryArea; public Integer getCreditsInSecundaryArea() { // only StudentCurricularPlanLEEC and StudentCurricularPlanLEIC should // return a value return Integer.valueOf(0); } public void setCreditsInSecundaryArea(Integer creditsInSecundaryArea) { // only StudentCurricularPlanLEEC and StudentCurricularPlanLEIC should // set a value } protected Integer creditsInSpecializationArea; public Integer getCreditsInSpecializationArea() { // only StudentCurricularPlanLEEC and StudentCurricularPlanLEIC should // return a value return Integer.valueOf(0); } public void setCreditsInSpecializationArea(Integer creditsInSpecializationArea) { // only StudentCurricularPlanLEEC and StudentCurricularPlanLEIC should // set a value } public Branch getSecundaryBranch() { // only StudentCurricularPlanLEEC and StudentCurricularPlanLEIC should // return a value return null; } public boolean hasSecundaryBranch() { return (getSecundaryBranch() != null); } public void setSecundaryBranch(Branch secundaryBranch) { // only StudentCurricularPlanLEEC and StudentCurricularPlanLEIC should // set a value } final public Integer getSecundaryBranchKey() { // only StudentCurricularPlanLEEC and StudentCurricularPlanLEIC should // return a value return null; } public void setSecundaryBranchKey(Integer secundaryBranchKey) { // only StudentCurricularPlanLEEC and StudentCurricularPlanLEIC should // set a value } // ------------------------------------------------------------- // BEGIN: Only for enrollment purposes (PUBLIC) // ------------------------------------------------------------- public List getAllEnrollments() { List allEnrollments = new ArrayList(); addNonInvisibleEnrolments(allEnrollments, getEnrolments()); for (final StudentCurricularPlan studentCurricularPlan : getRegistration().getStudentCurricularPlans()) { addNonInvisibleEnrolments(allEnrollments, studentCurricularPlan.getEnrolments()); } return allEnrollments; } private void addNonInvisibleEnrolments(List allEnrollments, List enrollmentsToAdd) { for (Enrolment enrolment : enrollmentsToAdd) { if (!enrolment.isInvisible()) { allEnrollments.add(enrolment); } } } final public int getNumberOfStudentEnrollments() { return getAllEnrollments().size(); } public List getStudentEnrollmentsWithApprovedState() { final List result = new ArrayList(); for (final Enrolment enrolment : getAllEnrollments()) { if (enrolment.isApproved()) { result.add(enrolment); } } return result; } final public int getNumberOfStudentEnrollmentsWithApprovedState() { int result = 0; for (final Enrolment enrolment : getAllEnrollments()) { if (enrolment.isApproved()) { result++; } } return result; } final public boolean isCurricularCourseApprovedInCurrentOrPreviousPeriod(final CurricularCourse course, final ExecutionSemester executionSemester) { final List studentApprovedEnrollments = getStudentEnrollmentsWithApprovedState(); final List approvedCurricularCourses = new ArrayList(); for (Iterator iter = studentApprovedEnrollments.iterator(); iter.hasNext();) { Enrolment enrolment = (Enrolment) iter.next(); if (enrolment.getExecutionPeriod().compareTo(executionSemester) <= 0) { approvedCurricularCourses.add(enrolment.getCurricularCourse()); } } return isApproved(course, approvedCurricularCourses); } final protected boolean isApproved(CurricularCourse curricularCourse, List approvedCourses) { return hasEquivalenceIn(curricularCourse, approvedCourses) || hasEquivalenceInNotNeedToEnroll(curricularCourse); } final public boolean isApproved(final CurricularCourse curricularCourse, final ExecutionSemester executionSemester) { return isBoxStructure() ? getRoot().isApproved(curricularCourse, executionSemester) : isCurricularCourseApprovedInCurrentOrPreviousPeriod(curricularCourse, executionSemester); } final public boolean isCurricularCourseApproved(CurricularCourse curricularCourse) { List studentApprovedEnrollments = getStudentEnrollmentsWithApprovedState(); List result = (List) CollectionUtils.collect(studentApprovedEnrollments, new Transformer() { final public Object transform(Object obj) { Enrolment enrollment = (Enrolment) obj; return enrollment.getCurricularCourse(); } }); return isApproved(curricularCourse, result); } final public boolean isApproved(final CurricularCourse curricularCourse) { return isBoxStructure() ? getRoot().isApproved(curricularCourse) : isCurricularCourseApproved(curricularCourse); } public int getNumberOfApprovedCurricularCourses() { int counter = 0; int size = getDegreeCurricularPlan().getCurricularCourses().size(); for (int i = 0; i < size; i++) { CurricularCourse curricularCourse = getDegreeCurricularPlan().getCurricularCourses().get(i); if (isCurricularCourseApproved(curricularCourse)) { counter++; } } return counter; } final public boolean isCurricularCourseNotExtraApprovedInCurrentOrPreviousPeriod(final CurricularCourse course, final ExecutionSemester executionSemester) { final List studentApprovedEnrollments = getStudentEnrollmentsWithApprovedState(); final List approvedCurricularCourses = new ArrayList(); for (Iterator iter = studentApprovedEnrollments.iterator(); iter.hasNext();) { Enrolment enrolment = (Enrolment) iter.next(); if (!enrolment.isExtraCurricular() && enrolment.getExecutionPeriod().compareTo(executionSemester) <= 0) { approvedCurricularCourses.add(enrolment.getCurricularCourse()); } } return isApproved(course, approvedCurricularCourses); } final public boolean isCurricularCourseApprovedWithoutEquivalencesInCurrentOrPreviousPeriod( final CurricularCourse curricularCourse, final ExecutionSemester executionSemester) { for (final Enrolment enrolment : getStudentEnrollmentsWithApprovedState()) { if (enrolment.getCurricularCourse().getIdInternal().equals(curricularCourse.getIdInternal()) && enrolment.isApproved() && (enrolment.getExecutionPeriod().compareTo(executionSemester) <= 0)) { return true; } } return false; } final public boolean isEquivalentAproved(CurricularCourse curricularCourse) { List studentApprovedEnrollments = getStudentEnrollmentsWithApprovedState(); List result = (List) CollectionUtils.collect(studentApprovedEnrollments, new Transformer() { final public Object transform(Object obj) { Enrolment enrollment = (Enrolment) obj; return enrollment.getCurricularCourse(); } }); return isThisCurricularCoursesInTheList(curricularCourse, result) || hasEquivalenceInNotNeedToEnroll(curricularCourse); } private boolean hasEquivalenceInNotNeedToEnroll(CurricularCourse curricularCourse) { if (notNeedToEnroll(curricularCourse)) { return true; } for (CurricularCourseEquivalence equiv : curricularCourse.getCurricularCourseEquivalences()) { if (allNotNeedToEnroll(equiv.getOldCurricularCourses())) { return true; } } return false; } final public void initEctsCreditsToEnrol(List setOfCurricularCoursesToEnroll, ExecutionSemester executionSemester) { for (CurricularCourse2Enroll curricularCourse2Enroll : setOfCurricularCoursesToEnroll) { curricularCourse2Enroll.setEctsCredits(this.getAccumulatedEctsCredits(executionSemester, curricularCourse2Enroll .getCurricularCourse())); } } private boolean allNotNeedToEnroll(List oldCurricularCourses) { for (CurricularCourse course : oldCurricularCourses) { if (!notNeedToEnroll(course)) { return false; } } return true; } final protected boolean hasEquivalenceIn(CurricularCourse curricularCourse, List otherCourses) { if (otherCourses.isEmpty()) { return false; } if (isThisCurricularCoursesInTheList(curricularCourse, otherCourses)) { return true; } for (CurricularCourseEquivalence equiv : curricularCourse.getCurricularCourseEquivalences()) { if (allCurricularCoursesInTheList(equiv.getOldCurricularCourses(), otherCourses)) { return true; } } return false; } private boolean allCurricularCoursesInTheList(List oldCurricularCourses, List otherCourses) { for (CurricularCourse oldCurricularCourse : oldCurricularCourses) { if (!isThisCurricularCoursesInTheList(oldCurricularCourse, otherCourses) && !hasEquivalenceInNotNeedToEnroll(oldCurricularCourse)) { return false; } } return true; } final public boolean isCurricularCourseEnrolled(CurricularCourse curricularCourse) { List result = (List) CollectionUtils.collect(getStudentEnrollmentsWithEnrolledState(), new Transformer() { final public Object transform(Object obj) { Enrolment enrollment = (Enrolment) obj; return enrollment.getCurricularCourse(); } }); return result.contains(curricularCourse); } final public boolean isEnroledInExecutionPeriod(final CurricularCourse curricularCourse) { return isBoxStructure() ? isEnroledInExecutionPeriod(curricularCourse, ExecutionSemester.readActualExecutionSemester()) : isCurricularCourseEnrolled(curricularCourse); } final public boolean isCurricularCourseEnrolledInExecutionPeriod(CurricularCourse curricularCourse, ExecutionSemester executionSemester) { List studentEnrolledEnrollments = getAllStudentEnrolledEnrollmentsInExecutionPeriod(executionSemester); for (Enrolment enrolment : studentEnrolledEnrollments) { if (enrolment.getCurricularCourse().equals(curricularCourse)) { return true; } } return false; } final public boolean isEnroledInExecutionPeriod(final CurricularCourse curricularCourse, final ExecutionSemester executionSemester) { return isBoxStructure() ? getRoot().isEnroledInExecutionPeriod(curricularCourse, executionSemester) : isCurricularCourseEnrolledInExecutionPeriod(curricularCourse, executionSemester); } final public Integer getCurricularCourseAcumulatedEnrollments(CurricularCourse curricularCourse, ExecutionSemester executionSemester) { String key = curricularCourse.getCurricularCourseUniqueKeyForEnrollment(); Integer curricularCourseAcumulatedEnrolments = getAcumulatedEnrollmentsMap(executionSemester).get(key); if (curricularCourseAcumulatedEnrolments == null) { curricularCourseAcumulatedEnrolments = Integer.valueOf(0); } if (curricularCourseAcumulatedEnrolments.intValue() >= curricularCourse.getMinimumValueForAcumulatedEnrollments() .intValue()) { curricularCourseAcumulatedEnrolments = curricularCourse.getMaximumValueForAcumulatedEnrollments(); } if (curricularCourseAcumulatedEnrolments.intValue() == 0) { curricularCourseAcumulatedEnrolments = curricularCourse.getMinimumValueForAcumulatedEnrollments(); } return curricularCourseAcumulatedEnrolments; } final public Integer getCurricularCourseAcumulatedEnrollments(CurricularCourse curricularCourse) { return getCurricularCourseAcumulatedEnrollments(curricularCourse, ExecutionSemester.readActualExecutionSemester()); } final public List getAllStudentEnrolledEnrollmentsInExecutionPeriod(final ExecutionSemester executionSemester) { List result = new ArrayList(); for (Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.getExecutionPeriod().equals(executionSemester) && enrolment.isEnroled() && !enrolment.isInvisible()) { result.add(enrolment); } } initEctsCredits(executionSemester, result); return result; } private void initEctsCredits(ExecutionSemester executionSemester, List enrolments) { for (final Enrolment enrolment : enrolments) { enrolment.setAccumulatedEctsCredits(this .getAccumulatedEctsCredits(executionSemester, enrolment.getCurricularCourse())); } } final public boolean hasEnrolledStateInPreviousExecutionPerdiod(CurricularCourse curricularCourse, List enrollmentsWithEnrolledStateInPreviousExecutionPeriod) { for (Enrolment enrolment : enrollmentsWithEnrolledStateInPreviousExecutionPeriod) { if (enrolment.getCurricularCourse().equals(curricularCourse)) { return true; } } return false; } public boolean areNewAreasCompatible(Branch specializationArea, Branch secundaryArea) throws BothAreasAreTheSameServiceException, InvalidArgumentsServiceException { return true; } public boolean getCanChangeSpecializationArea() { if (getBranch() != null) { return false; } return true; } final public double getAccumulatedEctsCredits(final ExecutionSemester executionSemester) { double result = 0.0; for (final Enrolment enrolment : getVisibleEnroledEnrolments(executionSemester)) { result += getAccumulatedEctsCredits(executionSemester, enrolment.getCurricularCourse()); } return result; } final public double getAccumulatedEctsCredits(final ExecutionSemester executionSemester, final CurricularCourse curricularCourse) { if (curricularCourse.isBolonhaDegree()) { return isAccumulated(executionSemester, curricularCourse) ? MaximumNumberOfCreditsForEnrolmentPeriod .getAccumulatedEcts(curricularCourse, executionSemester) : curricularCourse.getEctsCredits(executionSemester .getSemester(), executionSemester); } else { return getAccumulatedEctsCreditsForOldCurricularCourses(curricularCourse, executionSemester); } } private double getAccumulatedEctsCreditsForOldCurricularCourses(final CurricularCourse curricularCourse, ExecutionSemester executionSemester) { Double factor; Integer curricularCourseAcumulatedEnrolments = getAcumulatedEnrollmentsMap(executionSemester).get( curricularCourse.getCurricularCourseUniqueKeyForEnrollment()); if (curricularCourseAcumulatedEnrolments == null || curricularCourseAcumulatedEnrolments.intValue() == 0) { factor = 1.0; } else { factor = 0.75; } return curricularCourse.getEctsCredits() * factor; } private boolean isAccumulated(final ExecutionSemester executionSemester, final CurricularCourse curricularCourse) { if (curricularCourse.isBolonhaDegree()) { return getPreviouslyEnroledCurricularCourses(executionSemester).contains(curricularCourse); } else { Integer curricularCourseAcumulatedEnrolments = getAcumulatedEnrollmentsMap(executionSemester).get( curricularCourse.getCurricularCourseUniqueKeyForEnrollment()); return curricularCourseAcumulatedEnrolments != null && curricularCourseAcumulatedEnrolments.intValue() != 0; } } private Map> previouslyEnroledCurricularCoursesByExecutionPeriod; private Collection getPreviouslyEnroledCurricularCourses(final ExecutionSemester executionSemester) { if (previouslyEnroledCurricularCoursesByExecutionPeriod == null) { previouslyEnroledCurricularCoursesByExecutionPeriod = new HashMap>(); } Collection previouslyEnroledCurricularCourses = previouslyEnroledCurricularCoursesByExecutionPeriod .get(executionSemester); if (previouslyEnroledCurricularCourses == null && this.isBolonhaDegree()) { previouslyEnroledCurricularCourses = new HashSet(); previouslyEnroledCurricularCoursesByExecutionPeriod.put(executionSemester, previouslyEnroledCurricularCourses); for (final Enrolment enrolment : getEnrolmentsSet()) { if (!enrolment.isAnnulled() && enrolment.getExecutionPeriod().isBefore(executionSemester)) { previouslyEnroledCurricularCourses.add(enrolment.getCurricularCourse()); } } } return previouslyEnroledCurricularCourses; } // ------------------------------------------------------------- // END: Only for enrollment purposes (PUBLIC) // ------------------------------------------------------------- public double getEnrolmentsEctsCredits(final ExecutionYear executionYear) { double result = 0.0; for (final ExecutionSemester executionSemester : executionYear.getExecutionPeriodsSet()) { result += getEnrolmentsEctsCredits(executionSemester); } return result; } final public double getEnrolmentsEctsCredits(final ExecutionSemester executionSemester) { double result = 0.0; for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.isValid(executionSemester)) { result += enrolment.getEctsCredits(); } } return result; } final public double getDismissalsEctsCredits() { double result = 0.0; for (final Dismissal dismissal : getDismissals()) { result += dismissal.getEctsCredits(); } return result; } // ------------------------------------------------------------- // BEGIN: Only for enrollment purposes (PROTECTED) // ------------------------------------------------------------- private Map> acumulatedEnrollments; private void calculateStudentAcumulatedEnrollments(ExecutionSemester executionSemester) { if (!this.isBolonhaDegree()) { if (this.acumulatedEnrollments == null) { this.acumulatedEnrollments = new HashMap>(); } if (this.acumulatedEnrollments.get(executionSemester) == null) { List curricularCourses = new ArrayList(); for (Enrolment enrolment : this.getEnrolmentsSet()) { if (!enrolment.isAnnulled() && enrolment.getExecutionPeriod().isBefore(executionSemester)) { curricularCourses.add(enrolment.getCurricularCourse().getCurricularCourseUniqueKeyForEnrollment()); } } Map map = CollectionUtils.getCardinalityMap(curricularCourses); this.acumulatedEnrollments.put(executionSemester, map); } } } private Set getCurricularCoursesInCurricularCourseEquivalences(final CurricularCourse curricularCourse) { final Set curricularCoursesEquivalent = new HashSet(); final List sameCompetenceCurricularCourses; if (curricularCourse.getCompetenceCourse() == null) { sameCompetenceCurricularCourses = new ArrayList(); sameCompetenceCurricularCourses.add(curricularCourse); } else { sameCompetenceCurricularCourses = new ArrayList(); for (final CurricularCourse course : curricularCourse.getCompetenceCourse().getAssociatedCurricularCourses()) { if (!course.isBolonhaDegree()) { sameCompetenceCurricularCourses.add(course); } } } for (CurricularCourse course : sameCompetenceCurricularCourses) { for (CurricularCourseEquivalence curricularCourseEquivalence : course.getOldCurricularCourseEquivalences()) { curricularCoursesEquivalent.add(curricularCourseEquivalence.getEquivalentCurricularCourse()); } } return curricularCoursesEquivalent; } private boolean isThisCurricularCoursesInTheList(final CurricularCourse curricularCourse, List curricularCourses) { for (CurricularCourse otherCourse : curricularCourses) { if ((curricularCourse == otherCourse) || haveSameCompetence(curricularCourse, otherCourse)) { return true; } } return false; } final public NotNeedToEnrollInCurricularCourse findNotNeddToEnrol(final CurricularCourse curricularCourse) { for (NotNeedToEnrollInCurricularCourse notNeedToEnrollInCurricularCourse : getNotNeedToEnrollCurricularCoursesSet()) { final CurricularCourse otherCourse = notNeedToEnrollInCurricularCourse.getCurricularCourse(); if ((curricularCourse == otherCourse) || haveSameCompetence(curricularCourse, otherCourse)) { return notNeedToEnrollInCurricularCourse; } } return null; } final public boolean notNeedToEnroll(final CurricularCourse curricularCourse) { return findNotNeddToEnrol(curricularCourse) != null; } private boolean haveSameCompetence(CurricularCourse course1, CurricularCourse course2) { CompetenceCourse comp1 = course1.getCompetenceCourse(); CompetenceCourse comp2 = course2.getCompetenceCourse(); return (comp1 != null) && (comp1 == comp2); } private Map getAcumulatedEnrollmentsMap(ExecutionSemester executionSemester) { if (!this.isBolonhaDegree()) { if (this.acumulatedEnrollments == null) { calculateStudentAcumulatedEnrollments(executionSemester); } else { if (this.acumulatedEnrollments.get(executionSemester) == null) { calculateStudentAcumulatedEnrollments(executionSemester); } } return this.acumulatedEnrollments.get(executionSemester); } return null; } private List getStudentNotNeedToEnrollCurricularCourses() { return (List) CollectionUtils.collect(getNotNeedToEnrollCurricularCourses(), new Transformer() { final public Object transform(Object obj) { NotNeedToEnrollInCurricularCourse notNeedToEnrollInCurricularCourse = (NotNeedToEnrollInCurricularCourse) obj; return notNeedToEnrollInCurricularCourse.getCurricularCourse(); } }); } final protected boolean hasCurricularCourseEquivalenceIn(CurricularCourse curricularCourse, List curricularCoursesEnrollments) { int size = curricularCoursesEnrollments.size(); for (int i = 0; i < size; i++) { CurricularCourse tempCurricularCourse = ((Enrolment) curricularCoursesEnrollments.get(i)).getCurricularCourse(); Set curricularCourseEquivalences = getCurricularCoursesInCurricularCourseEquivalences(tempCurricularCourse); if (curricularCourseEquivalences.contains(curricularCourse)) { return true; } } List studentNotNeedToEnrollCourses = getStudentNotNeedToEnrollCurricularCourses(); if (isThisCurricularCoursesInTheList(curricularCourse, studentNotNeedToEnrollCourses)) { return true; } size = studentNotNeedToEnrollCourses.size(); for (int i = 0; i < size; i++) { CurricularCourse ccNotNeedToDo = studentNotNeedToEnrollCourses.get(i); Set curricularCourseEquivalences = getCurricularCoursesInCurricularCourseEquivalences(ccNotNeedToDo); if (curricularCourseEquivalences.contains(curricularCourse)) { return true; } } return false; } final protected boolean isMathematicalCourse(CurricularCourse curricularCourse) { String code = curricularCourse.getCode(); return code.equals("QN") || code.equals("PY") || code.equals("P5") || code.equals("UN") || code.equals("U8") || code.equals("AZ2") || code.equals("AZ3") || code.equals("AZ4") || code.equals("AZ5") || code.equals("AZ6"); } // ------------------------------------------------------------- // END: Only for enrollment purposes (PROTECTED) // ------------------------------------------------------------- final public void setStudentAreasWithoutRestrictions(Branch specializationArea, Branch secundaryArea) throws DomainException { if (specializationArea != null && secundaryArea != null && specializationArea.equals(secundaryArea)) throw new DomainException("error.student.curricular.plan.areas.conflict"); setBranch(specializationArea); setSecundaryBranch(secundaryArea); } final public void setStudentAreas(Branch specializationArea, Branch secundaryArea) throws NotAuthorizedBranchChangeException, BothAreasAreTheSameServiceException, InvalidArgumentsServiceException, DomainException { if (!getCanChangeSpecializationArea()) { throw new NotAuthorizedBranchChangeException(); } if (areNewAreasCompatible(specializationArea, secundaryArea)) { setStudentAreasWithoutRestrictions(specializationArea, secundaryArea); } else { throw new DomainException("error.student.curricular.plan.areas.conflict"); } } final public GratuitySituation getGratuitySituationByGratuityValues(final GratuityValues gratuityValues) { for (final GratuitySituation gratuitySituation : getGratuitySituations()) { if (gratuitySituation.getGratuityValues().equals(gratuityValues)) { return gratuitySituation; } } return null; } final public GratuitySituation getGratuitySituationByGratuityValuesAndGratuitySituationType( final GratuitySituationType gratuitySituationType, final GratuityValues gratuityValues) { GratuitySituation gratuitySituation = this.getGratuitySituationByGratuityValues(gratuityValues); if (gratuitySituation != null && (gratuitySituationType == null || ((gratuitySituationType.equals(GratuitySituationType.CREDITOR) && gratuitySituation .getRemainingValue() < 0.0) || (gratuitySituationType.equals(GratuitySituationType.DEBTOR) && gratuitySituation.getRemainingValue() > 0.0) || (gratuitySituationType .equals(GratuitySituationType.REGULARIZED) && gratuitySituation.getRemainingValue() == 0.0)))) { return gratuitySituation; } return null; } final public T getGratuityEvent(final ExecutionYear executionYear, final Class type) { for (final GratuityEvent gratuityEvent : getGratuityEvents()) { if (!gratuityEvent.isCancelled() && gratuityEvent.getExecutionYear() == executionYear && gratuityEvent.getClass().equals(type)) { return (T) gratuityEvent; } } return null; } final public boolean hasGratuityEvent(final ExecutionYear executionYear, final Class type) { return getGratuityEvent(executionYear, type) != null; } final public Set getNotPayedGratuityEvents() { final Set result = new HashSet(); for (final GratuityEvent gratuityEvent : getGratuityEvents()) { if (gratuityEvent.isInDebt()) { result.add(gratuityEvent); } } return result; } final public boolean hasAnyNotPayedGratuityEvents() { for (final GratuityEvent gratuityEvent : getGratuityEvents()) { if (gratuityEvent.isInDebt()) { return true; } } return false; } final public boolean hasAnyNotPayedGratuityEventsUntil(final ExecutionYear executionYear) { for (final GratuityEvent gratuityEvent : getGratuityEvents()) { if (gratuityEvent.getExecutionYear().isBeforeOrEquals(executionYear) && gratuityEvent.isInDebt()) { return true; } } return false; } final public boolean hasAnyNotPayedGratuityEventsForPreviousYears() { final ExecutionYear currentExecutionYear = ExecutionYear.readCurrentExecutionYear(); for (final GratuityEvent gratuityEvent : getGratuityEvents()) { if (gratuityEvent.getExecutionYear() != currentExecutionYear && gratuityEvent.isInDebt()) { return true; } } return false; } final public MasterDegreeProofVersion readActiveMasterDegreeProofVersion() { MasterDegreeThesis masterDegreeThesis = this.getMasterDegreeThesis(); if (masterDegreeThesis != null) { for (MasterDegreeProofVersion masterDegreeProofVersion : masterDegreeThesis.getMasterDegreeProofVersions()) { if (masterDegreeProofVersion.getCurrentState().getState().equals(State.ACTIVE)) { return masterDegreeProofVersion; } } } return null; } final public List readNotActiveMasterDegreeProofVersions() { MasterDegreeThesis masterDegreeThesis = this.getMasterDegreeThesis(); List masterDegreeProofVersions = new ArrayList(); if (masterDegreeThesis != null) { for (MasterDegreeProofVersion masterDegreeProofVersion : masterDegreeThesis.getMasterDegreeProofVersions()) { if (!masterDegreeProofVersion.getCurrentState().getState().equals(State.ACTIVE)) { masterDegreeProofVersions.add(masterDegreeProofVersion); } } } Collections.sort(masterDegreeProofVersions, new ReverseComparator(MasterDegreeProofVersion.LAST_MODIFICATION_COMPARATOR)); return masterDegreeProofVersions; } final public MasterDegreeThesisDataVersion readActiveMasterDegreeThesisDataVersion() { MasterDegreeThesis masterDegreeThesis = this.getMasterDegreeThesis(); if (masterDegreeThesis != null) { for (MasterDegreeThesisDataVersion masterDegreeThesisDataVersion : masterDegreeThesis .getMasterDegreeThesisDataVersions()) { if (masterDegreeThesisDataVersion.getCurrentState().getState().equals(State.ACTIVE)) { return masterDegreeThesisDataVersion; } } } return null; } final public List readNotActiveMasterDegreeThesisDataVersions() { MasterDegreeThesis masterDegreeThesis = this.getMasterDegreeThesis(); List masterDegreeThesisDataVersions = new ArrayList(); if (masterDegreeThesis != null) { for (MasterDegreeThesisDataVersion masterDegreeThesisDataVersion : masterDegreeThesis .getMasterDegreeThesisDataVersions()) { if (!masterDegreeThesisDataVersion.getCurrentState().getState().equals(State.ACTIVE)) { masterDegreeThesisDataVersions.add(masterDegreeThesisDataVersion); } } } Collections.sort(masterDegreeThesisDataVersions, new ReverseComparator( MasterDegreeThesisDataVersion.LAST_MODIFICATION_COMPARATOR)); return masterDegreeThesisDataVersions; } final public boolean approvedInAllCurricularCoursesUntilInclusiveCurricularYear(final Integer curricularYearInteger) { final DegreeCurricularPlan degreeCurricularPlan = getDegreeCurricularPlan(); for (final CurricularCourse curricularCourse : degreeCurricularPlan.getCurricularCoursesSet()) { final Collection activeCurricularCourseScopes = curricularCourse.getActiveScopes(); for (final CurricularCourseScope curricularCourseScope : activeCurricularCourseScopes) { final CurricularSemester curricularSemester = curricularCourseScope.getCurricularSemester(); final CurricularYear curricularYear = curricularSemester.getCurricularYear(); if (curricularYearInteger == null || curricularYear.getYear().intValue() <= curricularYearInteger.intValue()) { if (!isCurricularCourseApproved(curricularCourse)) { if (LogLevel.INFO) { System.out.println("curricular course failed: " + curricularCourse.getName() + " " + curricularCourse.getCode()); } return false; } } } } return true; } public int numberCompletedCoursesForSpecifiedDegrees(final Set degrees) { int numberCompletedCourses = 0; for (final StudentCurricularPlan studentCurricularPlan : getRegistration().getStudentCurricularPlansSet()) { for (Enrolment enrolment : studentCurricularPlan.getEnrolmentsSet()) { if (!enrolment.isInvisible() && enrolment.isApproved()) { final ExecutionSemester executionSemester = enrolment.getExecutionPeriod(); final ExecutionYear executionYear = executionSemester.getExecutionYear(); if (!executionYear.isCurrent()) { final CurricularCourse curricularCourse = enrolment.getCurricularCourse(); final DegreeCurricularPlan degreeCurricularPlan = curricularCourse.getDegreeCurricularPlan(); final Degree degree = degreeCurricularPlan.getDegree(); final CompetenceCourse competenceCourse = curricularCourse.getCompetenceCourse(); if (degrees.contains(degree) || (competenceCourse != null && competenceCourse.isAssociatedToAnyDegree(degrees))) { numberCompletedCourses++; } } } } } return numberCompletedCourses; } public boolean isEnroledInSpecialSeason(final ExecutionSemester executionSemester) { return hasRoot() ? getRoot().isEnroledInSpecialSeason(executionSemester) : false; } public boolean isEnroledInSpecialSeason(final ExecutionYear executionYear) { return hasRoot() ? getRoot().isEnroledInSpecialSeason(executionYear) : false; } final public Collection getSpecialSeasonToEnrol(ExecutionYear executionYear) { Map result = new HashMap(); for (Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.getEnrolmentEvaluationType() != EnrolmentEvaluationType.SPECIAL_SEASON && enrolment.getExecutionPeriod().getExecutionYear().equals(executionYear) && !enrolment.isApproved()) { if (result.get(enrolment.getCurricularCourse()) != null) { Enrolment enrolmentMap = result.get(enrolment.getCurricularCourse()); if (enrolment.getExecutionPeriod().compareTo(enrolmentMap.getExecutionPeriod()) > 0) { result.put(enrolment.getCurricularCourse(), enrolment); } } else { result.put(enrolment.getCurricularCourse(), enrolment); } } } return new HashSet(result.values()); } final public Collection getSpecialSeasonEnrolments(ExecutionYear executionYear) { if (isBolonhaDegree()) { return getRoot().getSpecialSeasonEnrolments(executionYear); } final Set result = new HashSet(); for (Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.getEnrolmentEvaluationType() == EnrolmentEvaluationType.SPECIAL_SEASON && enrolment.getExecutionPeriod().getExecutionYear().equals(executionYear)) { result.add(enrolment); } } return result; } @Linkare(author = "Paulo Zenida") public final Collection getAppealSeasonEnrolments(final ExecutionSemester executionPeriod) { if (isBolonhaDegree()) { return getRoot().getAppealSeasonEnrolments(executionPeriod); } final Set result = new HashSet(); for (Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.getEnrolmentEvaluationType() == EnrolmentEvaluationType.APPEAL && enrolment.getExecutionPeriod().equals(executionPeriod)) { result.add(enrolment); } } return result; } public BigDecimal getSpecialSeasonEcts(ExecutionYear executionYear) { Collection specialSeasonEnrolments = getSpecialSeasonEnrolments(executionYear); BigDecimal result = BigDecimal.ZERO; for (Enrolment enrolment : specialSeasonEnrolments) { result = result.add(BigDecimal.valueOf(enrolment.getEctsCredits())); } return result; } /** * Has special season in given semester if is enroled in special season in * previous semester * */ public boolean hasSpecialSeasonFor(final ExecutionSemester executionSemester) { final ExecutionSemester previous = executionSemester.getPreviousExecutionPeriod(); return previous != null && isEnroledInSpecialSeason(previous.getExecutionYear()); } public boolean isEnroledInSpecialSituation(final ExecutionSemester executionSemester) { return hasRoot() ? getRoot().isEnroledInSpecialSituation(executionSemester) : false; } public boolean isEnroledInSpecialSituation(final ExecutionYear executionYear) { return hasRoot() ? getRoot().isEnroledInSpecialSituation(executionYear) : false; } final public Collection getSpecialSituationToEnrol(ExecutionYear executionYear) { Map result = new HashMap(); for (Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.getEnrolmentEvaluationType() != EnrolmentEvaluationType.SPECIAL_SITUATION && enrolment.getExecutionPeriod().getExecutionYear().equals(executionYear) && !enrolment.isApproved()) { if (result.get(enrolment.getCurricularCourse()) != null) { Enrolment enrolmentMap = result.get(enrolment.getCurricularCourse()); if (enrolment.getExecutionPeriod().compareTo(enrolmentMap.getExecutionPeriod()) > 0) { result.put(enrolment.getCurricularCourse(), enrolment); } } else { result.put(enrolment.getCurricularCourse(), enrolment); } } } return new HashSet(result.values()); } @Linkare(author = "Paulo Zenida") public final Collection getSpecialSituationEnrolments(ExecutionYear executionYear) { if (isBolonhaDegree()) { return getRoot().getSpecialSituationEnrolments(executionYear); } final Set result = new HashSet(); for (Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.getEnrolmentEvaluationType() == EnrolmentEvaluationType.SPECIAL_SITUATION && enrolment.getExecutionPeriod().getExecutionYear().equals(executionYear)) { result.add(enrolment); } } return result; } @Linkare(author = "Paulo Zenida") public BigDecimal getSpecialSituationEcts(ExecutionYear executionYear) { Collection specialSituationEnrolments = getSpecialSituationEnrolments(executionYear); BigDecimal result = BigDecimal.ZERO; for (Enrolment enrolment : specialSituationEnrolments) { result = result.add(BigDecimal.valueOf(enrolment.getEctsCredits())); } return result; } /** * Has special situation in given semester if is enrolled in special * situation in previous semester * */ @Linkare(author = "Paulo Zenida") public boolean hasSpecialSituationFor(final ExecutionSemester executionSemester) { final ExecutionSemester previous = executionSemester.getPreviousExecutionPeriod(); return previous != null && isEnroledInSpecialSituation(previous.getExecutionYear()); } // Appeals @Linkare(author = "Paulo Zenida") public final void createEnrolmentEvaluationForAppeal(final Collection toCreate, final Employee employee, final ExecutionSemester executionSemester) { final Collection created = new HashSet(); for (final Enrolment enrolment : toCreate) { created.add(enrolment.createEnrolmentInAppealSeason(employee, executionSemester)); } if (isToPayEnrolmentInAppealSeason()) { new EnrolmentInAppealSeasonEvent(employee.getAdministrativeOffice(), getPerson(), created); } } // Improvements final public void createEnrolmentEvaluationForImprovement(final Collection toCreate, final Employee employee, final ExecutionSemester executionSemester) { final Collection created = new HashSet(); for (final Enrolment enrolment : toCreate) { created.add(enrolment.createEnrolmentEvaluationForImprovement(employee, executionSemester)); } if (isToPayImprovementOfApprovedEnrolments()) { new ImprovementOfApprovedEnrolmentEvent(employee.getAdministrativeOffice(), getPerson(), created); } } private boolean isToPayImprovementOfApprovedEnrolments() { final RegistrationAgreement registrationAgreement = getRegistration().getRegistrationAgreement(); return registrationAgreement != RegistrationAgreement.MA && registrationAgreement != RegistrationAgreement.AFA; } @Linkare(author = "Paulo Zenida") private boolean isToPayEnrolmentInAppealSeason() { return true; } final public List getEnroledImprovements() { final List enroledImprovements = new ArrayList(); for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.isImprovementEnroled()) { enroledImprovements.add(enrolment); } } return enroledImprovements; } public List getEnroledImprovements(final ExecutionSemester executionSemester) { final List result = new ArrayList(); for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.hasImprovementFor(executionSemester)) { result.add(enrolment); } } return result; } final public void createFirstTimeStudentEnrolmentsFor(ExecutionSemester executionSemester, String createdBy) { internalCreateFirstTimeStudentEnrolmentsFor(getRoot(), getDegreeCurricularPlan().getCurricularPeriodFor(1, 1), executionSemester, createdBy); } /** * Note: This is enrolment without rules and should only be used for first * time enrolments */ private void internalCreateFirstTimeStudentEnrolmentsFor(CurriculumGroup curriculumGroup, CurricularPeriod curricularPeriod, ExecutionSemester executionSemester, String createdBy) { if (curriculumGroup.hasDegreeModule()) { for (final Context context : curriculumGroup.getDegreeModule().getContextsWithCurricularCourseByCurricularPeriod( curricularPeriod, executionSemester)) { new Enrolment(this, curriculumGroup, (CurricularCourse) context.getChildDegreeModule(), executionSemester, EnrollmentCondition.FINAL, createdBy); } } if (curriculumGroup.hasAnyCurriculumModules()) { for (final CurriculumModule curriculumModule : curriculumGroup.getCurriculumModulesSet()) { if (!curriculumModule.isLeaf()) { internalCreateFirstTimeStudentEnrolmentsFor((CurriculumGroup) curriculumModule, curricularPeriod, executionSemester, createdBy); } } } } final public void createModules(Collection degreeModulesToEnrol, ExecutionSemester executionSemester, EnrollmentCondition enrollmentCondition) { for (DegreeModuleToEnrol degreeModuleToEnrol : degreeModulesToEnrol) { final DegreeModule childDegreeModule = degreeModuleToEnrol.getContext().getChildDegreeModule(); if (childDegreeModule.isLeaf()) { new Enrolment(this, degreeModuleToEnrol.getCurriculumGroup(), (CurricularCourse) childDegreeModule, executionSemester, enrollmentCondition, AccessControl.getUserView().getUtilizador()); } else if (childDegreeModule instanceof CycleCourseGroup) { new CycleCurriculumGroup((RootCurriculumGroup) degreeModuleToEnrol.getCurriculumGroup(), (CycleCourseGroup) childDegreeModule, executionSemester); } else { new CurriculumGroup(degreeModuleToEnrol.getCurriculumGroup(), (CourseGroup) childDegreeModule, executionSemester); } } } final public Set getDegreeModulesToEvaluate(final ExecutionSemester executionSemester) { return isBolonhaDegree() ? getRoot().getDegreeModulesToEvaluate(executionSemester) : Collections.EMPTY_SET; } @Checked("StudentCurricularPlanPredicates.ENROL") final public RuleResult enrol(final Person responsiblePerson, final ExecutionSemester executionSemester, final Set degreeModulesToEnrol, final List curriculumModulesToRemove, final CurricularRuleLevel curricularRuleLevel) { final EnrolmentContext enrolmentContext = new EnrolmentContext(responsiblePerson, this, executionSemester, degreeModulesToEnrol, curriculumModulesToRemove, curricularRuleLevel); return net.sourceforge.fenixedu.domain.studentCurriculum.StudentCurricularPlanEnrolment.createManager(enrolmentContext) .manage(); } final public RuleResult enrol(final Person responsiblePerson, final ExecutionSemester executionSemester, final CurricularRuleLevel curricularRuleLevel) { return enrol(responsiblePerson, executionSemester, Collections.EMPTY_SET, Collections.EMPTY_LIST, curricularRuleLevel); } @Checked("StudentCurricularPlanPredicates.ENROL_IN_AFFINITY_CYCLE") public void enrolInAffinityCycle(final CycleCourseGroup cycleCourseGroup, final ExecutionSemester executionSemester) { if (getDegreeCurricularPlan().getRoot().hasDegreeModule(cycleCourseGroup)) { new CycleCurriculumGroup(getRoot(), cycleCourseGroup, executionSemester); } else { new ExternalCurriculumGroup(getRoot(), cycleCourseGroup, executionSemester); } } final public String getName() { return getDegreeCurricularPlan().getName(); } final public String getPresentationName() { return getPresentationName(ExecutionYear.readCurrentExecutionYear()); } final public String getPresentationName(final ExecutionYear executionYear) { return getDegreeCurricularPlan().getPresentationName(executionYear); } final public Campus getCurrentCampus() { final Campus currentCampus = getDegreeCurricularPlan().getCurrentCampus(); return currentCampus == null ? getLastCampus() : currentCampus; } final public Campus getCampus(final ExecutionYear executionYear) { final Campus result = getDegreeCurricularPlan().getCampus(executionYear); return result == null ? getLastCampus() : result; } final public Campus getLastCampus() { final Campus lastScpCampus = getDegreeCurricularPlan().getCampus(getLastExecutionYear()); return lastScpCampus == null ? getDegreeCurricularPlan().getLastCampus() : lastScpCampus; } final public void createOptionalEnrolment(final CurriculumGroup curriculumGroup, final ExecutionSemester executionSemester, final OptionalCurricularCourse optionalCurricularCourse, final CurricularCourse curricularCourse, final EnrollmentCondition enrollmentCondition) { if (getRoot().isApproved(curricularCourse, executionSemester)) { throw new DomainException("error.already.aproved", new String[] { curricularCourse.getName() }); } if (getRoot().isEnroledInExecutionPeriod(curricularCourse, executionSemester)) { throw new DomainException("error.already.enroled.in.executioPerdiod", new String[] { curricularCourse.getName(), executionSemester.getQualifiedName() }); } new OptionalEnrolment(this, curriculumGroup, curricularCourse, executionSemester, enrollmentCondition, AccessControl .getUserView().getUtilizador(), optionalCurricularCourse); } final public RuleResult createNoCourseGroupCurriculumGroupEnrolment(final CurricularCourse curricularCourse, final ExecutionSemester executionSemester, final NoCourseGroupCurriculumGroupType groupType, final Person person) { final EnrolmentContext enrolmentContext = EnrolmentContext.createForNoCourseGroupCurriculumGroupEnrolment(person, this, curricularCourse, executionSemester, groupType); return net.sourceforge.fenixedu.domain.studentCurriculum.StudentCurricularPlanEnrolment.createManager(enrolmentContext) .manage(); } @Service public RuleResult removeCurriculumModulesFromNoCourseGroupCurriculumGroup(final List curriculumModules, final ExecutionSemester executionSemester, final NoCourseGroupCurriculumGroupType groupType, final Person person) { final EnrolmentContext context = new EnrolmentContext(person, this, executionSemester, Collections.EMPTY_SET, curriculumModules, groupType.getCurricularRuleLevel()); return net.sourceforge.fenixedu.domain.studentCurriculum.StudentCurricularPlanEnrolment.createManager(context).manage(); } final public NoCourseGroupCurriculumGroup getNoCourseGroupCurriculumGroup(final NoCourseGroupCurriculumGroupType groupType) { return (getRoot() != null) ? getRoot().getNoCourseGroupCurriculumGroup(groupType) : null; } final public NoCourseGroupCurriculumGroup createNoCourseGroupCurriculumGroup(final NoCourseGroupCurriculumGroupType groupType) { final NoCourseGroupCurriculumGroup noCourseGroupCurriculumGroup = getNoCourseGroupCurriculumGroup(groupType); if (noCourseGroupCurriculumGroup != null) { throw new DomainException("error.studentCurricularPlan.already.has.noCourseGroupCurriculumGroup.with.same.groupType"); } return NoCourseGroupCurriculumGroup.createNewNoCourseGroupCurriculumGroup(groupType, getRoot()); } public ExtraCurriculumGroup createExtraCurriculumGroup() { return (ExtraCurriculumGroup) createNoCourseGroupCurriculumGroup(NoCourseGroupCurriculumGroupType.EXTRA_CURRICULAR); } public ExtraCurriculumGroup getExtraCurriculumGroup() { return (ExtraCurriculumGroup) getNoCourseGroupCurriculumGroup(NoCourseGroupCurriculumGroupType.EXTRA_CURRICULAR); } public boolean hasExtraCurriculumGroup() { return getExtraCurriculumGroup() != null; } public StandaloneCurriculumGroup getStandaloneCurriculumGroup() { return (StandaloneCurriculumGroup) getNoCourseGroupCurriculumGroup(NoCourseGroupCurriculumGroupType.STANDALONE); } public boolean hasStandaloneCurriculumGroup() { return getStandaloneCurriculumGroup() != null; } final public Collection getExtraCurricularCurriculumLines() { final Collection result = new ArrayList(); if (hasExtraCurriculumGroup()) { for (final CurriculumLine curriculumLine : getExtraCurriculumGroup().getCurriculumLines()) { result.add(curriculumLine); } } return result; } /** * Note that this method must not use the ExtraCurriculumGroup due to the * pre-Bolonha SCPs */ final public Collection getExtraCurricularEnrolments() { final Collection result = new ArrayList(); for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.isExtraCurricular()) { result.add(enrolment); } } return result; } public List getExtraCurricularAprovedEnrolmentsNotInDismissal() { final List result = new ArrayList(); for (final Enrolment enrolment : getExtraCurricularEnrolments()) { if (!enrolment.isApproved() || enrolment.isSourceOfAnyCreditsInCurriculum()) { continue; } result.add(enrolment); } return result; } public List getStandaloneAprovedEnrolmentsNotInDismissal() { final List result = new ArrayList(); StandaloneCurriculumGroup standaloneGroup = getStandaloneCurriculumGroup(); if (standaloneGroup == null) { return result; } for (final Enrolment enrolment : standaloneGroup.getEnrolments()) { if (!enrolment.isApproved() || enrolment.isSourceOfAnyCreditsInCurriculum()) { continue; } result.add(enrolment); } return result; } public PropaedeuticsCurriculumGroup getPropaedeuticCurriculumGroup() { return (PropaedeuticsCurriculumGroup) getNoCourseGroupCurriculumGroup(NoCourseGroupCurriculumGroupType.PROPAEDEUTICS); } public boolean hasPropaedeuticsCurriculumGroup() { return getPropaedeuticCurriculumGroup() != null; } final public Collection getPropaedeuticCurriculumLines() { final Collection result = new ArrayList(); if (hasPropaedeuticsCurriculumGroup()) { for (final CurriculumLine curriculumLine : getPropaedeuticCurriculumGroup().getCurriculumLines()) { result.add(curriculumLine); } } return result; } /** * Note that this method must not use the ExtraCurriculumGroup due to the * pre-Bolonha SCPs */ final public Collection getPropaedeuticEnrolments() { final Collection result = new ArrayList(); for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.isPropaedeutic()) { result.add(enrolment); } } return result; } public Collection getAllCurricularCoursesToDismissal(final ExecutionSemester executionSemester) { final Collection result = new HashSet(); if (isBolonhaDegree()) { for (final CycleType cycleType : getDegreeType().getSupportedCyclesToEnrol()) { final CourseGroup courseGroup = getCourseGroupWithCycleTypeToCollectCurricularCourses(cycleType); if (courseGroup != null) { for (final CurricularCourse curricularCourse : courseGroup.getAllCurricularCourses(executionSemester)) { if (!isApproved(curricularCourse)) { result.add(curricularCourse); } } } } } else { for (final CurricularCourse curricularCourse : getDegreeCurricularPlan().getCurricularCoursesSet()) { if (curricularCourse.isActive(executionSemester) && !isApproved(curricularCourse)) { result.add(curricularCourse); } } } return result; } public Collection getAllCurricularCoursesToDismissal() { return getAllCurricularCoursesToDismissal(null); } private CourseGroup getCourseGroupWithCycleTypeToCollectCurricularCourses(final CycleType cycleType) { final CycleCurriculumGroup curriculumGroup = getCycle(cycleType); return curriculumGroup != null ? curriculumGroup.getDegreeModule() : getDegreeCurricularPlan().getCycleCourseGroup( cycleType); } @Checked("RolePredicates.MANAGER_OR_ACADEMIC_ADMINISTRATIVE_OFFICE_PREDICATE") final public Credits createNewCreditsDismissal(CourseGroup courseGroup, CurriculumGroup curriculumGroup, Collection dismissals, Collection enrolments, Double givenCredits, ExecutionSemester executionSemester) { checkPermission(courseGroup, curriculumGroup, dismissals); if (courseGroup != null) { Collection noEnrolCurricularCourse = new ArrayList(); if (dismissals != null) { for (SelectedCurricularCourse selectedCurricularCourse : dismissals) { noEnrolCurricularCourse.add(selectedCurricularCourse.getCurricularCourse()); } } return new Credits(this, courseGroup, enrolments, noEnrolCurricularCourse, givenCredits, executionSemester); } else if (curriculumGroup != null) { return new Credits(this, curriculumGroup, enrolments, givenCredits, executionSemester); } else { return new Credits(this, dismissals, enrolments, executionSemester); } } public List getDismissals() { final List result = new ArrayList(); if (isBoxStructure()) { getRoot().collectDismissals(result); } return result; } public Dismissal getDismissal(final CurricularCourse curricularCourse) { return isBoxStructure() ? getRoot().getDismissal(curricularCourse) : null; } public Substitution getSubstitution(final IEnrolment iEnrolment) { for (final Dismissal dismissal : getDismissals()) { if (dismissal.getCredits().isSubstitution() && dismissal.getSourceIEnrolments().contains(iEnrolment)) { return (Substitution) dismissal.getCredits(); } } return null; } @Checked("RolePredicates.MANAGER_OR_ACADEMIC_ADMINISTRATIVE_OFFICE_PREDICATE") final public Equivalence createNewEquivalenceDismissal(CourseGroup courseGroup, CurriculumGroup curriculumGroup, Collection dismissals, Collection enrolments, Double givenCredits, Grade givenGrade, ExecutionSemester executionSemester) { checkPermission(courseGroup, curriculumGroup, dismissals); if (courseGroup != null) { Collection noEnrolCurricularCourse = new ArrayList(); if (dismissals != null) { for (SelectedCurricularCourse selectedCurricularCourse : dismissals) { noEnrolCurricularCourse.add(selectedCurricularCourse.getCurricularCourse()); } } return new Equivalence(this, courseGroup, enrolments, noEnrolCurricularCourse, givenCredits, givenGrade, executionSemester); } else if (curriculumGroup != null) { return new Equivalence(this, curriculumGroup, enrolments, givenCredits, givenGrade, executionSemester); } else { return new Equivalence(this, dismissals, enrolments, givenGrade, executionSemester); } } private void checkPermission(final CourseGroup courseGroup, final CurriculumGroup curriculumGroup, final Collection dismissals) { final Person person = AccessControl.getPerson(); final AdministrativeOfficePermission permission = getUpdateRegistrationAfterConclusionProcessPermission(person); if (permission != null) { if (courseGroup != null) { final CurriculumGroup group = findCurriculumGroupFor(courseGroup); if (group != null && permission.isAppliable(group.getParentCycleCurriculumGroup()) && !permission.isMember(person)) { throw new DomainException("error.StudentCurricularPlan.cannot.create.dismissals"); } } else if (curriculumGroup != null) { if (permission.isAppliable(curriculumGroup.getParentCycleCurriculumGroup()) && !permission.isMember(person)) { throw new DomainException("error.StudentCurricularPlan.cannot.create.dismissals"); } } else { for (final SelectedCurricularCourse selected : dismissals) { if (permission.isAppliable(selected.getCurriculumGroup().getParentCycleCurriculumGroup()) && !permission.isMember(person)) { throw new DomainException("error.StudentCurricularPlan.cannot.create.dismissals"); } } } if (permission.isAppliable(getRegistration()) && !permission.isMember(person)) { throw new DomainException("error.StudentCurricularPlan.cannot.create.dismissals"); } } } @Checked("RolePredicates.MANAGER_OR_ACADEMIC_ADMINISTRATIVE_OFFICE_PREDICATE") final public Equivalence createNewSubstitutionDismissal(CourseGroup courseGroup, CurriculumGroup curriculumGroup, Collection dismissals, Collection enrolments, Double givenCredits, ExecutionSemester executionSemester) { checkPermission(courseGroup, curriculumGroup, dismissals); if (courseGroup != null) { Collection noEnrolCurricularCourse = new ArrayList(); if (dismissals != null) { for (SelectedCurricularCourse selectedCurricularCourse : dismissals) { noEnrolCurricularCourse.add(selectedCurricularCourse.getCurricularCourse()); } } return new Substitution(this, courseGroup, enrolments, noEnrolCurricularCourse, givenCredits, executionSemester); } else if (curriculumGroup != null) { return new Substitution(this, curriculumGroup, enrolments, givenCredits, executionSemester); } else { return new Substitution(this, dismissals, enrolments, executionSemester); } } final public Set getAllDegreeModules() { final Set degreeModules = new TreeSet(DegreeModule.COMPARATOR_BY_NAME); final RootCurriculumGroup rootCurriculumGroup = getRoot(); if (rootCurriculumGroup != null) { rootCurriculumGroup.getAllDegreeModules(degreeModules); } return degreeModules; } public boolean hasDegreeModule(final DegreeModule degreeModule) { return isBoxStructure() ? getRoot().hasDegreeModule(degreeModule) : false; } public boolean hasCurriculumModule(final CurriculumModule curriculumModule) { return isBoxStructure() ? getRoot().hasCurriculumModule(curriculumModule) : false; } public CurriculumGroup findCurriculumGroupFor(final CourseGroup courseGroup) { return isBoxStructure() ? getRoot().findCurriculumGroupFor(courseGroup) : null; } public boolean isConcluded(final DegreeModule degreeModule, final ExecutionYear executionYear) { return isBoxStructure() ? getRoot().hasConcluded(degreeModule, executionYear) : false; } final public MasterDegreeCandidate getMasterDegreeCandidate() { if (getDegreeType().equals(DegreeType.MASTER_DEGREE)) { if (this.getEnrolmentsSet().size() > 0) { ExecutionDegree firstExecutionDegree = this.getDegreeCurricularPlan().getExecutionDegreeByYear( this.getFirstExecutionPeriod().getExecutionYear()); for (final MasterDegreeCandidate candidate : this.getPerson().getMasterDegreeCandidates()) { if (candidate.getExecutionDegree() == firstExecutionDegree) { return candidate; } } } else if (this.getPerson().getMasterDegreeCandidatesCount() == 1) { return this.getPerson().getMasterDegreeCandidates().iterator().next(); } } return null; } final public Double getCreditsConcludedForCourseGroup(final CourseGroup courseGroup) { final CurriculumGroup curriculumGroup = findCurriculumGroupFor(courseGroup); return (curriculumGroup == null) ? Double.valueOf(0d) : curriculumGroup.getCreditsConcluded(); } final public void setIsFirstTimeToNull() { for (final Enrolment enrolment : getEnrolmentsSet()) { enrolment.setIsFirstTime(null); } } final public void resetIsFirstTimeEnrolmentForCurricularCourse(final CurricularCourse curricularCourse) { final SortedSet enrolments = new TreeSet(Enrolment.COMPARATOR_BY_EXECUTION_PERIOD_AND_ID); for (final Enrolment enrolment : getEnrolmentsSet()) { if (curricularCourse == enrolment.getCurricularCourse()) { enrolments.add(enrolment); } } Boolean b = Boolean.TRUE; for (final Enrolment enrolment : enrolments) { if (!enrolment.isAnnulled()) { enrolment.setIsFirstTime(b); b = Boolean.FALSE; } else { enrolment.setIsFirstTime(Boolean.FALSE); } } } final public StudentCurricularPlanEquivalencePlan createStudentCurricularPlanEquivalencePlan() { return new StudentCurricularPlanEquivalencePlan(this); } final public boolean hasEnrolmentOrAprovalInCurriculumModule(final DegreeModule degreeModule) { final RootCurriculumGroup rootCurriculumGroup = getRoot(); return rootCurriculumGroup != null && hasEnrolmentOrAprovalInCurriculumModule(rootCurriculumGroup, degreeModule); } private boolean hasEnrolmentOrAprovalInCurriculumModule(final CurriculumModule curriculumModule, final DegreeModule degreeModule) { if (curriculumModule.getDegreeModule() == degreeModule) { return true; } if (curriculumModule.isLeaf()) { return false; } final CurriculumGroup curriculumGroup = (CurriculumGroup) curriculumModule; for (final CurriculumModule child : curriculumGroup.getCurriculumModulesSet()) { if (hasEnrolmentOrAprovalInCurriculumModule(child, degreeModule)) { return true; } } return false; } public List getEnrolmentsWithExecutionYearBeforeOrEqualTo(final ExecutionYear executionYear) { final List result = new ArrayList(); for (final Enrolment enrolment : getEnrolmentsSet()) { if (enrolment.getExecutionPeriod().getExecutionYear().isBeforeOrEquals(executionYear)) { result.add(enrolment); } } return result; } public Tutorship getLastTutorship() { if (hasAnyTutorships()) { return Collections.max(getTutorships(), Tutorship.TUTORSHIP_START_DATE_COMPARATOR); } return null; } public Tutorship getActiveTutorship() { List tutorships = getTutorships(); if (!tutorships.isEmpty() && getLastTutorship().isActive()) { return getLastTutorship(); } return null; } @Override public void addTutorships(Tutorship tutorships) throws DomainException { for (Tutorship tutorship : getTutorships()) { if (tutorship.getTeacher().equals(tutorships.getTeacher()) && tutorship.getEndDate().equals(tutorships.getEndDate())) { throw new DomainException("error.tutorships.duplicatedTutorship"); } if (tutorship.isActive()) { throw new DomainException("error.tutorships.onlyOneActiveTutorship"); } } super.addTutorships(tutorships); } public boolean getHasAnyEquivalences() { return !this.getNotNeedToEnrollCurricularCourses().isEmpty(); } public boolean isLastStudentCurricularPlanFromRegistration() { return hasRegistration() && getRegistration().getLastStudentCurricularPlan() == this; } @Checked("StudentCurricularPlanPredicates.MOVE_CURRICULUM_LINES") public void moveCurriculumLines(final Person responsiblePerson, final MoveCurriculumLinesBean moveCurriculumLinesBean) { boolean runRules = false; final AdministrativeOfficePermission permission = getUpdateRegistrationAfterConclusionProcessPermission(responsiblePerson); for (final CurriculumLineLocationBean curriculumLineLocationBean : moveCurriculumLinesBean.getCurriculumLineLocations()) { final CurriculumGroup destination = curriculumLineLocationBean.getCurriculumGroup(); final CurriculumLine curriculumLine = curriculumLineLocationBean.getCurriculumLine(); if (curriculumLine.getCurriculumGroup() != destination) { checkPermission(responsiblePerson, permission, curriculumLineLocationBean); if (!destination.canAdd(curriculumLine)) { throw new DomainException("error.StudentCurricularPlan.cannot.move.curriculum.line.to.curriculum.group", curriculumLine.getFullPath(), destination.getFullPath()); } if (curriculumLine.hasExecutionPeriod() && curriculumLine.getExecutionYear().isBefore(destination.getRegistration().getStartExecutionYear())) { throw new DomainException( "error.StudentCurricularPlan.cannot.move.curriculum.line.to.curriculum.group.invalid.period", curriculumLine.getFullPath(), destination.getFullPath(), curriculumLine.getExecutionPeriod() .getQualifiedName(), destination.getRegistration().getStartExecutionYear().getQualifiedName()); } if (!destination.isExtraCurriculum()) { runRules = true; } curriculumLine.setCurriculumGroup(destination); } if (!curriculumLine.hasCreatedBy()) { curriculumLine.setCreatedBy(responsiblePerson != null ? responsiblePerson.getIstUsername() : null); } } runRules &= isBolonhaDegree(); if (runRules) { checkEnrolmentRules(responsiblePerson, moveCurriculumLinesBean.getIDegreeModulesToEvaluate(ExecutionSemester .readActualExecutionSemester()), ExecutionSemester.readActualExecutionSemester()); } } @Checked("StudentCurricularPlanPredicates.MOVE_CURRICULUM_LINES_WITHOUT_RULES") public void moveCurriculumLinesWithoutRules(final Person responsiblePerson, final MoveCurriculumLinesBean moveCurriculumLinesBean) { final AdministrativeOfficePermission permission = getUpdateRegistrationAfterConclusionProcessPermission(responsiblePerson); for (final CurriculumLineLocationBean curriculumLineLocationBean : moveCurriculumLinesBean.getCurriculumLineLocations()) { final CurriculumGroup destination = curriculumLineLocationBean.getCurriculumGroup(); final CurriculumLine curriculumLine = curriculumLineLocationBean.getCurriculumLine(); if (curriculumLine.getCurriculumGroup() != destination) { checkPermission(responsiblePerson, permission, curriculumLineLocationBean); if (curriculumLine.hasExecutionPeriod() && curriculumLine.getExecutionYear().isBefore(destination.getRegistration().getStartExecutionYear())) { throw new DomainException( "error.StudentCurricularPlan.cannot.move.curriculum.line.to.curriculum.group.invalid.period", curriculumLine.getFullPath(), destination.getFullPath(), curriculumLine.getExecutionPeriod() .getQualifiedName(), destination.getRegistration().getStartExecutionYear().getQualifiedName()); } curriculumLine.setCurriculumGroup(destination); } if (!curriculumLine.hasCreatedBy()) { curriculumLine.setCreatedBy(responsiblePerson != null ? responsiblePerson.getIstUsername() : null); } } } private void checkPermission(final Person responsiblePerson, final AdministrativeOfficePermission permission, final CurriculumLineLocationBean bean) { if (permission != null && permission.isAppliable(bean.getCurriculumGroup().getParentCycleCurriculumGroup())) { if (!permission.isMember(responsiblePerson)) { throw new DomainException("error.StudentCurricularPlan.cannot.move.is.not.authorized"); } } if (permission != null && permission.isAppliable(bean.getCurriculumLine().getParentCycleCurriculumGroup())) { if (!permission.isMember(responsiblePerson)) { throw new DomainException("error.StudentCurricularPlan.cannot.move.is.not.authorized"); } } } private AdministrativeOfficePermission getUpdateRegistrationAfterConclusionProcessPermission(final Person person) { final AdministrativeOffice office = person.getEmployeeAdministrativeOffice(); return office != null ? office.getPermission(PermissionType.UPDATE_REGISTRATION_AFTER_CONCLUSION, person .getEmployeeCampus()) : null; } @SuppressWarnings("unchecked") private void checkEnrolmentRules(final Person responsiblePerson, final Set degreeModuleToEvaluate, final ExecutionSemester executionSemester) { enrol(responsiblePerson, executionSemester, degreeModuleToEvaluate, Collections.EMPTY_LIST, CurricularRuleLevel.ENROLMENT_WITH_RULES); } public AdministrativeOffice getAdministrativeOffice() { return AdministrativeOffice.readByAdministrativeOfficeType(getDegree().getDegreeType().getAdministrativeOfficeType()); } public CycleCurriculumGroup getCycle(final CycleType cycleType) { return isBoxStructure() ? getRoot().getCycleCurriculumGroup(cycleType) : null; } public boolean hasCycleCurriculumGroup(final CycleType cycleType) { return getCycle(cycleType) != null; } public CycleCourseGroup getCycleCourseGroup(final CycleType cycleType) { return isBoxStructure() ? getDegreeCurricularPlan().getCycleCourseGroup(cycleType) : null; } public Collection getCurricularCoursePossibleGroups(final CurricularCourse curricularCourse) { return getRoot().getCurricularCoursePossibleGroups(curricularCourse); } public Collection getCurricularCoursePossibleGroupsWithoutNoCourseGroupCurriculumGroups( final CurricularCourse curricularCourse) { return getRoot().getCurricularCoursePossibleGroupsWithoutNoCourseGroupCurriculumGroups(curricularCourse); } public CycleCurriculumGroup getFirstCycle() { return isBoxStructure() ? getRoot().getCycleCurriculumGroup(CycleType.FIRST_CYCLE) : null; } public CycleCurriculumGroup getSecondCycle() { return isBoxStructure() ? getRoot().getCycleCurriculumGroup(CycleType.SECOND_CYCLE) : null; } public CycleCurriculumGroup getThirdCycle() { return isBoxStructure() ? getRoot().getCycleCurriculumGroup(CycleType.THIRD_CYCLE) : null; } public CycleCurriculumGroup getFirstOrderedCycleCurriculumGroup() { return isBoxStructure() ? getRoot().getFirstOrderedCycleCurriculumGroup() : null; } public CycleCurriculumGroup getLastOrderedCycleCurriculumGroup() { return isBoxStructure() ? getRoot().getLastOrderedCycleCurriculumGroup() : null; } public CycleCurriculumGroup getLastConcludedCycleCurriculumGroup() { return isBoxStructure() ? getRoot().getLastConcludedCycleCurriculumGroup() : null; } public Collection getCycleCurriculumGroups() { return hasRoot() ? getRoot().getCycleCurriculumGroups() : Collections.EMPTY_SET; } public List getInternalCycleCurriculumGrops() { return hasRoot() ? getRoot().getInternalCycleCurriculumGroups() : Collections.EMPTY_LIST; } public Collection getExternalCurriculumGroups() { return hasRoot() ? getRoot().getExternalCycleCurriculumGroups() : Collections.EMPTY_LIST; } public boolean hasExternalCycleCurriculumGroups() { return hasRoot() ? getRoot().hasExternalCycles() : false; } public Integer getInternalCycleCurriculumGroupsSize() { return getInternalCycleCurriculumGrops().size(); } public List getSupportedCycleTypesToEnrol() { final List result = new ArrayList(); final List supportedCyclesToEnrol = new ArrayList(getDegreeType().getSupportedCyclesToEnrol()); Collections.sort(supportedCyclesToEnrol, CycleType.COMPARATOR_BY_GREATER_WEIGHT); for (final CycleType cycleType : supportedCyclesToEnrol) { if (hasCycleCurriculumGroup(cycleType)) { break; } else { result.add(0, cycleType); } } return result; } public boolean isEmpty() { if (hasAnyEnrolments()) return false; if (hasAnyTutorships()) return false; if (hasRoot() && !getRoot().getAllCurriculumLines().isEmpty()) return false; if (hasEquivalencePlan()) return false; if (hasAnyGratuityEvents()) return false; if (hasAnyNotNeedToEnrollCurricularCourses()) return false; if (hasAnyCreditsInAnySecundaryAreas()) return false; if (hasAnyGratuitySituations()) return false; if (hasMasterDegreeThesis()) return false; if (hasAnyCreditsInScientificAreas()) return false; if (hasAnyCredits()) return false; return true; } public Collection getNoCourseGroupCurriculumGroups() { return isBoxStructure() ? getRoot().getNoCourseGroupCurriculumGroups() : new HashSet(); } @Checked("RolePredicates.ACADEMIC_ADMINISTRATIVE_OFFICE_PREDICATE") public void deleteExecutionYearEnrolments(final ExecutionYear executionYear) { for (Enrolment enrolment : getEnrolmentsByExecutionYear(executionYear)) { if (!enrolment.hasAnyAssociatedMarkSheetOrFinalGrade()) { enrolment.delete(); } } } public boolean hasAnyActiveRegistrationWithFirstCycleAffinity() { final CycleCurriculumGroup firstCycle = getFirstCycle(); if (firstCycle == null) { return false; } final Student student = getRegistration().getStudent(); for (final CycleCourseGroup affinity : getCycleCourseGroup(firstCycle.getCycleType()).getDestinationAffinities()) { if (student.hasActiveRegistrationFor(affinity.getParentDegreeCurricularPlan())) { return true; } } return false; } public Collection getCycleTypes() { return getDegreeType().getCycleTypes(); } public CurriculumLine getApprovedCurriculumLine(final CurricularCourse curricularCourse) { return isBoxStructure() ? getRoot().getApprovedCurriculumLine(curricularCourse) : null; } @Override public List getEnrolmentOutOfPeriodEvents() { final List result = new ArrayList(); for (final EnrolmentOutOfPeriodEvent each : super.getEnrolmentOutOfPeriodEvents()) { if (!each.isCancelled()) { result.add(each); } } return result; } public OptionalEnrolment convertEnrolmentToOptionalEnrolment(final Enrolment enrolment, final CurriculumGroup curriculumGroup, final OptionalCurricularCourse curricularCourse) { final Person person = AccessControl.getPerson(); final AdministrativeOfficePermission permission = getUpdateRegistrationAfterConclusionProcessPermission(person); if (permission != null && permission.isAppliable(enrolment.getParentCycleCurriculumGroup())) { if (!permission.isMember(person)) { throw new DomainException("error.StudentCurricularPlan.cannot.move.is.not.authorized"); } } if (!hasEnrolments(enrolment)) { // if we remove this test, then check if enrolment period is before // registration start throw new DomainException("error.StudentCurricularPlan.doesnot.have.enrolment", enrolment.getName().getContent()); } if (isApproved(curricularCourse)) { throw new DomainException("error.Enrolment.duplicate.enrolment", curricularCourse.getName()); } final OptionalEnrolment result = OptionalEnrolment.createBasedOn(enrolment, curriculumGroup, curricularCourse); enrolment.getProgramCertificateRequests().clear(); enrolment.getCourseLoadRequests().clear(); enrolment.getExamDateCertificateRequests().clear(); enrolment.delete(); if (result.getStudentCurricularPlan() != this) { correctInvalidAttends(result.getStudentCurricularPlan()); } return result; } private void correctInvalidAttends(final StudentCurricularPlan to) { for (final Attends attend : getRegistration().getAssociatedAttends()) { if (!attend.hasExecutionCourseTo(this) && attend.canMove(this, to)) { getRegistration().changeShifts(attend, to.getRegistration()); attend.setRegistration(to.getRegistration()); } } } public Enrolment convertOptionalEnrolmentToEnrolment(final OptionalEnrolment enrolment, final CurriculumGroup curriculumGroup) { final Person person = AccessControl.getPerson(); final AdministrativeOfficePermission permission = getUpdateRegistrationAfterConclusionProcessPermission(person); if (permission != null && permission.isAppliable(enrolment.getParentCycleCurriculumGroup())) { if (!permission.isMember(person)) { throw new DomainException("error.StudentCurricularPlan.cannot.move.is.not.authorized"); } } if (!hasEnrolments(enrolment)) { // if we remove this test, then check if enrolment period is before // registration start throw new DomainException("error.StudentCurricularPlan.doesnot.have.enrolment", enrolment.getName().getContent()); } final Enrolment result = Enrolment.createBasedOn(enrolment, curriculumGroup); enrolment.getProgramCertificateRequests().clear(); enrolment.getCourseLoadRequests().clear(); enrolment.getExamDateCertificateRequests().clear(); enrolment.delete(); if (result.getStudentCurricularPlan() != this) { correctInvalidAttends(result.getStudentCurricularPlan()); } return result; } public boolean isEmptyDegree() { return getDegreeCurricularPlan().isEmpty(); } public boolean hasAnyGratuityEventFor(final ExecutionYear executionYear) { for (final GratuityEvent gratuityEvent : getGratuityEvents()) { if (gratuityEvent.isFor(executionYear)) { return true; } } return false; } public boolean hasAnyGratuitySituationFor(final ExecutionYear executionYear) { for (final GratuitySituation gratuitySituation : getGratuitySituations()) { if (gratuitySituation.getGratuityValues().getExecutionDegree().getExecutionYear() == executionYear) { return true; } } return false; } }