*/
@Override
protected RuleResult executeEnrolmentVerificationWithRules(final ICurricularRule curricularRule,
IDegreeModuleToEvaluate sourceDegreeModuleToEvaluate, final EnrolmentContext enrolmentContext) {
final AnyCurricularCourse rule = (AnyCurricularCourse) curricularRule;
if (!rule.appliesToContext(sourceDegreeModuleToEvaluate.getContext())) {
return RuleResult.createNA(sourceDegreeModuleToEvaluate.getDegreeModule());
}
final CurricularCourse curricularCourseToEnrol;
if (sourceDegreeModuleToEvaluate.isEnroling()) {
final OptionalDegreeModuleToEnrol optionalDegreeModuleToEnrol =
(OptionalDegreeModuleToEnrol) sourceDegreeModuleToEvaluate;
curricularCourseToEnrol = optionalDegreeModuleToEnrol.getCurricularCourse();
if (isApproved(enrolmentContext, curricularCourseToEnrol) || isEnroled(enrolmentContext, curricularCourseToEnrol)
|| isApproved(enrolmentContext, optionalDegreeModuleToEnrol.getCurricularCourse())
|| isEnroled(enrolmentContext, optionalDegreeModuleToEnrol.getCurricularCourse())) {
return RuleResult.createFalse(sourceDegreeModuleToEvaluate.getDegreeModule(),
"curricularRules.ruleExecutors.AnyCurricularCourseExecutor.already.approved.or.enroled",
curricularCourseToEnrol.getName(), rule.getDegreeModuleToApplyRule().getName());
}
} else if (sourceDegreeModuleToEvaluate.isEnroled()) {
curricularCourseToEnrol =
(CurricularCourse) ((EnroledOptionalEnrolment) sourceDegreeModuleToEvaluate).getCurriculumModule()
.getDegreeModule();
} else {
throw new DomainException(
"error.curricularRules.executors.ruleExecutors.AnyCurricularCourseExecutor.unexpected.degree.module.to.evaluate");
}
final ExecutionSemester executionSemester = enrolmentContext.getExecutionPeriod();
final Degree degree = curricularCourseToEnrol.getDegree();
boolean result = true;
result &=
rule.hasMinimumCredits() ? rule.getMinimumCredits() <= curricularCourseToEnrol.getEctsCredits(executionSemester) : true;
result &=
rule.hasMaximumCredits() ? rule.getMaximumCredits() >= curricularCourseToEnrol.getEctsCredits(executionSemester) : true;
result &=
rule.getDegree() != null ? rule.getDegree() == degree : rule.hasBolonhaDegreeType() ? degree.getDegreeType() == rule
.getBolonhaDegreeType() : true;
if (rule.getDepartmentUnit() != null) {
final DepartmentUnit departmentUnit =
curricularCourseToEnrol.getCompetenceCourse().getDepartmentUnit(executionSemester);
result &= departmentUnit != null && departmentUnit.equals(rule.getDepartmentUnit());
}
if (result) {
return RuleResult.createTrue(sourceDegreeModuleToEvaluate.getDegreeModule());
} else {