| 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.List; |
| 19 | |
import java.util.Map; |
| 20 | |
import java.util.Map.Entry; |
| 21 | |
|
| 22 | |
import javax.persistence.EntityManager; |
| 23 | |
import javax.persistence.PersistenceContext; |
| 24 | |
|
| 25 | |
import org.apache.commons.lang.StringUtils; |
| 26 | |
import org.kuali.rice.kim.bo.entity.impl.KimPrincipalImpl; |
| 27 | |
import org.kuali.rice.kim.bo.group.impl.GroupAttributeDataImpl; |
| 28 | |
import org.kuali.rice.kim.bo.group.impl.GroupMemberImpl; |
| 29 | |
import org.kuali.rice.kim.bo.impl.GroupImpl; |
| 30 | |
import org.kuali.rice.kim.dao.KimGroupDao; |
| 31 | |
import org.kuali.rice.kim.util.KIMPropertyConstants; |
| 32 | |
import org.kuali.rice.kns.datadictionary.BusinessObjectEntry; |
| 33 | |
|
| 34 | |
import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria; |
| 35 | |
import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria; |
| 36 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | 0 | public class KimGroupDaoJpa implements KimGroupDao { |
| 45 | |
|
| 46 | |
@PersistenceContext(unitName="kim-unit") |
| 47 | |
private EntityManager entityManager; |
| 48 | |
|
| 49 | |
public List<GroupImpl> getGroups(Map<String,String> fieldValues) { |
| 50 | 0 | Criteria crit = new Criteria(GroupImpl.class.getName()); |
| 51 | 0 | BusinessObjectEntry boEntry = KNSServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getBusinessObjectEntry("org.kuali.rice.kim.bo.impl.GroupImpl"); |
| 52 | 0 | List lookupNames = boEntry.getLookupDefinition().getLookupFieldNames(); |
| 53 | 0 | String kimTypeId = null; |
| 54 | 0 | for (Map.Entry<String,String> entry : fieldValues.entrySet()) { |
| 55 | 0 | if (entry.getKey().equals("kimTypeId")) { |
| 56 | 0 | kimTypeId=entry.getValue(); |
| 57 | 0 | break; |
| 58 | |
} |
| 59 | |
} |
| 60 | 0 | for (Entry<String, String> entry : fieldValues.entrySet()) { |
| 61 | 0 | if (StringUtils.isNotBlank(entry.getValue())) { |
| 62 | 0 | if (entry.getKey().contains(".")) { |
| 63 | 0 | Criteria subCrit = new Criteria(GroupAttributeDataImpl.class.getName()); |
| 64 | 0 | String value = entry.getValue().replace('*', '%'); |
| 65 | |
|
| 66 | 0 | subCrit.like("attributeValue",value); |
| 67 | 0 | subCrit.eq("kimAttributeId",entry.getKey().substring(entry.getKey().indexOf(".")+1, entry.getKey().length())); |
| 68 | 0 | subCrit.eq("kimTypeId", kimTypeId); |
| 69 | |
|
| 70 | 0 | crit.and(subCrit); |
| 71 | |
|
| 72 | 0 | } else { |
| 73 | 0 | if (lookupNames.contains(entry.getKey())) { |
| 74 | 0 | String value = entry.getValue().replace('*', '%'); |
| 75 | 0 | crit.like(entry.getKey(), value); |
| 76 | 0 | } else { |
| 77 | 0 | if (entry.getKey().equals(KIMPropertyConstants.Person.PRINCIPAL_NAME)) { |
| 78 | 0 | Criteria subCrit = new Criteria(KimPrincipalImpl.class.getName()); |
| 79 | 0 | String principalName = entry.getValue().replace('*', '%'); |
| 80 | 0 | subCrit.like(KIMPropertyConstants.Person.PRINCIPAL_NAME, principalName ); |
| 81 | 0 | subCrit.eq(KIMPropertyConstants.Person.PRINCIPAL_ID, crit.getAlias() + KIMPropertyConstants.KimMember.MEMBER_ID); |
| 82 | |
|
| 83 | 0 | Criteria memberSubCrit = new Criteria(GroupMemberImpl.class.getName()); |
| 84 | 0 | memberSubCrit.eq(KIMPropertyConstants.Group.GROUP_ID, crit.getAlias() + KIMPropertyConstants.Group.GROUP_ID); |
| 85 | 0 | memberSubCrit.and(subCrit); |
| 86 | |
|
| 87 | 0 | crit.and(memberSubCrit); |
| 88 | 0 | } |
| 89 | |
} |
| 90 | |
} |
| 91 | |
} |
| 92 | |
} |
| 93 | 0 | return (List)new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
| 94 | |
} |
| 95 | |
|
| 96 | |
public EntityManager getEntityManager() { |
| 97 | 0 | return this.entityManager; |
| 98 | |
} |
| 99 | |
|
| 100 | |
public void setEntityManager(EntityManager entityManager) { |
| 101 | 0 | this.entityManager = entityManager; |
| 102 | 0 | } |
| 103 | |
} |