| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.lum.statement.config.context; | 
  | 17 |  |   | 
  | 18 |  |  import java.util.HashMap; | 
  | 19 |  |  import java.util.List; | 
  | 20 |  |  import java.util.Map; | 
  | 21 |  |   | 
  | 22 |  |  import org.kuali.student.core.statement.dto.ReqComponentInfo; | 
  | 23 |  |  import org.kuali.student.core.exceptions.OperationFailedException; | 
  | 24 |  |  import org.kuali.student.lum.lrc.dto.ResultComponentInfo; | 
  | 25 |  |  import org.kuali.student.lum.lrc.dto.ResultComponentTypeInfo; | 
  | 26 |  |  import org.kuali.student.lum.lrc.service.LrcService; | 
  | 27 |  |  import org.kuali.student.lum.statement.typekey.ReqComponentFieldTypes; | 
  | 28 |  |   | 
  | 29 |  |   | 
  | 30 |  |   | 
  | 31 |  |   | 
  | 32 | 19 |  public class LrcContextImpl extends BasicContextImpl { | 
  | 33 |  |           | 
  | 34 |  |          private LrcService lrcService; | 
  | 35 |  |           | 
  | 36 |  |            | 
  | 37 |  |          public final static String GRADE_TOKEN = "grade"; | 
  | 38 |  |      public final static String GRADE_TYPE_TOKEN = "gradeType";         | 
  | 39 |  |   | 
  | 40 |  |          public void setLrcService(LrcService lrcService) { | 
  | 41 | 10 |                  this.lrcService = lrcService; | 
  | 42 | 10 |          } | 
  | 43 |  |   | 
  | 44 |  |          private ResultComponentInfo getResultComponentByResultComponentId(String resultComponentId) throws OperationFailedException { | 
  | 45 | 3 |                  if (resultComponentId == null) { | 
  | 46 | 1 |                          return null; | 
  | 47 |  |                  } | 
  | 48 |  |                  try { | 
  | 49 | 2 |                          return lrcService.getResultComponent(resultComponentId); | 
  | 50 | 0 |                  } catch (Exception e) { | 
  | 51 | 0 |                          throw new OperationFailedException(e.getMessage(), e); | 
  | 52 |  |                  } | 
  | 53 |  |          } | 
  | 54 |  |           | 
  | 55 |  |          private String getResultValue(ResultComponentInfo resultComponent, String resultValue) throws OperationFailedException { | 
  | 56 | 16 |                  if(resultComponent == null || resultValue == null) { | 
  | 57 | 3 |                          return null; | 
  | 58 |  |                  } | 
  | 59 | 13 |                  for(String rv : resultComponent.getResultValues()) { | 
  | 60 | 21 |                          if(rv.equals(resultValue)) { | 
  | 61 | 13 |                                  return rv; | 
  | 62 |  |                          } | 
  | 63 |  |                  } | 
  | 64 | 0 |                  throw new OperationFailedException("Result value not found: "+resultValue); | 
  | 65 |  |          } | 
  | 66 |  |           | 
  | 67 |  |          private ResultComponentInfo getResultComponentByResultValueId(String resultValueId) throws OperationFailedException { | 
  | 68 | 13 |                  if(resultValueId == null) { | 
  | 69 | 0 |                          return null; | 
  | 70 |  |                  } | 
  | 71 |  |                   | 
  | 72 |  |                  try { | 
  | 73 | 13 |                          List<ResultComponentTypeInfo> typeList = lrcService.getResultComponentTypes(); | 
  | 74 | 13 |                          for(ResultComponentTypeInfo type : typeList) { | 
  | 75 | 49 |                                  List<String> resultComponentIdList = lrcService.getResultComponentIdsByResultComponentType(type.getId()); | 
  | 76 | 49 |                                  for(String resultComponentId : resultComponentIdList) { | 
  | 77 | 75 |                                          ResultComponentInfo resultComponent = lrcService.getResultComponent(resultComponentId); | 
  | 78 | 75 |                                          if(resultComponent.getResultValues().contains(resultValueId)) { | 
  | 79 | 13 |                                                  return resultComponent; | 
  | 80 |  |                                          } | 
  | 81 | 62 |                                  } | 
  | 82 | 36 |                          } | 
  | 83 | 0 |                  } catch (Exception e) { | 
  | 84 | 0 |                          throw new OperationFailedException(e.getMessage(), e); | 
  | 85 | 0 |                  } | 
  | 86 | 0 |                  throw new OperationFailedException("Result value id not found: "+resultValueId); | 
  | 87 |  |          } | 
  | 88 |  |           | 
  | 89 |  |       | 
  | 90 |  |   | 
  | 91 |  |   | 
  | 92 |  |   | 
  | 93 |  |   | 
  | 94 |  |   | 
  | 95 |  |      public Map<String, Object> createContextMap(ReqComponentInfo reqComponent) throws OperationFailedException { | 
  | 96 | 16 |          Map<String, Object> contextMap = new HashMap<String, Object>(); | 
  | 97 |  |   | 
  | 98 |  |   | 
  | 99 |  |   | 
  | 100 |  |   | 
  | 101 |  |   | 
  | 102 |  |   | 
  | 103 |  |   | 
  | 104 |  |   | 
  | 105 |  |   | 
  | 106 |  |   | 
  | 107 |  |   | 
  | 108 |  |   | 
  | 109 |  |   | 
  | 110 |  |               | 
  | 111 | 16 |          ResultComponentInfo gradeTypeResultComponent = null; | 
  | 112 | 16 |          String gradeId = getReqComponentFieldValue(reqComponent, ReqComponentFieldTypes.GRADE_KEY.getId()); | 
  | 113 | 16 |          if (gradeId == null) { | 
  | 114 | 3 |                          String gradeTypeId = getReqComponentFieldValue(reqComponent, ReqComponentFieldTypes.GRADE_TYPE_KEY.getId()); | 
  | 115 | 3 |                          gradeTypeResultComponent = getResultComponentByResultComponentId(gradeTypeId); | 
  | 116 | 3 |                          if (gradeTypeResultComponent != null) { | 
  | 117 | 2 |                                  contextMap.put(GRADE_TYPE_TOKEN, gradeTypeResultComponent); | 
  | 118 |  |                          } | 
  | 119 | 3 |          } else { | 
  | 120 | 13 |                  gradeTypeResultComponent = getResultComponentByResultValueId(gradeId); | 
  | 121 |  |          } | 
  | 122 | 16 |                  if (gradeTypeResultComponent != null) { | 
  | 123 | 15 |                          contextMap.put(GRADE_TYPE_TOKEN, gradeTypeResultComponent); | 
  | 124 |  |                  } | 
  | 125 |  |   | 
  | 126 | 16 |          String grade = getResultValue(gradeTypeResultComponent, gradeId); | 
  | 127 | 16 |          if(grade != null) { | 
  | 128 | 13 |                  contextMap.put(GRADE_TOKEN, grade); | 
  | 129 |  |          } | 
  | 130 |  |   | 
  | 131 | 16 |          return contextMap; | 
  | 132 |  |      } | 
  | 133 |  |  } |