Ejemplo n.º 1
0
  private void parseJSON(JSONObject jsonObject, boolean INCLUDE_BOOKINGS) {
    if (this.jsonObject != null) {
      JSONArray jsonGuests = (JSONArray) jsonObject.get("guests");
      JSONObject jsonGuest;
      Guest guest;
      for (int i = 0; i < jsonGuests.size(); i++) {
        jsonGuest = (JSONObject) jsonGuests.get(i);
        if (this.guests == null) this.guests = new ArrayList<Guest>();
        guest = new Guest();
        guest.setId(jsonGuest.get("id").toString());
        guest.setName(jsonGuest.get("name").toString());
        guest.setEmail(jsonGuest.get("email").toString());
        guest.setCineplexName(jsonGuest.get("cineplexname").toString());
        guest.setMobileNo(Integer.parseInt(jsonGuest.get("mobileno").toString()));

        if (INCLUDE_BOOKINGS) guest.setBookings(new BookingDAO().getBookingsByGuest(guest));

        this.guests.add(guest);
      }
    }
  }
Ejemplo n.º 2
0
  public ArrayList<Person> getAllPersons() throws SQLException {
    conn = DBTool.getInstance();

    System.out.println("Getting all persons...");
    if (conn.isValid(10000)) {
      Statement s = conn.createStatement();
      ArrayList<Person> persons = new ArrayList<>();

      ResultSet rs = s.executeQuery("SELECT * FROM person");
      while (rs.next()) {
        int idperson = rs.getInt("idperson");
        String firstname = rs.getString("firstname");
        String middlename = rs.getString("middlename");
        String lastname = rs.getString("lastname");
        String address = rs.getString("address");
        ADate birthday = new ADate(rs.getString("birthday"));
        ADate expirationDate = new ADate(rs.getString("expirationdate"));
        File picturePath = new File(rs.getString("picturepath"));
        ADate quarantineExpirationDate = null;
        if (!rs.getString("quarantineexpirationdate").isEmpty()) {
          quarantineExpirationDate = new ADate(rs.getString("quarantineexpirationdate"));
        }
        ADate creationDate = new ADate(rs.getString("creationdate"));
        boolean oneOne = false;
        if (rs.getInt("oneone") == 1) {
          oneOne = true;
        }
        boolean quarantine = false;
        if (rs.getInt("quarantine") == 1) {
          quarantine = true;
        }
        boolean enrolled = false;
        if (rs.getInt("enrolled") == 1) {
          enrolled = true;
        }
        boolean hone = false;
        if (rs.getInt("hone") == 1) {
          hone = true;
        }
        Statement s2 = conn.createStatement();
        ArrayList<Guest> guests = new ArrayList<>();
        ResultSet rsGuest =
            s2.executeQuery("SELECT * FROM guest WHERE idperson = " + idperson + ";");
        while (rsGuest.next()) {
          Guest g =
              new Guest(
                  rsGuest.getString("firstname"),
                  rsGuest.getString("middlename"),
                  rsGuest.getString("lastname"),
                  new ADate(rsGuest.getString("birthday")),
                  new ADate(rsGuest.getString("creationdate")));
          g.setId(rsGuest.getInt("idguest"));
          guests.add(g);
        }

        Person p =
            new Person(
                firstname,
                middlename,
                lastname,
                address,
                birthday,
                expirationDate,
                picturePath,
                creationDate,
                oneOne);
        p.setId(idperson);
        p.setQuarantine(quarantine);
        p.setQuarantineExpirationDate(quarantineExpirationDate);
        p.setEnrolled(enrolled);
        p.setHone(hone);
        p.setGuests(guests);
        persons.add(p);

        rsGuest.close();
        s2.close();
      }
      System.out.println("Get complete!");
      rs.close();
      s.close();
      conn.close();
      return persons;
    } else {
      System.out.println("Connection invalid");
      conn.close();
      return null;
    }
  }