/** Creates request fields for a customer, such as email and postal addresses. */
  private static Map buildCustomerRequest(Delegator delegator, Map context)
      throws GenericEntityException {
    Map request = FastMap.newInstance();
    GenericValue customer = (GenericValue) context.get("billToParty");
    GenericValue address = (GenericValue) context.get("billingAddress");
    GenericValue email = (GenericValue) context.get("billToEmail");

    if (customer != null && "Person".equals(customer.getEntityName())) {
      request.put("x_first_name", customer.get("firstName"));
      request.put("x_last_name", customer.get("lastName"));
    }
    if (customer != null && "PartyGroup".equals(customer.getEntityName())) {
      request.put("x_company", customer.get("groupName"));
    }
    if (address != null) {
      request.put("x_address", address.get("address1"));
      request.put("x_city", address.get("city"));
      request.put("x_zip", address.get("postalCode"));
      GenericValue country = address.getRelatedOneCache("CountryGeo");
      if (country != null) {
        request.put("x_country", country.get("geoCode"));
        if ("USA".equals(country.get("geoId"))) {
          request.put("x_state", address.get("stateProvinceGeoId"));
        }
      }
    }
    if (email != null && UtilValidate.isNotEmpty(email.getString("infoString"))) {
      request.put("x_email", email.get("infoString"));
    }

    return request;
  }
  public static List<GenericValue> getRelatedCategoriesRet(
      Delegator delegator,
      String attributeName,
      String parentId,
      boolean limitView,
      boolean excludeEmpty,
      boolean recursive) {
    List<GenericValue> categories = FastList.newInstance();

    if (Debug.verboseOn())
      Debug.logVerbose("[CategoryWorker.getRelatedCategories] ParentID: " + parentId, module);

    List<GenericValue> rollups = null;

    try {
      rollups =
          delegator.findByAndCache(
              "ProductCategoryRollup",
              UtilMisc.toMap("parentProductCategoryId", parentId),
              UtilMisc.toList("sequenceNum"));
      if (limitView) {
        rollups = EntityUtil.filterByDate(rollups, true);
      }
    } catch (GenericEntityException e) {
      Debug.logWarning(e.getMessage(), module);
    }
    if (rollups != null) {
      // Debug.logInfo("Rollup size: " + rollups.size(), module);
      for (GenericValue parent : rollups) {
        // Debug.logInfo("Adding child of: " + parent.getString("parentProductCategoryId"), module);
        GenericValue cv = null;

        try {
          cv = parent.getRelatedOneCache("CurrentProductCategory");
        } catch (GenericEntityException e) {
          Debug.logWarning(e.getMessage(), module);
        }
        if (cv != null) {
          if (excludeEmpty) {
            if (!isCategoryEmpty(cv)) {
              // Debug.logInfo("Child : " + cv.getString("productCategoryId") + " is not empty.",
              // module);
              categories.add(cv);
              if (recursive) {
                categories.addAll(
                    getRelatedCategoriesRet(
                        delegator,
                        attributeName,
                        cv.getString("productCategoryId"),
                        limitView,
                        excludeEmpty,
                        recursive));
              }
            }
          } else {
            categories.add(cv);
            if (recursive) {
              categories.addAll(
                  getRelatedCategoriesRet(
                      delegator,
                      attributeName,
                      cv.getString("productCategoryId"),
                      limitView,
                      excludeEmpty,
                      recursive));
            }
          }
        }
      }
    }
    return categories;
  }