Skip to content

Commit

Permalink
Merge pull request AY2324S1-CS2103T-W08-1#135 from craigtonlian/updat…
Browse files Browse the repository at this point in the history
…e-input-validation

Update input validation
  • Loading branch information
CelestineTan03 authored Oct 30, 2023
2 parents b50543f + c6dea55 commit d882b6b
Show file tree
Hide file tree
Showing 20 changed files with 49 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
run: git checkout --progress --force ${{ github.sha }}

- name: Run repository-wide tests
if: runner.os == 'Linux'
if: runner.os == 'macOS'
working-directory: ${{ github.workspace }}/.github
run: ./run-checks.sh

Expand All @@ -39,7 +39,7 @@ jobs:
run: ./gradlew check coverage

- name: Upload coverage reports to Codecov
if: runner.os == 'Linux'
if: runner.os == 'macOS'
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Expand Down
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,27 @@

This is a CS2103T project by [**AY2324S1-CS2103T-W08-1**](https://github.com/orgs/AY2324S1-CS2103T-W08-1/people).<br>

> An applicant management program for Hiring Managers to track applicants throughout the hiring process.
> A hiring management program for Hiring Managers to track applicants throughout the hiring process.
![Ui](docs/images/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.
Staff-Snap is a desktop app for Hiring 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.

## Features v1.2
* Add an applicant
* Edit an applicant's details
* Delete an applicant
* View all applicants
* Find an applicant by name
* Sort applicants by descriptors
* Sort applicants by descriptor
* Filter applicants by descriptor criteria
* Add an interview to an applicant
* Edit an interview of an applicant
* Delete an interview of an applicant
* Import csv data
* Save data to file
* Clear all data

## Future updates
* Update the status of an applicant
* View analytics of applicants by rating
* Import applicant details with `.csv` file

## Issues and Bugs
Spot a bug? Let us know by launching a Bug Report at the [Issues tab](https://github.com/AY2324S1-CS2103T-W08-1/tp/issues)!

Expand All @@ -39,5 +36,5 @@ Spot a bug? Let us know by launching a Bug Report at the [Issues tab](https://gi
* [Github Organization](https://github.com/orgs/AY2324S1-CS2103T-W08-1)

## Acknowldgements
* Libraries used: [JavaFX](https://openjfx.io/), [Jackson](https://github.com/FasterXML/jackson), [JUnit5](https://junit.org/junit5/), [OpenCSV](https://opencsv.sourceforge.net/project-info.html)
* Libraries used: [JavaFX](https://openjfx.io/), [Jackson](https://github.com/FasterXML/jackson), [JUnit5](https://junit.org/junit5/), [OpenCSV](https://opencsv.sourceforge.net/project-info.html), [TestFX](https://testfx.github.io/TestFX/docs/javadoc/testfx-core/javadoc/org.testfx/module-summary.html)
* Staff-Snap is based on the [AddressBook-Level3](https://se-education.org/addressbook-level3/) project created by the [SE-EDU initiative](https://se-education.org).
Binary file modified docs/images/Ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/main/java/seedu/staffsnap/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
public class MainApp extends Application {

public static final Version VERSION = new Version(1, 2, 1, false);
public static final Version VERSION = new Version(1, 3, 0, false);

private static final Logger logger = LogsCenter.getLogger(MainApp.class);

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/staffsnap/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ public static String format(Applicant applicant) {
.append("; Position: ")
.append(applicant.getPosition())
.append("; Interviews: ");
builder.append("[");
applicant.getInterviews().forEach(interview ->
builder.append(interview.getType())
.append("(")
.append(interview.getRating())
.append("); "));
builder.append("]");
builder.append("; Status: ")
.append(applicant.getStatus())
.append("; Score: ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class AddCommand extends Command {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an applicant to the applicant book. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an applicant to the applicant book.\n"
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class AddInterviewCommand extends Command {
public static final String COMMAND_WORD = "addi";

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. "
+ "by the index number used in the displayed applicant list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ PREFIX_TYPE + "TYPE" + " "
+ "[" + PREFIX_RATING + "RATING]...\n"
Expand All @@ -33,6 +33,7 @@ public class AddInterviewCommand extends Command {

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";
public static final String MESSAGE_INTERVIEW_LIMIT_REACHED = "This applicant has reached the interview limit of 5";

private final Index index;
private Interview interviewToAdd;
Expand All @@ -58,6 +59,10 @@ public CommandResult execute(Model model) throws CommandException {

Applicant applicantToEdit = lastShownList.get(index.getZeroBased());

if (applicantToEdit.getInterviews().size() == 5) {
throw new CommandException(MESSAGE_INTERVIEW_LIMIT_REACHED);
}

while (applicantToEdit.getInterviews().contains(interviewToAdd)
|| interviewToAdd.isContainedIn(applicantToEdit.getInterviews())) {
interviewToAdd = interviewToAdd.incrementName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ public CommandResult execute(Model model) throws CommandException {
applicantsToImport.size() == 1 ? MESSAGE_SUCCESS_SINGULAR : MESSAGE_SUCCESS_PLURAL,
applicantsToImport.size(),
fileName));


}

private boolean containsDuplicates(List<Applicant> applicantsToImport) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/staffsnap/model/applicant/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class Email {
+ "The domain name must:\n"
+ " - end with a domain label at least 2 characters long\n"
+ " - have each domain label start and end with alphanumeric characters\n"
+ " - have each domain label consist of alphanumeric characters, separated only by hyphens, if any.";
+ " - have each domain label consist of alphanumeric characters, separated only by hyphens, if any."
+ "3. The entire email address must not be more than 30 characters long.";
// alphanumeric and special characters
private static final String ALPHANUMERIC_NO_UNDERSCORE = "[^\\W_]+"; // alphanumeric characters except underscore
private static final String LOCAL_PART_REGEX = "^" + ALPHANUMERIC_NO_UNDERSCORE + "([" + SPECIAL_CHARACTERS + "]"
Expand Down Expand Up @@ -48,7 +49,7 @@ public Email(String email) {
* Returns if a given string is a valid email.
*/
public static boolean isValidEmail(String test) {
return test.matches(VALIDATION_REGEX);
return test.matches(VALIDATION_REGEX) && test.length() <= 30;
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/staffsnap/model/applicant/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
public class Name implements Comparable<Name> {

public static final String MESSAGE_CONSTRAINTS =
"Names should only contain alphanumeric characters and spaces, and it should not be blank";
"Names should only contain alphanumeric characters and spaces, should not be blank, "
+ "and should not exceed 25 characters";

/*
* The first character of the name must not be a whitespace,
Expand All @@ -35,7 +36,7 @@ public Name(String name) {
* Returns true if a given string is a valid name.
*/
public static boolean isValidName(String test) {
return test.matches(VALIDATION_REGEX);
return test.matches(VALIDATION_REGEX) && test.length() <= 25;
}


Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/staffsnap/model/applicant/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class Phone implements Comparable<Phone> {


public static final String MESSAGE_CONSTRAINTS =
"Phone numbers should only contain numbers, and it should be at least 3 digits long";
"Phone numbers should only contain numbers, should be at least 3 digits long, "
+ "and at most 30 digits long";
public static final String VALIDATION_REGEX = "\\d{3,}";
public final String value;

Expand All @@ -30,7 +31,7 @@ public Phone(String phone) {
* Returns true if a given string is a valid phone number.
*/
public static boolean isValidPhone(String test) {
return test.matches(VALIDATION_REGEX);
return test.matches(VALIDATION_REGEX) && test.length() <= 30;
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/staffsnap/model/interview/Interview.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/
public class Interview implements Comparable<Interview> {

public static final String MESSAGE_CONSTRAINTS = "Interview types should not be empty";
public static final String MESSAGE_CONSTRAINTS = "Interview types should not be empty and should be at most 14 "
+ "characters long";

public final String type;

Expand All @@ -38,7 +39,7 @@ public Interview(String type, Rating rating) {
* Returns true if a given string is a valid interview type.
*/
public static boolean isValidType(String test) {
return !test.isEmpty();
return !test.isEmpty() && test.length() <= 14;
}

public String getType() {
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/seedu/staffsnap/ui/ApplicantCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public ApplicantCard(Applicant applicant, int displayedIndex) {
displayApplicantScore();
}


private void displayApplicantId(int displayedIndex) {
id.setText(displayedIndex + ". ");
}
Expand Down Expand Up @@ -109,10 +108,10 @@ private void displayApplicantStatus() {

switch (applicant.getStatus()) {
case OFFERED:
status.setStyle("-fx-background-color: #50c952");
status.setStyle("-fx-background-color: #0da811");
break;
case REJECTED:
status.setStyle("-fx-background-color: #e87f7f");
status.setStyle("-fx-background-color: #cc4242");
break;
case UNDECIDED:
status.setStyle("-fx-background-color: #36769a");
Expand All @@ -128,13 +127,12 @@ private void displayApplicantInterviews() {
HBox interviewRating = new HBox();

interviewBox.setMinHeight(100);
interviewBox.setMinWidth(100);
interviewBox.setMinWidth(120);
interviewRating.setPrefWidth(100);
interviewRating.setAlignment(Pos.CENTER);
interviewHeader.setAlignment(Pos.CENTER);
VBox.setVgrow(interviewRating, Priority.ALWAYS);

//sets the individual interview rating box with a border radius of 10
interviewBox.setBackground(new Background(new BackgroundFill(
Color.TRANSPARENT,
new CornerRadii(10),
Expand All @@ -153,7 +151,7 @@ private void displayApplicantInterviews() {
new CornerRadii(0, 0, 10, 10, false),
Insets.EMPTY)));

Label interviewLabel = new Label((int) applicant.getInterviewIndexForApplicantCard(interview)
Label interviewLabel = new Label(applicant.getInterviewIndexForApplicantCard(interview)
+ ". " + interview.type);

Label interviewRatingLabel = new Label();
Expand All @@ -180,7 +178,7 @@ private void displayApplicantScore() {
Group stackedArcs = new Group();
stackedArcs.getChildren().addAll(outerCircle, midCircle);

String labelText = applicant.getScore().hasRating() ? applicant.getScore().toString() : "N.A.";
String labelText = applicant.getScore().hasRating() ? applicant.getScore().toString() : "-";
Label scoreLabel = new Label(labelText);
scoreLabel.getStyleClass().add("score_label");

Expand All @@ -197,7 +195,7 @@ private void displayApplicantScore() {
stackedArcs.getChildren().add(arc);
}

double applicantRating = labelText.equals("N.A.") ? 0 : Double.parseDouble(labelText);
double applicantRating = labelText.equals("-") ? 0 : Double.parseDouble(labelText);
double ratingArcLength = -360 * (applicantRating / 10);
Arc ratingArc = new Arc(0, 0, 43, 43, 90, ratingArcLength);
Color arcColour = colours[(int) Math.floor(applicantRating)];
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/view/ApplicantListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<HBox id="cardPane" fx:id="cardPane" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1">
<GridPane HBox.hgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="300" minWidth="300" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="350" minWidth="350" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="150" minWidth="150" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="400" minWidth="400" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="715" minWidth="400" />
</columnConstraints>
<VBox alignment="CENTER_LEFT" minHeight="100" GridPane.columnIndex="0" GridPane.rowSpan="2">
<padding>
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<?import javafx.scene.Scene?>
<?import javafx.stage.Stage?>
<fx:root type="javafx.stage.Stage" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1"
title="Staff-Snap" minWidth="450" minHeight="600" onCloseRequest="#handleExit">
title="Staff-Snap" minWidth="1215" minHeight="660" onCloseRequest="#handleExit">
<icons>
<Image url="@/images/ss_logo.png" />
</icons>
Expand All @@ -34,14 +34,14 @@

<StackPane VBox.vgrow="NEVER" fx:id="commandBoxPlaceholder" styleClass="pane-with-border">
<padding>
<Insets top="5" right="10" bottom="5" left="10" />
<Insets top="10" right="10" bottom="10" left="10" />
</padding>
</StackPane>

<StackPane VBox.vgrow="NEVER" fx:id="resultDisplayPlaceholder" styleClass="pane-with-border"
minHeight="100" prefHeight="100" maxHeight="100">
<padding>
<Insets top="5" right="10" bottom="5" left="10" />
<Insets top="10" right="10" bottom="10" left="10" />
</padding>
</StackPane>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"name" : "Bob Choo",
"phone" : "22222222",
"email" : "[email protected]",
"position" : "Block 123, Bobby Street 3",
"position" : "Software Engineer",
"interviews" : []
}, {
"name" : "Carl Kurz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class CommandTestUtil {
public static final String VALID_PHONE_BOB = "22222222";
public static final String VALID_EMAIL_AMY = "[email protected]";
public static final String VALID_EMAIL_BOB = "[email protected]";
public static final String VALID_POSITION_AMY = "Block 312, Amy Street 1";
public static final String VALID_POSITION_BOB = "Block 123, Bobby Street 3";
public static final String VALID_POSITION_AMY = "Backend Engineer";
public static final String VALID_POSITION_BOB = "Software Engineer";
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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_POSITION_AMY;
import static seedu.staffsnap.testutil.Assert.assertThrows;
import static seedu.staffsnap.testutil.TypicalApplicants.ALICE;
import static seedu.staffsnap.testutil.TypicalApplicants.AMY;
Expand Down Expand Up @@ -90,7 +90,7 @@ public void equals() {
assertFalse(ALICE.equals(editedAlice));

// different position -> returns false
editedAlice = new ApplicantBuilder(ALICE).withPosition(VALID_POSITION_BOB).build();
editedAlice = new ApplicantBuilder(ALICE).withPosition(VALID_POSITION_AMY).build();
assertFalse(ALICE.equals(editedAlice));

// different interviews -> returns false
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/seedu/staffsnap/model/applicant/EmailTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void isValidEmail() {
assertFalse(Email.isValidEmail("peter@[email protected]")); // '@' symbol in local part
assertFalse(Email.isValidEmail("[email protected]")); // local part starts with a hyphen
assertFalse(Email.isValidEmail("[email protected]")); // local part ends with a hyphen
assertFalse(Email.isValidEmail("[email protected]")); // exceed 30 characters
// local part has two consecutive periods
assertFalse(Email.isValidEmail("[email protected]"));
assertFalse(Email.isValidEmail("peterjack@example@com")); // '@' symbol in domain name
Expand All @@ -63,8 +64,6 @@ public void isValidEmail() {
assertTrue(Email.isValidEmail("123@145")); // numeric local part and domain name
// mixture of alphanumeric and special characters
assertTrue(Email.isValidEmail("[email protected]"));
assertTrue(Email.isValidEmail("[email protected]")); // long domain name
assertTrue(Email.isValidEmail("[email protected]")); // long local part
assertTrue(Email.isValidEmail("[email protected]")); // more than one period in domain
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/seedu/staffsnap/model/applicant/NameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ public void isValidName() {
assertFalse(Name.isValidName(" ")); // spaces only
assertFalse(Name.isValidName("^")); // only non-alphanumeric characters
assertFalse(Name.isValidName("peter*")); // contains non-alphanumeric characters
assertFalse(Name.isValidName("David Roger Jackson Ray Jr 2nd")); // exceeds 25 characters

// valid name
assertTrue(Name.isValidName("peter jack")); // alphabets only
assertTrue(Name.isValidName("12345")); // numbers only
assertTrue(Name.isValidName("peter the 2nd")); // alphanumeric characters
assertTrue(Name.isValidName("Capital Tan")); // with capital letters
assertTrue(Name.isValidName("David Roger Jackson Ray Jr 2nd")); // long names

}

@Test
Expand Down

0 comments on commit d882b6b

Please sign in to comment.