Coverage Report - org.kuali.rice.shareddata.impl.state.StateServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
StateServiceImpl
100%
24/24
85%
12/14
4.667
 
 1  
 /*
 2  
  * Copyright 2006-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  
 
 17  
 package org.kuali.rice.shareddata.impl.state;
 18  
 
 19  
 
 20  
 import org.apache.commons.lang.StringUtils;
 21  
 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 22  
 import org.kuali.rice.krad.service.BusinessObjectService;
 23  
 import org.kuali.rice.shareddata.api.state.State;
 24  
 import org.kuali.rice.shareddata.api.state.StateService;
 25  
 
 26  
 import java.util.ArrayList;
 27  
 import java.util.Collection;
 28  
 import java.util.Collections;
 29  
 import java.util.HashMap;
 30  
 import java.util.List;
 31  
 import java.util.Map;
 32  
 
 33  7
 public class StateServiceImpl implements StateService {
 34  
 
 35  
     private BusinessObjectService businessObjectService;
 36  
 
 37  
     @Override
 38  
     public State getState(String countryCode, String code) {
 39  4
         if (StringUtils.isBlank(countryCode)) {
 40  1
             throw new RiceIllegalArgumentException(("countryCode is null"));
 41  
         }
 42  
 
 43  3
         if (StringUtils.isBlank(code)) {
 44  1
             throw new RiceIllegalArgumentException(("code is null"));
 45  
         }
 46  
 
 47  2
         final Map<String, Object> map = new HashMap<String, Object>();
 48  2
         map.put("countryCode", countryCode);
 49  2
         map.put("code", code);
 50  
 
 51  2
         return StateBo.to(businessObjectService.findByPrimaryKey(StateBo.class, Collections.unmodifiableMap(map)));
 52  
     }
 53  
 
 54  
     @Override
 55  
     public List<State> findAllStatesInCountry(String countryCode) {
 56  3
         if (StringUtils.isBlank(countryCode)) {
 57  1
             throw new RiceIllegalArgumentException(("countryCode is null"));
 58  
         }
 59  
 
 60  2
         final Map<String, Object> map = new HashMap<String, Object>();
 61  2
         map.put("countryCode", countryCode);
 62  2
         map.put("active", Boolean.TRUE);
 63  
 
 64  2
         final Collection<StateBo> bos = businessObjectService.findMatching(StateBo.class, Collections.unmodifiableMap(map));
 65  2
         if (bos == null) {
 66  1
             return Collections.emptyList();
 67  
         }
 68  
 
 69  1
         final List<State> toReturn = new ArrayList<State>();
 70  1
         for (StateBo bo : bos) {
 71  2
             if (bo != null && bo.isActive()) {
 72  2
                 toReturn.add(StateBo.to(bo));
 73  
             }
 74  
         }
 75  
 
 76  1
         return Collections.unmodifiableList(toReturn);
 77  
     }
 78  
 
 79  
     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
 80  7
         this.businessObjectService = businessObjectService;
 81  7
     }
 82  
 }