Skip to content

Commit

Permalink
Merge pull request #255 from zhixianggg/branch-parsing
Browse files Browse the repository at this point in the history
Check for Customer and Phone tags in OrderContainsKeywordsPredicate
  • Loading branch information
zhixianggg authored Nov 5, 2019
2 parents ce65d86 + 8276ae1 commit 43bb04f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public class AddOrderCommand extends UndoableCommand {
+ PREFIX_TAG + "Urgent ";

public static final String MESSAGE_SUCCESS = "New order added: %1$s";
public static final String MESSAGE_DUPLICATE_ORDER = "This order already exists in SML.";
public static final String MESSAGE_DUPLICATE_ORDER = "This order already exists in SML. "
+ "The phone that you are trying to add is part of another order. ";

private final Index toAddCustomerIndex;
private final Index toAddPhoneIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public boolean test(Order order) {
order.getCustomer().getContactNumber().toString(), keyword)
|| StringUtil.containsWordIgnoreCase(
order.getCustomer().getEmail().toString(), keyword)
|| order.getCustomer().getTags().stream().anyMatch(tag ->
StringUtil.containsWordIgnoreCase(tag.toString(), keyword))

|| StringUtil.containsWordIgnoreCase(order.getPhone().getCapacity().toString(), keyword)
|| StringUtil.containsWordIgnoreCase(order.getPhone().getColour().toString(), keyword)
Expand All @@ -38,6 +40,8 @@ public boolean test(Order order) {
|| StringUtil.containsWordIgnoreCase(order.getPhone().getBrand().toString(), keyword)
|| StringUtil.containsWordIgnoreCase(order.getPhone().getSerialNumber().toString(), keyword)
|| StringUtil.containsWordIgnoreCase(order.getPhone().getCost().toString(), keyword)
|| order.getPhone().getTags().stream().anyMatch(tag ->
StringUtil.containsWordIgnoreCase(tag.toString(), keyword))

|| StringUtil.containsWordIgnoreCase(order.getId().toString(), keyword)
|| StringUtil.containsWordIgnoreCase(order.getPrice().toString(), keyword)
Expand Down
30 changes: 25 additions & 5 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import seedu.address.logic.commands.editcommand.EditPhoneCommand.EditPhoneDescriptor;
import seedu.address.logic.commands.editcommand.EditScheduleCommand.EditScheduleDescriptor;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.AddressBook;
import seedu.address.model.DataBook;
import seedu.address.model.Model;
import seedu.address.model.customer.Customer;
import seedu.address.model.customer.predicates.CustomerContainsKeywordsPredicate;
Expand All @@ -48,6 +48,7 @@
import seedu.address.model.phone.Capacity;
import seedu.address.model.phone.Phone;
import seedu.address.model.phone.predicates.PhoneContainsKeywordsPredicate;
import seedu.address.model.schedule.Schedule;
import seedu.address.testutil.EditCustomerDescriptorBuilder;
import seedu.address.testutil.EditOrderDescriptorBuilder;
import seedu.address.testutil.EditPersonDescriptorBuilder;
Expand Down Expand Up @@ -376,13 +377,32 @@ public static void assertCommandSuccess(Command command, Model actualModel, Undo
public static void assertCommandFailure(Command command, Model actualModel, String expectedMessage) {
// we are unable to defensively copy the model for comparison later, so we can
// only do so by copying its components.
AddressBook expectedAddressBook = new AddressBook(actualModel.getAddressBook());
List<Person> expectedFilteredList = new ArrayList<>(actualModel.getFilteredPersonList());
DataBook<Customer> expectedCustomerBook = new DataBook<>(actualModel.getCustomerBook());
DataBook<Phone> expectedPhoneBook = new DataBook<>(actualModel.getPhoneBook());
DataBook<Order> expectedOrderBook = new DataBook<>(actualModel.getOrderBook());
DataBook<Schedule> expectedScheduleBook = new DataBook<>(actualModel.getScheduleBook());
DataBook<Order> expectedArchivedOrderBook = new DataBook<>(actualModel.getArchivedOrderBook());


List<Customer> expectedFilteredCustomerList = new ArrayList<>(actualModel.getFilteredCustomerList());
List<Phone> expectedFilteredPhoneList = new ArrayList<>(actualModel.getFilteredPhoneList());
List<Order> expectedFilteredOrderList = new ArrayList<>(actualModel.getFilteredOrderList());
List<Schedule> expectedFilteredScheduleList = new ArrayList<>(actualModel.getFilteredScheduleList());
List<Order> expectedFilteredArchivedOrderList = new ArrayList<>(actualModel.getFilteredArchivedOrderList());

assertThrows(CommandException.class, expectedMessage, () -> command.execute(actualModel, new CommandHistory(),
new UndoRedoStack()));
assertEquals(expectedAddressBook, actualModel.getAddressBook());
assertEquals(expectedFilteredList, actualModel.getFilteredPersonList());
assertEquals(expectedCustomerBook, actualModel.getCustomerBook());
assertEquals(expectedPhoneBook, actualModel.getPhoneBook());
assertEquals(expectedOrderBook, actualModel.getOrderBook());
assertEquals(expectedScheduleBook, actualModel.getScheduleBook());
assertEquals(expectedArchivedOrderBook, actualModel.getArchivedOrderBook());

assertEquals(expectedFilteredCustomerList, actualModel.getFilteredCustomerList());
assertEquals(expectedFilteredPhoneList, actualModel.getFilteredPhoneList());
assertEquals(expectedFilteredOrderList, actualModel.getFilteredOrderList());
assertEquals(expectedFilteredScheduleList, actualModel.getFilteredScheduleList());
assertEquals(expectedFilteredArchivedOrderList, actualModel.getFilteredArchivedOrderList());
}
/**
* Updates {@code model}'s filtered list to show only the person at the given {@code targetIndex} in the
Expand Down

0 comments on commit 43bb04f

Please sign in to comment.