1
2
3
4
5
6
7
8
9
10
11
12
13
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
33
34 public class LrcContextImpl extends BasicContextImpl {
35
36 private LRCService lrcService;
37 private TypeService typeService;
38
39
40
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
89
90
91
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 }