updates
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
|
||||
package lodge;
|
||||
|
||||
import lodge.data.Account;
|
||||
import lodge.data.Address;
|
||||
import lodge.data.EmailAddress;
|
||||
import lodge.datamodel.Account;
|
||||
import lodge.datamodel.Address;
|
||||
import lodge.datamodel.EmailAddress;
|
||||
import lodge.reservationsystem.AccomodationManager;
|
||||
|
||||
/**
|
||||
@@ -9,18 +9,17 @@ import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import lodge.data.Account;
|
||||
import lodge.data.Address;
|
||||
import lodge.data.DuplicateObjectException;
|
||||
import lodge.data.EmailAddress;
|
||||
import lodge.data.ReservationStatusEnum;
|
||||
import lodge.reservation.IReservation;
|
||||
import lodge.reservation.Reservation;
|
||||
import lodge.datamodel.Account;
|
||||
import lodge.datamodel.Address;
|
||||
import lodge.datamodel.DuplicateObjectException;
|
||||
import lodge.datamodel.EmailAddress;
|
||||
import lodge.datamodel.IReservation;
|
||||
import lodge.datamodel.Reservation;
|
||||
import lodge.datamodel.ReservationStatusEnum;
|
||||
import lodge.reservationsystem.AccomodationManager;
|
||||
import lodge.reservationsystem.CabinReservation;
|
||||
import lodge.reservationsystem.HotelReservation;
|
||||
import lodge.reservationsystem.HouseReservation;
|
||||
|
||||
/**
|
||||
* The Tests for the ReservationSystem Module
|
||||
*
|
||||
@@ -58,7 +57,6 @@ public final class TestReservations {
|
||||
|
||||
mgr.UpdateAccount(acct);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
// Configure data repository
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.data;
|
||||
package lodge.datamodel;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
@@ -12,9 +12,8 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import lodge.reservation.IReservation;
|
||||
import lodge.reservation.Reservation;
|
||||
import lodge.reservationsystem.DataRepository;
|
||||
|
||||
/**
|
||||
* Concrete account data class for account json storage record.
|
||||
* Collects account attributes, and hash instance to enforce uniqueness.
|
||||
@@ -41,11 +40,25 @@ public class Account {
|
||||
this.email_address = email_address;
|
||||
}
|
||||
|
||||
public Account(String phone_number, Address mailing_address, EmailAddress email_address) {
|
||||
this(AccountList.accountSerial(phone_number, mailing_address, email_address),
|
||||
phone_number,
|
||||
mailing_address,
|
||||
email_address);
|
||||
public Account(String phone_number, Address mailing_address, EmailAddress email_address)
|
||||
throws IllegalArgumentException {
|
||||
if (phone_number == null) {
|
||||
throw new IllegalArgumentException(String.format("%s %s", "Account: requires phone number",
|
||||
mailing_address.toString()));
|
||||
}
|
||||
if (mailing_address == null) {
|
||||
throw new IllegalArgumentException(String.format("%s %s", "Account: requires mailing address",
|
||||
phone_number.substring(phone_number.length() - 4)));
|
||||
}
|
||||
if (email_address == null) {
|
||||
throw new IllegalArgumentException(String.format("%s %s", "Account: requires phone number",
|
||||
mailing_address.toString()));
|
||||
}
|
||||
|
||||
this.account_number = AccountList.accountSerial(phone_number, mailing_address, email_address);
|
||||
this.phone_number = phone_number;
|
||||
this.mailing_address = mailing_address;
|
||||
this.email_address = email_address;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -157,6 +170,22 @@ public class Account {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean checkValid() throws IllegalArgumentException {
|
||||
if (email_address == null) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("not valid, email_address %s", this.getAccount_number()));
|
||||
}
|
||||
if (phone_number == null) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("not valid, phone_number: %s", this.getAccount_number()));
|
||||
}
|
||||
if (getMailing_address() == null) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("not valid, mailing_address: %s", this.getAccount_number()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void update(Account acct) {
|
||||
this.setEmail_address(acct.email_address);
|
||||
this.setPhone_number(acct.phone_number);
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.data;
|
||||
package lodge.datamodel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -10,8 +10,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import lodge.reservation.IReservation;
|
||||
|
||||
public class AccountList extends ArrayList<Account> {
|
||||
|
||||
public static String accountSerial(String phone_number, Address mailing_address, EmailAddress email_address) {
|
||||
@@ -2,13 +2,10 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.data;
|
||||
package lodge.datamodel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import lodge.reservation.IReservation;
|
||||
import lodge.reservation.Reservation;
|
||||
|
||||
class AccountReservationList extends ArrayList<IReservation> {
|
||||
|
||||
private static String reservationSerial(Reservation reservation) {
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.data;
|
||||
package lodge.datamodel;
|
||||
|
||||
public final class Address{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.data;
|
||||
package lodge.datamodel;
|
||||
|
||||
public class DuplicateObjectException extends RuntimeException {
|
||||
public DuplicateObjectException() {
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.data;
|
||||
package lodge.datamodel;
|
||||
|
||||
public class EmailAddress{
|
||||
String email_address;
|
||||
@@ -1,6 +1,4 @@
|
||||
package lodge.reservation;
|
||||
|
||||
import lodge.data.Address;
|
||||
package lodge.datamodel;
|
||||
|
||||
public interface IReservation {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.data;
|
||||
package lodge.datamodel;
|
||||
|
||||
public class IllegalOperationException extends RuntimeException {
|
||||
public IllegalOperationException () {
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.data;
|
||||
package lodge.datamodel;
|
||||
|
||||
public enum KitchenTypeEnum {
|
||||
None, Kitchenette, FullKitchen;
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.reservation;
|
||||
package lodge.datamodel;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
@@ -12,10 +12,6 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import lodge.data.Address;
|
||||
import lodge.data.IllegalOperationException;
|
||||
import lodge.data.KitchenTypeEnum;
|
||||
import lodge.data.ReservationStatusEnum;
|
||||
import lodge.reservationsystem.DataRepository;
|
||||
|
||||
public abstract class Reservation implements IReservation{
|
||||
@@ -2,7 +2,7 @@
|
||||
* license: GPLv3
|
||||
* lodge.reservationsystem
|
||||
*/
|
||||
package lodge.data;
|
||||
package lodge.datamodel;
|
||||
|
||||
public enum ReservationStatusEnum {
|
||||
Draft,
|
||||
@@ -4,17 +4,20 @@
|
||||
*/
|
||||
package lodge.reservationsystem;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import lodge.data.Account;
|
||||
import lodge.data.AccountList;
|
||||
import lodge.data.Address;
|
||||
import lodge.data.EmailAddress;
|
||||
import lodge.reservation.IReservation;
|
||||
import lodge.reservation.Reservation;
|
||||
import lodge.datamodel.Account;
|
||||
import lodge.datamodel.AccountList;
|
||||
import lodge.datamodel.Address;
|
||||
import lodge.datamodel.DuplicateObjectException;
|
||||
import lodge.datamodel.EmailAddress;
|
||||
import lodge.datamodel.IReservation;
|
||||
import lodge.datamodel.IllegalOperationException;
|
||||
import lodge.datamodel.Reservation;
|
||||
|
||||
public final class AccomodationManager {
|
||||
|
||||
@@ -33,7 +36,7 @@ public final class AccomodationManager {
|
||||
DataRepository.setDataStoreRoot(home);
|
||||
}
|
||||
|
||||
public final void loadAll() throws Exception {
|
||||
public final void loadAll()throws IOException,IllegalArgumentException,IllegalOperationException,DuplicateObjectException{
|
||||
accounts.clear();
|
||||
// walk directories
|
||||
Path rootDir = Paths.get(DataRepository.getPath());
|
||||
@@ -42,12 +45,13 @@ public final class AccomodationManager {
|
||||
}
|
||||
|
||||
// Load / Deserialize Account
|
||||
protected void load(Path file) throws Exception {
|
||||
protected void load(Path file) throws IOException,IllegalArgumentException,IllegalOperationException,DuplicateObjectException {
|
||||
|
||||
Account account = DataRepository.LoadAccount(file);
|
||||
if (account == null) {
|
||||
System.out.println(String.format("%s", file.toString()));
|
||||
System.out.println(String.format("No Account: %s", file.toString()));
|
||||
} else {
|
||||
account.checkValid();
|
||||
accounts.add(account);
|
||||
}
|
||||
}
|
||||
@@ -7,9 +7,9 @@ package lodge.reservationsystem;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import lodge.data.Address;
|
||||
import lodge.data.KitchenTypeEnum;
|
||||
import lodge.reservation.Reservation;
|
||||
import lodge.datamodel.Address;
|
||||
import lodge.datamodel.KitchenTypeEnum;
|
||||
import lodge.datamodel.Reservation;
|
||||
|
||||
/**
|
||||
* Concrete reservation data class for reservation storage record
|
||||
@@ -17,12 +17,13 @@ import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import lodge.data.Address;
|
||||
import lodge.data.EmailAddress;
|
||||
import lodge.data.Account;
|
||||
import lodge.data.KitchenTypeEnum;
|
||||
import lodge.data.ReservationStatusEnum;
|
||||
import lodge.reservation.Reservation;
|
||||
|
||||
import lodge.datamodel.Account;
|
||||
import lodge.datamodel.Address;
|
||||
import lodge.datamodel.EmailAddress;
|
||||
import lodge.datamodel.KitchenTypeEnum;
|
||||
import lodge.datamodel.Reservation;
|
||||
import lodge.datamodel.ReservationStatusEnum;
|
||||
|
||||
public final class DataRepository {
|
||||
// SINGLETON CLASS
|
||||
@@ -162,7 +163,7 @@ public final class DataRepository {
|
||||
}
|
||||
|
||||
private static void loadReservation(Account ac, String reservationType,
|
||||
String reservationNumber) throws NullPointerException, IOException {
|
||||
String reservationNumber) throws IOException {
|
||||
String filename = String.format("rsv-%s.json", reservationNumber);
|
||||
Path basePath = Paths.get(getPath());
|
||||
Path resolvedPath = basePath.resolve(filename);
|
||||
@@ -8,9 +8,9 @@ import java.time.LocalTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import lodge.data.Address;
|
||||
import lodge.data.KitchenTypeEnum;
|
||||
import lodge.reservation.Reservation;
|
||||
import lodge.datamodel.Address;
|
||||
import lodge.datamodel.KitchenTypeEnum;
|
||||
import lodge.datamodel.Reservation;
|
||||
|
||||
/**
|
||||
* Concrete reservation data class for reservation storage record
|
||||
@@ -7,9 +7,9 @@ package lodge.reservationsystem;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import lodge.data.Address;
|
||||
import lodge.data.KitchenTypeEnum;
|
||||
import lodge.reservation.Reservation;
|
||||
import lodge.datamodel.Address;
|
||||
import lodge.datamodel.KitchenTypeEnum;
|
||||
import lodge.datamodel.Reservation;
|
||||
|
||||
/**
|
||||
* Concrete reservation data class for reservation storage record
|
||||
@@ -1 +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"}},"reservations":[{"CabinReservation":{"reservation_number":"R0535276622"}},{"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"}},"reservations":[]}}
|
||||
Reference in New Issue
Block a user