Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DocumentTypeAndNodeOrStatePermissionTypeServiceImpl |
|
| 3.3333333333333335;3.333 |
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.util.KimConstants; | |
25 | ||
26 | /** | |
27 | * | |
28 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
29 | * | |
30 | */ | |
31 | 0 | public class DocumentTypeAndNodeOrStatePermissionTypeServiceImpl extends DocumentTypePermissionTypeServiceImpl { |
32 | ||
33 | { | |
34 | // requiredAttributes.add(KimAttributes.ROUTE_NODE_NAME); | |
35 | // requiredAttributes.add(KimAttributes.ROUTE_STATUS_CODE); | |
36 | 0 | } |
37 | ||
38 | /** | |
39 | * Permission type service which can check the route node and status as well as the document hierarchy. | |
40 | * | |
41 | * Permission should be able to (in addition to taking the routingStatus, routingNote, and documentTypeName attributes) | |
42 | * should take a documentNumber and retrieve those values from workflow before performing the comparison. | |
43 | * | |
44 | * consider the document type hierarchy - check for a permission that just specifies the document type first at each level | |
45 | * - then if you don't find that, check for the doc type and the node, then the doc type and the state. | |
46 | * | |
47 | * @see org.kuali.rice.kns.service.impl.DocumentTypePermissionTypeServiceImpl#performPermissionMatches(org.kuali.rice.core.util.AttributeSet, java.util.List) | |
48 | */ | |
49 | @Override | |
50 | protected List<KimPermissionInfo> performPermissionMatches(AttributeSet requestedDetails, | |
51 | List<KimPermissionInfo> permissionsList) { | |
52 | 0 | List<KimPermissionInfo> matchingPermissions = new ArrayList<KimPermissionInfo>(); |
53 | // loop over the permissions, checking the non-document-related ones | |
54 | 0 | for ( KimPermissionInfo kpi : permissionsList ) { |
55 | 0 | if ( routeNodeMatches(requestedDetails, kpi.getDetails()) && |
56 | routeStatusMatches(requestedDetails, kpi.getDetails())) { | |
57 | 0 | matchingPermissions.add( kpi ); |
58 | } | |
59 | } | |
60 | // now, filter the list to just those for the current document | |
61 | 0 | matchingPermissions = super.performPermissionMatches( requestedDetails, matchingPermissions ); |
62 | 0 | return matchingPermissions; |
63 | } | |
64 | ||
65 | protected boolean routeNodeMatches(AttributeSet requestedDetails, AttributeSet permissionDetails) { | |
66 | 0 | if ( StringUtils.isBlank( permissionDetails.get(KimConstants.AttributeConstants.ROUTE_NODE_NAME) ) ) { |
67 | 0 | return true; |
68 | } | |
69 | 0 | return StringUtils.equals( requestedDetails.get(KimConstants.AttributeConstants.ROUTE_NODE_NAME), permissionDetails.get(KimConstants.AttributeConstants.ROUTE_NODE_NAME)); |
70 | } | |
71 | ||
72 | protected boolean routeStatusMatches(AttributeSet requestedDetails, AttributeSet permissionDetails) { | |
73 | 0 | if ( StringUtils.isBlank( permissionDetails.get(KimConstants.AttributeConstants.ROUTE_STATUS_CODE) ) ) { |
74 | 0 | return true; |
75 | } | |
76 | 0 | return StringUtils.equals( requestedDetails.get(KimConstants.AttributeConstants.ROUTE_STATUS_CODE), permissionDetails.get(KimConstants.AttributeConstants.ROUTE_STATUS_CODE)); |
77 | } | |
78 | ||
79 | } |