View Javadoc

1   package org.kuali.student.enrollment.class1.state.impl;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
5   import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
6   import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
7   import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
8   import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
9   import org.kuali.student.enrollment.examoffering.dto.ExamOfferingInfo;
10  import org.kuali.student.enrollment.examoffering.dto.ExamOfferingRelationInfo;
11  import org.kuali.student.enrollment.examoffering.service.ExamOfferingService;
12  import org.kuali.student.r2.common.dto.ContextInfo;
13  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
14  import org.kuali.student.r2.common.exceptions.InvalidParameterException;
15  import org.kuali.student.r2.common.exceptions.MissingParameterException;
16  import org.kuali.student.r2.common.exceptions.OperationFailedException;
17  import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
18  import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
19  import org.kuali.student.r2.common.util.constants.ExamOfferingServiceConstants;
20  import org.kuali.student.r2.common.util.constants.LuServiceConstants;
21  import org.kuali.student.r2.core.class1.state.service.RelatedObjectHelper;
22  
23  import javax.xml.namespace.QName;
24  import java.util.HashMap;
25  import java.util.List;
26  import java.util.Map;
27  
28  /**
29   * @Version 2.0
30   * @Author Sri komandur@uw.edu
31   */
32  
33  public class RelatedObjectHelperAOtoEOImpl implements RelatedObjectHelper {
34  
35      private ExamOfferingService examOfferingService;
36      private CourseOfferingService courseOfferingService;
37  
38      public RelatedObjectHelperAOtoEOImpl() {
39      }
40  
41      @Override
42      public Map<String, String> getRelatedObjectsIdAndState(String activityOfferingId, ContextInfo contextInfo)
43              throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
44  
45          Map<String, String> idsAndStatesMap = new HashMap<String, String>();
46  
47          //retrieve the final exam driver of the CO that the AO is associated with
48          String finalExamDriver = null;
49          ActivityOfferingInfo aoInfo = this.getCourseOfferingService().getActivityOffering(activityOfferingId, contextInfo);
50          if (aoInfo != null) {
51              CourseOfferingInfo coInfo = this.getCourseOfferingService().getCourseOffering(aoInfo.getCourseOfferingId(), contextInfo);
52              if (coInfo != null) {
53                  finalExamDriver = coInfo.getAttributeValue(CourseOfferingServiceConstants.FINAL_EXAM_DRIVER_ATTR);
54              }
55          }
56  
57          if (StringUtils.equals(finalExamDriver, LuServiceConstants.LU_EXAM_DRIVER_AO_KEY)) {
58              List<String> eoRelationIds = this.getExamOfferingService().getExamOfferingRelationIdsByActivityOffering(activityOfferingId, contextInfo);
59  
60              if(eoRelationIds.isEmpty()){
61                  return idsAndStatesMap;
62              }
63  
64              List<ExamOfferingRelationInfo> eoRelations = this.getExamOfferingService().getExamOfferingRelationsByIds(eoRelationIds, contextInfo);
65              for(ExamOfferingRelationInfo eoRelation : eoRelations){
66                  ExamOfferingInfo examOffering = this.getExamOfferingService().getExamOffering(eoRelation.getExamOfferingId(), contextInfo);
67  
68                  if (StringUtils.equals(examOffering.getAttributeValue(ExamOfferingServiceConstants.FINAL_EXAM_DRIVER_ATTR), "PER_AO")) {
69                      idsAndStatesMap.put(examOffering.getId(), examOffering.getStateKey());
70                  }
71              }
72          }
73  
74  
75          return idsAndStatesMap;
76      }
77  
78      protected ExamOfferingService getExamOfferingService(){
79          if (examOfferingService == null){
80              examOfferingService = (ExamOfferingService) GlobalResourceLoader.getService(new QName(ExamOfferingServiceConstants.NAMESPACE, ExamOfferingServiceConstants.SERVICE_NAME_LOCAL_PART));
81          }
82          return  examOfferingService;
83      }
84  
85      protected CourseOfferingService getCourseOfferingService(){
86          if (courseOfferingService == null){
87              courseOfferingService = (CourseOfferingService) GlobalResourceLoader.getService(new QName(CourseOfferingServiceConstants.NAMESPACE, CourseOfferingServiceConstants.SERVICE_NAME_LOCAL_PART));
88          }
89          return  courseOfferingService;
90      }
91  
92  }