1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.permission; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collection; |
20 | |
import java.util.List; |
21 | |
|
22 | |
import javax.persistence.EntityManager; |
23 | |
import javax.persistence.PersistenceContext; |
24 | |
|
25 | |
import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria; |
26 | |
import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria; |
27 | |
import org.kuali.rice.kim.api.permission.Permission; |
28 | |
import org.kuali.rice.kim.impl.role.RolePermissionBo; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public class PermissionDaoJpa implements PermissionDao { |
34 | |
|
35 | |
@SuppressWarnings("unchecked") |
36 | |
public List<String> getRoleIdsForPermissions(Collection<Permission> permissions) { |
37 | 0 | if ( permissions.isEmpty() ) { |
38 | 0 | return new ArrayList<String>(0); |
39 | |
} |
40 | 0 | List<String> permissionIds = new ArrayList<String>( permissions.size() ); |
41 | 0 | for ( Permission kp : permissions ) { |
42 | 0 | permissionIds.add( kp.getId() ); |
43 | |
} |
44 | 0 | Criteria c = new Criteria(RolePermissionBo.class.getName()); |
45 | 0 | c.in( "permissionId", permissionIds ); |
46 | 0 | c.eq( "active", true ); |
47 | |
|
48 | 0 | ArrayList<RolePermissionBo> coll = (ArrayList<RolePermissionBo>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
49 | 0 | List<String> roleIds = new ArrayList<String>( coll.size() ); |
50 | 0 | for ( RolePermissionBo rp : coll ) { |
51 | 0 | roleIds.add( rp.getRoleId() ); |
52 | |
} |
53 | 0 | return roleIds; |
54 | |
} |
55 | |
|
56 | |
@PersistenceContext(unitName="kim-unit") |
57 | |
private EntityManager entityManager; |
58 | |
|
59 | |
public EntityManager getEntityManager() { |
60 | 0 | return this.entityManager; |
61 | |
} |
62 | |
|
63 | |
public void setEntityManager(EntityManager entityManager) { |
64 | 0 | this.entityManager = entityManager; |
65 | 0 | } |
66 | |
|
67 | |
|
68 | |
} |