Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find UUID feature #148

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.'";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class DeleteCommandParser implements Parser<DeleteCommand> {
* @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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public NameContainsKeywordsPredicate(List<String> 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)
)
);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"));
}

}
Loading