1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
17
18 import org.apache.commons.lang.BooleanUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.core.api.util.RiceKeyConstants;
21 import org.kuali.rice.krad.lookup.LookupForm;
22 import org.kuali.rice.krad.lookup.LookupableImpl;
23 import org.kuali.rice.krad.util.GlobalVariables;
24 import org.kuali.rice.krad.util.KRADConstants;
25 import org.kuali.student.enrollment.class2.courseoffering.dto.ActivityOfferingWrapper;
26 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingManagementUtil;
27 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
28 import org.kuali.student.common.util.security.ContextUtils;
29 import org.kuali.student.r2.core.class1.search.CourseOfferingManagementSearchImpl;
30 import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
31 import org.kuali.student.r2.core.search.dto.SearchResultCellInfo;
32 import org.kuali.student.r2.core.search.dto.SearchResultInfo;
33
34 import java.util.ArrayList;
35 import java.util.List;
36 import java.util.Map;
37
38
39
40
41
42
43 public class ActivityOfferingWrapperLookupableImpl extends LookupableImpl {
44
45 @Override
46 public boolean validateSearchParameters(LookupForm form, Map<String, String> searchCriteria){
47 if (searchCriteria == null || searchCriteria.isEmpty() || StringUtils.isBlank(searchCriteria.get("termId")) || StringUtils.isBlank(searchCriteria.get("courseOfferingCode"))){
48 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,RiceKeyConstants.ERROR_CUSTOM,"Missing Course Offering code");
49 return false;
50 }
51 return true;
52 }
53
54 @Override
55 public List<?> performSearch(LookupForm lookupForm, Map<String, String> searchCriteria, boolean bounded) {
56 boolean isValidCriteria = validateSearchParameters(lookupForm, searchCriteria);
57 if (!isValidCriteria) {
58 return new ArrayList<Object>();
59 }
60
61 List<ActivityOfferingWrapper> activityOfferingWrappers = new ArrayList<ActivityOfferingWrapper>();
62
63 String termId = searchCriteria.get("termId");
64 String courseOfferingCode = searchCriteria.get("courseOfferingCode");
65
66
67
68
69 if (StringUtils.isNotBlank(termId) && StringUtils.isNotBlank(courseOfferingCode)){
70
71 SearchRequestInfo searchRequest = new SearchRequestInfo(CourseOfferingManagementSearchImpl.CO_MANAGEMENT_SEARCH.getKey());
72 searchRequest.addParam(CourseOfferingManagementSearchImpl.SearchParameters.COURSE_CODE, StringUtils.upperCase(courseOfferingCode));
73 searchRequest.addParam(CourseOfferingManagementSearchImpl.SearchParameters.ATP_ID, termId);
74 searchRequest.addParam(CourseOfferingManagementSearchImpl.SearchParameters.IS_EXACT_MATCH_CO_CODE_SEARCH, BooleanUtils.toStringTrueFalse(true));
75
76 try {
77 String coId = "";
78 SearchResultInfo searchResult = CourseOfferingManagementUtil.getSearchService().search(searchRequest, ContextUtils.createDefaultContextInfo());
79
80 if (searchResult.getRows().isEmpty()){
81 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM,"Invalid CourseOfferingCode " + courseOfferingCode);
82 } else if (searchResult.getRows().size() > 1){
83 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM,"Multiple CourseOfferings entries found for " + courseOfferingCode);
84 } else {
85 for(SearchResultCellInfo cellInfo : searchResult.getRows().get(0).getCells()){
86
87 if(CourseOfferingManagementSearchImpl.SearchResultColumns.CO_ID.equals(cellInfo.getKey())){
88 coId = cellInfo.getValue();
89 break;
90 }
91
92 }
93 }
94
95 if (StringUtils.isNotBlank(coId)){
96 List<ActivityOfferingInfo> aos = CourseOfferingManagementUtil.getCourseOfferingService().getActivityOfferingsByCourseOffering(coId,ContextUtils.createDefaultContextInfo());
97 for (ActivityOfferingInfo activityOffering : aos) {
98 CO_AO_RG_ViewHelperServiceImpl helper = new CO_AO_RG_ViewHelperServiceImpl();
99 ActivityOfferingWrapper wrapper = helper.convertAOInfoToWrapper(activityOffering);
100 wrapper.setCourseOfferingId(coId);
101 activityOfferingWrappers.add(wrapper);
102 }
103 }
104
105 } catch (Exception e){
106 throw new RuntimeException(e);
107 }
108
109 }
110
111 return activityOfferingWrappers;
112 }
113
114 }