Ejemplo n.º 1
0
  /**
   * Add a CPI (CustomerProductInstance) value into the CustomerCache
   *
   * @param custId The customer ID to add the product to
   * @param service The service of the product
   * @param subscription The subscription ID
   * @param prodID The product identifier
   * @param validFrom The start of the product validity
   * @param validTo The end of the product validity
   * @param orderId The JBilling order ID
   * @param orderLineId The JBilling order line ID
   * @param quantity The order line quantity
   */
  public void addCPI(
      int custId,
      String service,
      String subscription,
      String prodID,
      long validFrom,
      long validTo,
      int orderId,
      int orderLineId,
      int quantity) {
    CustInfo tmpCustInfo;
    CustProductInfo tmpCPI;

    // See if we already have ID for this customer
    if (custIDCache.containsKey(custId)) {
      // Create the new entry for the customer ID
      tmpCustInfo = custIDCache.get(custId);
      tmpCPI = new CustProductInfo();
      tmpCPI.Service = service;
      tmpCPI.Subscription = subscription;
      tmpCPI.ProductID = prodID;
      tmpCPI.UTCValidFrom = validFrom;
      tmpCPI.UTCValidTo = validTo - 1; // exclude the last second
      tmpCPI.OrderId = orderId;
      tmpCPI.OrderLineId = orderLineId;
      tmpCPI.Quantity = quantity;
      tmpCustInfo.CPI.add(tmpCustInfo.productCount, tmpCPI);
      tmpCustInfo.productCount++;
    } else {
      // Otherwise write an error and ignore it
      OpenRate.getOpenRateFrameworkLog()
          .error("Customer ID <" + custId + "> not found. Add CPI failed.");
    }
  }
Ejemplo n.º 2
0
  /**
   * Get the products that are attached to the customer account, using the alias to locate the
   * account
   *
   * @param custID The customer ID we want to retireve for
   * @param service The service
   * @param subscription The subscription to get products for
   * @param CDRDate The date to retrieve the products for
   * @return The product list
   */
  public ProductList getProducts(int custID, String service, String subscription, long CDRDate) {
    ProductList tmpProductList;
    CustInfo tmpCustInfo;
    CustProductInfo tmpCPI;
    boolean firstProduct = true;

    // Prepare the result
    tmpProductList = new ProductList();

    // Get the product information
    tmpCustInfo = custIDCache.get(custID);

    // See if the CDR is within the period of validity
    if (tmpCustInfo != null) {
      if (tmpCustInfo.UTCValidFrom <= CDRDate) {
        if (tmpCustInfo.UTCValidTo > CDRDate) {
          // We have validity, get back the product list

          for (int i = 0; i < tmpCustInfo.productCount; i++) {
            tmpCPI = tmpCustInfo.CPI.get(i);
            if ((tmpCPI.Service.equals(service)) & (tmpCPI.Subscription.equals(subscription))) {
              if (tmpCPI.UTCValidFrom <= CDRDate) {
                if (tmpCPI.UTCValidTo > CDRDate) {
                  if (firstProduct) {
                    tmpProductList.addProduct(
                        0,
                        tmpCPI.ProductID,
                        null,
                        tmpCPI.Service,
                        tmpCPI.UTCValidFrom,
                        tmpCPI.UTCValidTo,
                        tmpCPI.Quantity);
                    firstProduct = false;
                  } else {
                    tmpProductList.addProduct(
                        0,
                        tmpCPI.ProductID,
                        null,
                        tmpCPI.Service,
                        tmpCPI.UTCValidFrom,
                        tmpCPI.UTCValidTo,
                        tmpCPI.Quantity);
                  }
                }
              }
            }
          }
        }
        tmpProductList.setBalanceGroup(tmpCustInfo.balanceGroup);
        return tmpProductList;
      }
    }

    return null;
  }