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 venkat 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.exceptions.DoesNotExistException;
24  import org.kuali.student.r2.common.exceptions.InvalidParameterException;
25  import org.kuali.student.r2.common.exceptions.MissingParameterException;
26  import org.kuali.student.r2.common.exceptions.OperationFailedException;
27  import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
28  import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
29  import org.kuali.student.r2.core.class1.state.service.RelatedObjectHelper;
30  
31  import javax.xml.namespace.QName;
32  import java.util.HashMap;
33  import java.util.List;
34  import java.util.Map;
35  
36  /**
37   * This class implements RelatedObjectHelper to provide relation logic for Course Offerings and Format Offerings
38   *
39   * @author Kuali Student Team
40   */
41  public class RelatedObjectHelperCOtoFOImpl implements RelatedObjectHelper {
42  
43      private CourseOfferingService courseOfferingService;
44  
45      @Override
46      public Map<String, String> getRelatedObjectsIdAndState(String entityId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
47          //TODO - FIXME - these are expensive calls to get ids and states (should be done with one DB call using search)
48          List<FormatOfferingInfo> formatOfferingInfos = getCourseOfferingService().getFormatOfferingsByCourseOffering(entityId, contextInfo);
49          Map<String,String> idsAndState = new HashMap<String, String>();
50          for (FormatOfferingInfo formatOfferingInfo : formatOfferingInfos) {
51              idsAndState.put(formatOfferingInfo.getId(), formatOfferingInfo.getStateKey());
52          }
53          return idsAndState;
54      }
55  
56      protected CourseOfferingService getCourseOfferingService(){
57          if (courseOfferingService == null){
58              courseOfferingService = (CourseOfferingService) GlobalResourceLoader.getService(new QName(CourseOfferingServiceConstants.NAMESPACE, CourseOfferingServiceConstants.SERVICE_NAME_LOCAL_PART));
59          }
60          return  courseOfferingService;
61      }
62  
63  
64  }