1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.service.impl; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.HashSet; |
20 | |
import java.util.List; |
21 | |
import java.util.Set; |
22 | |
|
23 | |
import org.apache.commons.lang.StringUtils; |
24 | |
import org.kuali.rice.core.xml.dto.AttributeSet; |
25 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
26 | |
import org.kuali.rice.kew.doctype.service.DocumentTypeService; |
27 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
28 | |
import org.kuali.rice.kim.bo.role.dto.KimPermissionInfo; |
29 | |
import org.kuali.rice.kim.service.support.impl.KimPermissionTypeServiceBase; |
30 | |
import org.kuali.rice.kim.util.KimConstants; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class DocumentTypePermissionTypeServiceImpl extends KimPermissionTypeServiceBase { |
40 | |
protected transient DocumentTypeService documentTypeService; |
41 | |
|
42 | |
{ |
43 | 0 | requiredAttributes.add( KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME ); |
44 | 0 | checkRequiredAttributes = true; |
45 | 0 | } |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
@Override |
55 | |
protected List<KimPermissionInfo> performPermissionMatches(AttributeSet requestedDetails, |
56 | |
List<KimPermissionInfo> permissionsList) { |
57 | |
|
58 | 0 | Set<String> permissionDocTypeNames = new HashSet<String>( permissionsList.size() ); |
59 | 0 | for ( KimPermissionInfo kpi : permissionsList ) { |
60 | 0 | String docTypeName = kpi.getDetails().get( KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME ); |
61 | 0 | if ( StringUtils.isNotBlank( docTypeName ) ) { |
62 | 0 | permissionDocTypeNames.add( docTypeName ); |
63 | |
} |
64 | 0 | } |
65 | |
|
66 | 0 | DocumentType docType = getDocumentTypeService().findByName(requestedDetails.get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME)); |
67 | 0 | String matchingDocTypeName = getClosestParentDocumentTypeName(docType, permissionDocTypeNames); |
68 | |
|
69 | |
|
70 | 0 | List<KimPermissionInfo> matchingPermissions = new ArrayList<KimPermissionInfo>(); |
71 | 0 | for ( KimPermissionInfo kpi : permissionsList ) { |
72 | 0 | String docTypeName = kpi.getDetails().get( KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME ); |
73 | |
|
74 | 0 | if((StringUtils.isEmpty(matchingDocTypeName) && StringUtils.equals(docTypeName,"*")) |
75 | |
|| (StringUtils.isNotEmpty(matchingDocTypeName) && matchingDocTypeName.equals(docTypeName))) { |
76 | 0 | matchingPermissions.add( kpi ); |
77 | |
} |
78 | 0 | } |
79 | |
|
80 | 0 | return matchingPermissions; |
81 | |
} |
82 | |
|
83 | |
protected DocumentTypeService getDocumentTypeService() { |
84 | 0 | if ( documentTypeService == null ) { |
85 | 0 | documentTypeService = KEWServiceLocator.getDocumentTypeService(); |
86 | |
} |
87 | 0 | return this.documentTypeService; |
88 | |
} |
89 | |
|
90 | |
} |