1 package org.kuali.student.common.conversion.util.converter;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7
8 import org.dozer.DozerConverter;
9 import org.kuali.student.r2.common.dto.AttributeInfo;
10
11 @SuppressWarnings("rawtypes")
12 public class AttributeInfoConverter extends DozerConverter<Map, List> {
13
14 public AttributeInfoConverter() {
15 super(Map.class, List.class);
16 }
17
18 @Override
19 public List convertTo(Map source, List destination) {
20 List<AttributeInfo> convertedList = null;
21 if (source != null) {
22 convertedList = new ArrayList<AttributeInfo>();
23 for (Object key : source.keySet()) {
24 String srcKey = (String) key;
25 AttributeInfo attrInfo = new AttributeInfo();
26 attrInfo.setId(srcKey);
27 attrInfo.setKey(srcKey);
28 attrInfo.setValue((String) source.get(srcKey));
29 convertedList.add(attrInfo);
30 }
31 }
32 return convertedList;
33 }
34
35 @Override
36 public Map convertFrom(List source, Map destination) {
37 Map<String, String> convertedMap = null;
38 if (source != null) {
39 convertedMap = new HashMap<String, String>();
40 for (Object object : source) {
41 AttributeInfo attrInfo = (AttributeInfo) object;
42 convertedMap.put(attrInfo.getKey(), attrInfo.getValue());
43 }
44 }
45 return convertedMap;
46 }
47
48 }