diff --git a/src/main/java/staffconnect/logic/Messages.java b/src/main/java/staffconnect/logic/Messages.java index 237754bf0e1..7e6639ea5ac 100644 --- a/src/main/java/staffconnect/logic/Messages.java +++ b/src/main/java/staffconnect/logic/Messages.java @@ -40,6 +40,8 @@ public static String format(Person person) { .append("; Phone: ") .append(person.getPhone()) .append("; Email: ") + .append(person.getFaculty()) + .append("; Faculty: ") .append(person.getEmail()) .append("; Venue: ") .append(person.getVenue()) diff --git a/src/main/java/staffconnect/logic/commands/AddCommand.java b/src/main/java/staffconnect/logic/commands/AddCommand.java index e89a8a8ad1a..b0e72105f48 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_FACULTY; import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; @@ -26,6 +27,7 @@ public class AddCommand extends Command { + PREFIX_NAME + "NAME " + PREFIX_PHONE + "PHONE " + PREFIX_EMAIL + "EMAIL " + + PREFIX_FACULTY + "FACULTY " + PREFIX_VENUE + "VENUE " + PREFIX_MODULE + "MODULE " + "[" + PREFIX_TAG + "TAG]...\n" @@ -33,6 +35,7 @@ public class AddCommand extends Command { + PREFIX_NAME + "John Doe " + PREFIX_PHONE + "98765432 " + PREFIX_EMAIL + "johnd@example.com " + + PREFIX_FACULTY + "Computing " + PREFIX_VENUE + "311, Clementi Ave 2, #02-25 " + PREFIX_MODULE + "CS2103 " + PREFIX_TAG + "friends " diff --git a/src/main/java/staffconnect/logic/commands/EditCommand.java b/src/main/java/staffconnect/logic/commands/EditCommand.java index a2a253942d1..ee47549c189 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_FACULTY; import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; @@ -23,6 +24,7 @@ import staffconnect.logic.commands.exceptions.CommandException; import staffconnect.model.Model; import staffconnect.model.person.Email; +import staffconnect.model.person.Faculty; import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; @@ -44,6 +46,7 @@ public class EditCommand extends Command { + "[" + PREFIX_NAME + "NAME] " + "[" + PREFIX_PHONE + "PHONE] " + "[" + PREFIX_EMAIL + "EMAIL] " + + "[" + PREFIX_FACULTY + "FACULTY] " + "[" + PREFIX_VENUE + "VENUE] " + "[" + PREFIX_MODULE + "MODULE] " + "[" + PREFIX_TAG + "TAG]...\n" @@ -101,11 +104,13 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName()); Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone()); Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); + Faculty updatedFaculty = editPersonDescriptor.getFaculty().orElse(personToEdit.getFaculty()); Venue updatedVenue = editPersonDescriptor.getVenue().orElse(personToEdit.getVenue()); Module updatedModule = editPersonDescriptor.getModule().orElse(personToEdit.getModule()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedVenue, updatedModule, updatedTags); + return new Person(updatedName, updatedPhone, updatedEmail, updatedFaculty, + updatedVenue, updatedModule, updatedTags); } @Override @@ -140,6 +145,7 @@ public static class EditPersonDescriptor { private Name name; private Phone phone; private Email email; + private Faculty faculty; private Venue venue; private Module module; private Set tags; @@ -154,6 +160,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { setName(toCopy.name); setPhone(toCopy.phone); setEmail(toCopy.email); + setFaculty(toCopy.faculty); setVenue(toCopy.venue); setModule(toCopy.module); setTags(toCopy.tags); @@ -163,7 +170,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { * Returns true if at least one field is edited. */ public boolean isAnyFieldEdited() { - return CollectionUtil.isAnyNonNull(name, phone, email, venue, module, tags); + return CollectionUtil.isAnyNonNull(name, phone, email, faculty, venue, module, tags); } public void setName(Name name) { @@ -190,6 +197,14 @@ public Optional getEmail() { return Optional.ofNullable(email); } + public void setFaculty(Faculty faculty) { + this.faculty = faculty; + } + + public Optional getFaculty() { + return Optional.ofNullable(faculty); + } + public void setVenue(Venue venue) { this.venue = venue; } @@ -238,6 +253,7 @@ public boolean equals(Object other) { return Objects.equals(name, otherEditPersonDescriptor.name) && Objects.equals(phone, otherEditPersonDescriptor.phone) && Objects.equals(email, otherEditPersonDescriptor.email) + && Objects.equals(faculty, otherEditPersonDescriptor.faculty) && Objects.equals(venue, otherEditPersonDescriptor.venue) && Objects.equals(module, otherEditPersonDescriptor.module) && Objects.equals(tags, otherEditPersonDescriptor.tags); @@ -249,6 +265,7 @@ public String toString() { .add("name", name) .add("phone", phone) .add("email", email) + .add("faculty", faculty) .add("venue", venue) .add("module", module) .add("tags", tags) diff --git a/src/main/java/staffconnect/logic/parser/AddCommandParser.java b/src/main/java/staffconnect/logic/parser/AddCommandParser.java index 3b8bf5a2f62..660065236d4 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_FACULTY; import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; @@ -14,6 +15,7 @@ import staffconnect.logic.commands.AddCommand; import staffconnect.logic.parser.exceptions.ParseException; import staffconnect.model.person.Email; +import staffconnect.model.person.Faculty; import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; @@ -33,23 +35,24 @@ public class AddCommandParser implements Parser { */ public AddCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, - PREFIX_EMAIL, PREFIX_VENUE, PREFIX_MODULE, PREFIX_TAG); + PREFIX_EMAIL, PREFIX_FACULTY, PREFIX_VENUE, PREFIX_MODULE, PREFIX_TAG); - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VENUE, PREFIX_MODULE) - || !argMultimap.getPreamble().isEmpty()) { + if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_FACULTY, + 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, + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_FACULTY, 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()); + Faculty faculty = ParserUtil.parseFaculty(argMultimap.getValue(PREFIX_FACULTY).get()); Module module = ParserUtil.parseModule(argMultimap.getValue(PREFIX_MODULE).get()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Person person = new Person(name, phone, email, venue, module, tagList); + Person person = new Person(name, phone, email, faculty, 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 9493ab188e5..9676d720b05 100644 --- a/src/main/java/staffconnect/logic/parser/CliSyntax.java +++ b/src/main/java/staffconnect/logic/parser/CliSyntax.java @@ -9,6 +9,7 @@ public class CliSyntax { public static final Prefix PREFIX_NAME = new Prefix("n/"); public static final Prefix PREFIX_PHONE = new Prefix("p/"); public static final Prefix PREFIX_EMAIL = new Prefix("e/"); + public static final Prefix PREFIX_FACULTY = new Prefix("f/"); 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 3249935c101..e24b767e6c0 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_FACULTY; import static staffconnect.logic.parser.CliSyntax.PREFIX_MODULE; import static staffconnect.logic.parser.CliSyntax.PREFIX_NAME; import static staffconnect.logic.parser.CliSyntax.PREFIX_PHONE; @@ -33,7 +34,7 @@ public class EditCommandParser implements Parser { public EditCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, + ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_FACULTY, PREFIX_VENUE, PREFIX_MODULE, PREFIX_TAG); Index index; @@ -44,7 +45,7 @@ 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, + argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_FACULTY, PREFIX_VENUE, PREFIX_MODULE); EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor(); @@ -58,6 +59,9 @@ public EditCommand parse(String args) throws ParseException { if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) { editPersonDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get())); } + if (argMultimap.getValue(PREFIX_FACULTY).isPresent()) { + editPersonDescriptor.setFaculty(ParserUtil.parseFaculty(argMultimap.getValue(PREFIX_FACULTY).get())); + } if (argMultimap.getValue(PREFIX_VENUE).isPresent()) { editPersonDescriptor.setVenue(ParserUtil.parseVenue(argMultimap.getValue(PREFIX_VENUE).get())); } diff --git a/src/main/java/staffconnect/logic/parser/ParserUtil.java b/src/main/java/staffconnect/logic/parser/ParserUtil.java index 454061da8b3..eae100013dd 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.Faculty; import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Phone; @@ -81,6 +82,21 @@ public static Email parseEmail(String email) throws ParseException { return new Email(trimmedEmail); } + /** + * Parses a {@code String faculty} into an {@code Faculty}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code faculty} is invalid. + */ + public static Faculty parseFaculty(String faculty) throws ParseException { + requireNonNull(faculty); + String trimmedFaculty = faculty.trim(); + if (!Faculty.isValidFaculty(trimmedFaculty)) { + throw new ParseException(Faculty.MESSAGE_CONSTRAINTS); + } + return new Faculty(trimmedFaculty); + } + /** * Parses a {@code String venue} into an {@code Venue}. * Leading and trailing whitespaces will be trimmed. diff --git a/src/main/java/staffconnect/model/person/Person.java b/src/main/java/staffconnect/model/person/Person.java index 5c10209078e..a445c35b4a2 100644 --- a/src/main/java/staffconnect/model/person/Person.java +++ b/src/main/java/staffconnect/model/person/Person.java @@ -20,6 +20,7 @@ public class Person { private final Name name; private final Phone phone; private final Email email; + private final Faculty faculty; // Data fields private final Venue venue; @@ -29,11 +30,12 @@ public class Person { /** * Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Venue venue, Module module, Set tags) { - requireAllNonNull(name, phone, email, venue, module, tags); + public Person(Name name, Phone phone, Email email, Faculty faculty, Venue venue, Module module, Set tags) { + requireAllNonNull(name, phone, email, faculty, venue, module, tags); this.name = name; this.phone = phone; this.email = email; + this.faculty = faculty; this.venue = venue; this.module = module; this.tags.addAll(tags); @@ -51,6 +53,10 @@ public Email getEmail() { return email; } + public Faculty getFaculty() { + return faculty; + } + public Venue getVenue() { return venue; } @@ -99,6 +105,7 @@ public boolean equals(Object other) { return name.equals(otherPerson.name) && phone.equals(otherPerson.phone) && email.equals(otherPerson.email) + && faculty.equals(otherPerson.faculty) && venue.equals(otherPerson.venue) && module.equals(otherPerson.module) && tags.equals(otherPerson.tags); @@ -107,7 +114,7 @@ public boolean equals(Object other) { @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, venue, module, tags); + return Objects.hash(name, phone, email, faculty, venue, module, tags); } @Override @@ -116,6 +123,7 @@ public String toString() { .add("name", name) .add("phone", phone) .add("email", email) + .add("faculty", faculty) .add("venue", venue) .add("module", module) .add("tags", tags) diff --git a/src/main/java/staffconnect/model/util/SampleDataUtil.java b/src/main/java/staffconnect/model/util/SampleDataUtil.java index 1befd734f31..88ab2d5edc9 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.Faculty; import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; @@ -19,25 +20,37 @@ */ public class SampleDataUtil { public static Person[] getSamplePersons() { - return new Person[] { + 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"), new Module("CS1101S"), - getTagSet("professor")), + new Faculty("Computing"), + 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"), new Module("CS1231S"), - getTagSet("tutor", "friends")), + new Faculty("Computing"), + 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"), new Module("CS2030S"), - getTagSet("professor")), + new Faculty("Computing"), + 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"), new Module("CS2040S"), - getTagSet("professor")), + new Faculty("Computing"), + 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"), new Module("CS2100"), - getTagSet("tutor")), + new Faculty("Computing"), + 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"), new Module("CS2101"), - getTagSet("professor")) + new Faculty("Computing"), + 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 600299c7a12..557ebc407ce 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.Faculty; import staffconnect.model.person.Module; import staffconnect.model.person.Name; import staffconnect.model.person.Person; @@ -28,6 +29,7 @@ class JsonAdaptedPerson { private final String name; private final String phone; private final String email; + private final String faculty; private final String venue; private final String module; private final List tags = new ArrayList<>(); @@ -37,11 +39,13 @@ class JsonAdaptedPerson { */ @JsonCreator public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, - @JsonProperty("email") String email, @JsonProperty("venue") String venue, - @JsonProperty("module") String module, @JsonProperty("tags") List tags) { + @JsonProperty("email") String email, @JsonProperty("faculty") String faculty, + @JsonProperty("venue") String venue, @JsonProperty("module") String module, + @JsonProperty("tags") List tags) { this.name = name; this.phone = phone; this.email = email; + this.faculty = faculty; this.venue = venue; this.module = module; if (tags != null) { @@ -56,6 +60,7 @@ public JsonAdaptedPerson(Person source) { name = source.getName().fullName; phone = source.getPhone().value; email = source.getEmail().value; + faculty = source.getFaculty().toString(); venue = source.getVenue().value; module = source.getModule().value; tags.addAll(source.getTags().stream() @@ -98,6 +103,15 @@ public Person toModelType() throws IllegalValueException { } final Email modelEmail = new Email(email); + if (faculty == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, + Faculty.class.getSimpleName())); + } + if (!Faculty.isValidFaculty(faculty)) { + throw new IllegalValueException(Faculty.MESSAGE_CONSTRAINTS); + } + final Faculty modelFaculty = new Faculty(faculty); + if (venue == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Venue.class.getSimpleName())); } @@ -115,7 +129,7 @@ public Person toModelType() throws IllegalValueException { final Module modelModule = new Module(module); final Set modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelVenue, modelModule, modelTags); + return new Person(modelName, modelPhone, modelEmail, modelFaculty, modelVenue, modelModule, modelTags); } } diff --git a/src/main/java/staffconnect/ui/PersonCard.java b/src/main/java/staffconnect/ui/PersonCard.java index f93f79e7476..62a7fdb51e5 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 { @FXML private Label venue; @FXML + private Label faculty; + @FXML private Label module; @FXML private Label email; @@ -52,6 +54,7 @@ public PersonCard(Person person, int displayedIndex) { id.setText(displayedIndex + ". "); name.setText(person.getName().fullName); phone.setText(person.getPhone().value); + faculty.setText(person.getFaculty().toString()); venue.setText(person.getVenue().value); module.setText(person.getModule().value); email.setText(person.getEmail().value); diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index 2101c6c5ed9..2eaa73653dc 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -29,6 +29,7 @@