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 David Yin on 10/20/13
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.ActivityOfferingInfo;
21  import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
22  import org.kuali.student.enrollment.examoffering.dto.ExamOfferingInfo;
23  import org.kuali.student.enrollment.examoffering.dto.ExamOfferingRelationInfo;
24  import org.kuali.student.enrollment.examoffering.service.ExamOfferingService;
25  import org.kuali.student.r2.common.dto.ContextInfo;
26  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
27  import org.kuali.student.r2.common.exceptions.InvalidParameterException;
28  import org.kuali.student.r2.common.exceptions.MissingParameterException;
29  import org.kuali.student.r2.common.exceptions.OperationFailedException;
30  import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
31  import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
32  import org.kuali.student.r2.common.util.constants.ExamOfferingServiceConstants;
33  import org.kuali.student.r2.core.class1.state.service.RelatedObjectHelper;
34  
35  import javax.xml.namespace.QName;
36  import java.util.ArrayList;
37  import java.util.HashMap;
38  import java.util.List;
39  import java.util.Map;
40  
41  /**
42   * This class retrieves the associated activity offerings given an exam offering
43   * It is for processing exam offering state constraints
44   *
45   * @author Kuali Student Team
46   */
47  public class RelatedObjectHelperEOtoAOImpl implements RelatedObjectHelper {
48      private ExamOfferingService examOfferingService;
49      private CourseOfferingService courseOfferingService;
50  
51      public RelatedObjectHelperEOtoAOImpl() {
52      }
53  
54      @Override
55      public Map<String, String> getRelatedObjectsIdAndState(String examOfferingId, ContextInfo contextInfo)
56              throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
57  
58          Map<String, String> idsAndStatesMap = new HashMap<String, String>();
59          List<ExamOfferingRelationInfo> eoRelations = this.getExamOfferingService().getExamOfferingRelationsByExamOffering(examOfferingId, contextInfo);
60          if(eoRelations==null || eoRelations.isEmpty()){
61              return idsAndStatesMap;
62          }
63  
64          List<String> activityOfferingIds = new ArrayList<String>();
65  
66          for(ExamOfferingRelationInfo eoRelation : eoRelations){
67              activityOfferingIds.addAll(eoRelation.getActivityOfferingIds());
68          }
69  
70          if (activityOfferingIds!=null && !activityOfferingIds.isEmpty()) {
71              List<ActivityOfferingInfo> aoInfoList = getCourseOfferingService().getActivityOfferingsByIds(activityOfferingIds,contextInfo);
72              for(ActivityOfferingInfo activityOfferingInfo : aoInfoList) {
73                  idsAndStatesMap.put(activityOfferingInfo.getId(),activityOfferingInfo.getStateKey());
74              }
75          }
76  
77          return idsAndStatesMap;
78      }
79  
80      protected ExamOfferingService getExamOfferingService(){
81          if (examOfferingService == null){
82              examOfferingService = (ExamOfferingService) GlobalResourceLoader.getService(new QName(ExamOfferingServiceConstants.NAMESPACE, ExamOfferingServiceConstants.SERVICE_NAME_LOCAL_PART));
83          }
84          return  examOfferingService;
85      }
86  
87      protected CourseOfferingService getCourseOfferingService(){
88          if (courseOfferingService == null){
89              courseOfferingService = (CourseOfferingService) GlobalResourceLoader.getService(new QName(CourseOfferingServiceConstants.NAMESPACE, CourseOfferingServiceConstants.SERVICE_NAME_LOCAL_PART));
90          }
91          return  courseOfferingService;
92      }
93  }