1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.courseofferingset.service.impl;
17
18 import org.apache.log4j.Logger;
19 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
20 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
21 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
22 import org.kuali.student.enrollment.courseofferingset.dto.SocInfo;
23 import org.kuali.student.enrollment.courseofferingset.service.CourseOfferingSetService;
24 import org.kuali.student.r2.common.dto.ContextInfo;
25 import org.kuali.student.r2.common.dto.StatusInfo;
26 import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants;
27 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
28 import org.kuali.student.r2.core.scheduling.service.SchedulingService;
29
30 import java.util.Date;
31 import java.util.List;
32
33
34
35
36
37
38
39 public class CourseOfferingSetSchedulingRunner implements Runnable {
40
41 final static Logger logger = Logger.getLogger(CourseOfferingSetSchedulingRunner.class);
42
43 private final StringBuffer logBuffer = new StringBuffer();
44
45 private final String socId;
46
47 private CourseOfferingSetService socService;
48
49 private SchedulingService schedulingService;
50
51 private CourseOfferingService coService;
52
53 private ContextInfo contextInfo;
54
55 public CourseOfferingSetSchedulingRunner (String socId) {
56 this.socId = socId;
57 }
58
59 public CourseOfferingService getCoService() {
60 return coService;
61 }
62
63 public void setCoService(CourseOfferingService coService) {
64 this.coService = coService;
65 }
66
67 public SchedulingService getSchedulingService() {
68 return schedulingService;
69 }
70
71 public void setSchedulingService(SchedulingService schedulingService) {
72 this.schedulingService = schedulingService;
73 }
74
75 public CourseOfferingSetService getSocService() {
76 return socService;
77 }
78
79 public void setSocService(CourseOfferingSetService socService) {
80 this.socService = socService;
81 }
82
83 public ContextInfo getContextInfo() {
84 return contextInfo;
85 }
86
87 public void setContextInfo(ContextInfo contextInfo) {
88 this.contextInfo = contextInfo;
89 }
90
91
92
93
94 @Override
95 public void run() {
96 try {
97 SocInfo soc = socService.getSoc(socId, contextInfo);
98 List<String> coIds = socService.getCourseOfferingIdsBySoc(soc.getId(), contextInfo);
99
100 log("Submitting ", coIds.size(), " course offerings for scheduling");
101
102 for (String id : coIds) {
103 CourseOfferingInfo coInfo = coService.getCourseOffering(id, contextInfo);
104 log("Processing schedule requests in AOs for CO, id=", coInfo.getId(), " , coCode=",coInfo.getCourseOfferingCode());
105
106 List<ActivityOfferingInfo> activityOfferings = coService.getActivityOfferingsByCourseOffering(id, contextInfo);
107
108 for (ActivityOfferingInfo aoInfo : activityOfferings) {
109 log("\tProcessing schedule requests in AO, id=", aoInfo.getId(), " , code=",aoInfo.getActivityCode(), " type=", aoInfo.getTypeKey());
110
111 if(aoInfo.getStateKey().equals(LuiServiceConstants.LUI_AO_STATE_APPROVED_KEY)) {
112 StatusInfo status = coService.scheduleActivityOffering(aoInfo.getId(), contextInfo);
113 log("\t...scheduleActivityOffering returned with a status of ", status.getIsSuccess(), " , message=", status.getMessage());
114 }
115 else {
116 log("\t...Activity Offering not sent to scheduler, not in a valid state to schedule: ", aoInfo.getStateKey());
117 }
118 }
119 }
120
121
122 contextInfo.setCurrentDate(new Date());
123 socService.updateSocState(socId, CourseOfferingSetServiceConstants.SOC_SCHEDULING_STATE_COMPLETED, contextInfo);
124
125 } catch (Exception e) {
126
127 logger.fatal(e);
128 throw new RuntimeException(e);
129 }
130 }
131
132 private void log(Object ... params) {
133 logBuffer.setLength(0);
134 for (Object o : params) {
135 logBuffer.append(o);
136 }
137 logger.info(logBuffer.toString());
138 logBuffer.setLength(0);
139 }
140
141 }