|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  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 |     | 
     | 
  |  33 |     | 
     | 
  |  34 |     | 
     | 
  |  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 |     | 
     | 
  |  65 |     | 
     | 
  |  66 |     | 
     | 
  |  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 |     | 
   }  |