return enrolStudent(mapping, request, process, bean);
}
public ActionForward doEnrol(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws FenixServiceException {
ErasmusBolonhaStudentEnrollmentBean erasmusBolonhaStudentEnrollmentBean =
(ErasmusBolonhaStudentEnrollmentBean) getRenderedObject();
try {
final RuleResult ruleResults =
EnrolBolonhaStudent.run(erasmusBolonhaStudentEnrollmentBean.getStudentCurricularPlan(),
erasmusBolonhaStudentEnrollmentBean.getExecutionPeriod(),
erasmusBolonhaStudentEnrollmentBean.getDegreeModulesToEvaluate(),
erasmusBolonhaStudentEnrollmentBean.getCurriculumModulesToRemove(),
erasmusBolonhaStudentEnrollmentBean.getCurricularRuleLevel());
if (!erasmusBolonhaStudentEnrollmentBean.getDegreeModulesToEvaluate().isEmpty()
|| !erasmusBolonhaStudentEnrollmentBean.getCurriculumModulesToRemove().isEmpty()) {
addActionMessage("success", request, "label.save.success");
}
if (ruleResults.isWarning()) {
addRuleResultMessagesToActionMessages("warning", request, ruleResults);
}
} catch (EnrollmentDomainException ex) {
addRuleResultMessagesToActionMessages("error", request, ex.getFalseResult());
return enrolStudent(mapping, form, request, response);
} catch (DomainException ex) {
addActionMessage("error", request, ex.getKey(), ex.getArgs());
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);
}
}
MobilityIndividualApplicationProcess process = getProcess(request);
MobilityIndividualApplication candidacy = process.getCandidacy();
ErasmusBolonhaStudentEnrollmentBean bean =
new ErasmusBolonhaStudentEnrollmentBean(candidacy.getRegistration().getActiveStudentCurricularPlan(),
erasmusBolonhaStudentEnrollmentBean.getExecutionPeriod(), null, CurricularRuleLevel.ENROLMENT_NO_RULES,
candidacy);
RenderUtils.invalidateViewState();
return enrolStudent(mapping, request, getProcess(request), bean);
}