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.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.bo.role.KimResponsibility; |
28 | |
import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityActionImpl; |
29 | |
import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityImpl; |
30 | |
import org.kuali.rice.kim.dao.KimResponsibilityDao; |
31 | |
import org.kuali.rice.kim.util.KIMPropertyConstants; |
32 | |
import org.kuali.rice.kim.util.KimConstants; |
33 | |
import org.kuali.rice.kns.util.KNSPropertyConstants; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | 0 | public class KimResponsibilityDaoJpa implements KimResponsibilityDao { |
42 | |
|
43 | |
@PersistenceContext(unitName="kim-unit") |
44 | |
private EntityManager entityManager; |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
@SuppressWarnings("unchecked") |
50 | |
public List<String> getRoleIdsForResponsibilities(Collection<? extends KimResponsibility> responsibilities) { |
51 | 0 | List<String> responsibilityIds = new ArrayList<String>( responsibilities.size() ); |
52 | 0 | for ( KimResponsibility kp : responsibilities ) { |
53 | 0 | responsibilityIds.add( kp.getResponsibilityId() ); |
54 | |
} |
55 | 0 | Criteria c = new Criteria(RoleResponsibilityImpl.class.getName()); |
56 | 0 | c.in( KimConstants.PrimaryKeyConstants.RESPONSIBILITY_ID, responsibilityIds ); |
57 | 0 | c.eq( KNSPropertyConstants.ACTIVE, true ); |
58 | |
|
59 | |
|
60 | |
|
61 | 0 | ArrayList<RoleResponsibilityImpl> coll = (ArrayList<RoleResponsibilityImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
62 | 0 | List<String> roleIds = new ArrayList<String>( coll.size() ); |
63 | 0 | for ( RoleResponsibilityImpl rp : coll ) { |
64 | 0 | roleIds.add( rp.getRoleId() ); |
65 | |
} |
66 | 0 | return roleIds; |
67 | |
} |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
@SuppressWarnings("unchecked") |
73 | |
public List<String> getRoleIdsForResponsibility( KimResponsibility responsibility) { |
74 | 0 | Criteria c = new Criteria(RoleResponsibilityImpl.class.getName()); |
75 | 0 | c.eq( KimConstants.PrimaryKeyConstants.RESPONSIBILITY_ID, responsibility.getResponsibilityId() ); |
76 | 0 | c.eq( KNSPropertyConstants.ACTIVE, true ); |
77 | |
|
78 | 0 | ArrayList<RoleResponsibilityImpl> coll = (ArrayList<RoleResponsibilityImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
79 | 0 | List<String> roleIds = new ArrayList<String>( coll.size() ); |
80 | 0 | for ( RoleResponsibilityImpl rp : coll ) { |
81 | 0 | roleIds.add( rp.getRoleId() ); |
82 | |
} |
83 | 0 | return roleIds; |
84 | |
} |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
@SuppressWarnings("unchecked") |
90 | |
public RoleResponsibilityActionImpl getResponsibilityAction(String roleId, String responsibilityId, String roleMemberId ) { |
91 | 0 | if ( roleMemberId == null || responsibilityId == null ) { |
92 | 0 | return null; |
93 | |
} |
94 | |
|
95 | 0 | Criteria c = new Criteria(RoleResponsibilityActionImpl.class.getName()); |
96 | 0 | c.eq( "roleResponsibility.responsibilityId", responsibilityId ); |
97 | 0 | c.eq( "roleResponsibility.roleId", roleId ); |
98 | 0 | c.eq( "roleResponsibility.active", true ); |
99 | 0 | Criteria idCriteria = new Criteria(RoleResponsibilityActionImpl.class.getName(), c.getAlias()); |
100 | 0 | idCriteria.eq( KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, roleMemberId ); |
101 | |
|
102 | 0 | Criteria starCrit = new Criteria(RoleResponsibilityActionImpl.class.getName(), c.getAlias()); |
103 | 0 | starCrit.eq( KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, "*" ); |
104 | 0 | idCriteria.or( starCrit ); |
105 | 0 | c.and( idCriteria ); |
106 | |
|
107 | 0 | ArrayList<RoleResponsibilityActionImpl> coll = (ArrayList<RoleResponsibilityActionImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
108 | 0 | RoleResponsibilityActionImpl result = null; |
109 | 0 | if ( coll.size() == 0 ) { |
110 | |
|
111 | |
|
112 | 0 | c = new Criteria(RoleResponsibilityActionImpl.class.getName()); |
113 | 0 | c.eq( "roleResponsibilityId", "*" ); |
114 | 0 | c.eq( KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, roleMemberId ); |
115 | 0 | coll = (ArrayList<RoleResponsibilityActionImpl>) new QueryByCriteria(entityManager, c).toQuery().getResultList(); |
116 | 0 | if ( coll.size() != 0 ) { |
117 | 0 | result = coll.iterator().next(); |
118 | |
} |
119 | |
} else { |
120 | 0 | result = coll.iterator().next(); |
121 | |
} |
122 | 0 | return result; |
123 | |
} |
124 | |
|
125 | |
public EntityManager getEntityManager() { |
126 | 0 | return this.entityManager; |
127 | |
} |
128 | |
|
129 | |
public void setEntityManager(EntityManager entityManager) { |
130 | 0 | this.entityManager = entityManager; |
131 | 0 | } |
132 | |
} |