| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.common.ui.client.configurable.mvc.binding; | 
  | 17 |  |   | 
  | 18 |  |  import java.util.Iterator; | 
  | 19 |  |  import java.util.List; | 
  | 20 |  |   | 
  | 21 |  |  import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityFieldConfiguration; | 
  | 22 |  |  import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityTable; | 
  | 23 |  |  import org.kuali.student.common.ui.client.mvc.DataModel; | 
  | 24 |  |  import org.kuali.student.core.assembly.data.Data; | 
  | 25 |  |  import org.kuali.student.core.assembly.data.Metadata; | 
  | 26 |  |  import org.kuali.student.core.assembly.data.QueryPath; | 
  | 27 |  |  import org.kuali.student.core.assembly.data.Data.DataType; | 
  | 28 |  |   | 
  | 29 |  |  import com.google.gwt.core.client.GWT; | 
  | 30 |  |   | 
  | 31 |  |   | 
  | 32 |  |   | 
  | 33 |  |   | 
  | 34 | 0 |  public class MultiplicityTableBinding extends ModelWidgetBindingSupport<MultiplicityTable> { | 
  | 35 |  |   | 
  | 36 |  |   | 
  | 37 |  |       | 
  | 38 |  |   | 
  | 39 |  |   | 
  | 40 |  |   | 
  | 41 |  |      public void setModelValue(MultiplicityTable table, DataModel model, String path) { | 
  | 42 |  |           | 
  | 43 | 0 |          GWT.log("Method setModelValue not implemented for MultiplicityTable"); | 
  | 44 | 0 |      } | 
  | 45 |  |   | 
  | 46 |  |   | 
  | 47 |  |       | 
  | 48 |  |   | 
  | 49 |  |   | 
  | 50 |  |   | 
  | 51 |  |      public void setWidgetValue(MultiplicityTable table, DataModel model, String path) { | 
  | 52 | 0 |          table.initTable(); | 
  | 53 |  |   | 
  | 54 | 0 |          path = path.trim(); | 
  | 55 | 0 |          if (path.startsWith(QueryPath.getPathSeparator())) { | 
  | 56 | 0 |              path = path.substring(QueryPath.getPathSeparator().length()); | 
  | 57 |  |          } | 
  | 58 |  |   | 
  | 59 | 0 |          QueryPath qPath = QueryPath.parse(path); | 
  | 60 | 0 |          Data data = null; | 
  | 61 | 0 |          if (model != null) { | 
  | 62 | 0 |              data = model.get(qPath); | 
  | 63 |  |          } | 
  | 64 |  |   | 
  | 65 | 0 |          if (data != null) { | 
  | 66 | 0 |              Iterator<Data.Property> iter1 = data.iterator(); | 
  | 67 | 0 |              if (iter1.hasNext()) { | 
  | 68 | 0 |                  table.buildHeaders(); | 
  | 69 |  |   | 
  | 70 |  |                   | 
  | 71 | 0 |                  while (iter1.hasNext()) { | 
  | 72 | 0 |                      Data.Property prop = iter1.next(); | 
  | 73 | 0 |                      Object value = prop.getValue(); | 
  | 74 |  |   | 
  | 75 | 0 |                      if (value instanceof String) { | 
  | 76 |  |   | 
  | 77 | 0 |                          Metadata metadata = model.getMetadata(qPath); | 
  | 78 | 0 |                          String dataValue = null; | 
  | 79 | 0 |                          if(metadata!=null&&metadata.getInitialLookup()!=null){ | 
  | 80 | 0 |                              QueryPath translatedPath = QueryPath.concat("_runtimeData", prop.getKey().toString(), "id-translation"); | 
  | 81 | 0 |                              dataValue = data.query(translatedPath); | 
  | 82 |  |                          } | 
  | 83 |  |   | 
  | 84 | 0 |                          if (dataValue == null) | 
  | 85 | 0 |                              dataValue = (String)value; | 
  | 86 |  |                           | 
  | 87 | 0 |                          table.addNextCell(dataValue);                         | 
  | 88 | 0 |                          table.nextRow(); | 
  | 89 | 0 |                      } | 
  | 90 |  |                      else { | 
  | 91 | 0 |                          Data rowData = prop.getValue(); | 
  | 92 |  |   | 
  | 93 |  |                           | 
  | 94 | 0 |                          for (Integer row  : table.getConfig().getFields().keySet()) { | 
  | 95 | 0 |                              List<MultiplicityFieldConfiguration> fieldConfigs = table.getConfig().getFields().get(row); | 
  | 96 | 0 |                              for (MultiplicityFieldConfiguration fieldConfig : fieldConfigs) { | 
  | 97 |  |   | 
  | 98 | 0 |                                  QueryPath fullPath = QueryPath.parse(fieldConfig.getFieldPath()); | 
  | 99 | 0 |                                  QueryPath fieldPath = translatePath(path, fullPath, model);                            | 
  | 100 |  |   | 
  | 101 | 0 |                                  Object o = rowData.query(fieldPath); | 
  | 102 | 0 |                                  if (o != null) { | 
  | 103 |  |                                       | 
  | 104 |  |                                       | 
  | 105 | 0 |                                      if (o instanceof Data) { | 
  | 106 | 0 |                                          Data cellData = (Data) o; | 
  | 107 |  |                                           | 
  | 108 |  |                                           | 
  | 109 | 0 |                                          if (cellData != null && cellData.size() > 0) { | 
  | 110 | 0 |                                              StringBuilder sb = new StringBuilder(); | 
  | 111 | 0 |                                              Iterator<Data.Property> iter = cellData.realPropertyIterator(); | 
  | 112 | 0 |                                              while (iter.hasNext()) { | 
  | 113 | 0 |                                                  Data.Property p = iter.next(); | 
  | 114 | 0 |                                                  Data d = p.getValue(); | 
  | 115 | 0 |                                                  String key = table.getConfig().getConcatenatedFields().get(fullPath.toString()); | 
  | 116 | 0 |                                                  sb.append(d.get(key)).append(", "); | 
  | 117 | 0 |                                              } | 
  | 118 | 0 |                                              sb.deleteCharAt(sb.lastIndexOf(", ")); | 
  | 119 | 0 |                                              table.addNextCell((sb.toString())); | 
  | 120 | 0 |                                          } else { | 
  | 121 | 0 |                                              table.addEmptyCell(); | 
  | 122 |  |                                          } | 
  | 123 | 0 |                                      } | 
  | 124 |  |                                       | 
  | 125 |  |                                      else { | 
  | 126 | 0 |                                          table.addNextCell((o.toString())); | 
  | 127 |  |                                      } | 
  | 128 |  |                                  } else { | 
  | 129 | 0 |                                      table.addEmptyCell(); | 
  | 130 |  |                                  }                                 | 
  | 131 | 0 |                              } | 
  | 132 | 0 |                              table.nextRow(); | 
  | 133 | 0 |                          } | 
  | 134 |  |                      } | 
  | 135 | 0 |                  } | 
  | 136 |  |              } | 
  | 137 |  |          } | 
  | 138 | 0 |      } | 
  | 139 |  |   | 
  | 140 |  |       | 
  | 141 |  |   | 
  | 142 |  |   | 
  | 143 |  |   | 
  | 144 |  |   | 
  | 145 |  |   | 
  | 146 |  |   | 
  | 147 |  |   | 
  | 148 |  |   | 
  | 149 |  |   | 
  | 150 |  |      private QueryPath translatePath(String path, QueryPath fullPath, DataModel model) { | 
  | 151 | 0 |          QueryPath parentPath = QueryPath.parse(path); | 
  | 152 | 0 |          int i = parentPath.size(); | 
  | 153 |  |   | 
  | 154 | 0 |          Metadata metadata = model.getMetadata(fullPath); | 
  | 155 | 0 |          QueryPath fieldPath = null; | 
  | 156 |  |   | 
  | 157 | 0 |          if(metadata!=null&&metadata.getInitialLookup()!=null){ | 
  | 158 | 0 |              if (metadata.getDataType().equals(DataType.STRING)) { | 
  | 159 | 0 |                  QueryPath translatedPath = fullPath.subPath(0, fullPath.size()-1); | 
  | 160 | 0 |                  translatedPath.add(new Data.StringKey("_runtimeData")); | 
  | 161 | 0 |                  translatedPath.add(new Data.StringKey((String)fullPath.get(fullPath.size() - 1).get())); | 
  | 162 | 0 |                  translatedPath.add(new Data.StringKey("id-translation")); | 
  | 163 | 0 |                  fieldPath  =  translatedPath.subPath(i, translatedPath.size()); | 
  | 164 | 0 |              } | 
  | 165 |  |              else { | 
  | 166 | 0 |                  fieldPath =  fullPath.subPath(i, fullPath.size()); | 
  | 167 |  |              } | 
  | 168 |  |          } | 
  | 169 |  |          else { | 
  | 170 | 0 |              fieldPath =  fullPath.subPath(i, fullPath.size()); | 
  | 171 |  |          } | 
  | 172 |  |   | 
  | 173 | 0 |          if (fieldPath.get(0).toString().equals(QueryPath.getWildCard())) { | 
  | 174 | 0 |              fieldPath.remove(0); | 
  | 175 |  |          } | 
  | 176 | 0 |          return fieldPath; | 
  | 177 |  |      } | 
  | 178 |  |  } |