Coverage Report - org.kuali.rice.kns.service.impl.CountryServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
CountryServiceImpl
0%
0/39
0%
0/18
3
 
 1  
 /*
 2  
  * Copyright 2008-2009 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.kns.service.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.HashMap;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.apache.commons.lang.StringUtils;
 24  
 import org.apache.log4j.Logger;
 25  
 import org.kuali.rice.kns.bo.Country;
 26  
 import org.kuali.rice.kns.service.CountryService;
 27  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 28  
 import org.kuali.rice.kns.service.KualiModuleService;
 29  
 import org.kuali.rice.kns.util.KNSConstants;
 30  
 import org.kuali.rice.kns.util.KNSPropertyConstants;
 31  
 
 32  0
 public class CountryServiceImpl implements CountryService {
 33  0
     private static Logger LOG = Logger.getLogger(CountryServiceImpl.class);
 34  
 
 35  
     private KualiModuleService kualiModuleService;
 36  
 
 37  
     /**
 38  
      * @see org.kuali.kfs.sys.service.CountryService#getByPrimaryId(java.lang.String)
 39  
      */
 40  
     public Country getByPrimaryId(String postalCountryCode) {
 41  0
         if (StringUtils.isBlank(postalCountryCode)) {
 42  0
             LOG.debug("The postalCountryCode cannot be empty String.");
 43  0
             return null;
 44  
         }
 45  
 
 46  0
         Map<String, Object> postalCountryMap = new HashMap<String, Object>();
 47  0
         postalCountryMap.put(KNSPropertyConstants.POSTAL_COUNTRY_CODE, postalCountryCode);
 48  
 
 49  0
         return kualiModuleService.getResponsibleModuleService(Country.class).getExternalizableBusinessObject(Country.class, postalCountryMap);
 50  
     }
 51  
 
 52  
     public Country getByPrimaryIdIfNecessary(String postalCountryCode, Country existingCountry) {
 53  0
         if (existingCountry != null) {
 54  0
             if (StringUtils.equals(postalCountryCode, existingCountry.getPostalCountryCode())) {
 55  0
                 return existingCountry;
 56  
             }
 57  
         }
 58  
 
 59  0
         return this.getByPrimaryId(postalCountryCode);
 60  
     }
 61  
 
 62  
         /**
 63  
          * @see org.kuali.rice.kns.service.CountryService#getByAlternatePostalCountryCode(java.lang.String)
 64  
          */
 65  
         public Country getByAlternatePostalCountryCode(String alternatePostalCountryCode) {
 66  0
         if (StringUtils.isBlank(alternatePostalCountryCode)) {
 67  0
             LOG.debug("The alternatePostalCountryCode cannot be empty String.");
 68  0
             return null;
 69  
         }
 70  
 
 71  0
         Map<String, Object> postalCountryMap = new HashMap<String, Object>();
 72  0
         postalCountryMap.put(KNSPropertyConstants.ALTERNATE_POSTAL_COUNTRY_CODE, alternatePostalCountryCode);
 73  
 
 74  0
         List<Country> countryList = kualiModuleService.getResponsibleModuleService(Country.class).getExternalizableBusinessObjectsList(Country.class, postalCountryMap);
 75  0
         if (countryList == null || countryList.isEmpty()) {
 76  0
                 return null;
 77  
         }
 78  0
         else if (countryList.size() == 1) {
 79  0
                 return countryList.get(0);
 80  
         }
 81  0
         else throw new IllegalStateException("Multiple countries found with same alternatePostalCountryCode");
 82  
         }
 83  
 
 84  
         /**
 85  
          * @see org.kuali.rice.kns.service.CountryService#getByAlternatePostalCountryCodeIfNecessary(java.lang.String, org.kuali.rice.kns.bo.Country)
 86  
          */
 87  
         public Country getByAlternatePostalCountryCodeIfNecessary(String alternatePostalCountryCode, Country existingCountry) {
 88  0
                 if (existingCountry != null) {
 89  0
                         if (StringUtils.equals(alternatePostalCountryCode, existingCountry.getAlternatePostalCountryCode())) {
 90  0
                                 return existingCountry;
 91  
                         }
 92  
                 }
 93  
                 
 94  0
                 return this.getByAlternatePostalCountryCode(alternatePostalCountryCode);
 95  
         }
 96  
     
 97  
     /**
 98  
      * @see org.kuali.kfs.sys.service.CountryService#getDefaultCountry()
 99  
      */
 100  
     public Country getDefaultCountry() {
 101  0
         String postalCountryCode = KNSServiceLocator.getParameterService().getParameterValue(KNSConstants.KNS_NAMESPACE,
 102  
                         KNSConstants.DetailTypes.ALL_DETAIL_TYPE, KNSConstants.SystemGroupParameterNames.DEFAULT_COUNTRY);
 103  0
         return this.getByPrimaryId(postalCountryCode);
 104  
     }
 105  
     
 106  
     /**
 107  
      * @see org.kuali.kfs.sys.service.CountryService#findAllCountriesNotRestricted()
 108  
      */
 109  
     public List<Country> findAllCountriesNotRestricted() {
 110  0
         List<String> criteriaValues = new ArrayList<String>();
 111  0
         criteriaValues.add(null);
 112  0
         criteriaValues.add("N");
 113  
         
 114  0
         Map<String, Object> postalCountryMap = new HashMap<String, Object>();
 115  0
         postalCountryMap.put(KNSPropertyConstants.POSTAL_COUNTRY_RESTRICTED_INDICATOR, criteriaValues);
 116  
         
 117  0
         return kualiModuleService.getResponsibleModuleService(Country.class).getExternalizableBusinessObjectsList(Country.class, postalCountryMap);
 118  
     }
 119  
 
 120  
     /**
 121  
      * @see org.kuali.kfs.sys.service.CountryService#findAllCountries()
 122  
      */
 123  
     public List<Country> findAllCountries() {
 124  0
         Map<String, Object> postalCountryMap = new HashMap<String, Object>();
 125  0
         return kualiModuleService.getResponsibleModuleService(Country.class).getExternalizableBusinessObjectsList(Country.class, postalCountryMap);
 126  
     }
 127  
 
 128  
     /**
 129  
      * Sets the kualiModuleService attribute value.
 130  
      * 
 131  
      * @param kualiModuleService The kualiModuleService to set.
 132  
      */
 133  
     public void setKualiModuleService(KualiModuleService kualiModuleService) {
 134  0
         this.kualiModuleService = kualiModuleService;
 135  0
     }
 136  
 
 137  
 }