Coverage Report - org.kuali.rice.kns.service.impl.StateServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
StateServiceImpl
0%
0/30
0%
0/12
2.125
 
 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.HashMap;
 19  
 import java.util.List;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.apache.commons.lang.StringUtils;
 23  
 import org.apache.log4j.Logger;
 24  
 import org.kuali.rice.kns.bo.State;
 25  
 import org.kuali.rice.kns.service.CountryService;
 26  
 import org.kuali.rice.kns.service.KualiModuleService;
 27  
 import org.kuali.rice.kns.service.StateService;
 28  
 import org.kuali.rice.kns.util.KNSPropertyConstants;
 29  
 
 30  0
 public class StateServiceImpl implements StateService {
 31  0
     private static Logger LOG = Logger.getLogger(StateServiceImpl.class);
 32  
 
 33  
     private KualiModuleService kualiModuleService;
 34  
     private CountryService countryService;
 35  
 
 36  
     /**
 37  
      * @see org.kuali.kfs.sys.service.StateService#getByPrimaryId(java.lang.String)
 38  
      */
 39  
     public State getByPrimaryId(String postalStateCode) {
 40  0
         String postalCountryCode = countryService.getDefaultCountry().getPostalCountryCode();
 41  0
         return this.getByPrimaryId(postalCountryCode, postalStateCode);
 42  
     }
 43  
 
 44  
     /**
 45  
      * @see org.kuali.kfs.sys.service.StateService#getByPrimaryId(java.lang.String, java.lang.String)
 46  
      */
 47  
     public State getByPrimaryId(String postalCountryCode, String postalStateCode) {
 48  0
         if (StringUtils.isBlank(postalCountryCode) || StringUtils.isBlank(postalStateCode)) {
 49  0
             LOG.debug("neither postalCountryCode nor postalStateCode can be empty String.");
 50  0
             return null;
 51  
         }
 52  
 
 53  0
         Map<String, Object> postalStateMap = new HashMap<String, Object>();
 54  0
         postalStateMap.put(KNSPropertyConstants.POSTAL_COUNTRY_CODE, postalCountryCode);
 55  0
         postalStateMap.put(KNSPropertyConstants.POSTAL_STATE_CODE, postalStateCode);
 56  
 
 57  0
         return kualiModuleService.getResponsibleModuleService(State.class).getExternalizableBusinessObject(State.class, postalStateMap);
 58  
     }
 59  
 
 60  
     public State getByPrimaryIdIfNecessary(String postalStateCode, State existingState) {
 61  0
         String postalCountryCode = countryService.getDefaultCountry().getPostalCountryCode();
 62  
 
 63  0
         return this.getByPrimaryIdIfNecessary(postalCountryCode, postalStateCode, existingState);
 64  
     }
 65  
 
 66  
     public State getByPrimaryIdIfNecessary(String postalCountryCode, String postalStateCode, State existingState) {
 67  0
         if (existingState != null) {
 68  0
             String existingCountryCode = existingState.getPostalCountryCode();
 69  0
             String existingPostalStateCode = existingState.getPostalStateCode();
 70  0
             if (StringUtils.equals(postalCountryCode, existingCountryCode) && StringUtils.equals(postalStateCode, existingPostalStateCode)) {
 71  0
                 return existingState;
 72  
             }
 73  
         }
 74  
 
 75  0
         return this.getByPrimaryId(postalCountryCode, postalStateCode);
 76  
     }
 77  
 
 78  
     /**
 79  
      * @see org.kuali.kfs.sys.service.StateService#findAllStates()
 80  
      */
 81  
     public List<State> findAllStates() {
 82  0
         String postalCountryCode = countryService.getDefaultCountry().getPostalCountryCode();
 83  0
         return this.findAllStates(postalCountryCode);
 84  
     }
 85  
 
 86  
     /**
 87  
      * @see org.kuali.kfs.sys.service.StateService#findAllStates(java.lang.String)
 88  
      */
 89  
     public List<State> findAllStates(String postalCountryCode) {
 90  0
         if (StringUtils.isBlank(postalCountryCode)) {
 91  0
             throw new IllegalArgumentException("The postalCountryCode cannot be empty String.");
 92  
         }
 93  
 
 94  0
         Map<String, Object> postalStateMap = new HashMap<String, Object>();
 95  0
         postalStateMap.put(KNSPropertyConstants.POSTAL_COUNTRY_CODE, postalCountryCode);
 96  
 
 97  0
         return kualiModuleService.getResponsibleModuleService(State.class).getExternalizableBusinessObjectsList(State.class, postalStateMap);
 98  
     }
 99  
 
 100  
     /**
 101  
      * Sets the kualiModuleService attribute value.
 102  
      * 
 103  
      * @param kualiModuleService The kualiModuleService to set.
 104  
      */
 105  
     public void setKualiModuleService(KualiModuleService kualiModuleService) {
 106  0
         this.kualiModuleService = kualiModuleService;
 107  0
     }
 108  
 
 109  
     /**
 110  
      * Sets the countryService attribute value.
 111  
      * 
 112  
      * @param countryService The countryService to set.
 113  
      */
 114  
     public void setCountryService(CountryService countryService) {
 115  0
         this.countryService = countryService;
 116  0
     }
 117  
 }