1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.ui.admin.lrc;
17
18
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.Map;
22 import javax.xml.namespace.QName;
23 import org.apache.log4j.Logger;
24 import org.kuali.rice.core.api.criteria.Predicate;
25 import org.kuali.rice.core.api.criteria.PredicateFactory;
26 import org.kuali.rice.core.api.criteria.QueryByCriteria;
27 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
28 import org.kuali.rice.krad.lookup.LookupableImpl;
29 import org.kuali.rice.krad.web.form.LookupForm;
30 import org.kuali.student.common.util.ContextBuilder;
31 import org.kuali.student.r2.common.dto.ContextInfo;
32 import org.kuali.student.r2.lum.lrc.dto.ResultValueInfo;
33 import org.kuali.student.r2.lum.lrc.service.LRCService;
34 import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
35
36
37 public class ResultValueInfoAdminLookupableImpl extends LookupableImpl
38 {
39 private static final Logger LOG = Logger.getLogger(ResultValueInfoAdminLookupableImpl.class);
40 private transient LRCService lRCService;
41 private static final long serialVersionUID = 1L;
42 @Override
43 protected List<ResultValueInfo> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded)
44 {
45 QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
46 List<Predicate> pList = new ArrayList<Predicate>();
47
48 for(Map.Entry<String, String> entry: fieldValues.entrySet()) {
49 String fieldName = entry.getKey();
50 String value = entry.getValue();
51 if (value != null && !value.isEmpty())
52 {
53 if (fieldName.equals("maxResultsToReturn"))
54 {
55 qBuilder.setMaxResults (Integer.parseInt(value));
56 continue;
57 }
58 pList.add(PredicateFactory.equal(fieldName, value));
59 }
60 }
61 if (!pList.isEmpty())
62 {
63 qBuilder.setPredicates(PredicateFactory.and(pList.toArray(new Predicate[pList.size()])));
64 }
65 try
66 {
67 List<ResultValueInfo> list = this.getLRCService().searchForResultValues(qBuilder.build(), getContextInfo());
68 return list;
69 }
70 catch (Exception ex) {
71 throw new RuntimeException(ex);
72 }
73 }
74
75 public void setLRCService(LRCService lRCService)
76 {
77 this.lRCService = lRCService;
78 }
79
80 public LRCService getLRCService()
81 {
82 if (lRCService == null)
83 {
84 QName qname = new QName(LrcServiceConstants.NAMESPACE,LrcServiceConstants.SERVICE_NAME_LOCAL_PART);
85 lRCService = (LRCService) GlobalResourceLoader.getService(qname);
86 }
87 return this.lRCService;
88 }
89
90 private ContextInfo getContextInfo() {
91 return ContextBuilder.loadContextInfo();
92 }
93 }
94