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.dto.ContextInfo;
21 import org.kuali.student.r2.common.exceptions.OperationFailedException;
22 import org.kuali.student.r2.common.util.ContextUtils;
23 import org.kuali.student.r2.core.atp.service.AtpService;
24 import org.kuali.student.r2.core.class1.type.dto.TypeInfo;
25 import org.kuali.student.r2.core.class1.type.service.TypeService;
26
27 import java.util.Map;
28
29
30
31
32
33 public class AtpContextImpl extends BasicContextImpl {
34
35
36 private AtpService atpService;
37 private TypeService typeService;
38
39 public final static String DURATION_TYPE_TOKEN = "durationType";
40 public final static String DURATION_TOKEN = "duration";
41
42 public void setAtpService(AtpService atpService) {
43 this.atpService = atpService;
44 }
45
46
47 public TypeService getTypeService() {
48 return typeService;
49 }
50
51 public void setTypeService(TypeService typeService) {
52 this.typeService = typeService;
53 }
54
55 private TypeInfo getAtpDurationType(String atpDurationTypeKey) throws OperationFailedException {
56 if (atpDurationTypeKey == null) {
57 return null;
58 }
59 try {
60 TypeInfo atpDurationType = this.getTypeService().getType(atpDurationTypeKey, ContextUtils.getContextInfo());
61 return atpDurationType;
62 } catch (Exception e) {
63 throw new OperationFailedException(e.getMessage(), e);
64 }
65 }
66
67
68
69
70
71
72
73
74
75
76 public Map<String, Object> createContextMap(ReqComponentInfo reqComponent, ContextInfo contextInfo) throws OperationFailedException {
77 String durationTypeKey = getReqComponentFieldValue(reqComponent, ReqComponentFieldTypes.DURATION_TYPE_KEY.getId());
78 String duration = getReqComponentFieldValue(reqComponent, ReqComponentFieldTypes.DURATION_KEY.getId());
79 TypeInfo atpDurationType = getAtpDurationType(durationTypeKey);
80
81 Map<String, Object> contextMap = super.createContextMap(reqComponent, contextInfo);
82 contextMap.put(DURATION_TYPE_TOKEN, atpDurationType);
83 contextMap.put(DURATION_TOKEN, duration);
84 return contextMap;
85 }
86 }