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.sql.Timestamp; |
19 | |
import java.util.List; |
20 | |
import java.util.Map; |
21 | |
import java.util.Map.Entry; |
22 | |
|
23 | |
import org.apache.commons.lang.StringUtils; |
24 | |
import org.apache.log4j.Logger; |
25 | |
import org.apache.ojb.broker.query.Criteria; |
26 | |
import org.apache.ojb.broker.query.Query; |
27 | |
import org.apache.ojb.broker.query.QueryFactory; |
28 | |
import org.apache.ojb.broker.query.ReportQueryByCriteria; |
29 | |
import org.kuali.rice.kim.bo.entity.dto.KimPrincipalInfo; |
30 | |
import org.kuali.rice.kim.bo.entity.impl.KimPrincipalImpl; |
31 | |
import org.kuali.rice.kim.bo.group.impl.GroupAttributeDataImpl; |
32 | |
import org.kuali.rice.kim.bo.group.impl.GroupMemberImpl; |
33 | |
import org.kuali.rice.kim.bo.impl.GroupImpl; |
34 | |
import org.kuali.rice.kim.dao.KimGroupDao; |
35 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
36 | |
import org.kuali.rice.kim.util.KIMPropertyConstants; |
37 | |
import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb; |
38 | |
import org.kuali.rice.kns.datadictionary.BusinessObjectEntry; |
39 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | public class KimGroupDaoOjb extends PlatformAwareDaoBaseOjb implements KimGroupDao { |
48 | |
|
49 | 0 | private static final Logger LOG = Logger.getLogger(KimGroupDaoOjb.class); |
50 | |
|
51 | |
public List<GroupImpl> getGroups(Map<String,String> fieldValues) { |
52 | 0 | Criteria crit = new Criteria(); |
53 | 0 | BusinessObjectEntry boEntry = KNSServiceLocator.getDataDictionaryService().getDataDictionary().getBusinessObjectEntry("org.kuali.rice.kim.bo.impl.GroupImpl"); |
54 | 0 | List lookupNames = boEntry.getLookupDefinition().getLookupFieldNames(); |
55 | 0 | String kimTypeId = null; |
56 | 0 | for (Map.Entry<String,String> entry : fieldValues.entrySet()) { |
57 | 0 | if (entry.getKey().equals("kimTypeId")) { |
58 | 0 | kimTypeId=entry.getValue(); |
59 | 0 | break; |
60 | |
} |
61 | |
} |
62 | 0 | for (Entry<String, String> entry : fieldValues.entrySet()) { |
63 | 0 | if (StringUtils.isNotBlank(entry.getValue())) { |
64 | 0 | if (entry.getKey().contains(".")) { |
65 | 0 | Criteria subCrit = new Criteria(); |
66 | 0 | String value = entry.getValue().replace('*', '%'); |
67 | |
|
68 | 0 | subCrit.addLike("attributeValue",value); |
69 | 0 | subCrit.addEqualTo("kimAttributeId",entry.getKey().substring(entry.getKey().indexOf(".")+1, entry.getKey().length())); |
70 | 0 | subCrit.addEqualTo("kimTypeId", kimTypeId); |
71 | 0 | ReportQueryByCriteria subQuery = QueryFactory.newReportQuery(GroupAttributeDataImpl.class, subCrit); |
72 | 0 | crit.addExists(subQuery); |
73 | 0 | } else { |
74 | 0 | if (lookupNames.contains(entry.getKey())) { |
75 | 0 | String value = entry.getValue().replace('*', '%'); |
76 | 0 | if(entry.getKey().equalsIgnoreCase(KIMPropertyConstants.Group.GROUP_NAME)) { |
77 | 0 | crit.addLike(getDbPlatform().getUpperCaseFunction() + "(" + entry.getKey() + ")", value.toUpperCase()); |
78 | |
} |
79 | |
else { |
80 | 0 | crit.addLike((entry.getKey()), value); |
81 | |
} |
82 | 0 | } else { |
83 | 0 | if (entry.getKey().equals(KIMPropertyConstants.Person.PRINCIPAL_NAME)) { |
84 | |
|
85 | |
|
86 | 0 | Criteria memberSubCrit = new Criteria(); |
87 | 0 | memberSubCrit.addEqualToField(KIMPropertyConstants.Group.GROUP_ID, Criteria.PARENT_QUERY_PREFIX + KIMPropertyConstants.Group.GROUP_ID); |
88 | |
|
89 | 0 | String principalName = entry.getValue(); |
90 | |
|
91 | 0 | LOG.debug("Searching on Principal Name: " + entry.getValue()); |
92 | 0 | KimPrincipalInfo principalInfo = KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(principalName); |
93 | |
|
94 | 0 | if (principalInfo != null) |
95 | |
{ |
96 | 0 | LOG.debug("Retrieved Principal: " + principalInfo.getPrincipalName()); |
97 | 0 | String principalId = principalInfo.getPrincipalId(); |
98 | 0 | LOG.debug("Plugging in Principal ID: " + principalId + "as Member ID"); |
99 | 0 | memberSubCrit.addLike(KIMPropertyConstants.GroupMember.MEMBER_ID, principalId); |
100 | |
|
101 | |
|
102 | 0 | Timestamp now = KNSServiceLocator.getDateTimeService().getCurrentTimestamp(); |
103 | 0 | Criteria afterActiveFromSubCrit = new Criteria(); |
104 | 0 | afterActiveFromSubCrit.addLessOrEqualThan(KIMPropertyConstants.GroupMember.ACTIVE_FROM_DATE, now); |
105 | 0 | Criteria nullActiveFromSubCrit = new Criteria(); |
106 | 0 | nullActiveFromSubCrit.addIsNull(KIMPropertyConstants.GroupMember.ACTIVE_FROM_DATE); |
107 | |
|
108 | 0 | Criteria ActiveMemberSubCrit1 = new Criteria(); |
109 | 0 | ActiveMemberSubCrit1.addOrCriteria(afterActiveFromSubCrit); |
110 | 0 | ActiveMemberSubCrit1.addOrCriteria(nullActiveFromSubCrit); |
111 | |
|
112 | 0 | Criteria afterActiveToSubCrit = new Criteria(); |
113 | 0 | afterActiveToSubCrit.addGreaterOrEqualThan(KIMPropertyConstants.GroupMember.ACTIVE_TO_DATE, now); |
114 | 0 | Criteria nullActiveToSubCrit = new Criteria(); |
115 | 0 | nullActiveToSubCrit.addIsNull(KIMPropertyConstants.GroupMember.ACTIVE_TO_DATE); |
116 | |
|
117 | 0 | Criteria ActiveMemberSubCrit2 = new Criteria(); |
118 | 0 | ActiveMemberSubCrit2.addOrCriteria(afterActiveToSubCrit); |
119 | 0 | ActiveMemberSubCrit2.addOrCriteria(nullActiveToSubCrit); |
120 | |
|
121 | 0 | memberSubCrit.addAndCriteria(ActiveMemberSubCrit1); |
122 | 0 | memberSubCrit.addAndCriteria(ActiveMemberSubCrit2); |
123 | 0 | } |
124 | |
|
125 | |
else |
126 | |
{ |
127 | 0 | LOG.debug("No Principal ID, plugging in blank string as Member ID"); |
128 | 0 | memberSubCrit.addLike(KIMPropertyConstants.GroupMember.MEMBER_ID, ""); |
129 | |
} |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | 0 | ReportQueryByCriteria memberSubQuery = QueryFactory.newReportQuery(GroupMemberImpl.class, memberSubCrit); |
141 | 0 | crit.addExists(memberSubQuery); |
142 | 0 | } |
143 | |
} |
144 | |
} |
145 | |
} |
146 | |
} |
147 | 0 | Query q = QueryFactory.newQuery(GroupImpl.class, crit); |
148 | |
|
149 | 0 | return (List)getPersistenceBrokerTemplate().getCollectionByQuery(q); |
150 | |
} |
151 | |
|
152 | |
} |