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