diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 3d37b346343..4d599c0f685 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -15,13 +15,12 @@ public class Messages { public static final String MESSAGE_NO_SUCH_ATTRIBUTE = "No such attribute(s) found: "; public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command"; public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; - public static final String MESSAGE_INVALID_PERSON_DISPLAYED_UUID = "The person UUID provided is invalid."; public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!"; public static final String MESSAGE_DUPLICATE_FIELDS = "Multiple values specified for the following single-valued field(s): "; + public static final String MESSAGE_INVALID_PERSON_UUID = "The UUID provided is invalid: "; public static final String MESSAGE_MISSING_ATTRIBUTES = "Missing attributes to delete."; - public static final String MESSAGE_SPACES_IN_UUID = "Spaces found in UUID: "; public static final String MESSAGE_INVALID_PREDEFINED_RELATIONSHIP_DESCRIPTOR = "You cannot delete this " + "relationship type. \nType 'listRelations to see your list of relationship types.'"; diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 0c9fd640149..5fdf3b2b4ef 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -38,7 +38,7 @@ public CommandResult execute(Model model) throws CommandException { UUID targetUuid = model.getFullUuid(target); if (targetUuid == null) { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_UUID); + throw new CommandException(Messages.MESSAGE_INVALID_PERSON_UUID); } Person personToDelete = model.getPersonByUuid(targetUuid); diff --git a/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java b/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java index 0454cfcc0ea..c184848f89d 100644 --- a/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/DeleteCommandParser.java @@ -15,6 +15,9 @@ public class DeleteCommandParser implements Parser { * @throws ParseException if the user input does not conform the expected format */ public DeleteCommand parse(String args) throws ParseException { - return new DeleteCommand(args.trim()); + if (!args.trim().startsWith("/")) { + throw new ParseException("Input a UUID prefixed with '/'."); + } + return new DeleteCommand(args.trim().substring(1)); } } diff --git a/src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java b/src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java index 009c1988ce5..6443976ebcf 100644 --- a/src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java +++ b/src/main/java/seedu/address/model/person/NameContainsKeywordsPredicate.java @@ -19,7 +19,8 @@ public NameContainsKeywordsPredicate(List keywords) { @Override public boolean test(Person person) { return keywords.stream().anyMatch(keyword -> - person.getAttributes().stream().anyMatch(attribute -> + StringUtil.containsWordIgnoreCase(person.getUuid().toString().substring(32, 36), keyword) + || person.getAttributes().stream().anyMatch(attribute -> StringUtil.containsWordIgnoreCase(attribute.getValueAsString(), keyword) ) ); diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index 3296ff1cfa5..7c76edb5ad8 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -1,7 +1,7 @@ package seedu.address.logic; import static org.junit.jupiter.api.Assertions.assertEquals; -import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_UUID; +import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_UUID; import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND; import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; @@ -60,8 +60,8 @@ public void execute_invalidCommandFormat_throwsParseException() { @Test public void execute_commandExecutionError_throwsCommandException() { - String deleteCommand = "delete 9"; - assertCommandException(deleteCommand, MESSAGE_INVALID_PERSON_DISPLAYED_UUID); + String deleteCommand = "delete /9"; + assertCommandException(deleteCommand, MESSAGE_INVALID_PERSON_UUID); } @Test diff --git a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java index b05cb77b4d7..17c928e474a 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java @@ -55,7 +55,7 @@ public void execute_validUuid_success() { public void execute_nonRealUuidFilteredList_throwsCommandException() { DeleteCommand deleteCommand = new DeleteCommand("12345"); - assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_UUID); + assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_UUID); } @Test diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index e7ec9f0fbf4..b2c0cf28f26 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -61,7 +61,7 @@ public void parseCommand_clear() throws Exception { @Test public void parseCommand_delete() throws Exception { DeleteCommand command = (DeleteCommand) parser.parseCommand( - DeleteCommand.COMMAND_WORD + " " + ALICE_UUID); + DeleteCommand.COMMAND_WORD + " /" + ALICE_UUID); assertEquals(new DeleteCommand(ALICE_UUID), command); } diff --git a/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java b/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java index 9694e60f15a..6dc5e51f896 100644 --- a/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/DeleteCommandParserTest.java @@ -1,10 +1,12 @@ package seedu.address.logic.parser; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; +import static seedu.address.testutil.Assert.assertThrows; import org.junit.jupiter.api.Test; import seedu.address.logic.commands.DeleteCommand; +import seedu.address.logic.parser.exceptions.ParseException; /** * As we are only doing white-box testing, our test cases do not cover path variations @@ -19,7 +21,12 @@ public class DeleteCommandParserTest { @Test public void parse_validArgs_returnsDeleteCommand() { - assertParseSuccess(parser, "0001", new DeleteCommand("0001")); + assertParseSuccess(parser, "/0001", new DeleteCommand("0001")); + } + + @Test + public void parse_invalidArgs_throwsParseException() { + assertThrows(ParseException.class, () -> parser.parse("0001")); } }