예제 #1
0
  @RequestMapping(value = BoUrls.STORE_EDIT_URL, method = RequestMethod.GET)
  public ModelAndView storeEdit(
      final HttpServletRequest request,
      final Model model,
      @ModelAttribute(ModelConstants.STORE_FORM) StoreForm storeForm)
      throws Exception {
    ModelAndViewThemeDevice modelAndView =
        new ModelAndViewThemeDevice(
            getCurrentVelocityPath(request), BoUrls.STORE_EDIT.getVelocityPage());
    final RequestData requestData = requestUtil.getRequestData(request);

    final String storeCode = request.getParameter(RequestConstants.REQUEST_PARAMETER_STORE_CODE);
    if (StringUtils.isNotEmpty(storeCode)) {
      // EDIT MODE
      final Store store =
          retailerService.getStoreByCode(storeCode, FetchPlanGraphRetailer.fullStoreFetchPlan());

      // SANITY CHECK
      if (store != null) {
        modelAndView.addObject(
            ModelConstants.STORE_VIEW_BEAN,
            backofficeViewBeanFactory.buildViewBeanStore(requestData, store));
      } else {
        final String url = requestUtil.getLastRequestUrl(request);
        return new ModelAndView(new RedirectView(url));
      }

      model.addAttribute(
          ModelConstants.URL_BACK,
          backofficeUrlService.generateUrl(BoUrls.STORE_DETAILS, requestData, store));

      Object[] params = {store.getName() + " (" + store.getCode() + ")"};
      initPageTitleAndMainContentTitle(
          request, modelAndView, BoUrls.STORE_DETAILS.getKey(), params);

    } else {
      // ADD MODE

      initPageTitleAndMainContentTitle(request, modelAndView, BoUrls.STORE_ADD.getKey(), null);

      model.addAttribute(
          ModelConstants.URL_BACK,
          backofficeUrlService.generateUrl(BoUrls.STORE_LIST, requestData));
    }

    return modelAndView;
  }
예제 #2
0
  @RequestMapping(value = BoUrls.STORE_DETAILS_URL, method = RequestMethod.GET)
  public ModelAndView storeDetails(final HttpServletRequest request, final Model model)
      throws Exception {
    ModelAndViewThemeDevice modelAndView =
        new ModelAndViewThemeDevice(
            getCurrentVelocityPath(request), BoUrls.STORE_DETAILS.getVelocityPage());
    final RequestData requestData = requestUtil.getRequestData(request);

    final String storeCode = request.getParameter(RequestConstants.REQUEST_PARAMETER_STORE_CODE);

    // SANITY CHECK
    if (StringUtils.isEmpty(storeCode)) {
      final String urlRedirect = backofficeUrlService.generateUrl(BoUrls.STORE_LIST, requestData);
      return new ModelAndView(new RedirectView(urlRedirect));
    }

    final Store retailer = retailerService.getStoreByCode(storeCode);

    // SANITY CHECK
    if (retailer != null) {
      modelAndView.addObject(
          ModelConstants.STORE_VIEW_BEAN,
          backofficeViewBeanFactory.buildViewBeanStore(requestData, retailer));
    } else {
      final String url = requestUtil.getLastRequestUrl(request);
      return new ModelAndView(new RedirectView(url));
    }

    model.addAttribute(
        ModelConstants.URL_BACK, backofficeUrlService.generateUrl(BoUrls.STORE_LIST, requestData));
    model.addAttribute(
        ModelConstants.URL_RETAILER_VIEW,
        backofficeUrlService.generateUrl(BoUrls.RETAILER_DETAILS, requestData, retailer));

    Object[] params = {retailer.getName() + " (" + retailer.getCode() + ")"};
    initPageTitleAndMainContentTitle(request, modelAndView, BoUrls.STORE_DETAILS.getKey(), params);

    return modelAndView;
  }
예제 #3
0
  @SuppressWarnings("unchecked")
  public String generateUrl(
      final String urlWithoutWildcard,
      final boolean isSEO,
      final RequestData requestData,
      Object... params) {
    String urlStr = null;
    Map<String, String> getParams = new HashMap<String, String>();
    Map<String, String> urlParams = new HashMap<String, String>();
    try {
      if (params != null) {
        for (Object param : params) {
          if (param == null) continue;
          if (param instanceof Retailer) {
            Retailer retailer = (Retailer) param;
            urlParams.put(
                RequestConstants.URL_PATTERN_RETAILER_CODE, handleParamValue(retailer.getCode()));
            urlStr =
                addFullPrefixUrl(requestData, urlStr)
                    + replaceSpaceAndUnderscore(retailer.getName())
                    + "/";
          } else if (param instanceof ProductSku) {
            ProductSku productSku = (ProductSku) param;
            urlParams.put(
                RequestConstants.URL_PATTERN_PRODUCT_SKU_CODE,
                handleParamValue(productSku.getCode()));
            urlStr = addFullPrefixUrl(requestData, urlStr);
          } else if (param instanceof ProductMarketing) {
            ProductMarketing productMarketing = (ProductMarketing) param;
            urlParams.put(
                RequestConstants.URL_PATTERN_PRODUCT_MARKETING_CODE,
                handleParamValue(productMarketing.getCode()));
            urlStr =
                addFullPrefixUrl(requestData, urlStr)
                    + replaceSpaceAndUnderscore(productMarketing.getName())
                    + "/";
          } else if (param instanceof CatalogCategoryVirtual) {
            CatalogCategoryVirtual category = (CatalogCategoryVirtual) param;
            urlParams.put(
                RequestConstants.URL_PATTERN_CATEGORY_CODE, handleParamValue(category.getCode()));
            urlStr =
                addFullPrefixUrl(requestData, urlStr)
                    + replaceSpaceAndUnderscore(category.getName())
                    + "/";
          } else if (param instanceof CatalogCategoryMaster) {
            CatalogCategoryMaster category = (CatalogCategoryMaster) param;
            urlParams.put(
                RequestConstants.URL_PATTERN_CATEGORY_CODE, handleParamValue(category.getCode()));
            urlStr =
                addFullPrefixUrl(requestData, urlStr)
                    + replaceSpaceAndUnderscore(category.getName())
                    + "/";
          } else if (param instanceof ProductBrand) {
            ProductBrand productBrand = (ProductBrand) param;
            urlParams.put(
                RequestConstants.URL_PATTERN_BRAND_CODE, handleParamValue(productBrand.getCode()));
            urlStr =
                addFullPrefixUrl(requestData, urlStr)
                    + replaceSpaceAndUnderscore(productBrand.getName())
                    + "/";
          } else if (param instanceof CartItem) {
            CartItem cartItem = (CartItem) param;
            urlParams.put(
                RequestConstants.URL_PATTERN_CART_ITEM_CODE,
                handleParamValue(cartItem.getId().toString()));
          } else if (param instanceof Store) {
            Store store = (Store) param;
            urlParams.put(
                RequestConstants.URL_PATTERN_STORE_CODE,
                handleParamValue(store.getCode().toString()));
          } else if (param instanceof Map) {
            getParams = (Map<String, String>) param;
          } else {
            logger.warn("Unknowned url parameter : [{}]", param);
          }
        }
      }

      if (StringUtils.isEmpty(urlStr)) {
        // AD THE DEFAULT PREFIX - DEFAULT PATH IS
        urlStr = buildDefaultPrefix(requestData);
        if (isSEO) {
          urlStr = getFullPrefixUrl(requestData);
        }
      }

      // REMOVE THE / AT EH END BEFORE ADDING THE /**.html segment
      if (urlStr.endsWith("/")) {
        urlStr = urlStr.substring(0, urlStr.length() - 1);
      }

      urlStr = urlStr + urlWithoutWildcard;

    } catch (Exception e) {
      logger.error("Can't build Url!", e);
    }
    return handleUrlParameters(urlStr, urlParams, getParams);
  }