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();
|
||||
|
||||
Reference in New Issue
Block a user