@Override
protected RuleResult executeEnrolmentWithRulesAndTemporaryEnrolment(final ICurricularRule curricularRule,
final IDegreeModuleToEvaluate sourceDegreeModuleToEvaluate, final EnrolmentContext enrolmentContext) {
final DegreeModulesSelectionLimit rule = (DegreeModulesSelectionLimit) curricularRule;
if (!canApplyRule(enrolmentContext, rule)) {
return RuleResult.createNA(sourceDegreeModuleToEvaluate.getDegreeModule());
}
final IDegreeModuleToEvaluate degreeModuleToEvaluate = searchDegreeModuleToEvaluate(enrolmentContext, rule);
if (degreeModuleToEvaluate.isEnroled()) {
final CourseGroup courseGroup = rule.getDegreeModuleToApplyRule();
final EnroledCurriculumModuleWrapper moduleEnroledWrapper = (EnroledCurriculumModuleWrapper) degreeModuleToEvaluate;
final CurriculumGroup curriculumGroup = (CurriculumGroup) moduleEnroledWrapper.getCurriculumModule();
int total = countTotalDegreeModules(enrolmentContext, courseGroup, curriculumGroup);
if (rule.numberOfDegreeModulesExceedMaximum(total)) {
if (sourceDegreeModuleToEvaluate.isEnroled() && sourceDegreeModuleToEvaluate.isLeaf()) {
return createImpossibleRuleResult(rule, sourceDegreeModuleToEvaluate);
} else {
return createFalseRuleResult(rule, sourceDegreeModuleToEvaluate);
}
}
final ExecutionSemester executionSemester = enrolmentContext.getExecutionPeriod();
total += curriculumGroup.getNumberOfChildEnrolments(executionSemester.getPreviousExecutionPeriod());
return rule.numberOfDegreeModulesExceedMaximum(total) ? RuleResult.createTrue(EnrolmentResultType.TEMPORARY,
sourceDegreeModuleToEvaluate.getDegreeModule()) : RuleResult.createTrue(sourceDegreeModuleToEvaluate
.getDegreeModule());
}
// is enrolling now
return RuleResult.createNA(sourceDegreeModuleToEvaluate.getDegreeModule());