Coverage Report - org.kuali.rice.kim.service.impl.KimTypeInfoServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
KimTypeInfoServiceImpl
0%
0/34
0%
0/16
3
 
 1  
 /*
 2  
  * Copyright 2007-2009 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.service.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collection;
 20  
 import java.util.Collections;
 21  
 import java.util.HashMap;
 22  
 import java.util.Map;
 23  
 
 24  
 import org.kuali.rice.kim.bo.types.dto.KimTypeInfo;
 25  
 import org.kuali.rice.kim.bo.types.impl.KimTypeImpl;
 26  
 import org.kuali.rice.kim.service.KimTypeInfoService;
 27  
 import org.kuali.rice.kim.util.KimConstants;
 28  
 import org.kuali.rice.kns.service.BusinessObjectService;
 29  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 30  
 
 31  
 /**
 32  
  * This is a description of what this class does - kellerj don't forget to fill this in. 
 33  
  * 
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  *
 36  
  */
 37  0
 public class KimTypeInfoServiceImpl implements KimTypeInfoService {
 38  
 
 39  
         private BusinessObjectService businessObjectService;
 40  
         
 41  0
         protected Map<String,KimTypeInfo> infoCache = Collections.synchronizedMap( new HashMap<String, KimTypeInfo>() );
 42  0
         protected Map<String,KimTypeInfo> infoCacheByName = Collections.synchronizedMap( new HashMap<String, KimTypeInfo>() );
 43  0
         protected boolean allLoaded = false;
 44  
         
 45  
         @SuppressWarnings("unchecked")
 46  
         public Collection<KimTypeInfo> getAllTypes() {
 47  0
                 if ( !allLoaded ) {
 48  0
                         Collection<KimTypeImpl> types = getBusinessObjectService().findAll(KimTypeImpl.class);
 49  0
                         synchronized ( this ) {
 50  0
                                 for ( KimTypeImpl typ : types ) {
 51  0
                                         if ( typ.isActive() ) {
 52  0
                                                 KimTypeInfo info = typ.toInfo();
 53  0
                                                 infoCache.put(typ.getKimTypeId(), info);
 54  0
                                                 infoCacheByName.put(typ.getNamespaceCode()+typ.getName(), info);
 55  0
                                         }
 56  
                                 }
 57  0
                         }
 58  0
                         allLoaded = true;
 59  
                 }
 60  0
                 return new ArrayList<KimTypeInfo>( infoCache.values() );
 61  
         }
 62  
         
 63  
         /**
 64  
          * This overridden method ...
 65  
          * 
 66  
          * @see org.kuali.rice.kim.service.KimTypeInfoService#getKimType(java.lang.String)
 67  
          */
 68  
         public KimTypeInfo getKimType(String kimTypeId) {
 69  0
                 if ( !infoCache.containsKey(kimTypeId) ) {
 70  0
                         Map<String,String> pk = new HashMap<String, String>(1);
 71  0
                         pk.put(KimConstants.PrimaryKeyConstants.KIM_TYPE_ID, kimTypeId);
 72  0
                         KimTypeImpl impl = (KimTypeImpl)getBusinessObjectService().findByPrimaryKey(KimTypeImpl.class, pk);
 73  0
                         if ( impl != null ) {
 74  0
                                 infoCache.put(kimTypeId, impl.toInfo());
 75  
                         }
 76  
                 }
 77  0
                 return infoCache.get(kimTypeId);
 78  
         }
 79  
 
 80  
         public KimTypeInfo getKimTypeByName( String namespaceCode, String typeName ) {
 81  0
                 if ( !infoCacheByName.containsKey(namespaceCode+typeName) ) {
 82  0
                         Map<String,String> pk = new HashMap<String, String>(2);
 83  0
                         pk.put(KimConstants.UniqueKeyConstants.NAMESPACE_CODE, namespaceCode);
 84  0
                         pk.put("name", typeName);
 85  0
                         KimTypeImpl impl = (KimTypeImpl)getBusinessObjectService().findByPrimaryKey(KimTypeImpl.class, pk);
 86  0
                         if ( impl != null ) {
 87  0
                                 infoCacheByName.put(namespaceCode+typeName, impl.toInfo());
 88  
                         }
 89  
                 }
 90  0
                 return infoCacheByName.get(namespaceCode+typeName);
 91  
         }
 92  
         
 93  
         protected BusinessObjectService getBusinessObjectService() {
 94  0
                 if ( businessObjectService == null ) {
 95  0
                         businessObjectService = KNSServiceLocator.getBusinessObjectService();
 96  
                 }
 97  0
                 return businessObjectService;
 98  
         }
 99  
         
 100  
 }