Esempio n. 1
0
  @Override
  public Result execute(InteractionContext ctx) throws InteractionException {
    assert (ctx != null);
    // retrieve from a database, etc.
    String id = ctx.getId();
    Customer customer = daoHibernate.getCustomer(id);
    if (customer != null) {
      // Convert Customer object into Entity object
      EntityProperties addressFields = new EntityProperties();
      addressFields.setProperty(
          new EntityProperty("postcode", customer.getAddress().getPostcode()));
      addressFields.setProperty(
          new EntityProperty("houseNumber", customer.getAddress().getHouseNumber()));

      EntityProperties props = new EntityProperties();
      props.setProperty(new EntityProperty("name", customer.getName()));
      props.setProperty(new EntityProperty("address", addressFields));
      props.setProperty(new EntityProperty("dateOfBirth", customer.getDateOfBirth()));
      Entity entity = new Entity("Customer", props);

      ctx.setResource(createEntityResource(entity));
      return Result.SUCCESS;
    } else {
      return Result.FAILURE;
    }
  }
Esempio n. 2
0
  @Override
  public void createAccount() {
    System.out.println("createAccount_***************************");
    try {

      // requête d'insertion.
      String sql =
          "INSERT INTO customers (firstname,lastname,username,password,street,zipcode,city)"
              + " VALUES(?,?,?,?,?,?,?)";

      try (PreparedStatement stmt = cn.prepareStatement(sql)) {
        stmt.setString(1, customer.getFirstname());
        stmt.setString(2, customer.getLastname());
        stmt.setString(3, customer.getLogin().getUsername());
        stmt.setString(4, customer.getLogin().getPassword());
        stmt.setString(5, customer.getAddress().getStreet());
        stmt.setInt(6, customer.getAddress().getZipcode());
        stmt.setString(7, customer.getAddress().getCity());

        stmt.executeUpdate();
      }
    } catch (SQLException ex) {
      Logger.getLogger(AccountCreatorService.class.getName()).log(Level.SEVERE, null, ex);
      throw new EJBException(
          ex.getMessage()); // on relance une exception système - PreDestroy n'est pas invoquée
    }
  }
Esempio n. 3
0
  /**
   * searches all registry lists for a specific keyword and returns all matches in a a list
   *
   * <p>function is obsolete since 1.19
   *
   * @param req the "search keyword"
   * @return list of matching objects
   */
  public ArrayList<Object> search(String req) {
    ArrayList<Object> returnValues = new ArrayList<Object>();

    for (Customer c : getCustomers().values()) {
      if (c.getName().contains(req)
          || c.getAddress().contains(req)
          || c.getCivic().contains(req)
          || c.getPhone().contains(req)) {
        returnValues.add(c);
      }
    }

    for (Item i : getItems().values()) {
      if (i.getName().contains(req) || i.getPrice().contains(req) || i.getDetails().contains(req)) {
        returnValues.add(i);
      }
    }

    for (Order i : getOrders().values()) {
      if (i.getOrderNo().contains(req) || i.getCustomer().getName().contains(req)) {
        returnValues.add(i);
      }
    }
    return returnValues;
  }
 public void testSetNestedTextValueByXPath() {
   Customer customer = new Customer();
   Address address = new Address();
   customer.setAddress(address);
   xmlContext.setValueByXPath(
       customer, "contact-info/address/city/text()", null, CONTROL_ADDRESS_CITY);
   assertEquals(CONTROL_ADDRESS_CITY, customer.getAddress().getCity());
 }
 public String addDefaultCustomer(Customer customer) {
   customerMap.put(customer.getId(), customer);
   return "Customer ID: "
       + customer.getId()
       + " Name: "
       + customer.getName()
       + " Address: "
       + customer.getAddress();
 }
Esempio n. 6
0
  public void testIdClass() {
    Type type = getSessions().getClassMetadata(Customer.class).getIdentifierType();
    Type[] types = getSessions().getClassMetadata(Customer.class).getPropertyTypes();
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Customer cust = new FavoriteCustomer("JBoss", "RouteOne", "Detroit");
    s.persist(cust);
    t.commit();
    s.close();

    s = openSession();
    CustomerId custId = new CustomerId("JBoss", "RouteOne");
    t = s.beginTransaction();
    cust = (Customer) s.get(Customer.class, custId);
    assertEquals("Detroit", cust.getAddress());
    assertEquals(cust.getCustomerName(), custId.getCustomerName());
    assertEquals(cust.getOrgName(), custId.getOrgName());
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    cust =
        (Customer) s.createQuery("from Customer where id.customerName = 'RouteOne'").uniqueResult();
    assertEquals("Detroit", cust.getAddress());
    assertEquals(cust.getCustomerName(), custId.getCustomerName());
    assertEquals(cust.getOrgName(), custId.getOrgName());
    t.commit();
    s.close();

    s = openSession();
    t = s.beginTransaction();
    cust = (Customer) s.createQuery("from Customer where customerName = 'RouteOne'").uniqueResult();
    assertEquals("Detroit", cust.getAddress());
    assertEquals(cust.getCustomerName(), custId.getCustomerName());
    assertEquals(cust.getOrgName(), custId.getOrgName());

    s.createQuery("delete from Customer").executeUpdate();

    t.commit();
    s.close();
  }
  public void insertSale(Customer c) throws SQLException {
    int id = c.getId();
    String name = c.getName();
    String address = c.getAddress();
    String phone = c.getPhoneNumber();
    String cardType = c.getCardType();
    String cardNumber = c.getCardNumber();
    String cardExp = c.getCardExp();
    String secCode = c.getSecCode();
    String cartDetails = "";
    for (Product p : c.getCart().getProductList())
      cartDetails += p.getName() + "@" + p.getUnitPrice() + "x" + p.getQuantity() + " ";
    BigDecimal cartTotal = c.getCart().getTotal().setScale(2);

    Statement stmt = con.createStatement();

    String sql =
        "INSERT INTO App.SALES VALUES("
            + id
            + ",'"
            + name
            + "','"
            + address
            + "','"
            + phone
            + "','"
            + cardType
            + "','"
            + cardNumber
            + "','"
            + cardExp
            + "','"
            + secCode
            + "','"
            + cartDetails
            + "',"
            + cartTotal
            + ",'"
            + getCurrentTimeStamp()
            + "')";
    stmt.executeUpdate(sql);
  }
  public static void main(String[] args) {

    ArrayList<BankAccount> bankAccounts = new ArrayList<>();
    ArrayList<BankAccount> closedBankAccounts = new ArrayList<>();

    boolean done = false;

    DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    Date date = new Date();

    while (!done) {
      int menu =
          GetData.getInt(
              "\tUnited Bank of Java\n"
                  + "\nPlease Choose From the Following"
                  + "\n1. Create New Account"
                  + "\n2. Update Existing Account"
                  + "\n3. Close an Account"
                  + "\n4. View Account Information"
                  + "\n5. Exit");

      switch (menu) {
        case 1: // Create bank account obj and store in database
          String first = JOptionPane.showInputDialog(null, "What is your first name?");
          String last = JOptionPane.showInputDialog(null, "What is your last name?");
          Name customerName = new Name(first, last);
          JOptionPane.showMessageDialog(null, "Customer name is " + customerName.getName());
          String street = JOptionPane.showInputDialog(null, "What's your street address?");
          String city = JOptionPane.showInputDialog(null, "What city do you live in?");
          String state = JOptionPane.showInputDialog(null, "What state do you live in?");
          String zip = JOptionPane.showInputDialog(null, "What is your ZIP code?");
          Address customerAddress = new Address(street, city, state, zip);
          JOptionPane.showMessageDialog(
              null, "Customer's address is: \n" + customerAddress.getAddress());
          String accountNum =
              JOptionPane.showInputDialog(null, "What do you want your account number to be?");
          Customer c = new Customer(customerName, customerAddress, accountNum);
          JOptionPane.showMessageDialog(
              null,
              "Welcome!\nHere's your info.\nName: "
                  + c.getName()
                  + "\nAddress: "
                  + c.getAddress()
                  + "\nAccount #: "
                  + c.getAccountNum());
          String balance = JOptionPane.showInputDialog(null, "What will be your initial balance?");
          double bal = Double.parseDouble(balance);
          BankAccount bankacc = new BankAccount(c, bal);
          JOptionPane.showMessageDialog(null, "Your balance is: \n" + bankacc.getBalance());
          bankAccounts.add(bankacc);
          System.out.print(bankAccounts.indexOf(bankacc) + " " + bankAccounts.size());

          break;

        case 2: // Update Account
          int money =
              GetData.getInt(
                  "What would you like to do?"
                      + "\n1. Make a deposit."
                      + "\n2. Make a withdrawal."
                      + "\n");

          switch (money) {
            case 1: // Make a deposit
              String accNum = JOptionPane.showInputDialog(null, "What is your account number?");
              if (BankAccount.findAccNum(bankAccounts, accNum)) {
                JOptionPane.showMessageDialog(null, "Account found!");
                int i = BankAccount.findIndex(bankAccounts, accNum);
                JOptionPane.showMessageDialog(
                    null, "Account balance is currently: $" + bankAccounts.get(i).getBalance());
                String x = JOptionPane.showInputDialog(null, "How much would you like to deposit?");
                double y = Double.parseDouble(x);
                bankAccounts.get(i).deposit(y);
                JOptionPane.showMessageDialog(
                    null, "Your new balance is: $" + bankAccounts.get(i).getBalance());
              } else {
                JOptionPane.showMessageDialog(null, "Account not in database.");
              }
              break;

            case 2: // Make a withdrawal
              String accNum1 = JOptionPane.showInputDialog(null, "What is your account number?");
              if (BankAccount.findAccNum(bankAccounts, accNum1)) {
                JOptionPane.showMessageDialog(null, "Account found!");
                int i = BankAccount.findIndex(bankAccounts, accNum1);
                JOptionPane.showMessageDialog(
                    null, "Account balance is currently: $" + bankAccounts.get(i).getBalance());
                String x =
                    JOptionPane.showInputDialog(null, "How much would you like to withdraw?");
                double y = Double.parseDouble(x);

                if (y < bankAccounts.get(i).getBalance()) {
                  bankAccounts.get(i).withdraw(y);
                  JOptionPane.showMessageDialog(
                      null, "Your new balance is: $" + bankAccounts.get(i).getBalance());
                } else {
                  JOptionPane.showMessageDialog(null, "Insufficient funds.");
                }
              } else {
                JOptionPane.showMessageDialog(null, "Account not in database.");
              }
              break;

            default:
              JOptionPane.showMessageDialog(null, "Invalid option.");
              break;
          }

          break;

        case 3: // close account
          String accNum = JOptionPane.showInputDialog(null, "What is the account number?");
          if (BankAccount.findAccNum(bankAccounts, accNum)) {
            JOptionPane.showMessageDialog(null, "Account found!");
            int i = BankAccount.findIndex(bankAccounts, accNum);
            BankAccount clone = bankAccounts.get(i);
            bankAccounts.get(i).deactivate();
            JOptionPane.showMessageDialog(
                null, "Account is located in the ArrayList at index: " + i);
            closedBankAccounts.add(clone);
            bankAccounts.remove(i);
          } else {
            JOptionPane.showMessageDialog(null, "Account not found!");
          }

          break;

        case 4: // view account info
          int view =
              GetData.getInt(
                  "What information would you like to view?"
                      + "\n1. Single Account"
                      + "\n2. All active accounts"
                      + "\n3. All inactive accounts"
                      + "\n");

          switch (view) {
            case 1: // view single account
              String accNum2 =
                  JOptionPane.showInputDialog(
                      null, "Please enter account number to view information on it.");

              if (BankAccount.findAccNum(bankAccounts, accNum2)) {
                JOptionPane.showMessageDialog(null, "Account found!");

                int i = BankAccount.findIndex(bankAccounts, accNum2);
                JOptionPane.showMessageDialog(
                    null,
                    "Name: "
                        + bankAccounts.get(i).getName()
                        + "\nAccount Number: "
                        + bankAccounts.get(i).getAccountNum()
                        + "\nBalance: $"
                        + bankAccounts.get(i).getBalance());
              } else {
                JOptionPane.showMessageDialog(null, "Account not in database.");
              }

              break;

            case 2: // view all account

              /*JTextArea textArea = new JTextArea("Date: " + dateFormat.format(date) +
                          BankAccount.printAllCustomers(bankAccounts));
                  JScrollPane scrollPane = new JScrollPane(textArea);
                  textArea.setLineWrap(true);
                  textArea.setWrapStyleWord(true);
                  scrollPane.setPreferredSize( new Dimension( 300, 400 ) );
                  JOptionPane.showMessageDialog(null, scrollPane, "Current Customers",
                         JOptionPane.YES_NO_OPTION);

              */
              break;

            case 3: // view all closed accounts
              break;

            default:
              JOptionPane.showMessageDialog(null, "Invalid Option.");
              break;
          } // end view
          break;

        case 5: // exit
          done = true;
          break;

        default:
          JOptionPane.showMessageDialog(null, "Account not found.");
          break;
      }
    }
  }