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