diff --git a/src/main/java/safeforhall/logic/commands/AddCommand.java b/src/main/java/safeforhall/logic/commands/AddCommand.java index 51718a98fa8..c295452d338 100644 --- a/src/main/java/safeforhall/logic/commands/AddCommand.java +++ b/src/main/java/safeforhall/logic/commands/AddCommand.java @@ -22,7 +22,6 @@ public class AddCommand extends Command { + CliSyntax.PREFIX_EMAIL + "EMAIL " + CliSyntax.PREFIX_VACCSTATUS + "VACCINATION STATUS " + CliSyntax.PREFIX_FACULTY + "FACULTY " - //TODO + CliSyntax.PREFIX_FETDATE + "LAST FET DATE " + CliSyntax.PREFIX_COLLECTIONDATE + "LAST COLLECTION DATE \n" @@ -33,9 +32,8 @@ public class AddCommand extends Command { + CliSyntax.PREFIX_EMAIL + "johnd@example.com " + CliSyntax.PREFIX_VACCSTATUS + "T " + CliSyntax.PREFIX_FACULTY + "SoC " - //TODO - + CliSyntax.PREFIX_FETDATE + "TODO " - + CliSyntax.PREFIX_COLLECTIONDATE + "TODO "; + + CliSyntax.PREFIX_FETDATE + "20-10-2021 " + + CliSyntax.PREFIX_COLLECTIONDATE + "23-10-2021 "; public static final String MESSAGE_SUCCESS = "New resident added: %1$s"; public static final String MESSAGE_DUPLICATE_PERSON = "This resident already exists in the address book"; diff --git a/src/main/java/safeforhall/logic/parser/AddCommandParser.java b/src/main/java/safeforhall/logic/parser/AddCommandParser.java index 94134c63209..c525ece163c 100644 --- a/src/main/java/safeforhall/logic/parser/AddCommandParser.java +++ b/src/main/java/safeforhall/logic/parser/AddCommandParser.java @@ -16,6 +16,7 @@ import safeforhall.logic.parser.exceptions.ParseException; import safeforhall.model.person.Email; import safeforhall.model.person.Faculty; +import safeforhall.model.person.LastDate; import safeforhall.model.person.Name; import safeforhall.model.person.Person; import safeforhall.model.person.Phone; @@ -44,6 +45,7 @@ public AddCommand parse(String args) throws ParseException { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } + // Required fields Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); @@ -51,7 +53,13 @@ public AddCommand parse(String args) throws ParseException { VaccStatus vaccStatus = ParserUtil.parseVaccStatus(argMultimap.getValue(PREFIX_VACCSTATUS).get()); Faculty faculty = ParserUtil.parseFaculty(argMultimap.getValue(PREFIX_FACULTY).get()); - Person person = new Person(name, room, phone, email, vaccStatus, faculty, null, null); + // Optional fields + LastDate lastFetDate = ParserUtil.parseDate(argMultimap.getValue(PREFIX_FETDATE) + .orElse(LastDate.DEFAULT_DATE)); + LastDate lastCollectionDate = ParserUtil.parseDate(argMultimap.getValue(PREFIX_COLLECTIONDATE) + .orElse(LastDate.DEFAULT_DATE)); + + Person person = new Person(name, room, phone, email, vaccStatus, faculty, lastFetDate, lastCollectionDate); return new AddCommand(person); } diff --git a/src/main/java/safeforhall/model/person/Email.java b/src/main/java/safeforhall/model/person/Email.java index 844f1a0cc38..e70dca63e8f 100644 --- a/src/main/java/safeforhall/model/person/Email.java +++ b/src/main/java/safeforhall/model/person/Email.java @@ -9,6 +9,7 @@ */ public class Email { + public static final String DESC = "Email: "; private static final String SPECIAL_CHARACTERS = "+_.-"; public static final String MESSAGE_CONSTRAINTS = "Emails should be of the format local-part@domain " + "and adhere to the following constraints:\n" diff --git a/src/main/java/safeforhall/model/person/Faculty.java b/src/main/java/safeforhall/model/person/Faculty.java index c24790fa67d..2e8d762bc98 100644 --- a/src/main/java/safeforhall/model/person/Faculty.java +++ b/src/main/java/safeforhall/model/person/Faculty.java @@ -9,13 +9,15 @@ */ public class Faculty { - public static final String MESSAGE_CONSTRAINTS = "Faculty can take any values, and it should not be blank"; + public static final String MESSAGE_CONSTRAINTS = "Faculty is a single word made up of alphabets " + + "and it should not be blank"; /* - * The first character of the faculty must not be a whitespace, - * otherwise " " (a blank string) becomes a valid input. + * faculty must consist of 2 or more alphabets. */ - public static final String VALIDATION_REGEX = "[^\\s].*"; + public static final String VALIDATION_REGEX = "[A-Za-z]{2,}$"; + + public static final String DESC = "Faculty: "; public final String faculty; diff --git a/src/main/java/safeforhall/model/person/LastDate.java b/src/main/java/safeforhall/model/person/LastDate.java index 16fe384d4cf..5b5ea3d1cb9 100644 --- a/src/main/java/safeforhall/model/person/LastDate.java +++ b/src/main/java/safeforhall/model/person/LastDate.java @@ -8,6 +8,9 @@ public class LastDate { public static final String MESSAGE_CONSTRAINTS = "Date inputted has to be in dd-mm-yyyy format"; + public static final String DEFAULT_DATE = ""; + public static final String FET_DESC = "Last FET: "; + public static final String COLLECTION_DESC = "Last Collection: "; private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); @@ -29,6 +32,9 @@ public LastDate(String date) { * Returns true if a given string is a valid date. */ public static boolean isValidDate(String date) { + if (date.equals(DEFAULT_DATE)) { + return true; + } try { LocalDate.parse(date, dateFormatter); } catch (DateTimeParseException e) { @@ -52,7 +58,9 @@ public LocalDate toLocalDate() { * Adds the period of validity to the given {@code LastDate} to get the next deadline. */ public LocalDate getDeadline() { - return LocalDate.parse(date, dateFormatter).plusWeeks(LASTDATE_DEADLINE); + return date.equals("") + ? LocalDate.now() + : LocalDate.parse(date, dateFormatter).plusWeeks(LASTDATE_DEADLINE); } @Override diff --git a/src/main/java/safeforhall/model/person/Name.java b/src/main/java/safeforhall/model/person/Name.java index 5ead9eb3f27..8976dacdcfa 100644 --- a/src/main/java/safeforhall/model/person/Name.java +++ b/src/main/java/safeforhall/model/person/Name.java @@ -18,6 +18,8 @@ public class Name { */ public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + public static final String DESC = "Name: "; + public final String fullName; /** diff --git a/src/main/java/safeforhall/model/person/Person.java b/src/main/java/safeforhall/model/person/Person.java index 54559443253..507cb0be8b7 100644 --- a/src/main/java/safeforhall/model/person/Person.java +++ b/src/main/java/safeforhall/model/person/Person.java @@ -25,12 +25,11 @@ public class Person { private final LastDate lastCollectionDate; /** - * Every field must be present and only last 3 can be null. + * Every field must be present. */ public Person(Name name, Room room, Phone phone, Email email, VaccStatus vaccStatus, Faculty faculty, LastDate lastFetDate, LastDate lastCollectionDate) { - // Optionals: faculty, lastFetDate, lastCollectionDate - requireAllNonNull(name, room, phone, email, vaccStatus); + requireAllNonNull(name, room, phone, email, vaccStatus, faculty, lastFetDate, lastCollectionDate); this.name = name; this.room = room; this.phone = phone; @@ -104,7 +103,11 @@ public boolean equals(Object other) { return otherPerson.getName().equals(getName()) && otherPerson.getRoom().equals(getRoom()) && otherPerson.getPhone().equals(getPhone()) - && otherPerson.getEmail().equals(getEmail()); + && otherPerson.getEmail().equals(getEmail()) + && otherPerson.getVaccStatus().equals(getVaccStatus()) + && otherPerson.getFaculty().equals(getFaculty()) + && otherPerson.getLastFetDate().equals(getLastFetDate()) + && otherPerson.getLastCollectionDate().equals(getLastCollectionDate()); } @Override @@ -126,7 +129,11 @@ public String toString() { .append("; Vaccinated: ") .append(getVaccStatus()) .append("; Faculty: ") - .append(getFaculty()); + .append(getFaculty()) + .append("; Last Fet Date: ") + .append(getLastFetDate()) + .append("; Last Collection Date: ") + .append(getLastCollectionDate()); return builder.toString(); } diff --git a/src/main/java/safeforhall/model/person/Phone.java b/src/main/java/safeforhall/model/person/Phone.java index 98225e1507e..8cdb8de430c 100644 --- a/src/main/java/safeforhall/model/person/Phone.java +++ b/src/main/java/safeforhall/model/person/Phone.java @@ -13,6 +13,9 @@ public class Phone { public static final String MESSAGE_CONSTRAINTS = "Phone numbers should only contain numbers, and it should be at least 3 digits long"; public static final String VALIDATION_REGEX = "\\d{3,}"; + + public static final String DESC = "Phone: "; + public final String value; /** diff --git a/src/main/java/safeforhall/model/person/Room.java b/src/main/java/safeforhall/model/person/Room.java index 6a9562f4793..388a8e390b4 100644 --- a/src/main/java/safeforhall/model/person/Room.java +++ b/src/main/java/safeforhall/model/person/Room.java @@ -25,6 +25,8 @@ public class Room { */ public static final String VALIDATION_REGEX = "^[a-eA-E][1-4][0-2][0-9]$"; + public static final String DESC = "Room: "; + public final String room; /** diff --git a/src/main/java/safeforhall/model/person/VaccStatus.java b/src/main/java/safeforhall/model/person/VaccStatus.java index 54349ed52d0..d6bdc4f9d15 100644 --- a/src/main/java/safeforhall/model/person/VaccStatus.java +++ b/src/main/java/safeforhall/model/person/VaccStatus.java @@ -16,6 +16,8 @@ public class VaccStatus { */ public static final String VALIDATION_REGEX = "^([Tt]|[Ff])$"; + public static final String DESC = "Vaccinated: "; + public final String vaccStatus; public final boolean vaccinated; diff --git a/src/main/java/safeforhall/ui/PersonCard.java b/src/main/java/safeforhall/ui/PersonCard.java index ff6eb170c14..8bfd9cf0f60 100644 --- a/src/main/java/safeforhall/ui/PersonCard.java +++ b/src/main/java/safeforhall/ui/PersonCard.java @@ -1,5 +1,7 @@ package safeforhall.ui; +import static safeforhall.model.person.LastDate.DEFAULT_DATE; + import javafx.fxml.FXML; import javafx.scene.control.Label; import javafx.scene.image.Image; @@ -8,7 +10,12 @@ import javafx.scene.layout.VBox; import javafx.scene.paint.ImagePattern; import javafx.scene.shape.Rectangle; +import safeforhall.model.person.Email; +import safeforhall.model.person.Faculty; +import safeforhall.model.person.LastDate; import safeforhall.model.person.Person; +import safeforhall.model.person.Phone; +import safeforhall.model.person.Room; /** * An UI component that displays information of a {@code Person}. @@ -50,9 +57,9 @@ public class PersonCard extends UiPart { @FXML private VBox statusContainer; @FXML - private Label lastfetdate; + private VBox labelBox; @FXML - private Label lastcollectiondate; + private VBox labelBoxInterior; /** * Creates a {@code PersonCode} with the given {@code Person} and index to display. @@ -62,12 +69,22 @@ public PersonCard(Person person, int displayedIndex) { this.person = person; id.setText(displayedIndex + ". "); name.setText(person.getName().fullName); - room.setText(person.getRoom().room); - phone.setText(person.getPhone().value); - email.setText(person.getEmail().value); - faculty.setText(person.getFaculty().faculty); - lastfetdate.setText(person.getLastFetDate().date); - lastcollectiondate.setText(person.getLastCollectionDate().date); + room.setText(Room.DESC + person.getRoom().room); + phone.setText(Phone.DESC + person.getPhone().value); + email.setText(Email.DESC + person.getEmail().value); + faculty.setText(Faculty.DESC + person.getFaculty().faculty); + + if (person.getLastFetDate().date != DEFAULT_DATE) { + Label textBox = new Label(LastDate.FET_DESC + person.getLastFetDate().date); + textBox.getStyleClass().add("cell_small_label"); + labelBoxInterior.getChildren().add(textBox); + } + + if (person.getLastCollectionDate().date != DEFAULT_DATE) { + Label textBox = new Label(LastDate.COLLECTION_DESC + person.getLastCollectionDate().date); + textBox.getStyleClass().add("cell_small_label"); + labelBoxInterior.getChildren().add(textBox); + } if (person.hasMissedDeadline()) { this.getRoot().setStyle("-fx-background-color: #8B0000;"); diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index 65a45801a9f..b1818d82545 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -13,7 +13,7 @@ - + @@ -26,12 +26,12 @@ diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json index efaa8cb652b..da27e36a6a2 100644 --- a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json @@ -7,61 +7,61 @@ "email" : "alice@example.com", "vaccStatus" : "T", "faculty" : "SoC", - "lastFetDate" : "09-09-2021", - "lastCollectionDate" : "10-09-2021" + "lastFetDate" : "03-10-2021", + "lastCollectionDate" : "03-10-2021" }, { "name" : "Benson Meier", "room" : "A101", "phone" : "98765432", "email" : "johnd@example.com", "vaccStatus" : "T", - "faculty" : "FASS", - "lastFetDate" : "10-09-2021", - "lastCollectionDate" : "11-09-2021" + "faculty" : "SoC", + "lastFetDate" : "12-10-2021", + "lastCollectionDate" : "13-10-2021" }, { "name" : "Carl Kurz", "room" : "A102", "phone" : "95352563", "email" : "heinz@example.com", - "vaccStatus" : "T", - "faculty" : "FASS", - "lastFetDate" : "11-09-2021", - "lastCollectionDate" : "12-09-2021" + "vaccStatus" : "F", + "faculty" : "SoC", + "lastFetDate" : "10-10-2021", + "lastCollectionDate" : "03-10-2021" }, { "name" : "Daniel Meier", "room" : "A103", "phone" : "87652533", "email" : "cornelia@example.com", "vaccStatus" : "T", - "faculty" : "FASS", - "lastFetDate" : "09-09-2021", - "lastCollectionDate" : "08-09-2021" + "faculty" : "SoC", + "lastFetDate" : "12-10-2021", + "lastCollectionDate" : "13-10-2021" }, { "name" : "Elle Meyer", "room" : "A104", "phone" : "9482224", "email" : "werner@example.com", - "vaccStatus" : "T", - "faculty" : "FASS", - "lastFetDate" : "12-09-2021", - "lastCollectionDate" : "12-09-2021" + "vaccStatus" : "F", + "faculty" : "SoC", + "lastFetDate" : "05-10-2021", + "lastCollectionDate" : "16-10-2021" }, { "name" : "Fiona Kunz", "room" : "A105", "phone" : "9482427", "email" : "lydia@example.com", "vaccStatus" : "T", - "faculty" : "FASS", - "lastFetDate" : "20-09-2021", - "lastCollectionDate" : "21-09-2021" + "faculty" : "SoC", + "lastFetDate" : "20-10-2021", + "lastCollectionDate" : "04-10-2021" }, { "name" : "George Best", "room" : "A106", "phone" : "9482442", "email" : "anna@example.com", - "vaccStatus" : "T", - "faculty" : "FASS", - "lastFetDate" : "01-09-2021", - "lastCollectionDate" : "22-09-2021" + "vaccStatus" : "F", + "faculty" : "SoC", + "lastFetDate" : "15-10-2021", + "lastCollectionDate" : "01-10-2021" } ] } diff --git a/src/test/java/safeforhall/logic/LogicManagerTest.java b/src/test/java/safeforhall/logic/LogicManagerTest.java index 2716c052c3a..0c860cc402b 100644 --- a/src/test/java/safeforhall/logic/LogicManagerTest.java +++ b/src/test/java/safeforhall/logic/LogicManagerTest.java @@ -1,10 +1,10 @@ package safeforhall.logic; import static org.junit.jupiter.api.Assertions.assertEquals; +import static safeforhall.logic.commands.CommandTestUtil.COLLECTION_DESC_AMY; import static safeforhall.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; import static safeforhall.logic.commands.CommandTestUtil.FACULTY_DESC_AMY; -import static safeforhall.logic.commands.CommandTestUtil.LAST_DATE1_DESC_OCT; -import static safeforhall.logic.commands.CommandTestUtil.LAST_DATE2_DESC_OCT; +import static safeforhall.logic.commands.CommandTestUtil.FET_DESC_AMY; import static safeforhall.logic.commands.CommandTestUtil.NAME_DESC_AMY; import static safeforhall.logic.commands.CommandTestUtil.PHONE_DESC_AMY; import static safeforhall.logic.commands.CommandTestUtil.ROOM_DESC_AMY; @@ -103,7 +103,7 @@ public void execute_storageThrowsIoException_throwsCommandException() { // Execute add command String addCommand = AddCommand.COMMAND_WORD + NAME_DESC_AMY + ROOM_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY - + VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY + LAST_DATE1_DESC_OCT + LAST_DATE2_DESC_OCT; + + VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY + FET_DESC_AMY + COLLECTION_DESC_AMY; Person expectedPerson = new PersonBuilder(TypicalPersons.AMY).build(); ModelManager expectedModel = new ModelManager(); expectedModel.addPerson(expectedPerson); diff --git a/src/test/java/safeforhall/logic/commands/CommandTestUtil.java b/src/test/java/safeforhall/logic/commands/CommandTestUtil.java index 8cb8d72d382..d9ac5ace50c 100644 --- a/src/test/java/safeforhall/logic/commands/CommandTestUtil.java +++ b/src/test/java/safeforhall/logic/commands/CommandTestUtil.java @@ -2,10 +2,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static safeforhall.logic.parser.CliSyntax.PREFIX_COLLECTIONDATE; import static safeforhall.logic.parser.CliSyntax.PREFIX_DATE1; import static safeforhall.logic.parser.CliSyntax.PREFIX_DATE2; import static safeforhall.logic.parser.CliSyntax.PREFIX_EMAIL; import static safeforhall.logic.parser.CliSyntax.PREFIX_FACULTY; +import static safeforhall.logic.parser.CliSyntax.PREFIX_FETDATE; import static safeforhall.logic.parser.CliSyntax.PREFIX_KEYWORD; import static safeforhall.logic.parser.CliSyntax.PREFIX_NAME; import static safeforhall.logic.parser.CliSyntax.PREFIX_PHONE; @@ -42,6 +44,10 @@ public class CommandTestUtil { public static final String VALID_FACULTY_BOB = "FASS"; public static final String VALID_VACCSTATUS_AMY = "T"; public static final String VALID_VACCSTATUS_BOB = "F"; + public static final String VALID_FETDATE_AMY = "20-11-2021"; + public static final String VALID_FETDATE_BOB = "02-09-2021"; + public static final String VALID_COLLECTIONDATE_AMY = "22-11-2021"; + public static final String VALID_COLLECTIONDATE_BOB = "12-09-2021"; public static final String VALID_LAST_DATE1_OCT = "10-10-2021"; public static final String VALID_LAST_DATE2_OCT = "15-10-2021"; public static final String VALID_KEYWORD_F = "f"; @@ -59,6 +65,10 @@ public class CommandTestUtil { public static final String FACULTY_DESC_BOB = " " + PREFIX_FACULTY + VALID_FACULTY_BOB; public static final String VACCSTATUS_DESC_AMY = " " + PREFIX_VACCSTATUS + VALID_VACCSTATUS_AMY; public static final String VACCSTATUS_DESC_BOB = " " + PREFIX_VACCSTATUS + VALID_VACCSTATUS_BOB; + public static final String FET_DESC_AMY = " " + PREFIX_FETDATE + VALID_FETDATE_AMY; + public static final String FET_DESC_BOB = " " + PREFIX_FETDATE + VALID_FETDATE_BOB; + public static final String COLLECTION_DESC_AMY = " " + PREFIX_COLLECTIONDATE + VALID_COLLECTIONDATE_AMY; + public static final String COLLECTION_DESC_BOB = " " + PREFIX_COLLECTIONDATE + VALID_COLLECTIONDATE_BOB; public static final String LAST_DATE1_DESC_OCT = " " + PREFIX_DATE1 + VALID_LAST_DATE1_OCT; public static final String LAST_DATE2_DESC_OCT = " " + PREFIX_DATE2 + VALID_LAST_DATE2_OCT; public static final String KEYWORD_DESC_F = " " + PREFIX_KEYWORD + VALID_KEYWORD_F; @@ -70,7 +80,9 @@ public class CommandTestUtil { public static final String INVALID_EMAIL_DESC = " " + PREFIX_EMAIL + "bob!yahoo"; // missing '@' symbol public static final String INVALID_ROOM_DESC = " " + PREFIX_ROOM; // empty string not allowed for room public static final String INVALID_FACULTY_DESC = " " + PREFIX_FACULTY; // empty string not allowed for faculty - public static final String INVALID_VACCSTATUS_DESC = " " + PREFIX_VACCSTATUS + "fake"; //only T or F allowed + public static final String INVALID_VACCSTATUS_DESC = " " + PREFIX_VACCSTATUS + "fake"; // only T or F allowed + public static final String INVALID_FETDATE_DESC = " " + PREFIX_FETDATE + "41-20-20"; // not valid date + public static final String INVALID_COLLECTIONDATE_DESC = " " + PREFIX_FETDATE + "41/20/20"; // not valid date public static final String PREAMBLE_WHITESPACE = "\t \r \n"; public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble"; diff --git a/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java b/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java index 542dbdb5cb6..d45d8954d5c 100644 --- a/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java +++ b/src/test/java/safeforhall/logic/parser/AddCommandParserTest.java @@ -1,11 +1,17 @@ package safeforhall.logic.parser; +import static safeforhall.logic.commands.CommandTestUtil.COLLECTION_DESC_AMY; +import static safeforhall.logic.commands.CommandTestUtil.COLLECTION_DESC_BOB; import static safeforhall.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; import static safeforhall.logic.commands.CommandTestUtil.EMAIL_DESC_BOB; import static safeforhall.logic.commands.CommandTestUtil.FACULTY_DESC_AMY; import static safeforhall.logic.commands.CommandTestUtil.FACULTY_DESC_BOB; +import static safeforhall.logic.commands.CommandTestUtil.FET_DESC_AMY; +import static safeforhall.logic.commands.CommandTestUtil.FET_DESC_BOB; +import static safeforhall.logic.commands.CommandTestUtil.INVALID_COLLECTIONDATE_DESC; import static safeforhall.logic.commands.CommandTestUtil.INVALID_EMAIL_DESC; import static safeforhall.logic.commands.CommandTestUtil.INVALID_FACULTY_DESC; +import static safeforhall.logic.commands.CommandTestUtil.INVALID_FETDATE_DESC; import static safeforhall.logic.commands.CommandTestUtil.INVALID_NAME_DESC; import static safeforhall.logic.commands.CommandTestUtil.INVALID_PHONE_DESC; import static safeforhall.logic.commands.CommandTestUtil.INVALID_ROOM_DESC; @@ -28,7 +34,9 @@ import static safeforhall.logic.commands.CommandTestUtil.VALID_VACCSTATUS_BOB; import static safeforhall.logic.parser.CommandParserTestUtil.assertParseFailure; import static safeforhall.logic.parser.CommandParserTestUtil.assertParseSuccess; -//import static safeforhall.testutil.TypicalPersons.AMY; +import static safeforhall.testutil.TypicalPersons.AMY_NO_COLLECTION; +import static safeforhall.testutil.TypicalPersons.AMY_NO_FET; +import static safeforhall.testutil.TypicalPersons.AMY_NO_FET_COLLECTION; import static safeforhall.testutil.TypicalPersons.BOB; import org.junit.jupiter.api.Test; @@ -37,6 +45,7 @@ import safeforhall.logic.commands.AddCommand; import safeforhall.model.person.Email; import safeforhall.model.person.Faculty; +import safeforhall.model.person.LastDate; import safeforhall.model.person.Name; import safeforhall.model.person.Person; import safeforhall.model.person.Phone; @@ -53,40 +62,68 @@ public void parse_allFieldsPresent_success() { // whitespace only preamble assertParseSuccess(parser, PREAMBLE_WHITESPACE + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB - + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, new AddCommand(expectedPerson)); + + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); // multiple names - last name accepted assertParseSuccess(parser, NAME_DESC_AMY + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB - + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, new AddCommand(expectedPerson)); + + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); // multiple phones - last phone accepted assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_AMY + PHONE_DESC_BOB + EMAIL_DESC_BOB - + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, new AddCommand(expectedPerson)); + + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); // multiple emails - last email accepted assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_AMY + EMAIL_DESC_BOB - + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, new AddCommand(expectedPerson)); + + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); // multiple rooms - last room accepted assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_AMY - + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, new AddCommand(expectedPerson)); + + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); // multiple faculties - last faculty accepted assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB - + FACULTY_DESC_AMY + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, new AddCommand(expectedPerson)); + + FACULTY_DESC_AMY + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); // multiple vaccination status - last vaccStatus accepted assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB - + FACULTY_DESC_BOB + VACCSTATUS_DESC_AMY + VACCSTATUS_DESC_BOB, new AddCommand(expectedPerson)); + + FACULTY_DESC_BOB + VACCSTATUS_DESC_AMY + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); + + // multiple fet dates - last fet date accepted + assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB + + FACULTY_DESC_BOB + VACCSTATUS_DESC_AMY + VACCSTATUS_DESC_BOB + + FET_DESC_AMY + FET_DESC_BOB + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); + + // multiple collection dates - last collection date accepted + assertParseSuccess(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB + + FACULTY_DESC_BOB + VACCSTATUS_DESC_AMY + VACCSTATUS_DESC_BOB + + FET_DESC_BOB + COLLECTION_DESC_AMY + COLLECTION_DESC_BOB, new AddCommand(expectedPerson)); } - /*@Test + @Test public void parse_optionalFieldsMissing_success() { - // zero tags - Person expectedPerson = new PersonBuilder(AMY).build(); - assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ADDRESS_DESC_AMY, - new AddCommand(expectedPerson)); - }*/ + Person expectedPerson = new PersonBuilder(AMY_NO_FET_COLLECTION).build(); + + // missing lastFetDate and lastCollectionDate + assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ROOM_DESC_AMY + + VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY, new AddCommand(expectedPerson)); + + // missing lastFetDate + expectedPerson = new PersonBuilder(AMY_NO_FET).build(); + assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ROOM_DESC_AMY + + VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY + COLLECTION_DESC_AMY, new AddCommand(expectedPerson)); + + // missing lastCollectionDate + expectedPerson = new PersonBuilder(AMY_NO_COLLECTION).build(); + assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + ROOM_DESC_AMY + + VACCSTATUS_DESC_AMY + FACULTY_DESC_AMY + FET_DESC_AMY, new AddCommand(expectedPerson)); + } @Test public void parse_compulsoryFieldMissing_failure() { @@ -125,35 +162,52 @@ public void parse_compulsoryFieldMissing_failure() { public void parse_invalidValue_failure() { // invalid name assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB - + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, Name.MESSAGE_CONSTRAINTS); + + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + FET_DESC_BOB + + COLLECTION_DESC_BOB, Name.MESSAGE_CONSTRAINTS); // invalid phone assertParseFailure(parser, NAME_DESC_BOB + INVALID_PHONE_DESC + EMAIL_DESC_BOB + ROOM_DESC_BOB - + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, Phone.MESSAGE_CONSTRAINTS); + + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + FET_DESC_BOB + + COLLECTION_DESC_BOB, Phone.MESSAGE_CONSTRAINTS); // invalid email assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + INVALID_EMAIL_DESC + ROOM_DESC_BOB - + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, Email.MESSAGE_CONSTRAINTS); + + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + FET_DESC_BOB + + COLLECTION_DESC_BOB, Email.MESSAGE_CONSTRAINTS); // invalid room assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_ROOM_DESC - + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, Room.MESSAGE_CONSTRAINTS); + + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + FET_DESC_BOB + + COLLECTION_DESC_BOB, Room.MESSAGE_CONSTRAINTS); // invalid faculty assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB - + INVALID_FACULTY_DESC + VACCSTATUS_DESC_BOB, Faculty.MESSAGE_CONSTRAINTS); + + INVALID_FACULTY_DESC + VACCSTATUS_DESC_BOB + FET_DESC_BOB + + COLLECTION_DESC_BOB, Faculty.MESSAGE_CONSTRAINTS); // invalid vaccination status assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB - + FACULTY_DESC_BOB + INVALID_VACCSTATUS_DESC, VaccStatus.MESSAGE_CONSTRAINTS); + + FACULTY_DESC_BOB + INVALID_VACCSTATUS_DESC + FET_DESC_BOB + + COLLECTION_DESC_BOB, VaccStatus.MESSAGE_CONSTRAINTS); + + // invalid FET date + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB + + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + INVALID_FETDATE_DESC + + COLLECTION_DESC_BOB, LastDate.MESSAGE_CONSTRAINTS); + + // invalid collection date + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ROOM_DESC_BOB + + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + FET_DESC_BOB + + INVALID_COLLECTIONDATE_DESC, LastDate.MESSAGE_CONSTRAINTS); // two invalid values, only first invalid value reported assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_ROOM_DESC - + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, Name.MESSAGE_CONSTRAINTS); + + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + FET_DESC_BOB + + COLLECTION_DESC_BOB, Name.MESSAGE_CONSTRAINTS); // non-empty preamble assertParseFailure(parser, PREAMBLE_NON_EMPTY + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB - + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB, + + ROOM_DESC_BOB + FACULTY_DESC_BOB + VACCSTATUS_DESC_BOB + FET_DESC_BOB + COLLECTION_DESC_BOB, String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } } diff --git a/src/test/java/safeforhall/model/person/LastDateTest.java b/src/test/java/safeforhall/model/person/LastDateTest.java index 4e97d279108..dacad9349f0 100644 --- a/src/test/java/safeforhall/model/person/LastDateTest.java +++ b/src/test/java/safeforhall/model/person/LastDateTest.java @@ -18,7 +18,7 @@ public void isValidDate() { assertThrows(NullPointerException.class, () -> new LastDate(null)); // invalid dates - assertFalse(LastDate.isValidDate("")); + //assertFalse(LastDate.isValidDate("")); assertFalse(LastDate.isValidDate("10.10.2021")); assertFalse(LastDate.isValidDate("10/10/2021")); assertFalse(LastDate.isValidDate("9-9-2021")); diff --git a/src/test/java/safeforhall/testutil/EditPersonDescriptorBuilder.java b/src/test/java/safeforhall/testutil/EditPersonDescriptorBuilder.java index c827b7d4b42..7868d1f3602 100644 --- a/src/test/java/safeforhall/testutil/EditPersonDescriptorBuilder.java +++ b/src/test/java/safeforhall/testutil/EditPersonDescriptorBuilder.java @@ -39,10 +39,9 @@ public EditPersonDescriptorBuilder(Person person) { descriptor.setEmail(person.getEmail()); descriptor.setRoom(person.getRoom()); descriptor.setFaculty(person.getFaculty()); - //TODO: lastfetdate and lastcollectiondate - - // descriptor.setAddress(person.getAddress()); - // descriptor.setTags(person.getTags()); + descriptor.setVaccStatus(person.getVaccStatus()); + descriptor.setLastFetDate(person.getLastFetDate()); + descriptor.setLastCollectionDate(person.getLastCollectionDate()); } /** diff --git a/src/test/java/safeforhall/testutil/PersonBuilder.java b/src/test/java/safeforhall/testutil/PersonBuilder.java index 9c2a4300bf1..951d987ba6e 100644 --- a/src/test/java/safeforhall/testutil/PersonBuilder.java +++ b/src/test/java/safeforhall/testutil/PersonBuilder.java @@ -20,8 +20,8 @@ public class PersonBuilder { public static final String DEFAULT_EMAIL = "amy@gmail.com"; public static final String DEFAULT_VACCSTATUS = "T"; public static final String DEFAULT_FACULTY = "SoC"; - public static final String DEFAULT_FETDATE = "10-09-2021"; - public static final String DEFAULT_COLLECTDATE = "10-09-2021"; + public static final String DEFAULT_FETDATE = ""; + public static final String DEFAULT_COLLECTDATE = ""; private Name name; private Room room; diff --git a/src/test/java/safeforhall/testutil/PersonUtil.java b/src/test/java/safeforhall/testutil/PersonUtil.java index 674dd17a7f1..02888f1404b 100644 --- a/src/test/java/safeforhall/testutil/PersonUtil.java +++ b/src/test/java/safeforhall/testutil/PersonUtil.java @@ -1,7 +1,9 @@ package safeforhall.testutil; +import static safeforhall.logic.parser.CliSyntax.PREFIX_COLLECTIONDATE; import static safeforhall.logic.parser.CliSyntax.PREFIX_EMAIL; import static safeforhall.logic.parser.CliSyntax.PREFIX_FACULTY; +import static safeforhall.logic.parser.CliSyntax.PREFIX_FETDATE; import static safeforhall.logic.parser.CliSyntax.PREFIX_NAME; import static safeforhall.logic.parser.CliSyntax.PREFIX_PHONE; import static safeforhall.logic.parser.CliSyntax.PREFIX_ROOM; @@ -34,6 +36,8 @@ public static String getPersonDetails(Person person) { sb.append(PREFIX_ROOM + person.getRoom().room + " "); sb.append(PREFIX_FACULTY + person.getFaculty().faculty + " "); sb.append(PREFIX_VACCSTATUS + person.getVaccStatus().vaccStatus + " "); + sb.append(PREFIX_FETDATE + person.getLastFetDate().date + " "); + sb.append(PREFIX_COLLECTIONDATE + person.getLastCollectionDate().date + " "); return sb.toString(); } diff --git a/src/test/java/safeforhall/testutil/TypicalPersons.java b/src/test/java/safeforhall/testutil/TypicalPersons.java index a0964977e89..56e3992d452 100644 --- a/src/test/java/safeforhall/testutil/TypicalPersons.java +++ b/src/test/java/safeforhall/testutil/TypicalPersons.java @@ -1,9 +1,13 @@ package safeforhall.testutil; +import static safeforhall.logic.commands.CommandTestUtil.VALID_COLLECTIONDATE_AMY; +import static safeforhall.logic.commands.CommandTestUtil.VALID_COLLECTIONDATE_BOB; import static safeforhall.logic.commands.CommandTestUtil.VALID_EMAIL_AMY; import static safeforhall.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; import static safeforhall.logic.commands.CommandTestUtil.VALID_FACULTY_AMY; import static safeforhall.logic.commands.CommandTestUtil.VALID_FACULTY_BOB; +import static safeforhall.logic.commands.CommandTestUtil.VALID_FETDATE_AMY; +import static safeforhall.logic.commands.CommandTestUtil.VALID_FETDATE_BOB; import static safeforhall.logic.commands.CommandTestUtil.VALID_NAME_AMY; import static safeforhall.logic.commands.CommandTestUtil.VALID_NAME_BOB; import static safeforhall.logic.commands.CommandTestUtil.VALID_PHONE_AMY; @@ -36,8 +40,8 @@ public class TypicalPersons { .build(); public static final Person BENSON = new PersonBuilder().withName("Benson Meier") .withRoom("A101") - .withEmail("johnd@example.com") .withPhone("98765432") + .withEmail("johnd@example.com") .withVaccStatus("T") .withFaculty("SoC") .withFet("12-10-2021") @@ -116,8 +120,34 @@ public class TypicalPersons { .withRoom(VALID_ROOM_AMY) .withFaculty(VALID_FACULTY_AMY) .withVaccStatus(VALID_VACCSTATUS_AMY) - .withFet("09-10-2021") - .withCollection("08-10-2021") + .withFet(VALID_FETDATE_AMY) + .withCollection(VALID_COLLECTIONDATE_AMY) + .build(); + // Person AMY without FET or COLLECTION + public static final Person AMY_NO_FET_COLLECTION = new PersonBuilder().withName(VALID_NAME_AMY) + .withPhone(VALID_PHONE_AMY) + .withEmail(VALID_EMAIL_AMY) + .withRoom(VALID_ROOM_AMY) + .withFaculty(VALID_FACULTY_AMY) + .withVaccStatus(VALID_VACCSTATUS_AMY) + .build(); + // Person AMY without FET + public static final Person AMY_NO_FET = new PersonBuilder().withName(VALID_NAME_AMY) + .withPhone(VALID_PHONE_AMY) + .withEmail(VALID_EMAIL_AMY) + .withRoom(VALID_ROOM_AMY) + .withFaculty(VALID_FACULTY_AMY) + .withVaccStatus(VALID_VACCSTATUS_AMY) + .withCollection(VALID_COLLECTIONDATE_AMY) + .build(); + // Person AMY without COLLECTION + public static final Person AMY_NO_COLLECTION = new PersonBuilder().withName(VALID_NAME_AMY) + .withPhone(VALID_PHONE_AMY) + .withEmail(VALID_EMAIL_AMY) + .withRoom(VALID_ROOM_AMY) + .withFaculty(VALID_FACULTY_AMY) + .withVaccStatus(VALID_VACCSTATUS_AMY) + .withFet(VALID_FETDATE_AMY) .build(); public static final Person BOB = new PersonBuilder().withName(VALID_NAME_BOB) .withPhone(VALID_PHONE_BOB) @@ -125,8 +155,8 @@ public class TypicalPersons { .withRoom(VALID_ROOM_BOB) .withFaculty(VALID_FACULTY_BOB) .withVaccStatus(VALID_VACCSTATUS_BOB) - .withFet("15-11-2021") - .withCollection("12-11-2021") + .withFet(VALID_FETDATE_BOB) + .withCollection(VALID_COLLECTIONDATE_BOB) .build(); public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER