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