Ejemplo n.º 1
0
  /**
   * built market browse url
   *
   * @param itemSearch
   * @param name
   * @return
   */
  public static String browseUrl(ItemSearch itemSearch, String name) {
    String url;
    boolean check = false;
    if (itemSearch.getCategoryIds() == null || itemSearch.getCategoryIds().isEmpty()) {
      check = true;
      url = "/tim-kiem.html";
    } else {
      url =
          "/mua-ban/"
              + itemSearch.getCategoryIds().get(0)
              + "/"
              + TextUtils.createAlias(name)
              + ".html";
    }

    String search = "";
    String keyword = itemSearch.getKeyword();
    int pageIndex = itemSearch.getPageIndex();
    if ((itemSearch.getModelIds() != null && !itemSearch.getModelIds().isEmpty())
        || (itemSearch.getManufacturerIds() != null && !itemSearch.getManufacturerIds().isEmpty())
        || (itemSearch.getCityIds() != null && !itemSearch.getCityIds().isEmpty())
        || itemSearch.getOrderBy() > 0
        || (itemSearch.getProperties() != null && !itemSearch.getProperties().isEmpty())
        || (itemSearch.getCondition() == Condition.NEW
            || itemSearch.getCondition() == Condition.OLD)
        || (itemSearch.getListingType() == ListingType.AUCTION
            || itemSearch.getListingType() == ListingType.BUYNOW)
        || (itemSearch.getPriceFrom() > 0 || itemSearch.getPriceTo() > 0)
        || itemSearch.isCod()
        || itemSearch.isFreeShip()
        || itemSearch.isOnlinePayment()
        || itemSearch.isPromotion()
        || (itemSearch.getSellerId() != null && !itemSearch.getSellerId().equals(""))
        || (itemSearch.getPromotionId() != null && !itemSearch.getPromotionId().equals(""))) {
      itemSearch.setKeyword(null);
      itemSearch.setPageIndex(0);
      search =
          "filter="
              + Base64.encodeBase64String(StringUtils.getBytesUtf8(new Gson().toJson(itemSearch)));
    }

    if (keyword != null && !keyword.equals("")) {
      if (check && search.equals("")) {
        return "/s/"
            + keyword.replaceAll("\\s+", "\\+").trim()
            + ".html"
            + (pageIndex <= 1 ? "" : "?page=" + pageIndex);
      } else {
        url += "?keyword=" + keyword.replaceAll("\\s+", "\\+").trim();
        url = pageIndex <= 1 ? url : url + "&page=" + pageIndex;
        return search.equals("") ? url : url + (search.equals("") ? "" : ("&" + search));
      }
    } else {
      return search.equals("")
          ? (pageIndex <= 1 ? url : url + "?page=" + pageIndex)
          : ((pageIndex <= 1 ? (url + "?") : (url + "?page=" + pageIndex + "&")) + search);
    }
  }
Ejemplo n.º 2
0
 public static String browseToModel(ItemSearch itemSearch, String name) {
   ModelSearch modelSearch = new ModelSearch();
   if (itemSearch.getCategoryIds() != null && !itemSearch.getCategoryIds().isEmpty()) {
     modelSearch.setCategoryId(itemSearch.getCategoryIds().get(0));
   }
   modelSearch.setKeyword(itemSearch.getKeyword());
   modelSearch.setManufacturerIds(itemSearch.getManufacturerIds());
   modelSearch.setProperties(itemSearch.getProperties());
   return UrlUtils.modelBrowseUrl(modelSearch, name);
 }
Ejemplo n.º 3
0
  public static String modelDetailUrl(ItemSearch sourceItemSearch, String name, String strChange) {
    ItemSearch itemSearch;
    try {
      itemSearch = (ItemSearch) BeanUtils.cloneBean(sourceItemSearch);
      itemSearch.setModelIds(new ArrayList<>(sourceItemSearch.getModelIds()));
    } 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("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("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("cod")) {
          if (op.equals("mk")) {
            itemSearch.setCod(true);
          } else if (op.equals("rm")) {
            itemSearch.setCod(false);
          }
        }
        if (key.equals("manuf")) {
          if (op.equals("mk")) {
            itemSearch.setManufacturerIds(new ArrayList<String>());
          }
        }
        if (key.equals("promotion")) {
          if (op.equals("mk")) {
            itemSearch.setPromotion(true);
          } else if (op.equals("rm")) {
            itemSearch.setPromotion(false);
          }
        }

        if (key.equals("condition")) {
          try {
            if (val.equals("NEW")) {
              itemSearch.setCondition(Condition.NEW);
            } else if (val.equals("OLD")) {
              itemSearch.setCondition(Condition.OLD);
            } else {
              itemSearch.setListingType(null);
            }
          } 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) {
          }
        }
      }
    }
    String url;
    if (itemSearch.getModelIds() != null && itemSearch.getModelIds().size() > 0) {
      url =
          "/model/" + itemSearch.getModelIds().get(0) + "/" + TextUtils.createAlias(name) + ".html";
    } else {
      url = "/tim-kiem-model.html";
    }
    String search = "";
    String keyword = itemSearch.getKeyword();
    int pageIndex = itemSearch.getPageIndex();
    if ((itemSearch.getManufacturerIds() != null && !itemSearch.getManufacturerIds().isEmpty())
        || (itemSearch.getCityIds() != null && !itemSearch.getCityIds().isEmpty())
        || itemSearch.getOrderBy() > 0
        || (itemSearch.getProperties() != null && !itemSearch.getProperties().isEmpty())
        || (itemSearch.getCondition() == Condition.NEW
            || itemSearch.getCondition() == Condition.OLD)
        || (itemSearch.getListingType() == ListingType.AUCTION
            || itemSearch.getListingType() == ListingType.BUYNOW)
        || (itemSearch.getPriceFrom() > 0 || itemSearch.getPriceTo() > 0)
        || itemSearch.isCod()
        || itemSearch.isFreeShip()
        || itemSearch.isOnlinePayment()
        || itemSearch.isPromotion()) {
      itemSearch.setKeyword(null);
      search =
          "?filter="
              + Base64.encodeBase64String(StringUtils.getBytesUtf8(new Gson().toJson(itemSearch)));
    }
    if (keyword != null && !keyword.equals("")) {
      url += "?keyword=" + keyword.replaceAll("\\s+", "\\+");
      url = pageIndex <= 1 ? url : url + "&page=" + pageIndex;
      return search.equals("") ? url : url + "&" + search;
    } else {
      return search.equals("")
          ? (pageIndex <= 1 ? url : url + "?page=" + pageIndex)
          : ((pageIndex <= 1 ? (url + "?") : (url + "?page=" + pageIndex + "&")) + search);
    }
  }
Ejemplo n.º 4
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);
  }