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