Coverage Report - org.kuali.student.enrollment.class2.courseoffering.service.assembler.CourseOfferingAssembler
 
Classes in this File Line Coverage Branch Coverage Complexity
CourseOfferingAssembler
0%
0/150
0%
0/58
4.769
 
 1  
 package org.kuali.student.enrollment.class2.courseoffering.service.assembler;
 2  
 
 3  
 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
 4  
 import org.kuali.student.enrollment.courseoffering.dto.OfferingInstructorInfo;
 5  
 import org.kuali.student.enrollment.courseoffering.service.R1ToR2CopyHelper;
 6  
 import org.kuali.student.enrollment.lpr.dto.LuiPersonRelationInfo;
 7  
 import org.kuali.student.enrollment.lpr.service.LuiPersonRelationService;
 8  
 import org.kuali.student.enrollment.lui.dto.LuiIdentifierInfo;
 9  
 import org.kuali.student.enrollment.lui.dto.LuiInfo;
 10  
 import org.kuali.student.enrollment.lui.dto.LuiLuiRelationInfo;
 11  
 import org.kuali.student.enrollment.lui.service.LuiService;
 12  
 import org.kuali.student.lum.course.dto.CourseInfo;
 13  
 import org.kuali.student.r2.common.assembler.AssemblyException;
 14  
 import org.kuali.student.r2.common.assembler.DTOAssembler;
 15  
 import org.kuali.student.r2.common.assembler.EntityDTOAssembler;
 16  
 import org.kuali.student.r2.common.dto.AttributeInfo;
 17  
 import org.kuali.student.r2.common.dto.ContextInfo;
 18  
 import org.kuali.student.r2.common.exceptions.*;
 19  
 import org.kuali.student.r2.common.util.constants.LuiPersonRelationServiceConstants;
 20  
 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
 21  
 import org.kuali.student.r2.lum.clu.dto.LuCodeInfo;
 22  
 
 23  
 import java.util.ArrayList;
 24  
 import java.util.List;
 25  
 
 26  0
 public class CourseOfferingAssembler implements DTOAssembler<CourseOfferingInfo, LuiInfo>{
 27  
         private LuiService luiService;
 28  
         private LuiPersonRelationService lprService;
 29  
         
 30  
         public LuiService getLuiService() {
 31  0
                 return luiService;
 32  
         }
 33  
 
 34  
         public void setLuiService(LuiService luiService) {
 35  0
                 this.luiService = luiService;
 36  0
         }
 37  
 
 38  
         public LuiPersonRelationService getLprService() {
 39  0
                 return lprService;
 40  
         }
 41  
 
 42  
         public void setLprService(LuiPersonRelationService lprService) {
 43  0
                 this.lprService = lprService;
 44  0
         }
 45  
 
 46  
         @Override
 47  
         public CourseOfferingInfo assemble(LuiInfo lui, ContextInfo context) throws AssemblyException {
 48  0
                 if(lui != null){
 49  0
                         CourseOfferingInfo co = new CourseOfferingInfo();
 50  0
             EntityDTOAssembler<LuiInfo, CourseOfferingInfo> commonAssembler = new EntityDTOAssembler<LuiInfo, CourseOfferingInfo>();
 51  0
             co = commonAssembler.assemble(lui, co, context);
 52  0
                         co.setId(lui.getId());
 53  0
                         co.setMaximumEnrollment(lui.getMaximumEnrollment());
 54  0
                         co.setMinimumEnrollment(lui.getMinimumEnrollment());
 55  
 
 56  0
                         assembleLuiCodes(lui, co);
 57  
                         
 58  
                         //below undecided
 59  
                         //co.setHasWaitlist(lui.getHasWaitlist());
 60  
                         //co.setWaitlistTypeKey(lui.getWaitlistTypeKey());
 61  
                         //co.setWaitlistMaximum(lui.getWaitlistMaximum());
 62  
                         //co.setIsWaitlistCheckinRequired(lui.getIsWaitlistCheckinRequired());
 63  
                         //co.setWaitlistCheckinFrequency(lui.getWaitlistCheckinFrequency());
 64  
                         
 65  0
                         co.setCourseId(lui.getCluId());
 66  0
                         co.setTermId(lui.getAtpId());
 67  0
                         co.setUnitsDeployment(lui.getUnitsDeployment());
 68  0
                         co.setUnitsContentOwner(lui.getUnitsContentOwner());
 69  
 
 70  0
                         co.setFees(lui.getFees());
 71  0
                         co.setRevenues(lui.getRevenues());
 72  0
             co.setGradingOptionKeys(lui.getResultValuesGroupKeys());
 73  
 
 74  
             /*
 75  
              * From Bonnie: Comment out setting for Expenditure since we got  DataValidationErrorException:
 76  
              * Error(s) validating course offering Validation Results:
 77  
              *             [2] Path: [expenditure.id] - error.outOfRange data=[null]
 78  
              * the value of expenditure.id looks like this org.kuali.student.lum.course.dto.CourseExpenditureInfo@16a3516.
 79  
              * Norm's input:
 80  
              *  the problem is in the code I wrote a long time ago...
 81  
              *  // TODO: worry about using the toString method for the id
 82  
              *  r2.setId(r1.toString());
 83  
              *  well I should have worried about it more... :(
 84  
              *  I was using that as part of a mock impl where I needed a fake id but we should remove it
 85  
              * it is in the R1ToR2CopyHelper.java
 86  
              *
 87  
              * After the above issue is fixed, we can revisit about   co.setExpenditure(lui.getExpenditure());
 88  
              */
 89  
 //                        co.setExpenditure(lui.getExpenditure());
 90  
 
 91  0
                         assembleIdentifier(lui, co);
 92  
                         
 93  
                         //TODO: lui.getResultOptionIds() -- co.setCreditOptions & co.setGradingOptionKeys --- call LRCService.getResultValuesByIds
 94  
                         
 95  
                         //instructors
 96  0
                         assembleInstructors(co, lui.getId(), context);
 97  
                         
 98  
                         //lui.getAlternateIdentifiers() -- where to map?
 99  
                         //lui.getName() -- where to map?
 100  
                         //lui.getReferenceURL() -- where to map?
 101  
                 
 102  
                 
 103  
                         //LuiLuiRelation (to set jointOfferingIds, hasFinalExam)
 104  0
                          assembleLuiLuiRelations(co, lui.getId(), context);
 105  
                         
 106  0
                         return co;
 107  
                 }
 108  
                 else
 109  0
                         return null;
 110  
         }
 111  
 
 112  
         private void assembleLuiCodes(LuiInfo lui, CourseOfferingInfo co){
 113  0
                 co.setIsHonorsOffering(false);
 114  0
                 List<LuCodeInfo> luiCodes = lui.getLuiCodes();
 115  0
                 if(luiCodes!= null && !luiCodes.isEmpty()){
 116  0
                         for(LuCodeInfo luiCode : luiCodes){
 117  0
                                 if(luiCode.getTypeKey().equals("kuali.lu.code.honorsOffering"))
 118  0
                                         co.setIsHonorsOffering(Boolean.parseBoolean(luiCode.getValue()));
 119  
                                         break;
 120  
                         }
 121  
                 }
 122  0
         }
 123  
         
 124  
         private void assembleInstructors(CourseOfferingInfo co, String luiId, ContextInfo context) throws AssemblyException{
 125  0
                 List<LuiPersonRelationInfo> lprs = null;;
 126  
                 try {
 127  0
                         lprs = lprService.getLprsByLui(luiId, context);
 128  0
                 } catch (DoesNotExistException e) {
 129  0
                         throw new AssemblyException("DoesNotExistException: " + e.getMessage());
 130  0
                 } catch (InvalidParameterException e) {
 131  0
                         throw new AssemblyException("InvalidParameterException:" + e.getMessage());
 132  0
                 } catch (MissingParameterException e) {
 133  0
                         throw new AssemblyException("MissingParameterException"  + e.getMessage());
 134  0
                 } catch (OperationFailedException e) {
 135  0
                         throw new AssemblyException("OperationFailedException"  + e.getMessage());
 136  0
                 } catch (PermissionDeniedException e) {
 137  0
                         throw new AssemblyException("PermissionDeniedException"  + e.getMessage());
 138  0
                 }
 139  
                 
 140  0
                 if(lprs != null && !lprs.isEmpty()){
 141  0
                         List<OfferingInstructorInfo> instructors = new ArrayList<OfferingInstructorInfo>();
 142  0
                         for (LuiPersonRelationInfo lpr : lprs){
 143  0
                                 if(lpr != null && lpr.getTypeKey() != null && lpr.getTypeKey().equals(LuiPersonRelationServiceConstants.INSTRUCTOR_MAIN_TYPE_KEY)){
 144  0
                                         OfferingInstructorInfo instructor = new OfferingInstructorInfo();
 145  0
                                         instructor.setPersonId(lpr.getPersonId());
 146  0
                                         instructor.setPercentageEffort(lpr.getCommitmentPercent());
 147  0
                                         instructor.setId(lpr.getId());
 148  0
                                         instructor.setTypeKey(lpr.getTypeKey());
 149  0
                                         instructor.setStateKey(lpr.getStateKey());
 150  0
                                         instructors.add(instructor);
 151  0
                                 }
 152  
                         }
 153  0
                         co.setInstructors(instructors);
 154  
                 }                
 155  0
         }
 156  
         
 157  
         private void assembleLuiLuiRelations(CourseOfferingInfo co, String luiId, ContextInfo context) throws AssemblyException {
 158  
                 try {
 159  0
                         List<String> jointOfferingIds = new ArrayList<String>();
 160  0
                         List<String> finalExams = new ArrayList<String>();
 161  0
                         List<LuiLuiRelationInfo> rels = luiService.getLuiLuiRelationsByLui(luiId, context);
 162  0
                         if(rels != null && !rels.isEmpty()){                  
 163  0
                 for(LuiLuiRelationInfo rel : rels){
 164  0
                         if(rel.getLuiId().equals(luiId)){
 165  0
                                 if(rel.getTypeKey().equals(LuiServiceConstants.LUI_LUI_RELATION_ASSOCIATED_TYPE_KEY)){
 166  0
                                         LuiInfo lui1 = luiService.getLui(rel.getRelatedLuiId(), context);
 167  0
                                         if(lui1 != null && lui1.getTypeKey().equals(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY) && !jointOfferingIds.contains(rel.getRelatedLuiId())){
 168  0
                                                 jointOfferingIds.add(rel.getRelatedLuiId());
 169  
                                         }
 170  
                                 }
 171  
                                 
 172  0
                                    if(rel.getTypeKey().equals(LuiServiceConstants.LUI_LUI_RELATION_DELIVEREDVIA_TYPE_KEY)){
 173  0
                                         LuiInfo lui2 = luiService.getLui(rel.getRelatedLuiId(), context);
 174  0
                                         if(lui2 != null && lui2.getTypeKey().equals("kuali.lui.type.course.finalExam") && !finalExams.contains(rel.getRelatedLuiId())){
 175  0
                                                 finalExams.add(rel.getRelatedLuiId());
 176  
                                         }
 177  0
                                 }
 178  
                         }
 179  
                 }
 180  
                         }
 181  
                         
 182  0
                         if (!jointOfferingIds.isEmpty()) co.setJointOfferingIds(jointOfferingIds);
 183  
                                 
 184  0
                         if (finalExams.size() > 0) co.setHasFinalExam(true);
 185  
                         
 186  0
                 } catch (DoesNotExistException e) {
 187  0
                         return;
 188  0
                 } catch (InvalidParameterException e) {
 189  0
                         throw new AssemblyException("InvalidParameterException: " + e.getMessage());
 190  0
                 } catch (MissingParameterException e) {
 191  0
                         throw new AssemblyException("MissingParameterException: " + e.getMessage());
 192  0
                 } catch (OperationFailedException e) {
 193  0
                         throw new AssemblyException("OperationFailedException: " + e.getMessage());
 194  0
                 }
 195  0
         }
 196  
         @Override
 197  
         public LuiInfo disassemble(CourseOfferingInfo co, ContextInfo context) {
 198  0
                 if(co != null){                        
 199  0
                         LuiInfo lui = new LuiInfo();
 200  0
                         lui.setId(co.getId());
 201  0
                         lui.setTypeKey(co.getTypeKey());
 202  0
                         lui.setStateKey(co.getStateKey());
 203  0
                         lui.setDescr(co.getDescr());
 204  0
                         lui.setMeta(co.getMeta());
 205  0
                         lui.setAttributes(co.getAttributes());
 206  
                         
 207  0
                         disassembleLuiCodes(co, lui);
 208  
                         
 209  
                         //below undecided
 210  
                         //lui.setHasWaitlist(co.getHasWaitlist());
 211  
                         //lui.setIsWaitlistCheckinRequired(co.getIsWaitlistCheckinRequired());
 212  
                         //lui.setWaitlistCheckinFrequency(co.getWaitlistCheckinFrequency());
 213  
                         //lui.setWaitlistMaximum(co.getWaitlistMaximum());
 214  
                         //lui.setWaitlistTypeKey(co.getWaitlistTypeKey());
 215  
                         
 216  0
                         lui.setCluId(co.getCourseId());
 217  0
                         lui.setAtpId(co.getTermId());
 218  0
                         lui.setUnitsContentOwner(co.getUnitsContentOwner());
 219  0
                         lui.setUnitsDeployment(co.getUnitsDeployment());
 220  0
                         lui.setMaximumEnrollment(co.getMaximumEnrollment());
 221  0
                         lui.setMinimumEnrollment(co.getMinimumEnrollment());
 222  0
                     lui.setResultValuesGroupKeys(co.getGradingOptionKeys());
 223  
 
 224  0
                         lui.setFees(co.getFees());
 225  0
                         lui.setExpenditure(co.getExpenditure());
 226  0
                         lui.setRevenues(co.getRevenues());
 227  
                 
 228  0
                         disassembleIdentifier(co, lui);
 229  
                                         
 230  
                         //TODO: the following mapping undecided on wiki
 231  
                         //gradeRosterLevelTypeKey
 232  
                         //fundingSource
 233  
                         //isFinancialAidEligible
 234  
                         //registrationOrderTypeKey
 235  
                                                 
 236  0
                         return lui;
 237  
                 }
 238  
                 else
 239  0
                         return null;
 240  
         }
 241  
 
 242  
         private void disassembleLuiCodes(CourseOfferingInfo co, LuiInfo lui){
 243  0
                 lui.setLuiCodes(new ArrayList<LuCodeInfo>());
 244  
                 
 245  0
         LuCodeInfo code = new LuCodeInfo();
 246  0
         code.setTypeKey("kuali.lu.code.honorsOffering");
 247  0
         code.setValue(co.getIsHonorsOffering().toString());
 248  0
         code.setAttributes(new ArrayList<AttributeInfo>());
 249  0
         lui.getLuiCodes().add(code);
 250  
                                 
 251  0
         }
 252  
         
 253  
         private void disassembleIdentifier(CourseOfferingInfo co, LuiInfo lui){
 254  0
                 LuiIdentifierInfo identifier = new LuiIdentifierInfo();
 255  0
                 identifier.setCode(co.getCourseOfferingCode());
 256  0
                 identifier.setSuffixCode(co.getCourseNumberSuffix());
 257  0
                 identifier.setLongName(co.getCourseTitle());
 258  0
                 identifier.setDivision(co.getSubjectArea());
 259  0
                 lui.setOfficialIdentifier(identifier);                
 260  0
         }
 261  
         
 262  
         private void assembleIdentifier(LuiInfo lui, CourseOfferingInfo co){
 263  0
                 LuiIdentifierInfo identifier = lui.getOfficialIdentifier();
 264  0
                 if(identifier != null){
 265  0
                         co.setCourseOfferingCode(identifier.getCode());
 266  0
                         co.setCourseNumberSuffix(identifier.getSuffixCode());
 267  0
                         co.setCourseTitle(identifier.getLongName());
 268  0
                         co.setSubjectArea(identifier.getDivision());
 269  
                 }
 270  0
         }
 271  
         
 272  
         public CourseOfferingInfo assemble(CourseInfo courseInfo){
 273  0
                 CourseOfferingInfo courseOfferingInfo = new CourseOfferingInfo();
 274  0
                 courseOfferingInfo.setCourseId(courseInfo.getId());
 275  0
                 courseOfferingInfo.setCourseNumberSuffix(courseInfo.getCourseNumberSuffix());
 276  0
                 courseOfferingInfo.setCourseTitle(courseInfo.getCourseTitle());
 277  0
                 courseOfferingInfo.setSubjectArea(courseInfo.getSubjectArea());
 278  0
                 courseOfferingInfo.setCourseOfferingCode(courseInfo.getCode());
 279  0
                 courseOfferingInfo.setUnitsContentOwner(courseInfo.getUnitsContentOwner());
 280  0
                 courseOfferingInfo.setUnitsDeployment(courseInfo.getUnitsDeployment());
 281  0
                 courseOfferingInfo.setGradingOptionKeys(courseInfo.getGradingOptions());
 282  0
                 if (courseInfo.getCreditOptions() == null) {
 283  0
                     courseOfferingInfo.setCreditOptions(null);
 284  0
                 } else if (courseInfo.getCreditOptions().isEmpty()) {
 285  0
                     courseOfferingInfo.setCreditOptions(null);
 286  
                 } else {
 287  0
                     courseOfferingInfo.setCreditOptions(new R1ToR2CopyHelper().copyResultValuesGroup(courseInfo.getCreditOptions().get(0)));
 288  
                 }
 289  0
                 courseOfferingInfo.setDescr(new R1ToR2CopyHelper().copyRichText(courseInfo.getDescr()));
 290  0
                 courseOfferingInfo.setExpenditure(new R1ToR2CopyHelper().copyCourseExpenditure(courseInfo.getExpenditure()));
 291  0
                 courseOfferingInfo.setFees(new R1ToR2CopyHelper().copyCourseFeeList(courseInfo.getFees()));
 292  0
                 courseOfferingInfo.setInstructors(new R1ToR2CopyHelper().copyInstructors(courseInfo.getInstructors()));                
 293  
                 
 294  0
                 return courseOfferingInfo;
 295  
         }
 296  
 
 297  
 }