From c7217adafdde2b1f695d0019595da47e961ab97e Mon Sep 17 00:00:00 2001 From: Ivan Lee <84584280+ivanleekk@users.noreply.github.com> Date: Wed, 18 Oct 2023 10:40:47 +0800 Subject: [PATCH 01/12] Add FilterCommand --- .../logic/commands/FilterCommand.java | 70 ++++++++++++++++++ .../staffsnap/logic/commands/SortCommand.java | 1 + .../logic/parser/ApplicantBookParser.java | 7 +- .../logic/parser/FilterCommandParser.java | 66 +++++++++++++++++ .../logic/parser/SortCommandParser.java | 2 +- .../applicant/CustomFilterPredicate.java | 71 +++++++++++++++++++ 6 files changed, 215 insertions(+), 2 deletions(-) create mode 100644 src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java create mode 100644 src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java create mode 100644 src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java diff --git a/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java b/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java new file mode 100644 index 00000000000..db2c549364e --- /dev/null +++ b/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java @@ -0,0 +1,70 @@ +package seedu.staffsnap.logic.commands; + +import seedu.staffsnap.commons.util.ToStringBuilder; +import seedu.staffsnap.logic.Messages; +import seedu.staffsnap.model.Model; +import seedu.staffsnap.model.applicant.CustomFilterPredicate; + +import static java.util.Objects.requireNonNull; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_POSITION; + +/** + * Finds and lists all applicants in address book whose name contains any of the argument keywords. + * Keyword matching is case-insensitive. + */ +public class FilterCommand extends Command { + + public static final String COMMAND_WORD = "filter"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Filters all applicants who match the descriptor."; + public static final String MESSAGE_FAILURE = "Please add at least one field to filter by. " + + "Possible fields include:" + "\n" + + PREFIX_NAME + " [NAME], " + + PREFIX_EMAIL + " [EMAIL], " + + PREFIX_POSITION + " [POSITION], " + + PREFIX_PHONE + " [PHONE]"; + + private final CustomFilterPredicate predicate; + + public FilterCommand(CustomFilterPredicate predicate) { + this.predicate = predicate; + } + + @Override + public CommandResult execute(Model model) { + requireNonNull(model); + model.updateFilteredApplicantList(predicate); + return new CommandResult( + String.format(Messages.MESSAGE_APPLICANTS_LISTED_OVERVIEW, model.getFilteredApplicantList().size())); + } + + /** + * Checks if the applicant exists. + * @param other Other applicant. + * @return true if equals, false if not equals. + */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof FilterCommand)) { + return false; + } + + FilterCommand otherFilterCommand = (FilterCommand) other; + return predicate.equals(otherFilterCommand.predicate); + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .add("predicate", predicate) + .toString(); + } +} diff --git a/src/main/java/seedu/staffsnap/logic/commands/SortCommand.java b/src/main/java/seedu/staffsnap/logic/commands/SortCommand.java index e14dc3d2a0c..cd7090b0565 100644 --- a/src/main/java/seedu/staffsnap/logic/commands/SortCommand.java +++ b/src/main/java/seedu/staffsnap/logic/commands/SortCommand.java @@ -20,6 +20,7 @@ public class SortCommand extends Command { + "Parameters: " + PREFIX_DESCRIPTOR + "DESCRIPTOR "; public static final String MESSAGE_SUCCESS = "Sorted all Applicants"; + public static final String MESSAGE_FAILURE = "Please add a descriptor with d/ [name/phone]."; private final Descriptor descriptor; diff --git a/src/main/java/seedu/staffsnap/logic/parser/ApplicantBookParser.java b/src/main/java/seedu/staffsnap/logic/parser/ApplicantBookParser.java index c9a4f3cc00f..e95e8b55d78 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/ApplicantBookParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/ApplicantBookParser.java @@ -16,6 +16,7 @@ import seedu.staffsnap.logic.commands.EditCommand; import seedu.staffsnap.logic.commands.ExitCommand; import seedu.staffsnap.logic.commands.FindCommand; +import seedu.staffsnap.logic.commands.FilterCommand; import seedu.staffsnap.logic.commands.HelpCommand; import seedu.staffsnap.logic.commands.ListCommand; import seedu.staffsnap.logic.commands.SortCommand; @@ -60,7 +61,7 @@ public Command parseCommand(String userInput) throws ParseException { IsConfirmed = IsConfirmedNext; IsConfirmedNext = false; - switch (commandWord) { + switch (commandWord.toLowerCase()) { case AddCommand.COMMAND_WORD: return new AddCommandParser().parse(arguments); @@ -97,6 +98,10 @@ public Command parseCommand(String userInput) throws ParseException { case SortCommand.COMMAND_WORD: return new SortCommandParser().parse(arguments); + case FilterCommand.COMMAND_WORD: + return new FilterCommandParser().parse(arguments); + + default: logger.finer("This user input caused a ParseException: " + userInput); throw new ParseException(MESSAGE_UNKNOWN_COMMAND); diff --git a/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java new file mode 100644 index 00000000000..9e9df76b4de --- /dev/null +++ b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java @@ -0,0 +1,66 @@ +package seedu.staffsnap.logic.parser; + +import seedu.staffsnap.logic.commands.FilterCommand; +import seedu.staffsnap.logic.parser.exceptions.ParseException; +import seedu.staffsnap.model.applicant.CustomFilterPredicate; +import seedu.staffsnap.model.applicant.Email; +import seedu.staffsnap.model.applicant.Name; +import seedu.staffsnap.model.applicant.Phone; +import seedu.staffsnap.model.applicant.Position; +import seedu.staffsnap.model.interview.Interview; + +import java.util.Set; + +import static seedu.staffsnap.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_INTERVIEW; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_POSITION; + +/** + * Parses input arguments and creates a new FilterCommand object + */ +public class FilterCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the FilterCommand + * and returns a FilterCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public FilterCommand parse(String args) throws ParseException { + String trimmedArgs = args.trim(); + if (trimmedArgs.isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, FilterCommand.MESSAGE_FAILURE)); + } + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_POSITION, PREFIX_INTERVIEW); + + Name name = null; + Phone phone = null; + Email email = null; + Position position = null; + Set interviewList = null; + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_POSITION); + if (argMultimap.getValue(PREFIX_NAME).isPresent()) { + name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); + } + if (argMultimap.getValue(PREFIX_PHONE).isPresent()) { + phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); + } + if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) { + email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); + } + if (argMultimap.getValue(PREFIX_POSITION).isPresent()) { + position = ParserUtil.parsePosition(argMultimap.getValue(PREFIX_POSITION).get()); + } + if (argMultimap.getValue(PREFIX_INTERVIEW).isPresent()) { + interviewList = ParserUtil.parseInterviews(argMultimap.getAllValues(PREFIX_INTERVIEW)); + } + + return new FilterCommand(new CustomFilterPredicate(name, phone, email, position, interviewList)); + } + +} diff --git a/src/main/java/seedu/staffsnap/logic/parser/SortCommandParser.java b/src/main/java/seedu/staffsnap/logic/parser/SortCommandParser.java index a67ab4db56e..e830d9cf19d 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/SortCommandParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/SortCommandParser.java @@ -25,7 +25,7 @@ public SortCommand parse(String args) throws ParseException { if (!arePrefixesPresent(argMultimap, PREFIX_DESCRIPTOR) || !argMultimap.getPreamble().isEmpty()) { - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortCommand.MESSAGE_USAGE)); + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortCommand.MESSAGE_FAILURE)); } argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_DESCRIPTOR); diff --git a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java new file mode 100644 index 00000000000..454aef1983b --- /dev/null +++ b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java @@ -0,0 +1,71 @@ +package seedu.staffsnap.model.applicant; + +import seedu.staffsnap.commons.util.StringUtil; +import seedu.staffsnap.model.interview.Interview; + +import java.util.Set; +import java.util.function.Predicate; + +public class CustomFilterPredicate implements Predicate { + + // Identity fields + private final Name name; + private final Phone phone; + // Data fields + private final Email email; + private final Position position; + private final Set interviews; + + /** + * @param applicant the input argument + * @return true if applicant matches all specified fields in the predicate + */ + @Override + public boolean test(Applicant applicant) { + if (this.name != null) { + if (!StringUtil.containsWordIgnoreCase(applicant.getName().toString(), this.name.toString())) { + return false; + } + } + if (this.phone != null) { + if (!StringUtil.containsWordIgnoreCase(applicant.getPhone().toString(), this.phone.toString())) { + return false; + } + } + if (this.email != null) { + if (!StringUtil.containsWordIgnoreCase(applicant.getEmail().toString(), this.email.toString())) { + return false; + } + } + if (this.position != null) { + if (!StringUtil.containsWordIgnoreCase(applicant.getPosition().toString(), this.position.toString())) { + return false; + } + } + /* + * TODO: + * add filtering for interviews + */ + return true; + } + + public CustomFilterPredicate(Name name, Phone phone, Email email, Position position, Set interviews) { + this.name = name; + this.phone = phone; + this.email = email; + this.position = position; + this.interviews = interviews; + System.out.println(this); + } + + @Override + public String toString() { + return "CustomFilterPredicate{" + + "name=" + name + + ", phone=" + phone + + ", email=" + email + + ", position=" + position + + ", interviews=" + interviews + + '}'; + } +} From a3c28f8f22295959dd8bbc9701e0cdc9917900d3 Mon Sep 17 00:00:00 2001 From: Ivan Lee <84584280+ivanleekk@users.noreply.github.com> Date: Thu, 19 Oct 2023 17:37:24 +0800 Subject: [PATCH 02/12] Add basic tests for FilterCommand --- .gitignore | 1 + .../staffsnap/commons/util/StringUtil.java | 23 +++- .../applicant/CustomFilterPredicate.java | 2 +- .../logic/commands/FilterCommandTest.java | 121 ++++++++++++++++++ 4 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java diff --git a/.gitignore b/.gitignore index eab4c7db6a5..29b729090d3 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ src/test/data/sandbox/ .DS_Store docs/_site/ docs/_markbind/logs/ +/htmlReport/ diff --git a/src/main/java/seedu/staffsnap/commons/util/StringUtil.java b/src/main/java/seedu/staffsnap/commons/util/StringUtil.java index 4d11a031385..5409d3c125e 100644 --- a/src/main/java/seedu/staffsnap/commons/util/StringUtil.java +++ b/src/main/java/seedu/staffsnap/commons/util/StringUtil.java @@ -31,13 +31,32 @@ public static boolean containsWordIgnoreCase(String sentence, String word) { checkArgument(!preppedWord.isEmpty(), "Word parameter cannot be empty"); checkArgument(preppedWord.split("\\s+").length == 1, "Word parameter should be a single word"); - String preppedSentence = sentence; - String[] wordsInPreppedSentence = preppedSentence.split("\\s+"); + String[] wordsInPreppedSentence = sentence.split("\\s+"); return Arrays.stream(wordsInPreppedSentence) .anyMatch(sentenceWord -> sentenceWord.toLowerCase().contains(preppedWord.toLowerCase())); } + /** + * Returns true if the {@code sentence} contains the {@code word}. + * Ignores case, but a full word match is required. + *
examples:
+     *       containsWordIgnoreCase("ABc def", "abc") == true
+     *       containsWordIgnoreCase("ABc def", "DEF") == true
+     *       containsWordIgnoreCase("ABc def", "AB") == false //not a full word match
+     *       
+ * @param sentence cannot be null + * @param word cannot be null, cannot be empty, must be a single word + */ + public static boolean containsStringIgnoreCase(String sentence, String word) { + requireNonNull(sentence); + requireNonNull(word); + + String preppedWord = word.trim(); + checkArgument(!preppedWord.isEmpty(), "Word parameter cannot be empty"); + + return sentence.contains(word); + } /** * Returns a detailed message of the t, including the stack trace. */ diff --git a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java index 454aef1983b..2b6882631b1 100644 --- a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java +++ b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java @@ -23,7 +23,7 @@ public class CustomFilterPredicate implements Predicate { @Override public boolean test(Applicant applicant) { if (this.name != null) { - if (!StringUtil.containsWordIgnoreCase(applicant.getName().toString(), this.name.toString())) { + if (!StringUtil.containsStringIgnoreCase(applicant.getName().toString(), this.name.toString())) { return false; } } diff --git a/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java b/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java new file mode 100644 index 00000000000..b75930a631c --- /dev/null +++ b/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java @@ -0,0 +1,121 @@ +package seedu.staffsnap.logic.commands; + +import org.junit.jupiter.api.Test; +import seedu.staffsnap.model.Model; +import seedu.staffsnap.model.ModelManager; +import seedu.staffsnap.model.UserPrefs; +import seedu.staffsnap.model.applicant.CustomFilterPredicate; +import seedu.staffsnap.model.applicant.Email; +import seedu.staffsnap.model.applicant.Name; +import seedu.staffsnap.model.applicant.Phone; +import seedu.staffsnap.model.applicant.Position; +import seedu.staffsnap.model.interview.Interview; + +import java.util.Arrays; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.*; +import static seedu.staffsnap.logic.Messages.MESSAGE_APPLICANTS_LISTED_OVERVIEW; +import static seedu.staffsnap.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.staffsnap.testutil.TypicalApplicants.ALICE; +import static seedu.staffsnap.testutil.TypicalApplicants.BENSON; +import static seedu.staffsnap.testutil.TypicalApplicants.CARL; +import static seedu.staffsnap.testutil.TypicalApplicants.DANIEL; +import static seedu.staffsnap.testutil.TypicalApplicants.ELLE; +import static seedu.staffsnap.testutil.TypicalApplicants.FIONA; +import static seedu.staffsnap.testutil.TypicalApplicants.getTypicalApplicantBook; + +class FilterCommandTest { + + private Model model = new ModelManager(getTypicalApplicantBook(), new UserPrefs()); + private Model expectedModel = new ModelManager(getTypicalApplicantBook(), new UserPrefs()); + + @Test + public void equals() { + Name name1 = BENSON.getName(); + Phone phone1 = BENSON.getPhone(); + Email email1 = BENSON.getEmail(); + Position position1 = BENSON.getPosition(); + Set interviewList1 = BENSON.getInterviews(); + + Name name2 = CARL.getName(); + Phone phone2 = CARL.getPhone(); + Email email2 = CARL.getEmail(); + Position position2 = CARL.getPosition(); + Set interviewList2 = CARL.getInterviews(); + + CustomFilterPredicate firstPredicate = new CustomFilterPredicate(name1, phone1, email1, position1, interviewList1); + CustomFilterPredicate secondPredicate = new CustomFilterPredicate(name2, phone2, email2, position2, interviewList2); + + FilterCommand filterFirstCommand = new FilterCommand(firstPredicate); + FilterCommand filterSecondCommand = new FilterCommand(secondPredicate); + + // same object -> returns true + assertTrue(filterFirstCommand.equals(filterFirstCommand)); + + // same values -> returns true + FilterCommand findFirstCommandCopy = new FilterCommand(firstPredicate); + assertTrue(filterFirstCommand.equals(findFirstCommandCopy)); + + // different types -> returns false + assertFalse(filterFirstCommand.equals(1)); + + // null -> returns false + assertFalse(filterFirstCommand.equals(null)); + + // different applicant -> returns false + assertFalse(filterFirstCommand.equals(filterSecondCommand)); + } + + @Test + public void execute_zeroKeywords_allApplicantsFound() { + String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 7); + CustomFilterPredicate predicate = new CustomFilterPredicate(null, null, null, null, null); + FilterCommand command = new FilterCommand(predicate); + expectedModel.updateFilteredApplicantList(predicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(expectedModel.getFilteredApplicantList(), model.getFilteredApplicantList()); + } + + @Test + public void execute_partialName_multipleApplicantsFound() { + String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 4); + CustomFilterPredicate predicate = new CustomFilterPredicate(new Name("a"), null, null, null, null); + FilterCommand command = new FilterCommand(predicate); + expectedModel.updateFilteredApplicantList(predicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(ALICE, CARL, DANIEL, FIONA), model.getFilteredApplicantList()); + } + + @Test + public void execute_multipleKeywords_singleApplicantFound() { + String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 1); + CustomFilterPredicate predicate = new CustomFilterPredicate(FIONA.getName(), FIONA.getPhone(), null, null, null); + FilterCommand command = new FilterCommand(predicate); + expectedModel.updateFilteredApplicantList(predicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + assertEquals(Arrays.asList(FIONA), model.getFilteredApplicantList()); + } + + @Test + public void execute_multipleKeywords_zeroApplicantsFound() { + String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 0); + CustomFilterPredicate predicate = new CustomFilterPredicate( + ALICE.getName(), BENSON.getPhone(), CARL.getEmail(), DANIEL.getPosition(), ELLE.getInterviews()); + FilterCommand command = new FilterCommand(predicate); + expectedModel.updateFilteredApplicantList(predicate); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + System.out.println(model.getFilteredApplicantList()); + assertEquals(Arrays.asList(), model.getFilteredApplicantList()); + } + + + @Test + public void toStringMethod() { + CustomFilterPredicate predicate = new CustomFilterPredicate(FIONA.getName(), null, null, null, null); + FilterCommand findCommand = new FilterCommand(predicate); + String expected = FilterCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; + assertEquals(expected, findCommand.toString()); + } + +} \ No newline at end of file From debc4f086b61b5bdb96c737a85d56d4d87fb39a1 Mon Sep 17 00:00:00 2001 From: Ivan Lee <84584280+ivanleekk@users.noreply.github.com> Date: Mon, 23 Oct 2023 14:53:01 +0800 Subject: [PATCH 03/12] Fix bug with CustomFilterPredicate from merge --- .../seedu/staffsnap/logic/parser/FilterCommandParser.java | 3 ++- .../staffsnap/model/applicant/CustomFilterPredicate.java | 5 +++-- .../seedu/staffsnap/logic/commands/FilterCommandTest.java | 7 ++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java index 9e9df76b4de..70b6d1ea1a0 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java @@ -9,6 +9,7 @@ import seedu.staffsnap.model.applicant.Position; import seedu.staffsnap.model.interview.Interview; +import java.util.List; import java.util.Set; import static seedu.staffsnap.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; @@ -42,7 +43,7 @@ public FilterCommand parse(String args) throws ParseException { Phone phone = null; Email email = null; Position position = null; - Set interviewList = null; + List interviewList = null; argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_POSITION); if (argMultimap.getValue(PREFIX_NAME).isPresent()) { name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); diff --git a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java index 2b6882631b1..8af5a3de6e0 100644 --- a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java +++ b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java @@ -3,6 +3,7 @@ import seedu.staffsnap.commons.util.StringUtil; import seedu.staffsnap.model.interview.Interview; +import java.util.List; import java.util.Set; import java.util.function.Predicate; @@ -14,7 +15,7 @@ public class CustomFilterPredicate implements Predicate { // Data fields private final Email email; private final Position position; - private final Set interviews; + private final List interviews; /** * @param applicant the input argument @@ -49,7 +50,7 @@ public boolean test(Applicant applicant) { return true; } - public CustomFilterPredicate(Name name, Phone phone, Email email, Position position, Set interviews) { + public CustomFilterPredicate(Name name, Phone phone, Email email, Position position, List interviews) { this.name = name; this.phone = phone; this.email = email; diff --git a/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java b/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java index b75930a631c..144ac677374 100644 --- a/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java +++ b/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java @@ -12,6 +12,7 @@ import seedu.staffsnap.model.interview.Interview; import java.util.Arrays; +import java.util.List; import java.util.Set; import static org.junit.jupiter.api.Assertions.*; @@ -36,13 +37,13 @@ public void equals() { Phone phone1 = BENSON.getPhone(); Email email1 = BENSON.getEmail(); Position position1 = BENSON.getPosition(); - Set interviewList1 = BENSON.getInterviews(); + List interviewList1 = BENSON.getInterviews(); Name name2 = CARL.getName(); Phone phone2 = CARL.getPhone(); Email email2 = CARL.getEmail(); Position position2 = CARL.getPosition(); - Set interviewList2 = CARL.getInterviews(); + List interviewList2 = CARL.getInterviews(); CustomFilterPredicate firstPredicate = new CustomFilterPredicate(name1, phone1, email1, position1, interviewList1); CustomFilterPredicate secondPredicate = new CustomFilterPredicate(name2, phone2, email2, position2, interviewList2); @@ -69,7 +70,7 @@ public void equals() { @Test public void execute_zeroKeywords_allApplicantsFound() { - String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 7); + String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 8); CustomFilterPredicate predicate = new CustomFilterPredicate(null, null, null, null, null); FilterCommand command = new FilterCommand(predicate); expectedModel.updateFilteredApplicantList(predicate); From 75bdf45e87760d3b0f1759d09a6d77013a52891c Mon Sep 17 00:00:00 2001 From: Ivan Lee <84584280+ivanleekk@users.noreply.github.com> Date: Mon, 23 Oct 2023 15:06:04 +0800 Subject: [PATCH 04/12] Merge master --- .../logic/commands/FilterCommand.java | 24 ++++----- .../logic/parser/ApplicantBookParser.java | 3 +- .../logic/parser/FilterCommandParser.java | 24 +++++---- .../applicant/CustomFilterPredicate.java | 49 ++++++++++++------- .../logic/commands/FilterCommandTest.java | 46 +++++++++-------- 5 files changed, 87 insertions(+), 59 deletions(-) diff --git a/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java b/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java index db2c549364e..37f746948a4 100644 --- a/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java +++ b/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java @@ -1,16 +1,18 @@ package seedu.staffsnap.logic.commands; -import seedu.staffsnap.commons.util.ToStringBuilder; -import seedu.staffsnap.logic.Messages; -import seedu.staffsnap.model.Model; -import seedu.staffsnap.model.applicant.CustomFilterPredicate; - import static java.util.Objects.requireNonNull; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_POSITION; +import seedu.staffsnap.commons.util.ToStringBuilder; +import seedu.staffsnap.logic.Messages; +import seedu.staffsnap.model.Model; +import seedu.staffsnap.model.applicant.CustomFilterPredicate; + + + /** * Finds and lists all applicants in address book whose name contains any of the argument keywords. * Keyword matching is case-insensitive. @@ -20,12 +22,12 @@ public class FilterCommand extends Command { public static final String COMMAND_WORD = "filter"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Filters all applicants who match the descriptor."; - public static final String MESSAGE_FAILURE = "Please add at least one field to filter by. " + - "Possible fields include:" + "\n" + - PREFIX_NAME + " [NAME], " + - PREFIX_EMAIL + " [EMAIL], " + - PREFIX_POSITION + " [POSITION], " + - PREFIX_PHONE + " [PHONE]"; + public static final String MESSAGE_FAILURE = "Please add at least one field to filter by. " + + "Possible fields include:" + "\n" + + PREFIX_NAME + " [NAME], " + + PREFIX_EMAIL + " [EMAIL], " + + PREFIX_POSITION + " [POSITION], " + + PREFIX_PHONE + " [PHONE]"; private final CustomFilterPredicate predicate; diff --git a/src/main/java/seedu/staffsnap/logic/parser/ApplicantBookParser.java b/src/main/java/seedu/staffsnap/logic/parser/ApplicantBookParser.java index b2b7120384c..dbd5165ddeb 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/ApplicantBookParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/ApplicantBookParser.java @@ -16,8 +16,8 @@ import seedu.staffsnap.logic.commands.DeleteCommand; import seedu.staffsnap.logic.commands.EditCommand; import seedu.staffsnap.logic.commands.ExitCommand; -import seedu.staffsnap.logic.commands.FindCommand; import seedu.staffsnap.logic.commands.FilterCommand; +import seedu.staffsnap.logic.commands.FindCommand; import seedu.staffsnap.logic.commands.HelpCommand; import seedu.staffsnap.logic.commands.ListCommand; import seedu.staffsnap.logic.commands.SortCommand; @@ -113,4 +113,5 @@ public Command parseCommand(String userInput) throws ParseException { throw new ParseException(MESSAGE_UNKNOWN_COMMAND); } } + } diff --git a/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java index 70b6d1ea1a0..32a0424dc16 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java @@ -1,5 +1,14 @@ package seedu.staffsnap.logic.parser; +import static seedu.staffsnap.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_INTERVIEW; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_POSITION; + +import java.util.List; + import seedu.staffsnap.logic.commands.FilterCommand; import seedu.staffsnap.logic.parser.exceptions.ParseException; import seedu.staffsnap.model.applicant.CustomFilterPredicate; @@ -9,24 +18,21 @@ import seedu.staffsnap.model.applicant.Position; import seedu.staffsnap.model.interview.Interview; -import java.util.List; -import java.util.Set; - -import static seedu.staffsnap.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_EMAIL; -import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_INTERVIEW; -import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_PHONE; -import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_POSITION; /** * Parses input arguments and creates a new FilterCommand object */ + + + + + public class FilterCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the FilterCommand * and returns a FilterCommand object for execution. + * * @throws ParseException if the user input does not conform the expected format */ public FilterCommand parse(String args) throws ParseException { diff --git a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java index 8af5a3de6e0..3fbad214872 100644 --- a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java +++ b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java @@ -1,12 +1,16 @@ package seedu.staffsnap.model.applicant; +import java.util.List; +import java.util.function.Predicate; + import seedu.staffsnap.commons.util.StringUtil; import seedu.staffsnap.model.interview.Interview; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; + +/** + * Custom predicate to be used to filter applicants + */ public class CustomFilterPredicate implements Predicate { // Identity fields @@ -17,6 +21,22 @@ public class CustomFilterPredicate implements Predicate { private final Position position; private final List interviews; + /** + * Constructor for CustomFilterPredicate + * @param name Name of applicant + * @param phone Phone number of applicant + * @param email Email address of applicant + * @param position Position applied for by applicant + * @param interviews Interviews applicant has to go through + */ + public CustomFilterPredicate(Name name, Phone phone, Email email, Position position, List interviews) { + this.name = name; + this.phone = phone; + this.email = email; + this.position = position; + this.interviews = interviews; + } + /** * @param applicant the input argument * @return true if applicant matches all specified fields in the predicate @@ -50,23 +70,16 @@ public boolean test(Applicant applicant) { return true; } - public CustomFilterPredicate(Name name, Phone phone, Email email, Position position, List interviews) { - this.name = name; - this.phone = phone; - this.email = email; - this.position = position; - this.interviews = interviews; - System.out.println(this); - } + @Override public String toString() { - return "CustomFilterPredicate{" + - "name=" + name + - ", phone=" + phone + - ", email=" + email + - ", position=" + position + - ", interviews=" + interviews + - '}'; + return "CustomFilterPredicate{" + + "name=" + name + + ", phone=" + phone + + ", email=" + email + + ", position=" + position + + ", interviews=" + interviews + + '}'; } } diff --git a/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java b/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java index 144ac677374..269d29e981a 100644 --- a/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java +++ b/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java @@ -1,6 +1,23 @@ package seedu.staffsnap.logic.commands; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.staffsnap.logic.Messages.MESSAGE_APPLICANTS_LISTED_OVERVIEW; +import static seedu.staffsnap.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.staffsnap.testutil.TypicalApplicants.ALICE; +import static seedu.staffsnap.testutil.TypicalApplicants.BENSON; +import static seedu.staffsnap.testutil.TypicalApplicants.CARL; +import static seedu.staffsnap.testutil.TypicalApplicants.DANIEL; +import static seedu.staffsnap.testutil.TypicalApplicants.ELLE; +import static seedu.staffsnap.testutil.TypicalApplicants.FIONA; +import static seedu.staffsnap.testutil.TypicalApplicants.getTypicalApplicantBook; + +import java.util.Arrays; +import java.util.List; + import org.junit.jupiter.api.Test; + import seedu.staffsnap.model.Model; import seedu.staffsnap.model.ModelManager; import seedu.staffsnap.model.UserPrefs; @@ -11,20 +28,6 @@ import seedu.staffsnap.model.applicant.Position; import seedu.staffsnap.model.interview.Interview; -import java.util.Arrays; -import java.util.List; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.*; -import static seedu.staffsnap.logic.Messages.MESSAGE_APPLICANTS_LISTED_OVERVIEW; -import static seedu.staffsnap.logic.commands.CommandTestUtil.assertCommandSuccess; -import static seedu.staffsnap.testutil.TypicalApplicants.ALICE; -import static seedu.staffsnap.testutil.TypicalApplicants.BENSON; -import static seedu.staffsnap.testutil.TypicalApplicants.CARL; -import static seedu.staffsnap.testutil.TypicalApplicants.DANIEL; -import static seedu.staffsnap.testutil.TypicalApplicants.ELLE; -import static seedu.staffsnap.testutil.TypicalApplicants.FIONA; -import static seedu.staffsnap.testutil.TypicalApplicants.getTypicalApplicantBook; class FilterCommandTest { @@ -45,8 +48,10 @@ public void equals() { Position position2 = CARL.getPosition(); List interviewList2 = CARL.getInterviews(); - CustomFilterPredicate firstPredicate = new CustomFilterPredicate(name1, phone1, email1, position1, interviewList1); - CustomFilterPredicate secondPredicate = new CustomFilterPredicate(name2, phone2, email2, position2, interviewList2); + CustomFilterPredicate firstPredicate = new CustomFilterPredicate(name1, phone1, email1, position1, + interviewList1); + CustomFilterPredicate secondPredicate = new CustomFilterPredicate(name2, phone2, email2, position2, + interviewList2); FilterCommand filterFirstCommand = new FilterCommand(firstPredicate); FilterCommand filterSecondCommand = new FilterCommand(secondPredicate); @@ -91,7 +96,8 @@ public void execute_partialName_multipleApplicantsFound() { @Test public void execute_multipleKeywords_singleApplicantFound() { String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 1); - CustomFilterPredicate predicate = new CustomFilterPredicate(FIONA.getName(), FIONA.getPhone(), null, null, null); + CustomFilterPredicate predicate = new CustomFilterPredicate(FIONA.getName(), FIONA.getPhone(), null, null, + null); FilterCommand command = new FilterCommand(predicate); expectedModel.updateFilteredApplicantList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -101,8 +107,8 @@ public void execute_multipleKeywords_singleApplicantFound() { @Test public void execute_multipleKeywords_zeroApplicantsFound() { String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 0); - CustomFilterPredicate predicate = new CustomFilterPredicate( - ALICE.getName(), BENSON.getPhone(), CARL.getEmail(), DANIEL.getPosition(), ELLE.getInterviews()); + CustomFilterPredicate predicate = new CustomFilterPredicate(ALICE.getName(), BENSON.getPhone(), + CARL.getEmail(), DANIEL.getPosition(), ELLE.getInterviews()); FilterCommand command = new FilterCommand(predicate); expectedModel.updateFilteredApplicantList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -119,4 +125,4 @@ public void toStringMethod() { assertEquals(expected, findCommand.toString()); } -} \ No newline at end of file +} From 08d6a593327f8dfd4bf106e801c6edb5edf1a7e9 Mon Sep 17 00:00:00 2001 From: Ivan Lee <84584280+ivanleekk@users.noreply.github.com> Date: Mon, 23 Oct 2023 15:57:54 +0800 Subject: [PATCH 05/12] Add tests for FilterCommand --- .../logic/commands/FilterCommand.java | 1 + .../logic/parser/FilterCommandParser.java | 5 -- .../applicant/CustomFilterPredicate.java | 26 +++++++--- .../logic/parser/ApplicantBookParserTest.java | 31 +++++++---- .../logic/parser/FilterCommandParserTest.java | 51 +++++++++++++++++++ 5 files changed, 92 insertions(+), 22 deletions(-) create mode 100644 src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java diff --git a/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java b/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java index 37f746948a4..0df0d7a8dc7 100644 --- a/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java +++ b/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java @@ -60,6 +60,7 @@ public boolean equals(Object other) { } FilterCommand otherFilterCommand = (FilterCommand) other; + System.out.println("predicate = " + predicate); return predicate.equals(otherFilterCommand.predicate); } diff --git a/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java index 32a0424dc16..61a2560e237 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java @@ -23,10 +23,6 @@ * Parses input arguments and creates a new FilterCommand object */ - - - - public class FilterCommandParser implements Parser { /** @@ -66,7 +62,6 @@ public FilterCommand parse(String args) throws ParseException { if (argMultimap.getValue(PREFIX_INTERVIEW).isPresent()) { interviewList = ParserUtil.parseInterviews(argMultimap.getAllValues(PREFIX_INTERVIEW)); } - return new FilterCommand(new CustomFilterPredicate(name, phone, email, position, interviewList)); } diff --git a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java index 3fbad214872..27fc72d2591 100644 --- a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java +++ b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java @@ -1,13 +1,13 @@ package seedu.staffsnap.model.applicant; import java.util.List; +import java.util.Objects; import java.util.function.Predicate; import seedu.staffsnap.commons.util.StringUtil; import seedu.staffsnap.model.interview.Interview; - /** * Custom predicate to be used to filter applicants */ @@ -23,10 +23,11 @@ public class CustomFilterPredicate implements Predicate { /** * Constructor for CustomFilterPredicate - * @param name Name of applicant - * @param phone Phone number of applicant - * @param email Email address of applicant - * @param position Position applied for by applicant + * + * @param name Name of applicant + * @param phone Phone number of applicant + * @param email Email address of applicant + * @param position Position applied for by applicant * @param interviews Interviews applicant has to go through */ public CustomFilterPredicate(Name name, Phone phone, Email email, Position position, List interviews) { @@ -71,7 +72,6 @@ public boolean test(Applicant applicant) { } - @Override public String toString() { return "CustomFilterPredicate{" @@ -82,4 +82,18 @@ public String toString() { + ", interviews=" + interviews + '}'; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CustomFilterPredicate that = (CustomFilterPredicate) o; + return Objects.equals(name, that.name) && Objects.equals(phone, that.phone) && Objects.equals(email, + that.email) && Objects.equals(position, that.position) && Objects.equals(interviews, that.interviews); + } + + @Override + public int hashCode() { + return Objects.hash(name, phone, email, position, interviews); + } } diff --git a/src/test/java/seedu/staffsnap/logic/parser/ApplicantBookParserTest.java b/src/test/java/seedu/staffsnap/logic/parser/ApplicantBookParserTest.java index b54bfef802d..11fbd021cfd 100644 --- a/src/test/java/seedu/staffsnap/logic/parser/ApplicantBookParserTest.java +++ b/src/test/java/seedu/staffsnap/logic/parser/ApplicantBookParserTest.java @@ -15,10 +15,12 @@ import seedu.staffsnap.logic.commands.AddCommand; //import seedu.staffsnap.logic.commands.ClearCommand; +import seedu.staffsnap.logic.commands.AddInterviewCommand; import seedu.staffsnap.logic.commands.DeleteCommand; import seedu.staffsnap.logic.commands.EditCommand; import seedu.staffsnap.logic.commands.EditCommand.EditApplicantDescriptor; import seedu.staffsnap.logic.commands.ExitCommand; +import seedu.staffsnap.logic.commands.FilterCommand; import seedu.staffsnap.logic.commands.FindCommand; import seedu.staffsnap.logic.commands.HelpCommand; import seedu.staffsnap.logic.commands.ListCommand; @@ -51,8 +53,8 @@ public void parseCommand_clear() throws Exception { @Test public void parseCommand_delete() throws Exception { - DeleteCommand command = (DeleteCommand) parser.parseCommand( - DeleteCommand.COMMAND_WORD + " " + INDEX_FIRST_APPLICANT.getOneBased()); + DeleteCommand command = + (DeleteCommand) parser.parseCommand(DeleteCommand.COMMAND_WORD + " " + INDEX_FIRST_APPLICANT.getOneBased()); assertEquals(new DeleteCommand(INDEX_FIRST_APPLICANT), command); } @@ -60,11 +62,8 @@ public void parseCommand_delete() throws Exception { public void parseCommand_edit() throws Exception { Applicant applicant = new ApplicantBuilder().build(); EditApplicantDescriptor descriptor = new EditApplicantDescriptorBuilder(applicant).build(); - EditCommand command = (EditCommand) parser.parseCommand(EditCommand.COMMAND_WORD - + " " - + INDEX_FIRST_APPLICANT.getOneBased() - + " " - + ApplicantUtil.getEditApplicantDescriptorDetails(descriptor)); + EditCommand command = + (EditCommand) parser.parseCommand(EditCommand.COMMAND_WORD + " " + INDEX_FIRST_APPLICANT.getOneBased() + " " + ApplicantUtil.getEditApplicantDescriptorDetails(descriptor)); assertEquals(new EditCommand(INDEX_FIRST_APPLICANT, descriptor), command); } @@ -77,8 +76,8 @@ public void parseCommand_exit() throws Exception { @Test public void parseCommand_find() throws Exception { List keywords = Arrays.asList("foo", "bar", "baz"); - FindCommand command = (FindCommand) parser.parseCommand( - FindCommand.COMMAND_WORD + " " + keywords.stream().collect(Collectors.joining(" "))); + FindCommand command = + (FindCommand) parser.parseCommand(FindCommand.COMMAND_WORD + " " + keywords.stream().collect(Collectors.joining(" "))); assertEquals(new FindCommand(new NameContainsKeywordsPredicate(keywords)), command); } @@ -99,10 +98,20 @@ public void parseCommand_sort() throws Exception { assertTrue(parser.parseCommand(SortCommand.COMMAND_WORD + " " + "d/ name") instanceof SortCommand); } + @Test + public void parseCommand_filter() throws Exception { + assertTrue(parser.parseCommand(FilterCommand.COMMAND_WORD + " " + "d/ name") instanceof FilterCommand); + } + + @Test + public void parseCommand_addi() throws Exception { + assertTrue(parser.parseCommand(AddInterviewCommand.COMMAND_WORD + " 1 " + "t/ technical") instanceof AddInterviewCommand); + } + @Test public void parseCommand_unrecognisedInput_throwsParseException() { - assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE), () - -> parser.parseCommand("")); + assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE), + () -> parser.parseCommand("")); } @Test diff --git a/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java b/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java new file mode 100644 index 00000000000..7124df1bcef --- /dev/null +++ b/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java @@ -0,0 +1,51 @@ +package seedu.staffsnap.logic.parser; + + +import static seedu.staffsnap.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.staffsnap.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.staffsnap.logic.parser.CommandParserTestUtil.assertParseSuccess; + +import org.junit.jupiter.api.Test; +import seedu.staffsnap.logic.commands.FilterCommand; +import seedu.staffsnap.model.applicant.CustomFilterPredicate; +import seedu.staffsnap.model.applicant.Email; +import seedu.staffsnap.model.applicant.Name; +import seedu.staffsnap.model.applicant.Phone; +import seedu.staffsnap.model.applicant.Position; + +class FilterCommandParserTest { + + private FilterCommandParser parser = new FilterCommandParser(); + + private static final String MESSAGE_INVALID_FORMAT = String.format(MESSAGE_INVALID_COMMAND_FORMAT, + FilterCommand.MESSAGE_FAILURE); + + @Test + void parse_missingParts_failure() { + assertParseFailure(parser, " ", MESSAGE_INVALID_FORMAT); + } + + @Test + void parse_nameOnly_success() { + assertParseSuccess(parser, " n/ Name", new FilterCommand(new CustomFilterPredicate(new Name("Name"), null, + null, null, null))); + } + + @Test + void parse_emailOnly_success() { + assertParseSuccess(parser, " e/ test@test.com", new FilterCommand(new CustomFilterPredicate(null, null, + new Email("test@test.com"), null, null))); + } + + @Test + void parse_positionOnly_success() { + assertParseSuccess(parser, " p/ Software Engineer", new FilterCommand(new CustomFilterPredicate(null, null, + null, new Position("Software Engineer"), null))); + } + + @Test + void parse_phoneOnly_success() { + assertParseSuccess(parser, " hp/ 98765432", new FilterCommand(new CustomFilterPredicate(null, new Phone( + "98765432"), null, null, null))); + } +} \ No newline at end of file From 9a5ef64ef228c62d6c2aa3ae62330d285f1ead58 Mon Sep 17 00:00:00 2001 From: Ivan Lee <84584280+ivanleekk@users.noreply.github.com> Date: Tue, 24 Oct 2023 21:29:50 +0800 Subject: [PATCH 06/12] Fix checkstyle issues --- .../model/applicant/CustomFilterPredicate.java | 8 ++++++-- .../logic/parser/ApplicantBookParserTest.java | 17 +++++++++++------ .../logic/parser/FilterCommandParserTest.java | 7 ++++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java index 27fc72d2591..9ead62e7e0b 100644 --- a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java +++ b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java @@ -85,8 +85,12 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } CustomFilterPredicate that = (CustomFilterPredicate) o; return Objects.equals(name, that.name) && Objects.equals(phone, that.phone) && Objects.equals(email, that.email) && Objects.equals(position, that.position) && Objects.equals(interviews, that.interviews); diff --git a/src/test/java/seedu/staffsnap/logic/parser/ApplicantBookParserTest.java b/src/test/java/seedu/staffsnap/logic/parser/ApplicantBookParserTest.java index 11fbd021cfd..2b131e24189 100644 --- a/src/test/java/seedu/staffsnap/logic/parser/ApplicantBookParserTest.java +++ b/src/test/java/seedu/staffsnap/logic/parser/ApplicantBookParserTest.java @@ -54,7 +54,8 @@ public void parseCommand_clear() throws Exception { @Test public void parseCommand_delete() throws Exception { DeleteCommand command = - (DeleteCommand) parser.parseCommand(DeleteCommand.COMMAND_WORD + " " + INDEX_FIRST_APPLICANT.getOneBased()); + (DeleteCommand) parser.parseCommand(DeleteCommand.COMMAND_WORD + " " + + INDEX_FIRST_APPLICANT.getOneBased()); assertEquals(new DeleteCommand(INDEX_FIRST_APPLICANT), command); } @@ -63,7 +64,9 @@ public void parseCommand_edit() throws Exception { Applicant applicant = new ApplicantBuilder().build(); EditApplicantDescriptor descriptor = new EditApplicantDescriptorBuilder(applicant).build(); EditCommand command = - (EditCommand) parser.parseCommand(EditCommand.COMMAND_WORD + " " + INDEX_FIRST_APPLICANT.getOneBased() + " " + ApplicantUtil.getEditApplicantDescriptorDetails(descriptor)); + (EditCommand) parser.parseCommand(EditCommand.COMMAND_WORD + " " + + INDEX_FIRST_APPLICANT.getOneBased() + " " + + ApplicantUtil.getEditApplicantDescriptorDetails(descriptor)); assertEquals(new EditCommand(INDEX_FIRST_APPLICANT, descriptor), command); } @@ -77,7 +80,8 @@ public void parseCommand_exit() throws Exception { public void parseCommand_find() throws Exception { List keywords = Arrays.asList("foo", "bar", "baz"); FindCommand command = - (FindCommand) parser.parseCommand(FindCommand.COMMAND_WORD + " " + keywords.stream().collect(Collectors.joining(" "))); + (FindCommand) parser.parseCommand(FindCommand.COMMAND_WORD + " " + keywords.stream() + .collect(Collectors.joining(" "))); assertEquals(new FindCommand(new NameContainsKeywordsPredicate(keywords)), command); } @@ -105,13 +109,14 @@ public void parseCommand_filter() throws Exception { @Test public void parseCommand_addi() throws Exception { - assertTrue(parser.parseCommand(AddInterviewCommand.COMMAND_WORD + " 1 " + "t/ technical") instanceof AddInterviewCommand); + assertTrue(parser.parseCommand(AddInterviewCommand.COMMAND_WORD + " 1 " + "t/ technical") + instanceof AddInterviewCommand); } @Test public void parseCommand_unrecognisedInput_throwsParseException() { - assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE), - () -> parser.parseCommand("")); + assertThrows(ParseException.class, String.format(MESSAGE_INVALID_COMMAND_FORMAT, + HelpCommand.MESSAGE_USAGE), () -> parser.parseCommand("")); } @Test diff --git a/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java b/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java index 7124df1bcef..97cbfea2221 100644 --- a/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java +++ b/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java @@ -6,6 +6,7 @@ import static seedu.staffsnap.logic.parser.CommandParserTestUtil.assertParseSuccess; import org.junit.jupiter.api.Test; + import seedu.staffsnap.logic.commands.FilterCommand; import seedu.staffsnap.model.applicant.CustomFilterPredicate; import seedu.staffsnap.model.applicant.Email; @@ -15,10 +16,10 @@ class FilterCommandParserTest { - private FilterCommandParser parser = new FilterCommandParser(); - private static final String MESSAGE_INVALID_FORMAT = String.format(MESSAGE_INVALID_COMMAND_FORMAT, FilterCommand.MESSAGE_FAILURE); + private FilterCommandParser parser = new FilterCommandParser(); + @Test void parse_missingParts_failure() { @@ -48,4 +49,4 @@ void parse_phoneOnly_success() { assertParseSuccess(parser, " hp/ 98765432", new FilterCommand(new CustomFilterPredicate(null, new Phone( "98765432"), null, null, null))); } -} \ No newline at end of file +} From 6a21f222d401db69cf8959799389f2eda3bf117b Mon Sep 17 00:00:00 2001 From: Ivan Lee <84584280+ivanleekk@users.noreply.github.com> Date: Tue, 24 Oct 2023 22:22:13 +0800 Subject: [PATCH 07/12] Update DG --- docs/DeveloperGuide.md | 378 ++++++++++++------ .../FilterCommandActivityDiagram.puml | 35 ++ .../applicant/CustomFilterPredicate.java | 14 +- 3 files changed, 304 insertions(+), 123 deletions(-) create mode 100644 docs/diagrams/FilterCommandActivityDiagram.puml diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index 2ae6b3d0c8f..e1caef350b2 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -1,7 +1,7 @@ --- layout: default.md - title: "Developer Guide" - pageNav: 3 + title: "Developer Guide" + pageNav: 3 --- # Staff-Snap Developer Guide @@ -13,7 +13,8 @@ ## **Acknowledgements** -_{ list here sources of all reused/adapted ideas, code, documentation, and third-party libraries -- include links to the original source as well }_ +_{ list here sources of all reused/adapted ideas, code, documentation, and third-party libraries -- include links to the +original source as well }_ -------------------------------------------------------------------------------------------------------------------- @@ -35,7 +36,11 @@ Given below is a quick overview of main components and how they interact with ea **Main components of the architecture** -**`Main`** (consisting of classes [`Main`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/Main.java) and [`MainApp`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/MainApp.java)) is in charge of the app launch and shut down. +**`Main`** (consisting of +classes [`Main`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/Main.java) +and [`MainApp`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/MainApp.java)) is +in charge of the app launch and shut down. + * At app launch, it initializes the other components in the correct sequence, and connects them up with each other. * At shut down, it shuts down the other components and invokes cleanup methods where necessary. @@ -50,16 +55,21 @@ The bulk of the app's work is done by the following four components: **How the architecture components interact with each other** -The *Sequence Diagram* below shows how the components interact with each other for the scenario where the user issues the command `delete 1`. +The *Sequence Diagram* below shows how the components interact with each other for the scenario where the user issues +the command `delete 1`. Each of the four main components (also shown in the diagram above), * defines its *API* in an `interface` with the same name as the Component. -* implements its functionality using a concrete `{Component Name}Manager` class (which follows the corresponding API `interface` mentioned in the previous point. +* implements its functionality using a concrete `{Component Name}Manager` class (which follows the corresponding + API `interface` mentioned in the previous point. -For example, the `Logic` component defines its API in the `Logic.java` interface and implements its functionality using the `LogicManager.java` class which follows the `Logic` interface. Other components interact with a given component through its interface rather than the concrete class (reason: to prevent outside component's being coupled to the implementation of a component), as illustrated in the (partial) class diagram below. +For example, the `Logic` component defines its API in the `Logic.java` interface and implements its functionality using +the `LogicManager.java` class which follows the `Logic` interface. Other components interact with a given component +through its interface rather than the concrete class (reason: to prevent outside component's being coupled to the +implementation of a component), as illustrated in the (partial) class diagram below. @@ -67,13 +77,21 @@ The sections below give more details of each component. ### UI component -The **API** of this component is specified in [`Ui.java`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/ui/Ui.java) +The **API** of this component is specified +in [`Ui.java`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/ui/Ui.java) -The UI consists of a `MainWindow` that is made up of parts e.g.`CommandBox`, `ResultDisplay`, `PersonListPanel`, `StatusBarFooter` etc. All these, including the `MainWindow`, inherit from the abstract `UiPart` class which captures the commonalities between classes that represent parts of the visible GUI. +The UI consists of a `MainWindow` that is made up of parts +e.g.`CommandBox`, `ResultDisplay`, `PersonListPanel`, `StatusBarFooter` etc. All these, including the `MainWindow`, +inherit from the abstract `UiPart` class which captures the commonalities between classes that represent parts of the +visible GUI. -The `UI` component uses the JavaFx UI framework. The layout of these UI parts are defined in matching `.fxml` files that are in the `src/main/resources/view` folder. For example, the layout of the [`MainWindow`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/ui/MainWindow.java) is specified in [`MainWindow.fxml`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/resources/view/MainWindow.fxml) +The `UI` component uses the JavaFx UI framework. The layout of these UI parts are defined in matching `.fxml` files that +are in the `src/main/resources/view` folder. For example, the layout of +the [`MainWindow`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/ui/MainWindow.java) +is specified +in [`MainWindow.fxml`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/resources/view/MainWindow.fxml) The `UI` component, @@ -84,25 +102,30 @@ The `UI` component, ### Logic component -**API** : [`Logic.java`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/logic/Logic.java) +**API +** : [`Logic.java`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/logic/Logic.java) Here's a (partial) class diagram of the `Logic` component: -The sequence diagram below illustrates the interactions within the `Logic` component, taking `execute("delete 1")` API call as an example. +The sequence diagram below illustrates the interactions within the `Logic` component, taking `execute("delete 1")` API +call as an example. -**Note:** The lifeline for `DeleteCommandParser` should end at the destroy marker (X) but due to a limitation of PlantUML, the lifeline reaches the end of diagram. +**Note:** The lifeline for `DeleteCommandParser` should end at the destroy marker (X) but due to a limitation of +PlantUML, the lifeline reaches the end of diagram. How the `Logic` component works: -1. When `Logic` is called upon to execute a command, it is passed to an `AddressBookParser` object which in turn creates a parser that matches the command (e.g., `DeleteCommandParser`) and uses it to parse the command. -1. This results in a `Command` object (more precisely, an object of one of its subclasses e.g., `DeleteCommand`) which is executed by the `LogicManager`. +1. When `Logic` is called upon to execute a command, it is passed to an `AddressBookParser` object which in turn creates + a parser that matches the command (e.g., `DeleteCommandParser`) and uses it to parse the command. +1. This results in a `Command` object (more precisely, an object of one of its subclasses e.g., `DeleteCommand`) which + is executed by the `LogicManager`. 1. The command can communicate with the `Model` when it is executed (e.g. to delete a person). 1. The result of the command execution is encapsulated as a `CommandResult` object which is returned back from `Logic`. @@ -111,11 +134,18 @@ Here are the other classes in `Logic` (omitted from the class diagram above) tha How the parsing works: -* When called upon to parse a user command, the `AddressBookParser` class creates an `XYZCommandParser` (`XYZ` is a placeholder for the specific command name e.g., `AddCommandParser`) which uses the other classes shown above to parse the user command and create a `XYZCommand` object (e.g., `AddCommand`) which the `AddressBookParser` returns back as a `Command` object. -* All `XYZCommandParser` classes (e.g., `AddCommandParser`, `DeleteCommandParser`, ...) inherit from the `Parser` interface so that they can be treated similarly where possible e.g, during testing. + +* When called upon to parse a user command, the `AddressBookParser` class creates an `XYZCommandParser` (`XYZ` is a + placeholder for the specific command name e.g., `AddCommandParser`) which uses the other classes shown above to parse + the user command and create a `XYZCommand` object (e.g., `AddCommand`) which the `AddressBookParser` returns back as + a `Command` object. +* All `XYZCommandParser` classes (e.g., `AddCommandParser`, `DeleteCommandParser`, ...) inherit from the `Parser` + interface so that they can be treated similarly where possible e.g, during testing. ### Model component -**API** : [`Model.java`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/model/Model.java) + +**API +** : [`Model.java`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/model/Model.java) @@ -123,29 +153,39 @@ How the parsing works: The `Model` component, * stores the applicant book data i.e., all `Person` objects (which are contained in a `UniquePersonList` object). -* stores the currently 'selected' `Person` objects (e.g., results of a search query) as a separate _filtered_ list which is exposed to outsiders as an unmodifiable `ObservableList` that can be 'observed' e.g. the UI can be bound to this list so that the UI automatically updates when the data in the list change. -* stores a `UserPref` object that represents the user’s preferences. This is exposed to the outside as a `ReadOnlyUserPref` objects. -* does not depend on any of the other three components (as the `Model` represents data entities of the domain, they should make sense on their own without depending on other components) +* stores the currently 'selected' `Person` objects (e.g., results of a search query) as a separate _filtered_ list which + is exposed to outsiders as an unmodifiable `ObservableList` that can be 'observed' e.g. the UI can be bound to + this list so that the UI automatically updates when the data in the list change. +* stores a `UserPref` object that represents the user’s preferences. This is exposed to the outside as + a `ReadOnlyUserPref` objects. +* does not depend on any of the other three components (as the `Model` represents data entities of the domain, they + should make sense on their own without depending on other components) -**Note:** An alternative (arguably, a more OOP) model is given below. It has a `Tag` list in the `AddressBook`, which `Person` references. This allows `AddressBook` to only require one `Tag` object per unique tag, instead of each `Person` needing their own `Tag` objects.
+**Note:** An alternative (arguably, a more OOP) model is given below. It has a `Tag` list in the `AddressBook`, +which `Person` references. This allows `AddressBook` to only require one `Tag` object per unique tag, instead of +each `Person` needing their own `Tag` objects.
- ### Storage component -**API** : [`Storage.java`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/storage/Storage.java) +**API +** : [`Storage.java`](https://github.com/se-edu/addressbook-level3/tree/master/src/main/java/seedu/address/storage/Storage.java) The `Storage` component, -* can save both applicant book data and user preference data in JSON format, and read them back into corresponding objects. -* inherits from both `AddressBookStorage` and `UserPrefStorage`, which means it can be treated as either one (if only the functionality of only one is needed). -* depends on some classes in the `Model` component (because the `Storage` component's job is to save/retrieve objects that belong to the `Model`) + +* can save both applicant book data and user preference data in JSON format, and read them back into corresponding + objects. +* inherits from both `AddressBookStorage` and `UserPrefStorage`, which means it can be treated as either one (if only + the functionality of only one is needed). +* depends on some classes in the `Model` component (because the `Storage` component's job is to save/retrieve objects + that belong to the `Model`) ### Common classes @@ -161,42 +201,56 @@ This section describes some noteworthy details on how certain features are imple #### Proposed Implementation -The proposed undo/redo mechanism is facilitated by `VersionedAddressBook`. It extends `AddressBook` with an undo/redo history, stored internally as an `addressBookStateList` and `currentStatePointer`. Additionally, it implements the following operations: +The proposed undo/redo mechanism is facilitated by `VersionedAddressBook`. It extends `AddressBook` with an undo/redo +history, stored internally as an `addressBookStateList` and `currentStatePointer`. Additionally, it implements the +following operations: -* `VersionedAddressBook#commit()` — Saves the current applicant book state in its history. -* `VersionedAddressBook#undo()` — Restores the previous applicant book state from its history. -* `VersionedAddressBook#redo()` — Restores a previously undone applicant book state from its history. +* `VersionedAddressBook#commit()`— Saves the current applicant book state in its history. +* `VersionedAddressBook#undo()`— Restores the previous applicant book state from its history. +* `VersionedAddressBook#redo()`— Restores a previously undone applicant book state from its history. -These operations are exposed in the `Model` interface as `Model#commitAddressBook()`, `Model#undoAddressBook()` and `Model#redoAddressBook()` respectively. +These operations are exposed in the `Model` interface as `Model#commitAddressBook()`, `Model#undoAddressBook()` +and `Model#redoAddressBook()` respectively. Given below is an example usage scenario and how the undo/redo mechanism behaves at each step. -Step 1. The user launches the application for the first time. The `VersionedAddressBook` will be initialized with the initial applicant book state, and the `currentStatePointer` pointing to that single applicant book state. +Step 1. The user launches the application for the first time. The `VersionedAddressBook` will be initialized with the +initial applicant book state, and the `currentStatePointer` pointing to that single applicant book state. -Step 2. The user executes `delete 5` command to delete the 5th person in the applicant book. The `delete` command calls `Model#commitAddressBook()`, causing the modified state of the applicant book after the `delete 5` command executes to be saved in the `addressBookStateList`, and the `currentStatePointer` is shifted to the newly inserted applicant book state. +Step 2. The user executes `delete 5` command to delete the 5th person in the applicant book. The `delete` command +calls `Model#commitAddressBook()`, causing the modified state of the applicant book after the `delete 5` command +executes to be saved in the `addressBookStateList`, and the `currentStatePointer` is shifted to the newly inserted +applicant book state. -Step 3. The user executes `add n/David …​` to add a new person. The `add` command also calls `Model#commitAddressBook()`, causing another modified applicant book state to be saved into the `addressBookStateList`. +Step 3. The user executes `add n/David …​` to add a new person. The `add` command also +calls `Model#commitAddressBook()`, causing another modified applicant book state to be saved into +the `addressBookStateList`. -**Note:** If a command fails its execution, it will not call `Model#commitAddressBook()`, so the applicant book state will not be saved into the `addressBookStateList`. +**Note:** If a command fails its execution, it will not call `Model#commitAddressBook()`, so the applicant book state +will not be saved into the `addressBookStateList`. -Step 4. The user now decides that adding the person was a mistake, and decides to undo that action by executing the `undo` command. The `undo` command will call `Model#undoAddressBook()`, which will shift the `currentStatePointer` once to the left, pointing it to the previous applicant book state, and restores the applicant book to that state. +Step 4. The user now decides that adding the person was a mistake, and decides to undo that action by executing +the `undo` command. The `undo` command will call `Model#undoAddressBook()`, which will shift the `currentStatePointer` +once to the left, pointing it to the previous applicant book state, and restores the applicant book to that state. -**Note:** If the `currentStatePointer` is at index 0, pointing to the initial AddressBook state, then there are no previous AddressBook states to restore. The `undo` command uses `Model#canUndoAddressBook()` to check if this is the case. If so, it will return an error to the user rather +**Note:** If the `currentStatePointer` is at index 0, pointing to the initial AddressBook state, then there are no +previous AddressBook states to restore. The `undo` command uses `Model#canUndoAddressBook()` to check if this is the +case. If so, it will return an error to the user rather than attempting to perform the undo. @@ -207,23 +261,32 @@ The following sequence diagram shows how the undo operation works: -**Note:** The lifeline for `UndoCommand` should end at the destroy marker (X) but due to a limitation of PlantUML, the lifeline reaches the end of diagram. +**Note:** The lifeline for `UndoCommand` should end at the destroy marker (X) but due to a limitation of PlantUML, the +lifeline reaches the end of diagram. -The `redo` command does the opposite — it calls `Model#redoAddressBook()`, which shifts the `currentStatePointer` once to the right, pointing to the previously undone state, and restores the applicant book to that state. +The `redo` command does the opposite — it calls `Model#redoAddressBook()`, which shifts the `currentStatePointer` once +to the right, pointing to the previously undone state, and restores the applicant book to that state. -**Note:** If the `currentStatePointer` is at index `addressBookStateList.size() - 1`, pointing to the latest applicant book state, then there are no undone AddressBook states to restore. The `redo` command uses `Model#canRedoAddressBook()` to check if this is the case. If so, it will return an error to the user rather than attempting to perform the redo. +**Note:** If the `currentStatePointer` is at index `addressBookStateList.size() - 1`, pointing to the latest applicant +book state, then there are no undone AddressBook states to restore. The `redo` command uses `Model#canRedoAddressBook()` +to check if this is the case. If so, it will return an error to the user rather than attempting to perform the redo. -Step 5. The user then decides to execute the command `list`. Commands that do not modify the applicant book, such as `list`, will usually not call `Model#commitAddressBook()`, `Model#undoAddressBook()` or `Model#redoAddressBook()`. Thus, the `addressBookStateList` remains unchanged. +Step 5. The user then decides to execute the command `list`. Commands that do not modify the applicant book, such +as `list`, will usually not call `Model#commitAddressBook()`, `Model#undoAddressBook()` or `Model#redoAddressBook()`. +Thus, the `addressBookStateList` remains unchanged. -Step 6. The user executes `clear`, which calls `Model#commitAddressBook()`. Since the `currentStatePointer` is not pointing at the end of the `addressBookStateList`, all applicant book states after the `currentStatePointer` will be purged. Reason: It no longer makes sense to redo the `add n/David …​` command. This is the behavior that most modern desktop applications follow. +Step 6. The user executes `clear`, which calls `Model#commitAddressBook()`. Since the `currentStatePointer` is not +pointing at the end of the `addressBookStateList`, all applicant book states after the `currentStatePointer` will be +purged. Reason: It no longer makes sense to redo the `add n/David …​` command. This is the behavior that most modern +desktop applications follow. @@ -236,13 +299,13 @@ The following activity diagram summarizes what happens when a user executes a ne **Aspect: How undo & redo executes:** * **Alternative 1 (current choice):** Saves the entire applicant book. - * Pros: Easy to implement. - * Cons: May have performance issues in terms of memory usage. + * Pros: Easy to implement. + * Cons: May have performance issues in terms of memory usage. * **Alternative 2:** Individual command knows how to undo/redo by itself. - * Pros: Will use less memory (e.g. for `delete`, just save the person being deleted). - * Cons: We must ensure that the implementation of each individual command are correct. + * Pros: Will use less memory (e.g. for `delete`, just save the person being deleted). + * Cons: We must ensure that the implementation of each individual command are correct. _{more aspects and alternatives to be added}_ @@ -250,35 +313,113 @@ _{more aspects and alternatives to be added}_ _{Explain here how the data archiving feature will be implemented}_ - ### Help feature + #### Steps to trigger + 1. User opens the app 2. User keys in `help` 3. Command list is shown and opens user guide in browser + #### Implementation + 1. When the user enters the term help. it triggers the help feature in the parser under the switch case. 2. After it is triggered, it will display a short list of possible commands that the user can use. 3. The user guide will also be opened in their browser + #### Notes -1. Help can be called anytime and has no format to follow. The popup screen is disabled to avoid confusion but can be enabled in the future if need be. + +1. Help can be called anytime and has no format to follow. The popup screen is disabled to avoid confusion but can be + enabled in the future if need be. ### Confirmation + Clear command + #### Steps to trigger + 1. User opens the app 2. User enters `clear` (and subsequently sees a message asking to confirm) 3. User enters `yes` to confirm the clear + #### Implementation + 1. This features requires the state of the parser to be known. -2. The parser is modified to store the previous taken in command, in this case whether the previous command was a successful clear command. -3. If the previous command is not a clear command, it looks for the keyword clear. Otherwise, it looks for the keyword yes. -4. Hence, the user will first need to call clear, before calling yes to invoke the clear mechanism, ensuring safety of data. +2. The parser is modified to store the previous taken in command, in this case whether the previous command was a + successful clear command. +3. If the previous command is not a clear command, it looks for the keyword clear. Otherwise, it looks for the keyword + yes. +4. Hence, the user will first need to call clear, before calling yes to invoke the clear mechanism, ensuring safety of + data. + #### Notes -1. If you would like to extend the code for more features that require state, please do change the case condition for this feature. -2. Currently, it follows the default commands if a word other than yes is given. But this will be improved in a future update. + +1. If you would like to extend the code for more features that require state, please do change the case condition for + this feature. +2. Currently, it follows the default commands if a word other than yes is given. But this will be improved in a future + update. 3. The state of the parser, rather than the app is used to reduce the chances of accidental clears. +### Filter feature + +#### Implementation + +The filter feature works by updating the `Predicate` used in the `FilteredList` of `ModelManager`. Using +the predicate, minimal changes to the implementation of StaffSnap is required. + +To create a single predicate that is able to search and filter for multiple fields, a `CustomFilterPredicate` class is +created +It currently contains the following fields and is able to filter for applicants which match all specified fields. +1. Name +2. Phone +3. Email +4. Position + +When `CustomFilterPredicate#test` is called, it will check if the specified fields are a substring of the same field of +the applicant, +returning true if all specified fields match, and false otherwise. + +#### Steps to trigger + +1. User opens the app +2. User enters `filter [n/, e/, p/, hp/] [term]`, where one or more of the prefixes can be specified to be filtered by + +Once step 2 is complete, the GUI will update and refresh the applicant list with only applicants which match all +specified fields. +The following diagram summarises what happens when a user executes a Filter command: + + + +### Design considerations + +#### Aspect: How to filter applicants + +- Alternative 1 (current choice): use a custom predicate and FilteredList, **compare using strings** + - Pros: Current implementation of ModelManager already uses FilteredList, making a custom predicate an easy + extension. + The `CustomFilterPredicate` can easily be extended when more applicant fields are ready to expand the utility of + the + filter command. + - Cons: Comparison of predicate fields to applicant fields are done using string comparison. +- Alternative 2: use a custom predicate and FilteredList, **compare within field classes** + - Pros: Same as alternative 1, and definition of what is considered a match can be defined in the field class (e.g. + Name, Phone, etc). + - Cons: Will require greater complexity than alternative 1 in implementation. May be slower to integrate new classes + in the future. + +#### Aspect: Command syntax + +- Alternative 1: `filter n/ [Name] e/ [Email] p/ [Position] hp/ [Phone]` + - Pros: Unambiguous and forces all fields to be entered, preventing errors. + - Cons: Users cannot filter by single fields. Requires more key presses to enter a filter command. +- Alternative 2: `filter [n/, e/, p/, hp/] [term]`, where only one term is allowed + - Pros: Quicker to key in command than alternative 1. + - Cons: Only allows users to filter by one field at a time, limiting utility of filter command. +- Alternative 3 (current choice): `filter [n/, e/, p/, hp/] [term]`, where at least one term is required and the others + are optional + - Pros: Provides flexibility in the filter command to filter by one or more fields, while still retaining the speed + of alternative 2 when few fields are required. + - Cons: Unfamiliar users may not know that fields can be optional anc continue to key in the full command at all + times. -------------------------------------------------------------------------------------------------------------------- @@ -304,7 +445,7 @@ _{Explain here how the data archiving feature will be implemented}_ * prefers typing to mouse interactions * is reasonably comfortable using CLI apps -**Value proposition**: introduces organisation to applicant management, recruitment processes and +**Value proposition**: introduces organisation to applicant management, recruitment processes and streamlines hiring decisions ### User stories @@ -325,7 +466,6 @@ Priorities: High (must have) - `* * *`, Medium (nice to have) - `* *`, Low (unli | `* *` | user | filter applicants by a descriptor | find relevant applicants quickly | | `* *` | user | purge all existing data | remove sample data and populate real data | - ### Use cases (For all use cases below, the **System** is `Staff-Snap` and the **Actor** is the `user`, unless specified otherwise) @@ -336,10 +476,10 @@ Guarantees: The new applicant will be added to the list of applicants. **MSS** -1. User inputs the command to add an applicant. -2. Staff-Snap adds the new applicant to the list and displays the updated list. - - Use case ends. +1. User inputs the command to add an applicant. +2. Staff-Snap adds the new applicant to the list and displays the updated list. + + Use case ends. **Extensions** @@ -355,10 +495,10 @@ Guarantees: The applicant's information will be updated. **MSS** -1. User inputs the command to edit an applicant's information. -2. Staff-Snap updates the applicant list with the updated applicant information. +1. User inputs the command to edit an applicant's information. +2. Staff-Snap updates the applicant list with the updated applicant information. - Use case ends. + Use case ends. **Extensions** @@ -374,10 +514,10 @@ Guarantees: All applicants will be listed. **MSS** -1. User inputs the command to view the list of all applicants. -2. Staff-Snap displays the list of all applicants. +1. User inputs the command to view the list of all applicants. +2. Staff-Snap displays the list of all applicants. - Use case ends. + Use case ends. **Extensions** @@ -398,10 +538,10 @@ Guarantees: The applicant will be removed from the list of applicants. **MSS** -1. User inputs the command to delete an applicant. -2. Staff-Snap removes the applicant from the list of applicants. +1. User inputs the command to delete an applicant. +2. Staff-Snap removes the applicant from the list of applicants. - Use case ends. + Use case ends. **Extensions** @@ -417,10 +557,10 @@ Guarantees: The applicants with name matching the search will be listed. **MSS** -1. User inputs the command to to find an applicant by name. -2. Staff-Snap displays the list of all applicants that match the search. +1. User inputs the command to to find an applicant by name. +2. Staff-Snap displays the list of all applicants that match the search. - Use case ends. + Use case ends. **Extensions** @@ -441,10 +581,10 @@ Guarantees: The list of applicants will be sorted by the descriptor. **MSS** -1. User inputs the command to sort the applicants by a particular descriptor. -2. Staff-Snap displays the list of applicants sorted by the descriptor. +1. User inputs the command to sort the applicants by a particular descriptor. +2. Staff-Snap displays the list of applicants sorted by the descriptor. - Use case ends. + Use case ends. **Extensions** @@ -460,10 +600,10 @@ Guarantees: Only applicants that satisfies the specified criterion will be liste **MSS** -1. User inputs the command to filter the list of applicants by a specified criterion. -2. Staff-Snap displays the list of all applicants that satisfies the specified criterion. +1. User inputs the command to filter the list of applicants by a specified criterion. +2. Staff-Snap displays the list of all applicants that satisfies the specified criterion. - Use case ends. + Use case ends. **Extensions** @@ -479,10 +619,10 @@ Guarantees: The list of all available commands will be made accessible. **MSS** -1. User inputs the command to view the list of all available commands. -2. Staff-Snap opens the user guide in the default browser. +1. User inputs the command to view the list of all available commands. +2. Staff-Snap opens the user guide in the default browser. - Use case ends. + Use case ends. **Extensions** @@ -498,10 +638,10 @@ Guarantees: Staff-Snap exits. **MSS** -1. User inputs the command to exit the program. -2. Staff-Snap exits and closes. +1. User inputs the command to exit the program. +2. Staff-Snap exits and closes. - Use case ends. + Use case ends. **Extensions** @@ -513,7 +653,7 @@ Guarantees: Staff-Snap exits. * 1b. User closes the application window. - Use case resumes at step 2. + Use case resumes at step 2. **Use case: UC10 - Clear list of applicants** @@ -521,12 +661,12 @@ Guarantees: The list of applicants will be cleared. **MSS** -1. User inputs the command to clear the list of applicants. -2. Staff-Snap prompts for confirmation -3. User confirms the action. -4. Staff-Snap clears the list of applicants and displays an empty list. +1. User inputs the command to clear the list of applicants. +2. Staff-Snap prompts for confirmation +3. User confirms the action. +4. Staff-Snap clears the list of applicants and displays an empty list. - Use case ends. + Use case ends. **Extensions** @@ -548,10 +688,10 @@ Guarantees: A new interview will be added to the applicant. **MSS** -1. User inputs the command to add an interview to an applicant. -2. Staff-Snap updates the applicant information with the new interview. +1. User inputs the command to add an interview to an applicant. +2. Staff-Snap updates the applicant information with the new interview. - Use case ends. + Use case ends. **Extensions** @@ -568,10 +708,10 @@ Guarantees: A new interview will be added to the applicant. 1. Should work on any _mainstream OS_ as long as it has Java `11` or above installed. 2. The entire software should be able to be packaged into a single _JAR file_ for users to download. 3. The file size of the JAR file should not exceed 100MB. -4. A user who can type fast should be able to accomplish most tasks faster via a _command line interface (CLI)_, -compared to a hypothetical GUI-only version of the app. +4. A user who can type fast should be able to accomplish most tasks faster via a _command line interface (CLI)_, + compared to a hypothetical GUI-only version of the app. 5. The product is for single-users. The application should not be running in a shared computer and with - different people using it at different times. + different people using it at different times. 6. The software should respond to user input within 2 seconds under normal load conditions. 7. There should be no shared file storage mechanism. The data file created by one user should not be accessed by another user during regular operations. @@ -580,21 +720,25 @@ compared to a hypothetical GUI-only version of the app. 10. The software should not depend on a remote server so that anyone can use the app at anytime. 11. The _GUI_ should not cause any resolution-related inconveniences to the user for standard screen resolutions 1920x1080 and higher, and for screen scales 100% and 125%. -12. All functions can be used via the GUI, even if the user experience is not optimal, for resolutions 1280x720 and higher, +12. All functions can be used via the GUI, even if the user experience is not optimal, for resolutions 1280x720 and + higher, and for screen scales 150%. -13. The software should provide error messages which clearly states the error and provides guidance on correcting the error. -14. The software should provide easily accessible help in the form of documentation for users unfamiliar with the commands. +13. The software should provide error messages which clearly states the error and provides guidance on correcting the + error. +14. The software should provide easily accessible help in the form of documentation for users unfamiliar with the + commands. 15. The software should include automated tests to ensure correctness and reliability. ### Glossary * **Mainstream OS**: Windows, Linux, MacOS -* **JAR file**: A package file format that bundles all the components of a Java application into a single file for distribution. +* **JAR file**: A package file format that bundles all the components of a Java application into a single file for + distribution. * **Command Line Interface (CLI)**: A means for users to interact with a software by inputting commands -* **Human editable text file**: A text file that can be viewed and modified using a standard text editor by a user. -(e.g. a `.txt` file) -* **Graphical User Interface (GUI)**: A type of user interface that allows users to interact with software through -graphical icons and visual indicators. +* **Human editable text file**: A text file that can be viewed and modified using a standard text editor by a user. + (e.g. a `.txt` file) +* **Graphical User Interface (GUI)**: A type of user interface that allows users to interact with software through + graphical icons and visual indicators. -------------------------------------------------------------------------------------------------------------------- @@ -613,15 +757,16 @@ testers are expected to do more *exploratory* testing. 1. Initial launch - 1. Download the jar file and copy into an empty folder + 1. Download the jar file and copy into an empty folder - 1. Double-click the jar file Expected: Shows the GUI with a set of sample contacts. The window size may not be optimum. + 1. Double-click the jar file Expected: Shows the GUI with a set of sample contacts. The window size may not be + optimum. 1. Saving window preferences - 1. Resize the window to an optimum size. Move the window to a different location. Close the window. + 1. Resize the window to an optimum size. Move the window to a different location. Close the window. - 1. Re-launch the app by double-clicking the jar file.
+ 1. Re-launch the app by double-clicking the jar file.
Expected: The most recent window size and location is retained. 1. _{ more test cases …​ }_ @@ -630,16 +775,17 @@ testers are expected to do more *exploratory* testing. 1. Deleting a person while all persons are being shown - 1. Prerequisites: List all persons using the `list` command. Multiple persons in the list. + 1. Prerequisites: List all persons using the `list` command. Multiple persons in the list. - 1. Test case: `delete 1`
- Expected: First contact is deleted from the list. Details of the deleted contact shown in the status message. Timestamp in the status bar is updated. + 1. Test case: `delete 1`
+ Expected: First contact is deleted from the list. Details of the deleted contact shown in the status message. + Timestamp in the status bar is updated. - 1. Test case: `delete 0`
- Expected: No person is deleted. Error details shown in the status message. Status bar remains the same. + 1. Test case: `delete 0`
+ Expected: No person is deleted. Error details shown in the status message. Status bar remains the same. - 1. Other incorrect delete commands to try: `delete`, `delete x`, `...` (where x is larger than the list size)
- Expected: Similar to previous. + 1. Other incorrect delete commands to try: `delete`, `delete x`, `...` (where x is larger than the list size)
+ Expected: Similar to previous. 1. _{ more test cases …​ }_ @@ -647,6 +793,6 @@ testers are expected to do more *exploratory* testing. 1. Dealing with missing/corrupted data files - 1. _{explain how to simulate a missing/corrupted file, and the expected behavior}_ + 1. _{explain how to simulate a missing/corrupted file, and the expected behavior}_ 1. _{ more test cases …​ }_ diff --git a/docs/diagrams/FilterCommandActivityDiagram.puml b/docs/diagrams/FilterCommandActivityDiagram.puml new file mode 100644 index 00000000000..89151b0052a --- /dev/null +++ b/docs/diagrams/FilterCommandActivityDiagram.puml @@ -0,0 +1,35 @@ +@startuml +'https://plantuml.com/activity-diagram-beta + +start +:User enters filter command syntax; +:ApplicantBookParser parses command_word; +:FilterCommandParser parses arguments; +if (At least 1 argument is provided) then (true) + :Parse provided fields; + if (Provided fields are valid) then (true) + :Create new CustomFilterPredicate + from specified fields; + :Create new FilterCommand + from CustomFilterPredicate; + :Execute FilterCommand; + :Update predicate used in + ModelManager with + CustomFilterPredicate; + :Display success message; + :Show updated list in GUI; + stop + else (false) + + endif +else (false) + +endif +:Throw ParseException with + invalid command format + message and proper Filter + syntax; + :Display error message; + stop + +@enduml diff --git a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java index 9ead62e7e0b..c946231453b 100644 --- a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java +++ b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java @@ -5,6 +5,7 @@ import java.util.function.Predicate; import seedu.staffsnap.commons.util.StringUtil; +import seedu.staffsnap.commons.util.ToStringBuilder; import seedu.staffsnap.model.interview.Interview; @@ -74,13 +75,12 @@ public boolean test(Applicant applicant) { @Override public String toString() { - return "CustomFilterPredicate{" - + "name=" + name - + ", phone=" + phone - + ", email=" + email - + ", position=" + position - + ", interviews=" + interviews - + '}'; + return new ToStringBuilder(this) + .add("name", name) + .add("phone", phone) + .add("email", email) + .add("position", position) + .add("interviews", interviews).toString(); } @Override From a3381e616d66277664a0815908d1ba665cfb44b0 Mon Sep 17 00:00:00 2001 From: Ivan Lee <84584280+ivanleekk@users.noreply.github.com> Date: Tue, 24 Oct 2023 22:25:09 +0800 Subject: [PATCH 08/12] Fix activity diagram reference in DG --- docs/DeveloperGuide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index e1caef350b2..b1e5c383795 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -387,7 +387,7 @@ Once step 2 is complete, the GUI will update and refresh the applicant list with specified fields. The following diagram summarises what happens when a user executes a Filter command: - + ### Design considerations From 235fdcbc4ae7419c8c4f5ec571472e6b8bcf0403 Mon Sep 17 00:00:00 2001 From: Ivan Lee <84584280+ivanleekk@users.noreply.github.com> Date: Wed, 25 Oct 2023 10:21:50 +0800 Subject: [PATCH 09/12] Update FilterCommandActivityDiagram.puml --- .../FilterCommandActivityDiagram.puml | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/docs/diagrams/FilterCommandActivityDiagram.puml b/docs/diagrams/FilterCommandActivityDiagram.puml index 89151b0052a..23c4622ad33 100644 --- a/docs/diagrams/FilterCommandActivityDiagram.puml +++ b/docs/diagrams/FilterCommandActivityDiagram.puml @@ -3,8 +3,8 @@ start :User enters filter command syntax; -:ApplicantBookParser parses command_word; -:FilterCommandParser parses arguments; +:ApplicantBookParser and FilterCommandParser +parse arguments; if (At least 1 argument is provided) then (true) :Parse provided fields; if (Provided fields are valid) then (true) @@ -12,24 +12,31 @@ if (At least 1 argument is provided) then (true) from specified fields; :Create new FilterCommand from CustomFilterPredicate; - :Execute FilterCommand; - :Update predicate used in - ModelManager with - CustomFilterPredicate; - :Display success message; - :Show updated list in GUI; + :FilterCommand updates predicate used in + ModelManager with CustomFilterPredicate; + :Display success message and show updated list in GUI; stop else (false) + :Throw ParseException with + invalid command format + message and proper Filter + syntax; + :Display error message; + stop + endif - endif else (false) +label 1 +label 2 +label 3 -endif :Throw ParseException with - invalid command format - message and proper Filter - syntax; - :Display error message; - stop + invalid command format + message and proper Filter + syntax; + :Display error message; + stop +endif @enduml + From 6ec833ff7409df9c340274f41927f52fd6ca23ae Mon Sep 17 00:00:00 2001 From: Ivan Lee <84584280+ivanleekk@users.noreply.github.com> Date: Wed, 25 Oct 2023 10:54:13 +0800 Subject: [PATCH 10/12] Filter by status --- .../logic/commands/FilterCommand.java | 4 +++- .../logic/commands/StatusCommand.java | 7 ++++-- .../staffsnap/logic/parser/CliSyntax.java | 1 + .../logic/parser/FilterCommandParser.java | 13 ++++++++--- .../staffsnap/logic/parser/ParserUtil.java | 11 ++++++++++ .../logic/parser/StatusCommandParser.java | 22 ++++++++++++++----- .../applicant/CustomFilterPredicate.java | 18 +++++++++++---- .../logic/commands/FilterCommandTest.java | 17 ++++++++------ .../logic/parser/FilterCommandParserTest.java | 15 +++++++++---- .../logic/parser/StatusCommandParserTest.java | 7 +++--- 10 files changed, 85 insertions(+), 30 deletions(-) diff --git a/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java b/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java index 0df0d7a8dc7..f6f6b72bb50 100644 --- a/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java +++ b/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java @@ -5,6 +5,7 @@ import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_POSITION; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_STATUS; import seedu.staffsnap.commons.util.ToStringBuilder; import seedu.staffsnap.logic.Messages; @@ -27,7 +28,8 @@ public class FilterCommand extends Command { + PREFIX_NAME + " [NAME], " + PREFIX_EMAIL + " [EMAIL], " + PREFIX_POSITION + " [POSITION], " - + PREFIX_PHONE + " [PHONE]"; + + PREFIX_PHONE + " [PHONE], " + + PREFIX_STATUS + " [STATUS]"; private final CustomFilterPredicate predicate; diff --git a/src/main/java/seedu/staffsnap/logic/commands/StatusCommand.java b/src/main/java/seedu/staffsnap/logic/commands/StatusCommand.java index 4d0d5e14293..3d714a0af8b 100644 --- a/src/main/java/seedu/staffsnap/logic/commands/StatusCommand.java +++ b/src/main/java/seedu/staffsnap/logic/commands/StatusCommand.java @@ -22,12 +22,15 @@ public class StatusCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the status of the applicant identified " + "by the index number used in the displayed applicant list.\n" - + "Parameters: INDEX (must be a positive integer) " + "STATUS [u(ndecided)/o(ffered)/r(ejected)]."; + + "Parameters: INDEX (must be a positive integer) " + "s/ [u(ndecided)/o(ffered)/r(ejected)]."; public static final String MESSAGE_EDIT_STATUS_SUCCESS = "Edited Applicant Status: %1$s"; public static final String MESSAGE_NO_STATUS = "Missing Status, please follow the following parameters." + "Parameters: INDEX (must be a positive integer) " - + "STATUS [u(ndecided)/o(ffered)/r(ejected)]."; + + "s/ [u(ndecided)/o(ffered)/r(ejected)]."; + public static final String MESSAGE_NO_INDEX = "Missing Index, please follow the following parameters." + + "Parameters: INDEX (must be a positive integer) " + + "s/ [u(ndecided)/o(ffered)/r(ejected)]."; private final Index index; diff --git a/src/main/java/seedu/staffsnap/logic/parser/CliSyntax.java b/src/main/java/seedu/staffsnap/logic/parser/CliSyntax.java index c06096ef1b0..19194a6a621 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/staffsnap/logic/parser/CliSyntax.java @@ -14,5 +14,6 @@ public class CliSyntax { public static final Prefix PREFIX_INTERVIEW = new Prefix("i/"); public static final Prefix PREFIX_TYPE = new Prefix("t/"); public static final Prefix PREFIX_RATING = new Prefix("r/"); + public static final Prefix PREFIX_STATUS = new Prefix("s/"); } diff --git a/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java index 61a2560e237..289399def6b 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java @@ -6,6 +6,7 @@ import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_POSITION; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_STATUS; import java.util.List; @@ -16,6 +17,7 @@ import seedu.staffsnap.model.applicant.Name; import seedu.staffsnap.model.applicant.Phone; import seedu.staffsnap.model.applicant.Position; +import seedu.staffsnap.model.applicant.Status; import seedu.staffsnap.model.interview.Interview; @@ -39,14 +41,16 @@ public FilterCommand parse(String args) throws ParseException { } ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, - PREFIX_POSITION, PREFIX_INTERVIEW); + PREFIX_POSITION, PREFIX_INTERVIEW, PREFIX_STATUS); Name name = null; Phone phone = null; Email email = null; Position position = null; List interviewList = null; - argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_POSITION); + Status status = null; + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_POSITION, + PREFIX_STATUS); if (argMultimap.getValue(PREFIX_NAME).isPresent()) { name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); } @@ -62,7 +66,10 @@ public FilterCommand parse(String args) throws ParseException { if (argMultimap.getValue(PREFIX_INTERVIEW).isPresent()) { interviewList = ParserUtil.parseInterviews(argMultimap.getAllValues(PREFIX_INTERVIEW)); } - return new FilterCommand(new CustomFilterPredicate(name, phone, email, position, interviewList)); + if (argMultimap.getValue(PREFIX_STATUS).isPresent()) { + status = ParserUtil.parseStatus(argMultimap.getValue(PREFIX_STATUS).get()); + } + return new FilterCommand(new CustomFilterPredicate(name, phone, email, position, interviewList, status)); } } diff --git a/src/main/java/seedu/staffsnap/logic/parser/ParserUtil.java b/src/main/java/seedu/staffsnap/logic/parser/ParserUtil.java index 7695bebd740..341b2321391 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/staffsnap/logic/parser/ParserUtil.java @@ -15,6 +15,7 @@ import seedu.staffsnap.model.applicant.Name; import seedu.staffsnap.model.applicant.Phone; import seedu.staffsnap.model.applicant.Position; +import seedu.staffsnap.model.applicant.Status; import seedu.staffsnap.model.interview.Interview; import seedu.staffsnap.model.interview.Rating; @@ -213,4 +214,14 @@ public static Rating parseRating(String rating) throws ParseException { public static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); } + + /** + * Parses a {@code String status} into a {@code Status}. + * @param status String representation of Status + * @return Status if successful, or null of no matching status is found. + */ + public static Status parseStatus(String status) { + requireNonNull(status); + return Status.findByName(status); + } } diff --git a/src/main/java/seedu/staffsnap/logic/parser/StatusCommandParser.java b/src/main/java/seedu/staffsnap/logic/parser/StatusCommandParser.java index 87448f002fc..7fd899b1547 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/StatusCommandParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/StatusCommandParser.java @@ -1,6 +1,7 @@ package seedu.staffsnap.logic.parser; import static seedu.staffsnap.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_STATUS; import seedu.staffsnap.commons.core.index.Index; import seedu.staffsnap.logic.commands.StatusCommand; @@ -18,15 +19,24 @@ public class StatusCommandParser implements Parser { * @throws ParseException if the user input does not conform the expected format */ public StatusCommand parse(String args) throws ParseException { + String trimmedArgs = args.trim(); + if (trimmedArgs.isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatusCommand.MESSAGE_USAGE)); + } ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args); + ArgumentTokenizer.tokenize(args, PREFIX_STATUS); - if (argMultimap.getPreamble().length() <= 2) { - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatusCommand.MESSAGE_USAGE)); + Index index = null; + Status status = null; + try { + index = ParserUtil.parseIndex(argMultimap.getPreamble()); + } catch (ParseException e) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatusCommand.MESSAGE_NO_INDEX)); + } + if (argMultimap.getValue(PREFIX_STATUS).isPresent()) { + status = ParserUtil.parseStatus(argMultimap.getValue(PREFIX_STATUS).get()); } - String[] splitString = argMultimap.getPreamble().split("\\s+"); - Index index = ParserUtil.parseIndex(splitString[0]); - Status status = Status.findByName(splitString[1]); if (status == null) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatusCommand.MESSAGE_NO_STATUS)); } diff --git a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java index c946231453b..c96ef69ab06 100644 --- a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java +++ b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java @@ -21,6 +21,7 @@ public class CustomFilterPredicate implements Predicate { private final Email email; private final Position position; private final List interviews; + private final Status status; /** * Constructor for CustomFilterPredicate @@ -31,12 +32,14 @@ public class CustomFilterPredicate implements Predicate { * @param position Position applied for by applicant * @param interviews Interviews applicant has to go through */ - public CustomFilterPredicate(Name name, Phone phone, Email email, Position position, List interviews) { + public CustomFilterPredicate(Name name, Phone phone, Email email, Position position, List interviews, + Status status) { this.name = name; this.phone = phone; this.email = email; this.position = position; this.interviews = interviews; + this.status = status; } /** @@ -65,9 +68,14 @@ public boolean test(Applicant applicant) { return false; } } + if (this.status != null) { + if (applicant.getStatus() != this.status) { + return false; + } + } /* * TODO: - * add filtering for interviews + * add filtering for scores */ return true; } @@ -80,7 +88,8 @@ public String toString() { .add("phone", phone) .add("email", email) .add("position", position) - .add("interviews", interviews).toString(); + .add("interviews", interviews) + .add("status", status).toString(); } @Override @@ -93,7 +102,8 @@ public boolean equals(Object o) { } CustomFilterPredicate that = (CustomFilterPredicate) o; return Objects.equals(name, that.name) && Objects.equals(phone, that.phone) && Objects.equals(email, - that.email) && Objects.equals(position, that.position) && Objects.equals(interviews, that.interviews); + that.email) && Objects.equals(position, that.position) && Objects.equals(interviews, that.interviews) + && Objects.equals(status, that.status); } @Override diff --git a/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java b/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java index 269d29e981a..fd5653b84f0 100644 --- a/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java +++ b/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java @@ -26,6 +26,7 @@ import seedu.staffsnap.model.applicant.Name; import seedu.staffsnap.model.applicant.Phone; import seedu.staffsnap.model.applicant.Position; +import seedu.staffsnap.model.applicant.Status; import seedu.staffsnap.model.interview.Interview; @@ -41,17 +42,19 @@ public void equals() { Email email1 = BENSON.getEmail(); Position position1 = BENSON.getPosition(); List interviewList1 = BENSON.getInterviews(); + Status status1 = BENSON.getStatus(); Name name2 = CARL.getName(); Phone phone2 = CARL.getPhone(); Email email2 = CARL.getEmail(); Position position2 = CARL.getPosition(); List interviewList2 = CARL.getInterviews(); + Status status2 = CARL.getStatus(); CustomFilterPredicate firstPredicate = new CustomFilterPredicate(name1, phone1, email1, position1, - interviewList1); + interviewList1, status1); CustomFilterPredicate secondPredicate = new CustomFilterPredicate(name2, phone2, email2, position2, - interviewList2); + interviewList2, status2); FilterCommand filterFirstCommand = new FilterCommand(firstPredicate); FilterCommand filterSecondCommand = new FilterCommand(secondPredicate); @@ -76,7 +79,7 @@ public void equals() { @Test public void execute_zeroKeywords_allApplicantsFound() { String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 8); - CustomFilterPredicate predicate = new CustomFilterPredicate(null, null, null, null, null); + CustomFilterPredicate predicate = new CustomFilterPredicate(null, null, null, null, null, null); FilterCommand command = new FilterCommand(predicate); expectedModel.updateFilteredApplicantList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -86,7 +89,7 @@ public void execute_zeroKeywords_allApplicantsFound() { @Test public void execute_partialName_multipleApplicantsFound() { String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 4); - CustomFilterPredicate predicate = new CustomFilterPredicate(new Name("a"), null, null, null, null); + CustomFilterPredicate predicate = new CustomFilterPredicate(new Name("a"), null, null, null, null, null); FilterCommand command = new FilterCommand(predicate); expectedModel.updateFilteredApplicantList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -97,7 +100,7 @@ public void execute_partialName_multipleApplicantsFound() { public void execute_multipleKeywords_singleApplicantFound() { String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 1); CustomFilterPredicate predicate = new CustomFilterPredicate(FIONA.getName(), FIONA.getPhone(), null, null, - null); + null, null); FilterCommand command = new FilterCommand(predicate); expectedModel.updateFilteredApplicantList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -108,7 +111,7 @@ public void execute_multipleKeywords_singleApplicantFound() { public void execute_multipleKeywords_zeroApplicantsFound() { String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 0); CustomFilterPredicate predicate = new CustomFilterPredicate(ALICE.getName(), BENSON.getPhone(), - CARL.getEmail(), DANIEL.getPosition(), ELLE.getInterviews()); + CARL.getEmail(), DANIEL.getPosition(), ELLE.getInterviews(), FIONA.getStatus()); FilterCommand command = new FilterCommand(predicate); expectedModel.updateFilteredApplicantList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -119,7 +122,7 @@ public void execute_multipleKeywords_zeroApplicantsFound() { @Test public void toStringMethod() { - CustomFilterPredicate predicate = new CustomFilterPredicate(FIONA.getName(), null, null, null, null); + CustomFilterPredicate predicate = new CustomFilterPredicate(FIONA.getName(), null, null, null, null, null); FilterCommand findCommand = new FilterCommand(predicate); String expected = FilterCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; assertEquals(expected, findCommand.toString()); diff --git a/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java b/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java index 97cbfea2221..a0044f9fd98 100644 --- a/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java +++ b/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java @@ -13,6 +13,7 @@ import seedu.staffsnap.model.applicant.Name; import seedu.staffsnap.model.applicant.Phone; import seedu.staffsnap.model.applicant.Position; +import seedu.staffsnap.model.applicant.Status; class FilterCommandParserTest { @@ -29,24 +30,30 @@ void parse_missingParts_failure() { @Test void parse_nameOnly_success() { assertParseSuccess(parser, " n/ Name", new FilterCommand(new CustomFilterPredicate(new Name("Name"), null, - null, null, null))); + null, null, null, null))); } @Test void parse_emailOnly_success() { assertParseSuccess(parser, " e/ test@test.com", new FilterCommand(new CustomFilterPredicate(null, null, - new Email("test@test.com"), null, null))); + new Email("test@test.com"), null, null, null))); } @Test void parse_positionOnly_success() { assertParseSuccess(parser, " p/ Software Engineer", new FilterCommand(new CustomFilterPredicate(null, null, - null, new Position("Software Engineer"), null))); + null, new Position("Software Engineer"), null, null))); } @Test void parse_phoneOnly_success() { assertParseSuccess(parser, " hp/ 98765432", new FilterCommand(new CustomFilterPredicate(null, new Phone( - "98765432"), null, null, null))); + "98765432"), null, null, null, null))); + } + + @Test + void parse_statusOnly_success() { + assertParseSuccess(parser, " s/ o", new FilterCommand(new CustomFilterPredicate(null, null, null, null, + null, Status.OFFERED))); } } diff --git a/src/test/java/seedu/staffsnap/logic/parser/StatusCommandParserTest.java b/src/test/java/seedu/staffsnap/logic/parser/StatusCommandParserTest.java index 3878691487f..5c057cc7126 100644 --- a/src/test/java/seedu/staffsnap/logic/parser/StatusCommandParserTest.java +++ b/src/test/java/seedu/staffsnap/logic/parser/StatusCommandParserTest.java @@ -19,7 +19,7 @@ class StatusCommandParserTest { @Test void parse_validArgs_returnsStatusCommand() { StatusCommand expectedStatusCommand = new StatusCommand(Index.fromOneBased(1), Status.OFFERED); - assertParseSuccess(parser, "1 o", expectedStatusCommand); + assertParseSuccess(parser, "1 s/ o", expectedStatusCommand); } @Test @@ -29,11 +29,12 @@ void parse_invalidArgs_throwsParseException() { @Test void parse_missingStatus_throwsParseException() { - assertParseFailure(parser, "1", String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatusCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "1", String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatusCommand.MESSAGE_NO_STATUS)); } @Test void parse_missingIndex_throwsParseException() { - assertParseFailure(parser, "o", String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatusCommand.MESSAGE_USAGE)); + assertParseFailure(parser, "s/ o", String.format(MESSAGE_INVALID_COMMAND_FORMAT, + StatusCommand.MESSAGE_NO_INDEX)); } } From 1bc6905f80b52bfcfa9b1f7cfda607258e21655f Mon Sep 17 00:00:00 2001 From: Ivan Lee <84584280+ivanleekk@users.noreply.github.com> Date: Wed, 25 Oct 2023 11:29:54 +0800 Subject: [PATCH 11/12] Filter by score, less than or greater than --- .../logic/commands/FilterCommand.java | 8 +++++++- .../staffsnap/logic/parser/CliSyntax.java | 3 +++ .../logic/parser/FilterCommandParser.java | 18 ++++++++++++++--- .../staffsnap/logic/parser/ParserUtil.java | 18 +++++++++++++++++ .../staffsnap/model/applicant/Applicant.java | 15 ++++++++++++++ .../applicant/CustomFilterPredicate.java | 20 ++++++++++++++----- .../logic/commands/FilterCommandTest.java | 16 ++++++++------- .../logic/parser/FilterCommandParserTest.java | 10 +++++----- 8 files changed, 87 insertions(+), 21 deletions(-) diff --git a/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java b/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java index f6f6b72bb50..46a7d349707 100644 --- a/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java +++ b/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java @@ -2,6 +2,8 @@ import static java.util.Objects.requireNonNull; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_GREATER_THAN_SCORE; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_LESS_THAN_SCORE; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_POSITION; @@ -29,7 +31,11 @@ public class FilterCommand extends Command { + PREFIX_EMAIL + " [EMAIL], " + PREFIX_POSITION + " [POSITION], " + PREFIX_PHONE + " [PHONE], " - + PREFIX_STATUS + " [STATUS]"; + + PREFIX_STATUS + " [STATUS], " + + PREFIX_LESS_THAN_SCORE + " [SCORE], " + + PREFIX_GREATER_THAN_SCORE + " [SCORE]"; + public static final String MESSAGE_SCORE_PARSE_FAILURE = "Score in lts/ or gts/ has to be a number with up to 1 " + + "decimal place"; private final CustomFilterPredicate predicate; diff --git a/src/main/java/seedu/staffsnap/logic/parser/CliSyntax.java b/src/main/java/seedu/staffsnap/logic/parser/CliSyntax.java index 19194a6a621..a2333de653b 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/staffsnap/logic/parser/CliSyntax.java @@ -15,5 +15,8 @@ public class CliSyntax { public static final Prefix PREFIX_TYPE = new Prefix("t/"); public static final Prefix PREFIX_RATING = new Prefix("r/"); public static final Prefix PREFIX_STATUS = new Prefix("s/"); + public static final Prefix PREFIX_LESS_THAN_SCORE = new Prefix("lts/"); + public static final Prefix PREFIX_GREATER_THAN_SCORE = new Prefix("gts/"); + } diff --git a/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java index 289399def6b..16cf755c90c 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java @@ -2,7 +2,9 @@ import static seedu.staffsnap.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_GREATER_THAN_SCORE; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_INTERVIEW; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_LESS_THAN_SCORE; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_POSITION; @@ -41,7 +43,8 @@ public FilterCommand parse(String args) throws ParseException { } ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, - PREFIX_POSITION, PREFIX_INTERVIEW, PREFIX_STATUS); + PREFIX_POSITION, PREFIX_INTERVIEW, PREFIX_STATUS, PREFIX_LESS_THAN_SCORE, + PREFIX_GREATER_THAN_SCORE); Name name = null; Phone phone = null; @@ -49,8 +52,10 @@ public FilterCommand parse(String args) throws ParseException { Position position = null; List interviewList = null; Status status = null; + Double lessThanScore = null; + Double greaterThanScore = null; argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_POSITION, - PREFIX_STATUS); + PREFIX_STATUS, PREFIX_LESS_THAN_SCORE, PREFIX_GREATER_THAN_SCORE); if (argMultimap.getValue(PREFIX_NAME).isPresent()) { name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); } @@ -69,7 +74,14 @@ public FilterCommand parse(String args) throws ParseException { if (argMultimap.getValue(PREFIX_STATUS).isPresent()) { status = ParserUtil.parseStatus(argMultimap.getValue(PREFIX_STATUS).get()); } - return new FilterCommand(new CustomFilterPredicate(name, phone, email, position, interviewList, status)); + if (argMultimap.getValue(PREFIX_LESS_THAN_SCORE).isPresent()) { + lessThanScore = ParserUtil.parseScore(argMultimap.getValue(PREFIX_LESS_THAN_SCORE).get()); + } + if (argMultimap.getValue(PREFIX_GREATER_THAN_SCORE).isPresent()) { + greaterThanScore = ParserUtil.parseScore(argMultimap.getValue(PREFIX_GREATER_THAN_SCORE).get()); + } + return new FilterCommand(new CustomFilterPredicate(name, phone, email, position, interviewList, status, + lessThanScore, greaterThanScore)); } } diff --git a/src/main/java/seedu/staffsnap/logic/parser/ParserUtil.java b/src/main/java/seedu/staffsnap/logic/parser/ParserUtil.java index 341b2321391..d8581013157 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/staffsnap/logic/parser/ParserUtil.java @@ -9,6 +9,7 @@ import seedu.staffsnap.commons.core.index.Index; import seedu.staffsnap.commons.util.StringUtil; +import seedu.staffsnap.logic.commands.FilterCommand; import seedu.staffsnap.logic.parser.exceptions.ParseException; import seedu.staffsnap.model.applicant.Descriptor; import seedu.staffsnap.model.applicant.Email; @@ -224,4 +225,21 @@ public static Status parseStatus(String status) { requireNonNull(status); return Status.findByName(status); } + + /** + * Parses a {@code String score} into a {@code Double}. + * @param score String representation of score + * @return Double score which is the average rating of all interviews + * @throws ParseException if a NumberFormatException is caught + */ + public static Double parseScore(String score) throws ParseException { + requireNonNull(score); + Double result; + try { + result = new Double(score); + } catch (NumberFormatException e) { + throw new ParseException(FilterCommand.MESSAGE_SCORE_PARSE_FAILURE); + } + return result; + } } diff --git a/src/main/java/seedu/staffsnap/model/applicant/Applicant.java b/src/main/java/seedu/staffsnap/model/applicant/Applicant.java index b6fb8a263ed..212ebc7af82 100644 --- a/src/main/java/seedu/staffsnap/model/applicant/Applicant.java +++ b/src/main/java/seedu/staffsnap/model/applicant/Applicant.java @@ -215,4 +215,19 @@ public Status getStatus() { public void setStatus(Status status) { this.status = status; } + + /** + * Get the score of an Applicant + * @return Double score of Applicant + */ + public Double getScore() { + List interviews = getInterviews(); + Double totalScore = 0.; + for (Interview interview: interviews + ) { + totalScore += new Double(interview.rating.value); + } + Double averageScore = totalScore / interviews.size(); + return averageScore; + } } diff --git a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java index c96ef69ab06..34df9a85bd5 100644 --- a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java +++ b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java @@ -22,6 +22,8 @@ public class CustomFilterPredicate implements Predicate { private final Position position; private final List interviews; private final Status status; + private final Double lessThanScore; + private final Double greaterThanScore; /** * Constructor for CustomFilterPredicate @@ -33,13 +35,15 @@ public class CustomFilterPredicate implements Predicate { * @param interviews Interviews applicant has to go through */ public CustomFilterPredicate(Name name, Phone phone, Email email, Position position, List interviews, - Status status) { + Status status, Double lessThanScore, Double greaterThanScore) { this.name = name; this.phone = phone; this.email = email; this.position = position; this.interviews = interviews; this.status = status; + this.lessThanScore = lessThanScore; + this.greaterThanScore = greaterThanScore; } /** @@ -73,10 +77,16 @@ public boolean test(Applicant applicant) { return false; } } - /* - * TODO: - * add filtering for scores - */ + if (this.lessThanScore != null) { + if (applicant.getScore() >= this.lessThanScore) { + return false; + } + } + if (this.greaterThanScore != null) { + if (applicant.getScore() <= this.greaterThanScore) { + return false; + } + } return true; } diff --git a/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java b/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java index fd5653b84f0..935bcff524a 100644 --- a/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java +++ b/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java @@ -52,9 +52,9 @@ public void equals() { Status status2 = CARL.getStatus(); CustomFilterPredicate firstPredicate = new CustomFilterPredicate(name1, phone1, email1, position1, - interviewList1, status1); + interviewList1, status1, null, null); CustomFilterPredicate secondPredicate = new CustomFilterPredicate(name2, phone2, email2, position2, - interviewList2, status2); + interviewList2, status2, null, null); FilterCommand filterFirstCommand = new FilterCommand(firstPredicate); FilterCommand filterSecondCommand = new FilterCommand(secondPredicate); @@ -79,7 +79,7 @@ public void equals() { @Test public void execute_zeroKeywords_allApplicantsFound() { String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 8); - CustomFilterPredicate predicate = new CustomFilterPredicate(null, null, null, null, null, null); + CustomFilterPredicate predicate = new CustomFilterPredicate(null, null, null, null, null, null, null, null); FilterCommand command = new FilterCommand(predicate); expectedModel.updateFilteredApplicantList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -89,7 +89,8 @@ public void execute_zeroKeywords_allApplicantsFound() { @Test public void execute_partialName_multipleApplicantsFound() { String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 4); - CustomFilterPredicate predicate = new CustomFilterPredicate(new Name("a"), null, null, null, null, null); + CustomFilterPredicate predicate = new CustomFilterPredicate(new Name("a"), null, null, null, null, null, + null, null); FilterCommand command = new FilterCommand(predicate); expectedModel.updateFilteredApplicantList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -100,7 +101,7 @@ public void execute_partialName_multipleApplicantsFound() { public void execute_multipleKeywords_singleApplicantFound() { String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 1); CustomFilterPredicate predicate = new CustomFilterPredicate(FIONA.getName(), FIONA.getPhone(), null, null, - null, null); + null, null, null, null); FilterCommand command = new FilterCommand(predicate); expectedModel.updateFilteredApplicantList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -111,7 +112,7 @@ public void execute_multipleKeywords_singleApplicantFound() { public void execute_multipleKeywords_zeroApplicantsFound() { String expectedMessage = String.format(MESSAGE_APPLICANTS_LISTED_OVERVIEW, 0); CustomFilterPredicate predicate = new CustomFilterPredicate(ALICE.getName(), BENSON.getPhone(), - CARL.getEmail(), DANIEL.getPosition(), ELLE.getInterviews(), FIONA.getStatus()); + CARL.getEmail(), DANIEL.getPosition(), ELLE.getInterviews(), FIONA.getStatus(), null, null); FilterCommand command = new FilterCommand(predicate); expectedModel.updateFilteredApplicantList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); @@ -122,7 +123,8 @@ public void execute_multipleKeywords_zeroApplicantsFound() { @Test public void toStringMethod() { - CustomFilterPredicate predicate = new CustomFilterPredicate(FIONA.getName(), null, null, null, null, null); + CustomFilterPredicate predicate = new CustomFilterPredicate(FIONA.getName(), null, null, null, null, null, + null, null); FilterCommand findCommand = new FilterCommand(predicate); String expected = FilterCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; assertEquals(expected, findCommand.toString()); diff --git a/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java b/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java index a0044f9fd98..b06b06a0453 100644 --- a/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java +++ b/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java @@ -30,30 +30,30 @@ void parse_missingParts_failure() { @Test void parse_nameOnly_success() { assertParseSuccess(parser, " n/ Name", new FilterCommand(new CustomFilterPredicate(new Name("Name"), null, - null, null, null, null))); + null, null, null, null, null, null))); } @Test void parse_emailOnly_success() { assertParseSuccess(parser, " e/ test@test.com", new FilterCommand(new CustomFilterPredicate(null, null, - new Email("test@test.com"), null, null, null))); + new Email("test@test.com"), null, null, null, null, null))); } @Test void parse_positionOnly_success() { assertParseSuccess(parser, " p/ Software Engineer", new FilterCommand(new CustomFilterPredicate(null, null, - null, new Position("Software Engineer"), null, null))); + null, new Position("Software Engineer"), null, null, null, null))); } @Test void parse_phoneOnly_success() { assertParseSuccess(parser, " hp/ 98765432", new FilterCommand(new CustomFilterPredicate(null, new Phone( - "98765432"), null, null, null, null))); + "98765432"), null, null, null, null, null, null))); } @Test void parse_statusOnly_success() { assertParseSuccess(parser, " s/ o", new FilterCommand(new CustomFilterPredicate(null, null, null, null, - null, Status.OFFERED))); + null, Status.OFFERED, null, null))); } } From e21018938590e9999d406757db821c22730ebb1e Mon Sep 17 00:00:00 2001 From: Ivan Lee <84584280+ivanleekk@users.noreply.github.com> Date: Thu, 26 Oct 2023 11:28:41 +0800 Subject: [PATCH 12/12] Address review comments --- .../seedu/staffsnap/commons/util/StringUtil.java | 13 +++++++------ .../staffsnap/logic/commands/FilterCommand.java | 5 ++--- .../staffsnap/logic/parser/FilterCommandParser.java | 1 - .../seedu/staffsnap/logic/parser/ParserUtil.java | 4 +++- .../seedu/staffsnap/model/applicant/Applicant.java | 3 +-- .../model/applicant/CustomFilterPredicate.java | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/seedu/staffsnap/commons/util/StringUtil.java b/src/main/java/seedu/staffsnap/commons/util/StringUtil.java index 5409d3c125e..3fe3b5730ce 100644 --- a/src/main/java/seedu/staffsnap/commons/util/StringUtil.java +++ b/src/main/java/seedu/staffsnap/commons/util/StringUtil.java @@ -39,14 +39,15 @@ public static boolean containsWordIgnoreCase(String sentence, String word) { /** * Returns true if the {@code sentence} contains the {@code word}. - * Ignores case, but a full word match is required. + * Ignores case. *
examples:
-     *       containsWordIgnoreCase("ABc def", "abc") == true
-     *       containsWordIgnoreCase("ABc def", "DEF") == true
-     *       containsWordIgnoreCase("ABc def", "AB") == false //not a full word match
+     *       containsStringIgnoreCase("ABc def", "abc") == true
+     *       containsStringIgnoreCase("ABc def", "DEF") == true
+     *       containsStringIgnoreCase("ABc def", "AB") == true
+     *       containsStringIgnoreCase("ABc def", "acd") == false // "acd" is not a substring in "ABc def"
      *       
- * @param sentence cannot be null - * @param word cannot be null, cannot be empty, must be a single word + * @param sentence a String that is not null + * @param word a String that is not empty and is not null */ public static boolean containsStringIgnoreCase(String sentence, String word) { requireNonNull(sentence); diff --git a/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java b/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java index 46a7d349707..abdd2877232 100644 --- a/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java +++ b/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java @@ -52,8 +52,8 @@ public CommandResult execute(Model model) { } /** - * Checks if the applicant exists. - * @param other Other applicant. + * Checks if the two FilterCommand objects are equivalent, by comparing the equivalence of their predicates. + * @param other Other FilterCommand. * @return true if equals, false if not equals. */ @Override @@ -68,7 +68,6 @@ public boolean equals(Object other) { } FilterCommand otherFilterCommand = (FilterCommand) other; - System.out.println("predicate = " + predicate); return predicate.equals(otherFilterCommand.predicate); } diff --git a/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java index 16cf755c90c..f73f075e627 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java @@ -26,7 +26,6 @@ /** * Parses input arguments and creates a new FilterCommand object */ - public class FilterCommandParser implements Parser { /** diff --git a/src/main/java/seedu/staffsnap/logic/parser/ParserUtil.java b/src/main/java/seedu/staffsnap/logic/parser/ParserUtil.java index d8581013157..11842dbedd4 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/staffsnap/logic/parser/ParserUtil.java @@ -218,8 +218,9 @@ public static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Pref /** * Parses a {@code String status} into a {@code Status}. + * * @param status String representation of Status - * @return Status if successful, or null of no matching status is found. + * @return Status if successful, or null if no matching status is found. */ public static Status parseStatus(String status) { requireNonNull(status); @@ -228,6 +229,7 @@ public static Status parseStatus(String status) { /** * Parses a {@code String score} into a {@code Double}. + * * @param score String representation of score * @return Double score which is the average rating of all interviews * @throws ParseException if a NumberFormatException is caught diff --git a/src/main/java/seedu/staffsnap/model/applicant/Applicant.java b/src/main/java/seedu/staffsnap/model/applicant/Applicant.java index 212ebc7af82..583dd461897 100644 --- a/src/main/java/seedu/staffsnap/model/applicant/Applicant.java +++ b/src/main/java/seedu/staffsnap/model/applicant/Applicant.java @@ -223,8 +223,7 @@ public void setStatus(Status status) { public Double getScore() { List interviews = getInterviews(); Double totalScore = 0.; - for (Interview interview: interviews - ) { + for (Interview interview: interviews) { totalScore += new Double(interview.rating.value); } Double averageScore = totalScore / interviews.size(); diff --git a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java index 34df9a85bd5..fbfa6ae530f 100644 --- a/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java +++ b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java @@ -47,7 +47,7 @@ public CustomFilterPredicate(Name name, Phone phone, Email email, Position posit } /** - * @param applicant the input argument + * @param applicant the applicant to be tested. * @return true if applicant matches all specified fields in the predicate */ @Override