Example #1
0
 public static String browseToItem(ModelSearch modelSearch, String name) {
   ItemSearch itemSearch = new ItemSearch();
   if (modelSearch.getCategoryId() != null && !modelSearch.getCategoryId().trim().equals("")) {
     itemSearch.setCategoryIds(new ArrayList<String>());
     itemSearch.getCategoryIds().add(modelSearch.getCategoryId());
   }
   itemSearch.setKeyword(modelSearch.getKeyword());
   itemSearch.setManufacturerIds(modelSearch.getManufacturerIds());
   itemSearch.setProperties(modelSearch.getProperties());
   return UrlUtils.browseUrl(itemSearch, name);
 }
Example #2
0
  public static String browseUrl(ItemSearch sourceItemSearch, String name, String strChange) {
    ItemSearch itemSearch;
    try {
      itemSearch = (ItemSearch) BeanUtils.cloneBean(sourceItemSearch);
      itemSearch.setManufacturerIds(new ArrayList<>(sourceItemSearch.getManufacturerIds()));
      itemSearch.setModelIds(new ArrayList<>(sourceItemSearch.getModelIds()));
      itemSearch.setCityIds(new ArrayList<>(sourceItemSearch.getCityIds()));
      itemSearch.setProperties(new ArrayList<>(sourceItemSearch.getProperties()));
    } catch (IllegalAccessException
        | InstantiationException
        | InvocationTargetException
        | NoSuchMethodException ex) {
      itemSearch = new ItemSearch();
    }
    if (strChange != null && !strChange.equals("")) {
      List<Map<String, String>> changes =
          (List<Map<String, String>>)
              JsonUtils.decode(strChange, new TypeToken<List<Map<String, String>>>() {}.getType());

      for (Map<String, String> ch : changes) {
        String op = ch.get("op");
        String key = ch.get("key");
        String val = ch.get("val");
        if (key.equals("cid")) {
          if (op.equals("mk")) {
            itemSearch.setCategoryIds(new ArrayList<String>());
            itemSearch.getCategoryIds().add(val);
          } else if (op.equals("rm")) {
            itemSearch.setCategoryIds(null);
            itemSearch.setCategoryId(null);
          }
        }
        if (key.equals("keyword")) {
          if (op.equals("mk")) {
            itemSearch.setKeyword(val);
          } else if (op.equals("rm")) {
            itemSearch.setKeyword(null);
          }
        }
        if (key.equals("sellerId")) {
          if (op.equals("mk")) {
            itemSearch.setSellerId(val);
          } else if (op.equals("rm")) {
            itemSearch.setSellerId(null);
          }
        }
        if (key.equals("manufacturers")) {
          if (op.equals("mk")) {
            itemSearch.getManufacturerIds().remove(val);
            itemSearch.getManufacturerIds().add(val);
          } else if (op.equals("rm")) {
            itemSearch.getManufacturerIds().remove(val);
          } else if (op.equals("cl")) {
            itemSearch.getManufacturerIds().clear();
          }
        }
        if (key.equals("models")) {
          if (op.equals("mk")) {
            itemSearch.getModelIds().remove(val);
            itemSearch.getModelIds().add(val);
          } else if (op.equals("rm")) {
            itemSearch.getModelIds().remove(val);
          } else if (op.equals("cl")) {
            itemSearch.getModelIds().clear();
          }
        }
        if (key.equals("cities")) {
          if (op.equals("mk")) {
            itemSearch.getCityIds().remove(val);
            itemSearch.getCityIds().add(val);
          } else if (op.equals("rm")) {
            itemSearch.getCityIds().remove(val);
          } else if (op.equals("cl")) {
            itemSearch.getCityIds().clear();
          }
        }
        if (key.equals("properties")) {
          PropertySearch ps =
              (PropertySearch) JsonUtils.decode(val, new TypeToken<PropertySearch>() {}.getType());
          if (op.equals("mk")) {
            itemSearch.getProperties().remove(ps);
            itemSearch.getProperties().add(ps);
          } else if (op.equals("rm")) {
            itemSearch.getProperties().remove(ps);
          } else if (op.equals("cl")) {
            itemSearch.getProperties().clear();
          }
        }
        if (key.equals("freeship")) {
          if (op.equals("mk")) {
            itemSearch.setFreeShip(true);
          } else if (op.equals("rm")) {
            itemSearch.setFreeShip(false);
          }
        }
        if (key.equals("cod")) {
          if (op.equals("mk")) {
            itemSearch.setCod(true);
          } else if (op.equals("rm")) {
            itemSearch.setCod(false);
          }
        }
        if (key.equals("onlinepayment")) {
          if (op.equals("mk")) {
            itemSearch.setOnlinePayment(true);
          } else if (op.equals("rm")) {
            itemSearch.setOnlinePayment(false);
          }
        }
        if (key.equals("promotion")) {
          if (op.equals("mk")) {
            itemSearch.setPromotion(true);
          } else if (op.equals("rm")) {
            itemSearch.setPromotion(false);
          }
        }
        if (key.equals("promotionId")) {
          if (op.equals("mk")) {
            itemSearch.setPromotionId(val);
          } else if (op.equals("rm")) {
            itemSearch.setPromotionId(null);
          }
        }
        if (key.equals("type")) {
          try {
            if (val.equals("BUYNOW")) {
              itemSearch.setListingType(ListingType.BUYNOW);
            } else if (val.equals("AUCTION")) {
              itemSearch.setListingType(ListingType.AUCTION);
            } else {
              itemSearch.setListingType(null);
            }
          } catch (NumberFormatException ex) {
          }
        }
        if (key.equals("condition")) {
          try {
            if (val.equals("NEW")) {
              itemSearch.setCondition(Condition.NEW);
            } else if (val.equals("OLD")) {
              itemSearch.setCondition(Condition.OLD);
            } else {
              itemSearch.setCondition(null);
            }
          } catch (NumberFormatException ex) {
          }
        }
        if (key.equals("pricefrom")) {
          try {
            itemSearch.setPriceFrom(Integer.parseInt(val));
          } catch (NumberFormatException ex) {
          }
        }
        if (key.equals("priceto")) {
          try {
            itemSearch.setPriceTo(Integer.parseInt(val));
          } catch (NumberFormatException ex) {
          }
        }
        if (key.equals("order")) {
          try {
            itemSearch.setOrderBy(Integer.parseInt(val));
          } catch (NumberFormatException ex) {
          }
        }
        if (key.equals("page")) {
          try {
            itemSearch.setPageIndex(Integer.parseInt(val));
          } catch (NumberFormatException ex) {
          }
        }
      }
    }
    return UrlUtils.browseUrl(itemSearch, name);
  }