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/README.md b/README.md index 1ebfabf9643..cd884b3250e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ It is based on the AddressBook-Level3 project created by the [SE-EDU initiative] > An applicant management program for Hiring Managers to track applicants throughout the hiring process. -![Ui](docs/images/Ui.png) +![Ui](docs/images/readme/Ui.png) Staff-Snap is a desktop app for HR Managers to track staff information, optimized for use via a Command Line Interface (CLI) while still having the benefits of a Graphical User Interface (GUI). If you can type fast, Staff-Snap can get your staff information management tasks done faster than traditional GUI apps. diff --git a/build.gradle b/build.gradle index 19e2f352a54..1981f95e368 100644 --- a/build.gradle +++ b/build.gradle @@ -69,4 +69,8 @@ shadowJar { archiveFileName = 'staffsnap.jar' } +run { + enableAssertions = true +} + defaultTasks 'clean', 'test' diff --git a/docs/AboutUs.md b/docs/AboutUs.md index 761d3a42c93..6d31041025d 100644 --- a/docs/AboutUs.md +++ b/docs/AboutUs.md @@ -13,7 +13,7 @@ You can reach us at the email `craigton.lian[at]gmail.com` ### Craigton Lian Ee John - + * Links: @@ -28,7 +28,7 @@ You can reach us at the email `craigton.lian[at]gmail.com` ### Austin Huang De Yu - + * Links: [[github](http://github.com/austinhuang1203)] @@ -39,7 +39,7 @@ You can reach us at the email `craigton.lian[at]gmail.com` ### Ivan Lee Kai Kiat - + * Links: @@ -52,7 +52,7 @@ You can reach us at the email `craigton.lian[at]gmail.com` ### Celestine Tan Yen Tong - + * Links: @@ -66,7 +66,7 @@ You can reach us at the email `craigton.lian[at]gmail.com` ### Wang Jingting - + * Links: diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index 2ae6b3d0c8f..9d8ae9e0106 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,171 @@ _{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. +### Sort feature +#### Implementation + +The sort feature is facilitated by `Descriptor`, an enumeration which describes the valid fields which can be used to +sort an applicant. + +To enable sorting, `Applicant` implements `Comparable`, to allow for comparison between applicants. +To allow for applicants to be sorted by different descriptors, `Applicant` is augmented to contain a static `Descriptor` +field. This is used in `Applicant#compareTo()`, where a switch case checking the state of the `Descriptor` field will +then compare the specified field of both applicants. + +In order to enable comparison of each valid field, these fields will implement the `Comparable` interface. Currently +valid +fields for sorting are + +1. Name +2. Phone + +#### Steps to trigger + +1. User opens the app +2. User enters `sort d/ [valid field]`, where valid field is one of the fields listed above to be sorted by + +Once step 2 has been completed, the GUI will update and refresh the applicant list to be sorted by the specified field. + +The following diagram summarises what happens when a user executes a Sort command: + + +#### Design considerations + +##### Aspect: How to compare applicants + +- Alternative 1 (current choice): use Comparable interface + - Pros: Standard method of comparison between objects in Java and implementing it will make it compatible with most + other sorting functions in Java. Easily extensible by adding more cases to the switch statement, to compare by + other fields when it becomes supported. + - Cons: Applicant#compareTo has to return different values depending on which descriptor has been chosen, causing + some bugs when working with other Java functions as the order of Objects compared to each other is not meant to + change during runtime. + +##### Aspect: Command syntax + +- Alternative 1 (current choice): `sort d/ [valid field]` + - Pros: Simple and minimal text fields, with a single prefix required to enable sorting. + - Cons: Only able to sort in ascending order. +- Alternative 2: `sort d/ [valid field] o/ [a/d]` + - Pros: Able to sort in either ascending or descending order. + - Cons: Requires additional input from the user, slowing down the use of the command. +- Alternative 3: `sort d/ [valid field] o/ [a/d]` where `o/` is optional + - Pros: Retains the ability to sort in either order, but also the conciseness of Alternative 1. + - Cons: Users who are not aware of the `o/` feature may not use it. + +### 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 +5. Status +6. Less than score +7. Greater than score + +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/, s/, lts/, gts/] [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] s/ [Status] lts/ [Score] gts/ [Score]` + - 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/, s/, lts/, gts/] [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/, s/, lts/, gts/] [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 +503,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 +524,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 +534,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 +553,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 +572,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 +596,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 +615,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 +639,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 +658,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 +677,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 +696,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 +711,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 +719,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 +746,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 +766,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 +778,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 +815,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 +833,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 +851,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/UserGuide.md b/docs/UserGuide.md index 99911000b45..a029031d3b2 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -8,7 +8,7 @@ ## User Interface Guide -![User Interface Guide Example](./images/userInterfaceGuide.png) +![User Interface Guide Example](images/user-guide/userInterfaceGuide.png) @@ -17,7 +17,7 @@ -**Notation Guide** :rocket:
+**Notation Guide**
* Words in `UPPER_CASE` are the parameters to be supplied by the user. * Items in square brackets are optional. @@ -29,12 +29,12 @@ --- ### `help` : Viewing help -Displays a message explaining how to access the help page. +Opens up your browser to view the help page. Format: `help` UI mockup: -![Help UI Mockup](./images/help.png) +![Help UI Mockup](images/user-guide/help.png) --- ### `add` : Adding a new applicant @@ -48,7 +48,7 @@ Example: * `add n/Jane Greenwood p/Project Manager e/janeg@yahoo.com hp/91234567` UI mockup: -![Add UI Mockup](./images/add.png) +![Add UI Mockup](images/user-guide/add.png) --- ### `edit` : Editing an applicant @@ -65,7 +65,7 @@ Example: * `edit 2 hp/80081234 e/newEmail@hotmail.com` edits the phone number and email of the 2nd applicant in the list. UI mockup: -![Edit UI Mockup](./images/edit.png) +![Edit UI Mockup](images/user-guide/edit.png) --- ### `list` : Listing all applicants @@ -75,7 +75,7 @@ Displays the full list of all applicants. Format: `list` UI mockup: -![List UI Mockup](./images/list.png) +![List UI Mockup](images/user-guide/list.png) --- ### `delete` : Deleting an applicant @@ -92,7 +92,7 @@ Examples: * `sort d/name` followed by `delete 3` deletes the 3rd person in the sorted applicant list. UI mockup: -![Delete UI Mockup](./images/delete.png) +![Delete UI Mockup](images/user-guide/delete.png) --- ### `find` : Finding an applicant by name @@ -111,7 +111,7 @@ Examples: * `find IVAN CHEW` finds any applicant whose name contains “ivan” or contains “chew”. UI mockup: -![Find UI Mockup](./images/find.png) +![Find UI Mockup](images/user-guide/find.png) --- ### `sort`: Sorting applicants by descriptor @@ -119,36 +119,66 @@ UI mockup: Sorts the applicant list by using a particular descriptor as the sorting criteria. Format: `sort d/DESCRIPTOR` -* `DESCRIPTOR` must be either `name` or `phone`. +* `DESCRIPTOR` must be either `name` or `phone` or `email` or `position` or `score` or `status`. Examples: * `sort d/name` sorts the applicant list by name in alphabetical order. * `sort d/phone` sorts the applicant list by phone numbers in ascending order. +* `sort d/email` sorts the applicant list by email in alphabetical order. +* `sort d/position` sorts the applicant list by positions in alphabetical order. +* `sort d/score` sorts the applicant list by score in descending order. +* `sort d/status` sorts the applicant list by status in alphabetical order. UI mockup: -![Sort UI Mockup](./images/sort.png) +![Sort UI Mockup](images/user-guide/sort.png) --- ### `addi` : Adding an interview to an applicant Adds a new interview to an applicant. -Format: `addi INDEX t/TYPE` +Format: `addi INDEX t/TYPE [r/RATING]` Examples: -* `addi 1 t/technical` adds a Technical interview to the 1st person in the displayed applicant list. -* `addi 3 t/screening` +* `addi 1 t/technical r/8.6` adds a Technical interview with rating 8.6 to the 1st person in the displayed applicant list. +* `addi 3 t/screening` adds a Screening interview without rating to the 3rd person in the displayed applicant list. --- ### `editi` : Editing an interview of an applicant Edits an interview of an applicant. -Format: `editi INDEX i/INTERVIEW_INDEX t/TYPE` +Format: `editi INDEX i/INTERVIEW_INDEX [t/TYPE] [r/RATING]` +* Edits the person at the specified `INDEX`. The index refers to the index number shown in the displayed person list. +* At least one of the optional fields must be provided. +* Existing values will be updated by the input values. + +Examples: +* `editi 1 i/1 t/technical r/7.8` edits the 1st interview of the 1st person in the displayed applicant list to a technical interview with rating 7.8. +* `editi 3 i/2 t/screening` edits the 2nd interview type of the 3rd person in the displayed applicant list to a screening interview. +* `editi 2 i/1 r/8.9` edits the 1st interview rating of the 2nd person in the displayed applicant list to 8.9. + +--- +### `deletei` : Deleting an interview from an applicant + +Deletes an interview from an applicant. + +Format: `deletei INDEX i/INTERVIEW_INDEX` + +Examples: +* `deletei 1 i/2` deletes the 2nd interview of the 1st person in the displayed applicant list. + +--- +### `status` : Editing an applicant status + +Edits the status of an applicant. + +Format: `status INDEX s/STATUS` +* Edits the person at the specified `INDEX`. The index refers to the index number shown in the displayed person list. +* `STATUS` must be either `o`(offered) or `r`(rejected) or `u`(undecided). Examples: -* `editi 1 i/1 t/technical` edits the 1st interview of the 1st person in the displayed applicant list to a technical interview. -* `editi 3 i/2 t/screening` +* `status 3 s/o` updates the status of the 3rd person in the displayed applicant list to OFFERED. --- ### `clear` : Clearing all applicant entries @@ -158,7 +188,7 @@ Clears all the current data stored in the system. Format: `clear` UI mockup: -![Clear UI Mockup](./images/clear.png) +![Clear UI Mockup](images/user-guide/clear.png) --- ### `exit` : Exiting the program @@ -176,7 +206,7 @@ Automatically saves the data to a local storage whenever there is a change to th ### Editing the data file - Editing the data file directly may result in unexpected behaviour. + If the format of the edited data file is invalid, Staff-Snap will override the existing data file with an empty data file in the next run. Please make a backup before you attempt to edit the data file! Staff-Snap applicant data are saved automatically as a JSON file `[JAR file location]/data/applicantBook.json`. Advanced users are welcome to update data directly by editing that data file. diff --git a/docs/diagrams/FilterCommandActivityDiagram.puml b/docs/diagrams/FilterCommandActivityDiagram.puml new file mode 100644 index 00000000000..23c4622ad33 --- /dev/null +++ b/docs/diagrams/FilterCommandActivityDiagram.puml @@ -0,0 +1,42 @@ +@startuml +'https://plantuml.com/activity-diagram-beta + +start +:User enters filter command syntax; +:ApplicantBookParser and FilterCommandParser +parse 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; + :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 + +else (false) +label 1 +label 2 +label 3 + +:Throw ParseException with + invalid command format + message and proper Filter + syntax; + :Display error message; + stop +endif + +@enduml + diff --git a/docs/diagrams/SortCommandActivityDiagram.puml b/docs/diagrams/SortCommandActivityDiagram.puml new file mode 100644 index 00000000000..4426ca620f5 --- /dev/null +++ b/docs/diagrams/SortCommandActivityDiagram.puml @@ -0,0 +1,22 @@ +@startuml +'https://plantuml.com/activity-diagram-beta + +start +:User enters sort command syntax; +:ApplicantBookParser parses command_word; +:SortCommandParser parses arguments; +if (Descriptor is present) then (true) + :Execute SortCommand; + :Update Applicant Descriptor; + :Refresh Applicant List; + :Display success message; + :Show updated list in GUI; + stop +else (false) + :Throw ParseException with + invalid command format + message and proper Sort + syntax; + :Display error message; + stop +@enduml diff --git a/docs/images/austinhuang1203.png b/docs/images/developer-profiles/austinhuang1203.png similarity index 100% rename from docs/images/austinhuang1203.png rename to docs/images/developer-profiles/austinhuang1203.png diff --git a/docs/images/celestinetan03.png b/docs/images/developer-profiles/celestinetan03.png similarity index 100% rename from docs/images/celestinetan03.png rename to docs/images/developer-profiles/celestinetan03.png diff --git a/docs/images/craigtonlian.png b/docs/images/developer-profiles/craigtonlian.png similarity index 100% rename from docs/images/craigtonlian.png rename to docs/images/developer-profiles/craigtonlian.png diff --git a/docs/images/ivanleekk.png b/docs/images/developer-profiles/ivanleekk.png similarity index 100% rename from docs/images/ivanleekk.png rename to docs/images/developer-profiles/ivanleekk.png diff --git a/docs/images/jingting1412.png b/docs/images/developer-profiles/jingting1412.png similarity index 100% rename from docs/images/jingting1412.png rename to docs/images/developer-profiles/jingting1412.png diff --git a/docs/images/Ui.png b/docs/images/readme/Ui.png similarity index 100% rename from docs/images/Ui.png rename to docs/images/readme/Ui.png diff --git a/docs/images/add.png b/docs/images/user-guide/add.png similarity index 100% rename from docs/images/add.png rename to docs/images/user-guide/add.png diff --git a/docs/images/clear.png b/docs/images/user-guide/clear.png similarity index 100% rename from docs/images/clear.png rename to docs/images/user-guide/clear.png diff --git a/docs/images/delete.png b/docs/images/user-guide/delete.png similarity index 100% rename from docs/images/delete.png rename to docs/images/user-guide/delete.png diff --git a/docs/images/edit.png b/docs/images/user-guide/edit.png similarity index 100% rename from docs/images/edit.png rename to docs/images/user-guide/edit.png diff --git a/docs/images/filter.png b/docs/images/user-guide/filter.png similarity index 100% rename from docs/images/filter.png rename to docs/images/user-guide/filter.png diff --git a/docs/images/find.png b/docs/images/user-guide/find.png similarity index 100% rename from docs/images/find.png rename to docs/images/user-guide/find.png diff --git a/docs/images/help.png b/docs/images/user-guide/help.png similarity index 100% rename from docs/images/help.png rename to docs/images/user-guide/help.png diff --git a/docs/images/list.png b/docs/images/user-guide/list.png similarity index 100% rename from docs/images/list.png rename to docs/images/user-guide/list.png diff --git a/docs/images/sort.png b/docs/images/user-guide/sort.png similarity index 100% rename from docs/images/sort.png rename to docs/images/user-guide/sort.png diff --git a/docs/images/userInterfaceGuide.png b/docs/images/user-guide/userInterfaceGuide.png similarity index 100% rename from docs/images/userInterfaceGuide.png rename to docs/images/user-guide/userInterfaceGuide.png diff --git a/docs/index.md b/docs/index.md index ddc13a63f3f..7b01dffda80 100644 --- a/docs/index.md +++ b/docs/index.md @@ -8,9 +8,9 @@ [![CI Status](https://github.com/AY2324S1-CS2103T-W08-1/tp/actions/workflows/gradle.yml/badge.svg)](https://github.com/AY2324S1-CS2103T-W08-1/tp/actions) [![codecov](https://codecov.io/gh/AY2324S1-CS2103T-W08-1/tp/graph/badge.svg?token=7PPPGQNQFE)](https://codecov.io/gh/AY2324S1-CS2103T-W08-1/tp) -![Ui](images/Ui.png) +![Ui](images/readme/Ui.png) -**Staff-Snap is a desktop application for managing your employee details.** While it has a GUI, most of the user interactions happen using a CLI (Command Line Interface). +**Staff-Snap is a desktop application for managing your applicant details during your recruitment cycle.** While it has a GUI, most of the user interactions happen using a CLI (Command Line Interface). * If you are interested in using Staff-Snap, head over to the [_Quick Start_ section of the **User Guide**](UserGuide.html#quick-start). * If you are interested about developing Staff-Snap, the [**Developer Guide**](DeveloperGuide.html) is a good place to start. diff --git a/src/main/java/seedu/staffsnap/MainApp.java b/src/main/java/seedu/staffsnap/MainApp.java index f67c2f57b5f..0191792cc3b 100644 --- a/src/main/java/seedu/staffsnap/MainApp.java +++ b/src/main/java/seedu/staffsnap/MainApp.java @@ -37,7 +37,7 @@ */ public class MainApp extends Application { - public static final Version VERSION = new Version(0, 2, 2, true); + public static final Version VERSION = new Version(1, 2, 0, false); private static final Logger logger = LogsCenter.getLogger(MainApp.class); @@ -82,7 +82,7 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { try { applicantBookOptional = storage.readApplicantBook(); if (!applicantBookOptional.isPresent()) { - logger.info("No applicant book found at file path. A new data file will be created at" + logger.info("No applicant book found at file path. A new data file will be created at " + storage.getApplicantBookFilePath() + " populated with a sample ApplicantBook."); } @@ -173,7 +173,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) { @Override public void start(Stage primaryStage) { - logger.info("Starting ApplicantBook " + MainApp.VERSION); + logger.info("Starting Staff-Snap " + MainApp.VERSION); ui.start(primaryStage); } diff --git a/src/main/java/seedu/staffsnap/commons/util/StringUtil.java b/src/main/java/seedu/staffsnap/commons/util/StringUtil.java index 4d11a031385..3fe3b5730ce 100644 --- a/src/main/java/seedu/staffsnap/commons/util/StringUtil.java +++ b/src/main/java/seedu/staffsnap/commons/util/StringUtil.java @@ -31,13 +31,33 @@ 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. + *
examples:
+     *       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 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); + 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/logic/Messages.java b/src/main/java/seedu/staffsnap/logic/Messages.java index 61070433fe4..13b8aa920d1 100644 --- a/src/main/java/seedu/staffsnap/logic/Messages.java +++ b/src/main/java/seedu/staffsnap/logic/Messages.java @@ -45,7 +45,13 @@ public static String format(Applicant applicant) { .append("; Position: ") .append(applicant.getPosition()) .append("; Interviews: "); - applicant.getInterviews().forEach(builder::append); + applicant.getInterviews().forEach(interview -> + builder.append(interview.getType()) + .append("(") + .append(interview.getRating()) + .append("); ")); + builder.append("; Status: ") + .append(applicant.getStatus()); return builder.toString(); } diff --git a/src/main/java/seedu/staffsnap/logic/commands/AddInterviewCommand.java b/src/main/java/seedu/staffsnap/logic/commands/AddInterviewCommand.java index 75cea964b9d..8b59ae27a13 100644 --- a/src/main/java/seedu/staffsnap/logic/commands/AddInterviewCommand.java +++ b/src/main/java/seedu/staffsnap/logic/commands/AddInterviewCommand.java @@ -1,6 +1,7 @@ package seedu.staffsnap.logic.commands; import static java.util.Objects.requireNonNull; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_RATING; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_TYPE; import static seedu.staffsnap.model.Model.PREDICATE_HIDE_ALL_APPLICANTS; import static seedu.staffsnap.model.Model.PREDICATE_SHOW_ALL_APPLICANTS; @@ -25,9 +26,12 @@ public class AddInterviewCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an interview to an applicant identified " + "by the index number used in the displayed applicant list. " + "Parameters: INDEX (must be a positive integer)\n" - + PREFIX_TYPE + "TYPE\n" + + PREFIX_TYPE + "TYPE" + " " + + "[" + PREFIX_RATING + "RATING]...\n" + "Example: " + COMMAND_WORD + " " - + PREFIX_TYPE + "technical"; + + "1 " + + PREFIX_TYPE + "technical" + " " + + PREFIX_RATING + "8.0"; public static final String MESSAGE_SUCCESS = "New interview added to applicant: %1$s"; public static final String MESSAGE_DUPLICATE_INTERVIEW = "This interview already exists for this applicant"; @@ -56,7 +60,8 @@ public CommandResult execute(Model model) throws CommandException { Applicant applicantToEdit = lastShownList.get(index.getZeroBased()); - if (applicantToEdit.getInterviews().contains(interviewToAdd)) { + if (applicantToEdit.getInterviews().contains(interviewToAdd) + || interviewToAdd.isContainedIn(applicantToEdit.getInterviews())) { throw new CommandException(MESSAGE_DUPLICATE_INTERVIEW); } diff --git a/src/main/java/seedu/staffsnap/logic/commands/EditCommand.java b/src/main/java/seedu/staffsnap/logic/commands/EditCommand.java index 09f7894fe92..edd775b5834 100644 --- a/src/main/java/seedu/staffsnap/logic/commands/EditCommand.java +++ b/src/main/java/seedu/staffsnap/logic/commands/EditCommand.java @@ -24,6 +24,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; /** @@ -53,7 +54,7 @@ public class EditCommand extends Command { private final EditApplicantDescriptor editApplicantDescriptor; /** - * @param index of the applicant in the filtered applicant list to edit + * @param index of the applicant in the filtered applicant list to edit * @param editApplicantDescriptor details to edit the applicant with */ public EditCommand(Index index, EditApplicantDescriptor editApplicantDescriptor) { @@ -96,8 +97,8 @@ public CommandResult execute(Model model) throws CommandException { * Creates and returns a {@code Applicant} with the details of {@code applicantToEdit} * edited with {@code editApplicantDescriptor}. */ - private static Applicant createEditedApplicant( - Applicant applicantToEdit, EditApplicantDescriptor editApplicantDescriptor) { + private static Applicant createEditedApplicant(Applicant applicantToEdit, + EditApplicantDescriptor editApplicantDescriptor) { assert applicantToEdit != null; Name updatedName = editApplicantDescriptor.getName().orElse(applicantToEdit.getName()); @@ -105,8 +106,10 @@ private static Applicant createEditedApplicant( Email updatedEmail = editApplicantDescriptor.getEmail().orElse(applicantToEdit.getEmail()); Position updatedPosition = editApplicantDescriptor.getPosition().orElse(applicantToEdit.getPosition()); List updatedInterviews = applicantToEdit.getInterviews(); + Status updatedStatus = editApplicantDescriptor.getStatus().orElse(applicantToEdit.getStatus()); - return new Applicant(updatedName, updatedPhone, updatedEmail, updatedPosition, updatedInterviews); + return new Applicant(updatedName, updatedPhone, updatedEmail, updatedPosition, + updatedInterviews, updatedStatus); } @Override @@ -129,8 +132,7 @@ public boolean equals(Object other) { public String toString() { return new ToStringBuilder(this) .add("index", index) - .add("editApplicantDescriptor", editApplicantDescriptor) - .toString(); + .add("editApplicantDescriptor", editApplicantDescriptor).toString(); } /** @@ -144,7 +146,11 @@ public static class EditApplicantDescriptor { private Position position; private List interviews; - public EditApplicantDescriptor() {} + + private Status status; + + public EditApplicantDescriptor() { + } /** * Copy constructor. @@ -156,6 +162,7 @@ public EditApplicantDescriptor(EditApplicantDescriptor toCopy) { setEmail(toCopy.email); setPosition(toCopy.position); setInterviews(toCopy.interviews); + setStatus(toCopy.status); } /** @@ -214,6 +221,15 @@ public Optional> getInterviews() { return (interviews != null) ? Optional.of(Collections.unmodifiableList(interviews)) : Optional.empty(); } + public void setStatus(Status status) { + this.status = status; + } + + public Optional getStatus() { + return Optional.ofNullable(status); + } + + @Override public boolean equals(Object other) { if (other == this) { @@ -229,7 +245,8 @@ public boolean equals(Object other) { return Objects.equals(name, otherEditApplicantDescriptor.name) && Objects.equals(phone, otherEditApplicantDescriptor.phone) && Objects.equals(email, otherEditApplicantDescriptor.email) - && Objects.equals(position, otherEditApplicantDescriptor.position); + && Objects.equals(position, otherEditApplicantDescriptor.position) + && Objects.equals(status, otherEditApplicantDescriptor.status); } @Override @@ -239,6 +256,7 @@ public String toString() { .add("phone", phone) .add("email", email) .add("position", position) + .add("status", status).toString() .toString(); } } diff --git a/src/main/java/seedu/staffsnap/logic/commands/EditInterviewCommand.java b/src/main/java/seedu/staffsnap/logic/commands/EditInterviewCommand.java index 5c2455e0d6a..de84633a07b 100644 --- a/src/main/java/seedu/staffsnap/logic/commands/EditInterviewCommand.java +++ b/src/main/java/seedu/staffsnap/logic/commands/EditInterviewCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_INTERVIEW; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_RATING; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_TYPE; import static seedu.staffsnap.model.Model.PREDICATE_HIDE_ALL_APPLICANTS; import static seedu.staffsnap.model.Model.PREDICATE_SHOW_ALL_APPLICANTS; @@ -18,6 +19,7 @@ import seedu.staffsnap.model.Model; import seedu.staffsnap.model.applicant.Applicant; import seedu.staffsnap.model.interview.Interview; +import seedu.staffsnap.model.interview.Rating; /** * Edits the details of an existing interview of an applicant. @@ -32,10 +34,12 @@ public class EditInterviewCommand extends Command { + "Existing values will be overwritten by the input values.\n" + "Parameters: INDEX (must be a positive integer) " + PREFIX_INTERVIEW + "INTERVIEW_INDEX " - + PREFIX_TYPE + "TYPE\n" + + "[" + PREFIX_TYPE + "TYPE] \n" + + "[" + PREFIX_RATING + "RATING] \n" + "Example: " + COMMAND_WORD + " 1 " + PREFIX_INTERVIEW + "2 " - + PREFIX_TYPE + "Behavioral"; + + PREFIX_TYPE + "Behavioral " + + PREFIX_RATING + "8.0"; public static final String MESSAGE_EDIT_INTERVIEW_SUCCESS = "Edited interview of Applicant: %1$s"; public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; @@ -79,7 +83,8 @@ public CommandResult execute(Model model) throws CommandException { Interview interviewToEdit = applicantToEdit.getInterviews().get(interviewIndex.getZeroBased()); Interview editedInterview = createEditedInterview(interviewToEdit, editInterviewDescriptor); - if (!interviewToEdit.equals(editedInterview) && applicantToEdit.getInterviews().contains(editedInterview)) { + if (!interviewToEdit.getType().equals(editedInterview.getType()) + && editedInterview.isContainedIn(applicantToEdit.getInterviews())) { throw new CommandException(MESSAGE_DUPLICATE_INTERVIEW); } @@ -100,8 +105,9 @@ private static Interview createEditedInterview( assert interviewToEdit != null; String updatedType = editInterviewDescriptor.getType().orElse(interviewToEdit.getType()); + Rating updatedRating = editInterviewDescriptor.getRating().orElse(interviewToEdit.getRating()); - return new Interview(updatedType); + return new Interview(updatedType, updatedRating); } @Override @@ -136,6 +142,7 @@ public String toString() { */ public static class EditInterviewDescriptor { private String type; + private Rating rating; public EditInterviewDescriptor() {} @@ -145,13 +152,14 @@ public EditInterviewDescriptor() {} */ public EditInterviewDescriptor(EditInterviewDescriptor toCopy) { setType(toCopy.type); + setRating(toCopy.rating); } /** * Returns true if at least one field is edited. */ public boolean isAnyFieldEdited() { - return CollectionUtil.isAnyNonNull(type); + return CollectionUtil.isAnyNonNull(type, rating); } public void setType(String type) { @@ -162,6 +170,14 @@ public Optional getType() { return Optional.ofNullable(type); } + public void setRating(Rating rating) { + this.rating = rating; + } + + public Optional getRating() { + return Optional.ofNullable(rating); + } + @Override public boolean equals(Object other) { if (other == this) { @@ -174,13 +190,15 @@ public boolean equals(Object other) { } EditInterviewDescriptor otherEditInterviewDescriptor = (EditInterviewDescriptor) other; - return Objects.equals(type, otherEditInterviewDescriptor.type); + return Objects.equals(type, otherEditInterviewDescriptor.type) + && Objects.equals(rating, otherEditInterviewDescriptor.rating); } @Override public String toString() { return new ToStringBuilder(this) .add("type", type) + .add("rating", rating) .toString(); } } 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..abdd2877232 --- /dev/null +++ b/src/main/java/seedu/staffsnap/logic/commands/FilterCommand.java @@ -0,0 +1,80 @@ +package seedu.staffsnap.logic.commands; + +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; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_STATUS; + +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. + */ +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], " + + 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; + + 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 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 + 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..bf9b37cf773 100644 --- a/src/main/java/seedu/staffsnap/logic/commands/SortCommand.java +++ b/src/main/java/seedu/staffsnap/logic/commands/SortCommand.java @@ -2,8 +2,6 @@ import static java.util.Objects.requireNonNull; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_DESCRIPTOR; -import static seedu.staffsnap.model.Model.PREDICATE_HIDE_ALL_APPLICANTS; -import static seedu.staffsnap.model.Model.PREDICATE_SHOW_ALL_APPLICANTS; import seedu.staffsnap.logic.commands.exceptions.CommandException; import seedu.staffsnap.model.Model; @@ -20,6 +18,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; @@ -36,16 +35,7 @@ public SortCommand(Descriptor descriptor) { public CommandResult execute(Model model) throws CommandException { requireNonNull(model); model.updateSortedApplicantList(descriptor); - /* - This is a workaround to javaFX not updating the list shown to the user unless the predicate is changed - Possible fix in the future is to read the current predicate, then store it to be reused - Might be an issue when implementing filter() - TODO: - store current predicate in temp variable - use stored predicate when refreshing the filtered list - */ - model.updateFilteredApplicantList(PREDICATE_HIDE_ALL_APPLICANTS); - model.updateFilteredApplicantList(PREDICATE_SHOW_ALL_APPLICANTS); + model.refreshApplicantList(); return new CommandResult(MESSAGE_SUCCESS); } } diff --git a/src/main/java/seedu/staffsnap/logic/commands/StatusCommand.java b/src/main/java/seedu/staffsnap/logic/commands/StatusCommand.java new file mode 100644 index 00000000000..3d714a0af8b --- /dev/null +++ b/src/main/java/seedu/staffsnap/logic/commands/StatusCommand.java @@ -0,0 +1,96 @@ +package seedu.staffsnap.logic.commands; + +import static java.util.Objects.requireNonNull; + +import java.util.List; + +import seedu.staffsnap.commons.core.index.Index; +import seedu.staffsnap.commons.util.ToStringBuilder; +import seedu.staffsnap.logic.Messages; +import seedu.staffsnap.logic.commands.exceptions.CommandException; +import seedu.staffsnap.model.Model; +import seedu.staffsnap.model.applicant.Applicant; +import seedu.staffsnap.model.applicant.Status; + + +/** + * Edits the details of an existing applicant in the applicant book. + */ +public class StatusCommand extends Command { + + public static final String COMMAND_WORD = "status"; + + 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) " + "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) " + + "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; + private final Status status; + + /** + * @param index of the applicant in the filtered applicant list to edit + * @param status The status to assign to the applicant + */ + public StatusCommand(Index index, Status status) { + requireNonNull(index); + requireNonNull(status); + + this.index = index; + this.status = status; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + List lastShownList = model.getFilteredApplicantList(); + + if (index.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_APPLICANT_DISPLAYED_INDEX); + } + + Applicant applicantToEdit = lastShownList.get(index.getZeroBased()); + applicantToEdit.setStatus(this.status); + + model.refreshApplicantList(); + + return new CommandResult(String.format(MESSAGE_EDIT_STATUS_SUCCESS, Messages.format(applicantToEdit))); + } + + public Index getIndex() { + return index; + } + + public Status getStatus() { + return status; + } + + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof StatusCommand)) { + return false; + } + + StatusCommand otherStatusCommand = (StatusCommand) other; + return index.equals(otherStatusCommand.index) && status.equals(otherStatusCommand.status); + } + + @Override + public String toString() { + return new ToStringBuilder(this).add("index", index).add("status", status).toString(); + } +} diff --git a/src/main/java/seedu/staffsnap/logic/parser/AddCommandParser.java b/src/main/java/seedu/staffsnap/logic/parser/AddCommandParser.java index b732767269c..0184016f4cb 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/AddCommandParser.java @@ -17,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; /** @@ -45,8 +46,9 @@ public AddCommand parse(String args) throws ParseException { Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); Position position = ParserUtil.parsePosition(argMultimap.getValue(PREFIX_POSITION).get()); List interviewList = new ArrayList<>(); + Status status = Status.UNDECIDED; - Applicant applicant = new Applicant(name, phone, email, position, interviewList); + Applicant applicant = new Applicant(name, phone, email, position, interviewList, status); return new AddCommand(applicant); } diff --git a/src/main/java/seedu/staffsnap/logic/parser/AddInterviewCommandParser.java b/src/main/java/seedu/staffsnap/logic/parser/AddInterviewCommandParser.java index 5f2837ec478..590ffa5844b 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/AddInterviewCommandParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/AddInterviewCommandParser.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_RATING; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_TYPE; import static seedu.staffsnap.logic.parser.ParserUtil.arePrefixesPresent; @@ -8,6 +9,7 @@ import seedu.staffsnap.logic.commands.AddInterviewCommand; import seedu.staffsnap.logic.parser.exceptions.ParseException; import seedu.staffsnap.model.interview.Interview; +import seedu.staffsnap.model.interview.Rating; /** * Parses input arguments and creates a new AddInterviewCommand object @@ -21,7 +23,7 @@ public class AddInterviewCommandParser implements Parser { */ public AddInterviewCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_TYPE); + ArgumentTokenizer.tokenize(args, PREFIX_TYPE, PREFIX_RATING); Index index; @@ -36,10 +38,16 @@ public AddInterviewCommand parse(String args) throws ParseException { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddInterviewCommand.MESSAGE_USAGE)); } - argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_TYPE); + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_TYPE, PREFIX_RATING); String type = ParserUtil.parseType(argMultimap.getValue(PREFIX_TYPE).get()); - Interview interview = new Interview(type); + Rating rating = new Rating("-"); + + if (argMultimap.getValue(PREFIX_RATING).isPresent()) { + rating = ParserUtil.parseRating(argMultimap.getValue(PREFIX_RATING).get()); + } + + Interview interview = new Interview(type, rating); return new AddInterviewCommand(index, interview); } diff --git a/src/main/java/seedu/staffsnap/logic/parser/ApplicantBookParser.java b/src/main/java/seedu/staffsnap/logic/parser/ApplicantBookParser.java index a9c4ad5385c..4057fee7c36 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/ApplicantBookParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/ApplicantBookParser.java @@ -18,10 +18,12 @@ import seedu.staffsnap.logic.commands.EditCommand; import seedu.staffsnap.logic.commands.EditInterviewCommand; 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; import seedu.staffsnap.logic.commands.SortCommand; +import seedu.staffsnap.logic.commands.StatusCommand; import seedu.staffsnap.logic.parser.exceptions.ParseException; /** @@ -65,7 +67,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); @@ -105,12 +107,19 @@ public Command parseCommand(String userInput) throws ParseException { case AddInterviewCommand.COMMAND_WORD: return new AddInterviewCommandParser().parse(arguments); + case FilterCommand.COMMAND_WORD: + return new FilterCommandParser().parse(arguments); + case EditInterviewCommand.COMMAND_WORD: return new EditInterviewCommandParser().parse(arguments); case DeleteInterviewCommand.COMMAND_WORD: return new DeleteInterviewCommandParser().parse(arguments); + case StatusCommand.COMMAND_WORD: + return new StatusCommandParser().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/CliSyntax.java b/src/main/java/seedu/staffsnap/logic/parser/CliSyntax.java index 34bdb87c6b2..a2333de653b 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/staffsnap/logic/parser/CliSyntax.java @@ -13,5 +13,10 @@ public class CliSyntax { public static final Prefix PREFIX_DESCRIPTOR = new Prefix("d/"); 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/"); + 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/EditInterviewCommandParser.java b/src/main/java/seedu/staffsnap/logic/parser/EditInterviewCommandParser.java index 36cc894f6c4..eb76e9dd54d 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/EditInterviewCommandParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/EditInterviewCommandParser.java @@ -3,8 +3,10 @@ import static java.util.Objects.requireNonNull; import static seedu.staffsnap.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_INTERVIEW; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_RATING; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_TYPE; -import static seedu.staffsnap.logic.parser.ParserUtil.arePrefixesPresent; + +import java.util.NoSuchElementException; import seedu.staffsnap.commons.core.index.Index; import seedu.staffsnap.logic.commands.EditInterviewCommand; @@ -24,29 +26,32 @@ public class EditInterviewCommandParser implements Parser public EditInterviewCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_INTERVIEW, PREFIX_TYPE); + ArgumentTokenizer.tokenize(args, PREFIX_INTERVIEW, PREFIX_TYPE, PREFIX_RATING); Index applicantIndex; Index interviewIndex; try { applicantIndex = ParserUtil.parseIndex(argMultimap.getPreamble()); + interviewIndex = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_INTERVIEW).get()); } catch (ParseException pe) { throw new ParseException( String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditInterviewCommand.MESSAGE_USAGE), pe); + } catch (NoSuchElementException ex) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditInterviewCommand.MESSAGE_USAGE), ex); } - if (!arePrefixesPresent(argMultimap, PREFIX_INTERVIEW, PREFIX_TYPE)) { - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditInterviewCommand.MESSAGE_USAGE)); - } - - interviewIndex = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_INTERVIEW).get()); - argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_INTERVIEW, PREFIX_TYPE); + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_INTERVIEW, PREFIX_TYPE, PREFIX_RATING); EditInterviewDescriptor editInterviewDescriptor = new EditInterviewDescriptor(); if (argMultimap.getValue(PREFIX_TYPE).isPresent()) { editInterviewDescriptor.setType(ParserUtil.parseType(argMultimap.getValue(PREFIX_TYPE).get())); } + if (argMultimap.getValue(PREFIX_RATING).isPresent()) { + editInterviewDescriptor.setRating(ParserUtil.parseRating(argMultimap.getValue(PREFIX_RATING).get())); + } + if (!editInterviewDescriptor.isAnyFieldEdited()) { throw new ParseException(EditInterviewCommand.MESSAGE_NOT_EDITED); } 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..f73f075e627 --- /dev/null +++ b/src/main/java/seedu/staffsnap/logic/parser/FilterCommandParser.java @@ -0,0 +1,86 @@ +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_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; +import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_STATUS; + +import java.util.List; + +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.applicant.Status; +import seedu.staffsnap.model.interview.Interview; + + +/** + * 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, PREFIX_STATUS, PREFIX_LESS_THAN_SCORE, + PREFIX_GREATER_THAN_SCORE); + + Name name = null; + Phone phone = null; + Email email = null; + 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_LESS_THAN_SCORE, PREFIX_GREATER_THAN_SCORE); + 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)); + } + if (argMultimap.getValue(PREFIX_STATUS).isPresent()) { + status = ParserUtil.parseStatus(argMultimap.getValue(PREFIX_STATUS).get()); + } + 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 5062d0d9f1d..11842dbedd4 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/staffsnap/logic/parser/ParserUtil.java @@ -9,13 +9,16 @@ 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; 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; /** * Contains utility methods used for parsing strings in the various *Parser classes. @@ -118,18 +121,23 @@ public static Email parseEmail(String email) throws ParseException { } /** - * Parses a {@code String interview} into a {@code Interview}. + * Parses a {@code String type} and {@code String rating} into a {@code Interview}. * Leading and trailing whitespaces will be trimmed. * * @throws ParseException if the given {@code interview} is invalid. */ - public static Interview parseInterview(String interview) throws ParseException { - requireNonNull(interview); - String trimmedInterview = interview.trim(); - if (!Interview.isValidType(trimmedInterview)) { + public static Interview parseInterview(String type, String rating) throws ParseException { + requireNonNull(type, rating); + String trimmedType = type.trim(); + String trimmedRating = rating.trim(); + Rating ratingValue = new Rating(trimmedRating); + if (!Interview.isValidType(trimmedType)) { throw new ParseException(Interview.MESSAGE_CONSTRAINTS); } - return new Interview(trimmedInterview); + if (!Rating.isValidRating(trimmedRating)) { + throw new ParseException(Rating.MESSAGE_CONSTRAINTS); + } + return new Interview(trimmedType, ratingValue); } /** @@ -139,7 +147,7 @@ public static List parseInterviews(Collection interviews) thr requireNonNull(interviews); final List interviewList = new ArrayList<>(); for (String interviewType : interviews) { - interviewList.add(parseInterview(interviewType)); + interviewList.add(parseInterview(interviewType, "-")); } return interviewList; } @@ -177,10 +185,63 @@ public static String parseType(String type) throws ParseException { } /** - * Returns true if none of the prefixes contains empty {@code Optional} values in the given - * {@code ArgumentMultimap}. + * Parses a {@code String rating} into a {@code Rating}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code rating} is invalid. + */ + public static Rating parseRating(String rating) throws ParseException { + requireNonNull(rating); + String trimmedRating = rating.trim(); + Double ratingValue; + try { + ratingValue = Double.parseDouble(trimmedRating); + } catch (NumberFormatException e) { + throw new ParseException(Rating.MESSAGE_CONSTRAINTS); + } + String ratingString = String.format("%.1f", ratingValue); + if (!Rating.isValidRating(ratingString)) { + throw new ParseException(Rating.MESSAGE_CONSTRAINTS); + } + return new Rating(ratingString); + } + + /** + * Parses a {@code String rating} into a {@code Rating}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code rating} is invalid. */ 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 if no matching status is found. + */ + 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/logic/parser/SortCommandParser.java b/src/main/java/seedu/staffsnap/logic/parser/SortCommandParser.java index e296f8e2bfa..ceaccfa4e5b 100644 --- a/src/main/java/seedu/staffsnap/logic/parser/SortCommandParser.java +++ b/src/main/java/seedu/staffsnap/logic/parser/SortCommandParser.java @@ -24,7 +24,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/logic/parser/StatusCommandParser.java b/src/main/java/seedu/staffsnap/logic/parser/StatusCommandParser.java new file mode 100644 index 00000000000..7fd899b1547 --- /dev/null +++ b/src/main/java/seedu/staffsnap/logic/parser/StatusCommandParser.java @@ -0,0 +1,46 @@ +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; +import seedu.staffsnap.logic.parser.exceptions.ParseException; +import seedu.staffsnap.model.applicant.Status; + + +/** + * Parses inputs and returns a StatusCommand + */ +public class StatusCommandParser implements Parser { + /** + * Parses the given {@code String} of arguments in the context of the AddCommand + * and returns an AddCommand object for execution. + * @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, PREFIX_STATUS); + + 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()); + } + if (status == null) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatusCommand.MESSAGE_NO_STATUS)); + } + return new StatusCommand(index, status); + } + +} diff --git a/src/main/java/seedu/staffsnap/model/Model.java b/src/main/java/seedu/staffsnap/model/Model.java index 62ddaaf85d1..04b2ca5a62f 100644 --- a/src/main/java/seedu/staffsnap/model/Model.java +++ b/src/main/java/seedu/staffsnap/model/Model.java @@ -98,4 +98,9 @@ public interface Model { * Updates the Descriptor for sorting Applicants. */ void updateSortedApplicantList(Descriptor descriptor); + + /** + * Refreshes the applicant list and keeps the same predicate + */ + void refreshApplicantList(); } diff --git a/src/main/java/seedu/staffsnap/model/ModelManager.java b/src/main/java/seedu/staffsnap/model/ModelManager.java index a23830734ab..daa77511345 100644 --- a/src/main/java/seedu/staffsnap/model/ModelManager.java +++ b/src/main/java/seedu/staffsnap/model/ModelManager.java @@ -158,4 +158,17 @@ public boolean equals(Object other) { && filteredApplicants.equals(otherModelManager.filteredApplicants); } + /** + * Refreshes the applicant list with the same predicate + */ + public void refreshApplicantList() { + Predicate predicate = (Predicate) filteredApplicants.getPredicate(); + if (predicate == null) { + predicate = PREDICATE_SHOW_ALL_APPLICANTS; + } + updateFilteredApplicantList(PREDICATE_HIDE_ALL_APPLICANTS); + updateFilteredApplicantList(PREDICATE_SHOW_ALL_APPLICANTS); + updateFilteredApplicantList(predicate); + } + } diff --git a/src/main/java/seedu/staffsnap/model/applicant/Applicant.java b/src/main/java/seedu/staffsnap/model/applicant/Applicant.java index 6a612566e92..583dd461897 100644 --- a/src/main/java/seedu/staffsnap/model/applicant/Applicant.java +++ b/src/main/java/seedu/staffsnap/model/applicant/Applicant.java @@ -26,11 +26,13 @@ public class Applicant implements Comparable { private final Email email; private final Position position; private final List interviews = new ArrayList<>(); + private Status status; /** * Every field must be present and not null. */ - public Applicant(Name name, Phone phone, Email email, Position position, List interviews) { + public Applicant(Name name, Phone phone, Email email, Position position, List interviews, + Status status) { requireAllNonNull(name, phone, email, position, interviews); this.name = name; this.phone = phone; @@ -38,6 +40,11 @@ public Applicant(Name name, Phone phone, Email email, Position position, 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 new file mode 100644 index 00000000000..fbfa6ae530f --- /dev/null +++ b/src/main/java/seedu/staffsnap/model/applicant/CustomFilterPredicate.java @@ -0,0 +1,123 @@ +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.commons.util.ToStringBuilder; +import seedu.staffsnap.model.interview.Interview; + + +/** + * Custom predicate to be used to filter applicants + */ +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 List interviews; + private final Status status; + private final Double lessThanScore; + private final Double greaterThanScore; + + /** + * 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, + 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; + } + + /** + * @param applicant the applicant to be tested. + * @return true if applicant matches all specified fields in the predicate + */ + @Override + public boolean test(Applicant applicant) { + if (this.name != null) { + if (!StringUtil.containsStringIgnoreCase(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; + } + } + if (this.status != null) { + if (applicant.getStatus() != this.status) { + return false; + } + } + if (this.lessThanScore != null) { + if (applicant.getScore() >= this.lessThanScore) { + return false; + } + } + if (this.greaterThanScore != null) { + if (applicant.getScore() <= this.greaterThanScore) { + return false; + } + } + return true; + } + + + @Override + public String toString() { + return new ToStringBuilder(this) + .add("name", name) + .add("phone", phone) + .add("email", email) + .add("position", position) + .add("interviews", interviews) + .add("status", status).toString(); + } + + @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) + && Objects.equals(status, that.status); + } + + @Override + public int hashCode() { + return Objects.hash(name, phone, email, position, interviews); + } +} diff --git a/src/main/java/seedu/staffsnap/model/applicant/Status.java b/src/main/java/seedu/staffsnap/model/applicant/Status.java new file mode 100644 index 00000000000..93a729e14c9 --- /dev/null +++ b/src/main/java/seedu/staffsnap/model/applicant/Status.java @@ -0,0 +1,27 @@ +package seedu.staffsnap.model.applicant; + +/** + * Status enum for valid statuses + */ +public enum Status { + UNDECIDED, OFFERED, REJECTED; + + public static final String MESSAGE_CONSTRAINTS = "Status can take the following values: " + + "[u(ndecided)/o(ffered)/r(ejected)]"; + + /** + * Finds the correct descriptor by the string given + * @param name name of the descriptor + * @return the descriptor if valid, null otherwise + */ + public static Status findByName(String name) { + Status result = null; + for (Status status : values()) { + if (status.name().equalsIgnoreCase(name) || status.name().substring(0, 1).equalsIgnoreCase(name)) { + result = status; + break; + } + } + return result; + } +} diff --git a/src/main/java/seedu/staffsnap/model/interview/Interview.java b/src/main/java/seedu/staffsnap/model/interview/Interview.java index a1f88a35289..87430974672 100644 --- a/src/main/java/seedu/staffsnap/model/interview/Interview.java +++ b/src/main/java/seedu/staffsnap/model/interview/Interview.java @@ -1,7 +1,12 @@ package seedu.staffsnap.model.interview; -import static java.util.Objects.requireNonNull; import static seedu.staffsnap.commons.util.AppUtil.checkArgument; +import static seedu.staffsnap.commons.util.CollectionUtil.requireAllNonNull; + +import java.util.List; +import java.util.Objects; + +import seedu.staffsnap.commons.util.ToStringBuilder; /** * Represents an Interview in the applicant book. @@ -14,15 +19,18 @@ public class Interview implements Comparable { public final String type; + public final Rating rating; + /** * Constructs a {@code Interview}. * * @param type A valid interview type. */ - public Interview(String type) { - requireNonNull(type); + public Interview(String type, Rating rating) { + requireAllNonNull(type); checkArgument(isValidType(type), MESSAGE_CONSTRAINTS); this.type = type; + this.rating = rating; } /** @@ -36,6 +44,10 @@ public String getType() { return type; } + public Rating getRating() { + return rating; + } + @Override public boolean equals(Object other) { if (other == this) { @@ -48,19 +60,30 @@ public boolean equals(Object other) { } Interview otherInterview = (Interview) other; - return type.equals(otherInterview.type); + return type.equals(otherInterview.type) + && rating.equals(otherInterview.rating); + } + + /** + * Returns true if the applicant has an interview with the same interview type. + */ + public boolean isContainedIn(List otherInterviews) { + return otherInterviews.stream().anyMatch(interview -> interview.getType().equals(getType())); } @Override public int hashCode() { - return type.hashCode(); + return Objects.hash(type, rating); } /** * Format state as text for viewing. */ public String toString() { - return '[' + type + ']'; + return new ToStringBuilder(this) + .add("type", type) + .add("rating", rating) + .toString(); } /** diff --git a/src/main/java/seedu/staffsnap/model/interview/Rating.java b/src/main/java/seedu/staffsnap/model/interview/Rating.java new file mode 100644 index 00000000000..e3241a5a03d --- /dev/null +++ b/src/main/java/seedu/staffsnap/model/interview/Rating.java @@ -0,0 +1,60 @@ +package seedu.staffsnap.model.interview; + +import static java.util.Objects.requireNonNull; +import static seedu.staffsnap.commons.util.AppUtil.checkArgument; + +/** + * Represents an Interview's rating in the applicant book. + * Guarantees: immutable; is valid as declared in {@link #isValidRating(String)} + */ +public class Rating { + + public static final String MESSAGE_CONSTRAINTS = + "Rating should be a number between 0.0 and 10.0 to 1 decimal place"; + public static final String VALIDATION_REGEX = "^(10|10.0|\\d{1}(\\.\\d{1})?)$"; + + public final String value; + + /** + * Constructs a {@code Rating}. + * + * @param rating A valid rating. + */ + public Rating(String rating) { + requireNonNull(rating); + checkArgument(isValidRating(rating), MESSAGE_CONSTRAINTS); + value = rating; + } + + /** + * Returns true if a given string is a valid rating. + */ + public static boolean isValidRating(String test) { + return test.equals("-") || test.matches(VALIDATION_REGEX); + } + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof Rating)) { + return false; + } + + Rating otherRating = (Rating) other; + return value.equals(otherRating.value); + } + + @Override + public int hashCode() { + return value.hashCode(); + } +} diff --git a/src/main/java/seedu/staffsnap/model/util/SampleDataUtil.java b/src/main/java/seedu/staffsnap/model/util/SampleDataUtil.java index c4327f0e4f8..99759769d45 100644 --- a/src/main/java/seedu/staffsnap/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/staffsnap/model/util/SampleDataUtil.java @@ -11,7 +11,9 @@ 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; /** * Contains utility methods for populating {@code ApplicantBook} with sample data. @@ -21,22 +23,25 @@ public static Applicant[] getSampleApplicants() { return new Applicant[] { new Applicant(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), new Position("Software Engineer"), - getInterviewList("screening")), + getInterviewList(new Interview("behavioral", new Rating("7.5")), + new Interview("technical", new Rating("7.0"))), Status.OFFERED), new Applicant(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), - new Position("Testing Engineer"), - getInterviewList("technical", "screening")), + new Position("Software Engineer"), + getInterviewList(new Interview("behavioral", new Rating("7.9")), + new Interview("technical", new Rating("8.0"))), Status.UNDECIDED), new Applicant(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), new Position("Software Engineer"), - getInterviewList("behavioral")), + getInterviewList(new Interview("behavioral", new Rating("8.8")), + new Interview("technical", new Rating("8.7"))), Status.REJECTED), new Applicant(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), - new Position("Staff Engineer"), - getInterviewList("technical")), + new Position("Frontend Engineer"), + getInterviewList(new Interview("behavioral", new Rating("7.7"))), Status.OFFERED), new Applicant(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), - new Position("DevOps Engineer"), - getInterviewList("technical", "behavioral")), + new Position("Backend Engineer"), + getInterviewList(new Interview("behavioral", new Rating("7.9"))), Status.UNDECIDED), new Applicant(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), - new Position("Software Engineer"), - getInterviewList("screening", "technical", "behavioral")), + new Position("Testing Engineer"), + getInterviewList(new Interview("behavioral", new Rating("6.0"))), Status.REJECTED) }; } @@ -51,9 +56,8 @@ public static ReadOnlyApplicantBook getSampleApplicantBook() { /** * Returns a interview set containing the list of strings given. */ - public static List getInterviewList(String... strings) { - return Arrays.stream(strings) - .map(Interview::new) + public static List getInterviewList(Interview... interviews) { + return Arrays.stream(interviews) .collect(Collectors.toList()); } diff --git a/src/main/java/seedu/staffsnap/storage/JsonAdaptedApplicant.java b/src/main/java/seedu/staffsnap/storage/JsonAdaptedApplicant.java index a0e8f3038c8..b54d3c2ef26 100644 --- a/src/main/java/seedu/staffsnap/storage/JsonAdaptedApplicant.java +++ b/src/main/java/seedu/staffsnap/storage/JsonAdaptedApplicant.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; import seedu.staffsnap.model.interview.Interview; /** @@ -28,13 +29,16 @@ class JsonAdaptedApplicant { private final String position; private final List interviews = new ArrayList<>(); + private final String status; + /** * Constructs a {@code JsonAdaptedApplicant} with the given applicant details. */ @JsonCreator public JsonAdaptedApplicant(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("position") String position, - @JsonProperty("interviews") List interviews) { + @JsonProperty("interviews") List interviews, + @JsonProperty("status") String status) { this.name = name; this.phone = phone; this.email = email; @@ -42,6 +46,7 @@ public JsonAdaptedApplicant(@JsonProperty("name") String name, @JsonProperty("ph if (interviews != null) { this.interviews.addAll(interviews); } + this.status = status; } /** @@ -55,6 +60,7 @@ public JsonAdaptedApplicant(Applicant source) { interviews.addAll(source.getInterviews().stream() .map(JsonAdaptedInterview::new) .collect(Collectors.toList())); + status = source.getStatus().toString(); } /** @@ -102,8 +108,10 @@ public Applicant toModelType() throws IllegalValueException { } final Position modelPosition = new Position(position); + final Status modelStatus = Status.findByName(status); + final List modelInterviews = new ArrayList<>(applicantInterviews); - return new Applicant(modelName, modelPhone, modelEmail, modelPosition, modelInterviews); + return new Applicant(modelName, modelPhone, modelEmail, modelPosition, modelInterviews, modelStatus); } } diff --git a/src/main/java/seedu/staffsnap/storage/JsonAdaptedInterview.java b/src/main/java/seedu/staffsnap/storage/JsonAdaptedInterview.java index f2990ea6242..3943fc94de4 100644 --- a/src/main/java/seedu/staffsnap/storage/JsonAdaptedInterview.java +++ b/src/main/java/seedu/staffsnap/storage/JsonAdaptedInterview.java @@ -1,10 +1,11 @@ package seedu.staffsnap.storage; import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.annotation.JsonProperty; import seedu.staffsnap.commons.exceptions.IllegalValueException; import seedu.staffsnap.model.interview.Interview; +import seedu.staffsnap.model.interview.Rating; /** * Jackson-friendly version of {@link Interview}. @@ -12,13 +13,15 @@ class JsonAdaptedInterview { private final String type; + private final String rating; /** - * Constructs a {@code JsonAdaptedInterview} with the given {@code interviewName}. + * Constructs a {@code JsonAdaptedInterview} with the given interview details. */ @JsonCreator - public JsonAdaptedInterview(String type) { + public JsonAdaptedInterview(@JsonProperty("type") String type, @JsonProperty("rating") String rating) { this.type = type; + this.rating = rating; } /** @@ -26,11 +29,7 @@ public JsonAdaptedInterview(String type) { */ public JsonAdaptedInterview(Interview source) { type = source.type; - } - - @JsonValue - public String getType() { - return type; + rating = source.getRating().value; } /** @@ -42,7 +41,11 @@ public Interview toModelType() throws IllegalValueException { if (!Interview.isValidType(type)) { throw new IllegalValueException(Interview.MESSAGE_CONSTRAINTS); } - return new Interview(type); + if (!Rating.isValidRating(rating)) { + throw new IllegalValueException(Rating.MESSAGE_CONSTRAINTS); + } + final Rating modelRating = new Rating(rating); + return new Interview(type, modelRating); } } diff --git a/src/main/java/seedu/staffsnap/ui/ApplicantCard.java b/src/main/java/seedu/staffsnap/ui/ApplicantCard.java index aae20cfbf3e..6925d5cfaf0 100644 --- a/src/main/java/seedu/staffsnap/ui/ApplicantCard.java +++ b/src/main/java/seedu/staffsnap/ui/ApplicantCard.java @@ -1,12 +1,25 @@ package seedu.staffsnap.ui; import javafx.fxml.FXML; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Group; import javafx.scene.control.Label; import javafx.scene.image.ImageView; -import javafx.scene.layout.FlowPane; +import javafx.scene.layout.Background; +import javafx.scene.layout.BackgroundFill; +import javafx.scene.layout.CornerRadii; import javafx.scene.layout.HBox; +import javafx.scene.layout.Priority; import javafx.scene.layout.Region; +import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import javafx.scene.shape.Arc; +import javafx.scene.shape.ArcType; +import javafx.scene.shape.Circle; import seedu.staffsnap.model.applicant.Applicant; +import seedu.staffsnap.model.interview.Interview; /** * A UI component that displays information of a {@code Applicant}. @@ -38,7 +51,11 @@ public class ApplicantCard extends UiPart { @FXML private HBox position; @FXML - private FlowPane interviews; + private Label status; + @FXML + private StackPane overallRating; + @FXML + private HBox interviews; /** * Creates a {@code ApplicantCode} with the given {@code Applicant} and index to display. @@ -46,8 +63,17 @@ public class ApplicantCard extends UiPart { public ApplicantCard(Applicant applicant, int displayedIndex) { super(FXML); this.applicant = applicant; - id.setText(displayedIndex + ". "); + displayApplicantId(displayedIndex); + displayApplicantDetails(); + displayApplicantStatus(); + displayApplicantInterviews(); + displayApplicantOverallRating(); + } + private void displayApplicantId(int displayedIndex) { + id.setText(displayedIndex + ". "); + } + private void displayApplicantDetails() { name.setText(applicant.getName().fullName); Label phoneLabel = new Label(applicant.getPhone().value); @@ -70,11 +96,78 @@ public ApplicantCard(Applicant applicant, int displayedIndex) { positionIcon.setFitWidth(13.5); position.getChildren().add(positionIcon); position.getChildren().add(positionLabel); + } + + private void displayApplicantStatus() { + status.setText(applicant.getStatus().toString()); + + switch (applicant.getStatus()) { + case OFFERED: + status.setStyle("-fx-background-color: #50c952"); + break; + case REJECTED: + status.setStyle("-fx-background-color: #e87f7f"); + break; + case UNDECIDED: + status.setStyle("-fx-background-color: #36769a"); + break; + default: + } + } + + private void displayApplicantInterviews() { + for (Interview interview : applicant.getInterviews()) { + VBox interviewBox = new VBox(); + HBox interviewHeader = new HBox(); + HBox interviewRating = new HBox(); + + interviewBox.setMinHeight(100); + interviewBox.setMinWidth(100); + interviewRating.setPrefWidth(100); + interviewRating.setAlignment(Pos.CENTER); + interviewHeader.setAlignment(Pos.CENTER); + VBox.setVgrow(interviewRating, Priority.ALWAYS); + + interviewHeader.setBackground(new Background(new BackgroundFill(Color.web("#3e7b91"), + CornerRadii.EMPTY, Insets.EMPTY))); + interviewRating.setBackground(new Background(new BackgroundFill(Color.web("#7fc9e8"), + CornerRadii.EMPTY, Insets.EMPTY))); + + Label interviewLabel = new Label(applicant.getInterviewIndexForApplicantCard(interview) + + ". " + interview.type); + + Label interviewRatingLabel = new Label(); + interviewRatingLabel.getStyleClass().add("rating"); + interviewRatingLabel.setText(interview.getRating().toString()); + + interviewHeader.getChildren().add(interviewLabel); + interviewRating.getChildren().add(interviewRatingLabel); + interviewBox.getChildren().addAll(interviewHeader, interviewRating); + + interviews.getChildren().add(interviewBox); + } + } + private void displayApplicantOverallRating() { + Circle outerCircle = new Circle(50); + outerCircle.setFill(Color.web("#454545")); + Circle midCircle = new Circle(43); + midCircle.setFill(Color.web("#454545")); + Circle innerCircle = new Circle(36); + innerCircle.setFill(Color.web("#454545")); + Group stackedArcs = new Group(); + stackedArcs.getChildren().addAll(outerCircle, midCircle); + Label ratingLabel = new Label(); + ratingLabel.setText("8.2"); // TODO: update with overall rating + ratingLabel.getStyleClass().add("overall_rating_label"); + + for (int i = 0; i < 10; i++) { + Arc arc = new Arc(0, 0, 43, 43, + 90 + i * 36, -30); + arc.setType(ArcType.ROUND); + arc.setFill(Color.GREY); + stackedArcs.getChildren().add(arc); + } - applicant.getInterviews().stream() - .forEach(interview -> { - interviews.getChildren().add(new Label(applicant.getInterviewIndexForApplicantCard(interview) - + ". " + interview.type)); - }); + overallRating.getChildren().addAll(stackedArcs, innerCircle, ratingLabel); } } diff --git a/src/main/resources/view/ApplicantListCard.fxml b/src/main/resources/view/ApplicantListCard.fxml index 9416cc8e106..a7ee72bcabc 100644 --- a/src/main/resources/view/ApplicantListCard.fxml +++ b/src/main/resources/view/ApplicantListCard.fxml @@ -10,15 +10,17 @@ + - - + + + - + - + - - + - + + + + + + + - - diff --git a/src/main/resources/view/DarkTheme.css b/src/main/resources/view/DarkTheme.css index bafae922a4c..a73e9e9b72a 100644 --- a/src/main/resources/view/DarkTheme.css +++ b/src/main/resources/view/DarkTheme.css @@ -132,6 +132,14 @@ -fx-text-fill: #010504; } +.status_label { + -fx-font-family: "Segoe UI Black"; + -fx-font-size: 12px; + -fx-background-color: #0fa5ea; + -fx-background-radius: 10; + -fx-padding: 1 8 1 8; +} + .stack-pane { -fx-background-color: derive(#1d1d1d, 20%); } @@ -346,7 +354,13 @@ -fx-text-fill: white; -fx-background-color: #3e7b91; -fx-padding: 1 3 1 3; - -fx-border-radius: 2; - -fx-background-radius: 2; -fx-font-size: 11; } +#interviews .rating { + -fx-font-size: 30; + -fx-background-color: #7fc9e8; +} + +.overall_rating_label { + -fx-font-size: 30; +} diff --git a/src/test/data/JsonSerializableApplicantBookTest/duplicateApplicantApplicantBook.json b/src/test/data/JsonSerializableApplicantBookTest/duplicateApplicantApplicantBook.json index 80db8818c06..45c63a171c5 100644 --- a/src/test/data/JsonSerializableApplicantBookTest/duplicateApplicantApplicantBook.json +++ b/src/test/data/JsonSerializableApplicantBookTest/duplicateApplicantApplicantBook.json @@ -4,7 +4,10 @@ "phone": "94351253", "email": "alice@example.com", "position": "123, Jurong West Ave 6, #08-111", - "interviews": [ "friends" ] + "interviews": [ { + "type" : "behavioral", + "rating" : "7.5" + } ] }, { "name": "Alice Pauline", "phone": "94351253", diff --git a/src/test/data/JsonSerializableApplicantBookTest/typicalApplicantsApplicantBook.json b/src/test/data/JsonSerializableApplicantBookTest/typicalApplicantsApplicantBook.json index 2c3f67c50b7..8997496ac14 100644 --- a/src/test/data/JsonSerializableApplicantBookTest/typicalApplicantsApplicantBook.json +++ b/src/test/data/JsonSerializableApplicantBookTest/typicalApplicantsApplicantBook.json @@ -11,7 +11,10 @@ "phone" : "98765432", "email" : "benson@example.com", "position" : "Frontend Engineer", - "interviews" : [ "technical" ] + "interviews" : [ { + "type" : "technical", + "rating" : "8.0" + } ] }, { "name" : "Bob Choo", "phone" : "22222222", @@ -23,13 +26,19 @@ "phone" : "95352563", "email" : "carl@example.com", "position" : "Backend Engineer", - "interviews" : [ ] + "interviews" : [ { + "type" : "behavioral", + "rating" : "8.5" + } ] }, { "name" : "Daniel Meier", "phone" : "87652533", "email" : "daniel@example.com", "position" : "Testing Engineer", - "interviews" : [ "screening" ] + "interviews" : [ { + "type" : "technical", + "rating" : "8.0" + } ] }, { "name" : "Elle Meyer", "phone" : "9482224", diff --git a/src/test/java/seedu/staffsnap/logic/commands/AddCommandTest.java b/src/test/java/seedu/staffsnap/logic/commands/AddCommandTest.java index cedbc34bd0f..b124a46bffb 100644 --- a/src/test/java/seedu/staffsnap/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/staffsnap/logic/commands/AddCommandTest.java @@ -169,6 +169,11 @@ public void updateFilteredApplicantList(Predicate predicate) { public void updateSortedApplicantList(Descriptor descriptor) { throw new AssertionError("This method should not be called."); } + + @Override + public void refreshApplicantList() { + throw new AssertionError("This method should not be called."); + } } /** diff --git a/src/test/java/seedu/staffsnap/logic/commands/AddInterviewCommandTest.java b/src/test/java/seedu/staffsnap/logic/commands/AddInterviewCommandTest.java index 0cf0895e4f6..7ef9e8979c3 100644 --- a/src/test/java/seedu/staffsnap/logic/commands/AddInterviewCommandTest.java +++ b/src/test/java/seedu/staffsnap/logic/commands/AddInterviewCommandTest.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static seedu.staffsnap.testutil.Assert.assertThrows; +import static seedu.staffsnap.testutil.TypicalApplicants.BENSON; import static seedu.staffsnap.testutil.TypicalApplicants.getTypicalApplicantBook; import static seedu.staffsnap.testutil.TypicalIndexes.INDEX_FIRST_APPLICANT; @@ -22,7 +23,7 @@ public void constructor_nullArguments_throwsNullPointerException() { @Test public void toStringMethod() { - Interview stubInterview = new Interview("stub"); + Interview stubInterview = BENSON.getInterviews().get(0); AddInterviewCommand addInterviewCommand = new AddInterviewCommand(INDEX_FIRST_APPLICANT, stubInterview); String expected = AddInterviewCommand.class.getCanonicalName() + "{interviewToAdd=" + stubInterview + "}"; assertEquals(expected, addInterviewCommand.toString()); @@ -30,7 +31,7 @@ public void toStringMethod() { @Test public void equalsMethod() { - Interview stubInterview = new Interview("stub"); + Interview stubInterview = BENSON.getInterviews().get(0); AddInterviewCommand addInterviewCommand = new AddInterviewCommand(INDEX_FIRST_APPLICANT, stubInterview); assertEquals(addInterviewCommand, addInterviewCommand); assertEquals(addInterviewCommand, new AddInterviewCommand(INDEX_FIRST_APPLICANT, stubInterview)); @@ -38,7 +39,7 @@ public void equalsMethod() { @Test public void execute_nullModel_throwsNullPointerException() { - Interview stubInterview = new Interview("stub"); + Interview stubInterview = BENSON.getInterviews().get(0); AddInterviewCommand addInterviewCommand = new AddInterviewCommand(INDEX_FIRST_APPLICANT, stubInterview); assertThrows(NullPointerException.class, () -> addInterviewCommand.execute(null)); } diff --git a/src/test/java/seedu/staffsnap/logic/commands/ClearCommandTest.java b/src/test/java/seedu/staffsnap/logic/commands/ClearCommandTest.java index 2b90f11d2b5..909555888cb 100644 --- a/src/test/java/seedu/staffsnap/logic/commands/ClearCommandTest.java +++ b/src/test/java/seedu/staffsnap/logic/commands/ClearCommandTest.java @@ -1,16 +1,18 @@ package seedu.staffsnap.logic.commands; import static seedu.staffsnap.logic.commands.CommandTestUtil.assertCommandSuccess; -//import static seedu.staffsnap.testutil.TypicalApplicants.getTypicalApplicantBook; +import static seedu.staffsnap.testutil.TypicalApplicants.getTypicalApplicantBook; import org.junit.jupiter.api.Test; -//import seedu.staffsnap.model.ApplicantBook; +import seedu.staffsnap.logic.commands.exceptions.CommandException; +import seedu.staffsnap.model.ApplicantBook; import seedu.staffsnap.model.Model; import seedu.staffsnap.model.ModelManager; -//import seedu.staffsnap.model.UserPrefs; +import seedu.staffsnap.model.UserPrefs; public class ClearCommandTest { + private Command confirmStub = new ConfirmationCommand(); @Test @@ -20,16 +22,17 @@ public void execute_emptyApplicantBook_success() { assertCommandSuccess(new ClearCommand(), model, ClearCommand.MESSAGE_SUCCESS, expectedModel); } - /* + @Test - public void execute_nonEmptyApplicantBook_success() { + public void execute_nonEmptyApplicantBook_success() throws CommandException { Model model = new ModelManager(getTypicalApplicantBook(), new UserPrefs()); Model expectedModel = new ModelManager(getTypicalApplicantBook(), new UserPrefs()); expectedModel.setApplicantBook(new ApplicantBook()); + confirmStub.execute(model); assertCommandSuccess(new ClearCommand(), model, ClearCommand.MESSAGE_SUCCESS, expectedModel); } - */ + diff --git a/src/test/java/seedu/staffsnap/logic/commands/CommandTestUtil.java b/src/test/java/seedu/staffsnap/logic/commands/CommandTestUtil.java index 93f689e9398..2ef19128445 100644 --- a/src/test/java/seedu/staffsnap/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/staffsnap/logic/commands/CommandTestUtil.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_RATING; import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_TYPE; import static seedu.staffsnap.testutil.Assert.assertThrows; @@ -19,6 +20,8 @@ import seedu.staffsnap.model.Model; import seedu.staffsnap.model.applicant.Applicant; import seedu.staffsnap.model.applicant.NameContainsKeywordsPredicate; +import seedu.staffsnap.model.interview.Interview; +import seedu.staffsnap.model.interview.Rating; import seedu.staffsnap.testutil.EditApplicantDescriptorBuilder; /** @@ -36,6 +39,9 @@ public class CommandTestUtil { public static final String VALID_POSITION_BOB = "Block 123, Bobby Street 3"; public static final String VALID_TYPE_TECHNICAL = "technical"; public static final String VALID_TYPE_BEHAVIORAL = "behavioral"; + public static final String VALID_RATING_TEN = "10.0"; + public static final Interview VALID_INTERVIEW_BEHAVIORAL = new Interview("behavioral", new Rating("8.5")); + public static final Interview VALID_INTERVIEW_TECHNICAL = new Interview("technical", new Rating("8.0")); public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY; public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB; @@ -47,6 +53,7 @@ public class CommandTestUtil { public static final String POSITION_DESC_BOB = " " + PREFIX_POSITION + VALID_POSITION_BOB; public static final String TYPE_DESC_TECHNICAL = " " + PREFIX_TYPE + VALID_TYPE_TECHNICAL; public static final String TYPE_DESC_BEHAVIORAL = " " + PREFIX_TYPE + VALID_TYPE_BEHAVIORAL; + public static final String RATING_DESC_TEN = " " + PREFIX_RATING + VALID_RATING_TEN; public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names public static final String INVALID_PHONE_DESC = " " + PREFIX_PHONE + "911a"; // 'a' not allowed in phones @@ -54,7 +61,8 @@ public class CommandTestUtil { public static final String INVALID_POSITION_DESC = " " + PREFIX_POSITION; // empty string not allowed for positions public static final String INVALID_TYPE_DESC = " " + PREFIX_TYPE + "hubby*"; // '*' not allowed in interviews - + public static final String INVALID_RATING_DESC = " " + PREFIX_RATING + + "-1"; // negative numbers not allowed for ratings public static final String PREAMBLE_WHITESPACE = "\t \r \n"; public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble"; diff --git a/src/test/java/seedu/staffsnap/logic/commands/ConfirmationCommandTest.java b/src/test/java/seedu/staffsnap/logic/commands/ConfirmationCommandTest.java new file mode 100644 index 00000000000..46233b33a73 --- /dev/null +++ b/src/test/java/seedu/staffsnap/logic/commands/ConfirmationCommandTest.java @@ -0,0 +1,20 @@ +package seedu.staffsnap.logic.commands; + +import static seedu.staffsnap.logic.commands.CommandTestUtil.assertCommandSuccess; + +import org.junit.jupiter.api.Test; + +import seedu.staffsnap.model.Model; +import seedu.staffsnap.model.ModelManager; + + +public class ConfirmationCommandTest { + @Test + public void execute_emptyApplicantBook_success() { + Model model = new ModelManager(); + Model expectedModel = new ModelManager(); + + assertCommandSuccess(new ConfirmationCommand(), model, ConfirmationCommand.CONFIRM, expectedModel); + } + +} diff --git a/src/test/java/seedu/staffsnap/logic/commands/EditApplicantDescriptorTest.java b/src/test/java/seedu/staffsnap/logic/commands/EditApplicantDescriptorTest.java index 2e938b1ac05..84c40c1c0d8 100644 --- a/src/test/java/seedu/staffsnap/logic/commands/EditApplicantDescriptorTest.java +++ b/src/test/java/seedu/staffsnap/logic/commands/EditApplicantDescriptorTest.java @@ -60,7 +60,8 @@ public void toStringMethod() { + editApplicantDescriptor.getName().orElse(null) + ", phone=" + editApplicantDescriptor.getPhone().orElse(null) + ", email=" + editApplicantDescriptor.getEmail().orElse(null) + ", position=" - + editApplicantDescriptor.getPosition().orElse(null) + "}"; + + editApplicantDescriptor.getPosition().orElse(null) + ", status=" + + editApplicantDescriptor.getStatus().orElse(null) + "}"; assertEquals(expected, editApplicantDescriptor.toString()); } } 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..935bcff524a --- /dev/null +++ b/src/test/java/seedu/staffsnap/logic/commands/FilterCommandTest.java @@ -0,0 +1,133 @@ +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; +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.applicant.Status; +import seedu.staffsnap.model.interview.Interview; + + +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(); + 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, status1, null, null); + CustomFilterPredicate secondPredicate = new CustomFilterPredicate(name2, phone2, email2, position2, + interviewList2, status2, null, null); + + 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, 8); + 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); + 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, 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, 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(), FIONA.getStatus(), null, null); + 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, 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/commands/StatusCommandTest.java b/src/test/java/seedu/staffsnap/logic/commands/StatusCommandTest.java new file mode 100644 index 00000000000..4510419507f --- /dev/null +++ b/src/test/java/seedu/staffsnap/logic/commands/StatusCommandTest.java @@ -0,0 +1,66 @@ +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.testutil.TypicalApplicants.getUnsortedApplicantBook; + +import org.junit.jupiter.api.Test; + +import seedu.staffsnap.commons.core.index.Index; +import seedu.staffsnap.logic.commands.exceptions.CommandException; +import seedu.staffsnap.model.Model; +import seedu.staffsnap.model.ModelManager; +import seedu.staffsnap.model.UserPrefs; +import seedu.staffsnap.model.applicant.Status; + + + +class StatusCommandTest { + + @Test + void execute_setStatus_offered() { + Model model = new ModelManager(getUnsortedApplicantBook(), new UserPrefs()); + try { + new StatusCommand(Index.fromOneBased(1), Status.OFFERED).execute(model); + } catch (CommandException e) { + throw new RuntimeException(e); + } + assertTrue(model.getFilteredApplicantList().get(0).getStatus() == Status.OFFERED); + } + + @Test + void execute_setStatus_rejected() { + Model model = new ModelManager(getUnsortedApplicantBook(), new UserPrefs()); + try { + new StatusCommand(Index.fromOneBased(1), Status.REJECTED).execute(model); + } catch (CommandException e) { + throw new RuntimeException(e); + } + assertTrue(model.getFilteredApplicantList().get(0).getStatus() == Status.REJECTED); + } + + @Test + void execute_testEquals_sameParams() { + StatusCommand command1 = new StatusCommand(Index.fromOneBased(1), Status.OFFERED); + StatusCommand command2 = new StatusCommand(Index.fromOneBased(1), Status.OFFERED); + assertTrue(command1.equals(command2)); + } + + @Test + void execute_testEquals_differentParams() { + StatusCommand command1 = new StatusCommand(Index.fromOneBased(1), Status.OFFERED); + StatusCommand command2 = new StatusCommand(Index.fromOneBased(2), Status.REJECTED); + assertFalse(command1.equals(command2)); + } + + @Test + void testToString() { + StatusCommand command = new StatusCommand(Index.fromOneBased(1), Status.OFFERED); + String expected = StatusCommand.class.getCanonicalName() + "{index=" + + command.getIndex() + ", status=" + + command.getStatus() + "}"; + assertEquals(expected, + command.toString()); + } +} diff --git a/src/test/java/seedu/staffsnap/logic/parser/AddInterviewCommandParserTest.java b/src/test/java/seedu/staffsnap/logic/parser/AddInterviewCommandParserTest.java index a722d18766c..b8fda1df76f 100644 --- a/src/test/java/seedu/staffsnap/logic/parser/AddInterviewCommandParserTest.java +++ b/src/test/java/seedu/staffsnap/logic/parser/AddInterviewCommandParserTest.java @@ -1,12 +1,22 @@ package seedu.staffsnap.logic.parser; import static seedu.staffsnap.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.staffsnap.logic.commands.CommandTestUtil.EMAIL_DESC_BOB; +import static seedu.staffsnap.logic.commands.CommandTestUtil.INVALID_RATING_DESC; +import static seedu.staffsnap.logic.commands.CommandTestUtil.INVALID_TYPE_DESC; +import static seedu.staffsnap.logic.commands.CommandTestUtil.NAME_DESC_BOB; +import static seedu.staffsnap.logic.commands.CommandTestUtil.PHONE_DESC_BOB; +import static seedu.staffsnap.logic.commands.CommandTestUtil.POSITION_DESC_BOB; +import static seedu.staffsnap.logic.commands.CommandTestUtil.TYPE_DESC_BEHAVIORAL; +import static seedu.staffsnap.logic.commands.CommandTestUtil.TYPE_DESC_TECHNICAL; import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_TYPE_TECHNICAL; import static seedu.staffsnap.logic.parser.CommandParserTestUtil.assertParseFailure; import org.junit.jupiter.api.Test; import seedu.staffsnap.logic.commands.AddInterviewCommand; +import seedu.staffsnap.model.interview.Interview; +import seedu.staffsnap.model.interview.Rating; class AddInterviewCommandParserTest { private static final String MESSAGE_INVALID_FORMAT = @@ -25,4 +35,46 @@ public void parse_missingParts_failure() { // no index and no field specified assertParseFailure(parser, "", MESSAGE_INVALID_FORMAT); } + + @Test + public void parse_multipleInterviewValue_failure() { + String validExpectedApplicantString = NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + + POSITION_DESC_BOB + TYPE_DESC_TECHNICAL; + + // multiple types + assertParseFailure(parser, TYPE_DESC_BEHAVIORAL + validExpectedApplicantString, + MESSAGE_INVALID_FORMAT); + + // multiple ratings + assertParseFailure(parser, TYPE_DESC_BEHAVIORAL + validExpectedApplicantString, + MESSAGE_INVALID_FORMAT); + } + + @Test + public void parse_compulsoryFieldMissing_failure() { + String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddInterviewCommand.MESSAGE_USAGE); + + // missing index + assertParseFailure(parser, TYPE_DESC_BEHAVIORAL, expectedMessage); + + // missing interview type + String index = "1 "; + assertParseFailure(parser, index, expectedMessage); + + // missing interview prefix + assertParseFailure(parser, index + VALID_TYPE_TECHNICAL, expectedMessage); + } + + @Test + public void parse_invalidValue_failure() { + // invalid index + assertParseFailure(parser, "a" + TYPE_DESC_TECHNICAL, MESSAGE_INVALID_FORMAT); + + // invalid type + assertParseFailure(parser, "1" + INVALID_TYPE_DESC, Interview.MESSAGE_CONSTRAINTS); + + // invalid rating + assertParseFailure(parser, "1" + TYPE_DESC_TECHNICAL + INVALID_RATING_DESC, + Rating.MESSAGE_CONSTRAINTS); + } } diff --git a/src/test/java/seedu/staffsnap/logic/parser/ApplicantBookParserTest.java b/src/test/java/seedu/staffsnap/logic/parser/ApplicantBookParserTest.java index b54bfef802d..2b131e24189 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,9 @@ 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 +63,10 @@ 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 +79,9 @@ 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 +102,21 @@ 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..b06b06a0453 --- /dev/null +++ b/src/test/java/seedu/staffsnap/logic/parser/FilterCommandParserTest.java @@ -0,0 +1,59 @@ +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; +import seedu.staffsnap.model.applicant.Status; + +class FilterCommandParserTest { + + 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() { + 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, 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, 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, null))); + } + + @Test + void parse_phoneOnly_success() { + assertParseSuccess(parser, " hp/ 98765432", new FilterCommand(new CustomFilterPredicate(null, new Phone( + "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, null))); + } +} diff --git a/src/test/java/seedu/staffsnap/logic/parser/ParserUtilTest.java b/src/test/java/seedu/staffsnap/logic/parser/ParserUtilTest.java index fb67fd8261a..f828813207e 100644 --- a/src/test/java/seedu/staffsnap/logic/parser/ParserUtilTest.java +++ b/src/test/java/seedu/staffsnap/logic/parser/ParserUtilTest.java @@ -20,22 +20,25 @@ import seedu.staffsnap.model.applicant.Phone; import seedu.staffsnap.model.applicant.Position; import seedu.staffsnap.model.interview.Interview; +import seedu.staffsnap.model.interview.Rating; public class ParserUtilTest { private static final String INVALID_NAME = "R@chel"; private static final String INVALID_PHONE = "+651234"; private static final String INVALID_POSITION = " "; private static final String INVALID_EMAIL = "example.com"; - private static final String INVALID_INTERVIEW = "#friend"; + private static final String INVALID_TYPE = "#friend"; private static final String INVALID_DESCRIPTOR = "nam"; + private static final String INVALID_RATING = "15.0"; private static final String VALID_NAME = "Rachel Walker"; private static final String VALID_PHONE = "123456"; private static final String VALID_POSITION = "Software Engineer"; private static final String VALID_EMAIL = "rachel@example.com"; - private static final String VALID_INTERVIEW_1 = "friend"; - private static final String VALID_INTERVIEW_2 = "neighbour"; + private static final String VALID_TYPE_1 = "behavioral"; + private static final String VALID_TYPE_2 = "technical"; private static final String VALID_DESCRIPTOR = "name"; + private static final String VALID_RATING = "5.0"; private static final String CAPITALIZED_NAME = "RACHEL WALKER"; @@ -155,25 +158,31 @@ public void parseEmail_validValueWithWhitespace_returnsTrimmedEmail() throws Exc @Test public void parseInterview_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> ParserUtil.parseInterview(null)); + assertThrows(NullPointerException.class, () -> ParserUtil.parseInterview(null, null)); } @Test - public void parseInterview_invalidValue_throwsParseException() { - assertThrows(ParseException.class, () -> ParserUtil.parseInterview(INVALID_INTERVIEW)); + public void parseInterview_invalidType_throwsParseException() { + assertThrows(ParseException.class, () -> ParserUtil.parseInterview(INVALID_TYPE, VALID_RATING)); + } + + @Test + public void parseInterview_invalidRating_throwsParseException() { + assertThrows(IllegalArgumentException.class, () -> ParserUtil.parseInterview(VALID_TYPE_1, INVALID_RATING)); } @Test public void parseInterview_validValueWithoutWhitespace_returnsInterview() throws Exception { - Interview expectedInterview = new Interview(VALID_INTERVIEW_1); - assertEquals(expectedInterview, ParserUtil.parseInterview(VALID_INTERVIEW_1)); + Interview expectedInterview = new Interview(VALID_TYPE_1, new Rating(VALID_RATING)); + assertEquals(expectedInterview, ParserUtil.parseInterview(VALID_TYPE_1, VALID_RATING)); } @Test - public void parseInterview_validValueWithWhitespace_returnsTrimmedInterview() throws Exception { - String interviewWithWhitespace = WHITESPACE + VALID_INTERVIEW_1 + WHITESPACE; - Interview expectedInterview = new Interview(VALID_INTERVIEW_1); - assertEquals(expectedInterview, ParserUtil.parseInterview(interviewWithWhitespace)); + public void parseInterview_validValuesWithWhitespace_returnsTrimmedInterview() throws Exception { + String typeWithWhitespace = WHITESPACE + VALID_TYPE_1 + WHITESPACE; + String ratingWithWhitespace = WHITESPACE + VALID_RATING + WHITESPACE; + Interview expectedInterview = new Interview(VALID_TYPE_1, new Rating(VALID_RATING)); + assertEquals(expectedInterview, ParserUtil.parseInterview(typeWithWhitespace, ratingWithWhitespace)); } @Test @@ -184,7 +193,7 @@ public void parseInterviews_null_throwsNullPointerException() { @Test public void parseInterviews_collectionWithInvalidInterviews_throwsParseException() { assertThrows(ParseException.class, () -> ParserUtil - .parseInterviews(Arrays.asList(VALID_INTERVIEW_1, INVALID_INTERVIEW))); + .parseInterviews(Arrays.asList(VALID_TYPE_1, INVALID_TYPE))); } @Test @@ -195,9 +204,10 @@ public void parseInterviews_emptyCollection_returnsEmptySet() throws Exception { @Test public void parseInterviews_collectionWithValidInterviews_returnsInterviewList() throws Exception { List actualInterviewList = ParserUtil - .parseInterviews(Arrays.asList(VALID_INTERVIEW_1, VALID_INTERVIEW_2)); + .parseInterviews(Arrays.asList(VALID_TYPE_1, VALID_TYPE_2)); List expectedInterviewList = new ArrayList<>( - Arrays.asList(new Interview(VALID_INTERVIEW_1), new Interview(VALID_INTERVIEW_2))); + Arrays.asList(new Interview(VALID_TYPE_1, new Rating("-")), + new Interview(VALID_TYPE_2, new Rating("-")))); assertEquals(expectedInterviewList, actualInterviewList); } @@ -229,4 +239,55 @@ public void parseDescriptor_validValueWithWhitespace_returnsTrimmedName() throws public void standardizeCapitalization_validValueWithCapitalization_returnsCapitalizedString() { assertEquals(VALID_NAME, ParserUtil.standardizeCapitalization(CAPITALIZED_NAME)); } + + @Test + public void parseType_validValuesWithUppercaseType_returnsLowercaseType() throws Exception { + String typeWithUppercase = VALID_TYPE_1.toUpperCase(); + assertEquals(VALID_TYPE_1, ParserUtil.parseType(typeWithUppercase)); + } + + @Test + public void parseType_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> ParserUtil.parseType((String) null)); + } + + @Test + public void parseType_invalidValue_throwsParseException() { + assertThrows(ParseException.class, () -> ParserUtil.parseType(INVALID_TYPE)); + } + + @Test + public void parseType_validValueWithoutWhitespace_returnsType() throws Exception { + String typeWithoutWhitespace = VALID_TYPE_1; + assertEquals(VALID_TYPE_1, ParserUtil.parseType(typeWithoutWhitespace)); + } + + @Test + public void parseType_validValueWithWhitespace_returnsTrimmedType() throws Exception { + String typeWithWhitespace = WHITESPACE + VALID_TYPE_1 + WHITESPACE; + assertEquals(VALID_TYPE_1, ParserUtil.parseType(typeWithWhitespace)); + } + + @Test + public void parseRating_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> ParserUtil.parseRating((String) null)); + } + + @Test + public void parseRating_invalidValue_throwsParseException() { + assertThrows(ParseException.class, () -> ParserUtil.parseRating(INVALID_RATING)); + } + + @Test + public void parseRating_validValueWithoutWhitespace_returnsRating() throws Exception { + Rating expectedRating = new Rating(VALID_RATING); + assertEquals(expectedRating, ParserUtil.parseRating(VALID_RATING)); + } + + @Test + public void parseRating_validValueWithWhitespace_returnsTrimmedRating() throws Exception { + String ratingWithWhitespace = WHITESPACE + VALID_RATING + WHITESPACE; + Rating expectedRating = new Rating(VALID_RATING); + assertEquals(expectedRating, ParserUtil.parseRating(ratingWithWhitespace)); + } } diff --git a/src/test/java/seedu/staffsnap/logic/parser/StatusCommandParserTest.java b/src/test/java/seedu/staffsnap/logic/parser/StatusCommandParserTest.java new file mode 100644 index 00000000000..5c057cc7126 --- /dev/null +++ b/src/test/java/seedu/staffsnap/logic/parser/StatusCommandParserTest.java @@ -0,0 +1,40 @@ +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.commons.core.index.Index; +import seedu.staffsnap.logic.commands.StatusCommand; +import seedu.staffsnap.model.applicant.Status; + + + +class StatusCommandParserTest { + + private StatusCommandParser parser = new StatusCommandParser(); + + @Test + void parse_validArgs_returnsStatusCommand() { + StatusCommand expectedStatusCommand = new StatusCommand(Index.fromOneBased(1), Status.OFFERED); + assertParseSuccess(parser, "1 s/ o", expectedStatusCommand); + } + + @Test + void parse_invalidArgs_throwsParseException() { + assertParseFailure(parser, " ", String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatusCommand.MESSAGE_USAGE)); + } + + @Test + void parse_missingStatus_throwsParseException() { + assertParseFailure(parser, "1", String.format(MESSAGE_INVALID_COMMAND_FORMAT, StatusCommand.MESSAGE_NO_STATUS)); + } + + @Test + void parse_missingIndex_throwsParseException() { + assertParseFailure(parser, "s/ o", String.format(MESSAGE_INVALID_COMMAND_FORMAT, + StatusCommand.MESSAGE_NO_INDEX)); + } +} diff --git a/src/test/java/seedu/staffsnap/model/ApplicantBookTest.java b/src/test/java/seedu/staffsnap/model/ApplicantBookTest.java index 3ec3a850b6e..02c49944dd9 100644 --- a/src/test/java/seedu/staffsnap/model/ApplicantBookTest.java +++ b/src/test/java/seedu/staffsnap/model/ApplicantBookTest.java @@ -3,8 +3,8 @@ 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.commands.CommandTestUtil.VALID_INTERVIEW_BEHAVIORAL; import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_POSITION_BOB; -import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_TYPE_BEHAVIORAL; import static seedu.staffsnap.testutil.Assert.assertThrows; import static seedu.staffsnap.testutil.TypicalApplicants.ALICE; import static seedu.staffsnap.testutil.TypicalApplicants.getTypicalApplicantBook; @@ -47,7 +47,7 @@ public void resetData_withValidReadOnlyApplicantBook_replacesData() { public void resetData_withDuplicateApplicants_throwsDuplicateApplicantException() { // Two applicants with the same identity fields Applicant editedAlice = new ApplicantBuilder(ALICE) - .withPosition(VALID_POSITION_BOB).withInterviews(VALID_TYPE_BEHAVIORAL).build(); + .withPosition(VALID_POSITION_BOB).withInterviews(VALID_INTERVIEW_BEHAVIORAL).build(); List newApplicants = Arrays.asList(ALICE, editedAlice); ApplicantBookStub newData = new ApplicantBookStub(newApplicants); @@ -74,7 +74,7 @@ public void hasApplicant_applicantInApplicantBook_returnsTrue() { public void hasApplicant_applicantWithSameIdentityFieldsInApplicantBook_returnsTrue() { applicantBook.addApplicant(ALICE); Applicant editedAlice = new ApplicantBuilder(ALICE) - .withPosition(VALID_POSITION_BOB).withInterviews(VALID_TYPE_BEHAVIORAL).build(); + .withPosition(VALID_POSITION_BOB).withInterviews(VALID_INTERVIEW_BEHAVIORAL).build(); assertTrue(applicantBook.hasApplicant(editedAlice)); } diff --git a/src/test/java/seedu/staffsnap/model/applicant/ApplicantTest.java b/src/test/java/seedu/staffsnap/model/applicant/ApplicantTest.java index 1b490a6f489..678638f74eb 100644 --- a/src/test/java/seedu/staffsnap/model/applicant/ApplicantTest.java +++ b/src/test/java/seedu/staffsnap/model/applicant/ApplicantTest.java @@ -4,10 +4,10 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_INTERVIEW_BEHAVIORAL; import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_NAME_BOB; import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_PHONE_BOB; import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_POSITION_BOB; -import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_TYPE_BEHAVIORAL; import static seedu.staffsnap.testutil.Assert.assertThrows; import static seedu.staffsnap.testutil.TypicalApplicants.ALICE; import static seedu.staffsnap.testutil.TypicalApplicants.AMY; @@ -94,7 +94,7 @@ public void equals() { assertFalse(ALICE.equals(editedAlice)); // different interviews -> returns false - editedAlice = new ApplicantBuilder(ALICE).withInterviews(VALID_TYPE_BEHAVIORAL).build(); + editedAlice = new ApplicantBuilder(ALICE).withInterviews(VALID_INTERVIEW_BEHAVIORAL).build(); assertFalse(ALICE.equals(editedAlice)); } @@ -102,7 +102,8 @@ public void equals() { public void toStringMethod() { String expected = Applicant.class.getCanonicalName() + "{name=" + ALICE.getName() + ", phone=" + ALICE.getPhone() + ", email=" + ALICE.getEmail() - + ", position=" + ALICE.getPosition() + ", interviews=" + ALICE.getInterviews() + "}"; + + ", position=" + ALICE.getPosition() + ", interviews=" + ALICE.getInterviews() + + ", status=" + ALICE.getStatus() + "}"; assertEquals(expected, ALICE.toString()); } } diff --git a/src/test/java/seedu/staffsnap/model/applicant/UniqueApplicantListTest.java b/src/test/java/seedu/staffsnap/model/applicant/UniqueApplicantListTest.java index acb00b04519..80b77ec3287 100644 --- a/src/test/java/seedu/staffsnap/model/applicant/UniqueApplicantListTest.java +++ b/src/test/java/seedu/staffsnap/model/applicant/UniqueApplicantListTest.java @@ -3,8 +3,8 @@ 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.commands.CommandTestUtil.VALID_INTERVIEW_BEHAVIORAL; import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_POSITION_BOB; -import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_TYPE_BEHAVIORAL; import static seedu.staffsnap.testutil.Assert.assertThrows; import static seedu.staffsnap.testutil.TypicalApplicants.ALICE; import static seedu.staffsnap.testutil.TypicalApplicants.BOB; @@ -46,7 +46,7 @@ public void contains_applicantInList_returnsTrue() { public void contains_applicantWithSameIdentityFieldsInList_returnsTrue() { uniqueApplicantList.add(ALICE); Applicant editedAlice = new ApplicantBuilder(ALICE) - .withPosition(VALID_POSITION_BOB).withInterviews(VALID_TYPE_BEHAVIORAL).build(); + .withPosition(VALID_POSITION_BOB).withInterviews(VALID_INTERVIEW_BEHAVIORAL).build(); assertTrue(uniqueApplicantList.contains(editedAlice)); } @@ -89,7 +89,7 @@ public void setApplicant_editedApplicantIsSameApplicant_success() { public void setApplicant_editedApplicantHasSameIdentity_success() { uniqueApplicantList.add(ALICE); Applicant editedAlice = new ApplicantBuilder(ALICE) - .withPosition(VALID_POSITION_BOB).withInterviews(VALID_TYPE_BEHAVIORAL).build(); + .withPosition(VALID_POSITION_BOB).withInterviews(VALID_INTERVIEW_BEHAVIORAL).build(); uniqueApplicantList.setApplicant(ALICE, editedAlice); UniqueApplicantList expectedUniqueApplicantList = new UniqueApplicantList(); expectedUniqueApplicantList.add(editedAlice); diff --git a/src/test/java/seedu/staffsnap/model/interview/InterviewTest.java b/src/test/java/seedu/staffsnap/model/interview/InterviewTest.java index d824721f89c..9d45d0ef09b 100644 --- a/src/test/java/seedu/staffsnap/model/interview/InterviewTest.java +++ b/src/test/java/seedu/staffsnap/model/interview/InterviewTest.java @@ -1,6 +1,10 @@ package seedu.staffsnap.model.interview; 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.commands.CommandTestUtil.VALID_INTERVIEW_BEHAVIORAL; +import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_INTERVIEW_TECHNICAL; import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_TYPE_TECHNICAL; import static seedu.staffsnap.testutil.Assert.assertThrows; import static seedu.staffsnap.testutil.TypicalApplicants.BENSON; @@ -11,13 +15,14 @@ public class InterviewTest { @Test public void constructor_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new Interview(null)); + assertThrows(NullPointerException.class, () -> new Interview(null, null)); } @Test public void constructor_invalidInterviewName_throwsIllegalArgumentException() { String invalidType = ""; - assertThrows(IllegalArgumentException.class, () -> new Interview(invalidType)); + Rating validRating = BENSON.getInterviews().get(0).getRating(); + assertThrows(IllegalArgumentException.class, () -> new Interview(invalidType, validRating)); } @Test @@ -46,8 +51,8 @@ public void testEquals_sameInterview() { } @Test - public void testEquals_differentType() { - assertEquals(BENSON.getInterviews().get(0).equals(new Interview("HR")), false); + public void testEquals_differentInterview() { + assertEquals(BENSON.getInterviews().get(0).equals(VALID_INTERVIEW_BEHAVIORAL), false); } @Test @@ -57,8 +62,18 @@ public void testHashCode() { @Test void compareTo() { - assertEquals((new Interview("a")).compareTo(new Interview("a")), 0); - assertEquals((new Interview("a")).compareTo(new Interview("b")), -1); - assertEquals((new Interview("b")).compareTo(new Interview("a")), 1); + Rating rating = VALID_INTERVIEW_BEHAVIORAL.getRating(); + assertEquals((new Interview("a", rating)).compareTo(new Interview("a", rating)), 0); + assertEquals((new Interview("a", rating)).compareTo(new Interview("b", rating)), -1); + assertEquals((new Interview("b", rating)).compareTo(new Interview("a", rating)), 1); + } + + @Test + public void isSameInterview() { + // same interview type -> returns true + assertTrue(VALID_INTERVIEW_TECHNICAL.isContainedIn(BENSON.getInterviews())); + + // different interview type -> returns false + assertFalse(VALID_INTERVIEW_BEHAVIORAL.isContainedIn(BENSON.getInterviews())); } } diff --git a/src/test/java/seedu/staffsnap/model/interview/RatingTest.java b/src/test/java/seedu/staffsnap/model/interview/RatingTest.java new file mode 100644 index 00000000000..31c1e7c6e0f --- /dev/null +++ b/src/test/java/seedu/staffsnap/model/interview/RatingTest.java @@ -0,0 +1,74 @@ +package seedu.staffsnap.model.interview; + +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.testutil.Assert.assertThrows; +import static seedu.staffsnap.testutil.TypicalApplicants.BENSON; +import static seedu.staffsnap.testutil.TypicalApplicants.CARL; +import static seedu.staffsnap.testutil.TypicalApplicants.DANIEL; + +import org.junit.jupiter.api.Test; + +public class RatingTest { + + @Test + public void constructor_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new Rating(null)); + } + + @Test + public void constructor_invalidRating_throwsIllegalArgumentException() { + String invalidRating = "a"; + assertThrows(IllegalArgumentException.class, () -> new Rating(invalidRating)); + } + + @Test + public void isValidRating() { + // null rating + assertThrows(NullPointerException.class, () -> Rating.isValidRating(null)); + + // negative rating + assertFalse(Rating.isValidRating("-1")); + + // rating out of range + assertFalse(Rating.isValidRating("15")); + + // non numeric rating + assertFalse(Rating.isValidRating("a")); + } + + @Test + public void equals() { + // same rating -> returns true + Rating sameRating = new Rating(DANIEL.getInterviews().get(0).getRating().value); + assertTrue(BENSON.getInterviews().get(0).getRating().equals(sameRating)); + + // same object -> returns true + assertTrue(sameRating.equals(sameRating)); + + // null -> returns false + assertFalse(sameRating.equals(null)); + + // different rating -> returns false + Rating differentRating = CARL.getInterviews().get(0).getRating(); + assertFalse(sameRating.equals(differentRating)); + } + + @Test + public void toStringMethod() { + String expected = BENSON.getInterviews().get(0).getRating().value; + assertEquals(expected, BENSON.getInterviews().get(0).getRating().toString()); + } + + @Test + public void testHashCode() { + // same object -> equal hashcode + String rating = BENSON.getInterviews().get(0).getRating().value; + assertEquals(rating.hashCode(), rating.hashCode()); + + // same rating -> equal hashcode + String sameRating = DANIEL.getInterviews().get(0).getRating().value; + assertEquals(rating.hashCode(), sameRating.hashCode()); + } +} diff --git a/src/test/java/seedu/staffsnap/storage/JsonAdaptedApplicantTest.java b/src/test/java/seedu/staffsnap/storage/JsonAdaptedApplicantTest.java index 1c55b808447..e8695a2d911 100644 --- a/src/test/java/seedu/staffsnap/storage/JsonAdaptedApplicantTest.java +++ b/src/test/java/seedu/staffsnap/storage/JsonAdaptedApplicantTest.java @@ -23,6 +23,9 @@ public class JsonAdaptedApplicantTest { private static final String INVALID_POSITION = " "; private static final String INVALID_EMAIL = "example.com"; private static final String INVALID_INTERVIEW = "#friend"; + private static final String INVALID_TYPE = " "; + private static final String INVALID_RATING = "15.0"; + private static final String INVALID_STATUS = "POP"; private static final String VALID_NAME = BENSON.getName().toString(); private static final String VALID_PHONE = BENSON.getPhone().toString(); @@ -31,6 +34,7 @@ public class JsonAdaptedApplicantTest { private static final List VALID_INTERVIEWS = BENSON.getInterviews().stream() .map(JsonAdaptedInterview::new) .collect(Collectors.toList()); + private static final String VALID_STATUS = "O"; @Test public void toModelType_validApplicantDetails_returnsApplicant() throws Exception { @@ -41,7 +45,8 @@ public void toModelType_validApplicantDetails_returnsApplicant() throws Exceptio @Test public void toModelType_invalidName_throwsIllegalValueException() { JsonAdaptedApplicant applicant = - new JsonAdaptedApplicant(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_POSITION, VALID_INTERVIEWS); + new JsonAdaptedApplicant(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_POSITION, VALID_INTERVIEWS, + VALID_STATUS); String expectedMessage = Name.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, applicant::toModelType); } @@ -49,7 +54,7 @@ public void toModelType_invalidName_throwsIllegalValueException() { @Test public void toModelType_nullName_throwsIllegalValueException() { JsonAdaptedApplicant applicant = new JsonAdaptedApplicant( - null, VALID_PHONE, VALID_EMAIL, VALID_POSITION, VALID_INTERVIEWS); + null, VALID_PHONE, VALID_EMAIL, VALID_POSITION, VALID_INTERVIEWS, VALID_STATUS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, applicant::toModelType); } @@ -57,7 +62,8 @@ public void toModelType_nullName_throwsIllegalValueException() { @Test public void toModelType_invalidPhone_throwsIllegalValueException() { JsonAdaptedApplicant applicant = - new JsonAdaptedApplicant(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_POSITION, VALID_INTERVIEWS); + new JsonAdaptedApplicant(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_POSITION, VALID_INTERVIEWS, + VALID_STATUS); String expectedMessage = Phone.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, applicant::toModelType); } @@ -65,7 +71,7 @@ public void toModelType_invalidPhone_throwsIllegalValueException() { @Test public void toModelType_nullPhone_throwsIllegalValueException() { JsonAdaptedApplicant applicant = new JsonAdaptedApplicant( - VALID_NAME, null, VALID_EMAIL, VALID_POSITION, VALID_INTERVIEWS); + VALID_NAME, null, VALID_EMAIL, VALID_POSITION, VALID_INTERVIEWS, VALID_STATUS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, applicant::toModelType); } @@ -73,7 +79,8 @@ public void toModelType_nullPhone_throwsIllegalValueException() { @Test public void toModelType_invalidEmail_throwsIllegalValueException() { JsonAdaptedApplicant applicant = - new JsonAdaptedApplicant(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_POSITION, VALID_INTERVIEWS); + new JsonAdaptedApplicant(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_POSITION, VALID_INTERVIEWS, + VALID_STATUS); String expectedMessage = Email.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, applicant::toModelType); } @@ -81,7 +88,7 @@ public void toModelType_invalidEmail_throwsIllegalValueException() { @Test public void toModelType_nullEmail_throwsIllegalValueException() { JsonAdaptedApplicant applicant = new JsonAdaptedApplicant( - VALID_NAME, VALID_PHONE, null, VALID_POSITION, VALID_INTERVIEWS); + VALID_NAME, VALID_PHONE, null, VALID_POSITION, VALID_INTERVIEWS, VALID_STATUS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, applicant::toModelType); } @@ -89,7 +96,8 @@ public void toModelType_nullEmail_throwsIllegalValueException() { @Test public void toModelType_invalidPosition_throwsIllegalValueException() { JsonAdaptedApplicant applicant = - new JsonAdaptedApplicant(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_POSITION, VALID_INTERVIEWS); + new JsonAdaptedApplicant(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_POSITION, VALID_INTERVIEWS, + VALID_STATUS); String expectedMessage = Position.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, applicant::toModelType); } @@ -97,7 +105,7 @@ public void toModelType_invalidPosition_throwsIllegalValueException() { @Test public void toModelType_nullPosition_throwsIllegalValueException() { JsonAdaptedApplicant applicant = new JsonAdaptedApplicant(VALID_NAME, VALID_PHONE, - VALID_EMAIL, null, VALID_INTERVIEWS); + VALID_EMAIL, null, VALID_INTERVIEWS, VALID_STATUS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Position.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, applicant::toModelType); } @@ -105,9 +113,10 @@ public void toModelType_nullPosition_throwsIllegalValueException() { @Test public void toModelType_invalidInterviews_throwsIllegalValueException() { List invalidInterviews = new ArrayList<>(VALID_INTERVIEWS); - invalidInterviews.add(new JsonAdaptedInterview(INVALID_INTERVIEW)); + invalidInterviews.add(new JsonAdaptedInterview(INVALID_TYPE, INVALID_RATING)); JsonAdaptedApplicant applicant = - new JsonAdaptedApplicant(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_POSITION, invalidInterviews); + new JsonAdaptedApplicant(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_POSITION, invalidInterviews, + VALID_STATUS); assertThrows(IllegalValueException.class, applicant::toModelType); } diff --git a/src/test/java/seedu/staffsnap/testutil/ApplicantBuilder.java b/src/test/java/seedu/staffsnap/testutil/ApplicantBuilder.java index 24cdcd68ee0..e86040c3993 100644 --- a/src/test/java/seedu/staffsnap/testutil/ApplicantBuilder.java +++ b/src/test/java/seedu/staffsnap/testutil/ApplicantBuilder.java @@ -8,6 +8,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.util.SampleDataUtil; @@ -20,12 +21,14 @@ public class ApplicantBuilder { public static final String DEFAULT_PHONE = "85355255"; public static final String DEFAULT_EMAIL = "amy@gmail.com"; public static final String DEFAULT_POSITION = "123, Jurong West Ave 6, #08-111"; + public static final String DEFAULT_STATUS = "UNDECIDED"; private Name name; private Phone phone; private Email email; private Position position; private List interviews; + private Status status; /** * Creates a {@code ApplicantBuilder} with the default details. @@ -36,6 +39,7 @@ public ApplicantBuilder() { email = new Email(DEFAULT_EMAIL); position = new Position(DEFAULT_POSITION); interviews = new ArrayList<>(); + status = Status.findByName(DEFAULT_STATUS); } /** @@ -47,6 +51,7 @@ public ApplicantBuilder(Applicant applicantToCopy) { email = applicantToCopy.getEmail(); position = applicantToCopy.getPosition(); interviews = new ArrayList<>(applicantToCopy.getInterviews()); + status = applicantToCopy.getStatus(); } /** @@ -61,7 +66,7 @@ public ApplicantBuilder withName(String name) { * Parses the {@code interviews} into a {@code List} and set it to the {@code Applicant} that we are * building. */ - public ApplicantBuilder withInterviews(String ... interviews) { + public ApplicantBuilder withInterviews(Interview ... interviews) { this.interviews = SampleDataUtil.getInterviewList(interviews); return this; } @@ -90,8 +95,16 @@ public ApplicantBuilder withEmail(String email) { return this; } + /** + * Sets the {@code Status} of the {@code Applicant} that we are building. + */ + public ApplicantBuilder withStatus(String status) { + this.status = Status.findByName(status); + return this; + } + public Applicant build() { - return new Applicant(name, phone, email, position, interviews); + return new Applicant(name, phone, email, position, interviews, status); } } diff --git a/src/test/java/seedu/staffsnap/testutil/EditApplicantDescriptorBuilder.java b/src/test/java/seedu/staffsnap/testutil/EditApplicantDescriptorBuilder.java index cd47caae7c0..b5839c76433 100644 --- a/src/test/java/seedu/staffsnap/testutil/EditApplicantDescriptorBuilder.java +++ b/src/test/java/seedu/staffsnap/testutil/EditApplicantDescriptorBuilder.java @@ -11,6 +11,7 @@ import seedu.staffsnap.model.applicant.Phone; import seedu.staffsnap.model.applicant.Position; import seedu.staffsnap.model.interview.Interview; +import seedu.staffsnap.model.interview.Rating; /** * A utility class to help with building EditApplicantDescriptor objects. @@ -76,7 +77,8 @@ public EditApplicantDescriptorBuilder withPosition(String position) { * that we are building. */ public EditApplicantDescriptorBuilder withInterviews(String... interviews) { - List interviewList = Stream.of(interviews).map(Interview::new).collect(Collectors.toList()); + List interviewList = Stream.of(interviews).map(interview -> + new Interview(interview, new Rating("-"))).collect(Collectors.toList()); descriptor.setInterviews(interviewList); return this; } diff --git a/src/test/java/seedu/staffsnap/testutil/TypicalApplicants.java b/src/test/java/seedu/staffsnap/testutil/TypicalApplicants.java index 9a4d8e42984..ac8f0ace699 100644 --- a/src/test/java/seedu/staffsnap/testutil/TypicalApplicants.java +++ b/src/test/java/seedu/staffsnap/testutil/TypicalApplicants.java @@ -2,6 +2,8 @@ import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_EMAIL_AMY; import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_INTERVIEW_BEHAVIORAL; +import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_INTERVIEW_TECHNICAL; import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_NAME_AMY; import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_NAME_BOB; import static seedu.staffsnap.logic.commands.CommandTestUtil.VALID_PHONE_AMY; @@ -26,11 +28,13 @@ public class TypicalApplicants { .withPosition("Software Engineer").withEmail("alice@example.com").withPhone("94351253").build(); public static final Applicant BENSON = new ApplicantBuilder().withName("Benson Meier") .withPosition("Frontend Engineer").withEmail("benson@example.com").withPhone("98765432") - .withInterviews("technical").build(); + .withInterviews(VALID_INTERVIEW_TECHNICAL).build(); public static final Applicant CARL = new ApplicantBuilder().withName("Carl Kurz").withPhone("95352563") - .withEmail("carl@example.com").withPosition("Backend Engineer").build(); + .withEmail("carl@example.com").withPosition("Backend Engineer").withInterviews(VALID_INTERVIEW_BEHAVIORAL) + .build(); public static final Applicant DANIEL = new ApplicantBuilder().withName("Daniel Meier").withPhone("87652533") - .withEmail("daniel@example.com").withPosition("Testing Engineer").withInterviews("screening").build(); + .withEmail("daniel@example.com").withPosition("Testing Engineer").withInterviews(VALID_INTERVIEW_TECHNICAL) + .build(); public static final Applicant ELLE = new ApplicantBuilder().withName("Elle Meyer").withPhone("9482224") .withEmail("elle@example.com").withPosition("Frontend Engineer").build(); public static final Applicant FIONA = new ApplicantBuilder().withName("Fiona Kunz").withPhone("9482427")