public static String getCatalogTopCategory(ServletRequest request, String defaultTopCategory) {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    Map<String, Object> requestParameters = UtilHttp.getParameterMap(httpRequest);
    String topCatName = null;
    boolean fromSession = false;

    // first see if a new category was specified as a parameter
    topCatName = (String) requestParameters.get("CATALOG_TOP_CATEGORY");
    // if no parameter, try from session
    if (topCatName == null) {
      topCatName = (String) httpRequest.getSession().getAttribute("CATALOG_TOP_CATEGORY");
      if (topCatName != null) fromSession = true;
    }
    // if nothing else, just use a default top category name
    if (topCatName == null) topCatName = defaultTopCategory;
    if (topCatName == null) topCatName = "CATALOG1";

    if (!fromSession) {
      if (Debug.infoOn())
        Debug.logInfo(
            "[CategoryWorker.getCatalogTopCategory] Setting new top category: " + topCatName,
            module);
      httpRequest.getSession().setAttribute("CATALOG_TOP_CATEGORY", topCatName);
    }
    return topCatName;
  }
  public static void getRelatedCategories(
      ServletRequest request, String attributeName, boolean limitView) {
    Map<String, Object> requestParameters = UtilHttp.getParameterMap((HttpServletRequest) request);
    String requestId = null;

    requestId =
        UtilFormatOut.checkNull(
            (String) requestParameters.get("catalog_id"),
            (String) requestParameters.get("CATALOG_ID"),
            (String) requestParameters.get("category_id"),
            (String) requestParameters.get("CATEGORY_ID"));

    if (requestId.equals("")) return;
    if (Debug.infoOn())
      Debug.logInfo("[CategoryWorker.getRelatedCategories] RequestID: " + requestId, module);
    getRelatedCategories(request, attributeName, requestId, limitView);
  }
Ejemplo n.º 3
0
  /* call run test suite from webtool selenium */
  public static String runTestSuite(HttpServletRequest request, HttpServletResponse response) {
    Map parameters = UtilHttp.getParameterMap(request);
    String para = (String) parameters.get("testSuitePath");
    if (para == null) {
      System.out.println("Error message : Test suite Path  is null");
      return "success";
    }
    if (para.length() == 0) {
      System.out.println("Error message : Test suite Path  is null");
      return "success";
    }
    try {
      URL url = UtilURL.fromResource("seleniumXml.properties");
      if (props == null) {
        props = new Properties();
        initConfig(url);
      }
      SeleniumXml sel = new SeleniumXml();
      File testFile = new File(para.trim());
      if (testFile.exists()) {
        System.err.println(" Argument : " + para.trim());
        System.err.println(" Full absolute path of file : " + testFile.getAbsolutePath());
        System.err.println(" Full canonical path of file : " + testFile.getCanonicalPath());

        sel.testCaseDirectory = sel.getFileDirectory(testFile.getAbsolutePath());
        System.err.println(" testCaseDirectory: " + sel.testCaseDirectory);
        sel.runTest(testFile.getAbsolutePath());
      } else {
        System.err.println("Test File is not exist :" + para.trim());
      }
    } catch (JDOMException jdome) {
      System.out.println(jdome.getMessage());
    } catch (IOException ioe) {
      System.out.println("Error message : " + ioe.getMessage());
    } finally {
      return "success";
    }
  }
 public static void setTrail(ServletRequest request, String currentCategory) {
   Map<String, Object> requestParameters = UtilHttp.getParameterMap((HttpServletRequest) request);
   String previousCategory = (String) requestParameters.get("pcategory");
   setTrail(request, currentCategory, previousCategory);
 }
Ejemplo n.º 5
0
  public static Map<String, Object> payPalCheckoutUpdate(
      DispatchContext dctx, Map<String, Object> context) {
    LocalDispatcher dispatcher = dctx.getDispatcher();
    Delegator delegator = dctx.getDelegator();
    HttpServletRequest request = (HttpServletRequest) context.get("request");
    HttpServletResponse response = (HttpServletResponse) context.get("response");

    Map<String, Object> paramMap = UtilHttp.getParameterMap(request);

    String token = (String) paramMap.get("TOKEN");
    WeakReference<ShoppingCart> weakCart = tokenCartMap.get(new TokenWrapper(token));
    ShoppingCart cart = null;
    if (weakCart != null) {
      cart = weakCart.get();
    }
    if (cart == null) {
      Debug.logError("Could locate the ShoppingCart for token " + token, module);
      return ServiceUtil.returnSuccess();
    }
    // Since most if not all of the shipping estimate codes requires a persisted contactMechId we'll
    // create one and
    // then delete once we're done, now is not the time to worry about updating everything
    String contactMechId = null;
    Map<String, Object> inMap = FastMap.newInstance();
    inMap.put("address1", paramMap.get("SHIPTOSTREET"));
    inMap.put("address2", paramMap.get("SHIPTOSTREET2"));
    inMap.put("city", paramMap.get("SHIPTOCITY"));
    String countryGeoCode = (String) paramMap.get("SHIPTOCOUNTRY");
    String countryGeoId = PayPalServices.getCountryGeoIdFromGeoCode(countryGeoCode, delegator);
    if (countryGeoId == null) {
      return ServiceUtil.returnSuccess();
    }
    inMap.put("countryGeoId", countryGeoId);
    inMap.put(
        "stateProvinceGeoId",
        parseStateProvinceGeoId((String) paramMap.get("SHIPTOSTATE"), countryGeoId, delegator));
    inMap.put("postalCode", paramMap.get("SHIPTOZIP"));

    try {
      GenericValue userLogin =
          EntityQuery.use(delegator)
              .from("UserLogin")
              .where("userLoginId", "system")
              .cache()
              .queryOne();
      inMap.put("userLogin", userLogin);
    } catch (GenericEntityException e) {
      Debug.logError(e, module);
    }
    boolean beganTransaction = false;
    Transaction parentTransaction = null;
    try {
      parentTransaction = TransactionUtil.suspend();
      beganTransaction = TransactionUtil.begin();
    } catch (GenericTransactionException e1) {
      Debug.logError(e1, module);
    }
    try {
      Map<String, Object> outMap = dispatcher.runSync("createPostalAddress", inMap);
      contactMechId = (String) outMap.get("contactMechId");
    } catch (GenericServiceException e) {
      Debug.logError(e.getMessage(), module);
      return ServiceUtil.returnSuccess();
    }
    try {
      TransactionUtil.commit(beganTransaction);
      if (parentTransaction != null) TransactionUtil.resume(parentTransaction);
    } catch (GenericTransactionException e) {
      Debug.logError(e, module);
    }
    // clone the cart so we can modify it temporarily
    CheckOutHelper coh = new CheckOutHelper(dispatcher, delegator, cart);
    String oldShipAddress = cart.getShippingContactMechId();
    coh.setCheckOutShippingAddress(contactMechId);
    ShippingEstimateWrapper estWrapper = new ShippingEstimateWrapper(dispatcher, cart, 0);
    int line = 0;
    NVPEncoder encoder = new NVPEncoder();
    encoder.add("METHOD", "CallbackResponse");

    for (GenericValue shipMethod : estWrapper.getShippingMethods()) {
      BigDecimal estimate = estWrapper.getShippingEstimate(shipMethod);
      // Check that we have a valid estimate (allowing zero value estimates for now)
      if (estimate == null || estimate.compareTo(BigDecimal.ZERO) < 0) {
        continue;
      }
      cart.setAllShipmentMethodTypeId(shipMethod.getString("shipmentMethodTypeId"));
      cart.setAllCarrierPartyId(shipMethod.getString("partyId"));
      try {
        coh.calcAndAddTax();
      } catch (GeneralException e) {
        Debug.logError(e, module);
        continue;
      }
      String estimateLabel =
          shipMethod.getString("partyId") + " - " + shipMethod.getString("description");
      encoder.add("L_SHIPINGPOPTIONLABEL" + line, estimateLabel);
      encoder.add(
          "L_SHIPPINGOPTIONAMOUNT" + line,
          estimate.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
      // Just make this first one default for now
      encoder.add("L_SHIPPINGOPTIONISDEFAULT" + line, line == 0 ? "true" : "false");
      encoder.add(
          "L_TAXAMT" + line,
          cart.getTotalSalesTax().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
      line++;
    }
    String responseMsg = null;
    try {
      responseMsg = encoder.encode();
    } catch (PayPalException e) {
      Debug.logError(e, module);
    }
    if (responseMsg != null) {
      try {
        response.setContentLength(responseMsg.getBytes("UTF-8").length);
      } catch (UnsupportedEncodingException e) {
        Debug.logError(e, module);
      }

      try {
        Writer writer = response.getWriter();
        writer.write(responseMsg);
        writer.close();
      } catch (IOException e) {
        Debug.logError(e, module);
      }
    }

    // Remove the temporary ship address
    try {
      GenericValue postalAddress =
          EntityQuery.use(delegator)
              .from("PostalAddress")
              .where("contactMechId", contactMechId)
              .queryOne();
      postalAddress.remove();
      GenericValue contactMech =
          EntityQuery.use(delegator)
              .from("ContactMech")
              .where("contactMechId", contactMechId)
              .queryOne();
      contactMech.remove();
    } catch (GenericEntityException e) {
      Debug.logError(e, module);
    }
    coh.setCheckOutShippingAddress(oldShipAddress);
    return ServiceUtil.returnSuccess();
  }
  public void render(
      String name,
      String page,
      String info,
      String contentType,
      String encoding,
      HttpServletRequest request,
      HttpServletResponse response)
      throws ViewHandlerException {
    // some containers call filters on EVERY request, even forwarded ones,
    // so let it know that it came from the control servlet

    if (request == null) {
      throw new ViewHandlerException(
          "The HttpServletRequest object was null, how did that happen?");
    }
    if (UtilValidate.isEmpty(page)) {
      throw new ViewHandlerException("View page was null or empty, but must be specified");
    }
    if (UtilValidate.isEmpty(info)) {
      Debug.logInfo(
          "View info string was null or empty, (optionally used to specify an Entity that is mapped to the Entity Engine datasource that the report will use).",
          module);
    }

    // tell the ContextFilter we are forwarding
    request.setAttribute(ContextFilter.FORWARDED_FROM_SERVLET, Boolean.valueOf(true));
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    if (delegator == null) {
      throw new ViewHandlerException("The delegator object was null, how did that happen?");
    }

    try {
      JasperReport report = (JasperReport) jasperReportsCompiledCache.get(page);
      if (report == null) {
        synchronized (this) {
          report = (JasperReport) jasperReportsCompiledCache.get(page);
          if (report == null) {
            InputStream is = context.getResourceAsStream(page);
            report = JasperCompileManager.compileReport(is);
            jasperReportsCompiledCache.put(page, report);
          }
        }
      }

      response.setContentType("application/xls");

      Map parameters = (Map) request.getAttribute("jrParameters");
      if (parameters == null) {
        parameters = UtilHttp.getParameterMap(request);
      }

      JRDataSource jrDataSource = (JRDataSource) request.getAttribute("jrDataSource");
      JasperPrint jp = null;
      if (jrDataSource == null) {
        String datasourceName = delegator.getEntityHelperName(info);
        if (UtilValidate.isNotEmpty(datasourceName)) {
          Debug.logInfo(
              "Filling report with connection from datasource: " + datasourceName, module);
          jp =
              JasperFillManager.fillReport(
                  report, parameters, ConnectionFactory.getConnection(datasourceName));
        } else {
          Debug.logInfo("Filling report with an empty JR datasource", module);
          jp = JasperFillManager.fillReport(report, parameters, new JREmptyDataSource());
        }
      } else {
        Debug.logInfo("Filling report with a passed in jrDataSource", module);
        jp = JasperFillManager.fillReport(report, parameters, jrDataSource);
      }

      if (jp.getPages().size() < 1) {
        throw new ViewHandlerException("Report is Empty (no results?)");
      } else {
        Debug.logInfo("Got report, there are " + jp.getPages().size() + " pages.", module);
      }
      JExcelApiExporter exporter = new JExcelApiExporter();
      exporter.setParameter(JExcelApiExporterParameter.JASPER_PRINT, jp);
      exporter.setParameter(JExcelApiExporterParameter.OUTPUT_STREAM, response.getOutputStream());
      exporter.exportReport();

    } catch (IOException ie) {
      throw new ViewHandlerException("IO Error in report", ie);
    } catch (java.sql.SQLException e) {
      throw new ViewHandlerException("Database error while running report", e);
    } catch (Exception e) {
      throw new ViewHandlerException("Error in report", e);
      // } catch (ServletException se) {
      // throw new ViewHandlerException("Error in region", se.getRootCause());
    }
  }