1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.courseofferingset.service.impl;
18
19 import org.apache.log4j.Logger;
20 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
21 import org.kuali.student.enrollment.courseofferingset.dto.SocInfo;
22 import org.kuali.student.enrollment.courseofferingset.dto.SocRolloverResultItemInfo;
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.util.constants.CourseOfferingSetServiceConstants;
26
27 import java.util.List;
28
29
30
31
32
33
34
35
36
37 public class DeleteTargetTermRolloverRunner implements Runnable {
38 CourseOfferingSetService socService;
39 CourseOfferingService coService;
40 String termId;
41
42 final static Logger LOGGER = Logger.getLogger(DeleteTargetTermRolloverRunner.class);
43
44 public CourseOfferingSetService getSocService() {
45 return socService;
46 }
47
48 public void setSocService(CourseOfferingSetService socService) {
49 this.socService = socService;
50 }
51
52 public CourseOfferingService getCoService() {
53 return coService;
54 }
55
56 public void setCoService(CourseOfferingService coService) {
57 this.coService = coService;
58 }
59
60 public String getTermId() {
61 return termId;
62 }
63
64 public void setTermId(String termId) {
65 this.termId = termId;
66 }
67
68 private SocInfo _getMainSoc(List<String> socIds) {
69 try {
70 List<SocInfo> socInfoList = socService.getSocsByIds(socIds, new ContextInfo());
71 for (SocInfo socInfo: socInfoList) {
72 if (socInfo.getTypeKey().equals(CourseOfferingSetServiceConstants.MAIN_SOC_TYPE_KEY)) {
73 return socInfo;
74 }
75 }
76 } catch (Exception e) {
77
78 }
79 return null;
80 }
81
82 @Override
83 public void run() {
84 try {
85 List<String> socIds = socService.getSocIdsByTerm(termId, new ContextInfo());
86 SocInfo socInfo = _getMainSoc(socIds);
87 if (socInfo == null) {
88 return;
89 }
90 List<String> coIds = socService.getCourseOfferingIdsBySoc(socInfo.getId(), new ContextInfo());
91
92 for (String coId: coIds) {
93 coService.deleteCourseOfferingCascaded(coId, new ContextInfo());
94 }
95
96
97 List<String> resultIds = socService.getSocRolloverResultIdsByTargetSoc(socInfo.getId(), new ContextInfo());
98
99 for (String resultId: resultIds) {
100 List<SocRolloverResultItemInfo> itemList = socService.getSocRolloverResultItemsByResultId(resultId, new ContextInfo());
101
102 for (SocRolloverResultItemInfo item: itemList) {
103 socService.deleteSocRolloverResultItem(item.getId(), new ContextInfo());
104 }
105
106 socService.deleteSocRolloverResult(resultId, new ContextInfo());
107 }
108 } catch (Exception e) {
109 e.printStackTrace();
110 }
111 }
112 }