1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.core.api.criteria.PredicateFactory;
21 import org.kuali.rice.core.api.criteria.QueryByCriteria;
22 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
23 import org.kuali.rice.krad.lookup.LookupableImpl;
24 import org.kuali.rice.krad.web.form.LookupForm;
25 import org.kuali.student.r2.common.constants.CommonServiceConstants;
26 import org.kuali.student.r2.common.util.ContextUtils;
27 import org.kuali.student.r2.core.organization.dto.OrgInfo;
28 import org.kuali.student.r2.core.organization.service.OrganizationService;
29
30 import javax.xml.namespace.QName;
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.Map;
34
35
36
37
38
39
40
41 public class OrganizationInfoLookupableImpl extends LookupableImpl {
42 private OrganizationService organizationService;
43
44 @Override
45 protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
46 List<OrgInfo> results = new ArrayList<OrgInfo>();
47
48
49 String shortName = fieldValues.get("shortName");
50 String longName = fieldValues.get("longName");
51
52 QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
53 if (StringUtils.isNotBlank(longName) && !longName.isEmpty()) {
54 if (StringUtils.isNotBlank(shortName) && !shortName.isEmpty()){
55 qBuilder.setPredicates(PredicateFactory.or(
56 PredicateFactory.like("longName","*"+ fieldValues.get("longName")+ "*"),
57 PredicateFactory.like("shortName","*" + fieldValues.get("shortName") + "*")));
58 }
59 else {
60 qBuilder.setPredicates(PredicateFactory.like("longName","*"+ fieldValues.get("longName")+ "*"));
61 }
62 }else if (StringUtils.isNotBlank(shortName) && !shortName.isEmpty()){
63 qBuilder.setPredicates(PredicateFactory.like("shortName","*" + fieldValues.get("shortName") + "*"));
64 }
65 try {
66 QueryByCriteria query = qBuilder.build();
67
68 OrganizationService organizationService = getOrganizationService();
69
70 List<OrgInfo> orgInfos = organizationService.searchForOrgs(query, ContextUtils.createDefaultContextInfo());
71 if (!orgInfos.isEmpty()){
72 results.addAll(orgInfos);
73 }
74 } catch (Exception e) {
75 throw new RuntimeException("Error Performing Search", e);
76 }
77 return results;
78 }
79
80 private OrganizationService getOrganizationService(){
81 if(organizationService == null) {
82 organizationService = (OrganizationService) GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX + "organization", "OrganizationService"));
83
84 }
85 return organizationService;
86
87 }
88 }