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