コード例 #1
0
  /**
   * Adds the field values from the service item container to the map.
   *
   * @param service the service.
   * @param container the service item container.
   * @param values the map holding the values.
   * @param locked all locked values for the service.
   */
  private static void addFieldValues(
      CatalogServiceRestRep service,
      Collection<? extends ServiceItemRestRep> items,
      Map<String, String> values,
      Map<String, String> locked) {
    for (ServiceItemRestRep item : items) {
      if (item instanceof ServiceFieldTableRestRep) {
        addColumnValues(service, (ServiceFieldTableRestRep) item, values, locked);
      } else if (item instanceof ServiceFieldGroupRestRep) {
        addFieldValues(service, ((ServiceFieldGroupRestRep) item).getItems(), values, locked);
      } else if (item instanceof ServiceFieldRestRep) {
        ServiceFieldRestRep field = (ServiceFieldRestRep) item;
        String value = getFieldValue(field);
        if (locked.containsKey(field.getName())) {
          value = locked.get(field.getName());
        }
        if (value != null) {
          values.put(field.getName(), value);
        }

        List<String> fieldValues = TextUtils.parseCSV(value);
        if (fieldValues.isEmpty() && field.isRequired()) {
          Validation.required(field.getName(), null);
        }
        for (String fieldValue : fieldValues) {
          ServiceFieldValidator.validateField(service, field, fieldValue);
        }
      }
    }
  }
コード例 #2
0
  /**
   * 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));
    }
  }