Coverage Report - org.kuali.student.enrollment.class2.courseoffering.service.transformer.CourseOfferingTransformer
 
Classes in this File Line Coverage Branch Coverage Complexity
CourseOfferingTransformer
0%
0/105
0%
0/28
3.5
 
 1  
 package org.kuali.student.enrollment.class2.courseoffering.service.transformer;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.List;
 5  
 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
 6  
 import org.kuali.student.enrollment.courseoffering.dto.OfferingInstructorInfo;
 7  
 import org.kuali.student.enrollment.courseoffering.service.R1ToR2CopyHelper;
 8  
 import org.kuali.student.enrollment.lpr.dto.LprInfo;
 9  
 import org.kuali.student.enrollment.lpr.service.LprService;
 10  
 import org.kuali.student.enrollment.lui.dto.LuiIdentifierInfo;
 11  
 import org.kuali.student.enrollment.lui.dto.LuiInfo;
 12  
 import org.kuali.student.lum.course.dto.CourseInfo;
 13  
 import org.kuali.student.lum.lrc.dto.ResultComponentInfo;
 14  
 import org.kuali.student.r2.common.dto.ContextInfo;
 15  
 import org.kuali.student.r2.common.exceptions.OperationFailedException;
 16  
 import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants;
 17  
 import org.kuali.student.r2.common.util.constants.LprServiceConstants;
 18  
 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
 19  
 import org.kuali.student.r2.lum.clu.dto.LuCodeInfo;
 20  
 
 21  0
 public class CourseOfferingTransformer {
 22  
 
 23  
     public void lui2CourseOffering(LuiInfo lui, CourseOfferingInfo co, ContextInfo context) {
 24  0
         co.setId(lui.getId());
 25  0
         co.setTypeKey(lui.getTypeKey());
 26  0
         co.setStateKey(lui.getStateKey());
 27  0
         co.setDescr(lui.getDescr());
 28  0
         co.setMeta(lui.getMeta());
 29  0
         co.setAttributes(lui.getAttributes());
 30  
         // specific fields
 31  0
         co.setMaximumEnrollment(lui.getMaximumEnrollment());
 32  0
         co.setMinimumEnrollment(lui.getMinimumEnrollment());
 33  
 
 34  0
         co.setCourseId(lui.getCluId());
 35  0
         co.setTermId(lui.getAtpId());
 36  0
         co.setUnitsDeployment(lui.getUnitsDeployment());
 37  0
         co.setUnitsContentOwner(lui.getUnitsContentOwner());
 38  
 
 39  
         // TODO: to copy Grading Option Id as well and this should
 40  
         //       be filtered on type?
 41  0
         co.setRegistrationGradingOptionIds(lui.getResultValuesGroupKeys());
 42  
 
 43  0
         LuiIdentifierInfo identifier = lui.getOfficialIdentifier();
 44  0
         if (identifier == null) {
 45  0
             co.setCourseOfferingCode(null);
 46  0
             co.setCourseNumberSuffix(null);
 47  0
             co.setCourseOfferingTitle(null);
 48  0
             co.setSubjectArea(null);
 49  
         } else {
 50  0
             co.setCourseOfferingCode(identifier.getCode());
 51  0
             co.setCourseNumberSuffix(identifier.getSuffixCode());
 52  0
             co.setCourseOfferingTitle(identifier.getLongName());
 53  0
             co.setSubjectArea(identifier.getDivision());
 54  
         }
 55  
         // store honors in lu code
 56  0
         LuCodeInfo luCode = this.findLuCode(lui, LuiServiceConstants.HONORS_LU_CODE);
 57  0
         if (luCode == null) {
 58  0
             co.setIsHonorsOffering(false);
 59  
         } else {
 60  0
             co.setIsHonorsOffering(string2Boolean(luCode.getValue()));
 61  
         }
 62  
 
 63  
 
 64  
         //below undecided
 65  
         //co.setHasWaitlist(lui.getHasWaitlist());
 66  
         //co.setWaitlistTypeKey(lui.getWaitlistTypeKey());
 67  
         //co.setWaitlistMaximum(lui.getWaitlistMaximum());
 68  
         //co.setIsWaitlistCheckinRequired(lui.getIsWaitlistCheckinRequired());
 69  
         //co.setWaitlistCheckinFrequency(lui.getWaitlistCheckinFrequency());
 70  
 
 71  
         //lui.getAlternateIdentifiers() -- where to map?
 72  
         //lui.getName() -- where to map?
 73  
         //lui.getReferenceURL() -- where to map?
 74  
         //LuiLuiRelation (to set jointOfferingIds, hasFinalExam)
 75  
 //        assembleLuiLuiRelations(co, lui.getId(), context);
 76  0
         return;
 77  
     }
 78  
 
 79  
     private String boolean2String(Boolean bval) {
 80  0
         if (bval == null) {
 81  0
             return null;
 82  
         }
 83  0
         return bval.toString();
 84  
     }
 85  
 
 86  
     private Boolean string2Boolean(String sval) {
 87  0
         if (sval == null) {
 88  0
             return null;
 89  
         }
 90  0
         return Boolean.parseBoolean(sval.toString());
 91  
     }
 92  
 
 93  
     private LuCodeInfo findLuCode(LuiInfo lui, String typeKey) {
 94  0
         for (LuCodeInfo info : lui.getLuiCodes()) {
 95  0
             if (info.getTypeKey().equals(typeKey)) {
 96  0
                 return info;
 97  
             }
 98  
         }
 99  0
         return null;
 100  
     }
 101  
 
 102  
     private LuCodeInfo findAddLuCode(LuiInfo lui, String typeKey) {
 103  0
         LuCodeInfo info = this.findLuCode(lui, typeKey);
 104  0
         if (info != null) {
 105  0
             return info;
 106  
         }
 107  0
         info = new LuCodeInfo();
 108  0
         info.setTypeKey(typeKey);
 109  0
         lui.getLuiCodes().add(info);
 110  0
         return info;
 111  
     }
 112  
 
 113  
     public void courseOffering2Lui(CourseOfferingInfo co, LuiInfo lui, ContextInfo context) {
 114  0
         lui.setId(co.getId());
 115  0
         lui.setTypeKey(co.getTypeKey());
 116  0
         lui.setStateKey(co.getStateKey());
 117  0
         lui.setDescr(co.getDescr());
 118  0
         lui.setMeta(co.getMeta());
 119  0
         lui.setAttributes(co.getAttributes());
 120  
 
 121  0
         lui.setCluId(co.getCourseId());
 122  0
         lui.setAtpId(co.getTermId());
 123  0
         lui.setUnitsContentOwner(co.getUnitsContentOwnerOrgIds());
 124  0
         lui.setUnitsDeployment(co.getUnitsDeploymentOrgIds());
 125  0
         lui.setMaximumEnrollment(co.getMaximumEnrollment());
 126  0
         lui.setMinimumEnrollment(co.getMinimumEnrollment());
 127  
 
 128  0
         List<String> options = new ArrayList(co.getRegistrationGradingOptionIds());
 129  0
         options.add(co.getCreditOptionId());
 130  0
         lui.setResultValuesGroupKeys(options);
 131  
 
 132  0
         LuiIdentifierInfo oi = lui.getOfficialIdentifier();
 133  0
         if (oi == null) {
 134  0
             oi = new LuiIdentifierInfo();
 135  0
             lui.setOfficialIdentifier(oi);
 136  0
             oi.setStateKey(LuiServiceConstants.LUI_IDENTIFIER_ACTIVE_STATE_KEY);
 137  0
             oi.setTypeKey(LuiServiceConstants.LUI_IDENTIFIER_OFFICIAL_TYPE_KEY);
 138  
         }
 139  0
         oi.setCode(co.getCourseOfferingCode());
 140  0
         oi.setSuffixCode(co.getCourseNumberSuffix());
 141  0
         oi.setLongName(co.getCourseOfferingTitle());
 142  0
         oi.setDivision(co.getSubjectArea());
 143  
 
 144  0
         LuCodeInfo luCode = this.findAddLuCode(lui, LuiServiceConstants.HONORS_LU_CODE);
 145  0
         luCode.setValue(boolean2String(co.getIsHonorsOffering()));
 146  
 
 147  
         //below undecided
 148  
         //lui.setHasWaitlist(co.getHasWaitlist());
 149  
         //lui.setIsWaitlistCheckinRequired(co.getIsWaitlistCheckinRequired());
 150  
         //lui.setWaitlistCheckinFrequency(co.getWaitlistCheckinFrequency());
 151  
         //lui.setWaitlistMaximum(co.getWaitlistMaximum());
 152  
         //lui.setWaitlistTypeKey(co.getWaitlistTypeKey());
 153  
 
 154  
         //TODO: the following mapping undecided on wiki
 155  
         //gradeRosterLevelTypeKey
 156  
         //fundingSource
 157  
         //isFinancialAidEligible
 158  
         //registrationOrderTypeKey
 159  
 
 160  0
     }
 161  
 
 162  
     public void copyFromCanonical(CourseInfo courseInfo, CourseOfferingInfo courseOfferingInfo, List<String> optionKeys) {
 163  0
         courseOfferingInfo.setCourseId(courseInfo.getId());
 164  0
         courseOfferingInfo.setCourseNumberSuffix(courseInfo.getCourseNumberSuffix());
 165  0
         if (!optionKeys.contains(CourseOfferingSetServiceConstants.NOT_COURSE_TITLE_OPTION_KEY)) {
 166  0
          courseOfferingInfo.setCourseOfferingTitle(courseInfo.getCourseTitle());
 167  
         }
 168  0
         courseOfferingInfo.setSubjectArea(courseInfo.getSubjectArea());
 169  0
         courseOfferingInfo.setCourseOfferingCode(courseInfo.getCode());
 170  0
         courseOfferingInfo.setUnitsContentOwner(courseInfo.getUnitsContentOwner());
 171  0
         courseOfferingInfo.setUnitsDeployment(courseInfo.getUnitsDeployment());
 172  
 
 173  
         // TODO
 174  
         // courseOfferingInfo.setGradingOptionIds(courseInfo.getGradingOptions());
 175  0
         if ((courseInfo.getCreditOptions() != null) && !courseInfo.getCreditOptions().isEmpty()) {
 176  
             /* TODO: which one shouldbe copied ? */
 177  0
             courseOfferingInfo.setCreditOptionId(courseInfo.getCreditOptions().get(0).getId());
 178  
         }
 179  
 
 180  0
         courseOfferingInfo.setDescr(new R1ToR2CopyHelper().copyRichText(courseInfo.getDescr()));
 181  0
         courseOfferingInfo.setInstructors(new R1ToR2CopyHelper().copyInstructors(courseInfo.getInstructors()));
 182  0
     }
 183  
 
 184  
     // this is not currently in use and needs to be revisited and plugged into the impl
 185  
     public void assembleInstructors(CourseOfferingInfo co, String luiId, ContextInfo context, LprService lprService)
 186  
             throws OperationFailedException {
 187  0
         List<LprInfo> lprs = null;;
 188  
         try {
 189  0
             lprs = lprService.getLprsByLui(luiId, context);
 190  0
         } catch (Exception e) {
 191  0
             throw new OperationFailedException("DoesNotExistException: " + e.getMessage());
 192  0
         }
 193  
 
 194  0
         for (LprInfo lpr : lprs) {
 195  0
             if (lpr.getTypeKey().equals(LprServiceConstants.INSTRUCTOR_MAIN_TYPE_KEY)) {
 196  0
                 OfferingInstructorInfo instructor = new OfferingInstructorInfo();
 197  0
                 instructor.setPersonId(lpr.getPersonId());
 198  0
                 if (lpr.getCommitmentPercent() != null) {
 199  0
                     instructor.setPercentageEffort(Float.parseFloat(lpr.getCommitmentPercent()));
 200  
                 } else {
 201  0
                     instructor.setPercentageEffort(null);
 202  
                 }
 203  0
                 instructor.setId(lpr.getId());
 204  0
                 instructor.setTypeKey(lpr.getTypeKey());
 205  0
                 instructor.setStateKey(lpr.getStateKey());
 206  0
                 co.getInstructors().add(instructor);
 207  0
             }
 208  
         }
 209  0
     }
 210  
 }