| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.enrollment.class2.registration.controller; |
| 17 | |
|
| 18 | |
import org.apache.commons.collections.CollectionUtils; |
| 19 | |
import org.apache.commons.lang.StringUtils; |
| 20 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
| 21 | |
import org.kuali.rice.core.api.util.RiceKeyConstants; |
| 22 | |
import org.kuali.rice.krad.uif.UifParameters; |
| 23 | |
import org.kuali.rice.krad.uif.util.ObjectPropertyUtils; |
| 24 | |
import org.kuali.rice.krad.util.GlobalVariables; |
| 25 | |
import org.kuali.rice.krad.util.KRADConstants; |
| 26 | |
import org.kuali.rice.krad.web.controller.UifControllerBase; |
| 27 | |
import org.kuali.rice.krad.web.form.UifFormBase; |
| 28 | |
import org.kuali.student.core.statement.dto.StatementTreeViewInfo; |
| 29 | |
import org.kuali.student.core.statement.service.StatementService; |
| 30 | |
import org.kuali.student.enrollment.class2.registration.dto.ActivityOfferingWrapper; |
| 31 | |
import org.kuali.student.enrollment.class2.registration.dto.CourseOfferingWrapper; |
| 32 | |
import org.kuali.student.enrollment.class2.registration.dto.MeetingScheduleWrapper; |
| 33 | |
import org.kuali.student.enrollment.class2.registration.dto.RegistrationGroupWrapper; |
| 34 | |
import org.kuali.student.enrollment.class2.registration.form.RegistrationForm; |
| 35 | |
import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo; |
| 36 | |
import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo; |
| 37 | |
import org.kuali.student.enrollment.courseoffering.dto.RegistrationGroupInfo; |
| 38 | |
import org.kuali.student.enrollment.courseoffering.infc.RegistrationGroup; |
| 39 | |
import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService; |
| 40 | |
import org.kuali.student.enrollment.courseregistration.dto.CourseRegistrationInfo; |
| 41 | |
import org.kuali.student.enrollment.courseregistration.dto.RegRequestInfo; |
| 42 | |
import org.kuali.student.enrollment.courseregistration.dto.RegRequestItemInfo; |
| 43 | |
import org.kuali.student.enrollment.courseregistration.dto.RegResponseInfo; |
| 44 | |
import org.kuali.student.enrollment.courseregistration.infc.RegRequest; |
| 45 | |
import org.kuali.student.enrollment.courseregistration.infc.RegRequestItem; |
| 46 | |
import org.kuali.student.enrollment.courseregistration.service.CourseRegistrationService; |
| 47 | |
import org.kuali.student.lum.course.service.CourseService; |
| 48 | |
import org.kuali.student.lum.course.service.CourseServiceConstants; |
| 49 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
| 50 | |
import org.kuali.student.r2.common.dto.MeetingScheduleInfo; |
| 51 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
| 52 | |
import org.kuali.student.r2.common.exceptions.*; |
| 53 | |
import org.kuali.student.r2.common.infc.Context; |
| 54 | |
import org.kuali.student.r2.common.util.constants.LuiPersonRelationServiceConstants; |
| 55 | |
import org.springframework.stereotype.Controller; |
| 56 | |
import org.springframework.validation.BindingResult; |
| 57 | |
import org.springframework.web.bind.annotation.ModelAttribute; |
| 58 | |
import org.springframework.web.bind.annotation.RequestMapping; |
| 59 | |
import org.springframework.web.bind.annotation.RequestMethod; |
| 60 | |
import org.springframework.web.servlet.ModelAndView; |
| 61 | |
|
| 62 | |
import javax.servlet.http.HttpServletRequest; |
| 63 | |
import javax.servlet.http.HttpServletResponse; |
| 64 | |
import javax.xml.namespace.QName; |
| 65 | |
import java.util.ArrayList; |
| 66 | |
import java.util.Collection; |
| 67 | |
import java.util.Iterator; |
| 68 | |
import java.util.List; |
| 69 | |
|
| 70 | |
@Controller |
| 71 | |
@RequestMapping(value = "/registration") |
| 72 | 0 | public class RegistrationController extends UifControllerBase { |
| 73 | |
|
| 74 | |
private transient CourseOfferingService courseOfferingService; |
| 75 | |
private transient StatementService statementService; |
| 76 | |
private transient CourseService courseService; |
| 77 | |
private transient CourseRegistrationService courseRegistrationService; |
| 78 | |
|
| 79 | |
protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) { |
| 80 | 0 | return new RegistrationForm(); |
| 81 | |
} |
| 82 | |
|
| 83 | |
protected RegRequestInfo generateNewRegRequestInfo(ContextInfo context, RegistrationForm regForm){ |
| 84 | 0 | String id = context.getPrincipalId(); |
| 85 | 0 | RegRequestInfo info = new RegRequestInfo(); |
| 86 | 0 | info.setTermId(regForm.getTermId()); |
| 87 | 0 | info.setStateKey(LuiPersonRelationServiceConstants.LPRTRANS_ITEM_NEW_STATE_KEY); |
| 88 | 0 | info.setTypeKey(LuiPersonRelationServiceConstants.LPRTRANS_REGISTER_TYPE_KEY); |
| 89 | 0 | info.setRequestorId(id); |
| 90 | 0 | info.setRegRequestItems(new ArrayList<RegRequestItemInfo>()); |
| 91 | 0 | return info; |
| 92 | |
} |
| 93 | |
|
| 94 | |
protected RegRequestItemInfo generateRegRequestItem(RegistrationGroupWrapper regGroupWrapper, Context context){ |
| 95 | 0 | RegRequestItemInfo regRequestItem = new RegRequestItemInfo(); |
| 96 | 0 | regRequestItem.setTypeKey(LuiPersonRelationServiceConstants.LPRTRANS_ITEM_ADD_TYPE_KEY); |
| 97 | 0 | regRequestItem.setStateKey(LuiPersonRelationServiceConstants.LPRTRANS_ITEM_NEW_STATE_KEY); |
| 98 | 0 | regRequestItem.setStudentId(context.getPrincipalId()); |
| 99 | 0 | regRequestItem.setNewRegGroupId(regGroupWrapper.getRegistrationGroup().getId()); |
| 100 | 0 | regRequestItem.setCreditOptionKey("kuali.credit.option.RVG1"); |
| 101 | 0 | regRequestItem.setGradingOptionKey("kuali.grading.option.RVG1"); |
| 102 | 0 | regRequestItem.setName(regGroupWrapper.getRegistrationGroup().getName()); |
| 103 | 0 | regRequestItem.setOkToHoldList(false); |
| 104 | 0 | regRequestItem.setOkToWaitlist(regGroupWrapper.getRegistrationGroup().getHasWaitlist()); |
| 105 | 0 | return regRequestItem; |
| 106 | |
} |
| 107 | |
|
| 108 | |
protected RegRequestItemInfo generateDropRegRequestItem(RegistrationGroupWrapper regGroupWrapper, Context context){ |
| 109 | 0 | RegRequestItemInfo regRequestItem = new RegRequestItemInfo(); |
| 110 | 0 | regRequestItem.setTypeKey(LuiPersonRelationServiceConstants.LPRTRANS_ITEM_DROP_TYPE_KEY); |
| 111 | 0 | regRequestItem.setStateKey(LuiPersonRelationServiceConstants.LPRTRANS_ITEM_NEW_STATE_KEY); |
| 112 | 0 | regRequestItem.setStudentId(context.getPrincipalId()); |
| 113 | 0 | regRequestItem.setExistingRegGroupId(regGroupWrapper.getRegistrationGroup().getId()); |
| 114 | 0 | regRequestItem.setCreditOptionKey("kuali.credit.option.RVG1"); |
| 115 | 0 | regRequestItem.setGradingOptionKey("kuali.grading.option.RVG1"); |
| 116 | 0 | regRequestItem.setName(regGroupWrapper.getRegistrationGroup().getName()); |
| 117 | 0 | regRequestItem.setOkToHoldList(false); |
| 118 | 0 | regRequestItem.setOkToWaitlist(regGroupWrapper.getRegistrationGroup().getHasWaitlist()); |
| 119 | 0 | return regRequestItem; |
| 120 | |
} |
| 121 | |
|
| 122 | |
protected RegistrationGroupWrapper findRegGroupByIndex(RegistrationForm registrationForm){ |
| 123 | |
|
| 124 | 0 | String selectedCollectionPath = registrationForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH); |
| 125 | 0 | if (StringUtils.isBlank(selectedCollectionPath)) { |
| 126 | 0 | throw new RuntimeException("Selected collection was not set for registration line action, cannot register line"); |
| 127 | |
} |
| 128 | |
|
| 129 | 0 | int selectedLineIndex = -1; |
| 130 | 0 | String selectedLine = registrationForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); |
| 131 | 0 | if (StringUtils.isNotBlank(selectedLine)) { |
| 132 | 0 | selectedLineIndex = Integer.parseInt(selectedLine); |
| 133 | |
} |
| 134 | |
|
| 135 | 0 | if (selectedLineIndex == -1) { |
| 136 | 0 | throw new RuntimeException("Selected line index was not set for registration line action, cannot register line"); |
| 137 | |
} |
| 138 | |
|
| 139 | |
|
| 140 | 0 | Collection<Object> collection = ObjectPropertyUtils.getPropertyValue(registrationForm, selectedCollectionPath); |
| 141 | 0 | if (collection == null) { |
| 142 | 0 | throw new RuntimeException("Unable to get registration group collection property from RegistrationForm for path: " + selectedCollectionPath); |
| 143 | |
} |
| 144 | |
|
| 145 | 0 | if (collection instanceof List) { |
| 146 | 0 | return (RegistrationGroupWrapper) ((List<Object>) collection).get(selectedLineIndex); |
| 147 | |
} |
| 148 | |
else { |
| 149 | 0 | throw new RuntimeException("Only List collection implementations are supported for findRegGroup by index method"); |
| 150 | |
} |
| 151 | |
} |
| 152 | |
|
| 153 | |
protected List<CourseRegistrationInfo> getCourseRegistrations(String studentId, String termKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, DisabledIdentifierException, DoesNotExistException, PermissionDeniedException, OperationFailedException { |
| 154 | 0 | if (getCourseRegistrationService() != null) { |
| 155 | 0 | return getCourseRegistrationService().getCourseRegistrationsForStudentByTerm(studentId, termKey, context); |
| 156 | |
} |
| 157 | 0 | return new ArrayList<CourseRegistrationInfo>(); } |
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
@RequestMapping(method = RequestMethod.POST, params = "methodToCall=showRegistration") |
| 166 | |
public ModelAndView showRegistration(@ModelAttribute("KualiForm") UifFormBase formBase, BindingResult result, |
| 167 | |
HttpServletRequest request, HttpServletResponse response) { |
| 168 | 0 | ContextInfo context = new ContextInfo(); |
| 169 | 0 | RegistrationForm regForm = (RegistrationForm) formBase; |
| 170 | |
try { |
| 171 | 0 | regForm.setCourseRegistrations(getCourseRegistrations(context.getPrincipalId(), regForm.getTermId(), context)); |
| 172 | |
|
| 173 | |
|
| 174 | 0 | List<String> states = new ArrayList<String>(); |
| 175 | 0 | states.add(LuiPersonRelationServiceConstants.LPRTRANS_NEW_STATE_KEY); |
| 176 | 0 | List<RegRequestInfo> regRequestInfos = getCourseRegistrationService().getRegRequestsForStudentByTerm(context.getPrincipalId(), regForm.getTermId(), states, context); |
| 177 | 0 | RegRequestInfo regRequest = null; |
| 178 | 0 | if(regRequestInfos != null){ |
| 179 | 0 | for(RegRequestInfo info: regRequestInfos){ |
| 180 | 0 | if(regRequest != null && regRequest.getMeta().getCreateTime().before(info.getMeta().getCreateTime())){ |
| 181 | 0 | regRequest = info; |
| 182 | |
} |
| 183 | 0 | else if(regRequest == null){ |
| 184 | 0 | regRequest = info; |
| 185 | |
} |
| 186 | |
} |
| 187 | |
} |
| 188 | |
|
| 189 | 0 | regForm.setRegRequest(regRequest); |
| 190 | 0 | if(regRequest != null && regRequest.getRegRequestItems() != null){ |
| 191 | 0 | for(RegRequestItemInfo item: regRequest.getRegRequestItems()){ |
| 192 | 0 | if(StringUtils.isNotBlank(item.getNewRegGroupId())){ |
| 193 | 0 | RegistrationGroupInfo regGroup = getCourseOfferingService().getRegistrationGroup(item.getNewRegGroupId(), context); |
| 194 | 0 | CourseOfferingInfo courseOffering = getCourseOfferingService().getCourseOffering(regGroup.getCourseOfferingId(), context); |
| 195 | 0 | RegistrationGroupWrapper registrationGroupWrapper = new RegistrationGroupWrapper(); |
| 196 | 0 | registrationGroupWrapper.setRegistrationGroup(regGroup); |
| 197 | 0 | registrationGroupWrapper.setCourseOffering(courseOffering); |
| 198 | 0 | registrationGroupWrapper.setActivityOfferingWrappers(getActivityOfferingInfos(regGroup, courseOffering, context)); |
| 199 | 0 | regForm.getRegistrationGroupWrappersById().put(registrationGroupWrapper.getRegistrationGroup().getId(), registrationGroupWrapper); |
| 200 | |
} |
| 201 | 0 | if(StringUtils.isNotBlank(item.getExistingRegGroupId())){ |
| 202 | 0 | RegistrationGroupInfo regGroup = getCourseOfferingService().getRegistrationGroup(item.getExistingRegGroupId(), context); |
| 203 | 0 | CourseOfferingInfo courseOffering = getCourseOfferingService().getCourseOffering(regGroup.getCourseOfferingId(), context); |
| 204 | 0 | RegistrationGroupWrapper registrationGroupWrapper = new RegistrationGroupWrapper(); |
| 205 | 0 | registrationGroupWrapper.setRegistrationGroup(regGroup); |
| 206 | 0 | registrationGroupWrapper.setCourseOffering(courseOffering); |
| 207 | 0 | registrationGroupWrapper.setActivityOfferingWrappers(getActivityOfferingInfos(regGroup, courseOffering, context)); |
| 208 | 0 | regForm.getRegistrationGroupWrappersById().put(registrationGroupWrapper.getRegistrationGroup().getId(), registrationGroupWrapper); |
| 209 | 0 | } |
| 210 | |
} |
| 211 | |
} |
| 212 | |
|
| 213 | |
|
| 214 | 0 | return getUIFModelAndView(regForm, "registrationPage"); |
| 215 | 0 | } catch (InvalidParameterException e) { |
| 216 | 0 | throw new RuntimeException(e); |
| 217 | 0 | } catch (MissingParameterException e) { |
| 218 | 0 | throw new RuntimeException(e); |
| 219 | 0 | } catch (OperationFailedException e) { |
| 220 | 0 | throw new RuntimeException(e); |
| 221 | 0 | } catch (PermissionDeniedException e) { |
| 222 | 0 | throw new RuntimeException(e); |
| 223 | 0 | } catch (DisabledIdentifierException e) { |
| 224 | 0 | throw new RuntimeException(e); |
| 225 | 0 | } catch (DoesNotExistException e) { |
| 226 | 0 | throw new RuntimeException(e); |
| 227 | |
} |
| 228 | |
} |
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
@RequestMapping(params = "methodToCall=searchCourseOfferings") |
| 234 | |
public ModelAndView searchCourseOfferings(@ModelAttribute("KualiForm") RegistrationForm registrationForm, BindingResult result, |
| 235 | |
HttpServletRequest request, HttpServletResponse response) { |
| 236 | 0 | ContextInfo context = new ContextInfo(); |
| 237 | |
|
| 238 | |
try { |
| 239 | 0 | List<String> courseOfferingIds = getCourseOfferingIds(registrationForm, context); |
| 240 | 0 | registrationForm.setCourseOfferingWrappers(new ArrayList<CourseOfferingWrapper>(courseOfferingIds.size())); |
| 241 | |
|
| 242 | 0 | for (String coId : courseOfferingIds) { |
| 243 | 0 | CourseOfferingWrapper courseOfferingWrapper = new CourseOfferingWrapper(); |
| 244 | 0 | String prereq = "none"; |
| 245 | 0 | courseOfferingWrapper.setCourseOffering(getCourseOfferingService().getCourseOffering(coId, context)); |
| 246 | |
|
| 247 | 0 | List<StatementTreeViewInfo> statements = getCourseService().getCourseStatements(courseOfferingWrapper.getCourseOffering().getCourseId(),"KUALI.RULE", "en"); |
| 248 | 0 | if(statements != null && !statements.isEmpty()){ |
| 249 | 0 | for(StatementTreeViewInfo statement: statements){ |
| 250 | 0 | if(statement.getType().equals("kuali.statement.type.course.academicReadiness.studentEligibilityPrereq")){ |
| 251 | 0 | prereq = getStatementService().getNaturalLanguageForStatement(statement.getId(),"KUALI.RULE","en"); |
| 252 | 0 | break; |
| 253 | |
} |
| 254 | |
} |
| 255 | |
} |
| 256 | 0 | courseOfferingWrapper.setPrereq(prereq); |
| 257 | 0 | List<RegistrationGroupInfo> regGroups = getRegistrationGroupInfos(coId, context); |
| 258 | |
|
| 259 | 0 | List<RegistrationGroupWrapper> registrationGroupWrappers = new ArrayList<RegistrationGroupWrapper>(regGroups.size()); |
| 260 | 0 | for (RegistrationGroupInfo regGroup : regGroups) { |
| 261 | 0 | RegistrationGroupWrapper registrationGroupWrapper = new RegistrationGroupWrapper(); |
| 262 | 0 | registrationGroupWrapper.setRegistrationGroup(regGroup); |
| 263 | 0 | registrationGroupWrapper.setCourseOffering(courseOfferingWrapper.getCourseOffering()); |
| 264 | 0 | registrationGroupWrapper.setActivityOfferingWrappers(getActivityOfferingInfos(regGroup, courseOfferingWrapper.getCourseOffering(), context)); |
| 265 | 0 | registrationGroupWrappers.add(registrationGroupWrapper); |
| 266 | 0 | } |
| 267 | 0 | courseOfferingWrapper.setRegistrationGroupWrappers(registrationGroupWrappers); |
| 268 | 0 | registrationForm.getCourseOfferingWrappers().add(courseOfferingWrapper); |
| 269 | 0 | } |
| 270 | |
|
| 271 | 0 | } catch (DoesNotExistException e) { |
| 272 | 0 | throw new RuntimeException(e); |
| 273 | 0 | } catch (InvalidParameterException e) { |
| 274 | 0 | throw new RuntimeException(e); |
| 275 | 0 | } catch (MissingParameterException e) { |
| 276 | 0 | throw new RuntimeException(e); |
| 277 | 0 | } catch (OperationFailedException e) { |
| 278 | 0 | throw new RuntimeException(e); |
| 279 | 0 | } catch (PermissionDeniedException e) { |
| 280 | 0 | throw new RuntimeException(e); |
| 281 | 0 | } catch (Exception e) { |
| 282 | 0 | throw new RuntimeException(e); |
| 283 | 0 | } |
| 284 | 0 | return getUIFModelAndView(registrationForm); |
| 285 | |
} |
| 286 | |
|
| 287 | |
protected List<String> getCourseOfferingIds(RegistrationForm registrationForm, ContextInfo context) throws InvalidParameterException, MissingParameterException, DoesNotExistException, PermissionDeniedException, OperationFailedException { |
| 288 | |
|
| 289 | 0 | if (StringUtils.isNotBlank(registrationForm.getCourseOfferingCode())) { |
| 290 | 0 | GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, "Searching by Course Offering Code is not yet implemented"); |
| 291 | 0 | return new ArrayList<String>(); |
| 292 | |
} else { |
| 293 | 0 | return getCourseOfferingService().getCourseOfferingIdsByTermAndSubjectArea(registrationForm.getTermId(), registrationForm.getSubjectArea(), context); |
| 294 | |
} |
| 295 | |
} |
| 296 | |
|
| 297 | |
protected List<RegistrationGroupInfo> getRegistrationGroupInfos(String coId, ContextInfo context) throws InvalidParameterException, MissingParameterException, DoesNotExistException, PermissionDeniedException, OperationFailedException { |
| 298 | 0 | return getCourseOfferingService().getRegistrationGroupsForCourseOffering(coId, context); |
| 299 | |
} |
| 300 | |
|
| 301 | |
protected List<ActivityOfferingWrapper> getActivityOfferingInfos(RegistrationGroup regGroup, CourseOfferingInfo courseOfferingInfo, ContextInfo context) throws InvalidParameterException, MissingParameterException, DoesNotExistException, PermissionDeniedException, OperationFailedException { |
| 302 | |
|
| 303 | |
|
| 304 | 0 | List<ActivityOfferingWrapper> activityOfferingWrappers = new ArrayList<ActivityOfferingWrapper>(regGroup.getActivityOfferingIds().size()); |
| 305 | 0 | for (String activityId : regGroup.getActivityOfferingIds()) { |
| 306 | 0 | ActivityOfferingInfo activityOfferingInfo = getCourseOfferingService().getActivityOffering(activityId, context); |
| 307 | 0 | ActivityOfferingWrapper wrapper = new ActivityOfferingWrapper(); |
| 308 | 0 | wrapper.setActivityOffering(activityOfferingInfo); |
| 309 | 0 | wrapper.setMeetingScheduleWrappers(setupMeetingScheduleInfos(courseOfferingInfo, activityOfferingInfo)); |
| 310 | 0 | activityOfferingWrappers.add(wrapper); |
| 311 | 0 | } |
| 312 | |
|
| 313 | |
|
| 314 | 0 | StringBuilder builder = new StringBuilder(); |
| 315 | 0 | for (ActivityOfferingWrapper a : activityOfferingWrappers) { |
| 316 | 0 | for (MeetingScheduleWrapper m : a.getMeetingScheduleWrappers()) { |
| 317 | 0 | if (StringUtils.isNotBlank(builder.toString())) { |
| 318 | 0 | builder.append(","); |
| 319 | |
} |
| 320 | 0 | builder.append(m.getJsScheduleObject()); |
| 321 | |
} |
| 322 | |
} |
| 323 | 0 | String times = "[" + builder.toString() + "]"; |
| 324 | 0 | for (ActivityOfferingWrapper a : activityOfferingWrappers) { |
| 325 | 0 | for (MeetingScheduleWrapper m : a.getMeetingScheduleWrappers()) { |
| 326 | 0 | m.setRegGroupTimesJsObject(times); |
| 327 | |
} |
| 328 | |
} |
| 329 | 0 | return activityOfferingWrappers; |
| 330 | |
} |
| 331 | |
|
| 332 | |
protected List<MeetingScheduleWrapper> setupMeetingScheduleInfos(CourseOfferingInfo courseOfferingInfo, ActivityOfferingInfo activityOfferingInfo) { |
| 333 | 0 | List<MeetingScheduleWrapper> wrappers = new ArrayList<MeetingScheduleWrapper>(); |
| 334 | |
|
| 335 | 0 | List<MeetingScheduleInfo> list = new ArrayList<MeetingScheduleInfo> (); |
| 336 | 0 | for (MeetingScheduleInfo meetingScheduleInfo : list) { |
| 337 | 0 | MeetingScheduleWrapper wrapper = new MeetingScheduleWrapper(meetingScheduleInfo); |
| 338 | 0 | wrapper.setCourseTitle(courseOfferingInfo.getCourseOfferingTitle()); |
| 339 | 0 | wrapper.setCourseOfferingCode(courseOfferingInfo.getCourseOfferingCode()); |
| 340 | 0 | wrappers.add(wrapper); |
| 341 | 0 | } |
| 342 | 0 | return wrappers; |
| 343 | |
} |
| 344 | |
|
| 345 | |
@RequestMapping(params = "methodToCall=dropClass") |
| 346 | |
public ModelAndView dropClass(@ModelAttribute("KualiForm") RegistrationForm registrationForm, BindingResult result, |
| 347 | |
HttpServletRequest request, HttpServletResponse response) { |
| 348 | 0 | ContextInfo context = new ContextInfo(); |
| 349 | 0 | RegistrationGroupWrapper regGroupWrapper = findRegGroupByIndex(registrationForm); |
| 350 | |
|
| 351 | |
try { |
| 352 | 0 | RegRequestInfo regRequest = generateNewRegRequestInfo(context, registrationForm); |
| 353 | 0 | RegRequestItemInfo regRequestItem = generateDropRegRequestItem(regGroupWrapper, context); |
| 354 | |
|
| 355 | 0 | regRequest.getRegRequestItems().add(regRequestItem); |
| 356 | |
|
| 357 | 0 | List<ValidationResultInfo> validationResultInfos = getCourseRegistrationService().validateRegRequest(regRequest, context); |
| 358 | 0 | if (CollectionUtils.isEmpty(validationResultInfos)) { |
| 359 | 0 | regRequest = getCourseRegistrationService().createRegRequest(regRequest, context); |
| 360 | 0 | registrationForm.getRegistrationGroupWrappersById().put(regGroupWrapper.getRegistrationGroup().getId(), regGroupWrapper); |
| 361 | |
} else { |
| 362 | 0 | StringBuilder builder = new StringBuilder("Found multiple ValidationResultInfo objects after Registration Request validation:\n"); |
| 363 | 0 | for (ValidationResultInfo resultInfo : validationResultInfos) { |
| 364 | 0 | builder.append(resultInfo.getMessage()).append("\n"); |
| 365 | |
} |
| 366 | 0 | throw new RuntimeException(builder.toString()); |
| 367 | |
} |
| 368 | |
|
| 369 | 0 | processSubmitRegRequest(regRequest, registrationForm, true); |
| 370 | 0 | } catch (InvalidParameterException e) { |
| 371 | 0 | throw new RuntimeException(e); |
| 372 | 0 | } catch (DataValidationErrorException e) { |
| 373 | 0 | throw new RuntimeException(e); |
| 374 | 0 | } catch (PermissionDeniedException e) { |
| 375 | 0 | throw new RuntimeException(e); |
| 376 | 0 | } catch (OperationFailedException e) { |
| 377 | 0 | throw new RuntimeException(e); |
| 378 | 0 | } catch (MissingParameterException e) { |
| 379 | 0 | throw new RuntimeException(e); |
| 380 | 0 | } catch (AlreadyExistsException e) { |
| 381 | 0 | throw new RuntimeException(e); |
| 382 | 0 | } |
| 383 | |
|
| 384 | |
|
| 385 | 0 | return getUIFModelAndView(registrationForm); |
| 386 | |
} |
| 387 | |
|
| 388 | |
@RequestMapping(params = "methodToCall=registerClass") |
| 389 | |
public ModelAndView registerClass(@ModelAttribute("KualiForm") RegistrationForm registrationForm, BindingResult result, |
| 390 | |
HttpServletRequest request, HttpServletResponse response) { |
| 391 | 0 | ContextInfo context = new ContextInfo(); |
| 392 | 0 | RegistrationGroupWrapper regGroupWrapper = findRegGroupByIndex(registrationForm); |
| 393 | |
|
| 394 | |
try { |
| 395 | 0 | RegRequestInfo regRequest = generateNewRegRequestInfo(context, registrationForm); |
| 396 | 0 | RegRequestItemInfo regRequestItem = generateRegRequestItem(regGroupWrapper, context); |
| 397 | |
|
| 398 | 0 | regRequest.getRegRequestItems().add(regRequestItem); |
| 399 | |
|
| 400 | 0 | List<ValidationResultInfo> validationResultInfos = getCourseRegistrationService().validateRegRequest(regRequest, context); |
| 401 | 0 | if (CollectionUtils.isEmpty(validationResultInfos)) { |
| 402 | 0 | regRequest = getCourseRegistrationService().createRegRequest(regRequest, context); |
| 403 | 0 | registrationForm.getRegistrationGroupWrappersById().put(regGroupWrapper.getRegistrationGroup().getId(), regGroupWrapper); |
| 404 | |
} else { |
| 405 | 0 | StringBuilder builder = new StringBuilder("Found multiple ValidationResultInfo objects after Registration Request validation:\n"); |
| 406 | 0 | for (ValidationResultInfo resultInfo : validationResultInfos) { |
| 407 | 0 | builder.append(resultInfo.getMessage()).append("\n"); |
| 408 | |
} |
| 409 | 0 | throw new RuntimeException(builder.toString()); |
| 410 | |
} |
| 411 | |
|
| 412 | 0 | processSubmitRegRequest(regRequest, registrationForm, true); |
| 413 | 0 | } catch (InvalidParameterException e) { |
| 414 | 0 | throw new RuntimeException(e); |
| 415 | 0 | } catch (DataValidationErrorException e) { |
| 416 | 0 | throw new RuntimeException(e); |
| 417 | 0 | } catch (PermissionDeniedException e) { |
| 418 | 0 | throw new RuntimeException(e); |
| 419 | 0 | } catch (OperationFailedException e) { |
| 420 | 0 | throw new RuntimeException(e); |
| 421 | 0 | } catch (MissingParameterException e) { |
| 422 | 0 | throw new RuntimeException(e); |
| 423 | 0 | } catch (AlreadyExistsException e) { |
| 424 | 0 | throw new RuntimeException(e); |
| 425 | 0 | } |
| 426 | |
|
| 427 | |
|
| 428 | 0 | return getUIFModelAndView(registrationForm); |
| 429 | |
} |
| 430 | |
|
| 431 | |
@RequestMapping(params = "methodToCall=submitRegistration") |
| 432 | |
public ModelAndView submitRegistration(@ModelAttribute("KualiForm") RegistrationForm registrationForm, BindingResult result, |
| 433 | |
HttpServletRequest request, HttpServletResponse response) { |
| 434 | 0 | processSubmitRegRequest(registrationForm.getRegRequest(), registrationForm, false); |
| 435 | 0 | return getUIFModelAndView(registrationForm); |
| 436 | |
} |
| 437 | |
|
| 438 | |
protected void processSubmitRegRequest(RegRequestInfo regRequest, RegistrationForm registrationForm, boolean oneClick){ |
| 439 | 0 | ContextInfo context = new ContextInfo(); |
| 440 | |
try { |
| 441 | 0 | List<ValidationResultInfo> validationResultInfos = getCourseRegistrationService().validateRegRequest(regRequest, context); |
| 442 | 0 | if (CollectionUtils.isEmpty(validationResultInfos)) { |
| 443 | |
|
| 444 | 0 | RegResponseInfo regResponse = getCourseRegistrationService().submitRegRequest(regRequest.getId(), context); |
| 445 | |
|
| 446 | 0 | if(regResponse.getOperationStatus().getStatus().equalsIgnoreCase("SUCCESS")){ |
| 447 | 0 | GlobalVariables.getMessageMap().putInfo("GLOBAL_INFO", "enroll.registrationSuccessful"); |
| 448 | |
|
| 449 | |
|
| 450 | 0 | if(!oneClick){ |
| 451 | 0 | registrationForm.setRegRequest(null); |
| 452 | |
} |
| 453 | 0 | registrationForm.setCourseRegistrations(getCourseRegistrations(context.getPrincipalId(), registrationForm.getTermId(), context)); |
| 454 | |
} |
| 455 | |
else { |
| 456 | 0 | if(regResponse.getOperationStatus().getErrors().isEmpty()) { |
| 457 | 0 | GlobalVariables.getMessageMap().putError("GLOBAL_ERRORS", "enroll.registrationUnsuccessful"); |
| 458 | |
} |
| 459 | |
} |
| 460 | |
|
| 461 | 0 | if(!regResponse.getOperationStatus().getErrors().isEmpty()){ |
| 462 | 0 | for(String message: regResponse.getOperationStatus().getErrors()){ |
| 463 | 0 | GlobalVariables.getMessageMap().putError("GLOBAL_ERRORS", "error.enroll.requirementsNotMet", message); |
| 464 | |
} |
| 465 | |
} |
| 466 | 0 | if(!regResponse.getOperationStatus().getWarnings().isEmpty()){ |
| 467 | 0 | for(String message: regResponse.getOperationStatus().getWarnings()){ |
| 468 | 0 | GlobalVariables.getMessageMap().putWarning("GLOBAL_WARNINGS", message); |
| 469 | |
} |
| 470 | |
} |
| 471 | 0 | if(!regResponse.getOperationStatus().getMessages().isEmpty()){ |
| 472 | 0 | for(String message: regResponse.getOperationStatus().getMessages()){ |
| 473 | 0 | GlobalVariables.getMessageMap().putInfo("GLOBAL_INFO", message); |
| 474 | |
} |
| 475 | |
} |
| 476 | 0 | } else { |
| 477 | 0 | GlobalVariables.getMessageMap().putError("GLOBAL_ERRORS", "enroll.registrationUnsuccessful"); |
| 478 | 0 | StringBuilder builder = new StringBuilder("Found multiple ValidationResultInfo objects after Registration Request validation:\n"); |
| 479 | 0 | for (ValidationResultInfo resultInfo : validationResultInfos) { |
| 480 | 0 | builder.append(resultInfo.getMessage()).append("\n"); |
| 481 | |
} |
| 482 | 0 | throw new RuntimeException(builder.toString()); |
| 483 | |
} |
| 484 | 0 | } catch (DataValidationErrorException e) { |
| 485 | 0 | throw new RuntimeException(e); |
| 486 | 0 | } catch (DoesNotExistException e) { |
| 487 | 0 | throw new RuntimeException(e); |
| 488 | 0 | } catch (InvalidParameterException e) { |
| 489 | 0 | throw new RuntimeException(e); |
| 490 | 0 | } catch (MissingParameterException e) { |
| 491 | 0 | throw new RuntimeException(e); |
| 492 | 0 | } catch (OperationFailedException e) { |
| 493 | 0 | throw new RuntimeException(e); |
| 494 | 0 | } catch (PermissionDeniedException e) { |
| 495 | 0 | throw new RuntimeException(e); |
| 496 | 0 | } catch (AlreadyExistsException e) { |
| 497 | 0 | throw new RuntimeException(e); |
| 498 | 0 | } catch (DisabledIdentifierException e) { |
| 499 | 0 | throw new RuntimeException(e); |
| 500 | 0 | } |
| 501 | 0 | } |
| 502 | |
|
| 503 | |
|
| 504 | |
|
| 505 | |
|
| 506 | |
@RequestMapping(params = "methodToCall=removeFromCart") |
| 507 | |
public ModelAndView removeFromCart(@ModelAttribute("KualiForm") RegistrationForm registrationForm, BindingResult result, |
| 508 | |
HttpServletRequest request, HttpServletResponse response) { |
| 509 | 0 | ContextInfo context = new ContextInfo(); |
| 510 | |
|
| 511 | 0 | RegRequest regRequest = registrationForm.getRegRequest(); |
| 512 | 0 | String id = registrationForm.getActionParamaterValue("itemId"); |
| 513 | 0 | String regGroupId = ""; |
| 514 | |
|
| 515 | 0 | if(StringUtils.isBlank(id)){ |
| 516 | 0 | RegistrationGroupWrapper regGroupWrapper = findRegGroupByIndex(registrationForm); |
| 517 | 0 | regGroupId = regGroupWrapper.getRegistrationGroup().getId(); |
| 518 | |
} |
| 519 | |
|
| 520 | 0 | if(regRequest != null){ |
| 521 | 0 | List<? extends RegRequestItem> items = regRequest.getRegRequestItems(); |
| 522 | 0 | if(items != null && !items.isEmpty()){ |
| 523 | 0 | Iterator<? extends RegRequestItem> it = items.iterator(); |
| 524 | 0 | while(it.hasNext()){ |
| 525 | 0 | RegRequestItem item = it.next(); |
| 526 | 0 | if(StringUtils.isNotBlank(id) && item.getId().equals(id)){ |
| 527 | 0 | it.remove(); |
| 528 | 0 | break; |
| 529 | |
} |
| 530 | 0 | else if(StringUtils.isNotBlank(regGroupId) && StringUtils.isNotBlank(item.getNewRegGroupId()) |
| 531 | |
&& item.getNewRegGroupId().equals(regGroupId)){ |
| 532 | 0 | it.remove(); |
| 533 | 0 | break; |
| 534 | |
} |
| 535 | 0 | } |
| 536 | |
} |
| 537 | |
} |
| 538 | |
|
| 539 | |
try { |
| 540 | |
|
| 541 | 0 | List<ValidationResultInfo> validationResultInfos = getCourseRegistrationService().validateRegRequest(registrationForm.getRegRequest(), context); |
| 542 | 0 | if (CollectionUtils.isEmpty(validationResultInfos)) { |
| 543 | 0 | RegRequestInfo regRequestInfo = getCourseRegistrationService().updateRegRequest(registrationForm.getRegRequest().getId(), registrationForm.getRegRequest(), context); |
| 544 | 0 | registrationForm.setRegRequest(getCourseRegistrationService().getRegRequest(regRequestInfo.getId(),context)); |
| 545 | 0 | } else { |
| 546 | 0 | StringBuilder builder = new StringBuilder("Found multiple ValidationResultInfo objects after Registration Request validation:\n"); |
| 547 | 0 | for (ValidationResultInfo resultInfo : validationResultInfos) { |
| 548 | 0 | builder.append(resultInfo.getMessage()).append("\n"); |
| 549 | |
} |
| 550 | 0 | throw new RuntimeException(builder.toString()); |
| 551 | |
} |
| 552 | 0 | } catch (InvalidParameterException e) { |
| 553 | 0 | throw new RuntimeException(e); |
| 554 | 0 | } catch (DoesNotExistException e) { |
| 555 | 0 | throw new RuntimeException(e); |
| 556 | 0 | } catch (DataValidationErrorException e) { |
| 557 | 0 | throw new RuntimeException(e); |
| 558 | 0 | } catch (PermissionDeniedException e) { |
| 559 | 0 | throw new RuntimeException(e); |
| 560 | 0 | } catch (VersionMismatchException e) { |
| 561 | 0 | throw new RuntimeException(e); |
| 562 | 0 | } catch (OperationFailedException e) { |
| 563 | 0 | throw new RuntimeException(e); |
| 564 | 0 | } catch (MissingParameterException e) { |
| 565 | 0 | throw new RuntimeException(e); |
| 566 | 0 | } |
| 567 | |
|
| 568 | 0 | return getUIFModelAndView(registrationForm); |
| 569 | |
} |
| 570 | |
|
| 571 | |
|
| 572 | |
|
| 573 | |
|
| 574 | |
@RequestMapping(params = "methodToCall=addToCart") |
| 575 | |
public ModelAndView addToCart(@ModelAttribute("KualiForm") RegistrationForm registrationForm, BindingResult result, |
| 576 | |
HttpServletRequest request, HttpServletResponse response) { |
| 577 | 0 | ContextInfo context = new ContextInfo(); |
| 578 | |
|
| 579 | 0 | RegistrationGroupWrapper regGroupWrapper = findRegGroupByIndex(registrationForm); |
| 580 | |
|
| 581 | |
try { |
| 582 | |
|
| 583 | 0 | if (registrationForm.getRegRequest() == null || |
| 584 | |
(registrationForm.getRegRequest() != null && StringUtils.isBlank(registrationForm.getRegRequest().getId()))) { |
| 585 | 0 | RegRequestInfo regRequest = generateNewRegRequestInfo(context, registrationForm); |
| 586 | 0 | registrationForm.setRegRequest(regRequest); |
| 587 | |
} |
| 588 | |
|
| 589 | 0 | RegRequestItemInfo regRequestItem = generateRegRequestItem(regGroupWrapper, context); |
| 590 | 0 | registrationForm.getRegRequest().getRegRequestItems().add(regRequestItem); |
| 591 | |
|
| 592 | 0 | List<ValidationResultInfo> validationResultInfos = getCourseRegistrationService().validateRegRequest(registrationForm.getRegRequest(), context); |
| 593 | 0 | if (CollectionUtils.isEmpty(validationResultInfos)) { |
| 594 | 0 | if (StringUtils.isBlank(registrationForm.getRegRequest().getId())) { |
| 595 | 0 | RegRequestInfo regRequestInfo = getCourseRegistrationService().createRegRequest(registrationForm.getRegRequest(), context); |
| 596 | 0 | regRequestInfo = getCourseRegistrationService().getRegRequest(regRequestInfo.getId(),context); |
| 597 | 0 | registrationForm.setRegRequest(regRequestInfo); |
| 598 | 0 | } else { |
| 599 | 0 | getCourseRegistrationService().updateRegRequest(registrationForm.getRegRequest().getId(), registrationForm.getRegRequest(), context); |
| 600 | 0 | RegRequestInfo regRequestInfo = getCourseRegistrationService().getRegRequest(registrationForm.getRegRequest().getId(),context); |
| 601 | 0 | registrationForm.setRegRequest(regRequestInfo); |
| 602 | |
} |
| 603 | |
|
| 604 | 0 | registrationForm.getRegistrationGroupWrappersById().put(regGroupWrapper.getRegistrationGroup().getId(), regGroupWrapper); |
| 605 | |
} else { |
| 606 | 0 | StringBuilder builder = new StringBuilder("Found multiple ValidationResultInfo objects after Registration Request validation:\n"); |
| 607 | 0 | for (ValidationResultInfo resultInfo : validationResultInfos) { |
| 608 | 0 | builder.append(resultInfo.getMessage()).append("\n"); |
| 609 | |
} |
| 610 | 0 | throw new RuntimeException(builder.toString()); |
| 611 | |
} |
| 612 | 0 | } catch (InvalidParameterException e) { |
| 613 | 0 | throw new RuntimeException(e); |
| 614 | 0 | } catch (DoesNotExistException e) { |
| 615 | 0 | throw new RuntimeException(e); |
| 616 | 0 | } catch (DataValidationErrorException e) { |
| 617 | 0 | throw new RuntimeException(e); |
| 618 | 0 | } catch (PermissionDeniedException e) { |
| 619 | 0 | throw new RuntimeException(e); |
| 620 | 0 | } catch (VersionMismatchException e) { |
| 621 | 0 | throw new RuntimeException(e); |
| 622 | 0 | } catch (OperationFailedException e) { |
| 623 | 0 | throw new RuntimeException(e); |
| 624 | 0 | } catch (MissingParameterException e) { |
| 625 | 0 | throw new RuntimeException(e); |
| 626 | 0 | } catch (AlreadyExistsException e) { |
| 627 | 0 | throw new RuntimeException(e); |
| 628 | 0 | } |
| 629 | |
|
| 630 | 0 | return getUIFModelAndView(registrationForm); |
| 631 | |
} |
| 632 | |
|
| 633 | |
protected void processValidationResults(List<ValidationResultInfo> validationResultInfos, String operation) { |
| 634 | 0 | GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, "Found errors while trying to " + operation); |
| 635 | 0 | for (ValidationResultInfo resultInfo : validationResultInfos) { |
| 636 | 0 | GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, resultInfo.getMessage()); |
| 637 | |
} |
| 638 | 0 | } |
| 639 | |
|
| 640 | |
protected CourseOfferingService getCourseOfferingService() { |
| 641 | 0 | if (courseOfferingService == null) { |
| 642 | 0 | courseOfferingService = (CourseOfferingService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/courseOffering", "CourseOfferingService")); |
| 643 | |
} |
| 644 | |
|
| 645 | 0 | return courseOfferingService; |
| 646 | |
} |
| 647 | |
|
| 648 | |
protected CourseRegistrationService getCourseRegistrationService() { |
| 649 | 0 | if (courseRegistrationService == null) { |
| 650 | 0 | courseRegistrationService = (CourseRegistrationService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/courseRegistrationService", "CourseRegistrationService")); |
| 651 | |
} |
| 652 | 0 | return courseRegistrationService; |
| 653 | |
} |
| 654 | |
|
| 655 | |
protected StatementService getStatementService() { |
| 656 | 0 | if (statementService == null) { |
| 657 | 0 | statementService = (StatementService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/statement", "StatementService")); |
| 658 | |
} |
| 659 | 0 | return statementService; |
| 660 | |
} |
| 661 | |
|
| 662 | |
protected CourseService getCourseService() { |
| 663 | 0 | if (courseService == null) { |
| 664 | 0 | courseService = (CourseService) GlobalResourceLoader.getService(new QName(CourseServiceConstants.COURSE_NAMESPACE, "CourseService")); |
| 665 | |
} |
| 666 | 0 | return courseService; |
| 667 | |
} |
| 668 | |
} |