Exemple #1
0
  /**
   * Performs update of the specified item, as defined in the processing definition of the Admin
   * Confirm Web Interaction. It DOES NOT PERFORM updates of the I_RELATED* fields, as prescribed in
   * the clause 2.16.3.3 of the spec (version 1.8). It rather updates these values with randomly
   * selected IDs.
   *
   * @param I_ID id of the item to update
   * @param I_NEW_COST item's new cost
   * @param I_NEW_IMAGE item's new image
   * @param I_NEW_THUMBNAIL item's new thumbnail
   * @return updated item and author info
   */
  public ItemAuthorModel updateItem(
      Integer I_ID,
      Double I_NEW_COST,
      Integer I_NEW_STOCK,
      String I_NEW_IMAGE,
      String I_NEW_THUMBNAIL) {
    ItemAuthorModel model = null;
    Random rand = new Random(System.currentTimeMillis());
    int I_RELATED1, I_RELATED2, I_RELATED3, I_RELATED4, I_RELATED5;
    int i = I_ID.intValue();
    Item item = null;

    // choose I_RELATED* randomly, not as specified in the spec (clause 2.16.3.3)
    do {
      I_RELATED1 = Util.getRandomInt(rand, 1, Constants.NUM_ITEMS);
    } while (I_RELATED1 == i);
    do {
      I_RELATED2 = Util.getRandomInt(rand, 1, Constants.NUM_ITEMS);
    } while (I_RELATED2 == I_RELATED1 || I_RELATED2 == i);
    do {
      I_RELATED3 = Util.getRandomInt(rand, 1, Constants.NUM_ITEMS);
    } while (I_RELATED3 == I_RELATED1 || I_RELATED3 == I_RELATED2 || I_RELATED3 == i);
    do {
      I_RELATED4 = Util.getRandomInt(rand, 1, Constants.NUM_ITEMS);
    } while (I_RELATED4 == I_RELATED1
        || I_RELATED4 == I_RELATED2
        || I_RELATED4 == I_RELATED3
        || I_RELATED4 == i);
    do {
      I_RELATED5 = Util.getRandomInt(rand, 1, Constants.NUM_ITEMS);
    } while (I_RELATED5 == I_RELATED1
        || I_RELATED5 == I_RELATED2
        || I_RELATED5 == I_RELATED3
        || I_RELATED5 == I_RELATED4
        || I_RELATED5 == i);

    try {
      item = itemHome.findByPrimaryKey(I_ID);
      item.setI_COST(I_NEW_COST);
      item.setI_STOCK(I_NEW_STOCK);
      item.setI_IMAGE(I_NEW_IMAGE);
      item.setI_THUMBNAIL(I_NEW_THUMBNAIL);
      item.setI_RELATED1(new Integer(I_RELATED1));
      item.setI_RELATED2(new Integer(I_RELATED2));
      item.setI_RELATED3(new Integer(I_RELATED3));
      item.setI_RELATED4(new Integer(I_RELATED4));
      item.setI_RELATED5(new Integer(I_RELATED5));
      item.setI_PUB_DATE(new Date());
      ItemModel it = item.getItem();
      model = new ItemAuthorModel(it);
      Author author = authorHome.findByPrimaryKey(it.getI_A_ID());
      model.setA_FNAME(author.getA_FNAME());
      model.setA_LNAME(author.getA_LNAME());
    } catch (Exception re) {
      throw new EJBException(re);
    }
    return model;
  }
Exemple #2
0
  /**
   * Returns the last order placed by the customer, by first authenticating him.
   *
   * @param C_UNAME name of the customer
   * @param S_PASSWD password supplied by the customer
   * @return the BigOrderModel object, if successfully authenticated; null otherwise
   */
  public BigOrderModel getLastOrder(String C_UNAME, String C_PASSWD) {
    BigOrderModel bigOrder = null;
    CustomerModel custModel = null;
    try {
      // find Collection of customers with this C_UNAME
      // it should be actually one or none of them
      Collection coll = custHome.findByC_UNAME(C_UNAME);
      if (coll.isEmpty()) return null; // fail, if no such customers

      // get the CustomerModel object
      Customer customer = (Customer) coll.iterator().next();
      custModel = customer.getCustomer();

      // check the password
      if (!custModel.getC_PASSWD().equals(C_PASSWD)) return null; // fail if passwds do not match
    } catch (Exception e) {
      throw new EJBException(e);
    }

    // find the latest order
    Integer O_ID = null;
    Connection con = null;
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    try {
      con = datasource.getConnection();
      String s = "SELECT max(o_id) FROM orders WHERE o_c_id = ?";
      prepStmt = con.prepareStatement(s);
      prepStmt.setInt(1, custModel.getC_ID().intValue());
      rs = prepStmt.executeQuery();

      boolean exist = rs.next();
      if (exist) {
        int i = rs.getInt(1);
        if (rs.wasNull()) {
          O_ID = null;
        } else {
          O_ID = new Integer(i);
        }
      }
    } catch (Exception ex) {
      throw new EJBException(ex);
    } finally {
      try {
        rs.close();
      } catch (Exception e) {
      }
      try {
        prepStmt.close();
      } catch (Exception e) {
      }
      try {
        con.close();
      } catch (Exception e) {
      }
    }

    if (O_ID == null) {
      // no orders from this customer
      // return empty model object, which means that authentication was successfull, but no orders
      // ware found
      return new BigOrderModel();
    }

    OrderModel orderModel = null;
    try {
      orderModel = orderHome.findByPrimaryKey(O_ID).getOrder();
    } catch (Exception e) {
      throw new EJBException(e);
    }

    // create BigOrderModel object and fill it with right order related info
    bigOrder =
        new BigOrderModel(
            O_ID,
            orderModel.getO_C_ID(),
            orderModel.getO_DATE(),
            orderModel.getO_SUB_TOTAL(),
            orderModel.getO_TAX(),
            orderModel.getO_TOTAL(),
            orderModel.getO_SHIP_TYPE(),
            orderModel.getO_SHIP_DATE(),
            orderModel.getO_STATUS());

    // set customer information fields
    bigOrder.setC_FNAME(custModel.getC_FNAME());
    bigOrder.setC_LNAME(custModel.getC_LNAME());
    bigOrder.setC_PHONE(custModel.getC_PHONE());
    bigOrder.setC_EMAIL(custModel.getC_EMAIL());

    try {
      // set billing address related info
      Integer B_O_ID = orderModel.getO_BILL_ADDR_ID();
      AddressModel billAddr = addressHome.findByPrimaryKey(B_O_ID).getAddress();
      bigOrder.setBILL_ADDR(billAddr);
      bigOrder.setBILL_CO_NAME(
          countryHome.findByPrimaryKey(billAddr.getADDR_CO_ID()).getCountry().getCO_NAME());

      // set shipping address related info
      Integer S_O_ID = orderModel.getO_SHIP_ADDR_ID();
      AddressModel shipAddr = addressHome.findByPrimaryKey(S_O_ID).getAddress();
      bigOrder.setSHIP_ADDR(shipAddr);
      bigOrder.setSHIP_CO_NAME(
          countryHome.findByPrimaryKey(shipAddr.getADDR_CO_ID()).getCountry().getCO_NAME());

      // set credit card transaction related info
      Cc_xactModel xact = xactHome.findByPrimaryKey(O_ID).getCc_xact();
      bigOrder.setCX_TYPE(xact.getCX_TYPE());
      bigOrder.setCX_AUTH_ID(xact.getCX_AUTH_ID());

      // set lineItems related info
      Iterator iter = orderLineHome.findByOrderId(O_ID).iterator();
      ArrayList list = new ArrayList();
      while (iter.hasNext()) {
        OrderLineModel olm = ((OrderLine) iter.next()).getOrderLine();
        BigOrderLineModel bigOrderLine =
            new BigOrderLineModel(
                olm.getOL_ID(),
                olm.getOL_O_ID(),
                olm.getOL_I_ID(),
                olm.getOL_QTY(),
                olm.getOL_DISCOUNT(),
                olm.getOL_COMMENTS());
        ItemModel item = itemHome.findByPrimaryKey(olm.getOL_I_ID()).getItem();
        bigOrderLine.setI_TITLE(item.getI_TITLE());
        bigOrderLine.setI_PUBLISHER(item.getI_PUBLISHER());
        bigOrderLine.setI_COST(item.getI_COST());
        list.add(bigOrderLine);
      }
      bigOrder.setLineItems(list);
    } catch (Exception e) {
      throw new EJBException(e);
    }

    return bigOrder;
  }