return enrolStudent(mapping, form, request, response);
}
StudentCurricularPlan studentCurricularPlan = erasmusBolonhaStudentEnrollmentBean.getStudentCurricularPlan();
ExecutionSemester executionSemester = erasmusBolonhaStudentEnrollmentBean.getExecutionPeriod();
NoCourseGroupCurriculumGroup group =
studentCurricularPlan.getNoCourseGroupCurriculumGroup(NoCourseGroupCurriculumGroupType.STANDALONE);
Set<CurricularCourse> remaining = new HashSet<CurricularCourse>();
HashSet<CurricularCourse> set = new HashSet<CurricularCourse>();
set.addAll(erasmusBolonhaStudentEnrollmentBean.getCandidacy().getCurricularCoursesSet());
for (Enrolment enrolment : group.getEnrolments()) {
set.add(enrolment.getCurricularCourse());
}
remaining.addAll(set);
for (ErasmusExtraCurricularEnrolmentBean bean : erasmusBolonhaStudentEnrollmentBean.getExtraCurricularEnrolments()) {
remaining.remove(bean.getCurricularCourse());
if (group.hasEnrolmentWithEnroledState(bean.getCurricularCourse(),
erasmusBolonhaStudentEnrollmentBean.getExecutionPeriod())) {
continue;
}
MobilityExtraEnrolmentBean mobilityExtraEnrolmentBean =
new MobilityExtraEnrolmentBean(studentCurricularPlan, executionSemester);
mobilityExtraEnrolmentBean.setCurriculumGroup(studentCurricularPlan
.getNoCourseGroupCurriculumGroup(NoCourseGroupCurriculumGroupType.STANDALONE));
mobilityExtraEnrolmentBean.setDegree(bean.getCurricularCourse().getDegree());
mobilityExtraEnrolmentBean.setDegreeType(bean.getCurricularCourse().getDegree().getDegreeType());
mobilityExtraEnrolmentBean.setDegreeCurricularPlan(bean.getCurricularCourse().getDegreeCurricularPlan());
mobilityExtraEnrolmentBean.setSelectedCurricularCourse(bean.getCurricularCourse());
mobilityExtraEnrolmentBean.setCurricularRuleLevel(CurricularRuleLevel.EXTRA_ENROLMENT);
try {
final RuleResult ruleResult = CreateExtraEnrolment.run(mobilityExtraEnrolmentBean);
if (ruleResult.isWarning()) {
addRuleResultMessagesToActionMessages("warning", request, ruleResult);
}
} catch (final IllegalDataAccessException e) {
addActionMessage("error", request, "error.notAuthorized");
return enrolStudent(mapping, form, request, response);
} catch (final EnrollmentDomainException ex) {
addRuleResultMessagesToActionMessages("enrolmentError", request, ex.getFalseResult());
return enrolStudent(mapping, form, request, response);
} catch (final DomainException e) {
addActionMessage("error", request, e.getMessage(), e.getArgs());
return enrolStudent(mapping, form, request, response);
}
}
// After adding all that I want to add, the ones that I've not added
// that were enrolled are to be removed.
for (Enrolment enrolment : group.getEnrolmentsBy(executionSemester)) {
if (remaining.contains(enrolment.getCurricularCourse())) {
studentCurricularPlan.removeCurriculumModulesFromNoCourseGroupCurriculumGroup(
Collections.<CurriculumModule> singletonList(enrolment), executionSemester,
NoCourseGroupCurriculumGroupType.STANDALONE);
}