Coverage Report - org.kuali.student.enrollment.class2.acal.service.assembler.HolidayCalendarAssembler
 
Classes in this File Line Coverage Branch Coverage Complexity
HolidayCalendarAssembler
0%
0/38
0%
0/10
4.5
 
 1  
 package org.kuali.student.enrollment.class2.acal.service.assembler;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import org.kuali.student.enrollment.acal.dto.HolidayCalendarInfo;
 5  
 import org.kuali.student.r2.common.assembler.AssemblyException;
 6  
 import org.kuali.student.r2.common.assembler.DTOAssembler;
 7  
 import org.kuali.student.r2.common.dto.AttributeInfo;
 8  
 import org.kuali.student.r2.common.dto.ContextInfo;
 9  
 import org.kuali.student.r2.common.util.constants.AtpServiceConstants;
 10  
 import org.kuali.student.r2.core.atp.dto.AtpInfo;
 11  
 
 12  0
 public class HolidayCalendarAssembler implements DTOAssembler<HolidayCalendarInfo, AtpInfo> {
 13  
 
 14  
     @Override
 15  
     public HolidayCalendarInfo assemble(AtpInfo atp, ContextInfo context) throws AssemblyException {
 16  0
         if (atp != null) {
 17  0
             HolidayCalendarInfo holidayCalendarInfo = new HolidayCalendarInfo();
 18  0
             holidayCalendarInfo.setId(atp.getId());
 19  0
             holidayCalendarInfo.setName(atp.getName());
 20  0
             holidayCalendarInfo.setAdminOrgId(atp.getAdminOrgId());
 21  0
             holidayCalendarInfo.setDescr(atp.getDescr());
 22  0
             holidayCalendarInfo.setStartDate(atp.getStartDate());
 23  0
             holidayCalendarInfo.setEndDate(atp.getEndDate());
 24  0
             holidayCalendarInfo.setTypeKey(atp.getTypeKey());
 25  0
             holidayCalendarInfo.setStateKey(atp.getStateKey());
 26  0
             holidayCalendarInfo.setMeta(atp.getMeta());
 27  0
             for (AttributeInfo attr : atp.getAttributes()) {
 28  0
                 if (attr.getKey().equals(AtpServiceConstants.CAMPUS_LOCATION)) {
 29  0
                     holidayCalendarInfo.getCampusKeys().add(attr.getValue());
 30  
                 } else {
 31  0
                     holidayCalendarInfo.getAttributes().add(attr);
 32  
                 }
 33  
             }
 34  0
             return holidayCalendarInfo;
 35  
         } else {
 36  0
             return null;
 37  
         }
 38  
     }
 39  
 
 40  
     @Override
 41  
     public AtpInfo disassemble(HolidayCalendarInfo holidayCalendarInfo, ContextInfo context) throws AssemblyException {
 42  0
         if (holidayCalendarInfo != null) {
 43  0
             AtpInfo atp = new AtpInfo();
 44  0
             atp.setId(holidayCalendarInfo.getId());
 45  0
             atp.setName(holidayCalendarInfo.getName());
 46  0
             atp.setAdminOrgId(holidayCalendarInfo.getAdminOrgId());
 47  0
             atp.setDescr(holidayCalendarInfo.getDescr());
 48  0
             atp.setStartDate(holidayCalendarInfo.getStartDate());
 49  0
             atp.setEndDate(holidayCalendarInfo.getEndDate());
 50  0
             atp.setTypeKey(AtpServiceConstants.ATP_HOLIDAY_CALENDAR_TYPE_KEY);
 51  0
             atp.setStateKey(holidayCalendarInfo.getStateKey());
 52  0
             atp.setMeta(holidayCalendarInfo.getMeta());
 53  0
             atp.getAttributes().addAll(holidayCalendarInfo.getAttributes());
 54  
             // TODO: fix this essentially flawed mechanism -- that happens because of the assembler structure
 55  
 //            it really should take in as a paraemter the existing ATP, if there is one
 56  
 //            and find/match the campus keys there and update the set of attributes not replacing them
 57  
 //            doing it this way we lose the original id of attribute on update 
 58  
             // the making it hard (wrong?) to store it later
 59  0
             for (String campusKey : holidayCalendarInfo.getCampusKeys()) {
 60  0
                 AttributeInfo attr = new AttributeInfo();
 61  0
                 attr.setKey(AtpServiceConstants.CAMPUS_LOCATION);
 62  0
                 attr.setValue(campusKey);
 63  0
                 atp.getAttributes().add(attr);
 64  0
             }
 65  0
             return atp;
 66  
         }
 67  
 
 68  0
         return null;
 69  
     }
 70  
 }