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 org.apache.ojb.broker.query.Criteria; |
23 | |
import org.apache.ojb.broker.query.Query; |
24 | |
import org.apache.ojb.broker.query.QueryFactory; |
25 | |
import org.kuali.rice.kim.bo.role.KimResponsibility; |
26 | |
import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityActionImpl; |
27 | |
import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityImpl; |
28 | |
import org.kuali.rice.kim.dao.KimResponsibilityDao; |
29 | |
import org.kuali.rice.kim.util.KIMPropertyConstants; |
30 | |
import org.kuali.rice.kim.util.KimConstants; |
31 | |
import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb; |
32 | |
import org.kuali.rice.kns.util.KNSPropertyConstants; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public class KimResponsibilityDaoOjb extends PlatformAwareDaoBaseOjb implements KimResponsibilityDao { |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
@SuppressWarnings("unchecked") |
46 | |
public List<String> getRoleIdsForResponsibilities(Collection<? extends KimResponsibility> responsibilities) { |
47 | 0 | List<String> responsibilityIds = new ArrayList<String>( responsibilities.size() ); |
48 | 0 | for ( KimResponsibility kp : responsibilities ) { |
49 | 0 | responsibilityIds.add( kp.getResponsibilityId() ); |
50 | |
} |
51 | 0 | Criteria c = new Criteria(); |
52 | 0 | c.addIn( KimConstants.PrimaryKeyConstants.RESPONSIBILITY_ID, responsibilityIds ); |
53 | 0 | c.addEqualTo( KNSPropertyConstants.ACTIVE, true ); |
54 | |
|
55 | 0 | Query query = QueryFactory.newQuery( RoleResponsibilityImpl.class, c, true ); |
56 | 0 | Collection<RoleResponsibilityImpl> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query); |
57 | 0 | List<String> roleIds = new ArrayList<String>( coll.size() ); |
58 | 0 | for ( RoleResponsibilityImpl rp : coll ) { |
59 | 0 | roleIds.add( rp.getRoleId() ); |
60 | |
} |
61 | 0 | return roleIds; |
62 | |
} |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
@SuppressWarnings("unchecked") |
68 | |
public List<String> getRoleIdsForResponsibility( KimResponsibility responsibility) { |
69 | 0 | Criteria c = new Criteria(); |
70 | 0 | c.addEqualTo( KimConstants.PrimaryKeyConstants.RESPONSIBILITY_ID, responsibility.getResponsibilityId() ); |
71 | 0 | c.addEqualTo( KNSPropertyConstants.ACTIVE, true ); |
72 | |
|
73 | 0 | Query query = QueryFactory.newQuery( RoleResponsibilityImpl.class, c, true ); |
74 | 0 | Collection<RoleResponsibilityImpl> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query); |
75 | 0 | List<String> roleIds = new ArrayList<String>( coll.size() ); |
76 | 0 | for ( RoleResponsibilityImpl rp : coll ) { |
77 | 0 | roleIds.add( rp.getRoleId() ); |
78 | |
} |
79 | 0 | return roleIds; |
80 | |
} |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
@SuppressWarnings("unchecked") |
86 | |
public RoleResponsibilityActionImpl getResponsibilityAction(String roleId, String responsibilityId, String roleMemberId ) { |
87 | 0 | if ( roleMemberId == null || responsibilityId == null ) { |
88 | 0 | return null; |
89 | |
} |
90 | |
|
91 | 0 | Criteria c = new Criteria(); |
92 | 0 | c.addEqualTo( "roleResponsibility.responsibilityId", responsibilityId ); |
93 | 0 | c.addEqualTo( "roleResponsibility.roleId", roleId ); |
94 | 0 | c.addEqualTo( "roleResponsibility.active", true ); |
95 | 0 | Criteria idCriteria = new Criteria(); |
96 | 0 | idCriteria.addEqualTo( KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, roleMemberId ); |
97 | |
|
98 | 0 | Criteria starCrit = new Criteria(); |
99 | 0 | starCrit.addEqualTo( KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, "*" ); |
100 | 0 | idCriteria.addOrCriteria( starCrit ); |
101 | 0 | c.addAndCriteria( idCriteria ); |
102 | |
|
103 | 0 | Query query = QueryFactory.newQuery( RoleResponsibilityActionImpl.class, c ); |
104 | 0 | Collection<RoleResponsibilityActionImpl> coll = getPersistenceBrokerTemplate().getCollectionByQuery(query); |
105 | 0 | RoleResponsibilityActionImpl result = null; |
106 | 0 | if ( coll.size() == 0 ) { |
107 | |
|
108 | |
|
109 | 0 | c = new Criteria(); |
110 | 0 | c.addEqualTo( "roleResponsibilityId", "*" ); |
111 | 0 | c.addEqualTo( KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, roleMemberId ); |
112 | 0 | query = QueryFactory.newQuery( RoleResponsibilityActionImpl.class, c ); |
113 | 0 | coll = getPersistenceBrokerTemplate().getCollectionByQuery(query); |
114 | 0 | if ( coll.size() != 0 ) { |
115 | 0 | result = coll.iterator().next(); |
116 | |
} |
117 | |
} else { |
118 | 0 | result = coll.iterator().next(); |
119 | |
} |
120 | 0 | return result; |
121 | |
} |
122 | |
} |