/* * Created on Feb 17, 2006 */ package net.sourceforge.fenixedu.domain.curricularRules; import java.util.ArrayList; import java.util.List; import net.sourceforge.fenixedu.dataTransferObject.GenericPair; import net.sourceforge.fenixedu.domain.Degree; import net.sourceforge.fenixedu.domain.ExecutionSemester; import net.sourceforge.fenixedu.domain.curricularRules.executors.verifyExecutors.VerifyRuleExecutor; import net.sourceforge.fenixedu.domain.degree.DegreeType; import net.sourceforge.fenixedu.domain.degreeStructure.Context; import net.sourceforge.fenixedu.domain.degreeStructure.CourseGroup; import net.sourceforge.fenixedu.domain.degreeStructure.OptionalCurricularCourse; import net.sourceforge.fenixedu.domain.degreeStructure.RegimeType; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.organizationalStructure.DepartmentUnit; import net.sourceforge.fenixedu.domain.time.calendarStructure.AcademicPeriod; public class AnyCurricularCourse extends AnyCurricularCourse_Base { protected AnyCurricularCourse(final OptionalCurricularCourse toApplyRule, final CourseGroup contextCourseGroup, final ExecutionSemester begin, final ExecutionSemester end, final Double credits, final Integer curricularPeriodOrder, final Integer minimumYear, final Integer maximumYear, final DegreeType degreeType, final Degree degree, final DepartmentUnit departmentUnit) { super(); // TODO: check if already has this rule in toApplyRule init(toApplyRule, contextCourseGroup, begin, end, CurricularRuleType.ANY_CURRICULAR_COURSE); checkYears(minimumYear, maximumYear); setCredits(credits); setCurricularPeriodOrder(curricularPeriodOrder); setMinimumYear(minimumYear); setMaximumYear(maximumYear); setBolonhaDegreeType(degreeType); setDegree(degree); setDepartmentUnit(departmentUnit); } protected void edit(final CourseGroup contextCourseGroup, final Double credits, final Integer curricularPeriodOrder, final Integer minimumYear, final Integer maximumYear, final DegreeType degreeType, final Degree degree, final DepartmentUnit departmentUnit) { checkYears(minimumYear, maximumYear); setContextCourseGroup(contextCourseGroup); setCredits(credits); setCurricularPeriodOrder(curricularPeriodOrder); setMinimumYear(minimumYear); setMaximumYear(maximumYear); setBolonhaDegreeType(degreeType); setDegree(degree); setDepartmentUnit(departmentUnit); } private void checkYears(Integer minimumYear, Integer maximumYear) throws DomainException { if (minimumYear != null && maximumYear != null && minimumYear.intValue() > maximumYear.intValue()) { throw new DomainException("error.minimum.greater.than.maximum"); } } @Override public OptionalCurricularCourse getDegreeModuleToApplyRule() { return (OptionalCurricularCourse) super.getDegreeModuleToApplyRule(); } @Override public boolean appliesToContext(final Context context) { return super.appliesToContext(context) && appliesToPeriod(context) && appliesToYears(context); } private boolean appliesToPeriod(final Context context) { return !hasCurricularPeriodOrder() || hasCurricularPeriodOrderFor(context); } private boolean hasCurricularPeriodOrderFor(final Context context) { return context.containsSemester(getCurricularPeriodOrder()) && context.getCurricularPeriod().getAcademicPeriod().equals(AcademicPeriod.SEMESTER); } private boolean hasCurricularPeriodOrder() { return getCurricularPeriodOrder() != null && getCurricularPeriodOrder().intValue() != 0; } private boolean hasYearsLimit() { return getMinimumYear() != null && getMinimumYear().intValue() != 0 && getMaximumYear() != null && getMaximumYear().intValue() != 0; } private boolean appliesToYears(final Context context) { if (!hasYearsLimit()) { return true; } if (hasCurricularPeriodOrder()) { for (int year = getMinimumYear().intValue(); year <= getMaximumYear().intValue(); year++) { if (context.containsSemesterAndCurricularYear(getCurricularPeriodOrder(), Integer.valueOf(year), RegimeType.SEMESTRIAL)) { return true; } } } else { for (int year = getMinimumYear().intValue(); year <= getMaximumYear().intValue(); year++) { if (context.containsSemesterAndCurricularYear(Integer.valueOf(1), Integer.valueOf(year), RegimeType.SEMESTRIAL) || context.containsSemesterAndCurricularYear(Integer.valueOf(2), Integer.valueOf(year), RegimeType.SEMESTRIAL)) { return true; } } } return false; } @Override public List> getLabel() { final List> labelList = new ArrayList>(); labelList.add(new GenericPair("label.anyCurricularCourse", true)); if (getCredits() != null) { labelList.add(new GenericPair(", ", false)); labelList.add(new GenericPair("label.with", true)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair(getCredits(), false)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair("label.credits", true)); } if (getCurricularPeriodOrder().intValue() != 0) { labelList.add(new GenericPair(", ", false)); labelList.add(new GenericPair("label.in", true)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair(getCurricularPeriodOrder(), false)); labelList.add(new GenericPair("º ", false)); labelList.add(new GenericPair("SEMESTER", true)); } if (hasYearsLimit()) { if (getMinimumYear().compareTo(getMaximumYear()) == 0) { labelList.add(new GenericPair(", ", false)); labelList.add(new GenericPair("label.of", true)); labelList.add(new GenericPair("º ", false)); labelList.add(new GenericPair(getMinimumYear(), false)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair("label.year", true)); } else { labelList.add(new GenericPair(", ", false)); labelList.add(new GenericPair("label.of", true)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair(getMinimumYear(), false)); labelList.add(new GenericPair("º ", false)); labelList.add(new GenericPair("label.to1", true)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair(getMaximumYear(), false)); labelList.add(new GenericPair("º ", false)); labelList.add(new GenericPair("label.year", true)); } } labelList.add(new GenericPair(", ", false)); if (getDegree() == null) { if (!hasBolonhaDegreeType()) { labelList.add(new GenericPair("label.of", true)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair("institution.name.abbreviation", true)); } else { labelList.add(new GenericPair("label.of1", true)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair(getBolonhaDegreeType().name(), true)); } } else { labelList.add(new GenericPair("label.of", true)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair("label.degree", true)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair(getDegree().getNome(), false)); } if (getDepartmentUnit() != null) { labelList.add(new GenericPair(", ", false)); labelList.add(new GenericPair("label.of", true)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair(getDepartmentUnit().getName(), false)); } if (getContextCourseGroup() != null) { labelList.add(new GenericPair(", ", false)); labelList.add(new GenericPair("label.inGroup", true)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair(getContextCourseGroup().getOneFullName(), false)); } return labelList; } @Override protected void removeOwnParameters() { removeDegree(); removeDepartmentUnit(); } public boolean hasBolonhaDegreeType() { return getBolonhaDegreeType() != null; } public boolean hasCredits() { return getCredits() != null && getCredits().doubleValue() != 0d; } public VerifyRuleExecutor createVerifyRuleExecutor() { return VerifyRuleExecutor.NULL_VERIFY_EXECUTOR; } }