View Javadoc

1   /**
2    * Copyright 2010 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/lic enses/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  
16  package org.kuali.student.r2.lum.statement.config.context;
17  
18  import org.kuali.student.r1.core.statement.dto.ReqComponentInfo;
19  import org.kuali.student.r1.lum.statement.typekey.ReqComponentFieldTypes;
20  import org.kuali.student.r2.common.class1.type.service.TypeService;
21  import org.kuali.student.r2.common.dto.ContextInfo;
22  import org.kuali.student.r2.common.exceptions.OperationFailedException;
23  import org.kuali.student.r2.lum.lrc.dto.ResultScaleInfo;
24  import org.kuali.student.r2.lum.lrc.dto.ResultValueInfo;
25  import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
26  import org.kuali.student.r2.lum.lrc.service.LRCService;
27  
28  import java.util.HashMap;
29  import java.util.Map;
30  
31  /**
32   * This class creates the template context for grade condition type.
33   */
34  public class LrcContextImpl extends BasicContextImpl {
35  
36      private LRCService lrcService;
37      private TypeService typeService;
38  
39      /**
40       * Total credits template token
41       */
42      public final static String GRADE_TOKEN = "grade";
43      public final static String GRADE_TYPE_TOKEN = "gradeType";
44  
45      public void setLrcService(LRCService lrcService) {
46          this.lrcService = lrcService;
47      }
48  
49      public TypeService getTypeService() {
50          return typeService;
51      }
52  
53      public void setTypeService(TypeService typeService) {
54          this.typeService = typeService;
55      }
56  
57      private ResultScaleInfo getResultScale(String resultScaleId, ContextInfo contextInfo) throws OperationFailedException {
58          if (resultScaleId == null) {
59              return null;
60          }
61          try {
62              return lrcService.getResultScale(resultScaleId, contextInfo);
63          } catch (Exception e) {
64              throw new OperationFailedException(e.getMessage(), e);
65          }
66      }
67      private ResultValuesGroupInfo getResultValuesGroupByResultValueGroupId(String resultValueGroupId, ContextInfo contextInfo ) throws OperationFailedException {
68          if (resultValueGroupId == null) {
69              return null;
70          }
71          try {
72              return lrcService.getResultValuesGroup(resultValueGroupId,contextInfo);
73          } catch (Exception e) {
74              throw new OperationFailedException(e.getMessage(), e);
75          }
76      }
77  
78      private ResultValueInfo getResultValue(String resultValueId, ContextInfo contextInfo) throws OperationFailedException {
79          try {
80              return lrcService.getResultValue(resultValueId,contextInfo);
81          } catch (Exception e) {
82              throw new OperationFailedException(e.getMessage(), e);
83          }
84  
85      }
86  
87      /**
88       * Creates the context map (template data) for the requirement component.
89       *
90       * @param reqComponent Requirement component
91       * @throws OperationFailedException Creating context map fails
92       */
93      public Map<String, Object> createContextMap(ReqComponentInfo reqComponent, ContextInfo contextInfo) throws OperationFailedException {
94          Map<String, Object> contextMap = new HashMap<String, Object>();
95  
96          String gradeId = getReqComponentFieldValue(reqComponent, ReqComponentFieldTypes.GRADE_KEY.getId());
97          if (gradeId == null) {
98              gradeId = getReqComponentFieldValue(reqComponent, ReqComponentFieldTypes.GRADE_TYPE_KEY.getId());
99          }
100 
101         if (gradeId != null){
102         ResultValueInfo grade = getResultValue(gradeId, contextInfo);
103             if (grade != null) {
104                 contextMap.put(GRADE_TOKEN, grade.getValue());
105                 contextMap.put(GRADE_TYPE_TOKEN, getResultScale(grade.getResultScaleKey(),contextInfo));
106             }
107         }
108         return contextMap;
109     }
110 }