1 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
2
3 import edu.emory.mathcs.backport.java.util.Collections;
4 import org.apache.commons.lang.StringUtils;
5 import org.kuali.rice.core.api.criteria.PredicateFactory;
6 import org.kuali.rice.core.api.criteria.QueryByCriteria;
7 import org.kuali.rice.core.api.util.RiceKeyConstants;
8 import org.kuali.rice.krad.lookup.Lookupable;
9 import org.kuali.rice.krad.lookup.LookupableImpl;
10 import org.kuali.rice.krad.util.GlobalVariables;
11 import org.kuali.rice.krad.util.KRADConstants;
12 import org.kuali.rice.krad.web.form.LookupForm;
13 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingManagementUtil;
14 import org.kuali.student.r2.common.util.ContextUtils;
15 import org.kuali.student.r2.core.room.dto.BuildingInfo;
16
17 import org.apache.log4j.Logger;
18
19 import java.util.List;
20 import java.util.Map;
21
22
23
24
25
26
27 public class BuildingInfoLookupableImpl extends LookupableImpl implements Lookupable {
28 private static final Logger LOGGER = Logger.getLogger(BuildingInfoLookupableImpl.class);
29
30 @Override
31 protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
32
33 List<BuildingInfo> buildingInfos = null;
34
35 try {
36
37 String nameString = fieldValues.get("name");
38
39
40 String name = "*" + StringUtils.upperCase(nameString) + "*";
41
42
43 QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
44 qbcBuilder.setPredicates(PredicateFactory.like("name", name));
45 QueryByCriteria criteria = qbcBuilder.build();
46 buildingInfos = CourseOfferingManagementUtil.getRoomService().searchForBuildings(criteria, ContextUtils.createDefaultContextInfo());
47 } catch (Exception e) {
48
49 String errorTxt = "Query to RoomService failed. See the application log for additional details.";
50 LOGGER.error(errorTxt, e);
51 GlobalVariables.getMessageMap()
52 .putError(KRADConstants.GLOBAL_MESSAGES, RiceKeyConstants.ERROR_CUSTOM, errorTxt);
53 buildingInfos = Collections.emptyList();
54 }
55
56 return buildingInfos;
57 }
58 }