| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ComponentFieldPermissionTypeServiceImpl |
|
| 10.0;10 |
| 1 | /* | |
| 2 | * Copyright 2007-2008 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.krad.service.impl; | |
| 17 | ||
| 18 | import org.apache.commons.lang.StringUtils; | |
| 19 | import org.kuali.rice.kim.api.permission.Permission; | |
| 20 | import org.kuali.rice.kim.impl.permission.PermissionBo; | |
| 21 | import org.kuali.rice.kim.service.support.impl.KimPermissionTypeServiceBase; | |
| 22 | import org.kuali.rice.kim.util.KimConstants; | |
| 23 | ||
| 24 | import java.util.ArrayList; | |
| 25 | import java.util.List; | |
| 26 | import java.util.Map; | |
| 27 | ||
| 28 | /** | |
| 29 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 30 | */ | |
| 31 | 0 | public class ComponentFieldPermissionTypeServiceImpl extends KimPermissionTypeServiceBase { |
| 32 | ||
| 33 | /** | |
| 34 | * Compare the component and property names between the request and matching permissions. | |
| 35 | * Make entries with a matching property name take precedence over those with blank property | |
| 36 | * names on the stored permissions. Only match entries with blank property names if | |
| 37 | * no entries match on the exact property name. | |
| 38 | */ | |
| 39 | @Override | |
| 40 | protected List<Permission> performPermissionMatches(Map<String, String> requestedDetails, | |
| 41 | List<Permission> permissionsList) { | |
| 42 | 0 | List<Permission> propertyMatches = new ArrayList<Permission>(); |
| 43 | 0 | List<Permission> prefixPropertyMatches = new ArrayList<Permission>(); |
| 44 | 0 | List<Permission> blankPropertyMatches = new ArrayList<Permission>(); |
| 45 | 0 | String propertyName = requestedDetails.get(KimConstants.AttributeConstants.PROPERTY_NAME); |
| 46 | 0 | String componentName = requestedDetails.get(KimConstants.AttributeConstants.COMPONENT_NAME); |
| 47 | 0 | for ( Permission kpi : permissionsList ) { |
| 48 | 0 | PermissionBo bo = PermissionBo.from(kpi); |
| 49 | 0 | if ( StringUtils.equals( componentName, bo.getDetails().get( KimConstants.AttributeConstants.COMPONENT_NAME ) ) ) { |
| 50 | 0 | String permPropertyName = bo.getDetails().get(KimConstants.AttributeConstants.PROPERTY_NAME); |
| 51 | 0 | if ( StringUtils.isBlank( permPropertyName ) ) { |
| 52 | 0 | blankPropertyMatches.add( kpi ); |
| 53 | 0 | } else if ( StringUtils.equals( propertyName, permPropertyName ) ) { |
| 54 | 0 | propertyMatches.add( kpi ); |
| 55 | 0 | } else if ( doesPropertyNameMatch(propertyName, permPropertyName) ) { |
| 56 | 0 | prefixPropertyMatches.add( kpi ); |
| 57 | } | |
| 58 | } | |
| 59 | 0 | } |
| 60 | 0 | if ( !propertyMatches.isEmpty() ) { |
| 61 | 0 | return propertyMatches; |
| 62 | 0 | } else if ( !prefixPropertyMatches.isEmpty() ) { |
| 63 | 0 | return prefixPropertyMatches; |
| 64 | } else { | |
| 65 | 0 | return blankPropertyMatches; |
| 66 | } | |
| 67 | } | |
| 68 | ||
| 69 | } |