Coverage Report - org.kuali.rice.kim.impl.type.KimTypeInfoServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
KimTypeInfoServiceImpl
0%
0/27
0%
0/20
3.6
 
 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.kim.impl.type;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 20  
 import org.kuali.rice.kim.api.type.KimType;
 21  
 import org.kuali.rice.kim.api.type.KimTypeInfoService;
 22  
 import org.kuali.rice.krad.service.BusinessObjectService;
 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.Map;
 29  
 
 30  0
 public class KimTypeInfoServiceImpl implements KimTypeInfoService {
 31  
 
 32  
     private BusinessObjectService businessObjectService;
 33  
 
 34  
     @Override
 35  
     public KimType getKimType(final String id) throws RiceIllegalArgumentException {
 36  0
         incomingParamCheck(id, "id");
 37  
 
 38  0
         return KimTypeBo.to(businessObjectService.findBySinglePrimaryKey(KimTypeBo.class, id));
 39  
     }
 40  
 
 41  
     @Override
 42  
     public KimType findKimTypeByNameAndNamespace(final String namespaceCode, final String name) throws RiceIllegalArgumentException {
 43  0
         incomingParamCheck(namespaceCode, "namespaceCode");
 44  0
         incomingParamCheck(name, "name");
 45  
 
 46  0
         final Map<String, Object> crit = new HashMap<String, Object>();
 47  0
         crit.put("namespaceCode", namespaceCode);
 48  0
         crit.put("name", name);
 49  0
         crit.put("active", "true");
 50  
 
 51  0
         final Collection<KimTypeBo> bos = businessObjectService.findMatching(KimTypeBo.class, crit);
 52  
 
 53  0
         if (bos != null && bos.size() > 1) {
 54  0
             throw new IllegalStateException("multiple active results were found for the namespace code: " + namespaceCode + " and name: " + name);
 55  
         }
 56  
 
 57  0
         return bos != null && bos.iterator().hasNext() ? KimTypeBo.to(bos.iterator().next()) : null;
 58  
     }
 59  
 
 60  
     @Override
 61  
     public Collection<KimType> findAllKimTypes() {
 62  0
         final Collection<KimTypeBo> bos
 63  
                 = businessObjectService.findMatching(KimTypeBo.class, Collections.singletonMap("active", "true"));
 64  0
         final Collection<KimType> ims = new ArrayList<KimType>();
 65  
 
 66  0
         if (bos != null) {
 67  0
             for (KimTypeBo bo : bos) {
 68  0
                 if (bo != null) {
 69  0
                     ims.add(KimTypeBo.to(bo));
 70  
                 }
 71  
             }
 72  
         }
 73  0
         return Collections.unmodifiableCollection(ims);
 74  
     }
 75  
 
 76  
     public void setBusinessObjectService(final BusinessObjectService businessObjectService) {
 77  0
         this.businessObjectService = businessObjectService;
 78  0
     }
 79  
 
 80  
     private void incomingParamCheck(Object object, String name) {
 81  0
         if (object == null) {
 82  0
             throw new RiceIllegalArgumentException(name + " was null");
 83  0
         } else if (object instanceof String
 84  
                 && StringUtils.isBlank((String) object)) {
 85  0
             throw new RiceIllegalArgumentException(name + " was blank");
 86  
         }
 87  0
     }
 88  
 }