| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.lum.lrc.service.impl; | 
  | 17 |  |   | 
  | 18 |  |  import java.util.ArrayList; | 
  | 19 |  |  import java.util.HashMap; | 
  | 20 |  |  import java.util.List; | 
  | 21 |  |  import java.util.Map; | 
  | 22 |  |  import java.util.Map.Entry; | 
  | 23 |  |   | 
  | 24 |  |  import org.kuali.student.core.exceptions.DataValidationErrorException; | 
  | 25 |  |  import org.kuali.student.core.exceptions.DoesNotExistException; | 
  | 26 |  |  import org.kuali.student.core.exceptions.InvalidParameterException; | 
  | 27 |  |  import org.kuali.student.core.service.impl.BaseAssembler; | 
  | 28 |  |  import org.kuali.student.lum.lrc.dao.LrcDao; | 
  | 29 |  |  import org.kuali.student.lum.lrc.dto.ResultComponentInfo; | 
  | 30 |  |  import org.kuali.student.lum.lrc.dto.ResultComponentTypeInfo; | 
  | 31 |  |  import org.kuali.student.lum.lrc.dto.ScaleInfo; | 
  | 32 |  |  import org.kuali.student.lum.lrc.entity.LrcRichText; | 
  | 33 |  |  import org.kuali.student.lum.lrc.entity.ResultComponent; | 
  | 34 |  |  import org.kuali.student.lum.lrc.entity.ResultComponentAttribute; | 
  | 35 |  |  import org.kuali.student.lum.lrc.entity.ResultComponentType; | 
  | 36 |  |  import org.kuali.student.lum.lrc.entity.ResultValue; | 
  | 37 |  |  import org.kuali.student.lum.lrc.entity.Scale; | 
  | 38 |  |  import org.springframework.beans.BeanUtils; | 
  | 39 |  |   | 
  | 40 | 0 |  public class LrcServiceAssembler extends BaseAssembler { | 
  | 41 |  |      | 
  | 42 |  |   | 
  | 43 |  |      public static ResultComponentInfo toResultComponentInfo(ResultComponent entity) { | 
  | 44 | 111 |          ResultComponentInfo dto = new ResultComponentInfo(); | 
  | 45 |  |   | 
  | 46 | 111 |          BeanUtils.copyProperties(entity, dto, | 
  | 47 |  |                  new String[] { "resultValues", "desc", "attributes", "type" }); | 
  | 48 | 111 |          List<String> resultValues = new ArrayList<String>(entity.getResultValues().size()); | 
  | 49 | 111 |          for (ResultValue rv : entity.getResultValues()) { | 
  | 50 | 272 |                  resultValues.add(rv.getValue()); | 
  | 51 |  |          } | 
  | 52 | 111 |          dto.setDesc(toRichTextInfo(entity.getDescr())); | 
  | 53 | 111 |          dto.setResultValues(resultValues); | 
  | 54 | 111 |          dto.setAttributes(toAttributeMap(entity.getAttributes())); | 
  | 55 | 111 |                  dto.setMetaInfo(toMetaInfo(entity.getMeta(), entity.getVersionNumber())); | 
  | 56 | 111 |          dto.setType(entity.getType().getId()); | 
  | 57 | 111 |          return dto; | 
  | 58 |  |      } | 
  | 59 |  |   | 
  | 60 |  |      public static List<ResultComponentInfo> toReListComonentInfos(List<ResultComponent> entities) { | 
  | 61 | 0 |          List<ResultComponentInfo> dtos = new ArrayList<ResultComponentInfo>(entities.size()); | 
  | 62 | 0 |          for (ResultComponent entity : entities) { | 
  | 63 | 0 |              dtos.add(toResultComponentInfo(entity)); | 
  | 64 |  |          } | 
  | 65 | 0 |          return dtos; | 
  | 66 |  |      } | 
  | 67 |  |   | 
  | 68 |  |      public static ResultComponentTypeInfo toResultComponentTypeInfo(ResultComponentType entity) { | 
  | 69 | 71 |          ResultComponentTypeInfo dto = new ResultComponentTypeInfo(); | 
  | 70 |  |   | 
  | 71 | 71 |          BeanUtils.copyProperties(entity, dto, | 
  | 72 |  |                  new String[] {"attributes" }); | 
  | 73 | 71 |          dto.setAttributes(toAttributeMap(entity.getAttributes())); | 
  | 74 |  |   | 
  | 75 | 71 |          return dto; | 
  | 76 |  |      } | 
  | 77 |  |      public static List<ResultComponentTypeInfo> toResultComponentTypeInfos(List<ResultComponentType> entites) { | 
  | 78 | 10 |          List<ResultComponentTypeInfo> dtos = new ArrayList<ResultComponentTypeInfo>(entites.size()); | 
  | 79 | 10 |          for (ResultComponentType entity : entites) { | 
  | 80 | 70 |              dtos.add(toResultComponentTypeInfo(entity)); | 
  | 81 |  |          } | 
  | 82 | 10 |          return dtos; | 
  | 83 |  |      } | 
  | 84 |  |   | 
  | 85 |  |   | 
  | 86 |  |      public static ScaleInfo toScaleInfo(Scale entity) { | 
  | 87 | 0 |         ScaleInfo dto = new ScaleInfo(); | 
  | 88 | 0 |         BeanUtils.copyProperties(entity, dto, | 
  | 89 |  |                 new String[] { "desc", "attributes" }); | 
  | 90 | 0 |         dto.setDesc(toRichTextInfo(entity.getDesc())); | 
  | 91 | 0 |         dto.setAttributes(toAttributeMap(entity.getAttributes())); | 
  | 92 | 0 |         return dto; | 
  | 93 |  |      } | 
  | 94 |  |   | 
  | 95 |  |      public static ResultComponent toResultComponent(String resultComponentTypeKey, ResultComponentInfo dto, LrcDao lrcDao) throws DoesNotExistException, InvalidParameterException, DataValidationErrorException { | 
  | 96 | 5 |          ResultComponent entity = new ResultComponent(); | 
  | 97 | 5 |          toResultComponent(entity, dto, lrcDao); | 
  | 98 | 5 |          return entity; | 
  | 99 |  |      } | 
  | 100 |  |   | 
  | 101 |  |      public static void toResultComponent(ResultComponent entity, ResultComponentInfo dto, LrcDao lrcDao) throws DoesNotExistException, InvalidParameterException, DataValidationErrorException { | 
  | 102 | 7 |          BeanUtils.copyProperties(dto, entity, | 
  | 103 |  |                  new String[] { "desc", "resultValues", "attributes", "metaInfo", "type" }); | 
  | 104 | 7 |          ResultComponentType type = lrcDao.fetch(ResultComponentType.class, dto.getType()); | 
  | 105 | 7 |          entity.setType(type); | 
  | 106 |  |           | 
  | 107 | 7 |          entity.setDescr(toRichText(LrcRichText.class, dto.getDesc())); | 
  | 108 |  |   | 
  | 109 |  |           | 
  | 110 | 7 |          List<ResultValue> resultValues = new ArrayList<ResultValue>(dto.getResultValues().size()); | 
  | 111 | 7 |          Map<String,ResultValue> currentResultValues = new HashMap<String,ResultValue>(); | 
  | 112 | 7 |          if(entity.getResultValues()!=null){ | 
  | 113 | 2 |                  for(ResultValue resultValue:entity.getResultValues()){ | 
  | 114 | 3 |                          currentResultValues.put(resultValue.getValue(),resultValue); | 
  | 115 |  |                  } | 
  | 116 |  |          } | 
  | 117 |  |           | 
  | 118 | 7 |          for(String value:dto.getResultValues()){ | 
  | 119 | 21 |                  if(!currentResultValues.containsKey(value)){ | 
  | 120 | 18 |                          ResultValue newResultValue = new ResultValue(); | 
  | 121 | 18 |                          newResultValue.setValue(value); | 
  | 122 | 18 |                          newResultValue.setResultComponent(entity); | 
  | 123 | 18 |                          resultValues.add(newResultValue); | 
  | 124 | 18 |                  }else{ | 
  | 125 | 3 |                          resultValues.add(currentResultValues.remove(value)); | 
  | 126 |  |                  } | 
  | 127 |  |          } | 
  | 128 |  |           | 
  | 129 | 7 |          for(Entry<String,ResultValue> entry:currentResultValues.entrySet()){ | 
  | 130 | 0 |                  lrcDao.delete(entry.getValue()); | 
  | 131 |  |          } | 
  | 132 |  |           | 
  | 133 | 7 |          entity.setResultValues(resultValues); | 
  | 134 | 7 |          entity.setAttributes(toGenericAttributes(ResultComponentAttribute.class, dto.getAttributes(), entity, lrcDao)); | 
  | 135 | 7 |      } | 
  | 136 |  |  } |