View Javadoc

1   /**
2    * Copyright 2012 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   *
15   * Created by Charles on 6/14/12
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   * Cleans up any SOC Rollover Info, SOC Rollover Result Items in a term.  Deletes all course offerings (COs)
31   * and anything dependent on it (FO/CO) including attributes.
32   * 
33   * Similar to reverse rollover, but does not generate
34   *
35   * @author cclin
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              // Cascade delete course offerings
92              for (String coId: coIds) {
93                  coService.deleteCourseOfferingCascaded(coId, new ContextInfo());
94              }
95              // Delete SocInfo items
96              // 1 Get rollover results
97              List<String> resultIds = socService.getSocRolloverResultIdsByTargetSoc(socInfo.getId(), new ContextInfo());
98              // 2 Iterate over the results
99              for (String resultId: resultIds) {
100                 List<SocRolloverResultItemInfo> itemList = socService.getSocRolloverResultItemsByResultId(resultId, new ContextInfo());
101                 // 2.1 Delete the items
102                 for (SocRolloverResultItemInfo item: itemList) {
103                     socService.deleteSocRolloverResultItem(item.getId(), new ContextInfo());
104                 }
105                 // 2.2 Delete the info
106                 socService.deleteSocRolloverResult(resultId, new ContextInfo());
107             }
108         } catch (Exception e) {
109             e.printStackTrace();
110         }
111     }
112 }