cleanup
This commit is contained in:
@@ -6,10 +6,10 @@ import java.time.ZonedDateTime;
|
||||
import lodge.reservationsystem.AccomodationManager;
|
||||
import lodge.reservationsystem.Account;
|
||||
import lodge.reservationsystem.Address;
|
||||
import lodge.reservationsystem.EmailAddress;
|
||||
import lodge.reservationsystem.CabinReservation;
|
||||
import lodge.reservationsystem.HouseReservation;
|
||||
import lodge.reservationsystem.EmailAddress;
|
||||
import lodge.reservationsystem.HotelReservation;
|
||||
import lodge.reservationsystem.HouseReservation;
|
||||
import lodge.reservationsystem.Reservation;
|
||||
import lodge.reservationsystem.ReservationStatusEnum;
|
||||
|
||||
@@ -17,10 +17,7 @@ public final class TestReservations {
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
AccomodationManager mgr = new AccomodationManager();
|
||||
String home = System.getenv("HOMEDRIVE") + System.getenv("HOMEPATH");
|
||||
home = home.replace("\\", "/")
|
||||
+ "/workspace/reservationsystem/src/resources";
|
||||
mgr.setDataStoreRoot(home);
|
||||
mgr.setDataStoreRoot(getRepositoryConfig.getPath());
|
||||
// 1. Get the list of loaded accounts from Manager
|
||||
|
||||
mgr.loadAll();
|
||||
@@ -122,4 +119,10 @@ public final class TestReservations {
|
||||
*/
|
||||
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
|
||||
void load(Path file) throws Exception {
|
||||
DataRepository.LoadAccount(file);
|
||||
AddAccount( DataRepository.LoadAccount(file) );
|
||||
}
|
||||
|
||||
public final AccountList retrieveLoadedAccounts() {
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
final class DataRepository {
|
||||
@@ -32,19 +31,19 @@ final class DataRepository {
|
||||
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>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
|
||||
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) {
|
||||
System.out.println("File: " + file.toAbsolutePath());
|
||||
// load account number, and content
|
||||
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.startsWith("acc")) { // * load Account *//
|
||||
try {
|
||||
manager.load(file);
|
||||
} catch (Exception e) {
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -55,7 +54,7 @@ final class DataRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
|
||||
public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) {
|
||||
System.out.println("Directory: " + dir.toAbsolutePath());
|
||||
// prepare to load account number
|
||||
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 */
|
||||
final Gson gson = new Gson();
|
||||
try (BufferedReader in = new BufferedReader(new FileReader(file.toFile(), StandardCharsets.UTF_8))) {
|
||||
JsonReader jsonReader = new JsonReader(in);
|
||||
try (BufferedReader in = new BufferedReader(new FileReader(file.toFile(), StandardCharsets.UTF_8));
|
||||
JsonReader jsonReader = new JsonReader(in)) {
|
||||
jsonReader.beginObject();
|
||||
Account ac = null;
|
||||
Address ad = null;
|
||||
Account ac = new Account();
|
||||
while (jsonReader.hasNext()) {
|
||||
String name = jsonReader.nextName();
|
||||
String.format("Load Account %s", name);
|
||||
final String name = jsonReader.nextName();
|
||||
switch (name) {
|
||||
case "Account":
|
||||
jsonReader.beginObject();
|
||||
ac = new Account();
|
||||
break;
|
||||
case "account_number":
|
||||
ac.setAccount_number(jsonReader.nextString());
|
||||
@@ -90,8 +89,8 @@ final class DataRepository {
|
||||
break;
|
||||
case "Address":
|
||||
jsonReader.beginObject();
|
||||
Address ad = new Address();
|
||||
jsonReader.nextName();
|
||||
ad = new Address();
|
||||
ad.setStreet(jsonReader.nextString());
|
||||
jsonReader.nextName();
|
||||
ad.setCity(jsonReader.nextString());
|
||||
@@ -110,7 +109,9 @@ final class DataRepository {
|
||||
jsonReader.beginObject();
|
||||
break;
|
||||
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();
|
||||
break;
|
||||
@@ -122,17 +123,18 @@ final class DataRepository {
|
||||
}
|
||||
}
|
||||
jsonReader.close();
|
||||
return ac.account_number.length() > 8 ? ac : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void loadReservation(JsonReader rdr, Account ac) throws IOException {
|
||||
AccountReservationList reservation_list = new AccountReservationList();
|
||||
static void loadReservation(final JsonReader rdr, final Account ac) throws IOException {
|
||||
final AccountReservationList reservation_list = new AccountReservationList();
|
||||
rdr.beginArray();
|
||||
while (rdr.hasNext()) {
|
||||
rdr.beginObject();
|
||||
String name = rdr.nextName();
|
||||
Reservation rsrv = new HouseReservation(new Address());
|
||||
final Reservation rsrv = new HouseReservation(new Address());
|
||||
rdr.beginObject();
|
||||
name = rdr.nextName();
|
||||
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": "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"
|
||||
}
|
||||
}
|
||||
{ "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"}}
|
||||
Reference in New Issue
Block a user