private void getAutoFieldsServiceTag(Element element, Set<String> fieldNames)
      throws GenericServiceException {
    String serviceName = UtilFormatOut.checkNull(element.getAttribute("service-name"));
    String defaultFieldType = UtilFormatOut.checkNull(element.getAttribute("default-field-type"));
    if (UtilValidate.isNotEmpty(serviceName) && (!("hidden".equals(defaultFieldType)))) {
      ModelService modelService = dispatchContext.getModelService(serviceName);
      List<ModelParam> modelParams = modelService.getInModelParamList();
      Iterator<ModelParam> modelParamIter = modelParams.iterator();
      while (modelParamIter.hasNext()) {
        ModelParam modelParam = modelParamIter.next();
        // skip auto params that the service engine populates...
        if ("userLogin".equals(modelParam.name)
            || "locale".equals(modelParam.name)
            || "timeZone".equals(modelParam.name)) {
          continue;
        }
        if (modelParam.formDisplay) {
          if (UtilValidate.isNotEmpty(modelParam.entityName)
              && UtilValidate.isNotEmpty(modelParam.fieldName)) {
            ModelEntity modelEntity;
            modelEntity = delegator.getModelEntity(modelParam.entityName);

            if (modelEntity != null) {
              ModelField modelField = modelEntity.getField(modelParam.fieldName);

              if (modelField != null) {
                fieldNames.add(modelField.getName());
              }
            }
          }
        }
      }
    }
  }
 private void getWebappTag(Element element, String filePath) {
   String title = UtilFormatOut.checkNull(element.getAttribute("title"));
   String appBarDisplay = UtilFormatOut.checkNull(element.getAttribute("app-bar-display"));
   // title labels
   if (UtilValidate.isNotEmpty(title)
       && UtilValidate.isNotEmpty(appBarDisplay)
       && "true".equalsIgnoreCase(appBarDisplay)) {
     setLabelReference(title, filePath);
   }
 }
 private void getAutoFieldsEntityTag(Element element, Set<String> fieldNames) {
   String entityName = UtilFormatOut.checkNull(element.getAttribute("entity-name"));
   String defaultFieldType = UtilFormatOut.checkNull(element.getAttribute("default-field-type"));
   if (UtilValidate.isNotEmpty(entityName)
       && UtilValidate.isNotEmpty(defaultFieldType)
       && (!("hidden".equals(defaultFieldType)))) {
     ModelEntity entity = delegator.getModelEntity(entityName);
     for (Iterator<ModelField> f = entity.getFieldsIterator(); f.hasNext(); ) {
       ModelField field = f.next();
       fieldNames.add(field.getName());
     }
   }
 }
Exemple #4
0
 public static String formatPartyNameObject(GenericValue partyValue, boolean lastNameFirst) {
   if (partyValue == null) {
     return "";
   }
   StringBuilder result = new StringBuilder();
   ModelEntity modelEntity = partyValue.getModelEntity();
   if (modelEntity.isField("firstName")
       && modelEntity.isField("middleName")
       && modelEntity.isField("lastName")) {
     if (lastNameFirst) {
       if (UtilFormatOut.checkNull(partyValue.getString("lastName")) != null) {
         result.append(UtilFormatOut.checkNull(partyValue.getString("lastName")));
         if (partyValue.getString("firstName") != null) {
           result.append(", ");
         }
       }
       result.append(UtilFormatOut.checkNull(partyValue.getString("firstName")));
     } else {
       result.append(UtilFormatOut.ifNotEmpty(partyValue.getString("firstName"), "", " "));
       result.append(UtilFormatOut.ifNotEmpty(partyValue.getString("middleName"), "", " "));
       result.append(UtilFormatOut.checkNull(partyValue.getString("lastName")));
     }
   }
   if (modelEntity.isField("groupName") && partyValue.get("groupName") != null) {
     result.append(partyValue.getString("groupName"));
   }
   return result.toString();
 }
Exemple #5
0
  /**
   * Generate a sequenced club id using the prefix passed and a sequence value + check digit
   *
   * @param delegator used to obtain a sequenced value
   * @param prefix prefix inserted at the beginning of the ID
   * @param length total length of the ID including prefix and check digit
   * @return Sequenced Club ID string with a length as defined starting with the prefix defined
   */
  public static String createClubId(Delegator delegator, String prefix, int length) {
    final String clubSeqName = "PartyClubSeq";
    String clubId = prefix != null ? prefix : "";

    // generate the sequenced number and pad
    Long seq = delegator.getNextSeqIdLong(clubSeqName);
    clubId =
        clubId + UtilFormatOut.formatPaddedNumber(seq.longValue(), (length - clubId.length() - 1));

    // get the check digit
    int check = UtilValidate.getLuhnCheckDigit(clubId);
    clubId = clubId + Integer.toString(check);

    return clubId;
  }
  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);
  }
 @Override
 protected Object get(Map<String, ? extends Object> context, TimeZone timeZone, Locale locale) {
   try {
     Object obj = UelUtil.evaluate(context, new String(this.valueStr));
     if (obj != null) {
       String currencyCode = this.codeExpr.expandString(context, timeZone, locale);
       return UtilFormatOut.formatCurrency(new BigDecimal(obj.toString()), currencyCode, locale);
     }
   } catch (PropertyNotFoundException e) {
     if (Debug.verboseOn()) {
       Debug.logVerbose("Error evaluating expression: " + e, module);
     }
   } catch (Exception e) {
     Debug.logError("Error evaluating expression: " + e, module);
   }
   return null;
 }
  protected void applyLineToPackage(
      String shipmentId, GenericValue userLogin, LocalDispatcher dispatcher, int shipPackSeqId)
      throws GeneralException {
    String shipmentPackageSeqId = UtilFormatOut.formatPaddedNumber(shipPackSeqId, 5);

    Map<String, Object> packageMap = new HashMap<String, Object>();
    packageMap.put("shipmentId", shipmentId);
    packageMap.put("shipmentItemSeqId", this.getShipmentItemSeqId());
    // quanity given, by defult one because it is a required field
    packageMap.put("quantity", BigDecimal.ONE);
    packageMap.put("shipmentPackageSeqId", shipmentPackageSeqId);
    packageMap.put("userLogin", userLogin);
    Map<String, Object> packageResp = dispatcher.runSync("addShipmentContentToPackage", packageMap);

    if (ServiceUtil.isError(packageResp)) {
      throw new GeneralException(ServiceUtil.getErrorMessage(packageResp));
    }
  }
  public void renderSubContentBody(
      Appendable writer, Map<String, Object> context, ModelScreenWidget.SubContent content)
      throws IOException {
    Locale locale = UtilMisc.ensureLocale(context.get("locale"));
    String mimeTypeId = "text/html";
    String expandedContentId = content.getContentId(context);
    String expandedMapKey = content.getMapKey(context);
    String renderedContent = "";
    LocalDispatcher dispatcher = (LocalDispatcher) context.get("dispatcher");
    Delegator delegator = (Delegator) context.get("delegator");

    // create a new map for the content rendering; so our current context does not get overwritten!
    Map<String, Object> contentContext = FastMap.newInstance();
    contentContext.putAll(context);

    try {
      if (WidgetContentWorker.contentWorker != null) {
        renderedContent =
            WidgetContentWorker.contentWorker.renderSubContentAsTextExt(
                dispatcher,
                delegator,
                expandedContentId,
                expandedMapKey,
                contentContext,
                locale,
                mimeTypeId,
                true);
        // Debug.logInfo("renderedContent=" + renderedContent, module);
      } else {
        Debug.logError(
            "Not rendering content, WidgetContentWorker.contentWorker not found.", module);
      }
      if (UtilValidate.isEmpty(renderedContent)) {
        String editRequest = content.getEditRequest(context);
        if (UtilValidate.isNotEmpty(editRequest)) {
          if (WidgetContentWorker.contentWorker != null) {
            WidgetContentWorker.contentWorker.renderContentAsTextExt(
                dispatcher,
                delegator,
                "NOCONTENTFOUND",
                writer,
                contentContext,
                locale,
                mimeTypeId,
                true);
          } else {
            Debug.logError(
                "Not rendering content, WidgetContentWorker.contentWorker not found.", module);
          }
        }
      } else {
        if (content.xmlEscape()) {
          renderedContent = UtilFormatOut.encodeXmlValue(renderedContent);
        }

        writer.append(renderedContent);
      }

    } catch (GeneralException e) {
      String errMsg =
          "Error rendering included content with id [" + expandedContentId + "] : " + e.toString();
      Debug.logError(e, errMsg, module);
      // throw new RuntimeException(errMsg);
    } catch (IOException e2) {
      String errMsg =
          "Error rendering included content with id [" + expandedContentId + "] : " + e2.toString();
      Debug.logError(e2, errMsg, module);
      // throw new RuntimeException(errMsg);
    }
  }
  public void renderContentBody(
      Appendable writer, Map<String, Object> context, ModelScreenWidget.Content content)
      throws IOException {
    Locale locale = UtilMisc.ensureLocale(context.get("locale"));
    // Boolean nullThruDatesOnly = Boolean.valueOf(false);
    String mimeTypeId = "text/html";
    String expandedContentId = content.getContentId(context);
    String expandedDataResourceId = content.getDataResourceId(context);
    String renderedContent = null;
    LocalDispatcher dispatcher = (LocalDispatcher) context.get("dispatcher");
    Delegator delegator = (Delegator) context.get("delegator");

    // make a new map for content rendering; so our current map does not get clobbered
    Map<String, Object> contentContext = FastMap.newInstance();
    contentContext.putAll(context);
    String dataResourceId = (String) contentContext.get("dataResourceId");
    if (Debug.verboseOn()) Debug.logVerbose("expandedContentId:" + expandedContentId, module);

    try {
      if (UtilValidate.isNotEmpty(dataResourceId)) {
        if (WidgetDataResourceWorker.dataresourceWorker != null) {
          renderedContent =
              WidgetDataResourceWorker.dataresourceWorker.renderDataResourceAsTextExt(
                  delegator, dataResourceId, contentContext, locale, mimeTypeId, false);
        } else {
          Debug.logError(
              "Not rendering content, WidgetDataResourceWorker.dataresourceWorker not found.",
              module);
        }
      } else if (UtilValidate.isNotEmpty(expandedContentId)) {
        if (WidgetContentWorker.contentWorker != null) {
          renderedContent =
              WidgetContentWorker.contentWorker.renderContentAsTextExt(
                  dispatcher,
                  delegator,
                  expandedContentId,
                  contentContext,
                  locale,
                  mimeTypeId,
                  true);
        } else {
          Debug.logError(
              "Not rendering content, WidgetContentWorker.contentWorker not found.", module);
        }
      } else if (UtilValidate.isNotEmpty(expandedDataResourceId)) {
        if (WidgetDataResourceWorker.dataresourceWorker != null) {
          renderedContent =
              WidgetDataResourceWorker.dataresourceWorker.renderDataResourceAsTextExt(
                  delegator, expandedDataResourceId, contentContext, locale, mimeTypeId, false);
        } else {
          Debug.logError(
              "Not rendering content, WidgetDataResourceWorker.dataresourceWorker not found.",
              module);
        }
      }
      if (UtilValidate.isEmpty(renderedContent)) {
        String editRequest = content.getEditRequest(context);
        if (UtilValidate.isNotEmpty(editRequest)) {
          if (WidgetContentWorker.contentWorker != null) {
            WidgetContentWorker.contentWorker.renderContentAsTextExt(
                dispatcher,
                delegator,
                "NOCONTENTFOUND",
                writer,
                contentContext,
                locale,
                mimeTypeId,
                true);
          } else {
            Debug.logError(
                "Not rendering content, WidgetContentWorker.contentWorker not found.", module);
          }
        }
      } else {
        if (content.xmlEscape()) {
          renderedContent = UtilFormatOut.encodeXmlValue(renderedContent);
        }

        writer.append(renderedContent);
      }

    } catch (GeneralException e) {
      String errMsg =
          "Error rendering included content with id [" + expandedContentId + "] : " + e.toString();
      Debug.logError(e, errMsg, module);
      // throw new RuntimeException(errMsg);
    } catch (IOException e2) {
      String errMsg =
          "Error rendering included content with id [" + expandedContentId + "] : " + e2.toString();
      Debug.logError(e2, errMsg, module);
      // throw new RuntimeException(errMsg);
    }
  }
Exemple #11
0
  public static Map<String, Object> getPaymentMethodAndRelated(
      ServletRequest request, String partyId) {
    Delegator delegator = (Delegator) request.getAttribute("delegator");
    Map<String, Object> results = FastMap.newInstance();

    Boolean tryEntity = true;
    if (request.getAttribute("_ERROR_MESSAGE_") != null) tryEntity = false;

    String donePage = request.getParameter("DONE_PAGE");
    if (donePage == null || donePage.length() <= 0) donePage = "viewprofile";
    results.put("donePage", donePage);

    String paymentMethodId = request.getParameter("paymentMethodId");

    // check for a create
    if (request.getAttribute("paymentMethodId") != null) {
      paymentMethodId = (String) request.getAttribute("paymentMethodId");
    }

    results.put("paymentMethodId", paymentMethodId);

    GenericValue paymentMethod = null;
    GenericValue creditCard = null;
    GenericValue giftCard = null;
    GenericValue eftAccount = null;

    if (UtilValidate.isNotEmpty(paymentMethodId)) {
      try {
        paymentMethod =
            delegator.findByPrimaryKey(
                "PaymentMethod", UtilMisc.toMap("paymentMethodId", paymentMethodId));
        creditCard =
            delegator.findByPrimaryKey(
                "CreditCard", UtilMisc.toMap("paymentMethodId", paymentMethodId));
        giftCard =
            delegator.findByPrimaryKey(
                "GiftCard", UtilMisc.toMap("paymentMethodId", paymentMethodId));
        eftAccount =
            delegator.findByPrimaryKey(
                "EftAccount", UtilMisc.toMap("paymentMethodId", paymentMethodId));
      } catch (GenericEntityException e) {
        Debug.logWarning(e, module);
      }
    }
    if (paymentMethod != null) {
      results.put("paymentMethod", paymentMethod);
    } else {
      tryEntity = false;
    }

    if (creditCard != null) {
      results.put("creditCard", creditCard);
    }
    if (giftCard != null) {
      results.put("giftCard", giftCard);
    }
    if (eftAccount != null) {
      results.put("eftAccount", eftAccount);
    }

    String curContactMechId = null;

    if (creditCard != null) {
      curContactMechId =
          UtilFormatOut.checkNull(
              tryEntity
                  ? creditCard.getString("contactMechId")
                  : request.getParameter("contactMechId"));
    } else if (giftCard != null) {
      curContactMechId =
          UtilFormatOut.checkNull(
              tryEntity
                  ? giftCard.getString("contactMechId")
                  : request.getParameter("contactMechId"));
    } else if (eftAccount != null) {
      curContactMechId =
          UtilFormatOut.checkNull(
              tryEntity
                  ? eftAccount.getString("contactMechId")
                  : request.getParameter("contactMechId"));
    }
    if (curContactMechId != null) {
      results.put("curContactMechId", curContactMechId);
    }

    results.put("tryEntity", tryEntity);

    return results;
  }