Coverage Report - org.kuali.rice.location.impl.state.StateServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
StateServiceImpl
0%
0/36
0%
0/20
3.667
 
 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.state;
 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.location.api.country.Country;
 24  
 import org.kuali.rice.location.api.country.CountryService;
 25  
 import org.kuali.rice.location.api.services.LocationApiServiceLocator;
 26  
 import org.kuali.rice.location.api.state.State;
 27  
 import org.kuali.rice.location.api.state.StateService;
 28  
 
 29  
 import java.util.ArrayList;
 30  
 import java.util.Collection;
 31  
 import java.util.Collections;
 32  
 import java.util.HashMap;
 33  
 import java.util.List;
 34  
 import java.util.Map;
 35  
 
 36  0
 public class StateServiceImpl implements StateService {
 37  
 
 38  
     private BusinessObjectService businessObjectService;
 39  
     private CountryService countryService;
 40  
 
 41  
     @Override
 42  
     public State getState(String countryCode, String code) {
 43  0
         if (StringUtils.isBlank(countryCode)) {
 44  0
             throw new RiceIllegalArgumentException(("countryCode is null"));
 45  
         }
 46  
 
 47  0
         if (StringUtils.isBlank(code)) {
 48  0
             throw new RiceIllegalArgumentException(("code is null"));
 49  
         }
 50  
 
 51  0
         final Map<String, Object> map = new HashMap<String, Object>();
 52  0
         map.put("countryCode", countryCode);
 53  0
         map.put("code", code);
 54  
 
 55  0
         return StateBo.to(businessObjectService.findByPrimaryKey(StateBo.class, Collections.unmodifiableMap(map)));
 56  
     }
 57  
 
 58  
     @Override
 59  
     public List<State> findAllStatesInCountry(String countryCode) {
 60  0
         if (StringUtils.isBlank(countryCode)) {
 61  0
             throw new RiceIllegalArgumentException(("countryCode is null"));
 62  
         }
 63  
 
 64  0
         final Map<String, Object> map = new HashMap<String, Object>();
 65  0
         map.put("countryCode", countryCode);
 66  0
         map.put("active", Boolean.TRUE);
 67  
 
 68  0
         final Collection<StateBo> bos = businessObjectService.findMatching(StateBo.class, Collections.unmodifiableMap(map));
 69  0
         if (bos == null) {
 70  0
             return Collections.emptyList();
 71  
         }
 72  
 
 73  0
         final List<State> toReturn = new ArrayList<State>();
 74  0
         for (StateBo bo : bos) {
 75  0
             if (bo != null && bo.isActive()) {
 76  0
                 toReturn.add(StateBo.to(bo));
 77  
             }
 78  
         }
 79  
 
 80  0
         return Collections.unmodifiableList(toReturn);
 81  
     }
 82  
     
 83  
     @Override
 84  
     public List<State> findAllStatesInCountryByAltCode(String alternateCode) {
 85  0
         if (StringUtils.isBlank(alternateCode)) {
 86  0
             throw new RiceIllegalArgumentException(("alternateCode is null"));
 87  
         }
 88  
         
 89  0
         Country country = getCountryService().getCountryByAlternateCode(alternateCode);
 90  
         
 91  0
         if(country == null) {
 92  0
             throw new RiceIllegalStateException("The alternateCode is not a valid Alternate Postal Country Code.  alternateCode: " + alternateCode);
 93  
         }
 94  
         
 95  0
         final List<State> toReturn = findAllStatesInCountry(country.getCode());
 96  0
         return Collections.unmodifiableList(toReturn);
 97  
     }
 98  
 
 99  
     public CountryService getCountryService() {
 100  0
         if (countryService == null) {
 101  0
             countryService = LocationApiServiceLocator.getCountryService();
 102  
         }
 103  0
         return countryService;
 104  
     }   
 105  
 
 106  
     public void setCountryService(CountryService countryService) {
 107  0
         this.countryService = countryService;
 108  0
     }
 109  
     
 110  
     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
 111  0
         this.businessObjectService = businessObjectService;
 112  0
     }
 113  
 }