Coverage Report - org.kuali.rice.kns.kim.permission.PermissionTypeServiceBase
 
Classes in this File Line Coverage Branch Coverage Complexity
PermissionTypeServiceBase
0%
0/14
0%
0/12
3
 
 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.kns.kim.permission;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.kim.api.permission.Permission;
 20  
 import org.kuali.rice.kim.framework.permission.PermissionTypeService;
 21  
 import org.kuali.rice.kns.kim.type.DataDictionaryTypeServiceBase;
 22  
 
 23  
 import java.util.ArrayList;
 24  
 import java.util.Collections;
 25  
 import java.util.List;
 26  
 import java.util.Map;
 27  
 
 28  
 /**
 29  
  * @deprecated A krad integrated type service base class will be provided in the future.
 30  
  */
 31  
 @Deprecated
 32  0
 public class PermissionTypeServiceBase extends DataDictionaryTypeServiceBase implements PermissionTypeService {
 33  
 
 34  
         @Override
 35  
         public final List<Permission> getMatchingPermissions(Map<String, String> requestedDetails, List<Permission> permissionsList) {
 36  0
                 requestedDetails = translateInputAttributes(requestedDetails);
 37  0
                 validateRequiredAttributesAgainstReceived(requestedDetails);
 38  0
                 return Collections.unmodifiableList(performPermissionMatches(requestedDetails, permissionsList));
 39  
         }
 40  
 
 41  
         /**
 42  
          * Internal method for matching permissions.  Override this method to customize the matching behavior.
 43  
          * 
 44  
          * This base implementation uses the {@link #performMatch(Map, Map)} method
 45  
          * to perform an exact match on the permission details and return all that are equal.
 46  
          */
 47  
         protected List<Permission> performPermissionMatches(Map<String, String> requestedDetails, List<Permission> permissionsList) {
 48  0
                 List<Permission> matchingPermissions = new ArrayList<Permission>();
 49  0
                 for (Permission permission : permissionsList) {
 50  0
                         if ( performMatch(requestedDetails, permission.getAttributes()) ) {
 51  0
                                 matchingPermissions.add( permission );
 52  
                         }
 53  
                 }
 54  0
                 return matchingPermissions;
 55  
         }
 56  
         
 57  
         /**
 58  
          * 
 59  
          * Internal method for checking if property name matches
 60  
          * 
 61  
          * @param requestedDetailsPropertyName name of requested details property
 62  
          * @param permissionDetailsPropertyName name of permission details property
 63  
          * @return boolean 
 64  
          */
 65  
         protected boolean doesPropertyNameMatch(
 66  
                         String requestedDetailsPropertyName,
 67  
                         String permissionDetailsPropertyName) {
 68  0
                 if (StringUtils.isBlank(permissionDetailsPropertyName)) {
 69  0
                         return true;
 70  
                 }
 71  0
                 if ( requestedDetailsPropertyName == null ) {
 72  0
                     requestedDetailsPropertyName = ""; // prevent NPE
 73  
                 }
 74  0
                 return StringUtils.equals(requestedDetailsPropertyName, permissionDetailsPropertyName)
 75  
                                 || (requestedDetailsPropertyName.startsWith(permissionDetailsPropertyName+"."));
 76  
         }
 77  
 }