예제 #1
0
  public void doRentDVD(StaffData staff_data, CustomerData customer_data, DVDData DVD_data) {
    if (staff_data.getID() == 0 || customer_data.getID() == 0 || DVD_data.getID() == 0) {
      setMessage("Enter staff, customer and DVD IDs first");
      return;
    }

    try {
      // populate objects
      staff_data = getStaffManager().findStaff(staff_data.getID());
      customer_data = getCustomerManager().findCustomer(customer_data.getID());
      DVD_data = getDVDManager().findDVD(DVD_data.getID());

      // has customer asked for this DVD??
      RentalData rental =
          getRentalManager().findRental(customer_data.getID(), DVD_data.getID(), null);
      if (rental != null) {
        if (rental.getDispatched() != null && !rental.getDispatched().equals("null")) {
          setMessage("Already dispatched to customer on " + rental.getDispatched());
          return;
        }

        try {

          // need to do begin transaction...
          DVDStoreFactory.getInstance().begin();

          // indicate sent to customer & by whom
          rental.setStaffID(staff_data.getID());
          rental.setDispatched(DVDStoreFactory.getTodayDate());
          getRentalManager().dispatchDVD(rental);

          // indicate number of copies available now reduced by 1 - should change to do on REQUEST
          // !!!

          DVD_data.setNumCopies(DVD_data.getNumCopies() - 1);
          getDVDManager().updateDVD(DVD_data);

          // need to do commit transaction...
          DVDStoreFactory.getInstance().commit();

          setMessage("Rented DVD");

        } catch (Exception e) {
          setMessage("Couldn't rent DVD: exception: " + e);
          try {
            // need to do rollback of transaction...
            DVDStoreFactory.getInstance().rollback();

          } catch (Exception e2) {
            setMessage("*** Couldn't roll back transaction: " + e);
          }
        }
      } else setMessage("This DVD not requested by customer!");
    } catch (Exception e) {
      setMessage("Couldn't check DVD: exception:" + e);
    }
  }
예제 #2
0
  public void doReturnDVD(StaffData staff_data, CustomerData customer_data, DVDData DVD_data) {
    if (staff_data.getID() == 0 || customer_data.getID() == 0 || DVD_data.getID() == 0) {
      setMessage("Enter staff, customer and DVD IDs first");
      return;
    }

    try {
      // populate objects...
      staff_data = getStaffManager().findStaff(staff_data.getID());
      customer_data = getCustomerManager().findCustomer(customer_data.getID());
      DVD_data = getDVDManager().findDVD(DVD_data.getID());

      // has customer rented this DVD?
      RentalData rental_data =
          getRentalManager().findRental(customer_data.getID(), DVD_data.getID(), null);
      if (rental_data == null || !rental_data.getReturned().equals("null"))
        setMessage("This DVD not rented by this customer!");
      else {
        try {
          // begin transaction...
          DVDStoreFactory.getInstance().begin();

          rental_data.setReturned(DVDStoreFactory.getTodayDate());
          getRentalManager().returnDVD(rental_data);
          DVD_data.setNumCopies(DVD_data.getNumCopies() + 1);
          getDVDManager().updateDVD(DVD_data);

          // need to commit transaction...

          DVDStoreFactory.getInstance().commit();

          setMessage("Returned DVD");

        } catch (Exception e) {
          setMessage("Couldn't return DVD: exception " + e);
          try {
            // need to rollback transaction
            DVDStoreFactory.getInstance().rollback();
          } catch (Exception e2) {
            setMessage("Couldn't rollback transaction: exception " + e);
          }
        }
      }
    } catch (Exception e) {
      setMessage("couldn't check DVD record: " + e);
    }
  }
예제 #3
0
  public List<Customer> getCustomersList() {
    try {
      ResultSet rs = executeQuery("SELECT * FROM customers");

      List list = new ArrayList();
      while (rs.next()) {
        CustomerData custData = new CustomerData();
        String id = rs.getString(1);
        for (int i = 0; i < CustomerData.fieldsName.length; i++) {
          String fieldValue = rs.getString(CustomerData.fieldsName[i]);
          custData.updateByFieldName(CustomerData.fieldsName[i], fieldValue);
        }
        Customer cust = new Customer(custData);
        cust.setId(Integer.parseInt(id));
        list.add(cust);
      }

      return list;
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return null;
  }
예제 #4
0
  public void doFindCustomer(CustomerData customer_data) {
    if (customer_data.getID() == 0) {
      setMessage("Enter customer ID");
      customer_data.setID(0);
      return;
    }

    try {
      CustomerData c2 = getCustomerManager().findCustomer(customer_data.getID());
      if (c2 != null) {
        setMessage("Customer found");
        customer_data.setName(c2.getName());
        customer_data.setAddress(c2.getAddress());
      } else {
        setMessage("Can't find that customer record");
      }
    } catch (Exception e) {
      setMessage("Error looking up customer: " + e.toString());
      customer_data.setID(0);
    }
  }
  @Test(dependsOnMethods = "loginTest")
  public void selectCustomerTest() {

    customerData =
        SerializeHelper.deserializeObject(
            CustomerData.class, Constants.CUSTOMER_SERIALIZE_FILENAME);

    if (customerData == null) {
      customerData = DataFactory.generateDefaultCustomer(CustomerType.PROF_ADVERTISER);
      Actions.partnerActions().createCustomer(customerData);
      SerializeHelper.serializeObject(customerData, Constants.CUSTOMER_SERIALIZE_FILENAME);
    }

    Actions.partnerActions().searchPartnerByName(customerData.getCompanyName());
    Actions.partnerActions().openAdvancedBooking(customerData.getCompanyName());
  }