1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.courseofferingset.model;
18
19 import org.kuali.student.enrollment.courseofferingset.dto.SocRolloverResultInfo;
20 import org.kuali.student.enrollment.courseofferingset.infc.SocRolloverResult;
21 import org.kuali.student.r2.common.assembler.DynAttrConverter;
22 import org.kuali.student.r2.common.assembler.DynamicAttrReadOnlyWrapper;
23 import org.kuali.student.r2.common.assembler.DynamicAttrWrapper;
24 import org.kuali.student.r2.common.assembler.TransformUtility;
25 import org.kuali.student.r2.common.dto.AttributeInfo;
26 import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants;
27
28 import java.util.Date;
29 import java.util.HashMap;
30 import java.util.Map;
31
32
33
34
35
36
37 public class SocRolloverResultDynAttrConverter {
38 private static Map<String, DynamicAttrReadOnlyWrapper<SocRolloverResult>> _createDynAttrReadOnlyMap(SocRolloverResult result) {
39 Map<String, DynamicAttrReadOnlyWrapper<SocRolloverResult>> dynAttrReadOnlyMap =
40 new HashMap<String, DynamicAttrReadOnlyWrapper<SocRolloverResult>>();
41
42 dynAttrReadOnlyMap.put(CourseOfferingSetServiceConstants.DATE_INITIATED_RESULT_DYNATTR_KEY,
43 new DynamicAttrReadOnlyWrapper<SocRolloverResult>(result, Date.class,
44 CourseOfferingSetServiceConstants.DATE_INITIATED_RESULT_DYNATTR_KEY) {
45 @Override
46 public String writeOutStringValue() {
47 DynAttrConverter<Date> dateConverter = (DynAttrConverter<Date>) TransformUtility.getConverterByClass(Date.class);
48 String dateStr = dateConverter.convertNativeValueToString(getDto().getDateInitiated());
49 return dateStr;
50 }
51 });
52
53 dynAttrReadOnlyMap.put(CourseOfferingSetServiceConstants.DATE_COMPLETED_RESULT_DYNATTR_KEY,
54 new DynamicAttrReadOnlyWrapper<SocRolloverResult>(result, Date.class,
55 CourseOfferingSetServiceConstants.DATE_COMPLETED_RESULT_DYNATTR_KEY) {
56 @Override
57 public String writeOutStringValue() {
58 DynAttrConverter<Date> dateConverter = (DynAttrConverter<Date>) TransformUtility.getConverterByClass(Date.class);
59 String dateStr = dateConverter.convertNativeValueToString(getDto().getDateCompleted());
60 return dateStr;
61 }
62 });
63
64 dynAttrReadOnlyMap.put(CourseOfferingSetServiceConstants.CO_CREATED_RESULT_DYNATTR_KEY,
65 new DynamicAttrReadOnlyWrapper<SocRolloverResult>(result, Date.class,
66 CourseOfferingSetServiceConstants.CO_CREATED_RESULT_DYNATTR_KEY) {
67 @Override
68 public String writeOutStringValue() {
69 DynAttrConverter<Integer> intConverter = (DynAttrConverter<Integer>) TransformUtility.getConverterByClass(Integer.class);
70 String intStr = intConverter.convertNativeValueToString(getDto().getCourseOfferingsCreated());
71 return intStr;
72 }
73 });
74
75 dynAttrReadOnlyMap.put(CourseOfferingSetServiceConstants.CO_SKIPPED_RESULT_DYNATTR_KEY,
76 new DynamicAttrReadOnlyWrapper<SocRolloverResult>(result, Date.class,
77 CourseOfferingSetServiceConstants.CO_SKIPPED_RESULT_DYNATTR_KEY) {
78
79 @Override
80 public String writeOutStringValue() {
81 DynAttrConverter<Integer> intConverter = (DynAttrConverter<Integer>) TransformUtility.getConverterByClass(Integer.class);
82 String intStr = intConverter.convertNativeValueToString(getDto().getCourseOfferingsSkipped());
83 return intStr;
84 }
85 });
86
87 dynAttrReadOnlyMap.put(CourseOfferingSetServiceConstants.AO_CREATED_RESULT_DYNATTR_KEY,
88 new DynamicAttrReadOnlyWrapper<SocRolloverResult>(result, Date.class,
89 CourseOfferingSetServiceConstants.AO_CREATED_RESULT_DYNATTR_KEY) {
90
91 @Override
92 public String writeOutStringValue() {
93 DynAttrConverter<Integer> intConverter = (DynAttrConverter<Integer>) TransformUtility.getConverterByClass(Integer.class);
94 String intStr = intConverter.convertNativeValueToString(getDto().getActivityOfferingsCreated());
95 return intStr;
96 }
97 });
98
99 dynAttrReadOnlyMap.put(CourseOfferingSetServiceConstants.AO_SKIPPED_RESULT_DYNATTR_KEY,
100 new DynamicAttrReadOnlyWrapper<SocRolloverResult>(result, Date.class,
101 CourseOfferingSetServiceConstants.AO_SKIPPED_RESULT_DYNATTR_KEY) {
102
103 @Override
104 public String writeOutStringValue() {
105 DynAttrConverter<Integer> intConverter = (DynAttrConverter<Integer>) TransformUtility.getConverterByClass(Integer.class);
106 String intStr = intConverter.convertNativeValueToString(getDto().getActivityOfferingsSkipped());
107 return intStr;
108 }
109 });
110 return dynAttrReadOnlyMap;
111 }
112
113 private static Map<String, DynamicAttrWrapper<SocRolloverResultInfo>> _createDynAttrMap(SocRolloverResultInfo result) {
114 Map<String, DynamicAttrWrapper<SocRolloverResultInfo>> dynAttrMap = new HashMap<String, DynamicAttrWrapper<SocRolloverResultInfo>>();
115
116 dynAttrMap.put(CourseOfferingSetServiceConstants.DATE_INITIATED_RESULT_DYNATTR_KEY,
117 new DynamicAttrWrapper<SocRolloverResultInfo>(result, Date.class,
118 CourseOfferingSetServiceConstants.DATE_INITIATED_RESULT_DYNATTR_KEY) {
119
120 @Override
121 public void readInStringValue(String attrValue) {
122 DynAttrConverter<Date> dateConverter = (DynAttrConverter<Date>) TransformUtility.getConverterByClass(Date.class);
123 Date convertedDate = dateConverter.convertStringValueToNative(attrValue);
124 getDto().setDateInitiated(convertedDate);
125 }
126
127 @Override
128 public String writeOutStringValue() {
129 DynAttrConverter<Date> dateConverter = (DynAttrConverter<Date>) TransformUtility.getConverterByClass(Date.class);
130 String dateStr = dateConverter.convertNativeValueToString(getDto().getDateInitiated());
131 return dateStr;
132 }
133 });
134
135 dynAttrMap.put(CourseOfferingSetServiceConstants.DATE_COMPLETED_RESULT_DYNATTR_KEY,
136 new DynamicAttrWrapper<SocRolloverResultInfo>(result, Date.class,
137 CourseOfferingSetServiceConstants.DATE_COMPLETED_RESULT_DYNATTR_KEY) {
138
139 @Override
140 public void readInStringValue(String attrValue) {
141 DynAttrConverter<Date> dateConverter = (DynAttrConverter<Date>) TransformUtility.getConverterByClass(Date.class);
142 Date convertedDate = dateConverter.convertStringValueToNative(attrValue);
143 getDto().setDateCompleted(convertedDate);
144 }
145
146 @Override
147 public String writeOutStringValue() {
148 DynAttrConverter<Date> dateConverter = (DynAttrConverter<Date>) TransformUtility.getConverterByClass(Date.class);
149 String dateStr = dateConverter.convertNativeValueToString(getDto().getDateCompleted());
150 return dateStr;
151 }
152 });
153
154 dynAttrMap.put(CourseOfferingSetServiceConstants.CO_CREATED_RESULT_DYNATTR_KEY,
155 new DynamicAttrWrapper<SocRolloverResultInfo>(result, Date.class,
156 CourseOfferingSetServiceConstants.CO_CREATED_RESULT_DYNATTR_KEY) {
157
158 @Override
159 public void readInStringValue(String attrValue) {
160 DynAttrConverter<Integer> intConverter = (DynAttrConverter<Integer>) TransformUtility.getConverterByClass(Integer.class);
161 Integer intVal = intConverter.convertStringValueToNative(attrValue);
162 getDto().setCourseOfferingsCreated(intVal);
163 }
164
165 @Override
166 public String writeOutStringValue() {
167 DynAttrConverter<Integer> intConverter = (DynAttrConverter<Integer>) TransformUtility.getConverterByClass(Integer.class);
168 String intStr = intConverter.convertNativeValueToString(getDto().getCourseOfferingsCreated());
169 return intStr;
170 }
171 });
172
173 dynAttrMap.put(CourseOfferingSetServiceConstants.CO_SKIPPED_RESULT_DYNATTR_KEY,
174 new DynamicAttrWrapper<SocRolloverResultInfo>(result, Date.class,
175 CourseOfferingSetServiceConstants.CO_SKIPPED_RESULT_DYNATTR_KEY) {
176
177 @Override
178 public void readInStringValue(String attrValue) {
179 DynAttrConverter<Integer> intConverter = (DynAttrConverter<Integer>) TransformUtility.getConverterByClass(Integer.class);
180 Integer intVal = intConverter.convertStringValueToNative(attrValue);
181 getDto().setCourseOfferingsSkipped(intVal);
182 }
183
184 @Override
185 public String writeOutStringValue() {
186 DynAttrConverter<Integer> intConverter = (DynAttrConverter<Integer>) TransformUtility.getConverterByClass(Integer.class);
187 String intStr = intConverter.convertNativeValueToString(getDto().getCourseOfferingsSkipped());
188 return intStr;
189 }
190 });
191
192 dynAttrMap.put(CourseOfferingSetServiceConstants.AO_CREATED_RESULT_DYNATTR_KEY,
193 new DynamicAttrWrapper<SocRolloverResultInfo>(result, Date.class,
194 CourseOfferingSetServiceConstants.AO_CREATED_RESULT_DYNATTR_KEY) {
195
196 @Override
197 public void readInStringValue(String attrValue) {
198 DynAttrConverter<Integer> intConverter = (DynAttrConverter<Integer>) TransformUtility.getConverterByClass(Integer.class);
199 Integer intVal = intConverter.convertStringValueToNative(attrValue);
200 getDto().setActivityOfferingsCreated(intVal);
201 }
202
203 @Override
204 public String writeOutStringValue() {
205 DynAttrConverter<Integer> intConverter = (DynAttrConverter<Integer>) TransformUtility.getConverterByClass(Integer.class);
206 String intStr = intConverter.convertNativeValueToString(getDto().getActivityOfferingsCreated());
207 return intStr;
208 }
209 });
210
211 dynAttrMap.put(CourseOfferingSetServiceConstants.AO_SKIPPED_RESULT_DYNATTR_KEY,
212 new DynamicAttrWrapper<SocRolloverResultInfo>(result, Date.class,
213 CourseOfferingSetServiceConstants.AO_SKIPPED_RESULT_DYNATTR_KEY) {
214
215 @Override
216 public void readInStringValue(String attrValue) {
217 DynAttrConverter<Integer> intConverter = (DynAttrConverter<Integer>) TransformUtility.getConverterByClass(Integer.class);
218 Integer intVal = intConverter.convertStringValueToNative(attrValue);
219 getDto().setActivityOfferingsSkipped(intVal);
220 }
221
222 @Override
223 public String writeOutStringValue() {
224 DynAttrConverter<Integer> intConverter = (DynAttrConverter<Integer>) TransformUtility.getConverterByClass(Integer.class);
225 String intStr = intConverter.convertNativeValueToString(getDto().getActivityOfferingsSkipped());
226 return intStr;
227 }
228 });
229 return dynAttrMap;
230 }
231
232 private static Map<String, SocRolloverResultAttributeEntity> _createEntityAttrMap(SocRolloverResultEntity entity) {
233 Map<String, SocRolloverResultAttributeEntity> entityAttrMap = new HashMap<String, SocRolloverResultAttributeEntity>();
234 if (entity.getAttributes() != null) {
235 for (SocRolloverResultAttributeEntity attrEnt: entity.getAttributes()) {
236 entityAttrMap.put(attrEnt.getKey(), attrEnt);
237 }
238 }
239 return entityAttrMap;
240 }
241
242 public static void copyDtoDynAttrsToEntity(SocRolloverResult result, SocRolloverResultEntity entity) {
243 Map<String, DynamicAttrReadOnlyWrapper<SocRolloverResult>> dynAttrMap = _createDynAttrReadOnlyMap(result);
244 Map<String, SocRolloverResultAttributeEntity> entityAttrMap = _createEntityAttrMap(entity);
245
246 for(Map.Entry<String, DynamicAttrReadOnlyWrapper<SocRolloverResult>> entry: dynAttrMap.entrySet()){
247 String attrName = entry.getKey();
248 SocRolloverResultAttributeEntity attrEntity = entityAttrMap.get(attrName);
249 DynamicAttrReadOnlyWrapper<SocRolloverResult> wrapper = entry.getValue();
250 if (attrEntity == null) {
251
252 AttributeInfo attr = new AttributeInfo(attrName, wrapper.writeOutStringValue());
253 SocRolloverResultAttributeEntity newAttrEntity = new SocRolloverResultAttributeEntity(attr, entity);
254 entity.getAttributes().add(newAttrEntity);
255 } else {
256
257 attrEntity.setValue(wrapper.writeOutStringValue());
258 }
259 }
260 }
261
262 public static void copyEntityAttrsToDtoDynAttrs(SocRolloverResultEntity entity, SocRolloverResultInfo info) {
263 Map<String, DynamicAttrWrapper<SocRolloverResultInfo>> dynAttrMap = _createDynAttrMap(info);
264 Map<String, SocRolloverResultAttributeEntity> entityAttrMap = _createEntityAttrMap(entity);
265
266 for(Map.Entry<String, DynamicAttrWrapper<SocRolloverResultInfo>> entry: dynAttrMap.entrySet()){
267 String attrName = entry.getKey();
268 SocRolloverResultAttributeEntity attrEntity = entityAttrMap.get(attrName);
269 DynamicAttrWrapper<SocRolloverResultInfo> wrapper = entry.getValue();
270 if (attrEntity != null) {
271
272 wrapper.readInStringValue(attrEntity.getValue());
273 }
274 }
275 }
276 }