Coverage Report - org.kuali.student.core.enumerationmanagement.service.impl.util.EnumerationAssembler
 
Classes in this File Line Coverage Branch Coverage Complexity
EnumerationAssembler
0%
0/65
0%
0/8
3
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 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  0
     final static Logger logger = Logger.getLogger(EnumerationAssembler.class);
 34  
     
 35  
     public static void toEnumeratedValueEntity(EnumeratedValueInfo enumeratedValue, EnumeratedValue enumeratedValueEntity) {
 36  
         try {
 37  0
             BeanUtils.copyProperties(enumeratedValueEntity, enumeratedValue);
 38  0
             List<EnumContextValueInfo> contextList = enumeratedValue.getContexts();
 39  0
             List<ContextEntity> contextEntityList = new ArrayList<ContextEntity>();
 40  
             
 41  0
             for (EnumContextValueInfo c : contextList) {
 42  0
                     ContextEntity contextEntity = new ContextEntity();
 43  0
                     contextEntity.setContextValue(c.getValue());
 44  0
                 contextEntity.setContextKey(c.getKey());
 45  0
                 contextEntityList.add(contextEntity);
 46  0
             }
 47  0
             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  0
         }
 53  0
     }
 54  
 
 55  
     public static void toEnumeratedValueInfo(EnumeratedValue enumeratedValueEntity, EnumeratedValueInfo enumeratedValue) {
 56  
         try {
 57  0
             BeanUtils.copyProperties(enumeratedValue, enumeratedValueEntity);
 58  0
             List<ContextEntity> contextEntityList = enumeratedValueEntity.getContextEntityList();
 59  0
             List<EnumContextValueInfo> contextList = new ArrayList<EnumContextValueInfo>();
 60  
             
 61  0
             enumeratedValue.setEnumerationKey(enumeratedValueEntity.getEnumeration().getId());
 62  
             
 63  0
             for (ContextEntity c : contextEntityList) {
 64  0
                     EnumContextValueInfo context = new EnumContextValueInfo();
 65  0
                 context.setValue(c.getContextValue());
 66  0
                 context.setKey(c.getContextKey());
 67  0
                 contextList.add(context);
 68  0
             }
 69  0
             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  0
         }
 75  
 
 76  0
     }
 77  
 
 78  
     public static List<EnumeratedValueInfo> toEnumeratedValueList(List<EnumeratedValue> enumeratedValueEntityList) {
 79  
 
 80  0
         List<EnumeratedValueInfo> enumeratedValueList = new ArrayList<EnumeratedValueInfo>();
 81  
 
 82  0
         for (EnumeratedValue enumeratedValueEntity : enumeratedValueEntityList) {
 83  0
                 EnumeratedValueInfo eValue = new EnumeratedValueInfo();
 84  0
             toEnumeratedValueInfo(enumeratedValueEntity, eValue);
 85  0
             enumeratedValueList.add(eValue);
 86  0
         }
 87  0
         return enumeratedValueList;
 88  
 
 89  
     }
 90  
     
 91  
     public static List<EnumerationInfo> toEnumerationMetaList(List<Enumeration>enumerationMetaEntityList){
 92  
         
 93  0
         List<EnumerationInfo> enumerationMetaList = new ArrayList<EnumerationInfo>();
 94  
          
 95  0
         for(Enumeration enumerationMetaEntity :enumerationMetaEntityList ){
 96  0
                 EnumerationInfo eMeta = new EnumerationInfo();
 97  0
             toEnumerationInfo(enumerationMetaEntity,eMeta);
 98  0
             enumerationMetaList.add(eMeta);
 99  0
         }
 100  
         
 101  0
         return enumerationMetaList;
 102  
     }
 103  
         
 104  
 
 105  
     public static void toEnumerationInfo(Enumeration enumerationEntity, EnumerationInfo enumerationMeta) {
 106  
         try {
 107  0
             BeanUtils.copyProperties(enumerationMeta, enumerationEntity);
 108  0
             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  0
         }
 114  
 
 115  0
     }
 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  
 }