示例#1
0
 public static Map<String, String> toRequestMap(List paypalClassicModelList, String format) {
   Map<String, String> returnMap = new HashMap<>();
   if (paypalClassicModelList != null) {
     for (int i = 0; i < paypalClassicModelList.size(); i++) {
       if (paypalClassicModelList.get(i) instanceof PaypalClassicModel) {
         if (StringUtils.isNoneEmpty(format)) {
           returnMap.putAll(
               toRequestMap(
                   (PaypalClassicModel) paypalClassicModelList.get(i),
                   format + String.valueOf(i)));
         } else {
           returnMap.putAll(
               toRequestMap(
                   (PaypalClassicModel) paypalClassicModelList.get(i), String.valueOf(i)));
         }
       }
       if (paypalClassicModelList.get(i) instanceof List) {
         if (StringUtils.isNoneEmpty(format)) {
           returnMap.putAll(
               toRequestMap((List) paypalClassicModelList.get(i), format + String.valueOf(i)));
         } else {
           returnMap.putAll(toRequestMap((List) paypalClassicModelList.get(i), String.valueOf(i)));
         }
       }
     }
   }
   return returnMap;
 }
示例#2
0
  public static Map<String, String> toRequestMap(
      PaypalClassicModel paypalClassicModel, String format) {
    Map<String, String> returnMap = new HashMap<>();
    if (paypalClassicModel == null) {
      return returnMap;
    }
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    //        ValidatorFactory factory = Validation.byDefaultProvider()
    //                .configure()
    //                .messageInterpolator( new MyMessageInterpolator() )
    //                .buildValidatorFactory();
    Validator validator = factory.getValidator();
    Set<ConstraintViolation<PaypalClassicModel>> violations =
        validator.validate(paypalClassicModel);
    if (violations.size() == 0) {
      try {
        for (Field field : FieldUtils.getAllFields(paypalClassicModel.getClass())) {
          if (field.getType().isAssignableFrom(String.class)) {
            if (BeanUtils.getProperty(paypalClassicModel, field.getName()) != null) {
              if (StringUtils.isNumeric(format)) {
                returnMap.put(
                    field.getName().toUpperCase() + format,
                    BeanUtils.getProperty(paypalClassicModel, field.getName()));
              } else {
                returnMap.put(
                    getFormatedKeyName(format, field.getName(), null),
                    BeanUtils.getProperty(paypalClassicModel, field.getName()));
              }
            }
          }
          if (PaypalClassicModel.class.isAssignableFrom(field.getType())) {

            if (PropertyUtils.getProperty(paypalClassicModel, field.getName()) != null) {
              returnMap.putAll(
                  toRequestMap(
                      (PaypalClassicModel)
                          PropertyUtils.getProperty(paypalClassicModel, field.getName()),
                      format));
            }
          }
          if (List.class.isAssignableFrom(field.getType())) {
            List listItem = (List) PropertyUtils.getProperty(paypalClassicModel, field.getName());
            if (listItem != null) {
              for (int i = 0; i < listItem.size(); i++) {
                if (listItem.get(i) instanceof PaypalClassicModel) {
                  PaypalCollection paypalCollection = field.getAnnotation(PaypalCollection.class);
                  if (paypalCollection != null
                      && StringUtils.isNotEmpty(paypalCollection.format())) {
                    String formatStr = field.getAnnotation(PaypalCollection.class).format();
                    returnMap.putAll(
                        toRequestMap(
                            (PaypalClassicModel) listItem.get(i),
                            getFormatedKeyName(formatStr, null, i)));
                  } else {
                    if (StringUtils.isNoneEmpty(format)) {
                      returnMap.putAll(
                          toRequestMap(
                              (PaypalClassicModel) listItem.get(i), format + String.valueOf(i)));
                    } else {
                      returnMap.putAll(
                          toRequestMap((PaypalClassicModel) listItem.get(i), String.valueOf(i)));
                    }
                  }
                }
                if (listItem.get(i) instanceof List) {
                  PaypalCollection paypalCollection = field.getAnnotation(PaypalCollection.class);
                  if (paypalCollection != null
                      && StringUtils.isNotEmpty(paypalCollection.format())) {
                    String formatStr = field.getAnnotation(PaypalCollection.class).format();
                    returnMap.putAll(
                        toRequestMap(
                            (List) listItem.get(i), getFormatedKeyName(formatStr, null, i)));
                  } else {
                    if (StringUtils.isNoneEmpty(format)) {
                      returnMap.putAll(
                          toRequestMap((List) listItem.get(i), format + String.valueOf(i)));
                    } else {
                      returnMap.putAll(toRequestMap((List) listItem.get(i), String.valueOf(i)));
                    }
                  }
                }
                if (listItem.get(i) instanceof String) {
                  PaypalCollection paypalCollection = field.getAnnotation(PaypalCollection.class);
                  if (paypalCollection != null
                      && StringUtils.isNotEmpty(paypalCollection.format())) {
                    String formatStr = paypalCollection.format();
                    formatStr = getFormatedKeyName(formatStr, field.getName(), i);
                    returnMap.put(
                        getFormatedKeyName(format, formatStr, null), listItem.get(i).toString());
                  } else {
                    returnMap.put(
                        getFormatedKeyName(format, field.getName(), null) + i,
                        listItem.get(i).toString());
                  }
                }
              }
            }
          }
        }
      } catch (IllegalAccessException e) {
        throw new ValidationException(e.getMessage());
      } catch (InvocationTargetException e) {
        throw new ValidationException(e.getMessage());
      } catch (NoSuchMethodException e) {
        throw new ValidationException(e.getMessage());
      }
    } else {
      StringBuffer buf = new StringBuffer();
      for (ConstraintViolation<PaypalClassicModel> violation : violations) {
        buf.append(violation.getMessage() + "\n");
      }
      throw new ValidationException(buf.toString());
    }
    return returnMap;
  }
示例#3
0
 private static Map<String, String> getCaseInsensitveMap(Map<String, String> map) {
   Map<String, String> mapdata = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
   mapdata.putAll(map);
   return mapdata;
 }