Coverage Report - org.kuali.rice.kim.service.impl.PermissionServiceBase
 
Classes in this File Line Coverage Branch Coverage Complexity
PermissionServiceBase
0%
0/24
0%
0/6
1.273
 
 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 com.google.common.collect.MapMaker;
 19  
 import org.kuali.rice.kim.impl.permission.PermissionBo;
 20  
 import org.kuali.rice.kim.impl.role.RoleMemberAttributeDataBo;
 21  
 import org.kuali.rice.kim.service.support.KimPermissionTypeService;
 22  
 import org.kuali.rice.kim.util.KimConstants;
 23  
 import org.kuali.rice.krad.service.BusinessObjectService;
 24  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 25  
 import org.kuali.rice.krad.service.SequenceAccessorService;
 26  
 import org.kuali.rice.ksb.api.KsbApiServiceLocator;
 27  
 import org.kuali.rice.ksb.api.cache.RiceCacheAdministrator;
 28  
 
 29  
 import java.util.List;
 30  
 import java.util.Map;
 31  
 import java.util.concurrent.ConcurrentMap;
 32  
 import java.util.concurrent.TimeUnit;
 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 ConcurrentMap<List<PermissionBo>, List<String>> permissionToRoleCache = new MapMaker().expireAfterAccess(CACHE_MAX_AGE_SECONDS, TimeUnit.SECONDS).softValues().makeMap();//Collections.synchronizedMap(new HashMap<List<PermissionBo>, MaxAgeSoftReference<List<String>>>());
 53  
 
 54  
     // Not ThreadLocal or time limited- should not change during the life of the system
 55  0
         private ConcurrentMap<String,KimPermissionTypeService> permissionTypeServiceByNameCache = new MapMaker().makeMap();
 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 = KRADServiceLocator.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<PermissionBo> key, List<String> roleIds ) {
 79  0
             permissionToRoleCache.put(key, roleIds);
 80  0
     }
 81  
         
 82  
         protected List<String> getRolesForPermissionsFromCache( List<PermissionBo> key ) {
 83  0
             return permissionToRoleCache.get( key );
 84  
     }
 85  
         
 86  
         protected String getPermissionImplByTemplateNameCacheKey( String namespaceCode, String permissionTemplateName ) {
 87  0
             return PERMISSION_IMPL_CACHE_PREFIX + namespaceCode + "-" + permissionTemplateName;
 88  
     }
 89  
     protected String getPermissionImplByNameCacheKey( String namespaceCode, String permissionName ) {
 90  0
             return PERMISSION_IMPL_NAME_CACHE_PREFIX + namespaceCode + "-" + permissionName;
 91  
     }
 92  
     protected String getPermissionImplByIdCacheKey( String permissionId ) {
 93  0
             return PERMISSION_IMPL_ID_CACHE_PREFIX + permissionId;
 94  
     }
 95  
     
 96  
         protected String getNewAttributeDataId(){
 97  0
                 SequenceAccessorService sas = getSequenceAccessorService();                
 98  0
                 Long nextSeq = sas.getNextAvailableSequenceNumber(
 99  
                                 KimConstants.SequenceNames.KRIM_ATTR_DATA_ID_S, 
 100  
                                 RoleMemberAttributeDataBo.class );
 101  0
                 return nextSeq.toString();
 102  
     }
 103  
         
 104  
         protected SequenceAccessorService getSequenceAccessorService() {
 105  0
                 if ( sequenceAccessorService == null ) {
 106  0
                         sequenceAccessorService = KRADServiceLocator.getSequenceAccessorService();
 107  
                 }
 108  0
                 return sequenceAccessorService;
 109  
         }
 110  
         
 111  
         protected RiceCacheAdministrator getCacheAdministrator() {
 112  0
                 if ( cacheAdministrator == null ) {
 113  0
                         cacheAdministrator = KsbApiServiceLocator.getCacheAdministrator();
 114  
                 }
 115  0
                 return cacheAdministrator;
 116  
         }
 117  
 }