Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DocumentTypeAndNodeAndFieldsPermissionTypeServiceImpl |
|
| 3.5;3.5 |
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.util.KimConstants; | |
22 | ||
23 | import java.util.ArrayList; | |
24 | import java.util.List; | |
25 | import java.util.Map; | |
26 | ||
27 | /** | |
28 | * | |
29 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
30 | * | |
31 | */ | |
32 | 0 | public class DocumentTypeAndNodeAndFieldsPermissionTypeServiceImpl extends DocumentTypePermissionTypeServiceImpl { |
33 | ||
34 | { | |
35 | // requiredAttributes.add(KimAttributes.ROUTE_NODE_NAME); | |
36 | // requiredAttributes.add(KimAttributes.PROPERTY_NAME); | |
37 | 0 | checkRequiredAttributes = true; |
38 | 0 | } |
39 | ||
40 | /** | |
41 | * | |
42 | * consider the document type hierarchy - check for a permission that just specifies the document type first at each level | |
43 | * - then if you don't find that, check for the doc type and the node, then the doc type and the field. | |
44 | * | |
45 | * - if the field value passed in starts with the value on the permission detail it is a match. so... | |
46 | * permision detail sourceAccountingLines will match passed in value of sourceAccountingLines.amount and sourceAccountingLines | |
47 | * permission detail sourceAccountingLines.objectCode will match sourceAccountingLines.objectCode but not sourceAccountingLines | |
48 | */ | |
49 | @Override | |
50 | protected List<Permission> performPermissionMatches(Map<String, String> requestedDetails, | |
51 | List<Permission> permissionsList) { | |
52 | 0 | List<Permission> matchingPermissions = new ArrayList<Permission>(); |
53 | // loop over the permissions, checking the non-document-related ones | |
54 | 0 | for ( Permission kpi : permissionsList ) { |
55 | 0 | PermissionBo bo = PermissionBo.from(kpi); |
56 | 0 | if ( routeNodeMatches(requestedDetails, bo.getDetails()) && |
57 | doesPropertyNameMatch(requestedDetails.get(KimConstants.AttributeConstants.PROPERTY_NAME), bo.getDetails().get(KimConstants.AttributeConstants.PROPERTY_NAME)) ) { | |
58 | 0 | matchingPermissions.add( kpi ); |
59 | } | |
60 | 0 | } |
61 | // now, filter the list to just those for the current document | |
62 | 0 | matchingPermissions = super.performPermissionMatches( requestedDetails, matchingPermissions ); |
63 | 0 | return matchingPermissions; |
64 | } | |
65 | ||
66 | protected boolean routeNodeMatches(Map<String, String> requestedDetails, Map<String, String> permissionDetails) { | |
67 | 0 | if ( StringUtils.isBlank( permissionDetails.get(KimConstants.AttributeConstants.ROUTE_NODE_NAME) ) ) { |
68 | 0 | return true; |
69 | } | |
70 | 0 | return StringUtils.equals(requestedDetails.get(KimConstants.AttributeConstants.ROUTE_NODE_NAME), permissionDetails.get(KimConstants.AttributeConstants.ROUTE_NODE_NAME)); |
71 | } | |
72 | } |