Esempio n. 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();
  }
  public static void main(String[] args) {
    Locale.setDefault(Locale.ENGLISH);

    Configuration cfg = new Configuration().configure("hibernate.cfg.xml");
    StandardServiceRegistryBuilder sb = new StandardServiceRegistryBuilder();
    sb.applySettings(cfg.getProperties());
    StandardServiceRegistry standardServiceRegistry = sb.build();
    SessionFactory factory = cfg.buildSessionFactory(standardServiceRegistry);
    log.info("Reference to SessionFactory " + factory);

    Session session = null;
    try {
      session = factory.openSession();
      log.info("session opened!");
      session.beginTransaction();

      /*
      Product product = new Product("Automobil",35);
      session.save(product);
      */

      Product product = (Product) session.get(Product.class, 1L);
      System.out.println(product);
      product.setBarcode(15);
      System.out.println(product);
      session.update(product);

      // session.delete(product);
      session.getTransaction().commit();

    } catch (HibernateException e) {
      log.error("Open session failed", e);
      session.getTransaction().rollback();
    } finally {
      if (session != null) {
        session.close();
      }
      if (factory != null) {
        factory.close();
      }
    }
    log.info(session);
  }
Esempio n. 3
0
  @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;
  }
Esempio n. 4
0
 public Product toProduct() {
   Product product = new Product(getName(), getCode());
   product.setId((long) getId());
   return product;
 }
Esempio n. 5
0
 public ProductViewer(Product product) {
   this(product.getId().intValue(), product.getName(), product.getBarcode());
 }