diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index 1cfa2ad3031..dd966c114e2 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -337,3 +337,62 @@ to determine which faculty of in-built contacts to import - Cons: - Input will take longer to parse as the string input has to be parsed into a faculty object to be used as input to ImportCommand#execute +## Add Feature +### Add Implementation +The Add feature is facilitated by the classes `AddCommand`, +`AddCommandParser` and `ParserUtil`. +The `AddCommandParser` first parses through the user command to obtain +the necessary inputs through using `ParserUtil#parseIndex`. Following which an +instance of a `AddCommand` containing the details encapsulated in Person class is returned. +`AddCommand#execute` is then called, which sets the image of the contact +at the desired index to a default image, and deletes the existing person through +`DeleteCommand`. + +Given below is an example usage scenario for how the add mechanism behaves. + +Step 1: User starts up the application and sees their list of contacts. User must then enter +[name] [status] [phone] [email] [address] as they are required by the system if not it will cause +an invalid exception. + +Step 2: The user decides that the image given to the contact at index 4 is not +suitable, and wants to delete it. The user inputs `delete-image 4`. +`DeleteImageCommandParser#parse` is then called to parse this input for the +desired index. + +> **Note**: If the user inputs an index of a contact which currently does not have +an image, or if the user inputs an invalid index, an error will be returned to +the user + +Step 3: If the instruction was valid, `Model#deleteImage` is called to set the +image of the contact to the default image. + +Step 4: `ImageUtil#deleteImage` is then called to delete the existing image +from the program directory. + +The following sequence diagram shows how the delete-image operation works. + +![AddSequenceDiagram](images/AddSequenceDiagram.png) + +> **Note**: The lifeline of the `DeleteImageCommandParser` and `DeleteImageCommand` +> should end at the destroy marker (X) but due to the limitations of PlantUML, the +> lifeline reaches the end of the diagram. + +The following activity diagram summarizes what happens when a user executes a +delete-image command: + +![AddActivityDiagram](images/AddActivityDiagram.png) + +### Design Considerations: +- **Alternative 1 (current choice):** Delete the existing image file from program + directory. + - Pros: + - Ensures application does not consume excess storage + - Cons: + - Extra complexity in requiring file i/o operations + +- **Alternative 2:** Disregard deleting the image file from program directory. + - Pros: + - Easier to implement + - Cons: + - Application will take up increasingly more unnecessary storage during + its lifetime of usage diff --git a/docs/diagrams/AddActivityDiagram.puml b/docs/diagrams/AddActivityDiagram.puml new file mode 100644 index 00000000000..084012d14b3 --- /dev/null +++ b/docs/diagrams/AddActivityDiagram.puml @@ -0,0 +1,20 @@ +@startuml +start +:User executes add command; +'Since the beta syntax does not support placing the condition outside the +'diamond we place it as the true branch instead. + +if () then ([prefix is valid and necessary inputs are filled]) + :New person is being added to the contact list; + if () then ([contact does not have person]) + : Add new Person to model; + : Store person details in address book; + : Display success message; + else ([else]) + : Display error message; + endif +else ([else]) + : Display error message; +endif +stop +@enduml diff --git a/docs/diagrams/AddSequenceDiagram.puml b/docs/diagrams/AddSequenceDiagram.puml new file mode 100644 index 00000000000..e89535b2fdb --- /dev/null +++ b/docs/diagrams/AddSequenceDiagram.puml @@ -0,0 +1,85 @@ +@startuml +!include style.puml + +box Logic LOGIC_COLOR_T1 +participant ":LogicManager" as LogicManager LOGIC_COLOR +participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR +participant ":AddCommandParser" as AddCommandParser LOGIC_COLOR +participant "command:AddCommand" as AddCommand LOGIC_COLOR +end box +box Model MODEL_COLOR_T1 +participant ":Model" as Model MODEL_COLOR +end box +box Addressbook ADDRESSBOOK_COLOR_T1 +participant ":Addressbook" as Addressbook ADDRESSBOOK_COLOR +end box + +[-> LogicManager : execute(add) +activate LogicManager + +LogicManager -> AddressBookParser : parseCommand(add) +activate AddressBookParser + +create AddCommandParser +AddressBookParser -> AddCommandParser +activate AddCommandParser + +AddCommandParser --> AddressBookParser +deactivate AddCommandParser + +AddressBookParser -> AddCommandParser : parse(args) +activate AddCommandParser + +create AddCommand +AddCommandParser -> AddCommand +activate AddCommand + +AddCommand --> AddCommandParser +deactivate AddCommand + +AddCommandParser --> AddressBookParser : command +deactivate AddCommandParser + +AddressBookParser -[hidden]-> AddressBookParser : command +destroy AddCommandParser + +AddressBookParser --> LogicManager : command +deactivate AddressBookParser + +LogicManager -> AddCommand : execute(model) +activate AddCommand + +AddCommand -> Model : hasPerson(toAdd) +activate Model + +Model -> Addressbook : hasPerson(toAdd) +activate Addressbook + +Addressbook --> Model : result +deactivate Addressbook + +Model --> AddCommand : result +deactivate Model + +AddCommand -> Model : addPerson(toAdd) +activate Model + +Model -> Addressbook : addPerson(toAdd) +activate Addressbook + +Addressbook --> Model : result +deactivate Addressbook + +Model --> AddCommand : result +deactivate Model + +AddCommand --> LogicManager :commandResult +deactivate AddCommand + +AddCommand -[hidden]-> LogicManager : result +destroy AddCommand + +[<--LogicManager : commandResult +deactivate LogicManager + +@enduml diff --git a/docs/diagrams/style.puml b/docs/diagrams/style.puml index fad8b0adeaa..4365c80d117 100644 --- a/docs/diagrams/style.puml +++ b/docs/diagrams/style.puml @@ -31,6 +31,12 @@ !define STORAGE_COLOR_T3 #806600 !define STORAGE_COLOR_T2 #544400 +!define ADDRESSBOOK_COLOR #A38300 +!define ADDRESSBOOK_COLOR_T1 #FFE374 +!define ADDRESSBOOK_COLOR_T2 #EDC520 +!define ADDRESSBOOK_COLOR_T3 #806600 +!define ADDRESSBOOK_COLOR_T2 #544400 + !define USER_COLOR #000000 skinparam BackgroundColor #FFFFFFF diff --git a/docs/images/AddActivityDiagram.png b/docs/images/AddActivityDiagram.png new file mode 100644 index 00000000000..e65d3193c92 Binary files /dev/null and b/docs/images/AddActivityDiagram.png differ diff --git a/docs/images/AddSequenceDiagram.png b/docs/images/AddSequenceDiagram.png new file mode 100644 index 00000000000..8356f3848f0 Binary files /dev/null and b/docs/images/AddSequenceDiagram.png differ diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 17a88b8544b..2a0adfd0b8b 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -22,14 +22,14 @@ public class AddCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. " + "Parameters: " + PREFIX_NAME + "NAME " - + PREFIX_STATUS + "STATUS" + + PREFIX_STATUS + "STATUS " + PREFIX_PHONE + "PHONE " + PREFIX_EMAIL + "EMAIL " + PREFIX_ADDRESS + "ADDRESS " + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "John Doe " - + PREFIX_STATUS + "Y2 computer science" + + PREFIX_STATUS + "Y2 computer science " + PREFIX_PHONE + "98765432 " + PREFIX_EMAIL + "johnd@example.com " + PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "