Coverage Report - org.kuali.rice.kim.service.impl.PermissionServiceBase
 
Classes in this File Line Coverage Branch Coverage Complexity
PermissionServiceBase
0%
0/28
0%
0/8
1.364
 
 1  
 /*
 2  
  * Copyright 2007-2010 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.Collections;
 19  
 import java.util.HashMap;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.kuali.rice.core.util.MaxAgeSoftReference;
 24  
 import org.kuali.rice.kim.bo.role.dto.KimPermissionInfo;
 25  
 import org.kuali.rice.kim.bo.role.impl.RoleMemberAttributeDataImpl;
 26  
 import org.kuali.rice.kim.service.support.KimPermissionTypeService;
 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  
 import org.kuali.rice.kns.service.SequenceAccessorService;
 31  
 import org.kuali.rice.ksb.api.KsbApiServiceLocator;
 32  
 import org.kuali.rice.ksb.api.cache.RiceCacheAdministrator;
 33  
 
 34  
 /**
 35  
  * This is a description of what this class does - jjhanso don't forget to fill this in. 
 36  
  * 
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  *
 39  
  */
 40  0
 public class PermissionServiceBase {
 41  
         protected static final String PERMISSION_IMPL_CACHE_PREFIX = "PermissionImpl-Template-";
 42  
         protected static final String PERMISSION_IMPL_NAME_CACHE_PREFIX = "PermissionImpl-Name-";
 43  
         protected static final String PERMISSION_IMPL_ID_CACHE_PREFIX = "PermissionImpl-Id-";
 44  
         protected static final String PERMISSION_IMPL_CACHE_GROUP = "PermissionImpl";
 45  
 
 46  
         protected static final String DEFAULT_PERMISSION_TYPE_SERVICE = "defaultPermissionTypeService";
 47  
         
 48  
         private BusinessObjectService businessObjectService;
 49  
         private SequenceAccessorService sequenceAccessorService;
 50  
         private RiceCacheAdministrator cacheAdministrator;
 51  
         
 52  0
         private Map<List<KimPermissionInfo>,MaxAgeSoftReference<List<String>>> permissionToRoleCache = Collections.synchronizedMap( new HashMap<List<KimPermissionInfo>,MaxAgeSoftReference<List<String>>>() );
 53  
 
 54  
     // Not ThreadLocal or time limited- should not change during the life of the system
 55  0
         private Map<String,KimPermissionTypeService> permissionTypeServiceByNameCache = Collections.synchronizedMap( new HashMap<String, KimPermissionTypeService>() );
 56  
         
 57  
 
 58  
         private static final long CACHE_MAX_AGE_SECONDS = 60L;
 59  
         
 60  
         protected BusinessObjectService getBusinessObjectService() {
 61  0
                 if ( businessObjectService == null ) {
 62  0
                         businessObjectService = KNSServiceLocator.getBusinessObjectService();
 63  
                 }
 64  0
                 return businessObjectService;
 65  
         }
 66  
    
 67  
         public void flushPermissionImplCache() {
 68  0
             getCacheAdministrator().flushGroup(PERMISSION_IMPL_CACHE_GROUP);
 69  0
     }
 70  
         
 71  
         /**
 72  
          * @return the permissionTypeServiceByNameCache
 73  
          */
 74  
         protected Map<String, KimPermissionTypeService> getPermissionTypeServiceByNameCache() {
 75  0
                 return this.permissionTypeServiceByNameCache;
 76  
         }
 77  
         
 78  
         protected void addRolesForPermissionsToCache( List<KimPermissionInfo> key, List<String> roleIds ) {
 79  0
             permissionToRoleCache.put( key, new MaxAgeSoftReference<List<String>>( CACHE_MAX_AGE_SECONDS, roleIds ) );
 80  0
     }
 81  
         
 82  
         protected List<String> getRolesForPermissionsFromCache( List<KimPermissionInfo> key ) {
 83  0
             List<String> roleIds = null; 
 84  0
             MaxAgeSoftReference<List<String>> cacheRef = permissionToRoleCache.get( key );
 85  0
             if ( cacheRef != null ) {
 86  0
                     roleIds = cacheRef.get();
 87  
             }
 88  0
             return roleIds;
 89  
     }
 90  
         
 91  
         protected String getPermissionImplByTemplateNameCacheKey( String namespaceCode, String permissionTemplateName ) {
 92  0
             return PERMISSION_IMPL_CACHE_PREFIX + namespaceCode + "-" + permissionTemplateName;
 93  
     }
 94  
     protected String getPermissionImplByNameCacheKey( String namespaceCode, String permissionName ) {
 95  0
             return PERMISSION_IMPL_NAME_CACHE_PREFIX + namespaceCode + "-" + permissionName;
 96  
     }
 97  
     protected String getPermissionImplByIdCacheKey( String permissionId ) {
 98  0
             return PERMISSION_IMPL_ID_CACHE_PREFIX + permissionId;
 99  
     }
 100  
     
 101  
         protected String getNewAttributeDataId(){
 102  0
                 SequenceAccessorService sas = getSequenceAccessorService();                
 103  0
                 Long nextSeq = sas.getNextAvailableSequenceNumber(
 104  
                                 KimConstants.SequenceNames.KRIM_ATTR_DATA_ID_S, 
 105  
                                 RoleMemberAttributeDataImpl.class );
 106  0
                 return nextSeq.toString();
 107  
     }
 108  
         
 109  
         protected SequenceAccessorService getSequenceAccessorService() {
 110  0
                 if ( sequenceAccessorService == null ) {
 111  0
                         sequenceAccessorService = KNSServiceLocator.getSequenceAccessorService();
 112  
                 }
 113  0
                 return sequenceAccessorService;
 114  
         }
 115  
         
 116  
         protected RiceCacheAdministrator getCacheAdministrator() {
 117  0
                 if ( cacheAdministrator == null ) {
 118  0
                         cacheAdministrator = KsbApiServiceLocator.getCacheAdministrator();
 119  
                 }
 120  0
                 return cacheAdministrator;
 121  
         }
 122  
 }