View Javadoc
1   /*
2    * Kuali Coeus, a comprehensive research administration system for higher education.
3    * 
4    * Copyright 2005-2015 Kuali, Inc.
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.coeus.s2sgen.impl.location;
20  
21  import org.apache.commons.lang3.StringUtils;
22  import org.kuali.coeus.common.api.country.CountryContract;
23  import org.kuali.coeus.common.api.country.KcCountryService;
24  import org.kuali.coeus.common.api.state.KcStateService;
25  import org.kuali.coeus.common.api.state.StateContract;
26  import org.springframework.beans.factory.annotation.Autowired;
27  import org.springframework.beans.factory.annotation.Qualifier;
28  import org.springframework.stereotype.Component;
29  
30  @Component("s2SLocationService")
31  public class S2SLocationServiceImpl implements S2SLocationService {
32  
33      @Autowired
34      @Qualifier("kcCountryService")
35      private KcCountryService kcCountryService;
36  
37      @Autowired
38      @Qualifier("kcStateService")
39      private KcStateService kcStateService;
40  
41      /**
42       * This method is to get a Country object from the country code
43       *
44       * @param countryCode country code for the country.
45       * @return Country object matching the code
46       */
47      @Override
48      public CountryContract getCountryFromCode(String countryCode) {
49          if(StringUtils.isBlank(countryCode)) return null;
50          CountryContract country = getKcCountryService().getCountryByAlternateCode(countryCode);
51          if(country==null){
52              country = getKcCountryService().getCountry(countryCode);
53          }
54          return country;
55      }
56  
57  
58  
59      /**
60       * This method is to get a State object from the state name
61       *
62       * @param stateName Name of the state
63       * @return State object matching the name.
64       */
65      @Override
66      public StateContract getStateFromName(String countryAlternateCode, String stateName) {
67          CountryContract country = getCountryFromCode(countryAlternateCode);
68  
69          StateContract state = getKcStateService().getState(country.getCode(), stateName);
70          return state;
71      }
72  
73      public KcStateService getKcStateService() {
74          return kcStateService;
75      }
76  
77      public void setKcStateService(KcStateService kcStateService) {
78          this.kcStateService = kcStateService;
79      }
80  
81      public KcCountryService getKcCountryService() {
82          return kcCountryService;
83      }
84  
85      public void setKcCountryService(KcCountryService kcCountryService) {
86          this.kcCountryService = kcCountryService;
87      }
88  }