| 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.common.exceptions.OperationFailedException; |
| 23 | |
import org.kuali.student.core.statement.dto.ReqComponentInfo; |
| 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 | 0 | 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 | 0 | this.lrcService = lrcService; |
| 42 | 0 | } |
| 43 | |
|
| 44 | |
private ResultComponentInfo getResultComponentByResultComponentId(String resultComponentId) throws OperationFailedException { |
| 45 | 0 | if (resultComponentId == null) { |
| 46 | 0 | return null; |
| 47 | |
} |
| 48 | |
try { |
| 49 | 0 | 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 | 0 | if(resultComponent == null || resultValue == null) { |
| 57 | 0 | return null; |
| 58 | |
} |
| 59 | 0 | for(String rv : resultComponent.getResultValues()) { |
| 60 | 0 | if(rv.equals(resultValue)) { |
| 61 | 0 | 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 | 0 | if(resultValueId == null) { |
| 69 | 0 | return null; |
| 70 | |
} |
| 71 | |
|
| 72 | |
try { |
| 73 | 0 | List<ResultComponentTypeInfo> typeList = lrcService.getResultComponentTypes(); |
| 74 | 0 | for(ResultComponentTypeInfo type : typeList) { |
| 75 | 0 | List<String> resultComponentIdList = lrcService.getResultComponentIdsByResultComponentType(type.getId()); |
| 76 | 0 | for(String resultComponentId : resultComponentIdList) { |
| 77 | 0 | ResultComponentInfo resultComponent = lrcService.getResultComponent(resultComponentId); |
| 78 | 0 | if(resultComponent.getResultValues().contains(resultValueId)) { |
| 79 | 0 | return resultComponent; |
| 80 | |
} |
| 81 | 0 | } |
| 82 | 0 | } |
| 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 | 0 | Map<String, Object> contextMap = new HashMap<String, Object>(); |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | 0 | ResultComponentInfo gradeTypeResultComponent = null; |
| 112 | 0 | String gradeId = getReqComponentFieldValue(reqComponent, ReqComponentFieldTypes.GRADE_KEY.getId()); |
| 113 | 0 | if (gradeId == null) { |
| 114 | 0 | String gradeTypeId = getReqComponentFieldValue(reqComponent, ReqComponentFieldTypes.GRADE_TYPE_KEY.getId()); |
| 115 | 0 | gradeTypeResultComponent = getResultComponentByResultComponentId(gradeTypeId); |
| 116 | 0 | if (gradeTypeResultComponent != null) { |
| 117 | 0 | contextMap.put(GRADE_TYPE_TOKEN, gradeTypeResultComponent); |
| 118 | |
} |
| 119 | 0 | } else { |
| 120 | 0 | gradeTypeResultComponent = getResultComponentByResultValueId(gradeId); |
| 121 | |
} |
| 122 | 0 | if (gradeTypeResultComponent != null) { |
| 123 | 0 | contextMap.put(GRADE_TYPE_TOKEN, gradeTypeResultComponent); |
| 124 | |
} |
| 125 | |
|
| 126 | 0 | String grade = getResultValue(gradeTypeResultComponent, gradeId); |
| 127 | 0 | if(grade != null) { |
| 128 | 0 | contextMap.put(GRADE_TOKEN, grade); |
| 129 | |
} |
| 130 | |
|
| 131 | 0 | return contextMap; |
| 132 | |
} |
| 133 | |
} |