Skip to content

Commit

Permalink
Merge pull request #56 from AY1920S1-CS2103T-W12-3/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
joloong committed Oct 15, 2019
2 parents 462c595 + 8182ce4 commit 02da4b6
Show file tree
Hide file tree
Showing 61 changed files with 1,841 additions and 493 deletions.
45 changes: 23 additions & 22 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.Logic;
import seedu.address.logic.LogicManager;
import seedu.address.model.AddressBook;

import seedu.address.model.BankAccount;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyBankAccount;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.UserPrefs;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.storage.AddressBookStorage;
import seedu.address.storage.JsonAddressBookStorage;
import seedu.address.storage.BankAccountStorage;
import seedu.address.storage.JsonBankAccountStorage;
import seedu.address.storage.JsonUserPrefsStorage;
import seedu.address.storage.Storage;
import seedu.address.storage.StorageManager;
Expand All @@ -48,16 +49,16 @@ public class MainApp extends Application {

@Override
public void init() throws Exception {
logger.info("=============================[ Initializing AddressBook ]===========================");
logger.info("=============================[ Initializing PalPay ]===========================");
super.init();

AppParameters appParameters = AppParameters.parse(getParameters());
config = initConfig(appParameters.getConfigPath());

UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath());
UserPrefs userPrefs = initPrefs(userPrefsStorage);
AddressBookStorage addressBookStorage = new JsonAddressBookStorage(userPrefs.getAddressBookFilePath());
storage = new StorageManager(addressBookStorage, userPrefsStorage);
BankAccountStorage bankAccountStorage = new JsonBankAccountStorage(userPrefs.getBankAccountFilePath());
storage = new StorageManager(bankAccountStorage, userPrefsStorage);

initLogging(config);

Expand All @@ -69,25 +70,25 @@ public void init() throws Exception {
}

/**
* Returns a {@code ModelManager} with the data from {@code storage}'s address book and {@code userPrefs}. <br>
* The data from the sample address book will be used instead if {@code storage}'s address book is not found,
* or an empty address book will be used instead if errors occur when reading {@code storage}'s address book.
* Returns a {@code ModelManager} with the data from {@code storage}'s bank account and {@code userPrefs}. <br>
* The data from the sample bank account will be used instead if {@code storage}'s bank account is not found,
* or an empty bank account will be used instead if errors occur when reading {@code storage}'s bank account.
*/
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
Optional<ReadOnlyAddressBook> addressBookOptional;
ReadOnlyAddressBook initialData;
Optional<ReadOnlyBankAccount> bankAccountOptional;
ReadOnlyBankAccount initialData;
try {
addressBookOptional = storage.readAddressBook();
if (!addressBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample AddressBook");
bankAccountOptional = storage.readBankAccount();
if (!bankAccountOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample BankAccount");
}
initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
initialData = bankAccountOptional.orElseGet(SampleDataUtil::getSampleBankAccount);
} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook");
initialData = new AddressBook();
logger.warning("Data file not in the correct format. Will be starting with an empty BankAccount");
initialData = new BankAccount();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
initialData = new AddressBook();
logger.warning("Problem while reading from the file. Will be starting with an empty BankAccount");
initialData = new BankAccount();
}

return new ModelManager(initialData, userPrefs);
Expand Down Expand Up @@ -167,13 +168,13 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {

@Override
public void start(Stage primaryStage) {
logger.info("Starting AddressBook " + MainApp.VERSION);
logger.info("Starting PalPay " + MainApp.VERSION);
ui.start(primaryStage);
}

@Override
public void stop() {
logger.info("============================ [ Stopping Address Book ] =============================");
logger.info("============================ [ Stopping PalPay ] =============================");
try {
storage.saveUserPrefs(model.getUserPrefs());
} catch (IOException e) {
Expand Down
26 changes: 16 additions & 10 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyBankAccount;
import seedu.address.model.transaction.Transaction;

/**
* API of the Logic component
Expand All @@ -24,19 +25,16 @@ public interface Logic {
CommandResult execute(String commandText) throws CommandException, ParseException;

/**
* Returns the AddressBook.
* Returns the BankAccount.
*
* @see seedu.address.model.Model#getAddressBook()
* @see Model#getBankAccount()
*/
ReadOnlyAddressBook getAddressBook();

/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();
ReadOnlyBankAccount getBankAccount();

/**
* Returns the user prefs' address book file path.
* Returns the user prefs' bank account file path.
*/
Path getAddressBookFilePath();
Path getBankAccountFilePath();

/**
* Returns the user prefs' GUI settings.
Expand All @@ -47,4 +45,12 @@ public interface Logic {
* Set the user prefs' GUI settings.
*/
void setGuiSettings(GuiSettings guiSettings);

/** Returns an unmodifiable view of the filtered list of transactions */
ObservableList<Transaction> getFilteredTransactionList();

/**
* Returns an ObservableList of Transactions
*/
ObservableList<Transaction> getTransactionList();
}
38 changes: 21 additions & 17 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.AddressBookParser;
import seedu.address.logic.parser.BankAccountParser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.ReadOnlyBankAccount;
import seedu.address.model.transaction.Transaction;
import seedu.address.storage.Storage;

/**
Expand All @@ -23,27 +23,26 @@
public class LogicManager implements Logic {
public static final String FILE_OPS_ERROR_MESSAGE = "Could not save data to file: ";
private final Logger logger = LogsCenter.getLogger(LogicManager.class);

private final Model model;
private final Storage storage;
private final AddressBookParser addressBookParser;
private final BankAccountParser bankAccountParser;

public LogicManager(Model model, Storage storage) {
this.model = model;
this.storage = storage;
addressBookParser = new AddressBookParser();
bankAccountParser = new BankAccountParser();
}

@Override
public CommandResult execute(String commandText) throws CommandException, ParseException {
logger.info("----------------[USER COMMAND][" + commandText + "]");

CommandResult commandResult;
Command command = addressBookParser.parseCommand(commandText);
Command command = bankAccountParser.parseCommand(commandText);
commandResult = command.execute(model);

try {
storage.saveAddressBook(model.getAddressBook());
storage.saveBankAccount(model.getBankAccount());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
Expand All @@ -52,18 +51,13 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
}

@Override
public ReadOnlyAddressBook getAddressBook() {
return model.getAddressBook();
public ReadOnlyBankAccount getBankAccount() {
return model.getBankAccount();
}

@Override
public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
}

@Override
public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
public Path getBankAccountFilePath() {
return model.getBankAccountFilePath();
}

@Override
Expand All @@ -75,4 +69,14 @@ public GuiSettings getGuiSettings() {
public void setGuiSettings(GuiSettings guiSettings) {
model.setGuiSettings(guiSettings);
}

@Override
public ObservableList<Transaction> getFilteredTransactionList() {
return model.getFilteredTransactionList();
}

@Override
public ObservableList<Transaction> getTransactionList() {
return model.getFilteredTransactionList();
}
}
5 changes: 0 additions & 5 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ public AddCommand(Person person) {
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.hasPerson(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}

model.addPerson(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static java.util.Objects.requireNonNull;

import seedu.address.model.AddressBook;
import seedu.address.model.BankAccount;
import seedu.address.model.Model;

/**
Expand All @@ -11,13 +11,13 @@
public class ClearCommand extends Command {

public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_SUCCESS = "Address book has been cleared!";
public static final String MESSAGE_SUCCESS = "Bank Account has been cleared!";


@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.setAddressBook(new AddressBook());
model.setBankAccount(new BankAccount());
return new CommandResult(MESSAGE_SUCCESS);
}
}
9 changes: 5 additions & 4 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

import static java.util.Objects.requireNonNull;

import java.util.List;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

/**
* Deletes a person identified using it's displayed index from the address book.
Expand All @@ -33,6 +29,8 @@ public DeleteCommand(Index targetIndex) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
// TODO: FIX
/*
List<Person> lastShownList = model.getFilteredPersonList();
if (targetIndex.getZeroBased() >= lastShownList.size()) {
Expand All @@ -41,7 +39,10 @@ public CommandResult execute(Model model) throws CommandException {
Person personToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePerson(personToDelete);
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete));
*/
return null;
}

@Override
Expand Down
20 changes: 1 addition & 19 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.CollectionUtil;
import seedu.address.logic.commands.exceptions.CommandException;
Expand Down Expand Up @@ -68,22 +65,7 @@ public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Person> lastShownList = model.getFilteredPersonList();

if (index.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Person personToEdit = lastShownList.get(index.getZeroBased());
Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor);

if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}

model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedPerson));
return null;
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/seedu/address/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import static java.util.Objects.requireNonNull;

import seedu.address.commons.core.Messages;
import seedu.address.model.Model;
import seedu.address.model.person.NameContainsKeywordsPredicate;
// import seedu.address.commons.core.Messages;

/**
* Finds and lists all persons in address book whose name contains any of the argument keywords.
Expand All @@ -28,9 +28,10 @@ public FindCommand(NameContainsKeywordsPredicate predicate) {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPersonList(predicate);
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
// model.updateFilteredPersonList(predicate);
return null;
// return new CommandResult(
// String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
}

@Override
Expand Down

0 comments on commit 02da4b6

Please sign in to comment.