diff --git a/docs/diagrams/FavSequenceDiagram.puml b/docs/diagrams/FavSequenceDiagram.puml index bc7b3a9172a..6ffb3c747e1 100644 --- a/docs/diagrams/FavSequenceDiagram.puml +++ b/docs/diagrams/FavSequenceDiagram.puml @@ -7,8 +7,10 @@ participant ":LogicManager" as LogicManager LOGIC_COLOR participant ":StaffConnectParser" as StaffConnectParser LOGIC_COLOR participant ":FavCommandParser" as FavCommandParser LOGIC_COLOR participant "<>\nParserUtil" as ParserUtil LOGIC_COLOR -participant "d:FavCommand" as FavCommand LOGIC_COLOR +participant "f:FavCommand" as FavCommand LOGIC_COLOR participant "r:CommandResult" as CommandResult LOGIC_COLOR +participant FavCommand as FavCommand1 <> LOGIC_COLOR +participant "<>\nPersonUtil" as PersonUtil LOGIC_COLOR end box box Model MODEL_COLOR_T1 @@ -40,19 +42,28 @@ create FavCommand FavCommandParser -> FavCommand++ return -return m +return f destroy FavCommandParser -return m +return f LogicManager -> FavCommand : execute(model) activate FavCommand -FavCommand -> Model : getFilteredPersonList() +FavCommand -> Model : getSortedFilteredPersonList() activate Model return +FavCommand -> FavCommand1 : createFavPerson(personToFav) +activate FavCommand1 + +FavCommand1 -> PersonUtil : createPersonWithFavouriteStatus(Person selectedPerson, Favourite favourite) +activate PersonUtil + create Person -FavCommand -> Person++ +PersonUtil -> Person++ +return createdPerson + +return favPerson return favPerson FavCommand -> Model : setPerson(personToFav, favPerson) diff --git a/docs/diagrams/UnfavSequenceDiagram.puml b/docs/diagrams/UnfavSequenceDiagram.puml index 855e2a2e97c..b684111bfdc 100644 --- a/docs/diagrams/UnfavSequenceDiagram.puml +++ b/docs/diagrams/UnfavSequenceDiagram.puml @@ -7,8 +7,10 @@ participant ":LogicManager" as LogicManager LOGIC_COLOR participant ":StaffConnectParser" as StaffConnectParser LOGIC_COLOR participant ":UnfavCommandParser" as UnfavCommandParser LOGIC_COLOR participant "<>\nParserUtil" as ParserUtil LOGIC_COLOR -participant "d:UnfavCommand" as UnfavCommand LOGIC_COLOR +participant "u:UnfavCommand" as UnfavCommand LOGIC_COLOR participant "r:CommandResult" as CommandResult LOGIC_COLOR +participant UnfavCommand as UnfavCommand1 <> LOGIC_COLOR +participant "<>\nPersonUtil" as PersonUtil LOGIC_COLOR end box box Model MODEL_COLOR_T1 @@ -47,12 +49,21 @@ return u LogicManager -> UnfavCommand : execute(model) activate UnfavCommand -UnfavCommand -> Model : getFilteredPersonList() +UnfavCommand -> Model : getSortedFilteredPersonList() activate Model return +UnfavCommand -> UnfavCommand1 : createUnfavPerson(personToUnfav) +activate UnfavCommand1 + +UnfavCommand1 -> PersonUtil : createPersonWithFavouriteStatus(Person selectedPerson, Favourite favourite) +activate PersonUtil + create Person -UnfavCommand -> Person++ +PersonUtil -> Person++ +return createdPerson + +return unfavPerson return unfavPerson UnfavCommand -> Model : setPerson(personToUnfav, unfavPerson) diff --git a/docs/images/FavSequenceDiagram.png b/docs/images/FavSequenceDiagram.png index 38c59038da6..5e665b383d1 100644 Binary files a/docs/images/FavSequenceDiagram.png and b/docs/images/FavSequenceDiagram.png differ diff --git a/docs/images/UnfavSequenceDiagram.png b/docs/images/UnfavSequenceDiagram.png index 04f23ce24b7..5ef791060d1 100644 Binary files a/docs/images/UnfavSequenceDiagram.png and b/docs/images/UnfavSequenceDiagram.png differ diff --git a/src/main/java/staffconnect/logic/commands/FavCommand.java b/src/main/java/staffconnect/logic/commands/FavCommand.java index 9a64de47cb8..333197b54e1 100644 --- a/src/main/java/staffconnect/logic/commands/FavCommand.java +++ b/src/main/java/staffconnect/logic/commands/FavCommand.java @@ -2,25 +2,17 @@ import static java.util.Objects.requireNonNull; import static staffconnect.model.Model.PREDICATE_SHOW_ALL_PERSONS; +import static staffconnect.model.person.PersonUtil.createPersonWithFavouriteStatus; import java.util.List; -import java.util.Set; import staffconnect.commons.core.index.Index; import staffconnect.commons.util.ToStringBuilder; import staffconnect.logic.Messages; import staffconnect.logic.commands.exceptions.CommandException; import staffconnect.model.Model; -import staffconnect.model.availability.Availability; -import staffconnect.model.person.Email; -import staffconnect.model.person.Faculty; import staffconnect.model.person.Favourite; -import staffconnect.model.person.Module; -import staffconnect.model.person.Name; import staffconnect.model.person.Person; -import staffconnect.model.person.Phone; -import staffconnect.model.person.Venue; -import staffconnect.model.tag.Tag; /** * Sets a person as favourite in the staff book. @@ -76,19 +68,8 @@ public CommandResult execute(Model model) throws CommandException { private static Person createFavPerson(Person personToFav) { assert personToFav != null; - Name name = personToFav.getName(); - Phone phone = personToFav.getPhone(); - Email email = personToFav.getEmail(); - Module module = personToFav.getModule(); - Faculty faculty = personToFav.getFaculty(); - Venue venue = personToFav.getVenue(); - Set tags = personToFav.getTags(); - Set availabilities = personToFav.getAvailabilities(); Favourite updatedFavourite = new Favourite(true); - - Person favPerson = - new Person(name, phone, email, module, faculty, venue, tags, availabilities, updatedFavourite); - favPerson.setMeetings(personToFav.getMeetings()); + Person favPerson = createPersonWithFavouriteStatus(personToFav, updatedFavourite); return favPerson; } diff --git a/src/main/java/staffconnect/logic/commands/UnfavCommand.java b/src/main/java/staffconnect/logic/commands/UnfavCommand.java index bc16213cfde..7417dbcb732 100644 --- a/src/main/java/staffconnect/logic/commands/UnfavCommand.java +++ b/src/main/java/staffconnect/logic/commands/UnfavCommand.java @@ -2,25 +2,17 @@ import static java.util.Objects.requireNonNull; import static staffconnect.model.Model.PREDICATE_SHOW_ALL_PERSONS; +import static staffconnect.model.person.PersonUtil.createPersonWithFavouriteStatus; import java.util.List; -import java.util.Set; import staffconnect.commons.core.index.Index; import staffconnect.commons.util.ToStringBuilder; import staffconnect.logic.Messages; import staffconnect.logic.commands.exceptions.CommandException; import staffconnect.model.Model; -import staffconnect.model.availability.Availability; -import staffconnect.model.person.Email; -import staffconnect.model.person.Faculty; import staffconnect.model.person.Favourite; -import staffconnect.model.person.Module; -import staffconnect.model.person.Name; import staffconnect.model.person.Person; -import staffconnect.model.person.Phone; -import staffconnect.model.person.Venue; -import staffconnect.model.tag.Tag; /** * Removes a person as favourite in the staff book. @@ -62,7 +54,7 @@ public CommandResult execute(Model model) throws CommandException { throw new CommandException(MESSAGE_DUPLICATE_UNFAV); } - Person unfavPerson = createUnmarkedPerson(personToUnfav); + Person unfavPerson = createUnfavPerson(personToUnfav); model.setPerson(personToUnfav, unfavPerson); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); @@ -72,22 +64,11 @@ public CommandResult execute(Model model) throws CommandException { /** * Creates and returns a {@code Person} with the details of {@code personToUnfav}. */ - private static Person createUnmarkedPerson(Person personToUnfav) { + private static Person createUnfavPerson(Person personToUnfav) { assert personToUnfav != null; - Name name = personToUnfav.getName(); - Phone phone = personToUnfav.getPhone(); - Email email = personToUnfav.getEmail(); - Module module = personToUnfav.getModule(); - Faculty faculty = personToUnfav.getFaculty(); - Venue venue = personToUnfav.getVenue(); - Set tags = personToUnfav.getTags(); - Set availabilities = personToUnfav.getAvailabilities(); Favourite updatedFavourite = new Favourite(false); - - Person unfavPerson = - new Person(name, phone, email, module, faculty, venue, tags, availabilities, updatedFavourite); - unfavPerson.setMeetings(personToUnfav.getMeetings()); + Person unfavPerson = createPersonWithFavouriteStatus(personToUnfav, updatedFavourite); return unfavPerson; } diff --git a/src/main/java/staffconnect/model/person/PersonUtil.java b/src/main/java/staffconnect/model/person/PersonUtil.java index b816a9509a7..6d05a5ef91b 100644 --- a/src/main/java/staffconnect/model/person/PersonUtil.java +++ b/src/main/java/staffconnect/model/person/PersonUtil.java @@ -17,19 +17,39 @@ public class PersonUtil { * Copies and returns a new Person with the data of {@code personToCopy}. */ public static Person copyPerson(Person personToCopy) { - Name name = personToCopy.getName(); - Phone phone = personToCopy.getPhone(); - Email email = personToCopy.getEmail(); - Module module = personToCopy.getModule(); - Faculty faculty = personToCopy.getFaculty(); - Venue venue = personToCopy.getVenue(); - Set tags = personToCopy.getTags(); - Set availabilities = personToCopy.getAvailabilities(); - List meetings = personToCopy.getMeetings(); - Favourite favourite = personToCopy.getFavourite(); - - Person personToCreate = new Person(name, phone, email, module, faculty, venue, tags, availabilities, favourite); - personToCreate.setMeetings(meetings); - return personToCreate; + Name copiedName = personToCopy.getName(); + Phone copiedPhone = personToCopy.getPhone(); + Email copiedEmail = personToCopy.getEmail(); + Module copiedModule = personToCopy.getModule(); + Faculty copiedFaculty = personToCopy.getFaculty(); + Venue copiedVenue = personToCopy.getVenue(); + Set copiedTags = personToCopy.getTags(); + Set copiedAvailabilities = personToCopy.getAvailabilities(); + List copiedMeetings = personToCopy.getMeetings(); + Favourite copiedFavourite = personToCopy.getFavourite(); + + Person copiedPerson = new Person(copiedName, copiedPhone, copiedEmail, copiedModule, copiedFaculty, copiedVenue, + copiedTags, copiedAvailabilities, copiedFavourite); + copiedPerson.setMeetings(copiedMeetings); + return copiedPerson; + } + + /** + * Creates and returns a new Person with the data of {@code selectedPerson} and given {@code favourite}. + */ + public static Person createPersonWithFavouriteStatus(Person selectedPerson, Favourite favourite) { + Name name = selectedPerson.getName(); + Phone phone = selectedPerson.getPhone(); + Email email = selectedPerson.getEmail(); + Module module = selectedPerson.getModule(); + Faculty faculty = selectedPerson.getFaculty(); + Venue venue = selectedPerson.getVenue(); + Set tags = selectedPerson.getTags(); + Set availabilities = selectedPerson.getAvailabilities(); + + Person createdPerson = + new Person(name, phone, email, module, faculty, venue, tags, availabilities, favourite); + createdPerson.setMeetings(selectedPerson.getMeetings()); + return createdPerson; } } diff --git a/src/test/java/staffconnect/model/ModelManagerTest.java b/src/test/java/staffconnect/model/ModelManagerTest.java index 0edc677986b..a9183cd22c2 100644 --- a/src/test/java/staffconnect/model/ModelManagerTest.java +++ b/src/test/java/staffconnect/model/ModelManagerTest.java @@ -95,7 +95,7 @@ public void indexOf_personInStaffBook_equalsZero() { } @Test - public void getFilteredPersonList_modifyList_throwsUnsupportedOperationException() { + public void getSortedFilteredPersonList_modifyList_throwsUnsupportedOperationException() { assertThrows(UnsupportedOperationException.class, () -> modelManager.getSortedFilteredPersonList().remove(0)); }