Compare commits

...

2 Commits

Author SHA1 Message Date
97252c4c2b changes 2025-09-29 16:56:21 -04:00
0a9f014392 changes 2025-09-29 16:46:10 -04:00
33 changed files with 73 additions and 53 deletions

Binary file not shown.

BIN
libs/gson-2.13.2.jar Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge; package lodge;

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge; package lodge;

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge.datamodel; package lodge.datamodel;

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem * reservationsystem
*/ */
package lodge.datamodel; package lodge.datamodel;
@@ -13,7 +13,13 @@ import java.util.ListIterator;
public class AccountList extends ArrayList<Account> { public class AccountList extends ArrayList<Account> {
public static String accountSerial(String phone_number, Address mailing_address, EmailAddress email_address) { public static String accountSerial(String phone_number, Address mailing_address, EmailAddress email_address) {
return String.format("A%09d", Math.abs(java.util.Objects.hash(phone_number, mailing_address, email_address))); String serial = String.format("%09d", Math.abs(java.util.Objects.hash(phone_number, mailing_address, email_address)));
serial = serial.length() > 8 ? serial.substring(1, 9): serial;
return String.format("A%s",serial);
}
public static String reservationSerial(IReservation reservation) {
return AccountReservationList.reservationSerial((Reservation)reservation);
} }
// ** Add account throw error if account number is pre-existing. */ // ** Add account throw error if account number is pre-existing. */
@@ -52,6 +58,14 @@ public class AccountList extends ArrayList<Account> {
return null; return null;
} }
public List<Account> getListOfAccounts() {
ArrayList<Account> readList = new ArrayList<>();
for (Account acct : this) {
readList.add(acct);
}
return Collections.unmodifiableList(readList);
}
public List<? extends IReservation> getListOfReservations() { public List<? extends IReservation> getListOfReservations() {
ArrayList<IReservation> readList = new ArrayList<>(); ArrayList<IReservation> readList = new ArrayList<>();
for (Account acct : this) { for (Account acct : this) {
@@ -62,19 +76,4 @@ public class AccountList extends ArrayList<Account> {
} }
return Collections.unmodifiableList(readList); return Collections.unmodifiableList(readList);
} }
// Show the different accounts lists of resverations
public void showReservationList() {
for (IReservation irsrv : this.getListOfReservations()) {
System.out.println(String.format("Account %s: %s, %s", irsrv.getAccountNumber(),
irsrv.getReservation_number(), irsrv.getPhysical_address().getStreet()));
}
}
// show the accounts
public void showAccountList() {
for (Account acct : this) {
System.out.println(String.format("Account %s", acct.getAccount_number()));
}
}
} }

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge.datamodel; package lodge.datamodel;
@@ -8,15 +8,19 @@ import java.util.ArrayList;
class AccountReservationList extends ArrayList<IReservation> { class AccountReservationList extends ArrayList<IReservation> {
private static String reservationSerial(Reservation reservation) { public static String reservationSerial(Reservation reservation) {
return String.format("R%010d", Math.abs(java.util.Objects.hash(reservation.getPhysical_address()))); String serial = String.format("%010d", Math.abs(java.util.Objects.hash(reservation.getPhysical_address())));
int e = serial.length();
int s = e - 10;
serial = serial.substring(s, e);
return String.format("R%s", serial);
} }
@Override @Override
public synchronized boolean add(final IReservation reservation) throws RuntimeException { public synchronized boolean add(final IReservation reservation) throws RuntimeException {
boolean result = true; boolean result = true;
((Reservation) reservation) ((Reservation) reservation)
.setReservation_number(AccountReservationList.reservationSerial((Reservation) reservation)); .setReservation_number(AccountReservationList.reservationSerial((Reservation) reservation));
Reservation rsrv = this.find(reservation.getReservation_number()); Reservation rsrv = this.find(reservation.getReservation_number());
result = rsrv == null; result = rsrv == null;
if (!result) { if (!result) {

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge.datamodel; package lodge.datamodel;

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge.datamodel; package lodge.datamodel;

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge.datamodel; package lodge.datamodel;

View File

@@ -1,3 +1,7 @@
/**
* license: GPLv3
reservationsystem
*/
package lodge.datamodel; package lodge.datamodel;
public interface IReservation { public interface IReservation {

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge.datamodel; package lodge.datamodel;

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge.datamodel; package lodge.datamodel;

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge.datamodel; package lodge.datamodel;
@@ -227,7 +227,7 @@ public abstract class Reservation implements IReservation{
// @TODO write reservation out in json // @TODO write reservation out in json
public void Write(Reservation reservation) throws IOException { public void Write(Reservation reservation) throws IOException {
String dataRoot = DataRepository.getPath(); String dataRoot = DataRepository.getPath();
dataRoot = dataRoot + "/rsv-" + reservation.reservation_number + ".json"; dataRoot = dataRoot + "/res-" + reservation.reservation_number + ".json";
Path path = Paths.get(dataRoot); Path path = Paths.get(dataRoot);
try (BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { try (BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge.datamodel; package lodge.datamodel;

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge.reservationsystem; package lodge.reservationsystem;
@@ -36,7 +36,8 @@ public final class AccomodationManager {
DataRepository.setDataStoreRoot(home); DataRepository.setDataStoreRoot(home);
} }
public final void loadAll()throws IOException,IllegalArgumentException,IllegalOperationException,DuplicateObjectException{ public final void loadAll()
throws IOException, IllegalArgumentException, IllegalOperationException, DuplicateObjectException {
accounts.clear(); accounts.clear();
// walk directories // walk directories
Path rootDir = Paths.get(DataRepository.getPath()); Path rootDir = Paths.get(DataRepository.getPath());
@@ -45,7 +46,8 @@ public final class AccomodationManager {
} }
// Load / Deserialize Account // Load / Deserialize Account
protected void load(Path file) throws IOException,IllegalArgumentException,IllegalOperationException,DuplicateObjectException { protected void load(Path file)
throws IOException, IllegalArgumentException, IllegalOperationException, DuplicateObjectException {
Account account = DataRepository.LoadAccount(file); Account account = DataRepository.LoadAccount(file);
if (account == null) { if (account == null) {
@@ -69,7 +71,7 @@ public final class AccomodationManager {
} }
public synchronized void UpdateAccount(final Account acct) throws Exception { public synchronized void UpdateAccount(final Account acct) throws Exception {
if( acct != null ){ if (acct != null) {
accounts.save(acct); accounts.save(acct);
} }
} }
@@ -86,7 +88,7 @@ public final class AccomodationManager {
return acct; return acct;
} }
public boolean addReservation(final Account account, final Reservation reservation){ public boolean addReservation(final Account account, final Reservation reservation) {
boolean result = account.add(reservation); boolean result = account.add(reservation);
return result; return result;
} }
@@ -95,21 +97,32 @@ public final class AccomodationManager {
Reservation rsrv = null; Reservation rsrv = null;
for (Account acct : accounts) { for (Account acct : accounts) {
rsrv = acct.findReservation(reservation_number); rsrv = acct.findReservation(reservation_number);
if( rsrv!=null ) break; if (rsrv != null)
break;
} }
return rsrv; return rsrv;
} }
public List<Account> getListOfAccounts() {
return accounts.getListOfAccounts();
}
public List<? extends IReservation> getReservationList() { public List<? extends IReservation> getReservationList() {
return accounts.getListOfReservations(); return accounts.getListOfReservations();
} }
// Show all accounts lists of resverations
public void showReservationList() { public void showReservationList() {
accounts.showReservationList(); for (IReservation irsrv : accounts.getListOfReservations()) {
System.out.println(String.format("Account %s: %s, %s", irsrv.getAccountNumber(),
irsrv.getReservation_number(), irsrv.getPhysical_address().getStreet()));
}
} }
// show the accounts
public void showAccountList() { public void showAccountList() {
accounts.showAccountList(); for (Account acct : accounts.getListOfAccounts()) {
System.out.println(String.format("Account %s", acct.getAccount_number()));
}
} }
} }

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge.reservationsystem; package lodge.reservationsystem;

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge.reservationsystem; package lodge.reservationsystem;
@@ -164,7 +164,7 @@ public final class DataRepository {
private static void loadReservation(Account ac, String reservationType, private static void loadReservation(Account ac, String reservationType,
String reservationNumber) throws IOException { String reservationNumber) throws IOException {
String filename = String.format("rsv-%s.json", reservationNumber); String filename = String.format("res-%s.json", reservationNumber);
Path basePath = Paths.get(getPath()); Path basePath = Paths.get(getPath());
Path resolvedPath = basePath.resolve(filename); Path resolvedPath = basePath.resolve(filename);

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge.reservationsystem; package lodge.reservationsystem;

View File

@@ -1,6 +1,6 @@
/** /**
* license: GPLv3 * license: GPLv3
* lodge.reservationsystem reservationsystem
*/ */
package lodge.reservationsystem; package lodge.reservationsystem;

View File

@@ -0,0 +1 @@
{ "Account":{"account_number": "A07421233","phone_number": "301-356-3890","mailing_address": { "Address":{"street": "30 Amstadam ave","city": "New York","state": "NY","zip": "12010"}},"email_address": { "EmailAddress":{"email": "newbee952@aol.com"}},"reservations":[{"HotelReservation":{"reservation_number":"R0123087344"}},{"CabinReservation":{"reservation_number":"R2042828431"}}]}}

View File

@@ -1 +0,0 @@
{ "Account":{"account_number": "A1450981765","phone_number": "701-456-7890","mailing_address": { "Address":{"street": "10 wilco ave","city": "wilco","state": "WY","zip": "82801"}},"email_address": { "EmailAddress":{"email": "wilco@wyommin.net"}},"reservations":[]}}

View File

@@ -1 +0,0 @@
{ "Account":{"account_number": "A2074212339","phone_number": "301-356-3890","mailing_address": { "Address":{"street": "30 Amstadam ave","city": "New York","state": "NY","zip": "12010"}},"email_address": { "EmailAddress":{"email": "newbee952@aol.com"}},"reservations":[{"HotelReservation":{"reservation_number":"R0123087344"}},{"CabinReservation":{"reservation_number":"R2042828431"}}]}}

View File

@@ -0,0 +1 @@
{ "Account":{"account_number": "A45098176","phone_number": "701-456-7890","mailing_address": { "Address":{"street": "10 wilco ave","city": "wilco","state": "WY","zip": "82801"}},"email_address": { "EmailAddress":{"email": "wilco@wyommin.net"}},"reservations":[{"CabinReservation":{"reservation_number":"R0535276622"}},{"HouseReservation":{"reservation_number":"R0499811708"}}]}}

View File

@@ -0,0 +1 @@
{ "HotelReservation":{"reservation_type": "HotelReservation","reservation_number": "R0123087344","reservation_status": "Canceled","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_end_date": "2025-09-09T10:00Z[UTC]","account_number": "A07421233","physical_address": { "Address":{"street": "400 hotel ave","city": "Maryland City","state": "MD","zip": "20723"}},"mailing_address": { "Address":{"street": "400 hotel ave","city": "Maryland City","state": "MD","zip": "20723"}},"kitchen": "Kitchenette","numberOfBeds": "2","numberOfBedRooms": "1","numberOfBathRooms": "1","numberOfFloors": "1","squareFeet": "450","price": "410.0"}}

View File

@@ -0,0 +1 @@
{ "HouseReservation":{"reservation_type": "HouseReservation","reservation_number": "R0499811708","reservation_status": "Draft","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_end_date": "2025-09-09T10:00Z[UTC]","account_number": "A45098176","physical_address": { "Address":{"street": "3000 Osage ave","city": "GreenBelt","state": "MD","zip": "20740"}},"mailing_address": { "Address":{"street": "40012 College ave","city": "College Park","state": "MD","zip": "20740"}},"kitchen": "Kitchenette","numberOfBeds": "2","numberOfBedRooms": "1","numberOfBathRooms": "1","numberOfFloors": "1","squareFeet": "450","price": "360.0"}}

View File

@@ -0,0 +1 @@
{ "CabinReservation":{"reservation_type": "CabinReservation","reservation_number": "R0535276622","reservation_status": "Completed","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_end_date": "2025-09-09T10:00Z[UTC]","account_number": "A45098176","physical_address": { "Address":{"street": "40 cabin ave","city": "Carnelian","state": "CA","zip": "96140"}},"mailing_address": { "Address":{"street": "40 cabin ave","city": "Carnelian Bay","state": "CA","zip": "96140"}},"kitchen": "Kitchenette","numberOfBeds": "2","numberOfBedRooms": "1","numberOfBathRooms": "1","numberOfFloors": "1","squareFeet": "450","price": "360.0"}}

View File

@@ -0,0 +1 @@
{ "CabinReservation":{"reservation_type": "CabinReservation","reservation_number": "R2042828431","reservation_status": "Draft","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_end_date": "2025-09-09T10:00Z[UTC]","account_number": "A07421233","physical_address": { "Address":{"street": "30 cabin ave","city": "Carnelian","state": "CA","zip": "96140"}},"mailing_address": { "Address":{"street": "30 cabin ave","city": "Carnelian Bay","state": "CA","zip": "96140"}},"kitchen": "Kitchenette","numberOfBeds": "2","numberOfBedRooms": "1","numberOfBathRooms": "1","numberOfFloors": "1","squareFeet": "450","price": "360.0"}}

View File

@@ -1 +0,0 @@
{ "HotelReservation":{"reservation_type": "HotelReservation","reservation_number": "R0123087344","reservation_status": "Canceled","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_end_date": "2025-09-09T10:00Z[UTC]","account_number": "A2074212339","physical_address": { "Address":{"street": "400 hotel ave","city": "Maryland City","state": "MD","zip": "20723"}},"mailing_address": { "Address":{"street": "400 hotel ave","city": "Maryland City","state": "MD","zip": "20723"}},"kitchen": "Kitchenette","numberOfBeds": "2","numberOfBedRooms": "1","numberOfBathRooms": "1","numberOfFloors": "1","squareFeet": "450","price": "410.0"}}

View File

@@ -1 +0,0 @@
{ "HouseReservation":{"reservation_type": "HouseReservation","reservation_number": "R0499811708","reservation_status": "Draft","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_end_date": "2025-09-09T10:00Z[UTC]","account_number": "A1450981765","physical_address": { "Address":{"street": "3000 Osage ave","city": "GreenBelt","state": "MD","zip": "20740"}},"mailing_address": { "Address":{"street": "40012 College ave","city": "College Park","state": "MD","zip": "20740"}},"kitchen": "Kitchenette","numberOfBeds": "2","numberOfBedRooms": "1","numberOfBathRooms": "1","numberOfFloors": "1","squareFeet": "450","price": "360.0"}}

View File

@@ -1 +0,0 @@
{ "CabinReservation":{"reservation_type": "CabinReservation","reservation_number": "R0535276622","reservation_status": "Completed","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_end_date": "2025-09-09T10:00Z[UTC]","account_number": "A1450981765","physical_address": { "Address":{"street": "40 cabin ave","city": "Carnelian","state": "CA","zip": "96140"}},"mailing_address": { "Address":{"street": "40 cabin ave","city": "Carnelian Bay","state": "CA","zip": "96140"}},"kitchen": "Kitchenette","numberOfBeds": "2","numberOfBedRooms": "1","numberOfBathRooms": "1","numberOfFloors": "1","squareFeet": "450","price": "360.0"}}

View File

@@ -1 +0,0 @@
{ "CabinReservation":{"reservation_type": "CabinReservation","reservation_number": "R2042828431","reservation_status": "Draft","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_end_date": "2025-09-09T10:00Z[UTC]","account_number": "A2074212339","physical_address": { "Address":{"street": "30 cabin ave","city": "Carnelian","state": "CA","zip": "96140"}},"mailing_address": { "Address":{"street": "30 cabin ave","city": "Carnelian Bay","state": "CA","zip": "96140"}},"kitchen": "Kitchenette","numberOfBeds": "2","numberOfBedRooms": "1","numberOfBathRooms": "1","numberOfFloors": "1","squareFeet": "450","price": "360.0"}}