コード例 #1
0
ファイル: UrlUtils.java プロジェクト: toannh/ecommerce
 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);
 }
コード例 #2
0
ファイル: UrlUtils.java プロジェクト: toannh/ecommerce
  public static String modelBrowseUrl(
      ModelSearch sourceModelSearch, String name, String strChange) {
    ModelSearch modelSearch;
    try {
      modelSearch = (ModelSearch) BeanUtils.cloneBean(sourceModelSearch);
      modelSearch.setManufacturerIds(new ArrayList<>(sourceModelSearch.getManufacturerIds()));
      modelSearch.setProperties(new ArrayList<>(sourceModelSearch.getProperties()));
    } catch (IllegalAccessException
        | InstantiationException
        | InvocationTargetException
        | NoSuchMethodException ex) {
      modelSearch = new ModelSearch();
    }
    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")) {
          modelSearch.setCategoryId(val);
        }
        if (key.equals("keyword")) {
          if (op.equals("mk")) {
            modelSearch.setKeyword(val);
          } else if (op.equals("rm")) {
            modelSearch.setKeyword(null);
          }
        }
        if (key.equals("manufacturers")) {
          if (op.equals("mk")) {
            modelSearch.getManufacturerIds().remove(val);
            modelSearch.getManufacturerIds().add(val);
          } else if (op.equals("rm")) {
            modelSearch.getManufacturerIds().remove(val);
          } else if (op.equals("cl")) {
            modelSearch.getManufacturerIds().clear();
          }
        }
        if (key.equals("properties")) {
          PropertySearch ps =
              (PropertySearch) JsonUtils.decode(val, new TypeToken<PropertySearch>() {}.getType());
          if (op.equals("mk")) {
            modelSearch.getProperties().remove(ps);
            modelSearch.getProperties().add(ps);
          } else if (op.equals("rm")) {
            modelSearch.getProperties().remove(ps);
          } else if (op.equals("cl")) {
            modelSearch.getProperties().clear();
          }
        }

        if (key.equals("order")) {
          try {
            modelSearch.setOrderBy(Integer.parseInt(val));
          } catch (NumberFormatException ex) {
          }
        }
        if (key.equals("page")) {
          try {
            modelSearch.setPageIndex(Integer.parseInt(val));
          } catch (NumberFormatException ex) {
          }
        }
      }
    }
    return UrlUtils.modelBrowseUrl(modelSearch, name);
  }