changes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
|
||||
package lodge;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
|
||||
package lodge;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
package lodge.datamodel;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
* reservationsystem
|
||||
*/
|
||||
package lodge.datamodel;
|
||||
|
||||
@@ -13,7 +13,13 @@ import java.util.ListIterator;
|
||||
public class AccountList extends ArrayList<Account> {
|
||||
|
||||
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. */
|
||||
@@ -52,6 +58,14 @@ public class AccountList extends ArrayList<Account> {
|
||||
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() {
|
||||
ArrayList<IReservation> readList = new ArrayList<>();
|
||||
for (Account acct : this) {
|
||||
@@ -62,19 +76,4 @@ public class AccountList extends ArrayList<Account> {
|
||||
}
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
package lodge.datamodel;
|
||||
|
||||
@@ -8,15 +8,19 @@ import java.util.ArrayList;
|
||||
|
||||
class AccountReservationList extends ArrayList<IReservation> {
|
||||
|
||||
private static String reservationSerial(Reservation reservation) {
|
||||
return String.format("R%010d", Math.abs(java.util.Objects.hash(reservation.getPhysical_address())));
|
||||
public static String reservationSerial(Reservation reservation) {
|
||||
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-1);
|
||||
return String.format("R%s", serial);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean add(final IReservation reservation) throws RuntimeException {
|
||||
boolean result = true;
|
||||
((Reservation) reservation)
|
||||
.setReservation_number(AccountReservationList.reservationSerial((Reservation) reservation));
|
||||
.setReservation_number(AccountReservationList.reservationSerial((Reservation) reservation));
|
||||
Reservation rsrv = this.find(reservation.getReservation_number());
|
||||
result = rsrv == null;
|
||||
if (!result) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
package lodge.datamodel;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
package lodge.datamodel;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
package lodge.datamodel;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
package lodge.datamodel;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
package lodge.datamodel;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
package lodge.datamodel;
|
||||
|
||||
@@ -227,7 +227,7 @@ public abstract class Reservation implements IReservation{
|
||||
// @TODO write reservation out in json
|
||||
public void Write(Reservation reservation) throws IOException {
|
||||
String dataRoot = DataRepository.getPath();
|
||||
dataRoot = dataRoot + "/rsv-" + reservation.reservation_number + ".json";
|
||||
dataRoot = dataRoot + "/res-" + reservation.reservation_number + ".json";
|
||||
Path path = Paths.get(dataRoot);
|
||||
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
package lodge.datamodel;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
|
||||
@@ -36,7 +36,8 @@ public final class AccomodationManager {
|
||||
DataRepository.setDataStoreRoot(home);
|
||||
}
|
||||
|
||||
public final void loadAll()throws IOException,IllegalArgumentException,IllegalOperationException,DuplicateObjectException{
|
||||
public final void loadAll()
|
||||
throws IOException, IllegalArgumentException, IllegalOperationException, DuplicateObjectException {
|
||||
accounts.clear();
|
||||
// walk directories
|
||||
Path rootDir = Paths.get(DataRepository.getPath());
|
||||
@@ -45,8 +46,9 @@ public final class AccomodationManager {
|
||||
}
|
||||
|
||||
// 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);
|
||||
if (account == null) {
|
||||
System.out.println(String.format("No Account: %s", file.toString()));
|
||||
@@ -69,7 +71,7 @@ public final class AccomodationManager {
|
||||
}
|
||||
|
||||
public synchronized void UpdateAccount(final Account acct) throws Exception {
|
||||
if( acct != null ){
|
||||
if (acct != null) {
|
||||
accounts.save(acct);
|
||||
}
|
||||
}
|
||||
@@ -86,7 +88,7 @@ public final class AccomodationManager {
|
||||
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);
|
||||
return result;
|
||||
}
|
||||
@@ -95,21 +97,32 @@ public final class AccomodationManager {
|
||||
Reservation rsrv = null;
|
||||
for (Account acct : accounts) {
|
||||
rsrv = acct.findReservation(reservation_number);
|
||||
if( rsrv!=null ) break;
|
||||
if (rsrv != null)
|
||||
break;
|
||||
}
|
||||
return rsrv;
|
||||
}
|
||||
|
||||
public List<Account> getListOfAccounts() {
|
||||
return accounts.getListOfAccounts();
|
||||
}
|
||||
|
||||
public List<? extends IReservation> getReservationList() {
|
||||
return accounts.getListOfReservations();
|
||||
}
|
||||
|
||||
// Show all accounts lists of resverations
|
||||
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() {
|
||||
accounts.showAccountList();
|
||||
for (Account acct : accounts.getListOfAccounts()) {
|
||||
System.out.println(String.format("Account %s", acct.getAccount_number()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
|
||||
@@ -164,7 +164,7 @@ public final class DataRepository {
|
||||
|
||||
private static void loadReservation(Account ac, String reservationType,
|
||||
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 resolvedPath = basePath.resolve(filename);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
reservationsystem
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
|
||||
|
||||
1
src/resources/acc-A07421233.json
Normal file
1
src/resources/acc-A07421233.json
Normal 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":"R012308734"}},{"CabinReservation":{"reservation_number":"R204282843"}}]}}
|
||||
@@ -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":[]}}
|
||||
@@ -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"}}]}}
|
||||
1
src/resources/acc-A45098176.json
Normal file
1
src/resources/acc-A45098176.json
Normal 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":"R053527662"}},{"HouseReservation":{"reservation_number":"R049981170"}}]}}
|
||||
1
src/resources/res-R012308734.json
Normal file
1
src/resources/res-R012308734.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "HotelReservation":{"reservation_type": "HotelReservation","reservation_number": "R012308734","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"}}
|
||||
1
src/resources/res-R049981170.json
Normal file
1
src/resources/res-R049981170.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "HouseReservation":{"reservation_type": "HouseReservation","reservation_number": "R049981170","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"}}
|
||||
1
src/resources/res-R053527662.json
Normal file
1
src/resources/res-R053527662.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "CabinReservation":{"reservation_type": "CabinReservation","reservation_number": "R053527662","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"}}
|
||||
1
src/resources/res-R204282843.json
Normal file
1
src/resources/res-R204282843.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "CabinReservation":{"reservation_type": "CabinReservation","reservation_number": "R204282843","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"}}
|
||||
@@ -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"}}
|
||||
@@ -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"}}
|
||||
@@ -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"}}
|
||||
@@ -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"}}
|
||||
Reference in New Issue
Block a user