1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.api.cache;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.kim.api.permission.Permission;
21 import org.kuali.rice.kim.api.permission.PermissionService;
22 import org.kuali.rice.kim.api.responsibility.Responsibility;
23 import org.kuali.rice.kim.api.responsibility.ResponsibilityService;
24 import org.kuali.rice.kim.api.role.RoleService;
25 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
26
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.List;
30
31
32 public final class KimCacheUtils {
33
34 private KimCacheUtils() {
35 throw new UnsupportedOperationException();
36 }
37
38
39
40
41
42
43
44
45 public static boolean isDynamicRoleMembership(List<String> roleIds) {
46 if (CollectionUtils.isEmpty(roleIds)) {
47 return false;
48 }
49 RoleService roleService = KimApiServiceLocator.getRoleService();
50 for (String roleId : roleIds) {
51 if (roleService.isDynamicRoleMembership(roleId)) {
52 return true;
53 }
54 }
55 return false;
56 }
57
58
59
60
61
62
63
64
65
66 public static boolean isDynamicMembshipRoleByNamespaceAndName(String namespaceCode, String roleName) {
67 List<String> roleIds = Collections.singletonList(
68 KimApiServiceLocator.getRoleService().getRoleIdByNamespaceCodeAndName(namespaceCode, roleName));
69 return isDynamicRoleMembership(roleIds);
70 }
71
72
73
74
75
76
77
78
79 public static boolean isResponsibilityIdAssignedToDynamicRole(String responsibilityId) {
80 if ( StringUtils.isBlank(responsibilityId)) {
81 return false;
82 }
83
84 List<String> roleIds = KimApiServiceLocator.getResponsibilityService().getRoleIdsForResponsibility(responsibilityId);
85 return isDynamicRoleMembership(roleIds);
86 }
87
88
89
90
91
92
93
94
95
96 public static boolean isResponsibilityAssignedToDynamicRole(String namespaceCode, String responsibilityName) {
97 if (StringUtils.isBlank(namespaceCode) || StringUtils.isBlank(responsibilityName)) {
98 return false;
99 }
100 Responsibility responsibility = KimApiServiceLocator.getResponsibilityService().findRespByNamespaceCodeAndName(namespaceCode, responsibilityName);
101
102 if (responsibility != null) {
103 return isResponsibilityIdAssignedToDynamicRole(responsibility.getId());
104 }
105 return false;
106 }
107
108
109
110
111
112
113
114
115
116 public static boolean isResponsibilityTemplateAssignedToDynamicRole(String namespaceCode,
117 String responsibilityTemplateName) {
118 if (StringUtils.isBlank(namespaceCode) || StringUtils.isBlank(responsibilityTemplateName)) {
119 return false;
120 }
121 ResponsibilityService respService = KimApiServiceLocator.getResponsibilityService();
122 List<Responsibility> responsibilities = KimApiServiceLocator.getResponsibilityService().findResponsibilitiesByTemplate(namespaceCode, responsibilityTemplateName);
123 List<String> roleIds = new ArrayList<String>();
124 for (Responsibility resp : responsibilities) {
125 roleIds.addAll(respService.getRoleIdsForResponsibility(resp.getId()));
126 }
127
128 return isDynamicRoleMembership(roleIds);
129 }
130
131 }