Ejemplo n.º 1
0
  public List<ShopOrder> priceOrders(List<ShopOrder> allOrders) {

    Marketplace lmp = null;

    System.out.println("priceOrders:allOrders" + allOrders);

    for (ShopOrder odr : allOrders) {

      if (lmp == null)
        lmp =
            (Marketplace)
                wirc.getByID("localhost:8180", "Marketplace", new Long(odr.getMarketIdSrc()));

      Marketplace fmp =
          (Marketplace)
              wirc.getByID("localhost:8180", "Marketplace", new Long(odr.getMarketIdTgt()));

      if (odr.getMarketIdSrc().equals(odr.getMarketIdTgt())) {
        calculatePriceLocal(odr);
        odr.setTotalPrice(odr.getPrice().intValue());
      } else {

        calculatePriceLocal(odr);

        FXRate rt =
            (FXRate)
                wirc.getByPath(
                    "localhost:8180",
                    FXRate.class.getSimpleName(),
                    "convert/" + lmp.getCCY(),
                    fmp.getCCY());

        Product fprd =
            (Product) wirc.getByID(fmp.getURL(), "Product", new Long(odr.getProductID()));

        System.out.println("fprd:" + fprd);
        System.out.println("rate:" + rt);

        double rate = rt.getRate();

        odr.setRate(rate);

        odr.setFrgPrice(new Long((long) (odr.getQty() * rate * fprd.getPrice())));
        odr.setShippingCosts((int) fmp.getShippingCosts());

        odr.setTotalPrice((int) (odr.getFrgPrice() + odr.getShippingCosts()));
      }
    }

    return allOrders;
  }
Ejemplo n.º 2
0
  public List<ShopOrder> getCompoundOrders(
      ShopOrder localOrder, int localQty, List<ShopOrder> partialOrders) {

    System.out.println("getCompoundOrders");

    List<Marketplace> marketplaces = wirc.getAll("localhost:8180", "Marketplace");

    System.out.println("getCompoundOrders:marketlaces" + marketplaces);

    int itemsToOrder = localOrder.getQty() - localQty;

    for (Marketplace mp : marketplaces) {

      if (localOrder.getMarketIdTgt().equals((mp.getId().toString()))) continue;

      Stock foreigenStock =
          (Stock) wirc.getByPath(mp.getURL(), "Stock", "prdid", localOrder.getProductID());

      // ---------------------------------------
      if (foreigenStock == null) continue;
      // ---------------------------------------

      int items4ThisOrder =
          (itemsToOrder > foreigenStock.getQty()) ? foreigenStock.getQty() : itemsToOrder;

      if (items4ThisOrder > 0) {

        ShopOrder po = new ShopOrder();

        po.setMarketIdSrc(localOrder.getMarketIdSrc());
        po.setMarketIdTgt(mp.getId().toString());
        po.setProductID(localOrder.getProductID());
        po.setQty(items4ThisOrder);
        po.setUser(localOrder.getUser());
        po.setUserEmail(localOrder.getUserEmail());
        po.setBusinessKey(localOrder.getBusinessKey());

        partialOrders.add(po);

        itemsToOrder -= po.getQty();

        System.out.println("partialOrder:" + po);
      }
    }

    if (itemsToOrder > 0) {
      System.out.println("getCompoundOrders:Not enough items:" + itemsToOrder);
      return null;
    }

    priceOrders(partialOrders);

    return partialOrders;
  }
Ejemplo n.º 3
0
  public static List<ShopOrder> assembleOffer(ShopOrder lo) {

    System.out.println("assembleOffer:" + lo);

    OrderService os = new OrderService();

    Stock ls = (Stock) wirc.getByPath("localhost:8180", "Stock", "prdid", lo.getProductID());
    Product lp = (Product) wirc.getByID("localhost:8180", "Product", new Long(lo.getProductID()));

    List<ShopOrder> folist = new ArrayList<ShopOrder>();

    System.out.println("assembleOffer:folist:" + folist);

    int itemsLocal = 0;

    if (ls != null && ls.getQty() > 0) {

      itemsLocal = (lo.getQty() > ls.getQty()) ? ls.getQty() : lo.getQty();

      ShopOrder nol = new ShopOrder();

      nol.setProductID(lo.getProductID());
      nol.setMarketIdSrc(lo.getMarketIdSrc());
      nol.setMarketIdTgt(lo.getMarketIdSrc()); // eq.
      nol.setQty(itemsLocal);
      nol.setPrice(lp.getPrice() * itemsLocal);
      nol.setFrgPrice((long) 0);
      nol.setRate(1);
      nol.setUser(lo.getUser());
      nol.setUserEmail(lo.getUserEmail());
      nol.setBusinessKey(lo.getBusinessKey());

      System.out.println("LocalpartialOrder:" + nol);

      folist.add(nol);

      System.out.println("assembleOffer:folist:nol:" + folist);
    }

    System.out.println("assembleOffer:folist:getCompoundOrders:" + folist);
    folist = os.getCompoundOrders(lo, itemsLocal, folist);

    System.out.println("assembleOffer:folist:getCompoundOrders:" + folist);

    return folist;
  }