Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
KimPermissionTypeServiceBase |
|
| 3.0;3 |
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.kim.service.support.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.impl.type.KimTypeServiceBase; | |
22 | import org.kuali.rice.kim.service.support.KimPermissionTypeService; | |
23 | ||
24 | import java.util.ArrayList; | |
25 | import java.util.List; | |
26 | import java.util.Map; | |
27 | ||
28 | /** | |
29 | * This is a description of what this class does - bhargavp don't forget to fill this in. | |
30 | * | |
31 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
32 | * | |
33 | */ | |
34 | 0 | public class KimPermissionTypeServiceBase extends KimTypeServiceBase implements KimPermissionTypeService { |
35 | ||
36 | @Override | |
37 | public final List<Permission> getMatchingPermissions(Map<String, String> requestedDetails, List<Permission> permissionsList) { | |
38 | 0 | requestedDetails = translateInputAttributes(requestedDetails); |
39 | 0 | validateRequiredAttributesAgainstReceived(requestedDetails); |
40 | 0 | return performPermissionMatches(requestedDetails, permissionsList); |
41 | } | |
42 | ||
43 | /** | |
44 | * Internal method for matching permissions. Override this method to customize the matching behavior. | |
45 | * | |
46 | * This base implementation uses the {@link #performMatch(Map<String, String>, Map<String, String>)} method | |
47 | * to perform an exact match on the permission details and return all that are equal. | |
48 | */ | |
49 | protected List<Permission> performPermissionMatches(Map<String, String> requestedDetails, List<Permission> permissionsList) { | |
50 | 0 | List<Permission> matchingPermissions = new ArrayList<Permission>(); |
51 | 0 | for (Permission permission : permissionsList) { |
52 | 0 | PermissionBo bo = PermissionBo.from(permission); |
53 | 0 | if ( performMatch(requestedDetails, bo.getDetails()) ) { |
54 | 0 | matchingPermissions.add( permission ); |
55 | } | |
56 | 0 | } |
57 | 0 | return matchingPermissions; |
58 | } | |
59 | ||
60 | /** | |
61 | * | |
62 | * Internal method for checking if property name matches | |
63 | * | |
64 | * @param requestedDetailsPropertyName name of requested details property | |
65 | * @param permissionDetailsPropertyName name of permission details property | |
66 | * @return boolean | |
67 | */ | |
68 | protected boolean doesPropertyNameMatch( | |
69 | String requestedDetailsPropertyName, | |
70 | String permissionDetailsPropertyName) { | |
71 | 0 | if (StringUtils.isBlank(permissionDetailsPropertyName)) { |
72 | 0 | return true; |
73 | } | |
74 | 0 | if ( requestedDetailsPropertyName == null ) { |
75 | 0 | requestedDetailsPropertyName = ""; // prevent NPE |
76 | } | |
77 | 0 | return StringUtils.equals(requestedDetailsPropertyName, permissionDetailsPropertyName) |
78 | || (requestedDetailsPropertyName.startsWith(permissionDetailsPropertyName+".")); | |
79 | } | |
80 | } |