| 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 java.lang.reflect.InvocationTargetException; |
| 19 | |
import java.util.ArrayList; |
| 20 | |
import java.util.List; |
| 21 | |
|
| 22 | |
import org.apache.commons.beanutils.BeanUtils; |
| 23 | |
import org.apache.log4j.Logger; |
| 24 | |
import org.kuali.student.core.enumerationmanagement.dto.EnumContextValueInfo; |
| 25 | |
import org.kuali.student.core.enumerationmanagement.dto.EnumeratedValueInfo; |
| 26 | |
import org.kuali.student.core.enumerationmanagement.dto.EnumerationInfo; |
| 27 | |
import org.kuali.student.core.enumerationmanagement.entity.ContextEntity; |
| 28 | |
import org.kuali.student.core.enumerationmanagement.entity.EnumeratedValue; |
| 29 | |
import org.kuali.student.core.enumerationmanagement.entity.Enumeration; |
| 30 | |
|
| 31 | 0 | public class EnumerationAssembler { |
| 32 | |
|
| 33 | 1 | final static Logger logger = Logger.getLogger(EnumerationAssembler.class); |
| 34 | |
|
| 35 | |
public static void toEnumeratedValueEntity(EnumeratedValueInfo enumeratedValue, EnumeratedValue enumeratedValueEntity) { |
| 36 | |
try { |
| 37 | 24 | BeanUtils.copyProperties(enumeratedValueEntity, enumeratedValue); |
| 38 | 24 | List<EnumContextValueInfo> contextList = enumeratedValue.getContexts(); |
| 39 | 24 | List<ContextEntity> contextEntityList = new ArrayList<ContextEntity>(); |
| 40 | |
|
| 41 | 24 | for (EnumContextValueInfo c : contextList) { |
| 42 | 204 | ContextEntity contextEntity = new ContextEntity(); |
| 43 | 204 | contextEntity.setContextValue(c.getValue()); |
| 44 | 204 | contextEntity.setContextKey(c.getKey()); |
| 45 | 204 | contextEntityList.add(contextEntity); |
| 46 | 204 | } |
| 47 | 24 | enumeratedValueEntity.setContextEntityList(contextEntityList); |
| 48 | 0 | } catch (IllegalAccessException e) { |
| 49 | 0 | logger.error("Exception occured: ", e); |
| 50 | 0 | } catch (InvocationTargetException e) { |
| 51 | 0 | logger.error("Exception occured: ", e); |
| 52 | 24 | } |
| 53 | 24 | } |
| 54 | |
|
| 55 | |
public static void toEnumeratedValueInfo(EnumeratedValue enumeratedValueEntity, EnumeratedValueInfo enumeratedValue) { |
| 56 | |
try { |
| 57 | 44 | BeanUtils.copyProperties(enumeratedValue, enumeratedValueEntity); |
| 58 | 44 | List<ContextEntity> contextEntityList = enumeratedValueEntity.getContextEntityList(); |
| 59 | 44 | List<EnumContextValueInfo> contextList = new ArrayList<EnumContextValueInfo>(); |
| 60 | |
|
| 61 | 44 | enumeratedValue.setEnumerationKey(enumeratedValueEntity.getEnumeration().getId()); |
| 62 | |
|
| 63 | 44 | for (ContextEntity c : contextEntityList) { |
| 64 | 224 | EnumContextValueInfo context = new EnumContextValueInfo(); |
| 65 | 224 | context.setValue(c.getContextValue()); |
| 66 | 224 | context.setKey(c.getContextKey()); |
| 67 | 224 | contextList.add(context); |
| 68 | 224 | } |
| 69 | 44 | enumeratedValue.setContexts(contextList); |
| 70 | 0 | } catch (IllegalAccessException e) { |
| 71 | 0 | logger.error("Exception occured: ", e); |
| 72 | 0 | } catch (InvocationTargetException e) { |
| 73 | 0 | logger.error("Exception occured: ", e); |
| 74 | 44 | } |
| 75 | |
|
| 76 | 44 | } |
| 77 | |
|
| 78 | |
public static List<EnumeratedValueInfo> toEnumeratedValueList(List<EnumeratedValue> enumeratedValueEntityList) { |
| 79 | |
|
| 80 | 16 | List<EnumeratedValueInfo> enumeratedValueList = new ArrayList<EnumeratedValueInfo>(); |
| 81 | |
|
| 82 | 16 | for (EnumeratedValue enumeratedValueEntity : enumeratedValueEntityList) { |
| 83 | 43 | EnumeratedValueInfo eValue = new EnumeratedValueInfo(); |
| 84 | 43 | toEnumeratedValueInfo(enumeratedValueEntity, eValue); |
| 85 | 43 | enumeratedValueList.add(eValue); |
| 86 | 43 | } |
| 87 | 16 | return enumeratedValueList; |
| 88 | |
|
| 89 | |
} |
| 90 | |
|
| 91 | |
public static List<EnumerationInfo> toEnumerationMetaList(List<Enumeration>enumerationMetaEntityList){ |
| 92 | |
|
| 93 | 1 | List<EnumerationInfo> enumerationMetaList = new ArrayList<EnumerationInfo>(); |
| 94 | |
|
| 95 | 1 | for(Enumeration enumerationMetaEntity :enumerationMetaEntityList ){ |
| 96 | 13 | EnumerationInfo eMeta = new EnumerationInfo(); |
| 97 | 13 | toEnumerationInfo(enumerationMetaEntity,eMeta); |
| 98 | 13 | enumerationMetaList.add(eMeta); |
| 99 | 13 | } |
| 100 | |
|
| 101 | 1 | return enumerationMetaList; |
| 102 | |
} |
| 103 | |
|
| 104 | |
|
| 105 | |
public static void toEnumerationInfo(Enumeration enumerationEntity, EnumerationInfo enumerationMeta) { |
| 106 | |
try { |
| 107 | 14 | BeanUtils.copyProperties(enumerationMeta, enumerationEntity); |
| 108 | 14 | enumerationMeta.setId(enumerationEntity.getId()); |
| 109 | 0 | } catch (IllegalAccessException e) { |
| 110 | 0 | logger.error("Exception occured: ", e); |
| 111 | 0 | } catch (InvocationTargetException e) { |
| 112 | 0 | logger.error("Exception occured: ", e); |
| 113 | 14 | } |
| 114 | |
|
| 115 | 14 | } |
| 116 | |
|
| 117 | |
public static void toEnumeration(EnumerationInfo enumerationMeta, Enumeration enumerationEntity) { |
| 118 | |
try { |
| 119 | 0 | BeanUtils.copyProperties(enumerationEntity, enumerationMeta); |
| 120 | 0 | enumerationEntity.setId(enumerationMeta.getId()); |
| 121 | 0 | } catch (IllegalAccessException e) { |
| 122 | 0 | logger.error("Exception occured: ", e); |
| 123 | 0 | } catch (InvocationTargetException e) { |
| 124 | 0 | logger.error("Exception occured: ", e); |
| 125 | 0 | } |
| 126 | |
|
| 127 | 0 | } |
| 128 | |
} |