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.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.kim.bo.impl.KimAttributes; | |
23 | import org.kuali.rice.kim.bo.role.dto.KimPermissionInfo; | |
24 | import org.kuali.rice.kim.bo.types.dto.AttributeSet; | |
25 | import org.kuali.rice.kim.util.KimCommonUtils; | |
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 | * @see org.kuali.rice.kns.service.impl.DocumentTypePermissionTypeServiceImpl#performPermissionMatches(org.kuali.rice.kim.bo.types.dto.AttributeSet, java.util.List) | |
50 | */ | |
51 | @Override | |
52 | protected List<KimPermissionInfo> performPermissionMatches(AttributeSet requestedDetails, | |
53 | List<KimPermissionInfo> permissionsList) { | |
54 | 0 | List<KimPermissionInfo> matchingPermissions = new ArrayList<KimPermissionInfo>(); |
55 | // loop over the permissions, checking the non-document-related ones | |
56 | 0 | for ( KimPermissionInfo kpi : permissionsList ) { |
57 | 0 | if ( routeNodeMatches(requestedDetails, kpi.getDetails()) && |
58 | KimCommonUtils.doesPropertyNameMatch(requestedDetails.get(KimAttributes.PROPERTY_NAME), kpi.getDetails().get(KimAttributes.PROPERTY_NAME)) ) { | |
59 | 0 | matchingPermissions.add( kpi ); |
60 | } | |
61 | } | |
62 | // now, filter the list to just those for the current document | |
63 | 0 | matchingPermissions = super.performPermissionMatches( requestedDetails, matchingPermissions ); |
64 | 0 | return matchingPermissions; |
65 | } | |
66 | ||
67 | protected boolean routeNodeMatches(AttributeSet requestedDetails, AttributeSet permissionDetails) { | |
68 | 0 | if ( StringUtils.isBlank( permissionDetails.get(KimAttributes.ROUTE_NODE_NAME) ) ) { |
69 | 0 | return true; |
70 | } | |
71 | 0 | return KimCommonUtils.isAttributeSetEntryEquals( requestedDetails, permissionDetails, |
72 | KimAttributes.ROUTE_NODE_NAME ); | |
73 | } | |
74 | } |