From d2fab83fcee2eb17431cdc57cae406749e37552b Mon Sep 17 00:00:00 2001 From: ethan-goh Date: Mon, 14 Oct 2024 00:39:08 +0800 Subject: [PATCH 01/14] Change EditCommand to identify target student with studentID instead of index, yet to fix the corresponding tests and affected files --- src/main/java/seedu/address/logic/Messages.java | 1 + .../address/logic/commands/EditCommand.java | 16 +++++++++++----- .../address/logic/parser/EditCommandParser.java | 7 ++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 9b8087ce0a6..550521103dd 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -15,6 +15,7 @@ public class Messages { 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_INDEX = "The person index provided is invalid"; + public static final String MESSAGE_INVALID_PERSON_DISPLAYED_STUDENTID = "The person studentID 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): "; diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index c2336660b13..b76db917e28 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.stream.Collectors; import seedu.address.commons.core.index.Index; import seedu.address.commons.util.CollectionUtil; @@ -55,14 +56,14 @@ public class EditCommand extends Command { public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book."; - private final Index index; + private final StudentId index; private final EditPersonDescriptor editPersonDescriptor; /** * @param index of the person in the filtered person list to edit * @param editPersonDescriptor details to edit the person with */ - public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) { + public EditCommand(StudentId index, EditPersonDescriptor editPersonDescriptor) { requireNonNull(index); requireNonNull(editPersonDescriptor); @@ -75,11 +76,16 @@ public CommandResult execute(Model model) throws CommandException { requireNonNull(model); List lastShownList = model.getFilteredPersonList(); - if (index.getZeroBased() >= lastShownList.size()) { + + /*if (index.getZeroBased() >= lastShownList.size()) { throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); - } + }*/ + Person personToEdit = lastShownList.stream() + .filter(person -> person.getStudentId().equals(index)) + .findFirst() + .orElseThrow(() -> new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_STUDENTID));; - Person personToEdit = lastShownList.get(index.getZeroBased()); + /*Person personToEdit = lastShownList.get(index.getZeroBased());*/ Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor); if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) { diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 0d20eef615f..912a87d3908 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -14,6 +14,7 @@ import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.StudentId; /** @@ -32,10 +33,10 @@ public EditCommand parse(String args) throws ParseException { ArgumentTokenizer.tokenize(args, PREFIX_STUDENTID, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_COURSE, PREFIX_TAG); - Index index; + StudentId studentId; try { - index = ParserUtil.parseIndex(argMultimap.getPreamble()); + studentId = ParserUtil.parseStudentId(argMultimap.getPreamble()); } catch (ParseException pe) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe); } @@ -72,7 +73,7 @@ public EditCommand parse(String args) throws ParseException { throw new ParseException(EditCommand.MESSAGE_NOT_EDITED); } - return new EditCommand(index, editPersonDescriptor); + return new EditCommand(studentId, editPersonDescriptor); } /*/** From d7f544550e407809c2a299c1f9b142116745c7a8 Mon Sep 17 00:00:00 2001 From: ethan-goh Date: Mon, 14 Oct 2024 03:11:31 +0800 Subject: [PATCH 02/14] Edit test files to reflect new format of EditCommand --- .../address/logic/commands/EditCommand.java | 16 ++-- .../logic/commands/EditCommandTest.java | 55 ++++++++------ .../logic/parser/AddressBookParserTest.java | 5 +- .../logic/parser/EditCommandParserTest.java | 76 +++++++++---------- 4 files changed, 79 insertions(+), 73 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index b76db917e28..2d79b387c48 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -56,18 +56,18 @@ public class EditCommand extends Command { public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book."; - private final StudentId index; + private final StudentId studentId; private final EditPersonDescriptor editPersonDescriptor; /** - * @param index of the person in the filtered person list to edit + * @param studentId of the person in the filtered person list to edit * @param editPersonDescriptor details to edit the person with */ - public EditCommand(StudentId index, EditPersonDescriptor editPersonDescriptor) { - requireNonNull(index); + public EditCommand(StudentId studentId, EditPersonDescriptor editPersonDescriptor) { + requireNonNull(studentId); requireNonNull(editPersonDescriptor); - this.index = index; + this.studentId = studentId; this.editPersonDescriptor = new EditPersonDescriptor(editPersonDescriptor); } @@ -81,7 +81,7 @@ public CommandResult execute(Model model) throws CommandException { throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); }*/ Person personToEdit = lastShownList.stream() - .filter(person -> person.getStudentId().equals(index)) + .filter(person -> person.getStudentId().equals(studentId)) .findFirst() .orElseThrow(() -> new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_STUDENTID));; @@ -126,14 +126,14 @@ public boolean equals(Object other) { } EditCommand otherEditCommand = (EditCommand) other; - return index.equals(otherEditCommand.index) + return studentId.equals(otherEditCommand.studentId) && editPersonDescriptor.equals(otherEditCommand.editPersonDescriptor); } @Override public String toString() { return new ToStringBuilder(this) - .add("index", index) + .add("studentId", studentId) .add("editPersonDescriptor", editPersonDescriptor) .toString(); } diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 6dd8729bf3a..591e4540361 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -25,6 +25,7 @@ import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; import seedu.address.model.person.Person; +import seedu.address.model.person.StudentId; import seedu.address.testutil.EditPersonDescriptorBuilder; import seedu.address.testutil.PersonBuilder; @@ -39,7 +40,8 @@ public class EditCommandTest { public void execute_allFieldsSpecifiedUnfilteredList_success() { Person editedPerson = new PersonBuilder().build(); EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(editedPerson).build(); - EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON, descriptor); + StudentId studentId = model.getFilteredPersonList().get(0).getStudentId(); + EditCommand editCommand = new EditCommand(studentId, descriptor); String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); @@ -51,8 +53,8 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() { @Test public void execute_someFieldsSpecifiedUnfilteredList_success() { - Index indexLastPerson = Index.fromOneBased(model.getFilteredPersonList().size()); - Person lastPerson = model.getFilteredPersonList().get(indexLastPerson.getZeroBased()); + Person lastPerson = model.getFilteredPersonList().get(model.getFilteredPersonList().size() - 1); + StudentId lastPersonId = lastPerson.getStudentId(); PersonBuilder personInList = new PersonBuilder(lastPerson); Person editedPerson = personInList.withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB) @@ -60,7 +62,7 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB) .withPhone(VALID_PHONE_BOB).withTag(VALID_TAG_TUTOR).build(); - EditCommand editCommand = new EditCommand(indexLastPerson, descriptor); + EditCommand editCommand = new EditCommand(lastPersonId, descriptor); String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); @@ -72,7 +74,8 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { @Test public void execute_noFieldSpecifiedUnfilteredList_success() { - EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON, new EditPersonDescriptor()); + StudentId studentId = model.getFilteredPersonList().get(0).getStudentId(); + EditCommand editCommand = new EditCommand(studentId, new EditPersonDescriptor()); Person editedPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); @@ -88,7 +91,8 @@ public void execute_filteredList_success() { Person personInFilteredList = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); Person editedPerson = new PersonBuilder(personInFilteredList).withName(VALID_NAME_BOB).build(); - EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON, + StudentId studentId = personInFilteredList.getStudentId(); + EditCommand editCommand = new EditCommand(studentId, new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build()); String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); @@ -101,9 +105,11 @@ public void execute_filteredList_success() { @Test public void execute_duplicatePersonUnfilteredList_failure() { - Person firstPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + Person firstPerson = model.getFilteredPersonList().get(0); + Person secondPerson = model.getFilteredPersonList().get(1); EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(firstPerson).build(); - EditCommand editCommand = new EditCommand(INDEX_SECOND_PERSON, descriptor); + StudentId secondPersonId = secondPerson.getStudentId(); + EditCommand editCommand = new EditCommand(secondPersonId, descriptor); assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_PERSON); } @@ -111,20 +117,21 @@ public void execute_duplicatePersonUnfilteredList_failure() { @Test public void execute_duplicatePersonFilteredList_failure() { showPersonAtIndex(model, INDEX_FIRST_PERSON); + StudentId studentId = model.getFilteredPersonList().get(0).getStudentId(); // edit person in filtered list into a duplicate in address book Person personInList = model.getAddressBook().getPersonList().get(INDEX_SECOND_PERSON.getZeroBased()); - EditCommand editCommand = new EditCommand(INDEX_FIRST_PERSON, + EditCommand editCommand = new EditCommand(studentId, new EditPersonDescriptorBuilder(personInList).build()); assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_PERSON); } @Test - public void execute_invalidPersonIndexUnfilteredList_failure() { - Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1); + public void execute_invalidPersonIdUnfilteredList_failure() { + StudentId invalidStudentId = new StudentId("invalid-id-123"); EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build(); - EditCommand editCommand = new EditCommand(outOfBoundIndex, descriptor); + EditCommand editCommand = new EditCommand(invalidStudentId, descriptor); assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); } @@ -136,23 +143,23 @@ public void execute_invalidPersonIndexUnfilteredList_failure() { @Test public void execute_invalidPersonIndexFilteredList_failure() { showPersonAtIndex(model, INDEX_FIRST_PERSON); - Index outOfBoundIndex = INDEX_SECOND_PERSON; - // ensures that outOfBoundIndex is still in bounds of address book list - assertTrue(outOfBoundIndex.getZeroBased() < model.getAddressBook().getPersonList().size()); + StudentId invalidStudentId = new StudentId("invalid-id-123"); - EditCommand editCommand = new EditCommand(outOfBoundIndex, + EditCommand editCommand = new EditCommand(invalidStudentId, new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build()); - assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_STUDENTID); } @Test public void equals() { - final EditCommand standardCommand = new EditCommand(INDEX_FIRST_PERSON, DESC_AMY); + StudentId firstPersonId = model.getFilteredPersonList().get(0).getStudentId(); + StudentId secondPersonId = model.getFilteredPersonList().get(1).getStudentId(); + final EditCommand standardCommand = new EditCommand(firstPersonId, DESC_AMY); // same values -> returns true EditPersonDescriptor copyDescriptor = new EditPersonDescriptor(DESC_AMY); - EditCommand commandWithSameValues = new EditCommand(INDEX_FIRST_PERSON, copyDescriptor); + EditCommand commandWithSameValues = new EditCommand(firstPersonId, copyDescriptor); assertTrue(standardCommand.equals(commandWithSameValues)); // same object -> returns true @@ -165,18 +172,18 @@ public void equals() { assertFalse(standardCommand.equals(new ClearCommand())); // different index -> returns false - assertFalse(standardCommand.equals(new EditCommand(INDEX_SECOND_PERSON, DESC_AMY))); + assertFalse(standardCommand.equals(new EditCommand(secondPersonId, DESC_AMY))); // different descriptor -> returns false - assertFalse(standardCommand.equals(new EditCommand(INDEX_FIRST_PERSON, DESC_BOB))); + assertFalse(standardCommand.equals(new EditCommand(firstPersonId, DESC_BOB))); } @Test public void toStringMethod() { - Index index = Index.fromOneBased(1); + StudentId studentId = model.getFilteredPersonList().get(0).getStudentId(); EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor(); - EditCommand editCommand = new EditCommand(index, editPersonDescriptor); - String expected = EditCommand.class.getCanonicalName() + "{index=" + index + ", editPersonDescriptor=" + EditCommand editCommand = new EditCommand(studentId, editPersonDescriptor); + String expected = EditCommand.class.getCanonicalName() + "{studentId=" + studentId + ", editPersonDescriptor=" + editPersonDescriptor + "}"; assertEquals(expected, editCommand.toString()); } diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 618573edfe4..8cb0e622d35 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -60,9 +60,10 @@ public void parseCommand_delete() throws Exception { public void parseCommand_edit() throws Exception { Person person = new PersonBuilder().build(); EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(person).build(); + StudentId studentId = person.getStudentId(); EditCommand command = (EditCommand) parser.parseCommand(EditCommand.COMMAND_WORD + " " - + INDEX_FIRST_PERSON.getOneBased() + " " + PersonUtil.getEditPersonDescriptorDetails(descriptor)); - assertEquals(new EditCommand(INDEX_FIRST_PERSON, descriptor), command); + + studentId + " " + PersonUtil.getEditPersonDescriptorDetails(descriptor)); + assertEquals(new EditCommand(studentId, descriptor), command); } @Test diff --git a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java index e9c12ad96bc..29e7ccf22ee 100644 --- a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java @@ -63,7 +63,7 @@ public void parse_missingParts_failure() { assertParseFailure(parser, VALID_NAME_AMY, MESSAGE_INVALID_FORMAT); // no field specified - assertParseFailure(parser, "1", EditCommand.MESSAGE_NOT_EDITED); + assertParseFailure(parser, "12345678", EditCommand.MESSAGE_NOT_EDITED); // no index and no field specified assertParseFailure(parser, "", MESSAGE_INVALID_FORMAT); @@ -71,94 +71,92 @@ public void parse_missingParts_failure() { @Test public void parse_invalidPreamble_failure() { - // negative index - assertParseFailure(parser, "-5" + NAME_DESC_AMY, MESSAGE_INVALID_FORMAT); - - // zero index - assertParseFailure(parser, "0" + NAME_DESC_AMY, MESSAGE_INVALID_FORMAT); + // invalid id + assertParseFailure(parser, "invalid-id" + NAME_DESC_AMY, StudentId.MESSAGE_CONSTRAINTS); // invalid arguments being parsed as preamble - assertParseFailure(parser, "1 some random string", MESSAGE_INVALID_FORMAT); + assertParseFailure(parser, "12345678 some random string", MESSAGE_INVALID_FORMAT); // invalid prefix being parsed as preamble - assertParseFailure(parser, "1 i/ string", MESSAGE_INVALID_FORMAT); + assertParseFailure(parser, "12345678 i/ string", MESSAGE_INVALID_FORMAT); } @Test public void parse_invalidValue_failure() { - assertParseFailure(parser, "1" + INVALID_STUDENTID_DESC, StudentId.MESSAGE_CONSTRAINTS); // invalid studentID - assertParseFailure(parser, "1" + INVALID_NAME_DESC, Name.MESSAGE_CONSTRAINTS); // invalid name - assertParseFailure(parser, "1" + INVALID_PHONE_DESC, Phone.MESSAGE_CONSTRAINTS); // invalid phone - assertParseFailure(parser, "1" + INVALID_EMAIL_DESC, Email.MESSAGE_CONSTRAINTS); // invalid email - assertParseFailure(parser, "1" + INVALID_ADDRESS_DESC, Address.MESSAGE_CONSTRAINTS); // invalid address - assertParseFailure(parser, "1" + INVALID_COURSE_DESC, Course.MESSAGE_CONSTRAINTS); // invalid studentID - assertParseFailure(parser, "1" + INVALID_TAG_DESC, Tag.MESSAGE_CONSTRAINTS); // invalid tag + assertParseFailure(parser, "12" + INVALID_STUDENTID_DESC, StudentId.MESSAGE_CONSTRAINTS); // invalid studentID + assertParseFailure(parser, "12345678" + INVALID_NAME_DESC, Name.MESSAGE_CONSTRAINTS); // invalid name + assertParseFailure(parser, "12345678" + INVALID_PHONE_DESC, Phone.MESSAGE_CONSTRAINTS); // invalid phone + assertParseFailure(parser, "12345678" + INVALID_EMAIL_DESC, Email.MESSAGE_CONSTRAINTS); // invalid email + assertParseFailure(parser, "12345678" + INVALID_ADDRESS_DESC, Address.MESSAGE_CONSTRAINTS); // invalid address + assertParseFailure(parser, "12345678" + INVALID_COURSE_DESC, Course.MESSAGE_CONSTRAINTS); // invalid studentID + assertParseFailure(parser, "12345678" + INVALID_TAG_DESC, Tag.MESSAGE_CONSTRAINTS); // invalid tag // invalid phone followed by valid email - assertParseFailure(parser, "1" + INVALID_PHONE_DESC + EMAIL_DESC_AMY, Phone.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "12345678" + INVALID_PHONE_DESC + EMAIL_DESC_AMY, Phone.MESSAGE_CONSTRAINTS); // multiple invalid values, but only the first invalid value is captured - assertParseFailure(parser, "1" + INVALID_NAME_DESC + INVALID_EMAIL_DESC + VALID_ADDRESS_AMY + VALID_PHONE_AMY, + assertParseFailure(parser, "12345678" + INVALID_NAME_DESC + INVALID_EMAIL_DESC + VALID_ADDRESS_AMY + VALID_PHONE_AMY, Name.MESSAGE_CONSTRAINTS); } @Test public void parse_allFieldsSpecified_success() { - Index targetIndex = INDEX_SECOND_PERSON; - String userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + TAG_DESC_TUTOR + String studentId = "12345678"; + String userInput = studentId + PHONE_DESC_BOB + TAG_DESC_TUTOR + EMAIL_DESC_AMY + ADDRESS_DESC_AMY + NAME_DESC_AMY + TAG_DESC_STUDENT; EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY) .withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY) .withTag(VALID_TAG_STUDENT).build(); - EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); + EditCommand expectedCommand = new EditCommand(new StudentId(studentId), descriptor); assertParseSuccess(parser, userInput, expectedCommand); } @Test public void parse_someFieldsSpecified_success() { - Index targetIndex = INDEX_FIRST_PERSON; - String userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + EMAIL_DESC_AMY; + String studentId = "12345678"; + String userInput = studentId + PHONE_DESC_BOB + EMAIL_DESC_AMY; EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withPhone(VALID_PHONE_BOB) .withEmail(VALID_EMAIL_AMY).build(); - EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); + EditCommand expectedCommand = new EditCommand(new StudentId(studentId), descriptor); assertParseSuccess(parser, userInput, expectedCommand); } @Test public void parse_oneFieldSpecified_success() { + String studentId = "12345678"; + // name - Index targetIndex = INDEX_THIRD_PERSON; - String userInput = targetIndex.getOneBased() + NAME_DESC_AMY; + String userInput = studentId + NAME_DESC_AMY; EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY).build(); - EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); + EditCommand expectedCommand = new EditCommand(new StudentId(studentId), descriptor); assertParseSuccess(parser, userInput, expectedCommand); // phone - userInput = targetIndex.getOneBased() + PHONE_DESC_AMY; + userInput = studentId + PHONE_DESC_AMY; descriptor = new EditPersonDescriptorBuilder().withPhone(VALID_PHONE_AMY).build(); - expectedCommand = new EditCommand(targetIndex, descriptor); + expectedCommand = new EditCommand(new StudentId(studentId), descriptor); assertParseSuccess(parser, userInput, expectedCommand); // email - userInput = targetIndex.getOneBased() + EMAIL_DESC_AMY; + userInput = studentId + EMAIL_DESC_AMY; descriptor = new EditPersonDescriptorBuilder().withEmail(VALID_EMAIL_AMY).build(); - expectedCommand = new EditCommand(targetIndex, descriptor); + expectedCommand = new EditCommand(new StudentId(studentId), descriptor); assertParseSuccess(parser, userInput, expectedCommand); // address - userInput = targetIndex.getOneBased() + ADDRESS_DESC_AMY; + userInput = studentId + ADDRESS_DESC_AMY; descriptor = new EditPersonDescriptorBuilder().withAddress(VALID_ADDRESS_AMY).build(); - expectedCommand = new EditCommand(targetIndex, descriptor); + expectedCommand = new EditCommand(new StudentId(studentId), descriptor); assertParseSuccess(parser, userInput, expectedCommand); // tags - userInput = targetIndex.getOneBased() + TAG_DESC_STUDENT; + userInput = studentId + TAG_DESC_STUDENT; descriptor = new EditPersonDescriptorBuilder().withTag(VALID_TAG_STUDENT).build(); - expectedCommand = new EditCommand(targetIndex, descriptor); + expectedCommand = new EditCommand(new StudentId(studentId), descriptor); assertParseSuccess(parser, userInput, expectedCommand); } @@ -168,18 +166,18 @@ public void parse_multipleRepeatedFields_failure() { // AddCommandParserTest#parse_repeatedNonTagValue_failure() // valid followed by invalid - Index targetIndex = INDEX_FIRST_PERSON; - String userInput = targetIndex.getOneBased() + INVALID_PHONE_DESC + PHONE_DESC_BOB; + String studentId = "12345678"; + String userInput = studentId + INVALID_PHONE_DESC + PHONE_DESC_BOB; assertParseFailure(parser, userInput, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE)); // invalid followed by valid - userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + INVALID_PHONE_DESC; + userInput = studentId + PHONE_DESC_BOB + INVALID_PHONE_DESC; assertParseFailure(parser, userInput, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE)); // mulltiple valid fields repeated - userInput = targetIndex.getOneBased() + PHONE_DESC_AMY + ADDRESS_DESC_AMY + EMAIL_DESC_AMY + userInput = studentId + PHONE_DESC_AMY + ADDRESS_DESC_AMY + EMAIL_DESC_AMY + TAG_DESC_STUDENT + PHONE_DESC_AMY + ADDRESS_DESC_AMY + EMAIL_DESC_AMY + TAG_DESC_STUDENT + PHONE_DESC_BOB + ADDRESS_DESC_BOB + EMAIL_DESC_BOB + TAG_DESC_TUTOR; @@ -187,7 +185,7 @@ public void parse_multipleRepeatedFields_failure() { Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS)); // multiple invalid values - userInput = targetIndex.getOneBased() + INVALID_PHONE_DESC + INVALID_ADDRESS_DESC + INVALID_EMAIL_DESC + userInput = studentId + INVALID_PHONE_DESC + INVALID_ADDRESS_DESC + INVALID_EMAIL_DESC + INVALID_PHONE_DESC + INVALID_ADDRESS_DESC + INVALID_EMAIL_DESC; assertParseFailure(parser, userInput, From de50525e116370daf5fede9ae13da963d8e6ca9d Mon Sep 17 00:00:00 2001 From: ethan-goh Date: Mon, 14 Oct 2024 15:48:33 +0800 Subject: [PATCH 03/14] Minor fixes to editCommand example message and some checkstyle issues --- .../seedu/address/logic/commands/EditCommand.java | 13 +++---------- .../address/logic/parser/EditCommandParser.java | 15 --------------- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 2d79b387c48..d07d8d06055 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -13,9 +13,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.stream.Collectors; -import seedu.address.commons.core.index.Index; import seedu.address.commons.util.CollectionUtil; import seedu.address.commons.util.ToStringBuilder; import seedu.address.logic.Messages; @@ -38,9 +36,9 @@ public class EditCommand extends Command { public static final String COMMAND_WORD = "edit"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified " - + "by the index number used in the displayed person list. " + + "by the studentId assigned to the corresponding student. " + "Existing values will be overwritten by the input values.\n" - + "Parameters: INDEX (must be a positive integer) " + + "Parameters: STUDENTID (must be a valid and existing 8-digit Student ID) " + "[" + PREFIX_STUDENTID + "STUDENTID] " + "[" + PREFIX_NAME + "NAME] " + "[" + PREFIX_PHONE + "PHONE] " @@ -48,7 +46,7 @@ public class EditCommand extends Command { + "[" + PREFIX_ADDRESS + "ADDRESS] " + "[" + PREFIX_COURSE + " COURSE] " + "[" + PREFIX_TAG + "TAG]...\n" - + "Example: " + COMMAND_WORD + " 1 " + + "Example: " + COMMAND_WORD + " 12345678 " + PREFIX_PHONE + "91234567 " + PREFIX_EMAIL + "johndoe@example.com"; @@ -76,16 +74,11 @@ public CommandResult execute(Model model) throws CommandException { requireNonNull(model); List lastShownList = model.getFilteredPersonList(); - - /*if (index.getZeroBased() >= lastShownList.size()) { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); - }*/ Person personToEdit = lastShownList.stream() .filter(person -> person.getStudentId().equals(studentId)) .findFirst() .orElseThrow(() -> new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_STUDENTID));; - /*Person personToEdit = lastShownList.get(index.getZeroBased());*/ Person editedPerson = createEditedPerson(personToEdit, editPersonDescriptor); if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) { diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 912a87d3908..6f8139fe33a 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -76,19 +76,4 @@ public EditCommand parse(String args) throws ParseException { return new EditCommand(studentId, editPersonDescriptor); } - /*/** - * Parses {@code Collection tags} into a {@code Set} if {@code tags} is non-empty. - * If {@code tags} contain only one element which is an empty string, it will be parsed into a - * {@code Set} containing zero tags. - */ - /*private Optional> parseTagsForEdit(Collection tags) throws ParseException { - assert tags != null; - - if (tags.isEmpty()) { - return Optional.empty(); - } - Collection tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags; - return Optional.of(ParserUtil.parseTags(tagSet)); - }*/ - } From 85a1ec1da085fd4e02b150ac771a3f2180c7d4bc Mon Sep 17 00:00:00 2001 From: ethan-goh Date: Mon, 14 Oct 2024 16:13:30 +0800 Subject: [PATCH 04/14] Fix some testcases and checkstyle errors --- .../address/logic/commands/EditCommand.java | 2 +- .../logic/parser/EditCommandParser.java | 1 - .../logic/commands/EditCommandTest.java | 7 +++--- .../logic/parser/AddressBookParserTest.java | 1 - .../logic/parser/EditCommandParserTest.java | 23 +++++-------------- 5 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index d07d8d06055..c1c506053cf 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -74,7 +74,7 @@ public CommandResult execute(Model model) throws CommandException { requireNonNull(model); List lastShownList = model.getFilteredPersonList(); - Person personToEdit = lastShownList.stream() + Person personToEdit = lastShownList.stream() .filter(person -> person.getStudentId().equals(studentId)) .findFirst() .orElseThrow(() -> new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_STUDENTID));; diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 6f8139fe33a..4fb2b9a7002 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -10,7 +10,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENTID; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; -import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; import seedu.address.logic.parser.exceptions.ParseException; diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 591e4540361..d91af00b729 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -17,7 +17,6 @@ import org.junit.jupiter.api.Test; -import seedu.address.commons.core.index.Index; import seedu.address.logic.Messages; import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; import seedu.address.model.AddressBook; @@ -129,11 +128,11 @@ public void execute_duplicatePersonFilteredList_failure() { @Test public void execute_invalidPersonIdUnfilteredList_failure() { - StudentId invalidStudentId = new StudentId("invalid-id-123"); + StudentId invalidStudentId = new StudentId("99999999"); // id that doesn't exist in the address book EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build(); EditCommand editCommand = new EditCommand(invalidStudentId, descriptor); - assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_STUDENTID); } /** @@ -143,7 +142,7 @@ public void execute_invalidPersonIdUnfilteredList_failure() { @Test public void execute_invalidPersonIndexFilteredList_failure() { showPersonAtIndex(model, INDEX_FIRST_PERSON); - StudentId invalidStudentId = new StudentId("invalid-id-123"); + StudentId invalidStudentId = new StudentId("99999999"); // id that doesn't exist in the address book EditCommand editCommand = new EditCommand(invalidStudentId, new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build()); diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 8cb0e622d35..f8b6030e85f 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -6,7 +6,6 @@ import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND; import static seedu.address.logic.parser.CliSyntax.PREFIX_STUDENTID; import static seedu.address.testutil.Assert.assertThrows; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; import java.util.Arrays; import java.util.List; diff --git a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java index 29e7ccf22ee..e5e02c76051 100644 --- a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java @@ -29,13 +29,9 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; -import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; -import static seedu.address.testutil.TypicalIndexes.INDEX_THIRD_PERSON; import org.junit.jupiter.api.Test; -import seedu.address.commons.core.index.Index; import seedu.address.logic.Messages; import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; @@ -72,7 +68,7 @@ public void parse_missingParts_failure() { @Test public void parse_invalidPreamble_failure() { // invalid id - assertParseFailure(parser, "invalid-id" + NAME_DESC_AMY, StudentId.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "invalid-id" + NAME_DESC_AMY, MESSAGE_INVALID_FORMAT); // invalid arguments being parsed as preamble assertParseFailure(parser, "12345678 some random string", MESSAGE_INVALID_FORMAT); @@ -83,7 +79,9 @@ public void parse_invalidPreamble_failure() { @Test public void parse_invalidValue_failure() { - assertParseFailure(parser, "12" + INVALID_STUDENTID_DESC, StudentId.MESSAGE_CONSTRAINTS); // invalid studentID + assertParseFailure(parser, "12" + INVALID_STUDENTID_DESC, MESSAGE_INVALID_FORMAT); // invalid studentID preamble + assertParseFailure(parser, "12345678" + + INVALID_STUDENTID_DESC, StudentId.MESSAGE_CONSTRAINTS); // invalid studentID assertParseFailure(parser, "12345678" + INVALID_NAME_DESC, Name.MESSAGE_CONSTRAINTS); // invalid name assertParseFailure(parser, "12345678" + INVALID_PHONE_DESC, Phone.MESSAGE_CONSTRAINTS); // invalid phone assertParseFailure(parser, "12345678" + INVALID_EMAIL_DESC, Email.MESSAGE_CONSTRAINTS); // invalid email @@ -95,8 +93,8 @@ public void parse_invalidValue_failure() { assertParseFailure(parser, "12345678" + INVALID_PHONE_DESC + EMAIL_DESC_AMY, Phone.MESSAGE_CONSTRAINTS); // multiple invalid values, but only the first invalid value is captured - assertParseFailure(parser, "12345678" + INVALID_NAME_DESC + INVALID_EMAIL_DESC + VALID_ADDRESS_AMY + VALID_PHONE_AMY, - Name.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "12345678" + INVALID_NAME_DESC + INVALID_EMAIL_DESC + VALID_ADDRESS_AMY + + VALID_PHONE_AMY, Name.MESSAGE_CONSTRAINTS); } @Test @@ -192,14 +190,5 @@ public void parse_multipleRepeatedFields_failure() { Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS)); } - /*@Test - public void parse_resetTags_success() { - Index targetIndex = INDEX_THIRD_PERSON; - String userInput = targetIndex.getOneBased() + TAG_EMPTY; - EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withTag(VALID_TAG_STUDENT).build(); - EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); - - assertParseSuccess(parser, userInput, expectedCommand); - }*/ } From b81f7e4f6e4dc6fef619541e249376737742e06c Mon Sep 17 00:00:00 2001 From: JYL27 Date: Tue, 15 Oct 2024 11:57:18 +0800 Subject: [PATCH 05/14] Fix Ui to display Student ID --- src/main/java/seedu/address/ui/PersonCard.java | 3 +++ src/main/resources/view/PersonListCard.fxml | 1 + 2 files changed, 4 insertions(+) diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 1a13e765b8d..9ea61fb872f 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -31,6 +31,8 @@ public class PersonCard extends UiPart { @FXML private Label id; @FXML + private Label studentid; + @FXML private Label phone; @FXML private Label address; @@ -49,6 +51,7 @@ public PersonCard(Person person, int displayedIndex) { this.person = person; id.setText(displayedIndex + ". "); name.setText(person.getName().fullName); + studentid.setText("StudentID: " + person.getStudentId().toString()); phone.setText(person.getPhone().value); address.setText(person.getAddress().value); email.setText(person.getEmail().value); diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index b1d11bf33b5..f5308d3032f 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -28,6 +28,7 @@