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.kew.doctype.bo.DocumentType; |
25 | |
import org.kuali.rice.kew.doctype.service.DocumentTypeService; |
26 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
27 | |
import org.kuali.rice.kim.bo.impl.KimAttributes; |
28 | |
import org.kuali.rice.kim.bo.role.dto.KimPermissionInfo; |
29 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
30 | |
import org.kuali.rice.kim.service.support.impl.KimPermissionTypeServiceBase; |
31 | |
import org.kuali.rice.kim.util.KimCommonUtils; |
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( KimAttributes.DOCUMENT_TYPE_NAME ); |
45 | 0 | checkRequiredAttributes = true; |
46 | 0 | } |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
@Override |
56 | |
protected List<KimPermissionInfo> performPermissionMatches(AttributeSet requestedDetails, |
57 | |
List<KimPermissionInfo> permissionsList) { |
58 | |
|
59 | 0 | Set<String> permissionDocTypeNames = new HashSet<String>( permissionsList.size() ); |
60 | 0 | for ( KimPermissionInfo kpi : permissionsList ) { |
61 | 0 | String docTypeName = kpi.getDetails().get( KimAttributes.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(KimAttributes.DOCUMENT_TYPE_NAME)); |
68 | 0 | String matchingDocTypeName = KimCommonUtils.getClosestParentDocumentTypeName(docType, permissionDocTypeNames); |
69 | |
|
70 | |
|
71 | 0 | List<KimPermissionInfo> matchingPermissions = new ArrayList<KimPermissionInfo>(); |
72 | 0 | for ( KimPermissionInfo kpi : permissionsList ) { |
73 | 0 | String docTypeName = kpi.getDetails().get( KimAttributes.DOCUMENT_TYPE_NAME ); |
74 | |
|
75 | 0 | if((StringUtils.isEmpty(matchingDocTypeName) && StringUtils.equals(docTypeName,"*")) |
76 | |
|| (StringUtils.isNotEmpty(matchingDocTypeName) && matchingDocTypeName.equals(docTypeName))) { |
77 | 0 | matchingPermissions.add( kpi ); |
78 | |
} |
79 | 0 | } |
80 | |
|
81 | 0 | return matchingPermissions; |
82 | |
} |
83 | |
|
84 | |
protected DocumentTypeService getDocumentTypeService() { |
85 | 0 | if ( documentTypeService == null ) { |
86 | 0 | documentTypeService = KEWServiceLocator.getDocumentTypeService(); |
87 | |
} |
88 | 0 | return this.documentTypeService; |
89 | |
} |
90 | |
|
91 | |
} |