1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.dao.impl; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collection; |
20 | |
import java.util.HashMap; |
21 | |
import java.util.List; |
22 | |
import java.util.Map; |
23 | |
import java.util.Map.Entry; |
24 | |
|
25 | |
import javax.persistence.EntityManager; |
26 | |
import javax.persistence.PersistenceContext; |
27 | |
|
28 | |
import org.apache.commons.collections.CollectionUtils; |
29 | |
import org.apache.commons.lang.StringUtils; |
30 | |
import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria; |
31 | |
import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria; |
32 | |
import org.kuali.rice.core.xml.dto.AttributeSet; |
33 | |
import org.kuali.rice.kim.bo.Role; |
34 | |
import org.kuali.rice.kim.bo.entity.KimPrincipal; |
35 | |
import org.kuali.rice.kim.bo.entity.dto.KimEntityDefaultInfo; |
36 | |
import org.kuali.rice.kim.bo.group.dto.GroupMembershipInfo; |
37 | |
import org.kuali.rice.kim.bo.impl.RoleImpl; |
38 | |
import org.kuali.rice.kim.bo.role.dto.KimPermissionInfo; |
39 | |
import org.kuali.rice.kim.bo.role.dto.KimResponsibilityInfo; |
40 | |
import org.kuali.rice.kim.bo.role.dto.RoleMemberCompleteInfo; |
41 | |
import org.kuali.rice.kim.bo.role.dto.RoleMembershipInfo; |
42 | |
import org.kuali.rice.kim.bo.role.impl.KimDelegationImpl; |
43 | |
import org.kuali.rice.kim.bo.role.impl.KimDelegationMemberImpl; |
44 | |
import org.kuali.rice.kim.bo.role.impl.RoleMemberAttributeDataImpl; |
45 | |
import org.kuali.rice.kim.bo.role.impl.RoleMemberImpl; |
46 | |
import org.kuali.rice.kim.dao.KimRoleDao; |
47 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
48 | |
import org.kuali.rice.kim.util.KIMPropertyConstants; |
49 | |
import org.kuali.rice.kim.util.KimConstants; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | 0 | public class KimRoleDaoJpa implements KimRoleDao { |
59 | |
|
60 | |
@PersistenceContext(unitName="kim-unit") |
61 | |
private EntityManager entityManager; |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
@SuppressWarnings("unchecked") |
68 | |
public List<RoleMemberImpl> getRolePrincipalsForPrincipalIdAndRoleIds( Collection<String> roleIds, String principalId) { |
69 | |
|
70 | 0 | Criteria c = new Criteria(RoleMemberImpl.class.getName()); |
71 | |
|
72 | 0 | if ( roleIds != null ) { |
73 | 0 | c.in(KIMPropertyConstants.RoleMember.ROLE_ID, new ArrayList(roleIds)); |
74 | |
} |
75 | 0 | if(principalId!=null){ |
76 | 0 | c.eq(KIMPropertyConstants.RoleMember.MEMBER_ID, principalId); |
77 | |
} |
78 | 0 | c.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.PRINCIPAL_MEMBER_TYPE ); |
79 | 0 | ArrayList<RoleMemberImpl> coll = (ArrayList<RoleMemberImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
80 | 0 | ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() ); |
81 | 0 | for ( RoleMemberImpl rm : coll ) { |
82 | 0 | if ( rm.isActive() ) { |
83 | 0 | results.add(rm); |
84 | |
} |
85 | |
} |
86 | 0 | return results; |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
public List<GroupMembershipInfo> getGroupPrincipalsForPrincipalIdAndGroupIds( Collection<String> groupIds, String principalId) { |
94 | 0 | List<String> groupIdValues = new ArrayList<String>(); |
95 | 0 | List<GroupMembershipInfo> groupPrincipals = new ArrayList<GroupMembershipInfo>(); |
96 | 0 | if (groupIds != null |
97 | |
&& principalId == null) { |
98 | 0 | groupIdValues = new ArrayList<String>(groupIds); |
99 | 0 | } else if (principalId != null) { |
100 | 0 | groupIdValues = KIMServiceLocator.getGroupService().getGroupIdsForPrincipal(principalId); |
101 | |
} |
102 | 0 | if (groupIdValues != null |
103 | |
&& groupIdValues.size() > 0) { |
104 | 0 | Collection<GroupMembershipInfo> groupMembershipInfos = KIMServiceLocator.getGroupService().getGroupMembers(groupIdValues); |
105 | 0 | for (GroupMembershipInfo groupMembershipInfo : groupMembershipInfos) { |
106 | 0 | if (principalId != null) { |
107 | 0 | if (StringUtils.equals(groupMembershipInfo.getMemberTypeCode(), Role.PRINCIPAL_MEMBER_TYPE) |
108 | |
&& StringUtils.equals(principalId, groupMembershipInfo.getMemberId()) |
109 | |
&& groupMembershipInfo.isActive()) { |
110 | 0 | groupPrincipals.add(groupMembershipInfo); |
111 | |
} |
112 | |
} else { |
113 | 0 | groupPrincipals.add(groupMembershipInfo); |
114 | |
} |
115 | |
} |
116 | |
} |
117 | 0 | return groupPrincipals; |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
public List<GroupMembershipInfo> getGroupMembers(Collection<String> groupIds) { |
125 | 0 | List<String> groupIdValues = new ArrayList<String>(); |
126 | 0 | List<GroupMembershipInfo> groupMembers = new ArrayList<GroupMembershipInfo>(); |
127 | 0 | if (groupIds != null) { |
128 | 0 | groupIdValues = new ArrayList<String>(groupIds); |
129 | |
|
130 | 0 | if (groupIdValues != null |
131 | |
&& groupIdValues.size() > 0) { |
132 | 0 | Collection<GroupMembershipInfo> groupMembershipInfos = KIMServiceLocator.getGroupService().getGroupMembers(groupIdValues); |
133 | 0 | if (groupMembershipInfos != null) { |
134 | 0 | groupMembers = new ArrayList<GroupMembershipInfo>(groupMembershipInfos); |
135 | |
} |
136 | |
|
137 | |
|
138 | |
|
139 | |
} |
140 | |
} |
141 | 0 | return groupMembers; |
142 | |
} |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
@SuppressWarnings("unchecked") |
149 | |
public List<RoleMemberImpl> getRoleGroupsForGroupIdsAndRoleIds( Collection<String> roleIds, Collection<String> groupIds ) { |
150 | 0 | Criteria c = new Criteria(RoleMemberImpl.class.getName()); |
151 | 0 | if(roleIds!=null && !roleIds.isEmpty()) |
152 | 0 | c.in(KIMPropertyConstants.RoleMember.ROLE_ID, new ArrayList(roleIds)); |
153 | 0 | if(groupIds!=null && !groupIds.isEmpty()) |
154 | 0 | c.in(KIMPropertyConstants.RoleMember.MEMBER_ID, new ArrayList(groupIds)); |
155 | 0 | c.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.GROUP_MEMBER_TYPE ); |
156 | |
|
157 | 0 | ArrayList<RoleMemberImpl> coll = (ArrayList<RoleMemberImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
158 | 0 | ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() ); |
159 | 0 | for ( RoleMemberImpl rm : coll ) { |
160 | 0 | if ( rm.isActive() ) { |
161 | 0 | results.add(rm); |
162 | |
} |
163 | |
} |
164 | 0 | return results; |
165 | |
} |
166 | |
|
167 | |
@SuppressWarnings("unchecked") |
168 | |
public Map<String,KimDelegationImpl> getDelegationImplMapFromRoleIds(Collection<String> roleIds) { |
169 | 0 | HashMap<String,KimDelegationImpl> results = new HashMap<String, KimDelegationImpl>(); |
170 | 0 | if ( roleIds != null && !roleIds.isEmpty() ) { |
171 | 0 | Criteria c = new Criteria(KimDelegationImpl.class.getName()); |
172 | 0 | c.in(KIMPropertyConstants.Delegation.ROLE_ID, new ArrayList(roleIds)); |
173 | 0 | c.eq(KIMPropertyConstants.Delegation.ACTIVE, Boolean.TRUE); |
174 | |
|
175 | 0 | ArrayList<KimDelegationImpl> coll = (ArrayList<KimDelegationImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
176 | 0 | for ( KimDelegationImpl dele : coll ) { |
177 | 0 | results.put( dele.getDelegationId(), dele); |
178 | |
} |
179 | |
} |
180 | 0 | return results; |
181 | |
} |
182 | |
|
183 | |
@SuppressWarnings("unchecked") |
184 | |
public List<KimDelegationImpl> getDelegationImplsForRoleIds(Collection<String> roleIds) { |
185 | 0 | List<KimDelegationImpl> results = new ArrayList<KimDelegationImpl>(); |
186 | 0 | if ( roleIds != null && !roleIds.isEmpty() ) { |
187 | 0 | Criteria c = new Criteria(KimDelegationImpl.class.getName()); |
188 | 0 | c.in(KIMPropertyConstants.Delegation.ROLE_ID, new ArrayList(roleIds)); |
189 | 0 | c.eq(KIMPropertyConstants.Delegation.ACTIVE, Boolean.TRUE); |
190 | |
|
191 | 0 | ArrayList<KimDelegationImpl> coll = (ArrayList<KimDelegationImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
192 | 0 | for ( KimDelegationImpl dele : coll ) { |
193 | 0 | results.add(dele); |
194 | |
} |
195 | |
} |
196 | 0 | return results; |
197 | |
} |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
@SuppressWarnings("unchecked") |
206 | |
public List<KimDelegationMemberImpl> getDelegationPrincipalsForPrincipalIdAndDelegationIds( |
207 | |
Collection<String> delegationIds, String principalId) { |
208 | 0 | Criteria c = new Criteria(KimDelegationMemberImpl.class.getName()); |
209 | |
|
210 | 0 | if(principalId!=null) { |
211 | 0 | c.eq(KIMPropertyConstants.DelegationMember.MEMBER_ID, principalId); |
212 | |
} |
213 | 0 | c.eq( KIMPropertyConstants.DelegationMember.MEMBER_TYPE_CODE, Role.PRINCIPAL_MEMBER_TYPE ); |
214 | 0 | if(delegationIds!=null && !delegationIds.isEmpty()) { |
215 | 0 | c.in(KIMPropertyConstants.DelegationMember.DELEGATION_ID, new ArrayList(delegationIds)); |
216 | |
} |
217 | 0 | ArrayList<KimDelegationMemberImpl> coll = (ArrayList<KimDelegationMemberImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
218 | 0 | ArrayList<KimDelegationMemberImpl> results = new ArrayList<KimDelegationMemberImpl>( coll.size() ); |
219 | 0 | for ( KimDelegationMemberImpl rm : coll ) { |
220 | 0 | if ( rm.isActive() ) { |
221 | 0 | results.add(rm); |
222 | |
} |
223 | |
} |
224 | 0 | return results; |
225 | |
} |
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
@SuppressWarnings("unchecked") |
234 | |
public List<KimDelegationMemberImpl> getDelegationGroupsForGroupIdsAndDelegationIds( |
235 | |
Collection<String> delegationIds, List<String> groupIds) { |
236 | 0 | Criteria c = new Criteria(KimDelegationMemberImpl.class.getName()); |
237 | 0 | if(delegationIds!=null && !delegationIds.isEmpty()) { |
238 | 0 | c.in(KIMPropertyConstants.DelegationMember.DELEGATION_ID, new ArrayList(delegationIds)); |
239 | |
} |
240 | 0 | if(groupIds!=null && !groupIds.isEmpty()) { |
241 | 0 | c.in(KIMPropertyConstants.DelegationMember.MEMBER_ID, groupIds); |
242 | |
} |
243 | 0 | c.eq( KIMPropertyConstants.DelegationMember.MEMBER_TYPE_CODE, Role.GROUP_MEMBER_TYPE ); |
244 | |
|
245 | 0 | ArrayList<KimDelegationMemberImpl> coll = (ArrayList<KimDelegationMemberImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
246 | 0 | ArrayList<KimDelegationMemberImpl> results = new ArrayList<KimDelegationMemberImpl>( coll.size() ); |
247 | 0 | for ( KimDelegationMemberImpl rm : coll ) { |
248 | 0 | if ( rm.isActive() ) { |
249 | 0 | results.add(rm); |
250 | |
} |
251 | |
} |
252 | 0 | return results; |
253 | |
} |
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
@SuppressWarnings("unchecked") |
259 | |
public List<RoleMemberImpl> getRoleMembersForRoleIds( Collection<String> roleIds, String memberTypeCode ) { |
260 | 0 | Criteria c = new Criteria(RoleMemberImpl.class.getName()); |
261 | |
|
262 | 0 | if(roleIds!=null && !roleIds.isEmpty()) { |
263 | 0 | c.in(KIMPropertyConstants.RoleMember.ROLE_ID, new ArrayList(roleIds)); |
264 | |
} |
265 | 0 | if ( memberTypeCode != null ) { |
266 | 0 | c.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, memberTypeCode ); |
267 | |
} |
268 | 0 | ArrayList<RoleMemberImpl> coll = (ArrayList<RoleMemberImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
269 | 0 | ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() ); |
270 | 0 | for ( RoleMemberImpl rm : coll ) { |
271 | 0 | if ( rm.isActive() ) { |
272 | 0 | results.add(rm); |
273 | |
} |
274 | |
} |
275 | 0 | return results; |
276 | |
} |
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
@SuppressWarnings("unchecked") |
282 | |
public List<RoleMemberImpl> getRoleMembershipsForRoleIdsAsMembers( Collection<String> roleIds) { |
283 | 0 | Criteria c = new Criteria(RoleMemberImpl.class.getName()); |
284 | |
|
285 | 0 | if(roleIds!=null && !roleIds.isEmpty()) { |
286 | 0 | c.in(KIMPropertyConstants.RoleMember.MEMBER_ID, new ArrayList(roleIds)); |
287 | |
} |
288 | 0 | c.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, KimConstants.KimUIConstants.MEMBER_TYPE_ROLE_CODE); |
289 | |
|
290 | 0 | ArrayList<RoleMemberImpl> coll = (ArrayList<RoleMemberImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
291 | 0 | ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() ); |
292 | 0 | for ( RoleMemberImpl rm : coll ) { |
293 | 0 | if ( rm.isActive() ) { |
294 | 0 | results.add(rm); |
295 | |
} |
296 | |
} |
297 | 0 | return results; |
298 | |
} |
299 | |
|
300 | |
@SuppressWarnings("unchecked") |
301 | |
public List<RoleMemberImpl> getRoleMembersForRoleIdsWithFilters( Collection<String> roleIds, String principalId, List<String> groupIds ) { |
302 | 0 | Criteria c = new Criteria(RoleMemberImpl.class.getName()); |
303 | |
|
304 | 0 | if(roleIds!=null && !roleIds.isEmpty()) { |
305 | 0 | c.in(KIMPropertyConstants.RoleMember.ROLE_ID, new ArrayList(roleIds)); |
306 | |
} |
307 | 0 | Criteria orSet = new Criteria(RoleMemberImpl.class.getName(), c.getAlias()); |
308 | 0 | orSet.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.ROLE_MEMBER_TYPE ); |
309 | 0 | Criteria principalCheck = new Criteria(RoleMemberImpl.class.getName(), c.getAlias()); |
310 | 0 | if(principalId!=null) { |
311 | 0 | principalCheck.eq(KIMPropertyConstants.RoleMember.MEMBER_ID, principalId); |
312 | |
} |
313 | 0 | principalCheck.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.PRINCIPAL_MEMBER_TYPE ); |
314 | 0 | orSet.or( principalCheck ); |
315 | 0 | Criteria groupCheck = new Criteria(RoleMemberImpl.class.getName(), c.getAlias()); |
316 | 0 | if(groupIds!=null && !groupIds.isEmpty()) { |
317 | 0 | groupCheck.in(KIMPropertyConstants.RoleMember.MEMBER_ID, groupIds); |
318 | |
} |
319 | 0 | groupCheck.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.GROUP_MEMBER_TYPE ); |
320 | 0 | orSet.or( groupCheck ); |
321 | 0 | c.and( orSet ); |
322 | |
|
323 | 0 | ArrayList<RoleMemberImpl> coll = (ArrayList<RoleMemberImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
324 | 0 | ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() ); |
325 | 0 | for ( RoleMemberImpl rm : coll ) { |
326 | 0 | if ( rm.isActive() ) { |
327 | 0 | results.add(rm); |
328 | |
} |
329 | |
} |
330 | 0 | return results; |
331 | |
} |
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
@SuppressWarnings("unchecked") |
337 | |
public Map<String,List<KimDelegationMemberImpl>> getDelegationMembersForDelegationIds( |
338 | |
List<String> delegationIds) { |
339 | 0 | Criteria c = new Criteria(KimDelegationMemberImpl.class.getName()); |
340 | 0 | if(delegationIds!=null && !delegationIds.isEmpty()) { |
341 | 0 | c.in(KIMPropertyConstants.DelegationMember.DELEGATION_ID, delegationIds); |
342 | |
} |
343 | |
|
344 | 0 | ArrayList<KimDelegationMemberImpl> coll = (ArrayList<KimDelegationMemberImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
345 | 0 | HashMap<String,List<KimDelegationMemberImpl>> result = new HashMap<String,List<KimDelegationMemberImpl>>(); |
346 | 0 | for ( KimDelegationMemberImpl dp : coll ) { |
347 | 0 | if ( dp.isActive() ) { |
348 | 0 | if ( !result.containsKey( dp.getDelegationId() ) ) { |
349 | 0 | result.put( dp.getDelegationId(), new ArrayList<KimDelegationMemberImpl>() ); |
350 | |
} |
351 | 0 | result.get( dp.getDelegationId() ).add( dp ); |
352 | |
} |
353 | |
} |
354 | 0 | return result; |
355 | |
} |
356 | |
|
357 | |
public List<RoleImpl> getRoles(Map<String,String> fieldValues) { |
358 | 0 | Criteria crit = new Criteria(RoleImpl.class.getName()); |
359 | 0 | Map<String,Map<String,String>> critMap = setupCritMaps(fieldValues); |
360 | |
|
361 | |
|
362 | |
|
363 | 0 | Map<String,String> lookupNames = critMap.get("lookupNames"); |
364 | 0 | for (Entry<String, String> entry : lookupNames.entrySet()) { |
365 | 0 | if (StringUtils.isNotBlank(entry.getValue())) { |
366 | 0 | if (!entry.getKey().equals(KIMPropertyConstants.Principal.PRINCIPAL_NAME)) { |
367 | 0 | addLikeToCriteria(crit, entry.getKey(), entry.getValue()); |
368 | |
} else { |
369 | 0 | List roleIds = getRoleIdsForPrincipalName(entry.getValue()); |
370 | 0 | if (roleIds!=null && !roleIds.isEmpty()) { |
371 | 0 | crit.in(KIMPropertyConstants.Role.ROLE_ID, roleIds); |
372 | |
} else { |
373 | |
|
374 | 0 | roleIds.add("NOTFOUND"); |
375 | 0 | crit.in(KIMPropertyConstants.Role.ROLE_ID, roleIds); |
376 | |
} |
377 | 0 | } |
378 | |
} |
379 | |
} |
380 | 0 | if (!critMap.get("attr").isEmpty()) { |
381 | 0 | String kimTypeId=null; |
382 | 0 | for (Map.Entry<String,String> entry : fieldValues.entrySet()) { |
383 | 0 | if (entry.getKey().equals("kimTypeId")) { |
384 | 0 | kimTypeId=entry.getValue(); |
385 | 0 | break; |
386 | |
} |
387 | |
} |
388 | 0 | setupAttrCriteria(crit, critMap.get("attr"),kimTypeId); |
389 | |
} |
390 | 0 | if (!critMap.get("perm").isEmpty()) { |
391 | 0 | crit.exists(setupPermCriteria(critMap.get("perm"), crit)); |
392 | |
} |
393 | 0 | if (!critMap.get("resp").isEmpty()) { |
394 | 0 | crit.exists(setupRespCriteria(critMap.get("resp"), crit)); |
395 | |
} |
396 | 0 | if (!critMap.get("group").isEmpty()) { |
397 | 0 | crit.exists(setupGroupCriteria(critMap.get("group"), crit)); |
398 | |
} |
399 | |
|
400 | 0 | return (ArrayList<RoleImpl>) new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
401 | |
} |
402 | |
|
403 | |
private List<String> getPrincipalIdsForPrincipalName(String principalName){ |
404 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
405 | 0 | criteria.put("principals.principalName", principalName); |
406 | 0 | List<? extends KimEntityDefaultInfo> entities = KIMServiceLocator.getIdentityService().lookupEntityDefaultInfo(criteria, false); |
407 | |
|
408 | 0 | List<String> principalIds = new ArrayList<String>(); |
409 | 0 | for (KimEntityDefaultInfo entity : entities) { |
410 | 0 | for (KimPrincipal principal : entity.getPrincipals()) { |
411 | 0 | principalIds.add(principal.getPrincipalId()); |
412 | |
} |
413 | |
} |
414 | |
|
415 | 0 | return principalIds; |
416 | |
|
417 | |
} |
418 | |
|
419 | |
private List<String> getRoleIdsForPrincipalName(String value) { |
420 | 0 | String principalName = value.replace('*', '%'); |
421 | 0 | List<String> roleIds = new ArrayList<String>(); |
422 | 0 | Criteria memberSubCrit = new Criteria(RoleMemberImpl.class.getName()); |
423 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
424 | 0 | criteria.put("principals.principalName", principalName); |
425 | 0 | List<? extends KimEntityDefaultInfo> entities = KIMServiceLocator.getIdentityService().lookupEntityDefaultInfo(criteria, false); |
426 | 0 | if (entities == null |
427 | |
|| entities.size() == 0) { |
428 | 0 | return roleIds; |
429 | |
} |
430 | |
|
431 | 0 | List<String> principalIds = new ArrayList<String>(); |
432 | 0 | for (KimEntityDefaultInfo entity : entities) { |
433 | 0 | for (KimPrincipal principal : entity.getPrincipals()) { |
434 | 0 | principalIds.add(principal.getPrincipalId()); |
435 | |
} |
436 | |
} |
437 | 0 | if(principalIds!=null && !principalIds.isEmpty()){ |
438 | 0 | memberSubCrit.eq(KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.PRINCIPAL_MEMBER_TYPE); |
439 | 0 | memberSubCrit.in(KIMPropertyConstants.RoleMember.MEMBER_ID, principalIds); |
440 | |
|
441 | 0 | ArrayList<RoleMemberImpl> coll = (ArrayList<RoleMemberImpl>) new QueryByCriteria(entityManager, memberSubCrit).toQuery().getResultList(); |
442 | 0 | for (RoleMemberImpl roleMbr : coll) { |
443 | 0 | if (!roleIds.contains(roleMbr.getRoleId())) { |
444 | 0 | roleIds.add(roleMbr.getRoleId()); |
445 | |
} |
446 | |
} |
447 | |
} |
448 | |
|
449 | 0 | List<String> groupIds = new ArrayList<String>(); |
450 | 0 | for (String principalId : principalIds) { |
451 | 0 | List<String> principalGroupIds = KIMServiceLocator.getGroupService().getGroupIdsForPrincipal(principalId); |
452 | 0 | for (String groupId : principalGroupIds) { |
453 | 0 | if (!groupIds.contains(groupId)) { |
454 | 0 | groupIds.add(groupId); |
455 | |
} |
456 | |
} |
457 | 0 | } |
458 | |
|
459 | 0 | if(groupIds!=null && !groupIds.isEmpty()){ |
460 | 0 | Criteria grpRoleCrit = new Criteria(RoleMemberImpl.class.getName()); |
461 | 0 | grpRoleCrit.eq(KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.GROUP_MEMBER_TYPE); |
462 | 0 | grpRoleCrit.in(KIMPropertyConstants.RoleMember.MEMBER_ID, groupIds); |
463 | |
|
464 | 0 | ArrayList<RoleMemberImpl> roleMbrs = (ArrayList<RoleMemberImpl>) new QueryByCriteria(entityManager, grpRoleCrit).toQuery().getResultList(); |
465 | 0 | for (RoleMemberImpl roleMbr : roleMbrs) { |
466 | 0 | if (!roleIds.contains(roleMbr.getRoleId())) { |
467 | 0 | roleIds.add(roleMbr.getRoleId()); |
468 | |
} |
469 | |
} |
470 | |
} |
471 | |
|
472 | 0 | return roleIds; |
473 | |
} |
474 | |
|
475 | |
private Map setupCritMaps(Map<String,String> fieldValues) { |
476 | 0 | Map <String, Map> critMap = new HashMap(); |
477 | 0 | List permFieldName = new ArrayList(); |
478 | 0 | permFieldName.add("permName"); |
479 | 0 | permFieldName.add("permNamespaceCode"); |
480 | 0 | permFieldName.add("permTmplName"); |
481 | 0 | permFieldName.add("permTmplNamespaceCode"); |
482 | 0 | List respFieldName = new ArrayList(); |
483 | 0 | respFieldName.add("respName"); |
484 | 0 | respFieldName.add("respNamespaceCode"); |
485 | 0 | respFieldName.add("respTmplName"); |
486 | 0 | respFieldName.add("respTmplNamespaceCode"); |
487 | 0 | Map<String,String> permFieldMap = new HashMap<String,String>(); |
488 | 0 | Map<String,String> respFieldMap = new HashMap<String,String>(); |
489 | 0 | Map<String,String> attrFieldMap = new HashMap<String,String>(); |
490 | 0 | Map<String,String> groupFieldMap = new HashMap<String,String>(); |
491 | 0 | Map<String,String> lookupNamesMap = new HashMap<String,String>(); |
492 | |
|
493 | 0 | for (Entry<String, String> entry : fieldValues.entrySet()) { |
494 | 0 | if (StringUtils.isNotBlank(entry.getValue())) { |
495 | 0 | String nameValue = entry.getValue().replace('*', '%'); |
496 | 0 | if (permFieldName.contains(entry.getKey())) { |
497 | 0 | permFieldMap.put(entry.getKey(), nameValue); |
498 | 0 | } else if (respFieldName.contains(entry.getKey())) { |
499 | 0 | respFieldMap.put(entry.getKey(), nameValue); |
500 | 0 | } else if (entry.getKey().startsWith(KimConstants.AttributeConstants.GROUP_NAME)) { |
501 | 0 | groupFieldMap.put(entry.getKey(), nameValue); |
502 | 0 | } else if (entry.getKey().contains(".")) { |
503 | 0 | attrFieldMap.put(entry.getKey(), nameValue); |
504 | |
} else { |
505 | 0 | lookupNamesMap.put(entry.getKey(), nameValue); |
506 | |
} |
507 | 0 | } |
508 | |
} |
509 | |
|
510 | 0 | critMap.put("perm", permFieldMap); |
511 | 0 | critMap.put("resp", respFieldMap); |
512 | 0 | critMap.put("group", groupFieldMap); |
513 | 0 | critMap.put("attr", attrFieldMap); |
514 | 0 | critMap.put("lookupNames", lookupNamesMap); |
515 | 0 | return critMap; |
516 | |
} |
517 | |
|
518 | |
|
519 | |
private void setupAttrCriteria(Criteria crit, Map<String,String> attrCrit, String kimTypeId) { |
520 | 0 | for (Entry<String, String> entry : attrCrit.entrySet()) { |
521 | 0 | Criteria subCrit = new Criteria(RoleMemberImpl.class.getName()); |
522 | 0 | addLikeToCriteria(subCrit, "attributes.attributeValue",entry.getValue()); |
523 | 0 | addEqualToCriteria(subCrit, "attributes.kimAttributeId",entry.getKey().substring(entry.getKey().indexOf(".")+1, entry.getKey().length())); |
524 | 0 | addEqualToCriteria(subCrit, "attributes.kimTypeId", kimTypeId); |
525 | 0 | subCrit.eq("roleId", crit.getAlias() + "roleId"); |
526 | 0 | crit.exists(subCrit); |
527 | 0 | } |
528 | 0 | } |
529 | |
|
530 | |
private Criteria setupPermCriteria(Map<String,String> permCrit, Criteria parentCriteria) { |
531 | |
|
532 | 0 | Map<String,String> searchCrit = new HashMap<String, String>(); |
533 | |
|
534 | 0 | for (Entry<String, String> entry : permCrit.entrySet()) { |
535 | 0 | if (entry.getKey().equals("permTmplName") || entry.getKey().equals("permTmplNamespaceCode")) { |
536 | 0 | if (entry.getKey().equals("permTmplName")) { |
537 | 0 | searchCrit.put("template." + KimConstants.UniqueKeyConstants.PERMISSION_TEMPLATE_NAME,entry.getValue()); |
538 | |
|
539 | |
} else { |
540 | 0 | searchCrit.put("template." + KimConstants.UniqueKeyConstants.NAMESPACE_CODE,entry.getValue()); |
541 | |
} |
542 | |
} |
543 | |
|
544 | 0 | if (entry.getKey().equals("permName") || entry.getKey().equals("permNamespaceCode")) { |
545 | 0 | if (entry.getKey().equals("permName")) { |
546 | 0 | searchCrit.put(KimConstants.UniqueKeyConstants.PERMISSION_NAME, entry.getValue()); |
547 | |
} else { |
548 | 0 | searchCrit.put(KimConstants.UniqueKeyConstants.NAMESPACE_CODE,entry.getValue()); |
549 | |
|
550 | |
} |
551 | |
} |
552 | |
} |
553 | |
|
554 | 0 | List<KimPermissionInfo> permList = KIMServiceLocator.getPermissionService().lookupPermissions(searchCrit, true); |
555 | 0 | List<String> roleIds = null; |
556 | |
|
557 | 0 | if(permList != null && !permList.isEmpty()){ |
558 | 0 | roleIds = KIMServiceLocator.getPermissionService().getRoleIdsForPermissions(permList); |
559 | |
} |
560 | |
|
561 | 0 | if(roleIds == null || roleIds.isEmpty()){ |
562 | 0 | roleIds = new ArrayList<String>(); |
563 | 0 | roleIds.add("-1"); |
564 | |
} |
565 | |
|
566 | 0 | Criteria memberSubCrit = new Criteria(RoleImpl.class.getName()); |
567 | 0 | memberSubCrit.in("roleId", roleIds); |
568 | 0 | memberSubCrit.eq("roleId", parentCriteria.getAlias() + "roleId"); |
569 | 0 | return memberSubCrit; |
570 | |
|
571 | |
} |
572 | |
|
573 | |
private Criteria setupRespCriteria(Map<String,String> respCrit, Criteria parentCriteria) { |
574 | |
|
575 | |
try{ |
576 | |
|
577 | |
}catch(Exception ex){ |
578 | |
ex.printStackTrace(); |
579 | 0 | } |
580 | 0 | Map<String,String> searchCrit = new HashMap<String, String>(); |
581 | |
|
582 | 0 | for (Entry<String, String> entry : respCrit.entrySet()) { |
583 | 0 | if (entry.getKey().equals("respTmplName") || entry.getKey().equals("respTmplNamespaceCode")) { |
584 | 0 | if (entry.getKey().equals("respTmplName")) { |
585 | 0 | searchCrit.put("template." + KimConstants.UniqueKeyConstants.RESPONSIBILITY_TEMPLATE_NAME,entry.getValue()); |
586 | |
|
587 | |
} else { |
588 | 0 | searchCrit.put("template." + KimConstants.UniqueKeyConstants.NAMESPACE_CODE,entry.getValue()); |
589 | |
} |
590 | |
} |
591 | |
|
592 | 0 | if (entry.getKey().equals("respName") || entry.getKey().equals("respNamespaceCode")) { |
593 | 0 | if (entry.getKey().equals("respName")) { |
594 | 0 | searchCrit.put(KimConstants.UniqueKeyConstants.RESPONSIBILITY_NAME, entry.getValue()); |
595 | |
} else { |
596 | 0 | searchCrit.put(KimConstants.UniqueKeyConstants.NAMESPACE_CODE,entry.getValue()); |
597 | |
|
598 | |
} |
599 | |
} |
600 | |
} |
601 | |
|
602 | 0 | List<? extends KimResponsibilityInfo> kriList = KIMServiceLocator.getResponsibilityService().lookupResponsibilityInfo(searchCrit, true); |
603 | 0 | List<String> roleIds = new ArrayList<String>(); |
604 | |
|
605 | 0 | for(KimResponsibilityInfo kri : kriList){ |
606 | 0 | roleIds.addAll(KIMServiceLocator.getResponsibilityService().getRoleIdsForResponsibility(kri, null)); |
607 | |
} |
608 | |
|
609 | 0 | if(roleIds == null || roleIds.isEmpty()){ |
610 | 0 | roleIds = new ArrayList<String>(); |
611 | 0 | roleIds.add("-1"); |
612 | |
} |
613 | |
|
614 | 0 | Criteria memberSubCrit = new Criteria(RoleImpl.class.getName()); |
615 | 0 | memberSubCrit.in("roleId", roleIds); |
616 | 0 | memberSubCrit.eq("roleId", parentCriteria.getAlias() + "roleId"); |
617 | 0 | return memberSubCrit; |
618 | |
|
619 | |
} |
620 | |
|
621 | |
private Criteria setupGroupCriteria(Map<String,String> groupCrit, Criteria parentCriteria) { |
622 | |
|
623 | 0 | Map<String,String> searchCrit = new HashMap<String, String>(); |
624 | 0 | for (Entry<String, String> entry : groupCrit.entrySet()) { |
625 | 0 | if (entry.getKey().equals(KimConstants.AttributeConstants.GROUP_NAME)) { |
626 | 0 | searchCrit.put(entry.getKey(), entry.getValue()); |
627 | |
} else { |
628 | 0 | searchCrit.put(KimConstants.AttributeConstants.NAMESPACE_CODE, entry.getValue()); |
629 | |
} |
630 | |
} |
631 | |
|
632 | 0 | Criteria crit = new Criteria(RoleMemberImpl.class.getName()); |
633 | |
|
634 | 0 | List<String> groupIds = KIMServiceLocator.getGroupService().lookupGroupIds(searchCrit); |
635 | |
|
636 | 0 | if(groupIds == null || groupIds.isEmpty()){ |
637 | 0 | groupIds = new ArrayList<String>(); |
638 | 0 | groupIds.add("-1"); |
639 | |
} |
640 | 0 | crit.in("memberId", groupIds); |
641 | 0 | crit.eq("roleId", parentCriteria.getAlias() + "roleId"); |
642 | |
|
643 | 0 | return crit; |
644 | |
|
645 | |
} |
646 | |
|
647 | |
private void addLikeToCriteria(Criteria criteria, String propertyName, String propertyValue){ |
648 | 0 | String[] keyValues = getCaseInsensitiveValues(propertyName, propertyValue); |
649 | 0 | criteria.like(keyValues[0], keyValues[1]); |
650 | 0 | } |
651 | |
|
652 | |
private void addEqualToCriteria(Criteria criteria, String propertyName, String propertyValue){ |
653 | 0 | String[] keyValues = getCaseInsensitiveValues(propertyName, propertyValue); |
654 | 0 | criteria.eq(keyValues[0], keyValues[1]); |
655 | 0 | } |
656 | |
|
657 | |
private String[] getCaseInsensitiveValues(String propertyName, String propertyValue){ |
658 | 0 | String[] keyValues = new String[2]; |
659 | 0 | keyValues[0] = propertyName==null?"":"UPPER(__JPA_ALIAS[[0]]__." + propertyName + ")"; |
660 | 0 | keyValues[1] = propertyValue==null?"":propertyValue.toUpperCase(); |
661 | 0 | return keyValues; |
662 | |
} |
663 | |
|
664 | |
@SuppressWarnings("unchecked") |
665 | |
protected List<RoleMemberImpl> getRoleMemberImpls(Map<String, String> fieldValues){ |
666 | 0 | Criteria queryCriteria = new Criteria(RoleMemberImpl.class.getName()); |
667 | 0 | List<String> memberIds = new ArrayList<String>(); |
668 | 0 | if(hasExtraRoleMemberCriteria(fieldValues)){ |
669 | 0 | String memberName = fieldValues.get(KimConstants.KimUIConstants.MEMBER_NAME); |
670 | 0 | String memberNamespaceCode = fieldValues.get(KimConstants.KimUIConstants.MEMBER_NAMESPACE_CODE); |
671 | |
|
672 | |
|
673 | 0 | List<RoleImpl> roles = getRoleMembersRoles(memberNamespaceCode, memberName); |
674 | 0 | if(roles!=null){ |
675 | 0 | for(RoleImpl role: roles) |
676 | 0 | memberIds.add(role.getRoleId()); |
677 | |
} |
678 | |
|
679 | 0 | memberIds.addAll(this.getPrincipalIdsForPrincipalName(memberName)); |
680 | |
|
681 | 0 | memberIds.addAll(getRoleMembersGroupIds(memberNamespaceCode, memberName)); |
682 | |
|
683 | 0 | if(memberIds!=null && !memberIds.isEmpty()) |
684 | 0 | queryCriteria.in(KIMPropertyConstants.RoleMember.MEMBER_ID, memberIds); |
685 | |
} |
686 | 0 | if(hasCoreRoleMemberCriteria(fieldValues)){ |
687 | 0 | String roleMemberId = fieldValues.get(KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID); |
688 | 0 | String roleId = fieldValues.get(KimConstants.PrimaryKeyConstants.ROLE_ID); |
689 | 0 | String memberId = fieldValues.get(KimConstants.PrimaryKeyConstants.MEMBER_ID); |
690 | 0 | String memberTypeCode = fieldValues.get(KIMPropertyConstants.KimMember.MEMBER_TYPE_CODE); |
691 | 0 | String activeFromDate = fieldValues.get(KIMPropertyConstants.KimMember.ACTIVE_FROM_DATE); |
692 | 0 | String activeToDate = fieldValues.get(KIMPropertyConstants.KimMember.ACTIVE_TO_DATE); |
693 | |
|
694 | 0 | if(StringUtils.isNotEmpty(roleMemberId)) |
695 | 0 | addEqualToCriteria(queryCriteria, KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID, roleMemberId); |
696 | 0 | if(StringUtils.isNotEmpty(roleId)) |
697 | 0 | addEqualToCriteria(queryCriteria, KimConstants.PrimaryKeyConstants.ROLE_ID, roleId); |
698 | 0 | if(StringUtils.isNotEmpty(memberId)) |
699 | 0 | addEqualToCriteria(queryCriteria, KimConstants.PrimaryKeyConstants.MEMBER_ID, memberId); |
700 | 0 | if(StringUtils.isNotEmpty(memberTypeCode)) |
701 | 0 | addEqualToCriteria(queryCriteria, KIMPropertyConstants.KimMember.MEMBER_TYPE_CODE, memberTypeCode); |
702 | 0 | if(StringUtils.isNotEmpty(activeFromDate)) |
703 | 0 | queryCriteria.gte(KIMPropertyConstants.KimMember.ACTIVE_FROM_DATE, activeFromDate); |
704 | 0 | if(StringUtils.isNotEmpty(activeToDate)) |
705 | 0 | queryCriteria.lte(KIMPropertyConstants.KimMember.ACTIVE_TO_DATE, activeToDate); |
706 | |
} |
707 | |
|
708 | 0 | return (List<RoleMemberImpl>)new QueryByCriteria(entityManager, queryCriteria).toQuery().getResultList(); |
709 | |
} |
710 | |
|
711 | |
public List<RoleMembershipInfo> getRoleMembers(Map<String,String> fieldValues) { |
712 | 0 | List<RoleMemberImpl> roleMembers = getRoleMemberImpls(fieldValues); |
713 | 0 | List<RoleMembershipInfo> roleMemberships = new ArrayList<RoleMembershipInfo>(); |
714 | |
RoleMembershipInfo roleMembership; |
715 | 0 | for(RoleMemberImpl roleMember: roleMembers){ |
716 | 0 | roleMembership = new RoleMembershipInfo(roleMember.getRoleId(), roleMember.getRoleMemberId(), roleMember.getMemberId(), roleMember.getMemberTypeCode(), roleMember.getQualifier() ); |
717 | 0 | roleMemberships.add(roleMembership); |
718 | |
} |
719 | 0 | return roleMemberships; |
720 | |
} |
721 | |
|
722 | |
public List<RoleMemberCompleteInfo> getRoleMembersCompleteInfo(Map<String,String> fieldValues) { |
723 | 0 | List<RoleMemberImpl> roleMembers = getRoleMemberImpls(fieldValues); |
724 | 0 | List<RoleMemberCompleteInfo> roleMembersCompleteInfo = new ArrayList<RoleMemberCompleteInfo>(); |
725 | |
RoleMemberCompleteInfo roleMemberCompleteInfo; |
726 | 0 | for(RoleMemberImpl roleMember: roleMembers){ |
727 | 0 | roleMemberCompleteInfo = new RoleMemberCompleteInfo( |
728 | |
roleMember.getRoleId(), roleMember.getRoleMemberId(), roleMember.getMemberId(), |
729 | |
roleMember.getMemberTypeCode(), roleMember.getActiveFromDate(), roleMember.getActiveToDate(), |
730 | |
roleMember.getQualifier() ); |
731 | 0 | roleMembersCompleteInfo.add(roleMemberCompleteInfo); |
732 | |
} |
733 | 0 | return roleMembersCompleteInfo; |
734 | |
} |
735 | |
|
736 | |
private boolean hasCoreRoleMemberCriteria(Map<String, String> fieldValues){ |
737 | 0 | return StringUtils.isNotEmpty(fieldValues.get(KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID)) || |
738 | |
StringUtils.isNotEmpty(fieldValues.get(KimConstants.PrimaryKeyConstants.ROLE_ID)) || |
739 | |
StringUtils.isNotEmpty(fieldValues.get(KimConstants.PrimaryKeyConstants.MEMBER_ID)) || |
740 | |
StringUtils.isNotEmpty(fieldValues.get(KIMPropertyConstants.KimMember.MEMBER_TYPE_CODE)) || |
741 | |
StringUtils.isNotEmpty(fieldValues.get(KIMPropertyConstants.KimMember.ACTIVE_FROM_DATE)) || |
742 | |
StringUtils.isNotEmpty(fieldValues.get(KIMPropertyConstants.KimMember.ACTIVE_TO_DATE)); |
743 | |
} |
744 | |
|
745 | |
private boolean hasExtraRoleMemberCriteria(Map<String, String> fieldValues){ |
746 | 0 | return StringUtils.isNotEmpty(fieldValues.get(KimConstants.KimUIConstants.MEMBER_NAME)) || |
747 | |
StringUtils.isNotEmpty(fieldValues.get(KimConstants.KimUIConstants.MEMBER_NAMESPACE_CODE)); |
748 | |
} |
749 | |
|
750 | |
@SuppressWarnings("unchecked") |
751 | |
private List<RoleImpl> getRoleMembersRoles(String memberNamespaceCode, String memberName){ |
752 | 0 | Criteria queryCriteria = new Criteria(RoleImpl.class.getName()); |
753 | 0 | addEqualToCriteria(queryCriteria, KimConstants.UniqueKeyConstants.NAMESPACE_CODE, memberNamespaceCode); |
754 | 0 | addEqualToCriteria(queryCriteria, KimConstants.UniqueKeyConstants.ROLE_NAME, memberName); |
755 | |
|
756 | 0 | return (List<RoleImpl>)new QueryByCriteria(entityManager, queryCriteria).toQuery().getResultList(); |
757 | |
} |
758 | |
|
759 | |
private List<String> getRoleMembersGroupIds(String memberNamespaceCode, String memberName){ |
760 | |
|
761 | 0 | Map<String,String> searchCrit = new HashMap<String, String>(); |
762 | 0 | searchCrit.put(KimConstants.AttributeConstants.GROUP_NAME, memberName); |
763 | 0 | searchCrit.put(KimConstants.AttributeConstants.NAMESPACE_CODE, memberNamespaceCode); |
764 | |
|
765 | 0 | return KIMServiceLocator.getGroupService().lookupGroupIds(searchCrit); |
766 | |
} |
767 | |
|
768 | |
public EntityManager getEntityManager() { |
769 | 0 | return this.entityManager; |
770 | |
} |
771 | |
|
772 | |
public void setEntityManager(EntityManager entityManager) { |
773 | 0 | this.entityManager = entityManager; |
774 | 0 | } |
775 | |
|
776 | |
|
777 | |
|
778 | |
|
779 | |
public List<RoleMemberImpl> getRoleGroupsForGroupIdsAndRoleIds( |
780 | |
Collection<String> roleIds, Collection<String> groupIds, |
781 | |
AttributeSet qualification) { |
782 | 0 | Criteria c = new Criteria(RoleMemberImpl.class.getName()); |
783 | 0 | if(roleIds!=null && !roleIds.isEmpty()) |
784 | 0 | c.in(KIMPropertyConstants.RoleMember.ROLE_ID, roleIds); |
785 | 0 | if(groupIds!=null && !groupIds.isEmpty()) |
786 | 0 | c.in(KIMPropertyConstants.RoleMember.MEMBER_ID, groupIds); |
787 | 0 | c.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.GROUP_MEMBER_TYPE ); |
788 | 0 | addSubCriteriaBasedOnRoleQualification(c, qualification); |
789 | |
|
790 | 0 | Collection<RoleMemberImpl> coll = (Collection<RoleMemberImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
791 | 0 | ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() ); |
792 | 0 | for ( RoleMemberImpl rm : coll ) { |
793 | 0 | if ( rm.isActive() ) { |
794 | 0 | results.add(rm); |
795 | |
} |
796 | |
} |
797 | 0 | return results; |
798 | |
} |
799 | |
|
800 | |
|
801 | |
|
802 | |
|
803 | |
public List<RoleMemberImpl> getRoleMembersForRoleIds( |
804 | |
Collection<String> roleIds, String memberTypeCode, |
805 | |
AttributeSet qualification) { |
806 | 0 | Criteria c = new Criteria(RoleMemberImpl.class.getName()); |
807 | |
|
808 | 0 | if(roleIds!=null && !roleIds.isEmpty()) |
809 | 0 | c.in(KIMPropertyConstants.RoleMember.ROLE_ID, roleIds); |
810 | 0 | if ( memberTypeCode != null ) { |
811 | 0 | c.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, memberTypeCode ); |
812 | |
} |
813 | 0 | addSubCriteriaBasedOnRoleQualification(c, qualification); |
814 | |
|
815 | 0 | Collection<RoleMemberImpl> coll = (Collection<RoleMemberImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
816 | 0 | ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() ); |
817 | 0 | for ( RoleMemberImpl rm : coll ) { |
818 | 0 | if ( rm.isActive() ) { |
819 | 0 | results.add(rm); |
820 | |
} |
821 | |
} |
822 | 0 | return results; |
823 | |
} |
824 | |
|
825 | |
|
826 | |
|
827 | |
|
828 | |
public List<RoleMemberImpl> getRoleMembersForRoleIdsWithFilters( |
829 | |
Collection<String> roleIds, String principalId, |
830 | |
List<String> groupIds, AttributeSet qualification) { |
831 | 0 | Criteria c = new Criteria(RoleMemberImpl.class.getName()); |
832 | |
|
833 | 0 | if(roleIds!=null && !roleIds.isEmpty()) |
834 | 0 | c.in(KIMPropertyConstants.RoleMember.ROLE_ID, roleIds); |
835 | 0 | Criteria orSet = new Criteria(RoleMemberImpl.class.getName()); |
836 | 0 | orSet.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.ROLE_MEMBER_TYPE ); |
837 | 0 | Criteria principalCheck = new Criteria(RoleMemberImpl.class.getName()); |
838 | 0 | if(principalId!=null) |
839 | 0 | principalCheck.eq(KIMPropertyConstants.RoleMember.MEMBER_ID, principalId); |
840 | 0 | principalCheck.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.PRINCIPAL_MEMBER_TYPE ); |
841 | 0 | orSet.or( principalCheck ); |
842 | 0 | Criteria groupCheck = new Criteria(RoleMemberImpl.class.getName()); |
843 | 0 | if(groupIds!=null && !groupIds.isEmpty()) |
844 | 0 | groupCheck.in(KIMPropertyConstants.RoleMember.MEMBER_ID, groupIds); |
845 | 0 | groupCheck.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.GROUP_MEMBER_TYPE ); |
846 | 0 | orSet.or( groupCheck ); |
847 | 0 | c.and( orSet ); |
848 | 0 | addSubCriteriaBasedOnRoleQualification(c, qualification); |
849 | |
|
850 | 0 | Collection<RoleMemberImpl> coll = (Collection<RoleMemberImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
851 | 0 | ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() ); |
852 | 0 | for ( RoleMemberImpl rm : coll ) { |
853 | 0 | if ( rm.isActive() ) { |
854 | 0 | results.add(rm); |
855 | |
} |
856 | |
} |
857 | 0 | return results; |
858 | |
} |
859 | |
|
860 | |
|
861 | |
|
862 | |
|
863 | |
|
864 | |
public List<RoleMemberImpl> getRoleMembershipsForRoleIdsAsMembers( |
865 | |
Collection<String> roleIds, AttributeSet qualification) { |
866 | 0 | Criteria c = new Criteria(RoleMemberImpl.class.getName()); |
867 | |
|
868 | 0 | if(roleIds!=null && !roleIds.isEmpty()) |
869 | 0 | c.in(KIMPropertyConstants.RoleMember.MEMBER_ID, roleIds); |
870 | 0 | c.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, KimConstants.KimUIConstants.MEMBER_TYPE_ROLE_CODE); |
871 | 0 | addSubCriteriaBasedOnRoleQualification(c, qualification); |
872 | |
|
873 | 0 | Collection<RoleMemberImpl> coll = (Collection<RoleMemberImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
874 | 0 | ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() ); |
875 | 0 | for ( RoleMemberImpl rm : coll ) { |
876 | 0 | if ( rm.isActive() ) { |
877 | 0 | results.add(rm); |
878 | |
} |
879 | |
} |
880 | 0 | return results; |
881 | |
} |
882 | |
|
883 | |
|
884 | |
|
885 | |
|
886 | |
public List<RoleMemberImpl> getRolePrincipalsForPrincipalIdAndRoleIds( |
887 | |
Collection<String> roleIds, String principalId, |
888 | |
AttributeSet qualification) { |
889 | 0 | Criteria c = new Criteria(RoleMemberImpl.class.getName()); |
890 | |
|
891 | 0 | if ( roleIds != null ) { |
892 | 0 | c.in(KIMPropertyConstants.RoleMember.ROLE_ID, roleIds); |
893 | |
} |
894 | 0 | if(principalId!=null) |
895 | 0 | c.eq(KIMPropertyConstants.RoleMember.MEMBER_ID, principalId); |
896 | 0 | c.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, Role.PRINCIPAL_MEMBER_TYPE ); |
897 | 0 | addSubCriteriaBasedOnRoleQualification(c, qualification); |
898 | |
|
899 | 0 | Collection<RoleMemberImpl> coll = (Collection<RoleMemberImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
900 | 0 | ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() ); |
901 | 0 | for ( RoleMemberImpl rm : coll ) { |
902 | 0 | if ( rm.isActive() ) { |
903 | 0 | results.add(rm); |
904 | |
} |
905 | |
} |
906 | 0 | return results; |
907 | |
} |
908 | |
|
909 | |
|
910 | |
|
911 | |
|
912 | |
|
913 | |
|
914 | |
|
915 | |
private void addSubCriteriaBasedOnRoleQualification(Criteria c, AttributeSet qualification) { |
916 | 0 | if(qualification != null && CollectionUtils.isNotEmpty(qualification.keySet())) { |
917 | 0 | for(Map.Entry<String, String> qualifier : qualification.entrySet()) { |
918 | 0 | Criteria subCrit = new Criteria(RoleMemberAttributeDataImpl.class.getName()); |
919 | 0 | if(StringUtils.isNotEmpty(qualifier.getValue())) { |
920 | 0 | String value = (qualifier.getValue()).replace('*', '%'); |
921 | 0 | subCrit.like("attributeValue", value); |
922 | 0 | subCrit.eq("kimAttributeId", qualifier.getKey()); |
923 | |
|
924 | |
|
925 | 0 | c.exists(subCrit); |
926 | |
} |
927 | 0 | } |
928 | |
} |
929 | 0 | } |
930 | |
|
931 | |
|
932 | |
|
933 | |
|
934 | |
|
935 | |
public List<RoleMemberImpl> getRoleMembershipsForMemberId( |
936 | |
String memberType, String memberId, AttributeSet qualification) { |
937 | 0 | Criteria c = new Criteria(RoleMemberImpl.class.getName()); |
938 | 0 | List<RoleMemberImpl> parentRoleMembers = new ArrayList<RoleMemberImpl>(); |
939 | |
|
940 | 0 | if(StringUtils.isEmpty(memberId) |
941 | |
|| StringUtils.isEmpty(memberType)) { |
942 | 0 | return parentRoleMembers; |
943 | |
} |
944 | |
|
945 | 0 | c.eq(KIMPropertyConstants.RoleMember.MEMBER_ID, memberId); |
946 | 0 | c.eq( KIMPropertyConstants.RoleMember.MEMBER_TYPE_CODE, memberType); |
947 | 0 | addSubCriteriaBasedOnRoleQualification(c, qualification); |
948 | |
|
949 | 0 | Collection<RoleMemberImpl> coll = (Collection<RoleMemberImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
950 | 0 | ArrayList<RoleMemberImpl> results = new ArrayList<RoleMemberImpl>( coll.size() ); |
951 | 0 | for ( RoleMemberImpl rm : coll ) { |
952 | 0 | if ( rm.isActive() ) { |
953 | 0 | results.add(rm); |
954 | |
} |
955 | |
} |
956 | 0 | return results; |
957 | |
} |
958 | |
} |