Skip to content

Commit

Permalink
Add OrderBook Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
zhixianggg committed Oct 16, 2019
1 parent b7cdb2a commit b7debba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
15 changes: 14 additions & 1 deletion src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import seedu.address.model.CustomerBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.OrderBook;
import seedu.address.model.PhoneBook;
import seedu.address.model.ReadOnlyDataBook;
import seedu.address.model.ReadOnlyUserPrefs;
Expand Down Expand Up @@ -96,36 +97,48 @@ public void init() throws Exception {
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
Optional<ReadOnlyDataBook<Customer>> customerBookOptional;
Optional<ReadOnlyDataBook<Phone>> phoneBookOptional;
Optional<ReadOnlyDataBook<Order>> orderBookOptional;

ReadOnlyDataBook<Customer> initialCustomerData;
ReadOnlyDataBook<Phone> initialPhoneData;
ReadOnlyDataBook<Order> initialOrderData;
try {
customerBookOptional = storage.readCustomerBook();
phoneBookOptional = storage.readPhoneBook();
orderBookOptional = storage.readOrderBook();

if (!customerBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample CustomerBook");
}
if (!phoneBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample PhoneBook");
}
if (!orderBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample PhoneBook");
}

initialCustomerData = customerBookOptional.orElseGet(SampleDataUtil::getSampleCustomerBook);
initialPhoneData = phoneBookOptional.orElseGet(SampleDataUtil::getSamplePhoneBook);
initialOrderData = orderBookOptional.orElseGet(SampleDataUtil::getSampleOrderBook);

} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook");
initialPhoneData = new PhoneBook();
initialCustomerData = new CustomerBook();
initialOrderData = new OrderBook();

} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
initialPhoneData = new PhoneBook();
initialCustomerData = new CustomerBook();
initialOrderData = new OrderBook();
}

ReadOnlyDataBook<Customer> customerBook = SampleDataUtil.getSampleCustomerBook();
ReadOnlyDataBook<Phone> phoneBook = SampleDataUtil.getSamplePhoneBook();
ReadOnlyDataBook<Order> orderBook = SampleDataUtil.getSampleOrderBook();

return new ModelManager(initialCustomerData, initialPhoneData, orderBook, new ScheduleBook(), userPrefs);
return new ModelManager(initialCustomerData, initialPhoneData, initialOrderData, new ScheduleBook(), userPrefs);

}

Expand Down
19 changes: 0 additions & 19 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,6 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
try {
storage.saveCustomerBook(model.getCustomerBook());
storage.savePhoneBook(model.getPhoneBook());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
try {
storage.saveCustomerBook(model.getCustomerBook());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
try {
storage.savePhoneBook(model.getPhoneBook());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
try {
storage.saveScheduleBook(model.getScheduleBook());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
try {
storage.saveOrderBook(model.getOrderBook());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
Expand Down

0 comments on commit b7debba

Please sign in to comment.