Coverage Report - org.kuali.rice.shareddata.impl.campus.CampusServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
CampusServiceImpl
70%
19/27
75%
6/8
1.857
 
 1  
 /*
 2  
  * Copyright 2006-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.kuali.rice.shareddata.impl.campus;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 21  
 import org.kuali.rice.kns.service.BusinessObjectService;
 22  
 import org.kuali.rice.shareddata.api.campus.Campus;
 23  
 import org.kuali.rice.shareddata.api.campus.CampusService;
 24  
 import org.kuali.rice.shareddata.api.campus.CampusType;
 25  
 
 26  
 import java.util.ArrayList;
 27  
 import java.util.Collections;
 28  
 import java.util.List;
 29  
 
 30  
 import static java.util.Collections.singletonMap;
 31  
 
 32  9
 public class CampusServiceImpl implements CampusService {
 33  
 
 34  
         private BusinessObjectService boService;
 35  
         
 36  
         /**
 37  
      * @see org.kuali.rice.shareddata.api.campus.CampusService#getCampus(String code)
 38  
      */
 39  
         @Override
 40  
         public Campus getCampus(String code) {
 41  5
                 if (StringUtils.isBlank(code)) {
 42  2
             throw new RiceIllegalArgumentException("code is blank");
 43  
         }
 44  
 
 45  3
         CampusBo campusBo = boService.findByPrimaryKey(CampusBo.class, singletonMap("code", code));
 46  
 
 47  3
         return CampusBo.to(campusBo);
 48  
         }
 49  
 
 50  
         /**
 51  
      * @see org.kuali.rice.shareddata.api.campus.CampusService#findAllCampuses
 52  
      */
 53  
         @Override
 54  
         public List<Campus> findAllCampuses() {
 55  1
                 List<CampusBo> campusBos = (List<CampusBo>) boService.findMatching(CampusBo.class, singletonMap("active", "true"));
 56  
 
 57  1
         return this.convertListOfCampusBosToImmutables(campusBos);
 58  
         }
 59  
 
 60  
         /**
 61  
      * @see org.kuali.rice.shareddata.api.campus.CampusService#getCampusType(String code)
 62  
      */
 63  
         @Override
 64  
         public CampusType getCampusType(String code) {
 65  5
                 if (StringUtils.isBlank(code)) {
 66  2
             throw new RiceIllegalArgumentException("code is blank");
 67  
         }
 68  
 
 69  3
                 CampusTypeBo campusTypeBo = boService.findByPrimaryKey(CampusTypeBo.class, singletonMap("code", code));
 70  
 
 71  3
         return CampusTypeBo.to(campusTypeBo);
 72  
         }
 73  
 
 74  
         /**
 75  
      * @see org.kuali.rice.shareddata.api.campus.CampusService#findAllCampusTypes
 76  
      */
 77  
         @Override
 78  
         public List<CampusType> findAllCampusTypes() {
 79  0
                 List<CampusTypeBo> campusTypeBos = (List<CampusTypeBo>)boService.findMatching(CampusTypeBo.class, singletonMap("active", "true"));
 80  0
                 return this.convertListOfCampusTypesBosToImmutables(campusTypeBos);
 81  
         }
 82  
     
 83  
     public void setBusinessObjectService(BusinessObjectService boService) {
 84  5
         this.boService = boService;
 85  5
     }
 86  
 
 87  
     private List<Campus> convertListOfCampusBosToImmutables(List<CampusBo> campusBos) {
 88  1
         ArrayList<Campus> campuses = new ArrayList<Campus>();
 89  1
         for (CampusBo bo : campusBos) {
 90  2
             Campus campus = CampusBo.to(bo);
 91  2
             campuses.add(campus) ;
 92  2
         }
 93  1
         return Collections.unmodifiableList(campuses);
 94  
     }
 95  
     
 96  
     private List<CampusType> convertListOfCampusTypesBosToImmutables(List<CampusTypeBo> campusTypeBos) {
 97  0
         ArrayList<CampusType> campusTypes = new ArrayList<CampusType>();
 98  0
         for (CampusTypeBo bo : campusTypeBos) {
 99  0
             CampusType campusType = CampusTypeBo.to(bo);
 100  0
             campusTypes.add(campusType) ;
 101  0
         }
 102  0
         return Collections.unmodifiableList(campusTypes);
 103  
     }
 104  
 }