/** * Adds all column values for the given table. * * @param service the catalog service. * @param table the table of fields. * @param values the map holding the values. * @param locked all locked values for the service. */ private static void addColumnValues( CatalogServiceRestRep service, ServiceFieldTableRestRep table, Map<String, String> values, Map<String, String> locked) { List<ServiceFieldRestRep> fields = ServiceDescriptorUtils.getAllFieldList(table.getItems()); int rowCount = 0; for (ServiceFieldRestRep field : fields) { if (!locked.containsKey(field.getName())) { String[] columns = getColumnValue(table, field); rowCount = Math.max(rowCount, columns.length); } } for (ServiceFieldRestRep field : fields) { String[] columns = new String[rowCount]; if (locked.containsKey(field.getName())) { String lockedValue = locked.get(field.getName()); for (int i = 0; i < columns.length; i++) { columns[i] = lockedValue; } } else { String[] col = getColumnValue(table, field); System.arraycopy(col, 0, columns, 0, col.length); } for (int i = 0; i < columns.length; i++) { String prefix = table.getName() + "[" + i + "]"; ServiceFieldValidator.validateField(service, prefix, field, columns[i]); } values.put(field.getName(), TextUtils.formatCSV(columns)); } }
/** * Gets the submitted value for the column field from the HTTP params. The parameters are named: * <tt><<i>table.name</i>>[<i>i</i>].<<i>field.name</i>></tt> * * @param table the table containing the field. * @param field the field. * @return the values for the column. */ private static String[] getColumnValue( ServiceFieldTableRestRep table, ServiceFieldRestRep field) { List<String> values = Lists.newArrayList(); Pattern pattern = Pattern.compile(table.getName() + "\\[(\\d+)\\]." + field.getName()); for (String name : params.data.keySet()) { Matcher match = pattern.matcher(name); if (match.matches()) { int index = Integer.valueOf(match.group(1)); for (int i = values.size(); i <= index; i++) { values.add(null); } values.set(index, params.get(name)); } } return values.toArray(new String[values.size()]); }