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.api.KewApiServiceLocator; |
20 | |
import org.kuali.rice.kew.api.doctype.DocumentType; |
21 | |
import org.kuali.rice.kew.api.doctype.DocumentTypeService; |
22 | |
import org.kuali.rice.kim.api.KimConstants; |
23 | |
import org.kuali.rice.kim.api.permission.Permission; |
24 | |
import org.kuali.rice.kim.impl.permission.PermissionBo; |
25 | |
import org.kuali.rice.kns.kim.permission.PermissionTypeServiceBase; |
26 | |
|
27 | |
import java.util.ArrayList; |
28 | |
import java.util.Collections; |
29 | |
import java.util.HashSet; |
30 | |
import java.util.List; |
31 | |
import java.util.Map; |
32 | |
import java.util.Set; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class DocumentTypePermissionTypeServiceImpl extends PermissionTypeServiceBase { |
42 | |
protected transient DocumentTypeService documentTypeService; |
43 | |
|
44 | |
@Override |
45 | |
protected List<String> getRequiredAttributes() { |
46 | 0 | return Collections.singletonList(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME); |
47 | |
} |
48 | |
|
49 | |
@Override |
50 | |
protected boolean isCheckRequiredAttributes() { |
51 | 0 | return true; |
52 | |
} |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
@Override |
62 | |
protected List<Permission> performPermissionMatches(Map<String, String> requestedDetails, |
63 | |
List<Permission> permissionsList) { |
64 | |
|
65 | 0 | Set<String> permissionDocTypeNames = new HashSet<String>( permissionsList.size() ); |
66 | 0 | for ( Permission permission : permissionsList ) { |
67 | 0 | PermissionBo bo = PermissionBo.from(permission); |
68 | 0 | String docTypeName = bo.getDetails().get( KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME ); |
69 | 0 | if ( StringUtils.isNotBlank( docTypeName ) ) { |
70 | 0 | permissionDocTypeNames.add( docTypeName ); |
71 | |
} |
72 | 0 | } |
73 | |
|
74 | 0 | DocumentType docType = getDocumentTypeService().getDocumentTypeByName(requestedDetails.get(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME)); |
75 | 0 | String matchingDocTypeName = getClosestParentDocumentTypeName(docType, permissionDocTypeNames); |
76 | |
|
77 | |
|
78 | 0 | List<Permission> matchingPermissions = new ArrayList<Permission>(); |
79 | 0 | for ( Permission kpi : permissionsList ) { |
80 | 0 | PermissionBo bo = PermissionBo.from(kpi); |
81 | 0 | String docTypeName = bo.getDetails().get( KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME ); |
82 | |
|
83 | 0 | if((StringUtils.isEmpty(matchingDocTypeName) && StringUtils.equals(docTypeName,"*")) |
84 | |
|| (StringUtils.isNotEmpty(matchingDocTypeName) && matchingDocTypeName.equals(docTypeName))) { |
85 | 0 | matchingPermissions.add( kpi ); |
86 | |
} |
87 | 0 | } |
88 | |
|
89 | 0 | return matchingPermissions; |
90 | |
} |
91 | |
|
92 | |
protected DocumentTypeService getDocumentTypeService() { |
93 | 0 | if ( documentTypeService == null ) { |
94 | 0 | documentTypeService = KewApiServiceLocator.getDocumentTypeService(); |
95 | |
} |
96 | 0 | return this.documentTypeService; |
97 | |
} |
98 | |
|
99 | |
} |