Esempio n. 1
0
  public static Boolean checkProduct(ShopOrder order, Boolean execOrder) {

    boolean result = false;

    execOrder = false;

    OrderService os = new OrderService();

    Stock stock = (Stock) wirc.getByPath("localhost:8180", "Stock", "prdid", order.getProductID());

    System.out.println("O.qty" + order.getQty());
    System.out.println("s.qty" + stock.getQty());

    if (order.getQty() <= stock.getQty()) {
      result = true;
      if (execOrder) {
        stock.setQty(stock.getQty() - order.getQty());
        order.setPrice(os.calculatePriceLocal(order) * order.getQty());
        order.setTotalPrice(order.getPrice().intValue());
        wirc.putObject("localhost:8180", stock, stock.getId());
      }
      order.setStatus("OK");
    } else {
      order.setStatus("FAIL:QTY");
      result = false;
    }

    if (execOrder) {
      Long id = wirc.putObject("localhost:8180", order, null);
      order.setId(id);
    }

    return new Boolean(result);
  }
Esempio 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;
  }
Esempio 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;
  }