Exemplo n.º 1
0
  /** 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;
  }
Exemplo n.º 2
0
  public static String getPartyName(GenericValue partyObject, boolean lastNameFirst) {
    if (partyObject == null) {
      return "";
    }
    if ("PartyGroup".equals(partyObject.getEntityName())
        || "Person".equals(partyObject.getEntityName())) {
      return formatPartyNameObject(partyObject, lastNameFirst);
    } else {
      String partyId = null;
      try {
        partyId = partyObject.getString("partyId");
      } catch (IllegalArgumentException e) {
        Debug.logError(e, "Party object does not contain a party ID", module);
      }

      if (partyId == null) {
        Debug.logWarning(
            "No party ID found; cannot get name based on entity: " + partyObject.getEntityName(),
            module);
        return "";
      } else {
        return getPartyName(partyObject.getDelegator(), partyId, lastNameFirst);
      }
    }
  }
Exemplo n.º 3
0
  public static List<GenericValue> findParties(
      Delegator delegator, String idToFind, String partyIdentificationTypeId)
      throws GenericEntityException {
    List<GenericValue> partiesByIds =
        findPartiesById(delegator, idToFind, partyIdentificationTypeId);
    List<GenericValue> parties = null;
    if (UtilValidate.isNotEmpty(partiesByIds)) {
      for (GenericValue party : partiesByIds) {
        GenericValue partyToAdd = party;
        // retreive party GV if the actual genericValue came from viewEntity
        if (!"Party".equals(party.getEntityName())) {
          partyToAdd =
              delegator.findByPrimaryKeyCache(
                  "Party", UtilMisc.toMap("partyId", party.get("partyId")));
        }

        if (UtilValidate.isEmpty(parties)) {
          parties = UtilMisc.toList(partyToAdd);
        } else {
          parties.add(partyToAdd);
        }
      }
    }
    return parties;
  }
  /**
   * Creates a PartyRelationshipType
   *
   * @param ctx The DispatchContext that this service is operating in
   * @param context Map containing the input parameters
   * @return Map with the result of the service, the output parameters
   */
  public static Map<String, Object> createPartyRelationshipType(
      DispatchContext ctx, Map<String, ? extends Object> context) {
    Map<String, Object> result = FastMap.newInstance();
    Delegator delegator = ctx.getDelegator();
    Security security = ctx.getSecurity();
    GenericValue userLogin = (GenericValue) context.get("userLogin");

    ServiceUtil.getPartyIdCheckSecurity(
        userLogin, security, context, result, "PARTYMGR", "_CREATE");

    if (result.size() > 0) return result;

    GenericValue partyRelationshipType =
        delegator.makeValue(
            "PartyRelationshipType",
            UtilMisc.toMap("partyRelationshipTypeId", context.get("partyRelationshipTypeId")));

    partyRelationshipType.set("parentTypeId", context.get("parentTypeId"), true);
    partyRelationshipType.set("hasTable", context.get("hasTable"), true);
    partyRelationshipType.set("roleTypeIdValidFrom", context.get("roleTypeIdValidFrom"), true);
    partyRelationshipType.set("roleTypeIdValidTo", context.get("roleTypeIdValidTo"), false);
    partyRelationshipType.set("description", context.get("description"), true);
    partyRelationshipType.set("partyRelationshipName", context.get("partyRelationshipName"), true);

    try {
      if (delegator.findOne(
              partyRelationshipType.getEntityName(), partyRelationshipType.getPrimaryKey(), false)
          != null) {
        return ServiceUtil.returnError("Could not create party relationship type: already exists");
      }
    } catch (GenericEntityException e) {
      Debug.logWarning(e, module);
      return ServiceUtil.returnError(
          "Could not create party relationship type (read failure): " + e.getMessage());
    }

    try {
      partyRelationshipType.create();
    } catch (GenericEntityException e) {
      Debug.logWarning(e.getMessage(), module);
      return ServiceUtil.returnError(
          "Could not create party relationship type (write failure): " + e.getMessage());
    }

    result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS);
    return result;
  }
Exemplo n.º 5
0
  public static void addWeightedKeywordSourceString(
      GenericValue value, String fieldName, List<String> strings) {
    if (value.getString(fieldName) != null) {
      int weight = 1;

      try {
        weight =
            Integer.parseInt(
                UtilProperties.getPropertyValue(
                    "prodsearch", "index.weight." + value.getEntityName() + "." + fieldName, "1"));
      } catch (Exception e) {
        Debug.logWarning("Could not parse weight number: " + e.toString(), module);
      }

      for (int i = 0; i < weight; i++) {
        strings.add(value.getString(fieldName));
      }
    }
  }
Exemplo n.º 6
0
  public static Map<String, Object> assembleCrmsfaOrderFormMergeContext(
      Delegator delegator, String orderId) {
    Map<String, Object> templateContext = new HashMap<String, Object>();
    if (UtilValidate.isNotEmpty(orderId)) {
      try {
        OrderReadHelper orh = new OrderReadHelper(delegator, orderId);
        templateContext.put("orderId", orderId);
        templateContext.put("externalOrderId", orh.getOrderHeader().get("externalId"));
        templateContext.put("orderDate", orh.getOrderHeader().getTimestamp("orderDate"));

        GenericValue billingParty = orh.getBillToParty();
        if (UtilValidate.isNotEmpty(billingParty)) {
          if ("Person".equalsIgnoreCase(billingParty.getEntityName())) {
            templateContext.put("orderBillingFirstName", billingParty.get("firstName"));
            templateContext.put("orderBillingLastName", billingParty.get("lastName"));
          }
          templateContext.put("orderPartyId", billingParty.get("partyId"));
          templateContext.put(
              "orderBillingFullName",
              org.ofbiz.party.party.PartyHelper.getPartyName(billingParty, false));
        }

        templateContext.put("orderSubtotal", orh.getOrderItemsSubTotal());
        templateContext.put("orderTaxTotal", orh.getTaxTotal());
        templateContext.put("orderShippingTotal", orh.getShippingTotal());
        templateContext.put("orderGrandTotal", orh.getOrderGrandTotal());
        templateContext.put(
            "orderPaymentTotal",
            orh.getOrderGrandTotal().subtract(UtilOrder.getOrderOpenAmount(orh)));

        GenericValue shippingParty = orh.getShipToParty();
        if (UtilValidate.isNotEmpty(shippingParty)) {
          if ("Person".equalsIgnoreCase(shippingParty.getEntityName())) {
            templateContext.put("orderShippingFirstName", shippingParty.get("firstName"));
            templateContext.put("orderShippingLastName", shippingParty.get("lastName"));
          } else {
            templateContext.put("orderShippingCompanyName", shippingParty.get("groupName"));
          }
          templateContext.put(
              "orderShippingFullName",
              org.ofbiz.party.party.PartyHelper.getPartyName(shippingParty, false));
        }

        List<GenericValue> orderItemVals = orh.getOrderItems();
        List<Map<String, Object>> orderItems = new ArrayList<Map<String, Object>>();
        for (GenericValue orderItemVal : orderItemVals) {
          Map<String, Object> orderItem = orderItemVal.getAllFields();
          GenericValue product = orderItemVal.getRelatedOne("Product");
          if (UtilValidate.isEmpty(product)) {
            continue;
          }
          for (String fieldName : (Set<String>) product.keySet()) {
            orderItem.put(fieldName, product.get(fieldName));
          }
          orderItems.add(orderItem);
        }
        templateContext.put("orderItems", orderItems);

      } catch (GenericEntityException e) {
        Debug.logError(e, MODULE);
      }
    }
    return templateContext;
  }
 /**
  * Creates a new RecurrenceRule object from a RecurrenceInfo entity.
  *
  * @param rule GenericValue object defining this rule.
  */
 public RecurrenceRule(GenericValue rule) throws RecurrenceRuleException {
   this.rule = rule;
   if (!rule.getEntityName().equals("RecurrenceRule"))
     throw new RecurrenceRuleException("Invalid RecurrenceRule Value object.");
   init();
 }