| 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.ArrayList; | 
  | 19 |  |  import java.util.List; | 
  | 20 |  |  import java.util.Map; | 
  | 21 |  |   | 
  | 22 |  |  import org.kuali.student.core.exceptions.OperationFailedException; | 
  | 23 |  |  import org.kuali.student.core.statement.dto.ReqComponentInfo; | 
  | 24 |  |  import org.kuali.student.core.versionmanagement.dto.VersionDisplayInfo; | 
  | 25 |  |  import org.kuali.student.lum.lu.dto.CluInfo; | 
  | 26 |  |  import org.kuali.student.lum.lu.dto.CluSetInfo; | 
  | 27 |  |  import org.kuali.student.lum.lu.dto.CluSetTreeViewInfo; | 
  | 28 |  |  import org.kuali.student.lum.lu.service.LuService; | 
  | 29 |  |  import org.kuali.student.lum.lu.service.LuServiceConstants; | 
  | 30 |  |  import org.kuali.student.lum.statement.config.context.util.NLCluSet; | 
  | 31 |  |  import org.kuali.student.lum.statement.typekey.ReqComponentFieldTypes; | 
  | 32 |  |   | 
  | 33 |  |   | 
  | 34 |  |   | 
  | 35 |  |   | 
  | 36 | 58 |  public class LuContextImpl extends BasicContextImpl { | 
  | 37 |  |       | 
  | 38 |  |   | 
  | 39 |  |   | 
  | 40 |  |          private LuService luService; | 
  | 41 |  |   | 
  | 42 |  |           | 
  | 43 |  |   | 
  | 44 |  |   | 
  | 45 |  |   | 
  | 46 |  |   | 
  | 47 |  |          public final static String CLU_TOKEN = "clu"; | 
  | 48 |  |          public final static String COURSE_CLU_TOKEN = "courseClu"; | 
  | 49 |  |          public final static String PROGRAM_CLU_TOKEN = "programClu"; | 
  | 50 |  |          public final static String TEST_CLU_TOKEN = "testClu"; | 
  | 51 |  |   | 
  | 52 |  |           | 
  | 53 |  |   | 
  | 54 |  |   | 
  | 55 |  |   | 
  | 56 |  |   | 
  | 57 |  |          public final static String CLU_SET_TOKEN = "cluSet"; | 
  | 58 |  |          public final static String COURSE_CLU_SET_TOKEN = "courseCluSet"; | 
  | 59 |  |          public final static String PROGRAM_CLU_SET_TOKEN = "programCluSet"; | 
  | 60 |  |          public final static String TEST_CLU_SET_TOKEN = "testCluSet"; | 
  | 61 |  |   | 
  | 62 |  |           | 
  | 63 |  |   | 
  | 64 |  |   | 
  | 65 |  |   | 
  | 66 |  |   | 
  | 67 |  |      public void setLuService(LuService luService) { | 
  | 68 | 6 |                  this.luService = luService; | 
  | 69 | 6 |          } | 
  | 70 |  |   | 
  | 71 |  |           | 
  | 72 |  |   | 
  | 73 |  |   | 
  | 74 |  |   | 
  | 75 |  |   | 
  | 76 |  |   | 
  | 77 |  |   | 
  | 78 |  |      public CluInfo getCluInfo(String cluId) throws OperationFailedException { | 
  | 79 | 21 |                  if (cluId == null) { | 
  | 80 | 4 |                          return null; | 
  | 81 |  |                  } | 
  | 82 |  |                  try { | 
  | 83 | 17 |                          VersionDisplayInfo versionInfo = luService.getCurrentVersion(LuServiceConstants.CLU_NAMESPACE_URI, cluId); | 
  | 84 | 15 |                          CluInfo clu = this.luService.getClu(versionInfo.getId()); | 
  | 85 | 15 |                          return clu; | 
  | 86 | 2 |                  } catch(Exception e) { | 
  | 87 | 2 |                          throw new OperationFailedException(e.getMessage(), e); | 
  | 88 |  |                  } | 
  | 89 |  |      } | 
  | 90 |  |   | 
  | 91 |  |      private CluInfo getClu(ReqComponentInfo reqComponent, String key) throws OperationFailedException { | 
  | 92 | 218 |          Map<String, String> map = getReqComponentFieldMap(reqComponent); | 
  | 93 | 218 |          if(map.containsKey(key)) { | 
  | 94 | 21 |                      String cluId = map.get(key); | 
  | 95 | 21 |                      return getCluInfo(cluId); | 
  | 96 |  |          } | 
  | 97 | 197 |          return null; | 
  | 98 |  |      } | 
  | 99 |  |       | 
  | 100 |  |       | 
  | 101 |  |   | 
  | 102 |  |   | 
  | 103 |  |   | 
  | 104 |  |   | 
  | 105 |  |   | 
  | 106 |  |   | 
  | 107 |  |      public CluSetInfo getCluSetInfo(String cluSetId) throws OperationFailedException { | 
  | 108 | 51 |                  if (cluSetId == null) { | 
  | 109 | 0 |                          return null; | 
  | 110 |  |                  } | 
  | 111 |  |                  try { | 
  | 112 | 51 |                      CluSetInfo cluSet = this.luService.getCluSetInfo(cluSetId); | 
  | 113 | 40 |                      return cluSet; | 
  | 114 | 11 |                  } catch(Exception e) { | 
  | 115 | 11 |                          throw new OperationFailedException(e.getMessage(), e); | 
  | 116 |  |                  } | 
  | 117 |  |      } | 
  | 118 |  |   | 
  | 119 |  |       | 
  | 120 |  |   | 
  | 121 |  |   | 
  | 122 |  |   | 
  | 123 |  |   | 
  | 124 |  |   | 
  | 125 |  |   | 
  | 126 |  |      public NLCluSet getCluSet(String cluSetId) throws OperationFailedException { | 
  | 127 | 55 |                  if (cluSetId == null) { | 
  | 128 | 4 |                          return null; | 
  | 129 |  |                  } | 
  | 130 | 51 |              CluSetInfo cluSet = getCluSetInfo(cluSetId); | 
  | 131 |  |                  try { | 
  | 132 | 40 |                      List<CluInfo> list = new ArrayList<CluInfo>(); | 
  | 133 | 40 |                      CluSetTreeViewInfo tree = luService.getCluSetTreeView(cluSetId); | 
  | 134 | 40 |                      findClusInCluSet(tree, list); | 
  | 135 | 40 |                      return new NLCluSet(cluSet.getId(), list); | 
  | 136 | 0 |                  } catch(Exception e) { | 
  | 137 | 0 |                          throw new OperationFailedException(e.getMessage(), e); | 
  | 138 |  |                  } | 
  | 139 |  |      } | 
  | 140 |  |   | 
  | 141 |  |      private static void findClusInCluSet(CluSetTreeViewInfo tree, List<CluInfo> cluList) { | 
  | 142 | 42 |              if (tree.getCluSets() != null) { | 
  | 143 | 1 |                          for (CluSetTreeViewInfo cluSet : tree.getCluSets()) { | 
  | 144 | 2 |                                  findClusInCluSet(cluSet, cluList); | 
  | 145 |  |                          } | 
  | 146 |  |                  } else { | 
  | 147 | 41 |                          for (CluInfo clu : tree.getClus()) { | 
  | 148 | 75 |                                  if (!containsClu(cluList, clu)) { | 
  | 149 | 73 |                                          cluList.add(clu); | 
  | 150 |  |                                  } | 
  | 151 |  |                          } | 
  | 152 |  |                  } | 
  | 153 | 42 |          } | 
  | 154 |  |   | 
  | 155 |  |          private static boolean containsClu(List<CluInfo> cluList, CluInfo clu) { | 
  | 156 | 75 |                  for (CluInfo clu2 : cluList) { | 
  | 157 | 44 |                          if (clu2.getId().equals(clu.getId())) { | 
  | 158 | 2 |                                  return true; | 
  | 159 |  |                          } | 
  | 160 |  |                  } | 
  | 161 | 73 |                  return false; | 
  | 162 |  |          } | 
  | 163 |  |   | 
  | 164 |  |           | 
  | 165 |  |   | 
  | 166 |  |   | 
  | 167 |  |   | 
  | 168 |  |   | 
  | 169 |  |   | 
  | 170 |  |   | 
  | 171 |  |       | 
  | 172 |  |   | 
  | 173 |  |   | 
  | 174 |  |   | 
  | 175 |  |   | 
  | 176 |  |   | 
  | 177 |  |   | 
  | 178 |  |   | 
  | 179 |  |   | 
  | 180 |  |   | 
  | 181 |  |       | 
  | 182 |  |   | 
  | 183 |  |   | 
  | 184 |  |   | 
  | 185 |  |   | 
  | 186 |  |   | 
  | 187 |  |   | 
  | 188 |  |      public NLCluSet getCluSet(ReqComponentInfo reqComponent, String key) throws OperationFailedException { | 
  | 189 | 199 |          Map<String, String> map = getReqComponentFieldMap(reqComponent); | 
  | 190 | 199 |              NLCluSet cluSet = null; | 
  | 191 | 199 |              if(map.containsKey(key)) { | 
  | 192 | 55 |                  String cluSetId = map.get(key); | 
  | 193 | 55 |              cluSet = getCluSet(cluSetId); | 
  | 194 |  |          } | 
  | 195 | 188 |              return cluSet; | 
  | 196 |  |      } | 
  | 197 |  |   | 
  | 198 |  |       | 
  | 199 |  |   | 
  | 200 |  |   | 
  | 201 |  |   | 
  | 202 |  |   | 
  | 203 |  |   | 
  | 204 |  |      public Map<String, Object> createContextMap(ReqComponentInfo reqComponent) throws OperationFailedException { | 
  | 205 | 55 |          Map<String, Object> contextMap = super.createContextMap(reqComponent); | 
  | 206 |  |   | 
  | 207 | 55 |          CluInfo clu = getClu(reqComponent, ReqComponentFieldTypes.CLU_KEY.getId()); | 
  | 208 | 55 |          if(clu != null) { | 
  | 209 | 2 |                  contextMap.put(CLU_TOKEN, clu); | 
  | 210 |  |          } | 
  | 211 | 55 |          CluInfo courseClu = getClu(reqComponent, ReqComponentFieldTypes.COURSE_CLU_KEY.getId()); | 
  | 212 | 55 |          if(courseClu != null) { | 
  | 213 | 5 |                  contextMap.put(COURSE_CLU_TOKEN, courseClu); | 
  | 214 |  |          } | 
  | 215 | 55 |          CluInfo programClu = getClu(reqComponent, ReqComponentFieldTypes.PROGRAM_CLU_KEY.getId()); | 
  | 216 | 53 |          if(programClu != null) { | 
  | 217 | 6 |                  contextMap.put(PROGRAM_CLU_TOKEN, programClu); | 
  | 218 |  |          } | 
  | 219 | 53 |          CluInfo testClu = getClu(reqComponent, ReqComponentFieldTypes.TEST_CLU_KEY.getId()); | 
  | 220 | 53 |          if(testClu != null) { | 
  | 221 | 2 |                  contextMap.put(TEST_CLU_TOKEN, testClu); | 
  | 222 |  |          } | 
  | 223 |  |   | 
  | 224 | 53 |          NLCluSet cluSet = getCluSet(reqComponent, ReqComponentFieldTypes.CLUSET_KEY.getId()); | 
  | 225 | 53 |          if(cluSet != null) { | 
  | 226 | 2 |                  contextMap.put(CLU_SET_TOKEN, cluSet); | 
  | 227 |  |          } | 
  | 228 | 53 |          NLCluSet courseCluSet = getCluSet(reqComponent, ReqComponentFieldTypes.COURSE_CLUSET_KEY.getId()); | 
  | 229 | 51 |          if(courseCluSet != null) { | 
  | 230 | 28 |                  contextMap.put(COURSE_CLU_SET_TOKEN, courseCluSet); | 
  | 231 |  |          } | 
  | 232 | 51 |          NLCluSet programCluSet = getCluSet(reqComponent, ReqComponentFieldTypes.PROGRAM_CLUSET_KEY.getId()); | 
  | 233 | 42 |          if(programCluSet != null) { | 
  | 234 | 6 |                  contextMap.put(PROGRAM_CLU_SET_TOKEN, programCluSet); | 
  | 235 |  |          } | 
  | 236 | 42 |          NLCluSet testCluSet = getCluSet(reqComponent, ReqComponentFieldTypes.TEST_CLUSET_KEY.getId()); | 
  | 237 | 42 |          if(testCluSet != null) { | 
  | 238 | 4 |                  contextMap.put(TEST_CLU_SET_TOKEN, testCluSet); | 
  | 239 |  |          } | 
  | 240 |  |   | 
  | 241 | 42 |          return contextMap; | 
  | 242 |  |      } | 
  | 243 |  |  } |