View Javadoc

1   /**
2    * Copyright 2013 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 8/9/13
16   */
17  package org.kuali.student.enrollment.class2.courseoffering.service.facade;
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
21  import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
22  import org.kuali.student.enrollment.courseofferingset.service.CourseOfferingSetService;
23  import org.kuali.student.r2.common.dto.ContextInfo;
24  import org.kuali.student.r2.common.dto.StatusInfo;
25  import org.kuali.student.r2.common.exceptions.OperationFailedException;
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.class1.type.service.TypeService;
29  
30  import javax.annotation.Resource;
31  
32  /**
33   * Impl for CSR
34   *
35   * @author Kuali Student Team
36   */
37  public class CSRServiceFacadeImpl implements CSRServiceFacade {
38      @Resource(name="coService")
39      private CourseOfferingService coService;
40  
41      @Resource(name="typeService")
42      private TypeService typeService;
43  
44      @Resource(name="socService")
45      private CourseOfferingSetService socService;
46  
47      public void setCoService(CourseOfferingService coService) {
48          this.coService = coService;
49      }
50  
51      public void setTypeService(TypeService typeService) {
52          this.typeService = typeService;
53      }
54  
55      public void setSocService(CourseOfferingSetService socService) {
56          this.socService = socService;
57      }
58  
59      @Override
60      public void cancelActivityOffering(String aoId, ContextInfo context) throws Exception {
61          StatusInfo statusInfo = coService.changeActivityOfferingState(aoId, LuiServiceConstants.LUI_AO_STATE_CANCELED_KEY, context);
62          if (!statusInfo.getIsSuccess()){
63              throw new OperationFailedException("Error updating Activity offering state to " + LuiServiceConstants.LUI_AO_STATE_CANCELED_KEY + " " + statusInfo);
64          }
65      }
66  
67      @Override
68      public void suspendActivityOffering(String aoId, ContextInfo context) throws Exception {
69          StatusInfo statusInfo = coService.changeActivityOfferingState(aoId, LuiServiceConstants.LUI_AO_STATE_SUSPENDED_KEY, context);
70          if (!statusInfo.getIsSuccess()){
71              throw new OperationFailedException("Error updating Activity offering state to " + LuiServiceConstants.LUI_AO_STATE_SUSPENDED_KEY + " " + statusInfo);
72          }
73      }
74  
75      @Override
76      public void reinstateActivityOffering(ActivityOfferingInfo aoInfo, String socState, ContextInfo context) throws Exception {
77          // Checking if we have ADLs for AO or not. If we have no ADLs (scheduleIDs) -> AO goes into draft state, otherwise will depend on SOC state
78          if (aoInfo.getScheduleIds() != null && !aoInfo.getScheduleIds().isEmpty()) {
79              if (StringUtils.equals(socState, CourseOfferingSetServiceConstants.PUBLISHED_SOC_STATE_KEY)) {
80                  StatusInfo statusInfo = coService.changeActivityOfferingState(aoInfo.getId(), LuiServiceConstants.LUI_AO_STATE_OFFERED_KEY, context);
81                  if (!statusInfo.getIsSuccess()){
82                      throw new OperationFailedException("Error updating Activity offering state to " + LuiServiceConstants.LUI_AO_STATE_OFFERED_KEY + " " + statusInfo);
83                  }
84              } else if (StringUtils.equals(socState, CourseOfferingSetServiceConstants.FINALEDITS_SOC_STATE_KEY) ||
85                              StringUtils.equals(socState, CourseOfferingSetServiceConstants.LOCKED_SOC_STATE_KEY)) {
86                  StatusInfo statusInfo = coService.changeActivityOfferingState(aoInfo.getId(), LuiServiceConstants.LUI_AO_STATE_APPROVED_KEY, context);
87                  if (!statusInfo.getIsSuccess()){
88                      throw new OperationFailedException("Error updating Activity offering state to " + LuiServiceConstants.LUI_AO_STATE_APPROVED_KEY + " " + statusInfo);
89                  }
90              } else {
91                  throw new RuntimeException("Error reinstating Activity offering in SOC " + socState);
92              }
93          } else {
94              StatusInfo statusInfo = coService.changeActivityOfferingState(aoInfo.getId(), LuiServiceConstants.LUI_AO_STATE_DRAFT_KEY, context);
95              if (!statusInfo.getIsSuccess()){
96                  throw new OperationFailedException("Error updating Activity offering state to " + LuiServiceConstants.LUI_AO_STATE_DRAFT_KEY + " " + statusInfo);
97              }
98          }
99      }
100 }