View Javadoc

1   package org.kuali.student.enrollment.class2.registration.form;
2   
3   /*
4    * Copyright 2007 The Kuali Foundation
5    *
6    * Licensed under the Educational Community License, Version 1.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.opensource.org/licenses/ecl1.php
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.rice.krad.web.form.UifFormBase;
21  import org.kuali.student.enrollment.class2.registration.dto.ActivityOfferingWrapper;
22  import org.kuali.student.enrollment.class2.registration.dto.CourseOfferingWrapper;
23  import org.kuali.student.enrollment.class2.registration.dto.MeetingScheduleWrapper;
24  import org.kuali.student.enrollment.class2.registration.dto.RegistrationGroupWrapper;
25  import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
26  import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
27  import org.kuali.student.enrollment.courseregistration.dto.*;
28  import org.kuali.student.r2.common.dto.MeetingScheduleInfo;
29  import org.kuali.student.r2.common.util.constants.LprServiceConstants;
30  
31  import java.util.ArrayList;
32  import java.util.HashMap;
33  import java.util.List;
34  import java.util.Map;
35  
36  //Needs to clean up the core slice codes
37  @Deprecated
38  public class RegistrationForm extends UifFormBase {
39  
40      private static final long serialVersionUID = 2554632701931313545L;
41  
42      private String termKey;
43      private String subjectArea;
44      private String courseOfferingCode;
45      private List<CourseOfferingWrapper> courseOfferingWrappers;
46  
47      private List<CourseRegistrationInfo> courseRegistrations;
48      private Map<String,RegistrationGroupWrapper> registrationGroupWrappersById;
49  
50      private RegistrationRequestInfo regRequest;
51  
52      public RegistrationForm(){
53          super();
54          this.courseRegistrations = new ArrayList<CourseRegistrationInfo>();
55          this.registrationGroupWrappersById = new HashMap<String,RegistrationGroupWrapper>();
56      }
57  
58      public String getTermId() {
59          return termKey;
60      }
61  
62      public void setTermId(String termKey) {
63          this.termKey = termKey;
64      }
65  
66      public String getSubjectArea() {
67          return subjectArea;
68      }
69  
70      public void setSubjectArea(String subjectArea) {
71          this.subjectArea = subjectArea;
72      }
73  
74      public String getCourseOfferingCode() {
75          return courseOfferingCode;
76      }
77  
78      public void setCourseOfferingCode(String courseOfferingCode) {
79          this.courseOfferingCode = courseOfferingCode;
80      }
81  
82      public List<CourseOfferingWrapper> getCourseOfferingWrappers() {
83          return courseOfferingWrappers;
84      }
85  
86      public void setCourseOfferingWrappers(List<CourseOfferingWrapper> courseOfferingWrappers) {
87          this.courseOfferingWrappers = courseOfferingWrappers;
88      }
89  
90      public List<CourseRegistrationInfo> getCourseRegistrations() {
91          return courseRegistrations;
92      }
93  
94      public void setCourseRegistrations(List<CourseRegistrationInfo> courseRegistrations) {
95          this.courseRegistrations = courseRegistrations;
96      }
97  
98      public Map<String, RegistrationGroupWrapper> getRegistrationGroupWrappersById() {
99          return registrationGroupWrappersById;
100     }
101 
102     public void setRegistrationGroupWrappersById(Map<String, RegistrationGroupWrapper> registrationGroupWrappersById) {
103         this.registrationGroupWrappersById = registrationGroupWrappersById;
104     }
105 
106     public RegistrationRequestInfo getRegRequest() {
107         return regRequest;
108     }
109 
110     public void setRegRequest(RegistrationRequestInfo regRequest) {
111         this.regRequest = regRequest;
112     }
113 
114     // need to be redone
115     protected List<MeetingScheduleWrapper> getRegisteredCourses() {
116         List<MeetingScheduleWrapper> meetingScheduleWrappers = new ArrayList<MeetingScheduleWrapper>();
117         /*
118         if(getCourseRegistrations() != null) {
119             // first loop all the items in the course registration list
120             for (CourseRegistrationInfo courseRegistrationInfo : getCourseRegistrations()) {
121                 // TODO - remove this cast below if CourseRegistrationInfo.getCourseOffering() method is fixed
122                 CourseOfferingInfo courseOfferingInfo = (CourseOfferingInfo) courseRegistrationInfo.getCourseOffering();
123                 RegGroupRegistrationInfo regGroupRegistrationInfo = courseRegistrationInfo.getRegGroupRegistration();
124                 if(regGroupRegistrationInfo.getStateKey().equals(LprServiceConstants.REGISTERED_STATE_KEY)){
125                     for (ActivityRegistrationInfo activityRegistrationInfo : regGroupRegistrationInfo.getActivityRegistrations()) {
126                         ActivityOfferingInfo activityOfferingInfo = activityRegistrationInfo.getActivityOffering();
127                         // TODO: fix this to get the meeting schedule from the schedule Id and the schedule service
128                         List<MeetingScheduleInfo> list = new ArrayList<MeetingScheduleInfo> ();
129                         for (MeetingScheduleInfo info : list) {
130                             MeetingScheduleWrapper meetingScheduleWrapper = new MeetingScheduleWrapper(info);
131                             meetingScheduleWrapper.setCourseOfferingCode(courseOfferingInfo.getCourseOfferingCode());
132                             meetingScheduleWrapper.setCourseTitle(courseOfferingInfo.getCourseOfferingTitle());
133                             meetingScheduleWrapper.setItemId(regGroupRegistrationInfo.getId());
134                             // TODO - convert type key to actual activity type
135                             String key = activityOfferingInfo.getTypeKey();
136                             String name = key.substring(key.lastIndexOf(".") + 1);
137                             name = String.format( "%s%s", Character.toUpperCase(name.charAt(0)), name.substring(1));
138                             meetingScheduleWrapper.setTimeTypeName(name);
139                             meetingScheduleWrappers.add(meetingScheduleWrapper);
140                         }
141                     }
142                 }
143             }
144             }*/
145         return meetingScheduleWrappers;
146     }
147 
148     protected List<MeetingScheduleWrapper> getCartCourses() {
149         List<MeetingScheduleWrapper> meetingScheduleWrappers = new ArrayList<MeetingScheduleWrapper>();
150         if(getRegRequest() != null){
151             // first loop all the items in the reg request
152             for (RegistrationRequestItemInfo regRequestItemInfo : getRegRequest().getRegistrationRequestItems()) {
153                 // find the regGroupId of the current item
154                 String regGroupId = (StringUtils.isNotBlank(regRequestItemInfo.getNewRegistrationGroupId())) ? regRequestItemInfo.getNewRegistrationGroupId() : regRequestItemInfo.getExistingRegistrationGroupId();
155                 // find the regGroupWrapper that matches the id from the supplemental list
156                 RegistrationGroupWrapper regGroupWrapper = getRegistrationGroupWrappersById().get(regGroupId);
157                 // if no valid regGroupWrapper object can be found something is wrong with the RegistrationContoller method that adds courses to the cart
158                 if (regGroupWrapper == null) {
159                     throw new RuntimeException("Cannot find RegistrationGroup in RegistrationForm for registrationGroupId: " + regGroupId);
160                 }
161                 // look at the activityOfferingInfos from the regGroup to get all the Schedule information into one single list
162                 for (ActivityOfferingWrapper activityOfferingWrapper : regGroupWrapper.getActivityOfferingWrappers()) {
163                     for(MeetingScheduleWrapper meetingScheduleWrapper: activityOfferingWrapper.getMeetingScheduleWrappers()){
164                         meetingScheduleWrapper.setItemId(regRequestItemInfo.getId());
165                         meetingScheduleWrapper.setTimeTypeName(activityOfferingWrapper.getTypeName());
166                         meetingScheduleWrappers.add(meetingScheduleWrapper);
167                     }
168                 }
169             }
170         }
171         return meetingScheduleWrappers;
172     }
173 
174     protected String getJsArray(List<MeetingScheduleWrapper> meetingScheduleInfos) {
175         StringBuilder builder = new StringBuilder();
176         for(MeetingScheduleWrapper course: meetingScheduleInfos){
177             if (StringUtils.isNotBlank(builder.toString())) {
178                 builder.append(",");
179             }
180             builder.append(course.getJsScheduleObject());
181         }
182         return "[" + builder.toString() + "]";
183     }
184 
185     public void setRegisteredCoursesJsArray(String temp){}
186     public String getRegisteredCoursesJsArray(){
187         return getJsArray(getRegisteredCourses());
188     }
189 
190     public String getCartCoursesJsArray() {
191         return getJsArray(getCartCourses());
192     }
193 
194 }