2025-09-15 11:08:45 -04:00
|
|
|
/**
|
|
|
|
|
* license: GPLv3
|
|
|
|
|
* lodge.reservationsystem
|
|
|
|
|
*/
|
2025-09-18 21:39:24 -04:00
|
|
|
package lodge.reservation;
|
2025-08-28 21:08:16 -04:00
|
|
|
|
2025-08-31 18:59:49 -04:00
|
|
|
import java.io.BufferedWriter;
|
2025-08-29 10:32:10 -04:00
|
|
|
import java.io.IOException;
|
2025-08-31 18:59:49 -04:00
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
2025-09-03 08:56:57 -04:00
|
|
|
import java.time.ZonedDateTime;
|
2025-08-31 18:59:49 -04:00
|
|
|
|
2025-09-18 21:39:24 -04:00
|
|
|
import lodge.data.Address;
|
|
|
|
|
import lodge.data.IllegalOperationException;
|
|
|
|
|
import lodge.data.KitchenTypeEnum;
|
|
|
|
|
import lodge.data.ReservationStatusEnum;
|
2025-09-19 18:25:06 -04:00
|
|
|
import lodge.reservationsystem.DataRepository;
|
2025-09-18 12:18:33 -04:00
|
|
|
|
2025-09-18 21:39:24 -04:00
|
|
|
public abstract class Reservation implements IReservation{
|
2025-09-10 17:54:48 -04:00
|
|
|
private char type;
|
|
|
|
|
private String reservation_number = "-99";
|
|
|
|
|
private Address physical_address;
|
|
|
|
|
private Address mailing_address;
|
2025-08-28 21:08:16 -04:00
|
|
|
|
2025-09-10 17:54:48 -04:00
|
|
|
private ZonedDateTime reservation_start_date;
|
|
|
|
|
private ZonedDateTime reservation_end_date;
|
|
|
|
|
private ReservationStatusEnum reservation_status;
|
2025-08-28 21:08:16 -04:00
|
|
|
|
2025-09-16 20:53:58 -04:00
|
|
|
private KitchenTypeEnum kitchen;
|
2025-09-04 22:34:26 -04:00
|
|
|
|
2025-09-10 17:54:48 -04:00
|
|
|
private Integer numberOfBeds;
|
|
|
|
|
private Integer numberOfBedRooms;
|
|
|
|
|
private Integer numberOfBathRooms;
|
|
|
|
|
private Integer numberOfFloors;
|
|
|
|
|
private Integer squareFeet;
|
2025-08-28 21:08:16 -04:00
|
|
|
|
2025-09-13 20:33:29 -04:00
|
|
|
private Float price;
|
|
|
|
|
|
|
|
|
|
protected String accountNumber = null;
|
2025-08-28 21:08:16 -04:00
|
|
|
|
2025-09-10 17:54:48 -04:00
|
|
|
protected Reservation() {
|
2025-09-03 16:08:44 -04:00
|
|
|
numberOfBeds = 1;
|
|
|
|
|
numberOfBedRooms = 1;
|
|
|
|
|
numberOfBathRooms = 1;
|
|
|
|
|
numberOfFloors = 1;
|
2025-09-16 20:53:58 -04:00
|
|
|
kitchen = KitchenTypeEnum.None;
|
2025-09-03 16:08:44 -04:00
|
|
|
price = 120.0f;
|
|
|
|
|
reservation_status = ReservationStatusEnum.Draft;
|
|
|
|
|
mailing_address = null;
|
|
|
|
|
physical_address = null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-28 21:08:16 -04:00
|
|
|
public void setReservation_number(String reservation_number) {
|
|
|
|
|
this.reservation_number = reservation_number;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-10 17:54:48 -04:00
|
|
|
public String getReservation_number() {
|
|
|
|
|
return this.reservation_number;
|
2025-08-28 21:08:16 -04:00
|
|
|
}
|
|
|
|
|
|
2025-09-13 20:33:29 -04:00
|
|
|
public String getAccountNumber() {
|
|
|
|
|
return this.accountNumber;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-18 12:18:33 -04:00
|
|
|
public void setAccountNumber(String account_number) {
|
2025-09-13 20:33:29 -04:00
|
|
|
this.accountNumber = account_number;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-29 07:26:53 -04:00
|
|
|
public void setPhysical_address(Address physical_address) {
|
2025-08-28 21:08:16 -04:00
|
|
|
this.physical_address = physical_address;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-29 07:26:53 -04:00
|
|
|
public Address mailing_address() {
|
2025-08-28 21:08:16 -04:00
|
|
|
return mailing_address;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-29 07:26:53 -04:00
|
|
|
public void setMailing_address(Address mailing_address) {
|
2025-08-28 21:08:16 -04:00
|
|
|
this.mailing_address = mailing_address;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-03 08:56:57 -04:00
|
|
|
public void setReservation_start_date(ZonedDateTime reservation_start_date) {
|
2025-08-28 21:08:16 -04:00
|
|
|
this.reservation_start_date = reservation_start_date;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-03 08:56:57 -04:00
|
|
|
public void setReservation_end_date(ZonedDateTime reservation_end_date) {
|
2025-08-28 21:08:16 -04:00
|
|
|
this.reservation_end_date = reservation_end_date;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-03 16:08:44 -04:00
|
|
|
public void setReservation_status(ReservationStatusEnum reservation_status) {
|
2025-08-28 21:08:16 -04:00
|
|
|
this.reservation_status = reservation_status;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-16 20:53:58 -04:00
|
|
|
public KitchenTypeEnum getKitchen() {
|
2025-09-04 22:34:26 -04:00
|
|
|
return kitchen;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-16 20:53:58 -04:00
|
|
|
public void setKitchen(KitchenTypeEnum kitchen) {
|
2025-09-04 22:34:26 -04:00
|
|
|
this.kitchen = kitchen;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-28 21:08:16 -04:00
|
|
|
public void setNumberOfBeds(Integer numberOfBeds) {
|
|
|
|
|
this.numberOfBeds = numberOfBeds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer numberOfBedRooms() {
|
|
|
|
|
return numberOfBedRooms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setNumberOfBedRooms(Integer numberOfBedRooms) {
|
|
|
|
|
this.numberOfBedRooms = numberOfBedRooms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setNumberOfBathRooms(Integer numberOfBathRooms) {
|
|
|
|
|
this.numberOfBathRooms = numberOfBathRooms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setNumberOfFloors(Integer numberOfFloors) {
|
|
|
|
|
this.numberOfFloors = numberOfFloors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setSquareFeet(Integer squareFeet) {
|
|
|
|
|
this.squareFeet = squareFeet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setPrice(Float price) {
|
|
|
|
|
this.price = price;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-10 17:54:48 -04:00
|
|
|
public char getType() {
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-18 12:18:33 -04:00
|
|
|
public void setType(char type) {
|
2025-09-10 17:54:48 -04:00
|
|
|
this.type = type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Address getPhysical_address() {
|
|
|
|
|
return physical_address;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Address getMailing_address() {
|
|
|
|
|
return mailing_address;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ZonedDateTime getReservation_start_date() {
|
|
|
|
|
return reservation_start_date;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ZonedDateTime getReservation_end_date() {
|
|
|
|
|
return reservation_end_date;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ReservationStatusEnum getReservation_status() {
|
|
|
|
|
return reservation_status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer getNumberOfBeds() {
|
|
|
|
|
return numberOfBeds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer getNumberOfBedRooms() {
|
|
|
|
|
return numberOfBedRooms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer getNumberOfBathRooms() {
|
|
|
|
|
return numberOfBathRooms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer getNumberOfFloors() {
|
|
|
|
|
return numberOfFloors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer getSquareFeet() {
|
|
|
|
|
return squareFeet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Float getPrice() {
|
|
|
|
|
return price;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-28 21:08:16 -04:00
|
|
|
@Override
|
|
|
|
|
public int hashCode() {
|
|
|
|
|
final int prime = 31;
|
|
|
|
|
int result = 1;
|
|
|
|
|
result = prime * result + ((reservation_number == null) ? 0 : reservation_number.hashCode());
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
|
if (this == obj)
|
|
|
|
|
return true;
|
|
|
|
|
if (obj == null)
|
|
|
|
|
return false;
|
|
|
|
|
if (getClass() != obj.getClass())
|
|
|
|
|
return false;
|
|
|
|
|
Reservation other = (Reservation) obj;
|
|
|
|
|
if (reservation_number == null) {
|
|
|
|
|
if (other.reservation_number != null)
|
|
|
|
|
return false;
|
|
|
|
|
} else if (!reservation_number.equals(other.reservation_number))
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-29 07:26:53 -04:00
|
|
|
@Override
|
|
|
|
|
public String toString() {
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
2025-09-18 12:18:33 -04:00
|
|
|
sb.append(String.format("{ \"%s\":{", this.ReservationType()));
|
2025-09-10 17:54:48 -04:00
|
|
|
sb.append("\"reservation_type\": \"").append(ReservationType()).append("\",");
|
|
|
|
|
sb.append("\"reservation_number\": \"").append(reservation_number).append("\",");
|
|
|
|
|
sb.append("\"reservation_status\": \"").append(reservation_status).append("\",");
|
|
|
|
|
sb.append("\"reservation_start_date\": \"").append(reservation_start_date).append("\",");
|
|
|
|
|
sb.append("\"reservation_end_date\": \"").append(reservation_end_date).append("\",");
|
2025-09-13 20:33:29 -04:00
|
|
|
sb.append("\"account_number\": \"").append(accountNumber).append("\",");
|
2025-09-10 17:54:48 -04:00
|
|
|
sb.append("\"physical_address\": ").append(physical_address).append(",");
|
|
|
|
|
sb.append("\"mailing_address\": ").append(mailing_address).append(",");
|
|
|
|
|
sb.append("\"kitchen\": \"").append(kitchen).append("\",");
|
|
|
|
|
sb.append("\"numberOfBeds\": \"").append(numberOfBeds).append("\",");
|
|
|
|
|
sb.append("\"numberOfBedRooms\": \"").append(numberOfBedRooms).append("\",");
|
|
|
|
|
sb.append("\"numberOfBathRooms\": \"").append(numberOfBathRooms).append("\",");
|
|
|
|
|
sb.append("\"numberOfFloors\": \"").append(numberOfFloors).append("\",");
|
|
|
|
|
sb.append("\"squareFeet\": \"").append(squareFeet).append("\",");
|
|
|
|
|
sb.append("\"price\": \"").append(price).append("\"");
|
2025-08-29 07:26:53 -04:00
|
|
|
sb.append("}}");
|
|
|
|
|
return sb.toString();
|
|
|
|
|
}
|
2025-08-31 18:59:49 -04:00
|
|
|
|
|
|
|
|
// @TODO write reservation out in json
|
|
|
|
|
public void Write(Reservation reservation) throws IOException {
|
|
|
|
|
String dataRoot = DataRepository.getPath();
|
|
|
|
|
dataRoot = dataRoot + "/rsv-" + reservation.reservation_number + ".json";
|
|
|
|
|
Path path = Paths.get(dataRoot);
|
|
|
|
|
|
|
|
|
|
try (BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
|
2025-08-31 23:54:17 -04:00
|
|
|
writer.write(toString());
|
2025-08-31 18:59:49 -04:00
|
|
|
writer.flush();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-10 17:54:48 -04:00
|
|
|
public void Change(Reservation reservation, ReservationStatusEnum newStatus) throws IllegalOperationException {
|
2025-09-03 16:08:44 -04:00
|
|
|
try {
|
2025-09-18 12:18:33 -04:00
|
|
|
if (reservation.reservation_status == ReservationStatusEnum.Completed ||
|
|
|
|
|
reservation.reservation_status == ReservationStatusEnum.Canceled) {
|
2025-09-03 16:08:44 -04:00
|
|
|
if (newStatus == ReservationStatusEnum.Canceled) {
|
2025-09-18 12:18:33 -04:00
|
|
|
throw new IllegalOperationException(
|
|
|
|
|
String.format("Invalid Change, reservation has %s.", reservation.getReservation_status()));
|
2025-09-03 16:08:44 -04:00
|
|
|
}
|
|
|
|
|
if (ZonedDateTime.now().compareTo(this.reservation_start_date) > -1) {
|
2025-09-18 12:18:33 -04:00
|
|
|
throw new IllegalOperationException("Invalid Change, reservation has begun.");
|
2025-09-03 16:08:44 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newStatus == ReservationStatusEnum.Completed) {
|
2025-09-18 12:18:33 -04:00
|
|
|
IReservation irsrv = (IReservation) this;
|
|
|
|
|
this.setPrice(irsrv.calculatePrice());
|
2025-09-03 16:08:44 -04:00
|
|
|
}
|
|
|
|
|
reservation.setReservation_status(newStatus);
|
2025-09-04 22:34:26 -04:00
|
|
|
} catch (IllegalOperationException e) {
|
2025-09-10 15:44:29 -04:00
|
|
|
System.out.println(e.toString());
|
2025-09-03 16:08:44 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-10 15:44:29 -04:00
|
|
|
public void update(Reservation rsrv) {
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-10 19:51:15 -04:00
|
|
|
|
2025-09-10 20:47:45 -04:00
|
|
|
public abstract String ReservationType();
|
2025-09-03 16:08:44 -04:00
|
|
|
}
|