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.ExecutionSemester; import net.sourceforge.fenixedu.domain.curricularRules.executors.verifyExecutors.VerifyRuleExecutor; import net.sourceforge.fenixedu.domain.degreeStructure.Context; import net.sourceforge.fenixedu.domain.degreeStructure.CourseGroup; import net.sourceforge.fenixedu.domain.degreeStructure.DegreeModule; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.util.LogicOperator; public class RestrictionBetweenDegreeModules extends RestrictionBetweenDegreeModules_Base { private RestrictionBetweenDegreeModules(final DegreeModule precedenceDegreeModule, final Double minimumCredits) { super(); checkParameters(precedenceDegreeModule, minimumCredits); setPrecedenceDegreeModule(precedenceDegreeModule); setMinimumCredits(minimumCredits); setCurricularRuleType(CurricularRuleType.PRECEDENCY_BETWEEN_DEGREE_MODULES); } private void checkParameters(final DegreeModule precedenceDegreeModule, final Double minimumCredits) throws DomainException { if (precedenceDegreeModule == null || minimumCredits == null) { throw new DomainException("curricular.rule.invalid.parameters"); } } protected RestrictionBetweenDegreeModules(final DegreeModule degreeModuleToApplyRule, final DegreeModule precedenceDegreeModule, final Double minimumCredits, final CourseGroup contextCourseGroup, final ExecutionSemester begin, final ExecutionSemester end) { this(precedenceDegreeModule, minimumCredits); init(degreeModuleToApplyRule, contextCourseGroup, begin, end); } protected void edit(final DegreeModule precedenceDegreeModule, final Double minimumCredits, final CourseGroup contextCourseGroup) { checkParameters(precedenceDegreeModule, minimumCredits); setPrecedenceDegreeModule(precedenceDegreeModule); setMinimumCredits(minimumCredits); setContextCourseGroup(contextCourseGroup); } @Override public List> getLabel() { final List> labelList = new ArrayList>(); if (belongsToCompositeRule() && getParentCompositeRule().getCompositeRuleType().equals(LogicOperator.NOT)) { labelList.add(new GenericPair("label.precedence", true)); } else { labelList.add(new GenericPair("label.precedence", true)); } labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair("label.of", true)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair("label.module", true)); labelList.add(new GenericPair(": ", false)); // getting full name only for course groups String precedenceDegreeModule = (getPrecedenceDegreeModule().isLeaf()) ? getPrecedenceDegreeModule().getName() : getPrecedenceDegreeModule().getOneFullName(); labelList.add(new GenericPair(precedenceDegreeModule, false)); if (getMinimumCredits().doubleValue() != 0.0) { labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair("label.with", true)); labelList.add(new GenericPair(", ", false)); labelList.add(new GenericPair("label.in", true)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair("label.minimum", true)); labelList.add(new GenericPair(", ", false)); labelList.add(new GenericPair(getMinimumCredits(), false)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair("label.credits", true)); } if (getContextCourseGroup() != null) { labelList.add(new GenericPair(", ", false)); labelList.add(new GenericPair("label.inContext", true)); labelList.add(new GenericPair(" ", false)); labelList.add(new GenericPair(getContextCourseGroup().getOneFullName(), false)); } return labelList; } @Override protected boolean appliesToPeriod(final Context context) { return getDegreeModuleToApplyRule().isCourseGroup() || super.appliesToPeriod(context); } public boolean hasMinimumCredits() { return getMinimumCredits() != null && getMinimumCredits().doubleValue() != 0.0; } public boolean allowCredits(final Double credits) { return credits.doubleValue() >= getMinimumCredits().doubleValue(); } public VerifyRuleExecutor createVerifyRuleExecutor() { return VerifyRuleExecutor.NULL_VERIFY_EXECUTOR; } }