View Javadoc

1   /**
2    * Copyright 2005-2012 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.county;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
20  import org.kuali.rice.krad.service.BusinessObjectService;
21  import org.kuali.rice.location.api.county.County;
22  import org.kuali.rice.location.api.county.CountyService;
23  
24  import java.util.ArrayList;
25  import java.util.Collection;
26  import java.util.Collections;
27  import java.util.HashMap;
28  import java.util.List;
29  import java.util.Map;
30  
31  public class CountyServiceImpl implements CountyService {
32  
33      private BusinessObjectService businessObjectService;
34  
35      @Override
36      public County getCounty(String countryCode, String stateCode, String code) {
37          if (StringUtils.isBlank(countryCode)) {
38              throw new RiceIllegalArgumentException(("countryCode is null"));
39          }
40  
41          if (StringUtils.isBlank(code)) {
42              throw new RiceIllegalArgumentException(("code is null"));
43          }
44  
45          if (StringUtils.isBlank(stateCode)) {
46              throw new RiceIllegalArgumentException(("stateCode is null"));
47          }
48  
49          final Map<String, Object> map = new HashMap<String, Object>();
50          map.put("countryCode", countryCode);
51          map.put("stateCode", stateCode);
52          map.put("code", code);
53  
54          return CountyBo.to(businessObjectService.findByPrimaryKey(CountyBo.class, Collections.unmodifiableMap(map)));
55      }
56  
57      @Override
58      public List<County> findAllCountiesInCountryAndState(String countryCode, String stateCode) {
59          if (StringUtils.isBlank(countryCode)) {
60              throw new RiceIllegalArgumentException(("countryCode is null"));
61          }
62  
63          if (StringUtils.isBlank(stateCode)) {
64              throw new RiceIllegalArgumentException(("stateCode is null"));
65          }
66  
67          final Map<String, Object> map = new HashMap<String, Object>();
68          map.put("countryCode", countryCode);
69          map.put("stateCode", stateCode);
70          map.put("active", Boolean.TRUE);
71  
72          final Collection<CountyBo> bos = businessObjectService.findMatching(CountyBo.class, Collections.unmodifiableMap(map));
73          if (bos == null) {
74              return Collections.emptyList();
75          }
76  
77          final List<County> toReturn = new ArrayList<County>();
78          for (CountyBo bo : bos) {
79              if (bo != null && bo.isActive()) {
80                  toReturn.add(CountyBo.to(bo));
81              }
82          }
83  
84          return Collections.unmodifiableList(toReturn);
85      }
86  
87      public void setBusinessObjectService(BusinessObjectService businessObjectService) {
88          this.businessObjectService = businessObjectService;
89      }
90  }