コード例 #1
0
  @Override
  public String ship_items(Item[] items, Addresses address)
      throws UnknownAddressFault, UnknownProductFault, IllegalArgumentException {

    // check if all parameters are valid
    if (items == null || items.length <= 0)
      throw new IllegalArgumentException("No items to ship specified");
    if (address == null) throw new IllegalArgumentException("Provided address may not be null");

    // check if the address is known to the system
    Addresses storedAddress = DataBackend.getInstance().getAddress(address.getId());
    if (storedAddress == null || !storedAddress.equals(address))
      throw new UnknownAddressFault("[ShippingService] ship_items: unknown address");

    UUID ret = UUID.randomUUID();
    String retItems = "[ShippingService] Sending items ";
    for (Item item : items) {
      if (item != null) {
        Product p = item.getProduct();

        // is the stored product in the item valid?
        if (p == null) throw new UnknownProductFault("One of the products to ship is null");

        // check if the product is known to the system
        Product storedProduct = DataBackend.getInstance().getProduct(p.getId());
        if (storedProduct == null || !storedProduct.equals(p))
          throw new UnknownProductFault("Unknown product to ship");
        else
          // everything worked fine so ship the product
          // and add an info to the console
          retItems += "'" + storedProduct.getName() + "', ";
      }
    }

    // remove the last ", "
    retItems = retItems.substring(0, retItems.length() - 2);
    retItems += " to";

    // create log-output on server-side
    System.out.println("[ShippingService] " + new Date(System.currentTimeMillis()));
    System.out.println(retItems);
    System.out.println(
        "[ShippingService] "
            + address.getStreet()
            + " "
            + address.getHouse()
            + ", "
            + address.getZipCode()
            + " "
            + address.getCity());

    new ShippingCallbackHelper(ret.toString());

    return ret.toString();
  }
コード例 #2
0
ファイル: Supplier2.java プロジェクト: RovoMe/University
  @Override
  public BigDecimal order(Product product, int amount) throws UnknownProductFault {
    // check input parameters
    if (product == null) throw new IllegalArgumentException("Product to order is null");
    if (amount < 1)
      throw new IllegalArgumentException("At least one product has to be orderd - amount < 1");

    // check if the product is known to the system
    Product storedProduct = DataBackend.getInstance().getProduct(product.getId());
    if (storedProduct == null || !storedProduct.equals(product))
      throw new UnknownProductFault("Product is not known to the system");

    BigDecimal totalPrice = storedProduct.getSingleUnitPrice().multiply(new BigDecimal(amount));
    System.out.println(
        "[SupplierService][Supplier2] " + new Date(System.currentTimeMillis()).toString());
    System.out.println(
        "[SupplierService][Supplier2] order for "
            + amount
            + " '"
            + storedProduct.getName()
            + "' received");
    System.out.println("[SupplierService][Supplier2] total cost: " + totalPrice);
    return totalPrice;
  }