Coverage Report - org.kuali.rice.shareddata.impl.country.CountryServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
CountryServiceImpl
0%
0/33
0%
0/12
2.833
 
 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.country;
 18  
 
 19  
 
 20  
 import org.apache.commons.lang.StringUtils;
 21  
 import org.kuali.rice.kns.service.BusinessObjectService;
 22  
 import org.kuali.rice.kns.util.KNSPropertyConstants;
 23  
 import org.kuali.rice.shareddata.api.country.Country;
 24  
 import org.kuali.rice.shareddata.api.country.CountryService;
 25  
 
 26  
 import java.util.ArrayList;
 27  
 import java.util.Collection;
 28  
 import java.util.Collections;
 29  
 import java.util.HashMap;
 30  
 import java.util.List;
 31  
 import java.util.Map;
 32  
 
 33  0
 public final class CountryServiceImpl implements CountryService {
 34  
 
 35  
     private BusinessObjectService businessObjectService;
 36  
 
 37  
     @Override
 38  
     public Country getCountry(final String code) {
 39  0
         if (StringUtils.isBlank(code)) {
 40  0
             throw new IllegalArgumentException("code is blank");
 41  
         }
 42  
 
 43  0
         CountryBo countryBo = businessObjectService.findByPrimaryKey(CountryBo.class, Collections.singletonMap(KNSPropertyConstants.POSTAL_COUNTRY_CODE, code));
 44  
 
 45  0
         return CountryBo.to(countryBo);
 46  
     }
 47  
 
 48  
     @Override
 49  
     public Country getCountryByAlternateCode(final String alternateCode) {
 50  0
         if (StringUtils.isBlank(alternateCode)) {
 51  0
             throw new IllegalArgumentException("alt code is blank");
 52  
         }
 53  
 
 54  0
         Collection<CountryBo> countryList = businessObjectService.findMatching(CountryBo.class, Collections.singletonMap(KNSPropertyConstants.ALTERNATE_POSTAL_COUNTRY_CODE, alternateCode));
 55  0
         if (countryList == null || countryList.isEmpty()) {
 56  0
             return null;
 57  0
         } else if (countryList.size() == 1) {
 58  0
             return CountryBo.to(countryList.iterator().next());
 59  0
         } else throw new IllegalStateException("Multiple countries found with same alternateCode");
 60  
     }
 61  
 
 62  
     @Override
 63  
     public List<Country> findAllCountriesNotRestricted() {
 64  0
         List<String> criteriaValues = new ArrayList<String>();
 65  0
         criteriaValues.add(null);
 66  0
         criteriaValues.add("N");
 67  
 
 68  0
         final Map<String, Object> map = new HashMap<String, Object>();
 69  0
         map.put(KNSPropertyConstants.POSTAL_COUNTRY_RESTRICTED_INDICATOR, criteriaValues);
 70  0
         map.put("active", Boolean.TRUE);
 71  
 
 72  0
         Collection<CountryBo> countryBos = businessObjectService.findMatching(CountryBo.class, Collections.unmodifiableMap(map));
 73  
 
 74  0
         return convertListOfBosToImmutables(countryBos);
 75  
     }
 76  
 
 77  
     @Override
 78  
     public List<Country> findAllCountries() {
 79  0
         final Map<String, Object> map = new HashMap<String, Object>();
 80  0
         map.put("active", Boolean.TRUE);
 81  
 
 82  0
         Collection<CountryBo> countryBos = businessObjectService.findMatching(CountryBo.class, Collections.unmodifiableMap(map));
 83  0
         return convertListOfBosToImmutables(countryBos);
 84  
     }
 85  
 
 86  
     /**
 87  
      * Sets the businessObjectServiceMockFor attribute value.
 88  
      *
 89  
      * @param businessObjectService The businessObjectServiceMockFor to set.
 90  
      */
 91  
     public void setBusinessObjectService(final BusinessObjectService businessObjectService) {
 92  0
         this.businessObjectService = businessObjectService;
 93  0
     }
 94  
 
 95  
     /**
 96  
      * Converts a List<CountryBo> to an Unmodifiable List<Country>
 97  
      *
 98  
      * @param countryBos a mutable List<CountryBo> to made completely immutable.
 99  
      * @return An unmodifiable List<Country>
 100  
      */
 101  
     List<Country> convertListOfBosToImmutables(final Collection<CountryBo> countryBos) {
 102  0
         ArrayList<Country> countries = new ArrayList<Country>();
 103  0
         for (CountryBo bo : countryBos) {
 104  0
             Country country = CountryBo.to(bo);
 105  0
             countries.add(country);
 106  0
         }
 107  0
         return Collections.unmodifiableList(countries);
 108  
     }
 109  
 }