Coverage Report - org.kuali.rice.shareddata.impl.county.CountyServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
CountyServiceImpl
100%
30/30
88%
16/18
6
 
 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.county;
 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.county.County;
 23  
 import org.kuali.rice.shareddata.api.county.CountyService;
 24  
 
 25  
 import java.util.ArrayList;
 26  
 import java.util.Collection;
 27  
 import java.util.Collections;
 28  
 import java.util.HashMap;
 29  
 import java.util.List;
 30  
 import java.util.Map;
 31  
 
 32  9
 public class CountyServiceImpl implements CountyService {
 33  
 
 34  
     private BusinessObjectService businessObjectService;
 35  
 
 36  
     @Override
 37  
     public County getCounty(String countryCode, String stateCode, String code) {
 38  5
         if (StringUtils.isBlank(countryCode)) {
 39  1
             throw new RiceIllegalArgumentException(("countryCode is null"));
 40  
         }
 41  
 
 42  4
         if (StringUtils.isBlank(code)) {
 43  1
             throw new RiceIllegalArgumentException(("code is null"));
 44  
         }
 45  
 
 46  3
         if (StringUtils.isBlank(stateCode)) {
 47  1
             throw new RiceIllegalArgumentException(("stateCode is null"));
 48  
         }
 49  
 
 50  2
         final Map<String, Object> map = new HashMap<String, Object>();
 51  2
         map.put("countryCode", countryCode);
 52  2
         map.put("stateCode", stateCode);
 53  2
         map.put("code", code);
 54  
 
 55  2
         return CountyBo.to(businessObjectService.findByPrimaryKey(CountyBo.class, Collections.unmodifiableMap(map)));
 56  
     }
 57  
 
 58  
     @Override
 59  
     public List<County> findAllCountiesInCountryAndState(String countryCode, String stateCode) {
 60  4
         if (StringUtils.isBlank(countryCode)) {
 61  1
             throw new RiceIllegalArgumentException(("countryCode is null"));
 62  
         }
 63  
 
 64  3
         if (StringUtils.isBlank(stateCode)) {
 65  1
             throw new RiceIllegalArgumentException(("stateCode is null"));
 66  
         }
 67  
 
 68  2
         final Map<String, Object> map = new HashMap<String, Object>();
 69  2
         map.put("countryCode", countryCode);
 70  2
         map.put("stateCode", stateCode);
 71  2
         map.put("active", Boolean.TRUE);
 72  
 
 73  2
         final Collection<CountyBo> bos = businessObjectService.findMatching(CountyBo.class, Collections.unmodifiableMap(map));
 74  2
         if (bos == null) {
 75  1
             return Collections.emptyList();
 76  
         }
 77  
 
 78  1
         final List<County> toReturn = new ArrayList<County>();
 79  1
         for (CountyBo bo : bos) {
 80  1
             if (bo != null && bo.isActive()) {
 81  1
                 toReturn.add(CountyBo.to(bo));
 82  
             }
 83  
         }
 84  
 
 85  1
         return Collections.unmodifiableList(toReturn);
 86  
     }
 87  
 
 88  
     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
 89  9
         this.businessObjectService = businessObjectService;
 90  9
     }
 91  
 }