1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class1.hold.service;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.core.api.criteria.Predicate;
21 import org.kuali.rice.core.api.criteria.PredicateFactory;
22 import org.kuali.rice.core.api.criteria.QueryByCriteria;
23 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
24 import org.kuali.rice.krad.lookup.LookupableImpl;
25 import org.kuali.rice.krad.web.form.LookupForm;
26 import org.kuali.student.r2.common.constants.CommonServiceConstants;
27 import org.kuali.student.r2.common.dto.ContextInfo;
28 import org.kuali.student.r2.core.constants.HoldServiceConstants;
29 import org.kuali.student.r2.common.util.constants.OrganizationServiceConstants;
30 import org.kuali.student.r2.core.hold.dto.HoldIssueInfo;
31 import org.kuali.student.r2.core.hold.service.HoldService;
32 import org.kuali.student.r2.core.organization.dto.OrgInfo;
33 import org.kuali.student.r2.core.organization.service.OrganizationService;
34
35 import javax.xml.namespace.QName;
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.Map;
39
40 import static org.kuali.rice.core.api.criteria.PredicateFactory.and;
41 import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
42 import static org.kuali.rice.core.api.criteria.PredicateFactory.like;
43
44
45
46
47
48
49
50 public class HoldIssueInfoLookupableImpl extends LookupableImpl {
51 private HoldService holdService;
52 ContextInfo contextInfo = new ContextInfo();
53
54 @Override
55 protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
56 List<HoldIssueInfo> results = new ArrayList<HoldIssueInfo>();
57 QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
58 List<Predicate> pList = new ArrayList<Predicate>();
59 Predicate p;
60
61 String type = fieldValues.get("typeKey");
62 String name = fieldValues.get("name");
63 String state = fieldValues.get("stateKey");
64 String orgId = fieldValues.get("organizationId");
65 String descr = fieldValues.get("descr.plain");
66 qBuilder.setPredicates();
67 if (StringUtils.isNotBlank(name)){
68 p = like("name", "%" + name + "%");
69 pList.add(p);
70 }
71
72 if (StringUtils.isNotBlank(type)){
73 p = like("holdIssueType", "%" + type + "%");
74 pList.add(p);
75 }
76
77 if (StringUtils.isNotBlank(state)){
78 p = equal("holdIssueState", state);
79 pList.add(p);
80 }
81
82 if (StringUtils.isNotBlank(orgId)){
83 p = equal("organizationId", orgId);
84 pList.add(p);
85 }
86
87 if (StringUtils.isNotBlank(descr)){
88 p = like("descrPlain", "%" + descr + "%");
89 pList.add(p);
90 }
91
92 if (!pList.isEmpty()){
93 Predicate[] preds = new Predicate[pList.size()];
94 pList.toArray(preds);
95 qBuilder.setPredicates(and(preds));
96 }
97
98 try {
99 QueryByCriteria query = qBuilder.build();
100
101 HoldService holdService = getHoldService();
102
103
104 List<HoldIssueInfo> holdIssueInfos = holdService.searchForHoldIssues(query, getContextInfo());
105 if (!holdIssueInfos.isEmpty()){
106 results.addAll(holdIssueInfos);
107 }
108 } catch (Exception e) {
109 e.printStackTrace();
110 throw new RuntimeException("Error Performing Search",e);
111 }
112 return results;
113 }
114
115
116 protected HoldService getHoldService(){
117 if(holdService == null) {
118 holdService = (HoldService) GlobalResourceLoader.getService(new QName(HoldServiceConstants.NAMESPACE, HoldServiceConstants.SERVICE_NAME_LOCAL_PART));
119 }
120 return holdService;
121 }
122
123 public ContextInfo getContextInfo() {
124 if (contextInfo == null){
125 contextInfo = org.kuali.student.enrollment.common.util.ContextBuilder.loadContextInfo();
126 }
127 return contextInfo;
128 }
129 }