1 | |
package org.kuali.student.enrollment.class2.courseoffering.service; |
2 | |
|
3 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
4 | |
import org.kuali.rice.kns.uif.service.impl.LookupViewHelperServiceImpl; |
5 | |
import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo; |
6 | |
import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService; |
7 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
8 | |
import org.kuali.student.r2.common.exceptions.*; |
9 | |
|
10 | |
import javax.xml.namespace.QName; |
11 | |
import java.util.ArrayList; |
12 | |
import java.util.List; |
13 | |
import java.util.Map; |
14 | |
|
15 | 0 | public class CourseOfferingInfoLookupViewHelperServiceImpl extends LookupViewHelperServiceImpl { |
16 | |
|
17 | |
private transient CourseOfferingService courseOfferingService; |
18 | |
private static final String TERM_FIELD_NAME = "termKey"; |
19 | |
private static final String SUBJECT_AREA_FIELD_NAME = "subjectArea"; |
20 | |
|
21 | 0 | private static Boolean foundValidCourseOfferings = null; |
22 | |
|
23 | |
@Override |
24 | |
protected List<?> getSearchResultsWithBounding(Map<String, String> fieldValues, boolean unbounded) { |
25 | |
|
26 | 0 | ContextInfo context = ContextInfo.newInstance(); |
27 | 0 | String termKey = fieldValues.get(TERM_FIELD_NAME); |
28 | 0 | String subjectArea = fieldValues.get(SUBJECT_AREA_FIELD_NAME); |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | if(foundValidCourseOfferings == null) { |
37 | |
try { |
38 | 0 | List<String> courseOfferingIds = getCourseOfferingService().getCourseOfferingIdsByTermAndSubjectArea("testTermId1", "CHEM", context); |
39 | 0 | foundValidCourseOfferings = !courseOfferingIds.isEmpty(); |
40 | 0 | } catch (DoesNotExistException e) { |
41 | 0 | throw new RuntimeException(e); |
42 | 0 | } catch (InvalidParameterException e) { |
43 | 0 | throw new RuntimeException(e); |
44 | 0 | } catch (MissingParameterException e) { |
45 | 0 | throw new RuntimeException(e); |
46 | 0 | } catch (OperationFailedException e) { |
47 | 0 | throw new RuntimeException(e); |
48 | 0 | } catch (PermissionDeniedException e) { |
49 | 0 | throw new RuntimeException(e); |
50 | 0 | } |
51 | |
} |
52 | |
|
53 | 0 | if(!foundValidCourseOfferings) { |
54 | |
try { |
55 | 0 | getCourseOfferingService().createCourseOfferingFromCanonical("REFERENCECOURSECHEM131", "testTermId1", null, context); |
56 | 0 | getCourseOfferingService().createCourseOfferingFromCanonical("REFERENCECOURSECHEM132", "testTermId1", null, context); |
57 | |
|
58 | 0 | foundValidCourseOfferings = true; |
59 | 0 | } catch (Exception e) { |
60 | 0 | throw new RuntimeException(e); |
61 | 0 | } |
62 | |
} |
63 | |
|
64 | |
List<CourseOfferingInfo> courseOfferings; |
65 | |
|
66 | |
try { |
67 | 0 | List<String> courseOfferingIds = getCourseOfferingService().getCourseOfferingIdsByTermAndSubjectArea(termKey, subjectArea, context); |
68 | 0 | courseOfferings = new ArrayList<CourseOfferingInfo>(courseOfferingIds.size()); |
69 | |
|
70 | 0 | for(String coId : courseOfferingIds) { |
71 | 0 | courseOfferings.add(getCourseOfferingService().getCourseOffering(coId, context)); |
72 | |
} |
73 | |
|
74 | 0 | } catch (DoesNotExistException e) { |
75 | 0 | throw new RuntimeException(e); |
76 | 0 | } catch (InvalidParameterException e) { |
77 | 0 | throw new RuntimeException(e); |
78 | 0 | } catch (MissingParameterException e) { |
79 | 0 | throw new RuntimeException(e); |
80 | 0 | } catch (OperationFailedException e) { |
81 | 0 | throw new RuntimeException(e); |
82 | 0 | } catch (PermissionDeniedException e) { |
83 | 0 | throw new RuntimeException(e); |
84 | 0 | } |
85 | |
|
86 | 0 | return courseOfferings; |
87 | |
} |
88 | |
|
89 | |
protected CourseOfferingService getCourseOfferingService() { |
90 | 0 | if (courseOfferingService == null) { |
91 | 0 | courseOfferingService = (CourseOfferingService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/courseOffering", "CourseOfferingService")); |
92 | |
} |
93 | |
|
94 | 0 | return courseOfferingService; |
95 | |
} |
96 | |
} |