cleanup
This commit is contained in:
@@ -6,10 +6,10 @@ import java.time.ZonedDateTime;
|
|||||||
import lodge.reservationsystem.AccomodationManager;
|
import lodge.reservationsystem.AccomodationManager;
|
||||||
import lodge.reservationsystem.Account;
|
import lodge.reservationsystem.Account;
|
||||||
import lodge.reservationsystem.Address;
|
import lodge.reservationsystem.Address;
|
||||||
import lodge.reservationsystem.EmailAddress;
|
|
||||||
import lodge.reservationsystem.CabinReservation;
|
import lodge.reservationsystem.CabinReservation;
|
||||||
import lodge.reservationsystem.HouseReservation;
|
import lodge.reservationsystem.EmailAddress;
|
||||||
import lodge.reservationsystem.HotelReservation;
|
import lodge.reservationsystem.HotelReservation;
|
||||||
|
import lodge.reservationsystem.HouseReservation;
|
||||||
import lodge.reservationsystem.Reservation;
|
import lodge.reservationsystem.Reservation;
|
||||||
import lodge.reservationsystem.ReservationStatusEnum;
|
import lodge.reservationsystem.ReservationStatusEnum;
|
||||||
|
|
||||||
@@ -17,10 +17,7 @@ public final class TestReservations {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
AccomodationManager mgr = new AccomodationManager();
|
AccomodationManager mgr = new AccomodationManager();
|
||||||
String home = System.getenv("HOMEDRIVE") + System.getenv("HOMEPATH");
|
mgr.setDataStoreRoot(getRepositoryConfig.getPath());
|
||||||
home = home.replace("\\", "/")
|
|
||||||
+ "/workspace/reservationsystem/src/resources";
|
|
||||||
mgr.setDataStoreRoot(home);
|
|
||||||
// 1. Get the list of loaded accounts from Manager
|
// 1. Get the list of loaded accounts from Manager
|
||||||
|
|
||||||
mgr.loadAll();
|
mgr.loadAll();
|
||||||
@@ -122,4 +119,10 @@ public final class TestReservations {
|
|||||||
*/
|
*/
|
||||||
System.out.println("Program Completed.");
|
System.out.println("Program Completed.");
|
||||||
}
|
}
|
||||||
|
public final static class getRepositoryConfig{
|
||||||
|
public final static String getPath(){
|
||||||
|
String home = System.getenv("HOME")!=null? System.getenv("HOME"): System.getenv("HOMEDRIVE") + System.getenv("HOMEPATH");
|
||||||
|
return home.replace('\\', '/') + "/workspace/reservationsystem/src/resources";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public final class AccomodationManager {
|
|||||||
|
|
||||||
// Load / Deserialize Account
|
// Load / Deserialize Account
|
||||||
void load(Path file) throws Exception {
|
void load(Path file) throws Exception {
|
||||||
DataRepository.LoadAccount(file);
|
AddAccount( DataRepository.LoadAccount(file) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public final AccountList retrieveLoadedAccounts() {
|
public final AccountList retrieveLoadedAccounts() {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.SimpleFileVisitor;
|
import java.nio.file.SimpleFileVisitor;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
|
|
||||||
final class DataRepository {
|
final class DataRepository {
|
||||||
@@ -32,19 +31,19 @@ final class DataRepository {
|
|||||||
return getInstance().directoryPath;
|
return getInstance().directoryPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void WalkFileSystemTree(final AccomodationManager manager, Path rootDir) throws IOException {
|
public static void WalkFileSystemTree(final AccomodationManager manager, final Path rootDir) throws IOException {
|
||||||
Files.walkFileTree(rootDir, new SimpleFileVisitor<Path>() {
|
Files.walkFileTree(rootDir, new SimpleFileVisitor<Path>() {
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
|
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) {
|
||||||
System.out.println("File: " + file.toAbsolutePath());
|
System.out.println("File: " + file.toAbsolutePath());
|
||||||
// load account number, and content
|
// load account number, and content
|
||||||
if (attrs.isRegularFile()) {
|
if (attrs.isRegularFile()) {
|
||||||
String namestring = file.getName(file.getNameCount() - 1).toString();
|
final String namestring = file.getName(file.getNameCount() - 1).toString();
|
||||||
if (namestring.endsWith("json")) {
|
if (namestring.endsWith("json")) {
|
||||||
if (namestring.startsWith("acc")) { // * load Account *//
|
if (namestring.startsWith("acc")) { // * load Account *//
|
||||||
try {
|
try {
|
||||||
manager.load(file);
|
manager.load(file);
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +54,7 @@ final class DataRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
|
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) {
|
||||||
System.out.println("Directory: " + dir.toAbsolutePath());
|
System.out.println("Directory: " + dir.toAbsolutePath());
|
||||||
// prepare to load account number
|
// prepare to load account number
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.CONTINUE;
|
||||||
@@ -63,21 +62,21 @@ final class DataRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadAccount(Path file) throws IOException {
|
/**
|
||||||
|
* @param file
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public final static Account LoadAccount(final Path file) throws IOException {
|
||||||
/** @TODO finish loading Account */
|
/** @TODO finish loading Account */
|
||||||
final Gson gson = new Gson();
|
try (BufferedReader in = new BufferedReader(new FileReader(file.toFile(), StandardCharsets.UTF_8));
|
||||||
try (BufferedReader in = new BufferedReader(new FileReader(file.toFile(), StandardCharsets.UTF_8))) {
|
JsonReader jsonReader = new JsonReader(in)) {
|
||||||
JsonReader jsonReader = new JsonReader(in);
|
|
||||||
jsonReader.beginObject();
|
jsonReader.beginObject();
|
||||||
Account ac = null;
|
Account ac = new Account();
|
||||||
Address ad = null;
|
|
||||||
while (jsonReader.hasNext()) {
|
while (jsonReader.hasNext()) {
|
||||||
String name = jsonReader.nextName();
|
final String name = jsonReader.nextName();
|
||||||
String.format("Load Account %s", name);
|
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case "Account":
|
case "Account":
|
||||||
jsonReader.beginObject();
|
jsonReader.beginObject();
|
||||||
ac = new Account();
|
|
||||||
break;
|
break;
|
||||||
case "account_number":
|
case "account_number":
|
||||||
ac.setAccount_number(jsonReader.nextString());
|
ac.setAccount_number(jsonReader.nextString());
|
||||||
@@ -90,8 +89,8 @@ final class DataRepository {
|
|||||||
break;
|
break;
|
||||||
case "Address":
|
case "Address":
|
||||||
jsonReader.beginObject();
|
jsonReader.beginObject();
|
||||||
|
Address ad = new Address();
|
||||||
jsonReader.nextName();
|
jsonReader.nextName();
|
||||||
ad = new Address();
|
|
||||||
ad.setStreet(jsonReader.nextString());
|
ad.setStreet(jsonReader.nextString());
|
||||||
jsonReader.nextName();
|
jsonReader.nextName();
|
||||||
ad.setCity(jsonReader.nextString());
|
ad.setCity(jsonReader.nextString());
|
||||||
@@ -110,7 +109,9 @@ final class DataRepository {
|
|||||||
jsonReader.beginObject();
|
jsonReader.beginObject();
|
||||||
break;
|
break;
|
||||||
case "email":
|
case "email":
|
||||||
ac.setEmail_address(new EmailAddress(jsonReader.nextString()));
|
String s = jsonReader.nextString();
|
||||||
|
s = s != null ? s : "";
|
||||||
|
ac.setEmail_address(new EmailAddress(s));
|
||||||
jsonReader.endObject();
|
jsonReader.endObject();
|
||||||
jsonReader.endObject();
|
jsonReader.endObject();
|
||||||
break;
|
break;
|
||||||
@@ -122,17 +123,18 @@ final class DataRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsonReader.close();
|
jsonReader.close();
|
||||||
|
return ac.account_number.length() > 8 ? ac : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadReservation(JsonReader rdr, Account ac) throws IOException {
|
static void loadReservation(final JsonReader rdr, final Account ac) throws IOException {
|
||||||
AccountReservationList reservation_list = new AccountReservationList();
|
final AccountReservationList reservation_list = new AccountReservationList();
|
||||||
rdr.beginArray();
|
rdr.beginArray();
|
||||||
while (rdr.hasNext()) {
|
while (rdr.hasNext()) {
|
||||||
rdr.beginObject();
|
rdr.beginObject();
|
||||||
String name = rdr.nextName();
|
String name = rdr.nextName();
|
||||||
Reservation rsrv = new HouseReservation(new Address());
|
final Reservation rsrv = new HouseReservation(new Address());
|
||||||
rdr.beginObject();
|
rdr.beginObject();
|
||||||
name = rdr.nextName();
|
name = rdr.nextName();
|
||||||
rsrv.reservation_number = rdr.nextString();
|
rsrv.reservation_number = rdr.nextString();
|
||||||
|
|||||||
@@ -1,36 +1 @@
|
|||||||
{
|
{ "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"}},"reservation_list":[{"HotelReservation":{"reservation_number":"R0123077641"}},{"CabinReservation":{"reservation_number":"R2042828431"}},{"HouseReservation":{"reservation_number":"R0499811708"}}]}}
|
||||||
"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"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"reservation_list": [
|
|
||||||
{
|
|
||||||
"HotelReservation": {
|
|
||||||
"reservation_number": "R0123077641"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"CabinReservation": {
|
|
||||||
"reservation_number": "R2042828431"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"HouseReservation": {
|
|
||||||
"reservation_number": "R0499811708"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +1 @@
|
|||||||
{
|
{ "HotelReservation":{"reservation_type": "HotelReservation","reservation_number": "R0123077641","reservation_status": "Draft","reservation_start_date": "2025-07-05T10:00Z[UTC]","reservation_start_date": "2025-11-30T22:00Z[UTC]","physical_address": "{ "Address":{"street": "400 hotel ave","city": "Maryland City","state": "CA","zip": "20723"}}","mailing_address": "{ "Address":{"street": "400 hotel ave","city": "Maryland City","state": "MD","zip": "20723"}}","kitchen": "None","numberOfBeds": "2","numberOfBedRooms": "1","numberOfBathRooms": "1","numberOfFloors": "1","squareFeet": "450","price": "120.0"}}
|
||||||
"HotelReservation": {
|
|
||||||
"reservation_type": "HotelReservation",
|
|
||||||
"reservation_number": "R0123077641",
|
|
||||||
"reservation_status": "Draft",
|
|
||||||
"reservation_start_date": "2025-07-05T10:00Z[UTC]",
|
|
||||||
"reservation_start_date": "2025-11-30T22:00Z[UTC]",
|
|
||||||
"physical_address": "{ "Address":{"street": "400 hotel ave","city": "Maryland City","state": "CA","zip": "20723"}}",
|
|
||||||
"mailing_address": "{ "Address":{"street": "400 hotel ave","city": "Maryland City","state": "MD","zip": "20723"}}",
|
|
||||||
"kitchen": "None",
|
|
||||||
"numberOfBeds": "2",
|
|
||||||
"numberOfBedRooms": "1",
|
|
||||||
"numberOfBathRooms": "1",
|
|
||||||
"numberOfFloors": "1",
|
|
||||||
"squareFeet": "450",
|
|
||||||
"price": "120.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +1 @@
|
|||||||
{
|
{ "CabinReservation":{"reservation_type": "CabinReservation","reservation_number": "R2042828431","reservation_status": "Draft","reservation_start_date": "2025-09-05T10:00Z[UTC]","reservation_start_date": "2025-11-30T22:00Z[UTC]","physical_address": "{ "Address":{"street": "30 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": "4","numberOfBedRooms": "3","numberOfBathRooms": "1","numberOfFloors": "2","squareFeet": "806","price": "120.0"}}
|
||||||
"CabinReservation": {
|
|
||||||
"reservation_type": "CabinReservation",
|
|
||||||
"reservation_number": "R2042828431",
|
|
||||||
"reservation_status": "Completed",
|
|
||||||
"reservation_start_date": "2025-09-05T10:00Z[UTC]",
|
|
||||||
"reservation_start_date": "2025-11-30T22:00Z[UTC]",
|
|
||||||
"physical_address": "{ "Address":{"street": "30 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": "4",
|
|
||||||
"numberOfBedRooms": "3",
|
|
||||||
"numberOfBathRooms": "1",
|
|
||||||
"numberOfFloors": "2",
|
|
||||||
"squareFeet": "806",
|
|
||||||
"price": "10200.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user