1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.core.enumerationmanagement.service.impl.util; |
17 | |
|
18 | |
import org.apache.log4j.Logger; |
19 | |
import org.kuali.student.core.enumerationmanagement.dto.EnumContextValueInfo; |
20 | |
import org.kuali.student.core.enumerationmanagement.dto.EnumeratedValueInfo; |
21 | |
import org.kuali.student.core.enumerationmanagement.dto.EnumerationInfo; |
22 | |
import org.kuali.student.core.enumerationmanagement.entity.ContextEntity; |
23 | |
import org.kuali.student.core.enumerationmanagement.entity.EnumeratedValue; |
24 | |
import org.kuali.student.core.enumerationmanagement.entity.Enumeration; |
25 | |
|
26 | |
import java.util.ArrayList; |
27 | |
import java.util.List; |
28 | |
|
29 | 0 | public class EnumerationAssembler { |
30 | |
|
31 | 0 | final static Logger logger = Logger.getLogger(EnumerationAssembler.class); |
32 | |
|
33 | |
public static void toEnumeratedValueEntity(EnumeratedValueInfo info, EnumeratedValue entity) { |
34 | 0 | entity.setAbbrevValue(info.getAbbrevValue()); |
35 | 0 | entity.setCode(info.getCode()); |
36 | 0 | entity.setSortKey(Integer.parseInt(info.getSortKey())); |
37 | 0 | entity.setValue(info.getValue()); |
38 | 0 | entity.setEffectiveDate(info.getEffectiveDate()); |
39 | 0 | entity.setExpirationDate(info.getExpirationDate()); |
40 | |
|
41 | 0 | List<EnumContextValueInfo> contextList = info.getContexts(); |
42 | 0 | List<ContextEntity> contextEntityList = new ArrayList<ContextEntity>(); |
43 | |
|
44 | 0 | for (EnumContextValueInfo c : contextList) { |
45 | 0 | ContextEntity contextEntity = new ContextEntity(); |
46 | 0 | contextEntity.setContextValue(c.getValue()); |
47 | 0 | contextEntity.setContextKey(c.getKey()); |
48 | 0 | contextEntityList.add(contextEntity); |
49 | 0 | } |
50 | 0 | entity.setContextEntityList(contextEntityList); |
51 | 0 | } |
52 | |
|
53 | |
public static void toEnumeratedValueInfo(EnumeratedValue entity, EnumeratedValueInfo info) { |
54 | |
|
55 | 0 | info.setAbbrevValue(entity.getAbbrevValue()); |
56 | 0 | info.setCode(entity.getCode()); |
57 | 0 | info.setSortKey(String.valueOf(entity.getSortKey())); |
58 | 0 | info.setValue(entity.getValue()); |
59 | 0 | info.setEffectiveDate(entity.getEffectiveDate()); |
60 | 0 | info.setExpirationDate(entity.getExpirationDate()); |
61 | 0 | info.setEnumerationKey(entity.getEnumeration().getId()); |
62 | |
|
63 | 0 | List<ContextEntity> contextEntityList = entity.getContextEntityList(); |
64 | 0 | List<EnumContextValueInfo> contextList = new ArrayList<EnumContextValueInfo>(); |
65 | |
|
66 | 0 | for (ContextEntity c : contextEntityList) { |
67 | 0 | EnumContextValueInfo context = new EnumContextValueInfo(); |
68 | 0 | context.setValue(c.getContextValue()); |
69 | 0 | context.setKey(c.getContextKey()); |
70 | 0 | contextList.add(context); |
71 | 0 | } |
72 | 0 | info.setContexts(contextList); |
73 | |
|
74 | 0 | } |
75 | |
|
76 | |
public static List<EnumeratedValueInfo> toEnumeratedValueList(List<EnumeratedValue> enumeratedValueEntityList) { |
77 | |
|
78 | 0 | List<EnumeratedValueInfo> enumeratedValueList = new ArrayList<EnumeratedValueInfo>(); |
79 | |
|
80 | 0 | for (EnumeratedValue enumeratedValueEntity : enumeratedValueEntityList) { |
81 | 0 | EnumeratedValueInfo eValue = new EnumeratedValueInfo(); |
82 | 0 | toEnumeratedValueInfo(enumeratedValueEntity, eValue); |
83 | 0 | enumeratedValueList.add(eValue); |
84 | 0 | } |
85 | 0 | return enumeratedValueList; |
86 | |
|
87 | |
} |
88 | |
|
89 | |
public static List<EnumerationInfo> toEnumerationMetaList(List<Enumeration> enumerationMetaEntityList) { |
90 | |
|
91 | 0 | List<EnumerationInfo> enumerationMetaList = new ArrayList<EnumerationInfo>(); |
92 | |
|
93 | 0 | for (Enumeration enumerationMetaEntity : enumerationMetaEntityList) { |
94 | 0 | EnumerationInfo eMeta = new EnumerationInfo(); |
95 | 0 | toEnumerationInfo(enumerationMetaEntity, eMeta); |
96 | 0 | enumerationMetaList.add(eMeta); |
97 | 0 | } |
98 | |
|
99 | 0 | return enumerationMetaList; |
100 | |
} |
101 | |
|
102 | |
|
103 | |
public static void toEnumerationInfo(Enumeration entity, EnumerationInfo info) { |
104 | 0 | info.setDescr(entity.getDescr()); |
105 | 0 | info.setName(entity.getName()); |
106 | 0 | info.setEffectiveDate(entity.getEffectiveDate()); |
107 | 0 | info.setExpirationDate(entity.getExpirationDate()); |
108 | 0 | info.setId(entity.getId()); |
109 | 0 | } |
110 | |
|
111 | |
public static void toEnumeration(EnumerationInfo info, Enumeration entity) { |
112 | 0 | entity.setDescr(info.getDescr()); |
113 | 0 | entity.setName(info.getName()); |
114 | 0 | entity.setEffectiveDate(info.getEffectiveDate()); |
115 | 0 | entity.setExpirationDate(info.getExpirationDate()); |
116 | 0 | entity.setId(info.getId()); |
117 | 0 | } |
118 | |
} |