public String execute() {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();

    try {
      int custId;

      KKAppEng kkAppEng = this.getKKAppEng(request, response);

      custId = this.loggedIn(request, response, kkAppEng, null);

      // Ensure we are using the correct protocol. Redirect if not.
      String redirForward = checkSSL(kkAppEng, request, custId, /* forceSSL */ false);
      if (redirForward != null) {
        setupResponseForSSLRedirect(response, redirForward);
        return null;
      }

      /*
       * Save preferences in managers, cookies and tags
       */
      kkAppEng.getReviewMgr().setPageSize(numRevs);
      setKKCookie(TAG_REVIEW_PAGE_SIZE, Integer.toString(numRevs), request, response, kkAppEng);
      kkAppEng
          .getCustomerTagMgr()
          .insertCustomerTag(TAG_REVIEW_PAGE_SIZE, Integer.toString(numRevs));

      DataDescriptorIf dd = kkAppEng.getReviewMgr().getDataDesc();
      if (dd != null) {
        dd.setLimit(numRevs + 1);
        dd.setOffset(0);
        kkAppEng.getReviewMgr().orderCurrentReviews(dd.getOrderBy(), t);
      }
      kkAppEng.getReviewMgr().setShowTab(true);

      return SUCCESS;

    } catch (Exception e) {
      return super.handleException(request, e);
    }
  }
  @Override
  public void manageCookiesLogin(
      @Nonnull HttpServletRequest request,
      @Nonnull HttpServletResponse response,
      @Nonnull KKAppEng kkAppEng)
      throws HstComponentException {
    if (!kkAppEng.isKkCookieEnabled()) {
      return;
    }

    CustomerIf currentCustomer = kkAppEng.getCustomerMgr().getCurrentCustomer();
    if (currentCustomer != null) {
      setKKCookie(
          CUSTOMER_NAME,
          currentCustomer.getFirstName() + " " + currentCustomer.getLastName(),
          request,
          response,
          kkAppEng);
    }

    try {
      /*
       * Get customer preferences from customer tags. If the tag value exists, then set the
       * preference in the manager and set the cookie.
       */
      String prodPageSizeStr = kkAppEng.getCustomerTagMgr().getCustomerTagValue(TAG_PROD_PAGE_SIZE);
      if (prodPageSizeStr != null && prodPageSizeStr.length() > 0) {
        int prodPageSize = Integer.parseInt(prodPageSizeStr);
        kkAppEng.getProductMgr().setMaxDisplaySearchResults(prodPageSize);
        setKKCookie(TAG_PROD_PAGE_SIZE, prodPageSizeStr, request, response, kkAppEng);
      }
      String orderPageSizeStr =
          kkAppEng.getCustomerTagMgr().getCustomerTagValue(TAG_ORDER_PAGE_SIZE);
      if (orderPageSizeStr != null && orderPageSizeStr.length() > 0) {
        int orderPageSize = Integer.parseInt(orderPageSizeStr);
        kkAppEng.getOrderMgr().setPageSize(orderPageSize);
        setKKCookie(TAG_ORDER_PAGE_SIZE, orderPageSizeStr, request, response, kkAppEng);
      }
      String reviewPageSizeStr =
          kkAppEng.getCustomerTagMgr().getCustomerTagValue(TAG_REVIEW_PAGE_SIZE);
      if (reviewPageSizeStr != null && reviewPageSizeStr.length() > 0) {
        int reviewPageSize = Integer.parseInt(reviewPageSizeStr);
        kkAppEng.getReviewMgr().setPageSize(reviewPageSize);
        setKKCookie(TAG_REVIEW_PAGE_SIZE, reviewPageSizeStr, request, response, kkAppEng);
      }
    } catch (KKAppException e) {
      throw new HstComponentException(e);
    } catch (KKException e) {
      throw new HstComponentException(e);
    }
  }
Esempio n. 3
0
  /**
   * @param mapping The ActionMapping used to select this instance
   * @param form The optional ActionForm bean for this request (if any)
   * @param request The HTTP request we are processing
   * @param response The HTTP response we are creating
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {

    try {
      int custId;

      KKAppEng kkAppEng = this.getKKAppEng(request, response);

      custId = this.loggedIn(request, response, kkAppEng, null);

      // Ensure we are using the correct protocol. Redirect if not.
      ActionForward redirForward = checkSSL(kkAppEng, request, custId, /* forceSSL */ false);
      if (redirForward != null) {
        return redirForward;
      }

      String revId = request.getParameter("revId");
      if (revId == null) {
        return mapping.findForward("Welcome");
      }

      if (log.isDebugEnabled()) {
        log.debug("Review Id from application = " + revId);
      }

      kkAppEng.getReviewMgr().fetchReviewDetails(new Integer(revId).intValue());

      kkAppEng.nav.set(getCatMessage(request, "header.review.details"), request);
      return mapping.findForward("ShowReviewDetails");

    } catch (Exception e) {
      return mapping.findForward(super.handleException(request, e));
    }
  }
  @Override
  @Nullable
  public String manageCookies(
      @Nonnull HttpServletRequest request,
      @Nonnull HttpServletResponse response,
      @Nonnull KKAppEng kkAppEng)
      throws HstComponentException {
    if (!kkAppEng.isKkCookieEnabled()) {
      return null;
    }

    /*
     * The current customer should at this point be a guest customer with a negative customer id
     */
    CustomerIf currentCustomer = kkAppEng.getCustomerMgr().getCurrentCustomer();
    if (currentCustomer == null) {
      log.warn(
          "Current customer is set to null in the manageCookies method. This should never happen");
      return null;
    }

    /*
     * Get the customerUuid from the browser cookie. A new cookie is created if it doesn't exist
     */
    String customerUuid = getCustomerUuidFromBrowserCookie(request, response);

    /*
     * Get the guestCustomerId from the KK database.
     */
    String guestCustomerIdStr = getKKCookie(customerUuid, GUEST_CUSTOMER_ID, kkAppEng);

    if (guestCustomerIdStr == null) {
      /*
       * If it doesn't exist, then we create it
       */
      setKKCookie(
          customerUuid, GUEST_CUSTOMER_ID, Integer.toString(currentCustomer.getId()), kkAppEng);

    } else {
      /*
       * Set the current customer id with the one retrieved from the cookie and fetch any cart
       * items that he may have.
       */
      currentCustomer.setId(Integer.parseInt(guestCustomerIdStr));
      try {
        kkAppEng.getBasketMgr().getBasketItemsPerCustomer();
      } catch (Exception e) {
        throw new HstComponentException(e);
      }

      if (kkAppEng.getWishListMgr().allowWishListWhenNotLoggedIn()) {
        try {
          kkAppEng.getWishListMgr().fetchCustomersWishLists();
        } catch (Exception e) {
          throw new HstComponentException(e);
        }
      }

      // Get the product page size
      String prodPageSizeStr = getKKCookie(customerUuid, TAG_PROD_PAGE_SIZE, kkAppEng);
      if (prodPageSizeStr != null && prodPageSizeStr.length() > 0) {
        try {
          int prodPageSize = Integer.parseInt(prodPageSizeStr);
          kkAppEng.getProductMgr().setMaxDisplaySearchResults(prodPageSize);
        } catch (NumberFormatException e) {
          log.warn(
              "The product page size value stored in the cookie for customer with guest id "
                  + guestCustomerIdStr
                  + " is not a numeric value: "
                  + prodPageSizeStr);
        }
      }

      // Get the order page size
      String orderPageSizeStr = getKKCookie(customerUuid, TAG_ORDER_PAGE_SIZE, kkAppEng);
      if (orderPageSizeStr != null && orderPageSizeStr.length() > 0) {
        try {
          int orderPageSize = Integer.parseInt(orderPageSizeStr);
          kkAppEng.getOrderMgr().setPageSize(orderPageSize);
        } catch (NumberFormatException e) {
          log.warn(
              "The order page size value stored in the cookie for customer with guest id "
                  + guestCustomerIdStr
                  + " is not a numeric value: "
                  + orderPageSizeStr);
        }
      }

      // Get the review page size
      String reviewPageSizeStr = getKKCookie(customerUuid, TAG_REVIEW_PAGE_SIZE, kkAppEng);
      if (reviewPageSizeStr != null && reviewPageSizeStr.length() > 0) {
        try {
          int reviewPageSize = Integer.parseInt(reviewPageSizeStr);
          kkAppEng.getReviewMgr().setPageSize(reviewPageSize);
        } catch (NumberFormatException e) {
          log.warn(
              "The review page size value stored in the cookie for customer with guest id "
                  + guestCustomerIdStr
                  + " is not a numeric value: "
                  + reviewPageSizeStr);
        }
      }
    }

    if (log.isDebugEnabled()) {
      log.debug(
          "GUEST_CUSTOMER_ID cookie value = "
              + getKKCookie(customerUuid, GUEST_CUSTOMER_ID, kkAppEng));
      log.debug(
          "CUSTOMER_NAME cookie value = " + getKKCookie(customerUuid, CUSTOMER_NAME, kkAppEng));
      log.debug(
          "CUSTOMER_LOCALE cookie value = " + getKKCookie(customerUuid, CUSTOMER_LOCALE, kkAppEng));
      log.debug(
          "PROD_PAGE_SIZE cookie value = "
              + getKKCookie(customerUuid, TAG_PROD_PAGE_SIZE, kkAppEng));
      log.debug(
          "ORDER_PAGE_SIZE cookie value = "
              + getKKCookie(customerUuid, TAG_ORDER_PAGE_SIZE, kkAppEng));
      log.debug(
          "REVIEW_PAGE_SIZE cookie value = "
              + getKKCookie(customerUuid, TAG_REVIEW_PAGE_SIZE, kkAppEng));
    }

    return customerUuid;
  }