View Javadoc

1   /**
2    * Copyright 2012 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   *
15   * Created by vgadiyak on 5/30/12
16   */
17  package org.kuali.student.enrollment.class2.courseoffering.service.impl;
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.apache.log4j.Logger;
21  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
22  import org.kuali.rice.kim.api.identity.Person;
23  import org.kuali.rice.krad.maintenance.MaintenanceDocument;
24  import org.kuali.rice.krad.uif.container.CollectionGroup;
25  import org.kuali.rice.krad.uif.view.View;
26  import org.kuali.rice.krad.util.GlobalVariables;
27  import org.kuali.rice.krad.util.KRADConstants;
28  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
29  import org.kuali.student.enrollment.acal.dto.TermInfo;
30  import org.kuali.student.enrollment.acal.service.AcademicCalendarService;
31  import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingEditWrapper;
32  import org.kuali.student.enrollment.class2.courseoffering.dto.OfferingInstructorWrapper;
33  import org.kuali.student.enrollment.class2.courseoffering.dto.OrganizationInfoWrapper;
34  import org.kuali.student.enrollment.class2.courseoffering.service.CourseOfferingMaintainable;
35  import org.kuali.student.enrollment.class2.courseoffering.util.ActivityOfferingConstants;
36  import org.kuali.student.enrollment.class2.courseoffering.util.ViewHelperUtil;
37  import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
38  import org.kuali.student.enrollment.courseoffering.dto.CreditOptionInfo;
39  import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
40  import org.kuali.student.enrollment.courseoffering.dto.OfferingInstructorInfo;
41  import org.kuali.student.r2.common.constants.CommonServiceConstants;
42  import org.kuali.student.r2.common.dto.ContextInfo;
43  import org.kuali.student.r2.common.util.ContextUtils;
44  import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
45  import org.kuali.student.r2.common.util.constants.LprServiceConstants;
46  import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
47  import org.kuali.student.r2.common.util.date.DateFormatters;
48  import org.kuali.student.r2.core.organization.dto.OrgInfo;
49  import org.kuali.student.r2.core.organization.service.OrganizationService;
50  import org.kuali.student.r2.lum.course.dto.CourseInfo;
51  import org.kuali.student.r2.lum.course.dto.FormatInfo;
52  import org.kuali.student.r2.lum.course.service.assembler.CourseAssemblerConstants;
53  import org.kuali.student.r2.lum.lrc.dto.ResultValueInfo;
54  import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
55  import org.kuali.student.r2.lum.lrc.service.LRCService;
56  import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
57  
58  import javax.xml.namespace.QName;
59  import java.util.ArrayList;
60  import java.util.Arrays;
61  import java.util.Collections;
62  import java.util.HashSet;
63  import java.util.List;
64  import java.util.Map;
65  import java.util.Set;
66  
67  /**
68   * This class //TODO ...
69   *
70   * @author Kuali Student Team
71   */
72  public class CourseOfferingEditMaintainableImpl extends CourseOfferingMaintainableImpl implements CourseOfferingMaintainable{
73      private static final long serialVersionUID = 1L;
74      private final static Logger LOG = Logger.getLogger(CourseOfferingEditMaintainableImpl.class);
75  
76      private transient OrganizationService organizationService;
77      private transient LRCService lrcService;
78      private transient AcademicCalendarService acalService;
79  
80      //TODO : implement the functionality for Personnel section and its been delayed now since the backend implementation is not yet ready (06/06/2012).
81  
82      @Override
83      public void saveDataObject() {
84          if (getMaintenanceAction().equals(KRADConstants.MAINTENANCE_EDIT_ACTION)) {
85              CourseOfferingEditWrapper coEditWrapper = (CourseOfferingEditWrapper)getDataObject(); 
86              updateCourseOffering(coEditWrapper);
87          }
88          else{//for new and copy action, report error
89               LOG.error(">>>Do not support!");
90          }        
91   
92      }
93  
94      private void updateCourseOffering(CourseOfferingEditWrapper coEditWrapper){
95          try{
96              // persist format offerings
97              updateFormatOfferings(coEditWrapper);
98  
99              //persist unitDeploymentOrgIds
100             List<String> unitDeploymentOrgIds = new ArrayList<String>();
101             for(OrganizationInfoWrapper orgWrapper : coEditWrapper.getOrganizationNames()){
102                 unitDeploymentOrgIds.add(orgWrapper.getId());
103             }
104 
105             CourseOfferingInfo coInfo = coEditWrapper.getCoInfo();
106             coInfo.setUnitsDeploymentOrgIds(unitDeploymentOrgIds);
107 
108             ContextInfo contextInfo = ContextUtils.createDefaultContextInfo();
109 
110             // Credit Options (also creates extra-line)
111             if (coEditWrapper.getCreditOption().getTypeKey().equals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED) &&
112                     !coEditWrapper.getCreditOption().getFixedCredit().isEmpty()) {
113                 ResultValuesGroupInfo rvgInfo = getLrcService().getCreateFixedCreditResultValuesGroup(coEditWrapper.getCreditOption().getFixedCredit(),
114                         LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE, contextInfo);
115                 coInfo.setCreditOptionId(rvgInfo.getKey());
116             } else if (coEditWrapper.getCreditOption().getTypeKey().equals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE) &&
117                     !coEditWrapper.getCreditOption().getMinCredits().isEmpty() && !coEditWrapper.getCreditOption().getMaxCredits().isEmpty()) {
118                 ResultValuesGroupInfo rvgInfo = getLrcService().getCreateRangeCreditResultValuesGroup(coEditWrapper.getCreditOption().getMinCredits(),
119                         coEditWrapper.getCreditOption().getMaxCredits(), "1", LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE, contextInfo);
120                 coInfo.setCreditOptionId(rvgInfo.getKey());
121             } else if (coEditWrapper.getCreditOption().getTypeKey().equals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE) &&
122                     !coEditWrapper.getCreditOption().getCredits().isEmpty()) {
123                 ResultValuesGroupInfo rvgInfo = getLrcService().getCreateMultipleCreditResultValuesGroup(coEditWrapper.getCreditOption().getCredits(),
124                         LrcServiceConstants.RESULT_SCALE_KEY_CREDIT_DEGREE, contextInfo);
125                 coInfo.setCreditOptionId(rvgInfo.getKey());
126             }
127 
128             // CO code
129             String courseOfferingCode = coEditWrapper.getCourse().getCode();
130             if (!StringUtils.isEmpty(coInfo.getCourseNumberSuffix())) {
131                 courseOfferingCode += coInfo.getCourseNumberSuffix();
132             }
133             coInfo.setCourseOfferingCode(courseOfferingCode);
134 
135             // Waitlist
136             if (!coInfo.getHasWaitlist()) {
137                 coInfo.setWaitlistTypeKey(null);
138                 coInfo.setWaitlistLevelTypeKey(null);
139             }
140 
141             //TODO REMOVE THIS AFTER KRAD CHECKLISTS ARE FIXED for student registration options
142             if(coEditWrapper.getAuditStudentRegOpts() &&
143                     !coInfo.getStudentRegistrationGradingOptions().contains(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_AUDIT)){
144                 coInfo.getStudentRegistrationGradingOptions().add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_AUDIT);
145             }else{
146                 coInfo.getStudentRegistrationGradingOptions().remove(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_AUDIT);
147             }
148             if(coEditWrapper.getPassFailStudentRegOpts() &&
149                     !coInfo.getStudentRegistrationGradingOptions().contains(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL)){
150                 coInfo.getStudentRegistrationGradingOptions().add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL);
151             }else{
152                 coInfo.getStudentRegistrationGradingOptions().remove(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL);
153             }
154 
155             getCourseOfferingService().updateCourseOffering(coInfo.getId(), coInfo, contextInfo);
156 
157             // check for changes to states in CO and related FOs (may happen in the case of deleted FOs)
158             ViewHelperUtil.updateCourseOfferingStateFromActivityOfferingStateChange(coInfo, contextInfo);
159 
160         }   catch (Exception ex){
161             throw new RuntimeException(ex);
162         }
163 
164     }
165 
166     private void updateFormatOfferings(CourseOfferingEditWrapper coEditWrapper) throws Exception{
167         List<FormatOfferingInfo> updatedFormatOfferingList = new ArrayList<FormatOfferingInfo>();
168         List<FormatOfferingInfo> formatOfferingList = coEditWrapper.getFormatOfferingList();
169         CourseOfferingInfo coInfo = coEditWrapper.getCoInfo();
170         List <String> currentFOIds = getExistingFormatOfferingIds(coInfo.getId());
171         ContextInfo contextInfo = ContextUtils.createDefaultContextInfo();
172         if (formatOfferingList != null && !formatOfferingList.isEmpty())  {
173             for(FormatOfferingInfo formatOfferingInfo : formatOfferingList){
174                 if(formatOfferingInfo.getId()!=null &&
175                         !formatOfferingInfo.getId().isEmpty() &&
176                         currentFOIds.contains(formatOfferingInfo.getId())) {
177                     //update FO
178                     if (coInfo.getFinalExamType() != null && !coInfo.getFinalExamType().equals("STANDARD")) {
179                         formatOfferingInfo.setFinalExamLevelTypeKey(null);
180                     }
181                     FormatOfferingInfo updatedFormatOffering = getCourseOfferingService().
182                             updateFormatOffering(formatOfferingInfo.getId(),formatOfferingInfo, contextInfo);
183                     updatedFormatOfferingList.add(updatedFormatOffering);
184                     currentFOIds.remove(formatOfferingInfo.getId());
185                 }
186                 else{
187                     //create a new FO
188                     formatOfferingInfo.setStateKey(LuiServiceConstants.LUI_FO_STATE_PLANNED_KEY);
189                     formatOfferingInfo.setTypeKey(LuiServiceConstants.FORMAT_OFFERING_TYPE_KEY);
190                     formatOfferingInfo.setTermId(coInfo.getTermId());
191                     formatOfferingInfo.setCourseOfferingId(coInfo.getId());
192                     if (coInfo.getFinalExamType() != null && !coInfo.getFinalExamType().equals("STANDARD")) {
193                         formatOfferingInfo.setFinalExamLevelTypeKey(null);
194                     }
195                     FormatOfferingInfo createdFormatOffering = getCourseOfferingService().
196                             createFormatOffering(coInfo.getId(), formatOfferingInfo.getFormatId(), formatOfferingInfo.getTypeKey(), formatOfferingInfo, contextInfo);
197                     updatedFormatOfferingList.add(createdFormatOffering);
198                 }
199             }
200             coEditWrapper.setFormatOfferingList(updatedFormatOfferingList);
201 
202         }
203         //delete FormatOfferings that have been removed by the user
204         if (currentFOIds != null && currentFOIds.size() > 0){
205             for(String formatOfferingId: currentFOIds){
206                 //delete all AOs associated with this FO, then delete FO
207                 //Note by bonnie deleteAO invoked in deleteFormatOfferingCascaded seems not completely correct.
208                 //I didn't see the code if removing FO-AO relations before deleting AOs....
209                 getCourseOfferingService().deleteFormatOfferingCascaded(formatOfferingId, contextInfo);
210             }
211         }
212     }
213 
214     private List<String> getExistingFormatOfferingIds(String courseOfferingId) throws Exception{
215         List<FormatOfferingInfo> formatOfferingInfoList = getCourseOfferingService().getFormatOfferingsByCourseOffering(courseOfferingId, ContextUtils.createDefaultContextInfo());
216         List<String> formatOfferingIds = new ArrayList<String>();
217 
218         if(formatOfferingInfoList != null && !formatOfferingInfoList.isEmpty()){
219             for(FormatOfferingInfo formatOfferingInfo : formatOfferingInfoList){
220                 formatOfferingIds.add(formatOfferingInfo.getId());
221             }
222         }
223         return formatOfferingIds;
224     }
225 
226     @Override
227     protected boolean performAddLineValidation(View view, CollectionGroup collectionGroup, Object model, Object addLine) {
228         if (addLine instanceof OfferingInstructorInfo){
229             OfferingInstructorInfo instructorInfo = (OfferingInstructorInfo) addLine;
230 
231             //check duplication
232             MaintenanceDocumentForm form = (MaintenanceDocumentForm)model;
233             CourseOfferingEditWrapper coEditWrapper = (CourseOfferingEditWrapper)form.getDocument().getNewMaintainableObject().getDataObject();
234             List<OfferingInstructorWrapper> instructors = coEditWrapper.getInstructors();
235             if(instructors != null && !instructors.isEmpty()){
236                 for(OfferingInstructorWrapper thisInst : instructors){
237                     if(instructorInfo.getPersonId().equals(thisInst.getOfferingInstructorInfo().getPersonId())){
238                         GlobalVariables.getMessageMap().putErrorForSectionId("KS-CourseOfferingEdit-PersonnelSection", ActivityOfferingConstants.MSG_ERROR_INSTRUCTOR_DUPLICATE, instructorInfo.getPersonId());
239                         return false;
240                     }
241                 }
242             }
243 
244             //validate ID
245             List<Person> lstPerson = ViewHelperUtil.getInstructorByPersonId(instructorInfo.getPersonId());
246             if(lstPerson == null || lstPerson.isEmpty()){
247                 GlobalVariables.getMessageMap().putErrorForSectionId("KS-CourseOfferingEdit-PersonnelSection", ActivityOfferingConstants.MSG_ERROR_INSTRUCTOR_NOTFOUND, instructorInfo.getPersonId());
248                 return false;
249             }
250         }
251 
252         return super.performAddLineValidation(view, collectionGroup, model, addLine);
253     }
254 
255     @Override
256     protected void processBeforeAddLine(View view, CollectionGroup collectionGroup, Object model, Object addLine) {
257         if (addLine instanceof FormatOfferingInfo){
258             FormatOfferingInfo newLine = (FormatOfferingInfo)addLine;
259             String formatId = newLine.getFormatId();
260             MaintenanceDocumentForm form = (MaintenanceDocumentForm)model;
261             CourseOfferingEditWrapper coEditWrapper = (CourseOfferingEditWrapper)form.getDocument().getNewMaintainableObject().getDataObject();
262             getFormatInfo(coEditWrapper, formatId);
263             // TODO: fix R2 Format to include name and short name
264             newLine.setName("FIX ME!");
265             newLine.setShortName("FIX ME!");
266         }
267     }
268 
269     @Override
270     protected void processAfterAddLine(View view, CollectionGroup collectionGroup, Object model, Object addLine) {
271         if(addLine instanceof OfferingInstructorInfo) {
272             // set the person name if it's null, in the case of user-input personell id
273             OfferingInstructorInfo instructorInfo = (OfferingInstructorInfo)addLine;
274             if(instructorInfo.getPersonName() == null && instructorInfo.getPersonId() != null) {
275                 List<Person> personList = ViewHelperUtil.getInstructorByPersonId(instructorInfo.getPersonId());
276                 if(personList.size() == 1) {
277                     instructorInfo.setPersonName(personList.get(0).getName());
278                 }
279             }
280 
281             // make sure state is not null
282             if(instructorInfo.getStateKey() == null) {
283                 instructorInfo.setStateKey(LprServiceConstants.TENTATIVE_STATE_KEY);
284             }
285         }
286     }
287 
288     @Override
289     public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
290         try {
291             ContextInfo contextInfo = ContextUtils.createDefaultContextInfo();
292 
293             if (getDataObject() instanceof CourseOfferingEditWrapper){
294                 //0. get credit count from CourseInfo
295                 CourseOfferingInfo coInfo = getCourseOfferingService().getCourseOffering(dataObjectKeys.get("coInfo.id"), contextInfo);
296                 CourseInfo courseInfo = getCourseService().getCourse(coInfo.getCourseId(), contextInfo);
297 
298                 //1. set CourseOfferingInfo
299                 CourseOfferingEditWrapper formObject = new CourseOfferingEditWrapper(coInfo);
300 
301                 //2. set CourseInfo
302                 formObject.setCourse(courseInfo);
303 
304                 //3. set formatOfferingList
305                 List<FormatOfferingInfo> formatOfferingList = getCourseOfferingService().getFormatOfferingsByCourseOffering(coInfo.getId(), contextInfo);
306                 formObject.setFormatOfferingList(formatOfferingList);
307 
308                 //4. Checking if Grading Options should be disabled or not and assign default (if no value)
309                 //5. Checking if there are any student registration options from CLU for screen display
310                 List<String> studentRegOptions = new ArrayList<String>();
311                 List<String> crsGradingOptions = new ArrayList<String>();
312                 if (coInfo.getCourseId() != null && courseInfo != null) {
313                     List<String> gradingOptions = courseInfo.getGradingOptions();
314                     Set<String> regOpts = new HashSet<String>(Arrays.asList(CourseOfferingServiceConstants.ALL_STUDENT_REGISTRATION_OPTION_TYPE_KEYS));
315                     for (String gradingOption : gradingOptions) {
316                         if (regOpts.contains(gradingOption)) {
317                             studentRegOptions.add(gradingOption);
318                         } else {
319                             crsGradingOptions.add(gradingOption);
320                         }
321                     }
322                     //Audit is pulled out into a dynamic attribute on course so map it back
323                     if("true".equals(courseInfo.getAttributeValue(CourseAssemblerConstants.COURSE_RESULT_COMP_ATTR_AUDIT))){
324                         studentRegOptions.add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_AUDIT);
325                     }
326                 }
327 
328                 //TODO REMOVE THIS WHEN KRAD IS FIXED
329                 if(coInfo.getStudentRegistrationGradingOptions().contains(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_AUDIT)){
330                     formObject.setAuditStudentRegOpts(true);
331                 }else{
332                     formObject.setAuditStudentRegOpts(false);
333                 }
334                 if(coInfo.getStudentRegistrationGradingOptions().contains(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_PASSFAIL)){
335                     formObject.setPassFailStudentRegOpts(true);
336                 }else{
337                     formObject.setPassFailStudentRegOpts(false);
338                 }
339 
340                 formObject.setStudentRegOptions(studentRegOptions);
341                 formObject.setCrsGradingOptions(crsGradingOptions);
342 
343                 //6. Defining Credit Option and if CLU is fixed (then it's disabled)
344                 boolean creditOptionFixed = false;
345                 String creditOptionId = coInfo.getCreditOptionId();
346 
347                 CreditOptionInfo creditOption = new CreditOptionInfo();
348 
349                 //Grab the Course's credit constraints
350                 //FindBugs: getCreditOptions() null check is in CourseInfo
351                 List<ResultValuesGroupInfo> courseCreditOptions = courseInfo.getCreditOptions();
352 
353                 //Lookup the related course's credit constraints and set them on the creditOption
354                 if (coInfo.getCourseId() != null && !courseCreditOptions.isEmpty()) {
355                     ResultValuesGroupInfo resultValuesGroupInfo = courseCreditOptions.get(0);
356                     //Check for fixed
357                     if (resultValuesGroupInfo.getTypeKey().equalsIgnoreCase(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED)) {
358                         if (!resultValuesGroupInfo.getResultValueKeys().isEmpty()) {
359                             creditOption.setCourseFixedCredits(getLrcService().getResultValue(resultValuesGroupInfo.getResultValueKeys().get(0), contextInfo).getValue());
360                         }
361                         //Set the flag
362                         creditOptionFixed = true;
363 
364                         //Default the value
365                         creditOption.setTypeKey(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED);
366                         creditOption.setFixedCredit(creditOption.getCourseFixedCredits());
367                     } else {
368                         //This is either range or multiple
369 
370                         //Copy all the allowed credits and sort so that the multiple checkboxes can be properly displayed
371                         List<ResultValueInfo> resultValueInfos = getLrcService().getResultValuesForResultValuesGroup(resultValuesGroupInfo.getKey(), contextInfo);
372                         for (ResultValueInfo rVI: resultValueInfos) {
373                             creditOption.getAllowedCredits().add(rVI.getValue());
374                         }
375                         Collections.sort(creditOption.getAllowedCredits());
376 
377                         if (resultValuesGroupInfo.getTypeKey().equalsIgnoreCase(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE)) {
378                             creditOption.setCourseMinCredits(resultValuesGroupInfo.getResultValueRange().getMinValue());
379                             creditOption.setCourseMaxCredits(resultValuesGroupInfo.getResultValueRange().getMaxValue());
380 
381                             //Default the value
382                             creditOption.setTypeKey(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE);
383                             creditOption.setMinCredits(creditOption.getCourseMinCredits());
384                             creditOption.setMaxCredits(creditOption.getCourseMaxCredits());
385                         } else if (resultValuesGroupInfo.getTypeKey().equalsIgnoreCase(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE)) {
386                             //Default the value
387                             creditOption.setTypeKey(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE);
388                             creditOption.getCredits().addAll(creditOption.getAllowedCredits());
389                         }
390                     }
391                 }
392 
393                 //Lookup the selected credit option and set from persisted values
394                 if (creditOptionId != null) {
395                     //Lookup the resultValueGroup Information
396                     ResultValuesGroupInfo resultValuesGroupInfo = getLrcService().getResultValuesGroup(creditOptionId, contextInfo);
397                     String typeKey = resultValuesGroupInfo.getTypeKey();
398 
399                     //Get the actual values
400                     List<ResultValueInfo> resultValueInfos = getLrcService().getResultValuesByKeys(resultValuesGroupInfo.getResultValueKeys(), contextInfo);
401 
402                     if (typeKey.equals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED)) {
403                         creditOption.setTypeKey(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED);
404                         if (!resultValueInfos.isEmpty()) {
405                             creditOption.setFixedCredit(resultValueInfos.get(0).getValue());
406                         }
407                     } else if (typeKey.equals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE)) {
408                         creditOption.setTypeKey(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE);
409                         creditOption.setMinCredits(resultValuesGroupInfo.getResultValueRange().getMinValue());
410                         creditOption.setMaxCredits(resultValuesGroupInfo.getResultValueRange().getMaxValue());
411                     } else if (typeKey.equals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE)) {
412                         creditOption.setTypeKey(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE);
413                         if (!resultValueInfos.isEmpty()) {
414                             List<String> credits = new ArrayList<String>();
415                             for (ResultValueInfo resultValueInfo : resultValueInfos) {
416                                 credits.add(resultValueInfo.getValue());
417                             }
418                             creditOption.setCredits(credits);
419                         }
420                     }
421                 }
422 
423                 formObject.setCreditOption(creditOption);
424                 formObject.setCreditOptionFixed(creditOptionFixed);
425 
426                 formObject.setOrganizationNames(new ArrayList<OrganizationInfoWrapper>());
427 
428                 ArrayList<OrganizationInfoWrapper> orgList = new ArrayList<OrganizationInfoWrapper>();
429 
430                 if(coInfo.getUnitsDeploymentOrgIds() != null){
431                     for(String orgId: coInfo.getUnitsDeploymentOrgIds()){
432                         OrgInfo orgInfo = getOrganizationService().getOrg(orgId,contextInfo);
433                         orgList.add(new OrganizationInfoWrapper(orgInfo));
434                     }
435                 }
436                 formObject.setOrganizationNames(orgList);
437 
438                 // Setting term string: Fall 2012 (09/28/2012 to 12/15/2012)
439                 TermInfo termInfo = getAcalService().getTerm(coInfo.getTermId(), contextInfo);
440                 StringBuilder termStartDate = new StringBuilder(DateFormatters.MONTH_DAY_YEAR_DATE_FORMATTER.format(termInfo.getStartDate()));
441                 StringBuilder termEndDate = new StringBuilder(DateFormatters.MONTH_DAY_YEAR_DATE_FORMATTER.format(termInfo.getEndDate()));
442                 String termStartEnd = termInfo.getName() + " (" + termStartDate + " to " +termEndDate + ")";
443                 formObject.setTermStartEnd(termStartEnd);
444 
445                 document.getNewMaintainableObject().setDataObject(formObject);
446                 document.getOldMaintainableObject().setDataObject(formObject);
447                 document.getDocumentHeader().setDocumentDescription("Edit CO - " + coInfo.getCourseOfferingCode());
448 
449                 //            StateInfo state = getStateService().getState(formObject.getDto().getStateKey(), contextInfo());
450     //            formObject.setStateName(state.getName());
451                 return formObject;
452             }
453         } catch (Exception e) {
454             throw new RuntimeException(e);
455         }
456         return null;
457     }
458 
459     private FormatInfo getFormatInfo(CourseOfferingEditWrapper courseOfferingEditWrapper, String coFormId ){
460         List<FormatInfo> formatInfoList = courseOfferingEditWrapper.getCourse().getFormats();
461         for(FormatInfo formatInfo : formatInfoList) {
462             if(coFormId.equals(formatInfo.getId())){
463                 return formatInfo;
464             }
465         }
466         return null;
467     }
468 
469     private OrganizationService getOrganizationService(){
470         if(organizationService == null) {
471             organizationService = (OrganizationService) GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX + "organization", "OrganizationService"));
472         }
473         return organizationService;
474     }
475 
476     protected LRCService getLrcService() {
477         if(lrcService == null) {
478             lrcService = (LRCService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/lrc", "LrcService"));
479         }
480         return this.lrcService;
481     }
482 
483     protected AcademicCalendarService getAcalService() {
484         if(acalService == null) {
485             acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/acal", "AcademicCalendarService"));
486         }
487         return this.acalService;
488     }
489 
490 }