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