예제 #1
0
 /** Return a shopper-visible message detailing why the voucher is invalid. */
 public String getInvalidMessage(SlingHttpServletRequest request) {
   final I18n i18n = new I18n(request);
   for (Page parent = page.getParent(); parent != null; parent = parent.getParent()) {
     if (ResourceUtil.isA(
         parent.getContentResource(), "cq/personalization/components/campaignpage")) {
       long time = parent.timeUntilValid();
       if (time > 0) {
         return i18n.get("Invalid coupon code."); // Don't leak that it might be valid later
       } else if (time < 0) {
         return i18n.get("Coupon expired.");
       }
     }
   }
   return "";
 }
예제 #2
0
  public HtmlResponse performCommand(
      WCMCommandContext ctx,
      SlingHttpServletRequest request,
      SlingHttpServletResponse response,
      PageManager pageManager) {
    try {
      Page master = null;
      String srcPath = request.getParameter(WCMCommand.SRC_PATH_PARAM);
      if (StringUtils.isNotEmpty(srcPath)) {
        if (srcPath.endsWith("/jcr:content")) {
          srcPath = srcPath.substring(0, srcPath.length() - "/jcr:content".length());
        }
        master = pageManager.getPage(srcPath);
      }
      if (master == null) {
        return HtmlStatusResponseHelper.createStatusResponse(
            false, I18n.get(request, "Blueprint {0} not found.", "", srcPath));
      }

      boolean reset = "true".equals(request.getParameter(WCMCommand.FORCE_PARAM));

      String[] targets = request.getParameterValues(WCMCommand.DEST_PATH_PARAM);
      if (targets.length == 0) {
        return HtmlStatusResponseHelper.createStatusResponse(
            false, I18n.get(request, "No targets selected."));
      }

      int successCount = 0;
      int errorCount = 0;
      for (String target : targets) {
        try {
          Page targetPage = pageManager.getContainingPage(target);
          catalogGenerator.rolloutChanges(master, targetPage, reset);
          successCount++;
        } catch (Exception e) {
          log.error("Rollout failed for {}.", target, e);
          errorCount++;
        }
      }

      List<String> messages = new ArrayList<String>();
      messages.add(I18n.get(request, "Rollout Complete.  "));
      if (successCount > 0) {
        messages.add(I18n.get(request, "Rolled out changes to {0} catalogs.", "", successCount));
      }
      if (errorCount > 0) {
        messages.add(I18n.get(request, "Errors encountered in {0} catalogs.", "", errorCount));
      }
      return HtmlStatusResponseHelper.createStatusResponse(
          successCount > 0, messages.toArray(new String[messages.size()]), targets);
    } catch (Exception e) {
      String msg = I18n.get(request, "Error during rollout.");
      log.error(msg, e);
      return HtmlStatusResponseHelper.createStatusResponse(false, msg);
    }
  }