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 chongzhu on 11/27/12
16   */
17  package org.kuali.student.enrollment.class1.state.impl;
18  
19  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
20  import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
21  import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
22  import org.kuali.student.r2.common.dto.ContextInfo;
23  import org.kuali.student.r2.common.dto.StatusInfo;
24  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
25  import org.kuali.student.r2.common.exceptions.InvalidParameterException;
26  import org.kuali.student.r2.common.exceptions.MissingParameterException;
27  import org.kuali.student.r2.common.exceptions.OperationFailedException;
28  import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
29  import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
30  import org.kuali.student.r2.core.class1.state.service.StateHelper;
31  
32  import javax.xml.namespace.QName;
33  
34  /**
35   *  * @Version 2.0
36   *
37   * @author Kuali Student Team
38   */
39  public class FOStateHelperImpl implements StateHelper {
40      CourseOfferingService courseOfferingService;
41      public FOStateHelperImpl() {
42      }
43  
44      protected CourseOfferingService getCourseOfferingService(){
45          if (courseOfferingService == null){
46              courseOfferingService = (CourseOfferingService) GlobalResourceLoader.getService(new QName(CourseOfferingServiceConstants.NAMESPACE, CourseOfferingServiceConstants.SERVICE_NAME_LOCAL_PART));
47          }
48          return  courseOfferingService;
49      }
50  
51      @Override
52      public StatusInfo updateState(String id, String nextStateKey, ContextInfo contextInfo) {
53          StatusInfo si = null;
54          try {
55              si = getCourseOfferingService().changeFormatOfferingState(id, nextStateKey, contextInfo);
56              si.setSuccess(true);
57          } catch (Exception e) {
58              si.setSuccess(false);
59          }
60          return si;
61      }
62  
63      @Override
64      public String getStateKey(String entityId, ContextInfo context) throws InvalidParameterException, MissingParameterException, DoesNotExistException, OperationFailedException, PermissionDeniedException {
65          FormatOfferingInfo fo = getCourseOfferingService().getFormatOffering(entityId, context);
66          return fo.getStateKey();
67      }
68  }