コード例 #1
0
  @RequestMapping(FoUrls.PERSONAL_ORDER_LIST_URL)
  public ModelAndView customerWishList(final HttpServletRequest request, final Model model)
      throws Exception {
    ModelAndViewThemeDevice modelAndView =
        new ModelAndViewThemeDevice(
            getCurrentVelocityPath(request), FoUrls.PERSONAL_ORDER_LIST.getVelocityPage());
    final RequestData requestData = requestUtil.getRequestData(request);
    final Customer customer = requestData.getCustomer();

    final Customer reloadedCustomer =
        customerService.getCustomerById(
            customer.getId(), FetchPlanGraphCustomer.fullCustomerFetchPlan());

    List<OrderPurchase> orderPurchases =
        orderPurchaseService.findOrdersByCustomerId(reloadedCustomer.getId().toString());
    if (orderPurchases != null && orderPurchases.size() > 0) {
      String url = requestUtil.getCurrentRequestUrl(request);

      String sessionKey = "PagedListHolder_Search_List_Product_" + request.getSession().getId();
      String page = request.getParameter(Constants.PAGINATION_PAGE_PARAMETER);
      PagedListHolder<OrderViewBean> orderViewBeanPagedListHolder;

      if (StringUtils.isEmpty(page)) {
        orderViewBeanPagedListHolder =
            initList(request, sessionKey, orderPurchases, new PagedListHolder<OrderViewBean>());
      } else {
        orderViewBeanPagedListHolder =
            (PagedListHolder) request.getSession().getAttribute(sessionKey);
        if (orderViewBeanPagedListHolder == null) {
          orderViewBeanPagedListHolder =
              initList(request, sessionKey, orderPurchases, orderViewBeanPagedListHolder);
        }
        int pageTarget = new Integer(page).intValue() - 1;
        int pageCurrent = orderViewBeanPagedListHolder.getPage();
        if (pageCurrent < pageTarget) {
          for (int i = pageCurrent; i < pageTarget; i++) {
            orderViewBeanPagedListHolder.nextPage();
          }
        } else if (pageCurrent > pageTarget) {
          for (int i = pageTarget; i < pageCurrent; i++) {
            orderViewBeanPagedListHolder.previousPage();
          }
        }
      }
      model.addAttribute(Constants.PAGINATION_PAGE_URL, url);
      model.addAttribute(Constants.PAGINATION_PAGE_PAGED_LIST_HOLDER, orderViewBeanPagedListHolder);
    }

    Object[] params = {customer.getLastname(), customer.getFirstname()};
    overrideDefaultMainContentTitle(
        request, modelAndView, FoUrls.PERSONAL_ORDER_LIST.getKey(), params);

    return modelAndView;
  }
コード例 #2
0
  @RequestMapping(FoUrls.PERSONAL_ORDER_DETAILS_URL)
  public ModelAndView removeFromWishlist(final HttpServletRequest request, final Model model)
      throws Exception {
    ModelAndViewThemeDevice modelAndView =
        new ModelAndViewThemeDevice(
            getCurrentVelocityPath(request), FoUrls.PERSONAL_ORDER_DETAILS.getVelocityPage());
    final RequestData requestData = requestUtil.getRequestData(request);
    final String orderPurchaseId =
        request.getParameter(RequestConstants.REQUEST_PARAMETER_CUSTOMER_ORDER_GUID);
    if (StringUtils.isNotEmpty(orderPurchaseId)) {
      final OrderPurchase orderPurchase = orderPurchaseService.getOrderById(orderPurchaseId);
      if (orderPurchase != null) {
        // SANITY CHECK

        final Customer currentCustomer = requestData.getCustomer();

        // WE RELOAD THE CUSTOMER FOR THE PERSISTANCE PROXY FILTER
        // IT AVOIDS LazyInitializationException: could not initialize proxy - no Session
        final Customer reloadedCustomer =
            customerService.getCustomerByLoginOrEmail(currentCustomer.getLogin());

        List<OrderPurchase> orderPurchases =
            orderPurchaseService.findOrdersByCustomerId(reloadedCustomer.getId().toString());
        if (orderPurchases.contains(orderPurchase)) {
          return modelAndView;
        } else {
          logger.warn(
              "Customer, "
                  + reloadedCustomer.getId()
                  + "/"
                  + reloadedCustomer.getEmail()
                  + ", try to acces to a customer order, "
                  + orderPurchaseId
                  + ", which does not belong");
        }
      }
    }
    final String url = requestUtil.getLastRequestUrl(request);
    return new ModelAndView(new RedirectView(url));
  }