| 1 | |
package org.kuali.student.enrollment.class2.courseoffering.service; |
| 2 | |
|
| 3 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
| 4 | |
import org.kuali.rice.krad.lookup.LookupableImpl; |
| 5 | |
import org.kuali.rice.krad.web.form.LookupForm; |
| 6 | |
import org.kuali.student.common.search.dto.*; |
| 7 | |
import org.kuali.student.lum.course.dto.CourseInfo; |
| 8 | |
import org.kuali.student.lum.course.service.CourseService; |
| 9 | |
import org.kuali.student.lum.course.service.CourseServiceConstants; |
| 10 | |
import org.kuali.student.lum.lu.service.LuService; |
| 11 | |
import org.kuali.student.lum.lu.service.LuServiceConstants; |
| 12 | |
|
| 13 | |
import javax.xml.namespace.QName; |
| 14 | |
import java.util.ArrayList; |
| 15 | |
import java.util.List; |
| 16 | |
import java.util.Map; |
| 17 | |
|
| 18 | |
import static org.apache.commons.lang.StringUtils.isEmpty; |
| 19 | |
|
| 20 | 0 | public class CourseInfoLookupableImpl extends LookupableImpl { |
| 21 | |
private static final long serialVersionUID = 1L; |
| 22 | |
|
| 23 | |
private transient LuService luService; |
| 24 | |
private transient CourseService courseService; |
| 25 | |
|
| 26 | 0 | private enum QueryParamEnum { |
| 27 | 0 | ID("lu.queryParam.luOptionalId","id"), |
| 28 | 0 | SUBJECT("lu.queryParam.luOptionalStudySubjectArea", "subjectArea"), |
| 29 | 0 | CODE("lu.queryParam.luOptionalCode", "code"), |
| 30 | 0 | TITLE("lu.queryParam.luOptionalLongName", "courseTitle"); |
| 31 | |
|
| 32 | |
private final String fieldValue; |
| 33 | |
private final String queryKey; |
| 34 | |
|
| 35 | 0 | QueryParamEnum(String qKey, String fValue) { |
| 36 | 0 | this.queryKey = qKey; |
| 37 | 0 | this.fieldValue = fValue; |
| 38 | 0 | } |
| 39 | |
|
| 40 | |
public String getFieldValue() { |
| 41 | 0 | return fieldValue; |
| 42 | |
} |
| 43 | |
|
| 44 | |
public String getQueryKey() { |
| 45 | 0 | return queryKey; |
| 46 | |
} |
| 47 | |
} |
| 48 | |
|
| 49 | |
@Override |
| 50 | |
protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) { |
| 51 | 0 | List <CourseInfo> courseInfoList = new ArrayList<CourseInfo>(); |
| 52 | 0 | String courseId = null; |
| 53 | 0 | List<SearchParam> searchParams = new ArrayList<SearchParam>(); |
| 54 | 0 | SearchParam qpv1 = new SearchParam(); |
| 55 | 0 | qpv1.setKey("lu.queryParam.luOptionalType"); |
| 56 | 0 | qpv1.setValue("kuali.lu.type.CreditCourse"); |
| 57 | 0 | searchParams.add(qpv1); |
| 58 | 0 | for (QueryParamEnum qpEnum : QueryParamEnum.values()) { |
| 59 | 0 | String fieldValue = fieldValues.get(qpEnum.getFieldValue()); |
| 60 | 0 | if ( ! isEmpty(fieldValue) ) { |
| 61 | 0 | SearchParam qpv = new SearchParam(); |
| 62 | 0 | qpv.setKey(qpEnum.getQueryKey()); |
| 63 | 0 | qpv.setValue(fieldValue); |
| 64 | 0 | searchParams.add(qpv); |
| 65 | |
} |
| 66 | |
} |
| 67 | |
|
| 68 | 0 | SearchRequest searchRequest = new SearchRequest(); |
| 69 | 0 | searchRequest.setParams(searchParams); |
| 70 | 0 | searchRequest.setSearchKey("lu.search.mostCurrent.union"); |
| 71 | |
|
| 72 | |
try { |
| 73 | 0 | SearchResult searchResult = getLuService().search(searchRequest); |
| 74 | |
|
| 75 | 0 | if (searchResult.getRows().size() > 0) { |
| 76 | 0 | for(SearchResultRow srrow : searchResult.getRows()){ |
| 77 | 0 | List<SearchResultCell> srCells = srrow.getCells(); |
| 78 | 0 | if(srCells != null && srCells.size() > 0){ |
| 79 | 0 | for(SearchResultCell srcell : srCells){ |
| 80 | 0 | if (srcell.getKey().equals("lu.resultColumn.cluId")) { |
| 81 | 0 | courseId = srcell.getValue(); |
| 82 | 0 | CourseInfo course = getCourseService().getCourse(courseId); |
| 83 | 0 | courseInfoList.add(course); |
| 84 | 0 | } |
| 85 | |
} |
| 86 | |
} |
| 87 | 0 | } |
| 88 | |
} |
| 89 | |
|
| 90 | 0 | return courseInfoList; |
| 91 | 0 | } catch (Exception e) { |
| 92 | 0 | throw new RuntimeException(e); |
| 93 | |
} |
| 94 | |
} |
| 95 | |
|
| 96 | |
|
| 97 | |
protected LuService getLuService() { |
| 98 | 0 | if(luService == null) { |
| 99 | 0 | luService = (LuService)GlobalResourceLoader.getService(new QName(LuServiceConstants.LU_NAMESPACE,"LuService")); |
| 100 | |
} |
| 101 | 0 | return this.luService; |
| 102 | |
} |
| 103 | |
|
| 104 | |
protected CourseService getCourseService() { |
| 105 | 0 | if(courseService == null) { |
| 106 | 0 | courseService = (CourseService)GlobalResourceLoader.getService(new QName(CourseServiceConstants.COURSE_NAMESPACE,"CourseService")); |
| 107 | |
} |
| 108 | 0 | return this.courseService; |
| 109 | |
} |
| 110 | |
} |