Coverage Report - org.kuali.student.enrollment.class2.acal.service.assembler.CampusCalendarAssembler
 
Classes in this File Line Coverage Branch Coverage Complexity
CampusCalendarAssembler
0%
0/43
0%
0/22
5.667
 
 1  
 package org.kuali.student.enrollment.class2.acal.service.assembler;
 2  
 
 3  
 
 4  
 import org.kuali.student.enrollment.acal.dto.CampusCalendarInfo;
 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  
 import java.util.ArrayList;
 13  
 import java.util.List;
 14  
 
 15  0
 public class CampusCalendarAssembler implements DTOAssembler<CampusCalendarInfo, AtpInfo> {
 16  
 
 17  
     @Override
 18  
     public CampusCalendarInfo assemble(AtpInfo atp, ContextInfo context) throws AssemblyException {
 19  0
         if(atp != null){
 20  0
             CampusCalendarInfo campusCalendarInfo = new CampusCalendarInfo();
 21  0
             campusCalendarInfo.setKey(atp.getKey());
 22  0
             campusCalendarInfo.setName(atp.getName());
 23  0
             campusCalendarInfo.setDescr(atp.getDescr());
 24  0
             campusCalendarInfo.setStartDate(atp.getStartDate());
 25  0
             campusCalendarInfo.setEndDate(atp.getEndDate());
 26  0
             campusCalendarInfo.setTypeKey(atp.getTypeKey());
 27  0
             campusCalendarInfo.setStateKey(atp.getStateKey());
 28  0
             campusCalendarInfo.setMeta(atp.getMeta());
 29  0
             campusCalendarInfo.setAttributes(atp.getAttributes());
 30  
 
 31  0
             List<AttributeInfo> attributes = atp.getAttributes();
 32  0
             if(attributes != null && !attributes.isEmpty()){
 33  0
                 for (AttributeInfo attribute : attributes){
 34  0
                     if(attribute.getKey().equals(AtpServiceConstants.CAMPUS_LOCATION)){
 35  0
                         campusCalendarInfo.setLocation(attribute.getValue());
 36  0
                         break;
 37  
                     }
 38  
                 }
 39  
             }
 40  
 
 41  0
             return campusCalendarInfo;
 42  
         }
 43  
         else
 44  0
             return null;
 45  
     }
 46  
 
 47  
     @Override
 48  
     public AtpInfo disassemble(CampusCalendarInfo campusCalendarInfo, ContextInfo context) throws AssemblyException{
 49  0
         if (campusCalendarInfo != null){
 50  0
             AtpInfo atp = new AtpInfo();
 51  0
             atp.setKey(campusCalendarInfo.getKey());
 52  0
             atp.setName(campusCalendarInfo.getName());
 53  0
             atp.setDescr(campusCalendarInfo.getDescr());
 54  0
             atp.setStartDate(campusCalendarInfo.getStartDate());
 55  0
             atp.setEndDate(campusCalendarInfo.getEndDate());
 56  0
             atp.setTypeKey(AtpServiceConstants.ATP_CAMPUS_CALENDAR_TYPE_KEY);
 57  0
             atp.setStateKey(campusCalendarInfo.getStateKey());
 58  0
             atp.setMeta(campusCalendarInfo.getMeta());
 59  
 
 60  0
             List<AttributeInfo> attributes = (null != campusCalendarInfo.getAttributes() ? campusCalendarInfo.getAttributes() : new ArrayList<AttributeInfo>());
 61  
 
 62  0
             if (noAttributeEntryWithKey(attributes, AtpServiceConstants.CAMPUS_LOCATION) && campusCalendarInfo.getLocation() != null) {
 63  0
                 AttributeInfo cpt = new AttributeInfo();
 64  0
                 cpt.setKey(AtpServiceConstants.CAMPUS_LOCATION);
 65  0
                 cpt.setValue(campusCalendarInfo.getLocation());
 66  0
                 attributes.add(cpt);
 67  
             }
 68  
 
 69  0
             atp.setAttributes(attributes);
 70  
 
 71  0
             return atp;
 72  
         }
 73  
 
 74  0
         return null;
 75  
     }
 76  
 
 77  
     private boolean noAttributeEntryWithKey(List<AttributeInfo> attributes, String key) {
 78  0
         for (AttributeInfo attInfo : attributes) {
 79  0
             if (attInfo.getKey().equals(key)) {
 80  0
                 return false;
 81  
             }
 82  
         }
 83  0
         return true;
 84  
     }
 85  
 }