diff --git a/src/main/java/staffconnect/logic/Messages.java b/src/main/java/staffconnect/logic/Messages.java index 210b43d43e8..237754bf0e1 100644 --- a/src/main/java/staffconnect/logic/Messages.java +++ b/src/main/java/staffconnect/logic/Messages.java @@ -43,6 +43,8 @@ public static String format(Person person) { .append(person.getEmail()) .append("; Venue: ") .append(person.getVenue()) + .append("; Module: ") + .append(person.getModule()) .append("; Tags: "); person.getTags().forEach(builder::append); return builder.toString(); diff --git a/src/main/java/staffconnect/logic/commands/AddCommand.java b/src/main/java/staffconnect/logic/commands/AddCommand.java index 577b0f67521..e89a8a8ad1a 100644 --- a/src/main/java/staffconnect/logic/commands/AddCommand.java +++ b/src/main/java/staffconnect/logic/commands/AddCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; import static staffconnect.logic.parser.CliSyntax.PREFIX_EMAIL; +import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; import static staffconnect.logic.parser.CliSyntax.PREFIX_TAG; @@ -26,12 +27,14 @@ public class AddCommand extends Command { + PREFIX_PHONE + "PHONE " + PREFIX_EMAIL + "EMAIL " + PREFIX_VENUE + "VENUE " + + PREFIX_MODULE + "MODULE " + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "John Doe " + PREFIX_PHONE + "98765432 " + PREFIX_EMAIL + "johnd@example.com " + PREFIX_VENUE + "311, Clementi Ave 2, #02-25 " + + PREFIX_MODULE + "CS2103 " + PREFIX_TAG + "friends " + PREFIX_TAG + "owesMoney"; diff --git a/src/main/java/staffconnect/logic/commands/EditCommand.java b/src/main/java/staffconnect/logic/commands/EditCommand.java index 0b51e4aa99c..a2a253942d1 100644 --- a/src/main/java/staffconnect/logic/commands/EditCommand.java +++ b/src/main/java/staffconnect/logic/commands/EditCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; import static staffconnect.logic.parser.CliSyntax.PREFIX_EMAIL; +import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; import static staffconnect.logic.parser.CliSyntax.PREFIX_TAG; @@ -22,6 +23,7 @@ import staffconnect.logic.commands.exceptions.CommandException; import staffconnect.model.Model; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; import staffconnect.model.person.Phone; @@ -43,6 +45,7 @@ public class EditCommand extends Command { + "[" + PREFIX_PHONE + "PHONE] " + "[" + PREFIX_EMAIL + "EMAIL] " + "[" + PREFIX_VENUE + "VENUE] " + + "[" + PREFIX_MODULE + "MODULE] " + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " 1 " + PREFIX_PHONE + "91234567 " @@ -99,9 +102,10 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone()); Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); Venue updatedVenue = editPersonDescriptor.getVenue().orElse(personToEdit.getVenue()); + Module updatedModule = editPersonDescriptor.getModule().orElse(personToEdit.getModule()); Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedVenue, updatedTags); + return new Person(updatedName, updatedPhone, updatedEmail, updatedVenue, updatedModule, updatedTags); } @Override @@ -137,6 +141,7 @@ public static class EditPersonDescriptor { private Phone phone; private Email email; private Venue venue; + private Module module; private Set<Tag> tags; public EditPersonDescriptor() {} @@ -150,6 +155,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { setPhone(toCopy.phone); setEmail(toCopy.email); setVenue(toCopy.venue); + setModule(toCopy.module); setTags(toCopy.tags); } @@ -157,7 +163,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { * Returns true if at least one field is edited. */ public boolean isAnyFieldEdited() { - return CollectionUtil.isAnyNonNull(name, phone, email, venue, tags); + return CollectionUtil.isAnyNonNull(name, phone, email, venue, module, tags); } public void setName(Name name) { @@ -192,6 +198,14 @@ public Optional<Venue> getVenue() { return Optional.ofNullable(venue); } + public void setModule(Module module) { + this.module = module; + } + + public Optional<Module> getModule() { + return Optional.ofNullable(module); + } + /** * Sets {@code tags} to this object's {@code tags}. * A defensive copy of {@code tags} is used internally. @@ -225,6 +239,7 @@ public boolean equals(Object other) { && Objects.equals(phone, otherEditPersonDescriptor.phone) && Objects.equals(email, otherEditPersonDescriptor.email) && Objects.equals(venue, otherEditPersonDescriptor.venue) + && Objects.equals(module, otherEditPersonDescriptor.module) && Objects.equals(tags, otherEditPersonDescriptor.tags); } @@ -235,6 +250,7 @@ public String toString() { .add("phone", phone) .add("email", email) .add("venue", venue) + .add("module", module) .add("tags", tags) .toString(); } diff --git a/src/main/java/staffconnect/logic/parser/AddCommandParser.java b/src/main/java/staffconnect/logic/parser/AddCommandParser.java index 19f8d8e203e..3b8bf5a2f62 100644 --- a/src/main/java/staffconnect/logic/parser/AddCommandParser.java +++ b/src/main/java/staffconnect/logic/parser/AddCommandParser.java @@ -2,6 +2,7 @@ import static staffconnect.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static staffconnect.logic.parser.CliSyntax.PREFIX_EMAIL; +import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; import static staffconnect.logic.parser.CliSyntax.PREFIX_TAG; @@ -13,6 +14,7 @@ import staffconnect.logic.commands.AddCommand; import staffconnect.logic.parser.exceptions.ParseException; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; import staffconnect.model.person.Phone; @@ -30,22 +32,24 @@ public class AddCommandParser implements Parser<AddCommand> { * @throws ParseException if the user input does not conform the expected format */ public AddCommand parse(String args) throws ParseException { - ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VENUE, PREFIX_TAG); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, + PREFIX_EMAIL, PREFIX_VENUE, PREFIX_MODULE, PREFIX_TAG); - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_VENUE, PREFIX_PHONE, PREFIX_EMAIL) + if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VENUE, PREFIX_MODULE) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } - argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VENUE); + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_VENUE, PREFIX_MODULE); 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()); Venue venue = ParserUtil.parseVenue(argMultimap.getValue(PREFIX_VENUE).get()); + Module module = ParserUtil.parseModule(argMultimap.getValue(PREFIX_MODULE).get()); Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Person person = new Person(name, phone, email, venue, tagList); + Person person = new Person(name, phone, email, venue, module, tagList); return new AddCommand(person); } diff --git a/src/main/java/staffconnect/logic/parser/CliSyntax.java b/src/main/java/staffconnect/logic/parser/CliSyntax.java index 110c2dd1386..9493ab188e5 100644 --- a/src/main/java/staffconnect/logic/parser/CliSyntax.java +++ b/src/main/java/staffconnect/logic/parser/CliSyntax.java @@ -10,6 +10,7 @@ public class CliSyntax { public static final Prefix PREFIX_PHONE = new Prefix("p/"); public static final Prefix PREFIX_EMAIL = new Prefix("e/"); public static final Prefix PREFIX_VENUE = new Prefix("v/"); + public static final Prefix PREFIX_MODULE = new Prefix("m/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); } diff --git a/src/main/java/staffconnect/logic/parser/EditCommandParser.java b/src/main/java/staffconnect/logic/parser/EditCommandParser.java index 76ff492730f..3249935c101 100644 --- a/src/main/java/staffconnect/logic/parser/EditCommandParser.java +++ b/src/main/java/staffconnect/logic/parser/EditCommandParser.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import static staffconnect.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static staffconnect.logic.parser.CliSyntax.PREFIX_EMAIL; +import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; import static staffconnect.logic.parser.CliSyntax.PREFIX_TAG; @@ -32,7 +33,8 @@ public class EditCommandParser implements Parser<EditCommand> { public EditCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VENUE, PREFIX_TAG); + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_VENUE, PREFIX_MODULE, PREFIX_TAG); Index index; @@ -42,7 +44,8 @@ public EditCommand parse(String args) throws ParseException { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe); } - argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VENUE); + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_VENUE, PREFIX_MODULE); EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor(); @@ -58,6 +61,9 @@ public EditCommand parse(String args) throws ParseException { if (argMultimap.getValue(PREFIX_VENUE).isPresent()) { editPersonDescriptor.setVenue(ParserUtil.parseVenue(argMultimap.getValue(PREFIX_VENUE).get())); } + if (argMultimap.getValue(PREFIX_MODULE).isPresent()) { + editPersonDescriptor.setModule(ParserUtil.parseModule(argMultimap.getValue(PREFIX_MODULE).get())); + } parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags); if (!editPersonDescriptor.isAnyFieldEdited()) { diff --git a/src/main/java/staffconnect/logic/parser/ParserUtil.java b/src/main/java/staffconnect/logic/parser/ParserUtil.java index 182ab6e4755..454061da8b3 100644 --- a/src/main/java/staffconnect/logic/parser/ParserUtil.java +++ b/src/main/java/staffconnect/logic/parser/ParserUtil.java @@ -10,6 +10,7 @@ import staffconnect.commons.util.StringUtil; import staffconnect.logic.parser.exceptions.ParseException; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Phone; import staffconnect.model.person.Venue; @@ -65,6 +66,21 @@ public static Phone parsePhone(String phone) throws ParseException { return new Phone(trimmedPhone); } + /** + * Parses a {@code String email} into an {@code Email}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code email} is invalid. + */ + public static Email parseEmail(String email) throws ParseException { + requireNonNull(email); + String trimmedEmail = email.trim(); + if (!Email.isValidEmail(trimmedEmail)) { + throw new ParseException(Email.MESSAGE_CONSTRAINTS); + } + return new Email(trimmedEmail); + } + /** * Parses a {@code String venue} into an {@code Venue}. * Leading and trailing whitespaces will be trimmed. @@ -81,18 +97,18 @@ public static Venue parseVenue(String venue) throws ParseException { } /** - * Parses a {@code String email} into an {@code Email}. + * Parses a {@code String module} into an {@code Module}. * Leading and trailing whitespaces will be trimmed. * - * @throws ParseException if the given {@code email} is invalid. + * @throws ParseException if the given {@code module} is invalid. */ - public static Email parseEmail(String email) throws ParseException { - requireNonNull(email); - String trimmedEmail = email.trim(); - if (!Email.isValidEmail(trimmedEmail)) { - throw new ParseException(Email.MESSAGE_CONSTRAINTS); + public static Module parseModule(String module) throws ParseException { + requireNonNull(module); + String trimmedModule = module.trim(); + if (!Module.isValidModule(trimmedModule)) { + throw new ParseException(Module.MESSAGE_CONSTRAINTS); } - return new Email(trimmedEmail); + return new Module(trimmedModule); } /** diff --git a/src/main/java/staffconnect/model/person/Name.java b/src/main/java/staffconnect/model/person/Name.java index e1d9e927aa3..538b1e28e78 100644 --- a/src/main/java/staffconnect/model/person/Name.java +++ b/src/main/java/staffconnect/model/person/Name.java @@ -13,7 +13,7 @@ public class Name { "Names should only contain alphanumeric characters and spaces, and it should not be blank"; /* - * The first character of the address must not be a whitespace, + * The first character of the name must not be a whitespace, * otherwise " " (a blank string) becomes a valid input. */ public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; diff --git a/src/main/java/staffconnect/model/person/Person.java b/src/main/java/staffconnect/model/person/Person.java index 58424f05908..5c10209078e 100644 --- a/src/main/java/staffconnect/model/person/Person.java +++ b/src/main/java/staffconnect/model/person/Person.java @@ -23,17 +23,19 @@ public class Person { // Data fields private final Venue venue; + private final Module module; private final Set<Tag> tags = new HashSet<>(); /** * Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Venue venue, Set<Tag> tags) { - requireAllNonNull(name, phone, email, venue, tags); + public Person(Name name, Phone phone, Email email, Venue venue, Module module, Set<Tag> tags) { + requireAllNonNull(name, phone, email, venue, module, tags); this.name = name; this.phone = phone; this.email = email; this.venue = venue; + this.module = module; this.tags.addAll(tags); } @@ -53,6 +55,10 @@ public Venue getVenue() { return venue; } + public Module getModule() { + return module; + } + /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. @@ -94,13 +100,14 @@ public boolean equals(Object other) { && phone.equals(otherPerson.phone) && email.equals(otherPerson.email) && venue.equals(otherPerson.venue) + && module.equals(otherPerson.module) && tags.equals(otherPerson.tags); } @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, venue, tags); + return Objects.hash(name, phone, email, venue, module, tags); } @Override @@ -110,6 +117,7 @@ public String toString() { .add("phone", phone) .add("email", email) .add("venue", venue) + .add("module", module) .add("tags", tags) .toString(); } diff --git a/src/main/java/staffconnect/model/util/SampleDataUtil.java b/src/main/java/staffconnect/model/util/SampleDataUtil.java index b9704a48308..1befd734f31 100644 --- a/src/main/java/staffconnect/model/util/SampleDataUtil.java +++ b/src/main/java/staffconnect/model/util/SampleDataUtil.java @@ -7,6 +7,7 @@ import staffconnect.model.ReadOnlyStaffBook; import staffconnect.model.StaffBook; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; import staffconnect.model.person.Phone; @@ -20,23 +21,23 @@ public class SampleDataUtil { public static Person[] getSamplePersons() { return new Person[] { new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), - new Venue("Blk 30 Geylang Street 29, #06-40"), - getTagSet("friends")), + new Venue("Blk 30 Geylang Street 29, #06-40"), new Module("CS1101S"), + getTagSet("professor")), new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), - new Venue("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), - getTagSet("colleagues", "friends")), + new Venue("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), new Module("CS1231S"), + getTagSet("tutor", "friends")), new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), - new Venue("Blk 11 Ang Mo Kio Street 74, #11-04"), - getTagSet("neighbours")), + new Venue("Blk 11 Ang Mo Kio Street 74, #11-04"), new Module("CS2030S"), + getTagSet("professor")), new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), - new Venue("Blk 436 Serangoon Gardens Street 26, #16-43"), - getTagSet("family")), + new Venue("Blk 436 Serangoon Gardens Street 26, #16-43"), new Module("CS2040S"), + getTagSet("professor")), new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), - new Venue("Blk 47 Tampines Street 20, #17-35"), - getTagSet("classmates")), + new Venue("Blk 47 Tampines Street 20, #17-35"), new Module("CS2100"), + getTagSet("tutor")), new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), - new Venue("Blk 45 Aljunied Street 85, #11-31"), - getTagSet("colleagues")) + new Venue("Blk 45 Aljunied Street 85, #11-31"), new Module("CS2101"), + getTagSet("professor")) }; } diff --git a/src/main/java/staffconnect/storage/JsonAdaptedPerson.java b/src/main/java/staffconnect/storage/JsonAdaptedPerson.java index dd5958ff973..600299c7a12 100644 --- a/src/main/java/staffconnect/storage/JsonAdaptedPerson.java +++ b/src/main/java/staffconnect/storage/JsonAdaptedPerson.java @@ -11,6 +11,7 @@ import staffconnect.commons.exceptions.IllegalValueException; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; import staffconnect.model.person.Phone; @@ -28,6 +29,7 @@ class JsonAdaptedPerson { private final String phone; private final String email; private final String venue; + private final String module; private final List<JsonAdaptedTag> tags = new ArrayList<>(); /** @@ -36,11 +38,12 @@ class JsonAdaptedPerson { @JsonCreator public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("venue") String venue, - @JsonProperty("tags") List<JsonAdaptedTag> tags) { + @JsonProperty("module") String module, @JsonProperty("tags") List<JsonAdaptedTag> tags) { this.name = name; this.phone = phone; this.email = email; this.venue = venue; + this.module = module; if (tags != null) { this.tags.addAll(tags); } @@ -54,6 +57,7 @@ public JsonAdaptedPerson(Person source) { phone = source.getPhone().value; email = source.getEmail().value; venue = source.getVenue().value; + module = source.getModule().value; tags.addAll(source.getTags().stream() .map(JsonAdaptedTag::new) .collect(Collectors.toList())); @@ -102,8 +106,16 @@ public Person toModelType() throws IllegalValueException { } final Venue modelVenue = new Venue(venue); + if (module == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Module.class.getSimpleName())); + } + if (!Module.isValidModule(module)) { + throw new IllegalValueException(Module.MESSAGE_CONSTRAINTS); + } + final Module modelModule = new Module(module); + final Set<Tag> modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelVenue, modelTags); + return new Person(modelName, modelPhone, modelEmail, modelVenue, modelModule, modelTags); } } diff --git a/src/main/java/staffconnect/ui/PersonCard.java b/src/main/java/staffconnect/ui/PersonCard.java index 0abadaa1092..f93f79e7476 100644 --- a/src/main/java/staffconnect/ui/PersonCard.java +++ b/src/main/java/staffconnect/ui/PersonCard.java @@ -37,6 +37,8 @@ public class PersonCard extends UiPart<Region> { @FXML private Label venue; @FXML + private Label module; + @FXML private Label email; @FXML private FlowPane tags; @@ -51,6 +53,7 @@ public PersonCard(Person person, int displayedIndex) { name.setText(person.getName().fullName); phone.setText(person.getPhone().value); venue.setText(person.getVenue().value); + module.setText(person.getModule().value); email.setText(person.getEmail().value); person.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml index 7778f666a0a..bdfd006114b 100644 --- a/src/main/resources/view/MainWindow.fxml +++ b/src/main/resources/view/MainWindow.fxml @@ -12,7 +12,7 @@ <?import javafx.scene.layout.VBox?> <fx:root type="javafx.stage.Stage" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" - title="Address App" minWidth="450" minHeight="600" onCloseRequest="#handleExit"> + title="StaffConnect App" minWidth="450" minHeight="600" onCloseRequest="#handleExit"> <icons> <Image url="@/images/address_book_32.png" /> </icons> diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index c75735e6b23..2101c6c5ed9 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -30,6 +30,7 @@ <FlowPane fx:id="tags" /> <Label fx:id="phone" styleClass="cell_small_label" text="\$phone" /> <Label fx:id="venue" styleClass="cell_small_label" text="\$venue" /> + <Label fx:id="module" styleClass="cell_small_label" text="\$module" /> <Label fx:id="email" styleClass="cell_small_label" text="\$email" /> </VBox> </GridPane> diff --git a/src/test/data/JsonSerializableStaffBookTest/duplicatePersonStaffBook.json b/src/test/data/JsonSerializableStaffBookTest/duplicatePersonStaffBook.json index 4fb3e28db98..952b4bd598b 100644 --- a/src/test/data/JsonSerializableStaffBookTest/duplicatePersonStaffBook.json +++ b/src/test/data/JsonSerializableStaffBookTest/duplicatePersonStaffBook.json @@ -4,11 +4,13 @@ "phone": "94351253", "email": "alice@example.com", "venue": "123, Jurong West Ave 6, #08-111", + "module": "CS1101S", "tags": [ "friends" ] }, { "name": "Alice Pauline", "phone": "94351253", "email": "pauline@example.com", - "venue": "4th street" + "venue": "4th street", + "module": "CS1231S" } ] } diff --git a/src/test/data/JsonSerializableStaffBookTest/invalidPersonStaffBook.json b/src/test/data/JsonSerializableStaffBookTest/invalidPersonStaffBook.json index 084ec4b3c5f..f46f149ffd8 100644 --- a/src/test/data/JsonSerializableStaffBookTest/invalidPersonStaffBook.json +++ b/src/test/data/JsonSerializableStaffBookTest/invalidPersonStaffBook.json @@ -3,6 +3,7 @@ "name": "Hans Muster", "phone": "9482424", "email": "invalid@email!3e", - "venue": "4th street" + "venue": "4th street", + "module": "CS2030S" } ] } diff --git a/src/test/data/JsonSerializableStaffBookTest/typicalPersonsStaffBook.json b/src/test/data/JsonSerializableStaffBookTest/typicalPersonsStaffBook.json index 6085e355057..4c7a7b4ba6d 100644 --- a/src/test/data/JsonSerializableStaffBookTest/typicalPersonsStaffBook.json +++ b/src/test/data/JsonSerializableStaffBookTest/typicalPersonsStaffBook.json @@ -1,46 +1,53 @@ { - "_comment": "AddressBook save file which contains the same Person values as in TypicalPersons#getTypicalAddressBook()", + "_comment": "StaffConnect save file which contains the same Person values as in TypicalPersons#getTypicalStaffBook()", "persons" : [ { "name" : "Alice Pauline", "phone" : "94351253", "email" : "alice@example.com", "venue" : "123, Jurong West Ave 6, #08-111", + "module": "CS1101S", "tags" : [ "friends" ] }, { "name" : "Benson Meier", "phone" : "98765432", "email" : "johnd@example.com", "venue" : "311, Clementi Ave 2, #02-25", + "module": "CS1231S", "tags" : [ "owesMoney", "friends" ] }, { "name" : "Carl Kurz", "phone" : "95352563", "email" : "heinz@example.com", "venue" : "wall street", + "module": "CS2030S", "tags" : [ ] }, { "name" : "Daniel Meier", "phone" : "87652533", "email" : "cornelia@example.com", "venue" : "10th street", + "module": "CS2040S", "tags" : [ "friends" ] }, { "name" : "Elle Meyer", "phone" : "9482224", "email" : "werner@example.com", "venue" : "michegan ave", + "module": "CS2100", "tags" : [ ] }, { "name" : "Fiona Kunz", "phone" : "9482427", "email" : "lydia@example.com", "venue" : "little tokyo", + "module": "CS2101", "tags" : [ ] }, { "name" : "George Best", "phone" : "9482442", "email" : "anna@example.com", "venue" : "4th street", + "module": "CS2102", "tags" : [ ] } ] } diff --git a/src/test/data/JsonStaffBookStorageTest/invalidAndValidPersonStaffBook.json b/src/test/data/JsonStaffBookStorageTest/invalidAndValidPersonStaffBook.json index 3498507e711..2b4b77d5195 100644 --- a/src/test/data/JsonStaffBookStorageTest/invalidAndValidPersonStaffBook.json +++ b/src/test/data/JsonStaffBookStorageTest/invalidAndValidPersonStaffBook.json @@ -3,11 +3,13 @@ "name": "Valid Person", "phone": "9482424", "email": "hans@example.com", - "venue": "4th street" + "venue": "4th street", + "module": "CS1101S" }, { "name": "Person With Invalid Phone Field", "phone": "948asdf2424", "email": "hans@example.com", - "venue": "4th street" + "venue": "4th street", + "module": "CS1101S" } ] } diff --git a/src/test/data/JsonStaffBookStorageTest/invalidPersonStaffBook.json b/src/test/data/JsonStaffBookStorageTest/invalidPersonStaffBook.json index 46fdc860308..b04b9e663aa 100644 --- a/src/test/data/JsonStaffBookStorageTest/invalidPersonStaffBook.json +++ b/src/test/data/JsonStaffBookStorageTest/invalidPersonStaffBook.json @@ -3,6 +3,7 @@ "name": "Person with invalid name field: Ha!ns Mu@ster", "phone": "9482424", "email": "hans@example.com", - "venue": "4th street" + "venue": "4th street", + "module": "CS1101S" } ] } diff --git a/src/test/java/staffconnect/logic/LogicManagerTest.java b/src/test/java/staffconnect/logic/LogicManagerTest.java index f77a2001d48..1e912b65c6c 100644 --- a/src/test/java/staffconnect/logic/LogicManagerTest.java +++ b/src/test/java/staffconnect/logic/LogicManagerTest.java @@ -4,6 +4,7 @@ import static staffconnect.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; import static staffconnect.logic.Messages.MESSAGE_UNKNOWN_COMMAND; import static staffconnect.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; +import static staffconnect.logic.commands.CommandTestUtil.MODULE_DESC_AMY; import static staffconnect.logic.commands.CommandTestUtil.NAME_DESC_AMY; import static staffconnect.logic.commands.CommandTestUtil.PHONE_DESC_AMY; import static staffconnect.logic.commands.CommandTestUtil.VENUE_DESC_AMY; @@ -166,7 +167,7 @@ public void saveStaffBook(ReadOnlyStaffBook staffBook, Path filePath) // Triggers the saveStaffBook method by executing an add command String addCommand = AddCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY - + EMAIL_DESC_AMY + VENUE_DESC_AMY; + + EMAIL_DESC_AMY + VENUE_DESC_AMY + MODULE_DESC_AMY; Person expectedPerson = new PersonBuilder(AMY).withTags().build(); ModelManager expectedModel = new ModelManager(); expectedModel.addPerson(expectedPerson); diff --git a/src/test/java/staffconnect/logic/commands/CommandTestUtil.java b/src/test/java/staffconnect/logic/commands/CommandTestUtil.java index 03138de5717..61b8216c5d8 100644 --- a/src/test/java/staffconnect/logic/commands/CommandTestUtil.java +++ b/src/test/java/staffconnect/logic/commands/CommandTestUtil.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static staffconnect.logic.parser.CliSyntax.PREFIX_EMAIL; +import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; import static staffconnect.logic.parser.CliSyntax.PREFIX_TAG; @@ -32,10 +33,12 @@ public class CommandTestUtil { public static final String VALID_PHONE_BOB = "22222222"; public static final String VALID_EMAIL_AMY = "amy@example.com"; public static final String VALID_EMAIL_BOB = "bob@example.com"; - public static final String VALID_TAG_HUSBAND = "husband"; - public static final String VALID_TAG_FRIEND = "friend"; public static final String VALID_VENUE_AMY = "Block 312, Amy Street 1"; public static final String VALID_VENUE_BOB = "Block 123, Bobby Street 3"; + public static final String VALID_MODULE_AMY = "CS2103"; + public static final String VALID_MODULE_BOB = "CS2103T"; + public static final String VALID_TAG_HUSBAND = "husband"; + public static final String VALID_TAG_FRIEND = "friend"; public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY; public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB; @@ -43,16 +46,19 @@ public class CommandTestUtil { public static final String PHONE_DESC_BOB = " " + PREFIX_PHONE + VALID_PHONE_BOB; public static final String EMAIL_DESC_AMY = " " + PREFIX_EMAIL + VALID_EMAIL_AMY; public static final String EMAIL_DESC_BOB = " " + PREFIX_EMAIL + VALID_EMAIL_BOB; - public static final String TAG_DESC_FRIEND = " " + PREFIX_TAG + VALID_TAG_FRIEND; - public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND; public static final String VENUE_DESC_AMY = " " + PREFIX_VENUE + VALID_VENUE_AMY; public static final String VENUE_DESC_BOB = " " + PREFIX_VENUE + VALID_VENUE_BOB; + public static final String MODULE_DESC_AMY = " " + PREFIX_MODULE + VALID_MODULE_AMY; + public static final String MODULE_DESC_BOB = " " + PREFIX_MODULE + VALID_MODULE_BOB; + public static final String TAG_DESC_FRIEND = " " + PREFIX_TAG + VALID_TAG_FRIEND; + public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND; 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 public static final String INVALID_EMAIL_DESC = " " + PREFIX_EMAIL + "bob!yahoo"; // missing '@' symbol - public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags public static final String INVALID_VENUE_DESC = " " + PREFIX_VENUE; // empty string not allowed for venues + public static final String INVALID_MODULE_DESC = " " + PREFIX_MODULE; // empty string not allowed for modules + public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags public static final String PREAMBLE_WHITESPACE = "\t \r \n"; public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble"; @@ -63,10 +69,10 @@ public class CommandTestUtil { static { DESC_AMY = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY) .withPhone(VALID_PHONE_AMY).withEmail(VALID_EMAIL_AMY).withVenue(VALID_VENUE_AMY) - .withTags(VALID_TAG_FRIEND).build(); + .withModule(VALID_MODULE_AMY).withTags(VALID_TAG_FRIEND).build(); DESC_BOB = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB) .withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB).withVenue(VALID_VENUE_BOB) - .withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build(); + .withModule(VALID_MODULE_BOB).withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build(); } /** diff --git a/src/test/java/staffconnect/logic/commands/DeleteCommandTest.java b/src/test/java/staffconnect/logic/commands/DeleteCommandTest.java index b53dd325fe6..6e197426d4e 100644 --- a/src/test/java/staffconnect/logic/commands/DeleteCommandTest.java +++ b/src/test/java/staffconnect/logic/commands/DeleteCommandTest.java @@ -71,7 +71,7 @@ public void execute_invalidIndexFilteredList_throwsCommandException() { showPersonAtIndex(model, INDEX_FIRST_PERSON); Index outOfBoundIndex = INDEX_SECOND_PERSON; - // ensures that outOfBoundIndex is still in bounds of address book list + // ensures that outOfBoundIndex is still in bounds of staff book list assertTrue(outOfBoundIndex.getZeroBased() < model.getStaffBook().getPersonList().size()); DeleteCommand deleteCommand = new DeleteCommand(outOfBoundIndex); diff --git a/src/test/java/staffconnect/logic/commands/EditPersonDescriptorTest.java b/src/test/java/staffconnect/logic/commands/EditPersonDescriptorTest.java index 640ef2dfa0b..6e780888358 100644 --- a/src/test/java/staffconnect/logic/commands/EditPersonDescriptorTest.java +++ b/src/test/java/staffconnect/logic/commands/EditPersonDescriptorTest.java @@ -6,6 +6,7 @@ import static staffconnect.logic.commands.CommandTestUtil.DESC_AMY; import static staffconnect.logic.commands.CommandTestUtil.DESC_BOB; import static staffconnect.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static staffconnect.logic.commands.CommandTestUtil.VALID_MODULE_BOB; import static staffconnect.logic.commands.CommandTestUtil.VALID_NAME_BOB; import static staffconnect.logic.commands.CommandTestUtil.VALID_PHONE_BOB; import static staffconnect.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; @@ -52,6 +53,10 @@ public void equals() { editedAmy = new EditPersonDescriptorBuilder(DESC_AMY).withVenue(VALID_VENUE_BOB).build(); assertFalse(DESC_AMY.equals(editedAmy)); + // different module -> returns false + editedAmy = new EditPersonDescriptorBuilder(DESC_AMY).withModule(VALID_MODULE_BOB).build(); + assertFalse(DESC_AMY.equals(editedAmy)); + // different tags -> returns false editedAmy = new EditPersonDescriptorBuilder(DESC_AMY).withTags(VALID_TAG_HUSBAND).build(); assertFalse(DESC_AMY.equals(editedAmy)); @@ -64,7 +69,8 @@ public void toStringMethod() { + editPersonDescriptor.getName().orElse(null) + ", phone=" + editPersonDescriptor.getPhone().orElse(null) + ", email=" + editPersonDescriptor.getEmail().orElse(null) + ", venue=" - + editPersonDescriptor.getVenue().orElse(null) + ", tags=" + + editPersonDescriptor.getVenue().orElse(null) + ", module=" + + editPersonDescriptor.getModule().orElse(null) + ", tags=" + editPersonDescriptor.getTags().orElse(null) + "}"; assertEquals(expected, editPersonDescriptor.toString()); } diff --git a/src/test/java/staffconnect/logic/parser/AddCommandParserTest.java b/src/test/java/staffconnect/logic/parser/AddCommandParserTest.java index 953c812fb9f..fd9038a98b9 100644 --- a/src/test/java/staffconnect/logic/parser/AddCommandParserTest.java +++ b/src/test/java/staffconnect/logic/parser/AddCommandParserTest.java @@ -4,10 +4,13 @@ import static staffconnect.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; import static staffconnect.logic.commands.CommandTestUtil.EMAIL_DESC_BOB; import static staffconnect.logic.commands.CommandTestUtil.INVALID_EMAIL_DESC; +import static staffconnect.logic.commands.CommandTestUtil.INVALID_MODULE_DESC; import static staffconnect.logic.commands.CommandTestUtil.INVALID_NAME_DESC; import static staffconnect.logic.commands.CommandTestUtil.INVALID_PHONE_DESC; import static staffconnect.logic.commands.CommandTestUtil.INVALID_TAG_DESC; import static staffconnect.logic.commands.CommandTestUtil.INVALID_VENUE_DESC; +import static staffconnect.logic.commands.CommandTestUtil.MODULE_DESC_AMY; +import static staffconnect.logic.commands.CommandTestUtil.MODULE_DESC_BOB; import static staffconnect.logic.commands.CommandTestUtil.NAME_DESC_AMY; import static staffconnect.logic.commands.CommandTestUtil.NAME_DESC_BOB; import static staffconnect.logic.commands.CommandTestUtil.PHONE_DESC_AMY; @@ -17,6 +20,7 @@ import static staffconnect.logic.commands.CommandTestUtil.TAG_DESC_FRIEND; import static staffconnect.logic.commands.CommandTestUtil.TAG_DESC_HUSBAND; import static staffconnect.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static staffconnect.logic.commands.CommandTestUtil.VALID_MODULE_BOB; import static staffconnect.logic.commands.CommandTestUtil.VALID_NAME_BOB; import static staffconnect.logic.commands.CommandTestUtil.VALID_PHONE_BOB; import static staffconnect.logic.commands.CommandTestUtil.VALID_TAG_FRIEND; @@ -25,6 +29,7 @@ import static staffconnect.logic.commands.CommandTestUtil.VENUE_DESC_AMY; import static staffconnect.logic.commands.CommandTestUtil.VENUE_DESC_BOB; import static staffconnect.logic.parser.CliSyntax.PREFIX_EMAIL; +import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; import static staffconnect.logic.parser.CliSyntax.PREFIX_VENUE; @@ -38,6 +43,7 @@ import staffconnect.logic.Messages; import staffconnect.logic.commands.AddCommand; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; import staffconnect.model.person.Phone; @@ -54,20 +60,21 @@ public void parse_allFieldsPresent_success() { // whitespace only preamble assertParseSuccess(parser, PREAMBLE_WHITESPACE + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB - + VENUE_DESC_BOB + TAG_DESC_FRIEND, new AddCommand(expectedPerson)); + + VENUE_DESC_BOB + MODULE_DESC_BOB + TAG_DESC_FRIEND, new AddCommand(expectedPerson)); // multiple tags - all accepted Person expectedPersonMultipleTags = new PersonBuilder(BOB).withTags(VALID_TAG_FRIEND, VALID_TAG_HUSBAND) .build(); assertParseSuccess(parser, - NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + VENUE_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + VENUE_DESC_BOB + + MODULE_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, new AddCommand(expectedPersonMultipleTags)); } @Test public void parse_repeatedNonTagValue_failure() { String validExpectedPersonString = NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB - + VENUE_DESC_BOB + TAG_DESC_FRIEND; + + VENUE_DESC_BOB + MODULE_DESC_BOB + TAG_DESC_FRIEND; // multiple names assertParseFailure(parser, NAME_DESC_AMY + validExpectedPersonString, @@ -85,11 +92,16 @@ public void parse_repeatedNonTagValue_failure() { assertParseFailure(parser, VENUE_DESC_AMY + validExpectedPersonString, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_VENUE)); + // multiple modules + assertParseFailure(parser, MODULE_DESC_AMY + validExpectedPersonString, + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_MODULE)); + // multiple fields repeated assertParseFailure(parser, - validExpectedPersonString + PHONE_DESC_AMY + EMAIL_DESC_AMY + NAME_DESC_AMY + VENUE_DESC_AMY - + validExpectedPersonString, - Messages.getErrorMessageForDuplicatePrefixes(PREFIX_NAME, PREFIX_VENUE, PREFIX_EMAIL, PREFIX_PHONE)); + validExpectedPersonString + PHONE_DESC_AMY + EMAIL_DESC_AMY + NAME_DESC_AMY + + VENUE_DESC_AMY + MODULE_DESC_AMY + validExpectedPersonString, + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_NAME, PREFIX_VENUE, + PREFIX_EMAIL, PREFIX_PHONE, PREFIX_MODULE)); // invalid value followed by valid value @@ -109,6 +121,10 @@ public void parse_repeatedNonTagValue_failure() { assertParseFailure(parser, INVALID_VENUE_DESC + validExpectedPersonString, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_VENUE)); + // invalid module + assertParseFailure(parser, INVALID_MODULE_DESC + validExpectedPersonString, + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_MODULE)); + // valid value followed by invalid value // invalid name @@ -126,13 +142,17 @@ public void parse_repeatedNonTagValue_failure() { // invalid venue assertParseFailure(parser, validExpectedPersonString + INVALID_VENUE_DESC, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_VENUE)); + + // invalid module + assertParseFailure(parser, validExpectedPersonString + INVALID_MODULE_DESC, + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_MODULE)); } @Test public void parse_optionalFieldsMissing_success() { // zero tags Person expectedPerson = new PersonBuilder(AMY).withTags().build(); - assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + VENUE_DESC_AMY, + assertParseSuccess(parser, NAME_DESC_AMY + PHONE_DESC_AMY + EMAIL_DESC_AMY + VENUE_DESC_AMY + MODULE_DESC_AMY, new AddCommand(expectedPerson)); } @@ -141,55 +161,76 @@ public void parse_compulsoryFieldMissing_failure() { String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE); // missing name prefix - assertParseFailure(parser, VALID_NAME_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + VENUE_DESC_BOB, + assertParseFailure(parser, VALID_NAME_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + + VENUE_DESC_BOB + MODULE_DESC_BOB, expectedMessage); // missing phone prefix - assertParseFailure(parser, NAME_DESC_BOB + VALID_PHONE_BOB + EMAIL_DESC_BOB + VENUE_DESC_BOB, + assertParseFailure(parser, NAME_DESC_BOB + VALID_PHONE_BOB + EMAIL_DESC_BOB + + VENUE_DESC_BOB + MODULE_DESC_BOB, expectedMessage); // missing email prefix - assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + VALID_EMAIL_BOB + VENUE_DESC_BOB, + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + VALID_EMAIL_BOB + + VENUE_DESC_BOB + MODULE_DESC_BOB, expectedMessage); // missing venue prefix - assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + VALID_VENUE_BOB, + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + + VALID_VENUE_BOB + MODULE_DESC_BOB, + expectedMessage); + + // missing module prefix + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + + VALID_VENUE_BOB + VALID_MODULE_BOB, expectedMessage); // all prefixes missing - assertParseFailure(parser, VALID_NAME_BOB + VALID_PHONE_BOB + VALID_EMAIL_BOB + VALID_VENUE_BOB, + assertParseFailure(parser, VALID_NAME_BOB + VALID_PHONE_BOB + VALID_EMAIL_BOB + + VALID_VENUE_BOB + VALID_MODULE_BOB, expectedMessage); } @Test public void parse_invalidValue_failure() { // invalid name - assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + VENUE_DESC_BOB - + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Name.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + + VENUE_DESC_BOB + MODULE_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, + Name.MESSAGE_CONSTRAINTS); // invalid phone - assertParseFailure(parser, NAME_DESC_BOB + INVALID_PHONE_DESC + EMAIL_DESC_BOB + VENUE_DESC_BOB - + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Phone.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, NAME_DESC_BOB + INVALID_PHONE_DESC + EMAIL_DESC_BOB + + VENUE_DESC_BOB + MODULE_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, + Phone.MESSAGE_CONSTRAINTS); // invalid email - assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + INVALID_EMAIL_DESC + VENUE_DESC_BOB - + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Email.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + INVALID_EMAIL_DESC + + VENUE_DESC_BOB + MODULE_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, + Email.MESSAGE_CONSTRAINTS); // invalid venue - assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_VENUE_DESC - + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Venue.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + + INVALID_VENUE_DESC + MODULE_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, + Venue.MESSAGE_CONSTRAINTS); + + // invalid module + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + + VENUE_DESC_BOB + INVALID_MODULE_DESC + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, + Module.MESSAGE_CONSTRAINTS); // invalid tag - assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + VENUE_DESC_BOB - + INVALID_TAG_DESC + VALID_TAG_FRIEND, Tag.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + + VENUE_DESC_BOB + MODULE_DESC_BOB + INVALID_TAG_DESC + VALID_TAG_FRIEND, + Tag.MESSAGE_CONSTRAINTS); // two invalid values, only first invalid value reported - assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_VENUE_DESC, + assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + + INVALID_VENUE_DESC + MODULE_DESC_BOB, Name.MESSAGE_CONSTRAINTS); // non-empty preamble assertParseFailure(parser, PREAMBLE_NON_EMPTY + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB - + VENUE_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, + + VENUE_DESC_BOB + MODULE_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } } diff --git a/src/test/java/staffconnect/logic/parser/EditCommandParserTest.java b/src/test/java/staffconnect/logic/parser/EditCommandParserTest.java index b402c6d986e..2e4eeb4aa61 100644 --- a/src/test/java/staffconnect/logic/parser/EditCommandParserTest.java +++ b/src/test/java/staffconnect/logic/parser/EditCommandParserTest.java @@ -4,16 +4,20 @@ import static staffconnect.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; import static staffconnect.logic.commands.CommandTestUtil.EMAIL_DESC_BOB; import static staffconnect.logic.commands.CommandTestUtil.INVALID_EMAIL_DESC; +import static staffconnect.logic.commands.CommandTestUtil.INVALID_MODULE_DESC; import static staffconnect.logic.commands.CommandTestUtil.INVALID_NAME_DESC; import static staffconnect.logic.commands.CommandTestUtil.INVALID_PHONE_DESC; import static staffconnect.logic.commands.CommandTestUtil.INVALID_TAG_DESC; import static staffconnect.logic.commands.CommandTestUtil.INVALID_VENUE_DESC; +import static staffconnect.logic.commands.CommandTestUtil.MODULE_DESC_AMY; +import static staffconnect.logic.commands.CommandTestUtil.MODULE_DESC_BOB; import static staffconnect.logic.commands.CommandTestUtil.NAME_DESC_AMY; import static staffconnect.logic.commands.CommandTestUtil.PHONE_DESC_AMY; import static staffconnect.logic.commands.CommandTestUtil.PHONE_DESC_BOB; import static staffconnect.logic.commands.CommandTestUtil.TAG_DESC_FRIEND; import static staffconnect.logic.commands.CommandTestUtil.TAG_DESC_HUSBAND; import static staffconnect.logic.commands.CommandTestUtil.VALID_EMAIL_AMY; +import static staffconnect.logic.commands.CommandTestUtil.VALID_MODULE_AMY; import static staffconnect.logic.commands.CommandTestUtil.VALID_NAME_AMY; import static staffconnect.logic.commands.CommandTestUtil.VALID_PHONE_AMY; import static staffconnect.logic.commands.CommandTestUtil.VALID_PHONE_BOB; @@ -23,6 +27,7 @@ import static staffconnect.logic.commands.CommandTestUtil.VENUE_DESC_AMY; import static staffconnect.logic.commands.CommandTestUtil.VENUE_DESC_BOB; import static staffconnect.logic.parser.CliSyntax.PREFIX_EMAIL; +import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; import static staffconnect.logic.parser.CliSyntax.PREFIX_TAG; import static staffconnect.logic.parser.CliSyntax.PREFIX_VENUE; @@ -39,6 +44,7 @@ import staffconnect.logic.commands.EditCommand; import staffconnect.logic.commands.EditCommand.EditPersonDescriptor; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Phone; import staffconnect.model.person.Venue; @@ -87,6 +93,7 @@ public void parse_invalidValue_failure() { assertParseFailure(parser, "1" + INVALID_PHONE_DESC, Phone.MESSAGE_CONSTRAINTS); // invalid phone assertParseFailure(parser, "1" + INVALID_EMAIL_DESC, Email.MESSAGE_CONSTRAINTS); // invalid email assertParseFailure(parser, "1" + INVALID_VENUE_DESC, Venue.MESSAGE_CONSTRAINTS); // invalid venue + assertParseFailure(parser, "1" + INVALID_MODULE_DESC, Module.MESSAGE_CONSTRAINTS); // invalid module assertParseFailure(parser, "1" + INVALID_TAG_DESC, Tag.MESSAGE_CONSTRAINTS); // invalid tag // invalid phone followed by valid email @@ -99,7 +106,8 @@ public void parse_invalidValue_failure() { assertParseFailure(parser, "1" + TAG_EMPTY + TAG_DESC_FRIEND + TAG_DESC_HUSBAND, Tag.MESSAGE_CONSTRAINTS); // multiple invalid values, but only the first invalid value is captured - assertParseFailure(parser, "1" + INVALID_NAME_DESC + INVALID_EMAIL_DESC + VALID_VENUE_AMY + VALID_PHONE_AMY, + assertParseFailure(parser, "1" + INVALID_NAME_DESC + INVALID_EMAIL_DESC + + VALID_VENUE_AMY + VALID_PHONE_AMY + VALID_MODULE_AMY, Name.MESSAGE_CONSTRAINTS); } @@ -107,11 +115,11 @@ public void parse_invalidValue_failure() { public void parse_allFieldsSpecified_success() { Index targetIndex = INDEX_SECOND_PERSON; String userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + TAG_DESC_HUSBAND - + EMAIL_DESC_AMY + VENUE_DESC_AMY + NAME_DESC_AMY + TAG_DESC_FRIEND; + + EMAIL_DESC_AMY + VENUE_DESC_AMY + NAME_DESC_AMY + MODULE_DESC_AMY + TAG_DESC_FRIEND; EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY) .withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_AMY).withVenue(VALID_VENUE_AMY) - .withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build(); + .withModule(VALID_MODULE_AMY).withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build(); EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); @@ -156,6 +164,12 @@ public void parse_oneFieldSpecified_success() { expectedCommand = new EditCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); + // module + userInput = targetIndex.getOneBased() + MODULE_DESC_AMY; + descriptor = new EditPersonDescriptorBuilder().withModule(VALID_MODULE_AMY).build(); + expectedCommand = new EditCommand(targetIndex, descriptor); + assertParseSuccess(parser, userInput, expectedCommand); + // tags userInput = targetIndex.getOneBased() + TAG_DESC_FRIEND; descriptor = new EditPersonDescriptorBuilder().withTags(VALID_TAG_FRIEND).build(); @@ -181,18 +195,22 @@ public void parse_multipleRepeatedFields_failure() { // mulltiple valid fields repeated userInput = targetIndex.getOneBased() + PHONE_DESC_AMY + VENUE_DESC_AMY + EMAIL_DESC_AMY - + TAG_DESC_FRIEND + PHONE_DESC_AMY + VENUE_DESC_AMY + EMAIL_DESC_AMY + TAG_DESC_FRIEND - + PHONE_DESC_BOB + VENUE_DESC_BOB + EMAIL_DESC_BOB + TAG_DESC_HUSBAND; + + MODULE_DESC_AMY + TAG_DESC_FRIEND + PHONE_DESC_AMY + VENUE_DESC_AMY + + EMAIL_DESC_AMY + MODULE_DESC_AMY + TAG_DESC_FRIEND + PHONE_DESC_BOB + + VENUE_DESC_BOB + EMAIL_DESC_BOB + MODULE_DESC_BOB + TAG_DESC_HUSBAND; assertParseFailure(parser, userInput, - Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VENUE)); + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_VENUE, PREFIX_MODULE)); // multiple invalid values - userInput = targetIndex.getOneBased() + INVALID_PHONE_DESC + INVALID_VENUE_DESC + INVALID_EMAIL_DESC - + INVALID_PHONE_DESC + INVALID_VENUE_DESC + INVALID_EMAIL_DESC; + userInput = targetIndex.getOneBased() + INVALID_PHONE_DESC + INVALID_VENUE_DESC + + INVALID_EMAIL_DESC + INVALID_MODULE_DESC + INVALID_PHONE_DESC + INVALID_VENUE_DESC + + INVALID_EMAIL_DESC + INVALID_MODULE_DESC; assertParseFailure(parser, userInput, - Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VENUE)); + Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_VENUE, PREFIX_MODULE)); } @Test diff --git a/src/test/java/staffconnect/logic/parser/ParserUtilTest.java b/src/test/java/staffconnect/logic/parser/ParserUtilTest.java index 752e0989e58..046b3578d83 100644 --- a/src/test/java/staffconnect/logic/parser/ParserUtilTest.java +++ b/src/test/java/staffconnect/logic/parser/ParserUtilTest.java @@ -15,6 +15,7 @@ import staffconnect.logic.parser.exceptions.ParseException; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Phone; import staffconnect.model.person.Venue; @@ -24,13 +25,15 @@ public class ParserUtilTest { private static final String INVALID_NAME = "R@chel"; private static final String INVALID_PHONE = "+651234"; private static final String INVALID_VENUE = " "; + private static final String INVALID_MODULE = " "; private static final String INVALID_EMAIL = "example.com"; private static final String INVALID_TAG = "#friend"; private static final String VALID_NAME = "Rachel Walker"; private static final String VALID_PHONE = "123456"; - private static final String VALID_VENUE = "123 Main Street #0505"; private static final String VALID_EMAIL = "rachel@example.com"; + private static final String VALID_VENUE = "123 Main Street #0505"; + private static final String VALID_MODULE = "CS2103"; private static final String VALID_TAG_1 = "friend"; private static final String VALID_TAG_2 = "neighbour"; @@ -102,6 +105,29 @@ public void parsePhone_validValueWithWhitespace_returnsTrimmedPhone() throws Exc assertEquals(expectedPhone, ParserUtil.parsePhone(phoneWithWhitespace)); } + @Test + public void parseEmail_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> ParserUtil.parseEmail((String) null)); + } + + @Test + public void parseEmail_invalidValue_throwsParseException() { + assertThrows(ParseException.class, () -> ParserUtil.parseEmail(INVALID_EMAIL)); + } + + @Test + public void parseEmail_validValueWithoutWhitespace_returnsEmail() throws Exception { + Email expectedEmail = new Email(VALID_EMAIL); + assertEquals(expectedEmail, ParserUtil.parseEmail(VALID_EMAIL)); + } + + @Test + public void parseEmail_validValueWithWhitespace_returnsTrimmedEmail() throws Exception { + String emailWithWhitespace = WHITESPACE + VALID_EMAIL + WHITESPACE; + Email expectedEmail = new Email(VALID_EMAIL); + assertEquals(expectedEmail, ParserUtil.parseEmail(emailWithWhitespace)); + } + @Test public void parseVenue_null_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> ParserUtil.parseVenue((String) null)); @@ -126,26 +152,26 @@ public void parseVenue_validValueWithWhitespace_returnsTrimmedVenue() throws Exc } @Test - public void parseEmail_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> ParserUtil.parseEmail((String) null)); + public void parseModule_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> ParserUtil.parseModule((String) null)); } @Test - public void parseEmail_invalidValue_throwsParseException() { - assertThrows(ParseException.class, () -> ParserUtil.parseEmail(INVALID_EMAIL)); + public void parseModule_invalidValue_throwsParseException() { + assertThrows(ParseException.class, () -> ParserUtil.parseModule(INVALID_MODULE)); } @Test - public void parseEmail_validValueWithoutWhitespace_returnsEmail() throws Exception { - Email expectedEmail = new Email(VALID_EMAIL); - assertEquals(expectedEmail, ParserUtil.parseEmail(VALID_EMAIL)); + public void parseModule_validValueWithoutWhitespace_returnsModule() throws Exception { + Module expectedModule = new Module(VALID_MODULE); + assertEquals(expectedModule, ParserUtil.parseModule(VALID_MODULE)); } @Test - public void parseEmail_validValueWithWhitespace_returnsTrimmedEmail() throws Exception { - String emailWithWhitespace = WHITESPACE + VALID_EMAIL + WHITESPACE; - Email expectedEmail = new Email(VALID_EMAIL); - assertEquals(expectedEmail, ParserUtil.parseEmail(emailWithWhitespace)); + public void parseModule_validValueWithWhitespace_returnsTrimmedModule() throws Exception { + String moduleWithWhitespace = WHITESPACE + VALID_MODULE + WHITESPACE; + Module expectedModule = new Module(VALID_MODULE); + assertEquals(expectedModule, ParserUtil.parseModule(moduleWithWhitespace)); } @Test diff --git a/src/test/java/staffconnect/model/UserPrefsTest.java b/src/test/java/staffconnect/model/UserPrefsTest.java index 3ddd1798433..d920756b51d 100644 --- a/src/test/java/staffconnect/model/UserPrefsTest.java +++ b/src/test/java/staffconnect/model/UserPrefsTest.java @@ -13,7 +13,7 @@ public void setGuiSettings_nullGuiSettings_throwsNullPointerException() { } @Test - public void setAddressBookFilePath_nullPath_throwsNullPointerException() { + public void setStaffConnectFilePath_nullPath_throwsNullPointerException() { UserPrefs userPrefs = new UserPrefs(); assertThrows(NullPointerException.class, () -> userPrefs.setStaffConnectFilePath(null)); } diff --git a/src/test/java/staffconnect/model/person/PersonTest.java b/src/test/java/staffconnect/model/person/PersonTest.java index e2ad32cbe86..6d195eb7e81 100644 --- a/src/test/java/staffconnect/model/person/PersonTest.java +++ b/src/test/java/staffconnect/model/person/PersonTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static staffconnect.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static staffconnect.logic.commands.CommandTestUtil.VALID_MODULE_BOB; import static staffconnect.logic.commands.CommandTestUtil.VALID_NAME_BOB; import static staffconnect.logic.commands.CommandTestUtil.VALID_PHONE_BOB; import static staffconnect.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; @@ -34,7 +35,7 @@ public void isSamePerson() { // same name, all other attributes different -> returns true Person editedAlice = new PersonBuilder(ALICE).withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB) - .withVenue(VALID_VENUE_BOB).withTags(VALID_TAG_HUSBAND).build(); + .withVenue(VALID_VENUE_BOB).withModule(VALID_MODULE_BOB).withTags(VALID_TAG_HUSBAND).build(); assertTrue(ALICE.isSamePerson(editedAlice)); // different name, all other attributes same -> returns false @@ -85,6 +86,10 @@ public void equals() { editedAlice = new PersonBuilder(ALICE).withVenue(VALID_VENUE_BOB).build(); assertFalse(ALICE.equals(editedAlice)); + // different module -> returns false + editedAlice = new PersonBuilder(ALICE).withModule(VALID_MODULE_BOB).build(); + assertFalse(ALICE.equals(editedAlice)); + // different tags -> returns false editedAlice = new PersonBuilder(ALICE).withTags(VALID_TAG_HUSBAND).build(); assertFalse(ALICE.equals(editedAlice)); @@ -93,7 +98,8 @@ public void equals() { @Test public void toStringMethod() { String expected = Person.class.getCanonicalName() + "{name=" + ALICE.getName() + ", phone=" + ALICE.getPhone() - + ", email=" + ALICE.getEmail() + ", venue=" + ALICE.getVenue() + ", tags=" + ALICE.getTags() + "}"; + + ", email=" + ALICE.getEmail() + ", venue=" + ALICE.getVenue() + ", module=" + ALICE.getModule() + + ", tags=" + ALICE.getTags() + "}"; assertEquals(expected, ALICE.toString()); } } diff --git a/src/test/java/staffconnect/storage/JsonAdaptedPersonTest.java b/src/test/java/staffconnect/storage/JsonAdaptedPersonTest.java index c9d9896ee55..27e0e4f8df8 100644 --- a/src/test/java/staffconnect/storage/JsonAdaptedPersonTest.java +++ b/src/test/java/staffconnect/storage/JsonAdaptedPersonTest.java @@ -13,6 +13,7 @@ import staffconnect.commons.exceptions.IllegalValueException; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Phone; import staffconnect.model.person.Venue; @@ -20,14 +21,16 @@ public class JsonAdaptedPersonTest { private static final String INVALID_NAME = "R@chel"; private static final String INVALID_PHONE = "+651234"; - private static final String INVALID_VENUE = " "; private static final String INVALID_EMAIL = "example.com"; + private static final String INVALID_VENUE = " "; + private static final String INVALID_MODULE = " "; private static final String INVALID_TAG = "#friend"; private static final String VALID_NAME = BENSON.getName().toString(); private static final String VALID_PHONE = BENSON.getPhone().toString(); private static final String VALID_EMAIL = BENSON.getEmail().toString(); private static final String VALID_VENUE = BENSON.getVenue().toString(); + private static final String VALID_MODULE = BENSON.getModule().toString(); private static final List<JsonAdaptedTag> VALID_TAGS = BENSON.getTags().stream() .map(JsonAdaptedTag::new) .collect(Collectors.toList()); @@ -40,70 +43,90 @@ public void toModelType_validPersonDetails_returnsPerson() throws Exception { @Test public void toModelType_invalidName_throwsIllegalValueException() { - JsonAdaptedPerson person = - new JsonAdaptedPerson(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_VENUE, VALID_TAGS); + JsonAdaptedPerson person = new JsonAdaptedPerson(INVALID_NAME, VALID_PHONE, VALID_EMAIL, + VALID_VENUE, VALID_MODULE, VALID_TAGS); String expectedMessage = Name.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @Test public void toModelType_nullName_throwsIllegalValueException() { - JsonAdaptedPerson person = new JsonAdaptedPerson(null, VALID_PHONE, VALID_EMAIL, VALID_VENUE, VALID_TAGS); + JsonAdaptedPerson person = new JsonAdaptedPerson(null, VALID_PHONE, VALID_EMAIL, + VALID_VENUE, VALID_MODULE, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @Test public void toModelType_invalidPhone_throwsIllegalValueException() { - JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_VENUE, VALID_TAGS); + JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, INVALID_PHONE, VALID_EMAIL, + VALID_VENUE, VALID_MODULE, VALID_TAGS); String expectedMessage = Phone.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @Test public void toModelType_nullPhone_throwsIllegalValueException() { - JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, null, VALID_EMAIL, VALID_VENUE, VALID_TAGS); + JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, null, VALID_EMAIL, + VALID_VENUE, VALID_MODULE, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @Test public void toModelType_invalidEmail_throwsIllegalValueException() { - JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_VENUE, VALID_TAGS); + JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, INVALID_EMAIL, + VALID_VENUE, VALID_MODULE, VALID_TAGS); String expectedMessage = Email.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @Test public void toModelType_nullEmail_throwsIllegalValueException() { - JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, null, VALID_VENUE, VALID_TAGS); + JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, null, + VALID_VENUE, VALID_MODULE, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @Test public void toModelType_invalidVenue_throwsIllegalValueException() { - JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_VENUE, VALID_TAGS); + JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, + INVALID_VENUE, VALID_MODULE, VALID_TAGS); String expectedMessage = Venue.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @Test public void toModelType_nullVenue_throwsIllegalValueException() { - JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, null, VALID_TAGS); + JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, + null, VALID_MODULE, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Venue.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } + @Test + public void toModelType_invalidModule_throwsIllegalValueException() { + JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, + VALID_VENUE, INVALID_MODULE, VALID_TAGS); + String expectedMessage = Module.MESSAGE_CONSTRAINTS; + assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); + } + + @Test + public void toModelType_nullModule_throwsIllegalValueException() { + JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, + VALID_VENUE, null, VALID_TAGS); + String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Module.class.getSimpleName()); + assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); + } + @Test public void toModelType_invalidTags_throwsIllegalValueException() { List<JsonAdaptedTag> invalidTags = new ArrayList<>(VALID_TAGS); invalidTags.add(new JsonAdaptedTag(INVALID_TAG)); - JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_VENUE, invalidTags); + JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, + VALID_VENUE, VALID_MODULE, invalidTags); assertThrows(IllegalValueException.class, person::toModelType); } diff --git a/src/test/java/staffconnect/testutil/EditPersonDescriptorBuilder.java b/src/test/java/staffconnect/testutil/EditPersonDescriptorBuilder.java index 26f7212673f..0929f713762 100644 --- a/src/test/java/staffconnect/testutil/EditPersonDescriptorBuilder.java +++ b/src/test/java/staffconnect/testutil/EditPersonDescriptorBuilder.java @@ -6,6 +6,7 @@ import staffconnect.logic.commands.EditCommand.EditPersonDescriptor; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; import staffconnect.model.person.Phone; @@ -36,6 +37,7 @@ public EditPersonDescriptorBuilder(Person person) { descriptor.setPhone(person.getPhone()); descriptor.setEmail(person.getEmail()); descriptor.setVenue(person.getVenue()); + descriptor.setModule(person.getModule()); descriptor.setTags(person.getTags()); } @@ -71,6 +73,14 @@ public EditPersonDescriptorBuilder withVenue(String venue) { return this; } + /** + * Sets the {@code Module} of the {@code EditPersonDescriptor} that we are building. + */ + public EditPersonDescriptorBuilder withModule(String module) { + descriptor.setModule(new Module(module)); + return this; + } + /** * Parses the {@code tags} into a {@code Set<Tag>} and set it to the {@code EditPersonDescriptor} * that we are building. diff --git a/src/test/java/staffconnect/testutil/PersonBuilder.java b/src/test/java/staffconnect/testutil/PersonBuilder.java index b68d86cee65..070f4197947 100644 --- a/src/test/java/staffconnect/testutil/PersonBuilder.java +++ b/src/test/java/staffconnect/testutil/PersonBuilder.java @@ -4,6 +4,7 @@ import java.util.Set; import staffconnect.model.person.Email; +import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; import staffconnect.model.person.Phone; @@ -20,11 +21,13 @@ public class PersonBuilder { public static final String DEFAULT_PHONE = "85355255"; public static final String DEFAULT_EMAIL = "amy@gmail.com"; public static final String DEFAULT_VENUE = "123, Jurong West Ave 6, #08-111"; + public static final String DEFAULT_MODULE = "CS2103T"; private Name name; private Phone phone; private Email email; private Venue venue; + private Module module; private Set<Tag> tags; /** @@ -35,6 +38,7 @@ public PersonBuilder() { phone = new Phone(DEFAULT_PHONE); email = new Email(DEFAULT_EMAIL); venue = new Venue(DEFAULT_VENUE); + module = new Module(DEFAULT_MODULE); tags = new HashSet<>(); } @@ -46,6 +50,7 @@ public PersonBuilder(Person personToCopy) { phone = personToCopy.getPhone(); email = personToCopy.getEmail(); venue = personToCopy.getVenue(); + module = personToCopy.getModule(); tags = new HashSet<>(personToCopy.getTags()); } @@ -58,10 +63,18 @@ public PersonBuilder withName(String name) { } /** - * Parses the {@code tags} into a {@code Set<Tag>} and set it to the {@code Person} that we are building. + * Sets the {@code Phone} of the {@code Person} that we are building. */ - public PersonBuilder withTags(String ... tags) { - this.tags = SampleDataUtil.getTagSet(tags); + public PersonBuilder withPhone(String phone) { + this.phone = new Phone(phone); + return this; + } + + /** + * Sets the {@code Email} of the {@code Person} that we are building. + */ + public PersonBuilder withEmail(String email) { + this.email = new Email(email); return this; } @@ -74,23 +87,23 @@ public PersonBuilder withVenue(String venue) { } /** - * Sets the {@code Phone} of the {@code Person} that we are building. + * Sets the {@code Module} of the {@code Person} that we are building. */ - public PersonBuilder withPhone(String phone) { - this.phone = new Phone(phone); + public PersonBuilder withModule(String module) { + this.module = new Module(module); return this; } /** - * Sets the {@code Email} of the {@code Person} that we are building. + * Parses the {@code tags} into a {@code Set<Tag>} and set it to the {@code Person} that we are building. */ - public PersonBuilder withEmail(String email) { - this.email = new Email(email); + public PersonBuilder withTags(String ... tags) { + this.tags = SampleDataUtil.getTagSet(tags); return this; } public Person build() { - return new Person(name, phone, email, venue, tags); + return new Person(name, phone, email, venue, module, tags); } } diff --git a/src/test/java/staffconnect/testutil/PersonUtil.java b/src/test/java/staffconnect/testutil/PersonUtil.java index 4cbe2c15444..5229010d888 100644 --- a/src/test/java/staffconnect/testutil/PersonUtil.java +++ b/src/test/java/staffconnect/testutil/PersonUtil.java @@ -1,6 +1,7 @@ package staffconnect.testutil; import static staffconnect.logic.parser.CliSyntax.PREFIX_EMAIL; +import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; import static staffconnect.logic.parser.CliSyntax.PREFIX_TAG; @@ -34,6 +35,7 @@ public static String getPersonDetails(Person person) { sb.append(PREFIX_PHONE + person.getPhone().value + " "); sb.append(PREFIX_EMAIL + person.getEmail().value + " "); sb.append(PREFIX_VENUE + person.getVenue().value + " "); + sb.append(PREFIX_MODULE + person.getModule().value + " "); person.getTags().stream().forEach( s -> sb.append(PREFIX_TAG + s.tagName + " ") ); @@ -49,6 +51,7 @@ public static String getEditPersonDescriptorDetails(EditPersonDescriptor descrip descriptor.getPhone().ifPresent(phone -> sb.append(PREFIX_PHONE).append(phone.value).append(" ")); descriptor.getEmail().ifPresent(email -> sb.append(PREFIX_EMAIL).append(email.value).append(" ")); descriptor.getVenue().ifPresent(venue -> sb.append(PREFIX_VENUE).append(venue.value).append(" ")); + descriptor.getModule().ifPresent(module -> sb.append(PREFIX_MODULE).append(module.value).append(" ")); if (descriptor.getTags().isPresent()) { Set<Tag> tags = descriptor.getTags().get(); if (tags.isEmpty()) { diff --git a/src/test/java/staffconnect/testutil/TypicalPersons.java b/src/test/java/staffconnect/testutil/TypicalPersons.java index 1dd397a5656..55658e0c179 100644 --- a/src/test/java/staffconnect/testutil/TypicalPersons.java +++ b/src/test/java/staffconnect/testutil/TypicalPersons.java @@ -2,6 +2,8 @@ import static staffconnect.logic.commands.CommandTestUtil.VALID_EMAIL_AMY; import static staffconnect.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; +import static staffconnect.logic.commands.CommandTestUtil.VALID_MODULE_AMY; +import static staffconnect.logic.commands.CommandTestUtil.VALID_MODULE_BOB; import static staffconnect.logic.commands.CommandTestUtil.VALID_NAME_AMY; import static staffconnect.logic.commands.CommandTestUtil.VALID_NAME_BOB; import static staffconnect.logic.commands.CommandTestUtil.VALID_PHONE_AMY; @@ -25,35 +27,37 @@ public class TypicalPersons { public static final Person ALICE = new PersonBuilder().withName("Alice Pauline") .withVenue("123, Jurong West Ave 6, #08-111").withEmail("alice@example.com") - .withPhone("94351253") + .withPhone("94351253").withModule("CS1101S") .withTags("friends").build(); public static final Person BENSON = new PersonBuilder().withName("Benson Meier") .withVenue("311, Clementi Ave 2, #02-25") - .withEmail("johnd@example.com").withPhone("98765432") + .withEmail("johnd@example.com").withPhone("98765432").withModule("CS1231S") .withTags("owesMoney", "friends").build(); public static final Person CARL = new PersonBuilder().withName("Carl Kurz").withPhone("95352563") - .withEmail("heinz@example.com").withVenue("wall street").build(); + .withEmail("heinz@example.com").withVenue("wall street").withModule("CS2030S").build(); public static final Person DANIEL = new PersonBuilder().withName("Daniel Meier").withPhone("87652533") - .withEmail("cornelia@example.com").withVenue("10th street").withTags("friends").build(); + .withEmail("cornelia@example.com").withVenue("10th street").withModule("CS2040S") + .withTags("friends").build(); public static final Person ELLE = new PersonBuilder().withName("Elle Meyer").withPhone("9482224") - .withEmail("werner@example.com").withVenue("michegan ave").build(); + .withEmail("werner@example.com").withVenue("michegan ave").withModule("CS2100").build(); public static final Person FIONA = new PersonBuilder().withName("Fiona Kunz").withPhone("9482427") - .withEmail("lydia@example.com").withVenue("little tokyo").build(); + .withEmail("lydia@example.com").withVenue("little tokyo").withModule("CS2101").build(); public static final Person GEORGE = new PersonBuilder().withName("George Best").withPhone("9482442") - .withEmail("anna@example.com").withVenue("4th street").build(); + .withEmail("anna@example.com").withVenue("4th street").withModule("CS2102").build(); // Manually added public static final Person HOON = new PersonBuilder().withName("Hoon Meier").withPhone("8482424") - .withEmail("stefan@example.com").withVenue("little india").build(); + .withEmail("stefan@example.com").withVenue("little india").withModule("CS2103").build(); public static final Person IDA = new PersonBuilder().withName("Ida Mueller").withPhone("8482131") - .withEmail("hans@example.com").withVenue("chicago ave").build(); + .withEmail("hans@example.com").withVenue("chicago ave").withModule("CS2103T").build(); // Manually added - Person's details found in {@code CommandTestUtil} public static final Person AMY = new PersonBuilder().withName(VALID_NAME_AMY).withPhone(VALID_PHONE_AMY) - .withEmail(VALID_EMAIL_AMY).withVenue(VALID_VENUE_AMY).withTags(VALID_TAG_FRIEND).build(); + .withEmail(VALID_EMAIL_AMY).withVenue(VALID_VENUE_AMY).withModule(VALID_MODULE_AMY) + .withTags(VALID_TAG_FRIEND).build(); public static final Person BOB = new PersonBuilder().withName(VALID_NAME_BOB).withPhone(VALID_PHONE_BOB) - .withEmail(VALID_EMAIL_BOB).withVenue(VALID_VENUE_BOB).withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND) - .build(); + .withEmail(VALID_EMAIL_BOB).withVenue(VALID_VENUE_BOB).withModule(VALID_MODULE_BOB) + .withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build(); public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER