1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class1.krms.builder;
17
18 import org.apache.commons.lang.BooleanUtils;
19 import org.apache.log4j.Logger;
20 import org.kuali.rice.krad.util.GlobalVariables;
21 import org.kuali.rice.krms.util.PropositionTreeUtil;
22 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingConstants;
23 import org.kuali.student.lum.lu.ui.krms.builder.CourseComponentBuilder;
24 import org.kuali.student.lum.lu.ui.krms.dto.LUPropositionEditor;
25 import org.kuali.student.r2.common.util.ContextUtils;
26 import org.kuali.student.r2.core.class1.search.CourseOfferingManagementSearchImpl;
27 import org.kuali.student.r2.core.constants.KSKRMSServiceConstants;
28 import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
29 import org.kuali.student.r2.core.search.dto.SearchResultInfo;
30
31 import java.util.HashMap;
32 import java.util.Map;
33
34
35
36
37 public class EnrolCourseComponentBuilder extends CourseComponentBuilder {
38
39 private final static Logger LOG = Logger.getLogger(EnrolCourseComponentBuilder.class);
40
41 @Override
42 public Map<String, String> buildTermParameters(LUPropositionEditor propositionEditor) {
43 Map<String, String> termParameters = new HashMap<String, String>();
44 if (propositionEditor.getCourseInfo() != null) {
45 termParameters.put(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_CLU_KEY, propositionEditor.getCourseInfo().getVersion().getVersionIndId());
46 }
47
48 if (propositionEditor.getTermInfo() != null) {
49 termParameters.put(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_TERM_KEY, propositionEditor.getTermInfo().getId());
50 termParameters.put(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_TERMCODE_KEY, propositionEditor.getTermCode());
51 String propName = PropositionTreeUtil.getBindingPath(propositionEditor, "termCode");
52 loadCourseOfferingsByTermAndCourseCode(propositionEditor.getTermInfo().getId(), propositionEditor.getCourseInfo().getCode(), propName);
53 }
54
55 if (propositionEditor.getTermInfo2() != null) {
56 termParameters.put(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_TERM2_KEY, propositionEditor.getTermInfo2().getId());
57 termParameters.put(KSKRMSServiceConstants.TERM_PARAMETER_TYPE_TERMCODE2_KEY, propositionEditor.getTermCode2());
58 String propName = PropositionTreeUtil.getBindingPath(propositionEditor, "termCode2");
59 loadCourseOfferingsByTermAndCourseCode(propositionEditor.getTermInfo2().getId(), propositionEditor.getCourseInfo().getCode(),propName );
60 }
61
62 return termParameters;
63 }
64
65
66
67
68
69
70
71
72
73 public void loadCourseOfferingsByTermAndCourseCode(String termId, String courseCode, String propName ) {
74
75 SearchRequestInfo searchRequest = new SearchRequestInfo(CourseOfferingManagementSearchImpl.CO_MANAGEMENT_SEARCH.getKey());
76 searchRequest.addParam(CourseOfferingManagementSearchImpl.SearchParameters.COURSE_CODE, courseCode);
77 searchRequest.addParam(CourseOfferingManagementSearchImpl.SearchParameters.ATP_ID, termId);
78 searchRequest.addParam(CourseOfferingManagementSearchImpl.SearchParameters.CROSS_LIST_SEARCH_ENABLED, BooleanUtils.toStringTrueFalse(true));
79
80 SearchResultInfo searchResult = null;
81 try {
82 searchResult = getSearchService().search(searchRequest, ContextUtils.getContextInfo());
83 } catch (Exception e) {
84 throw new RuntimeException(e);
85 }
86 if (searchResult.getRows().isEmpty()) {
87 LOG.error("Error: Can't find any Course Offering for a Course Code: " + courseCode + " in term: " + termId);
88 GlobalVariables.getMessageMap().putError(propName, CourseOfferingConstants.COURSEOFFERING_MSG_ERROR_NO_COURSE_OFFERING_IS_FOUND, "Course Code",courseCode, termId);
89 }
90 }
91
92 }