Skip to content

Commit 189aca2

Browse files
authored
Merge pull request nus-cs2103-AY2223S2#66 from pkpaing/v1.3
[v1.3] Updated DG (Import), Fixed Import command bug
2 parents 39a62fc + e875e79 commit 189aca2

File tree

6 files changed

+160
-4
lines changed

6 files changed

+160
-4
lines changed

docs/DeveloperGuide.md

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ connections with their peers during their time in University.
2222

2323
System: BookFace
2424

25+
```
2526
Use case: UC1 - Add Contact
2627
2728
Actor: User
@@ -37,7 +38,9 @@ Extensions:
3738
2a. BookFace detects incomplete/invalid details entered.
3839
BookFace displays an example of valid details.
3940
System repeats Step 1-2 until valid details are entered.
41+
```
4042

43+
```
4144
Use case: UC2 - Delete Contact
4245
4346
Actor: User
@@ -53,7 +56,9 @@ Extensions:
5356
2a. BookFace detects incomplete/invalid index entered.
5457
BookFace displays an example of a valid index.
5558
System repeats Step 1-2 until valid information is entered.
59+
```
5660

61+
```
5762
Use case: UC3 - Edit Contact
5863
5964
Actor: User
@@ -69,7 +74,9 @@ Extensions:
6974
2a. BookFace detects incomplete/invalid details entered.
7075
BookFace displays an example of valid details.
7176
System repeats Step 1-2 until valid details are entered.
77+
```
7278

79+
```
7380
Use case: UC4 - Find Contact
7481
7582
Actor: User
@@ -85,7 +92,9 @@ Extensions:
8592
2a. BookFace detects no name entered.
8693
BookFace displays an example of a valid name.
8794
System repeats Step 1-2 until a name is entered.
95+
```
8896

97+
```
8998
Use case: UC5 - List Contacts
9099
91100
Actor: User
@@ -94,7 +103,9 @@ MSS:
94103
1. User chooses to view all contacts.
95104
2. BookFace displays all the user's contacts.
96105
Use case ends.
106+
```
97107

108+
```
98109
Use case: UC6 - Get Help on Commands
99110
100111
Actor: User
@@ -103,7 +114,9 @@ MSS:
103114
1. User chooses to view instructions on how to use BookFace.
104115
2. BookFace displays a url to its User Guide.
105116
Use case ends.
117+
```
106118

119+
```
107120
Use case: UC7 - Add Image for a Contact
108121
Actor: User
109122
MSS:
@@ -117,7 +130,9 @@ Extensions:
117130
2a. BookFace detects invalid/incomplete filepath or index.
118131
BookFace displays an example of a valid filepath and index.
119132
System repeats Step 1-2 until valid information is entered.
133+
```
120134

135+
```
121136
Use case: UC8 - Delete Image for a Contact
122137
123138
Actor: User
@@ -136,7 +151,9 @@ System repeats Step 1-2 until valid information is entered.
136151
137152
2b. BookFace detects that the contact does not have an image added.
138153
Use case ends.
154+
```
139155

156+
```
140157
Use case: UC9 - Import Contacts from a Faculty
141158
142159
Actor: User
@@ -152,6 +169,7 @@ Extensions:
152169
2a. BookFace detects incomplete/invalid details entered.
153170
BookFace displays an example of valid details.
154171
System repeats Step 1-2 until valid details are entered.
172+
```
155173

156174
**Glossary** :
157175
* Student: A user who belongs to a faculty and attends one or more classes with other students
@@ -209,7 +227,7 @@ The following activity diagram summarizes what happens when a user executes add-
209227
- Path is easily invalidated (e.g. user moves/deletes/renames the image)
210228
## Delete Image Feature
211229
### Delete Image Implementation
212-
The delete-image feature is facilitated by the classes `DeleteImageCommand`,
230+
The delete-image feature is facilitated by the classes `DeleteImageCommand`,
213231
`DeleteImageCommandParser`, `ImageUtil`, and `ParserUtil`.
214232
The `DeleteImageCommandParser` first parses through the user command to obtain
215233
the desired index through using `ParserUtil#parseIndex`. Following which an
@@ -225,7 +243,7 @@ which have already had an image added.
225243

226244
Step 2: The user decides that the image given to the contact at index 4 is not
227245
suitable, and wants to delete it. The user inputs `delete-image 4`.
228-
`DeleteImageCommandParser#parse` is then called to parse this input for the
246+
`DeleteImageCommandParser#parse` is then called to parse this input for the
229247
desired index.
230248

231249
> **Note**: If the user inputs an index of a contact which currently does not have
@@ -258,10 +276,64 @@ directory.
258276
- Ensures application does not consume excess storage
259277
- Cons:
260278
- Extra complexity in requiring file i/o operations
261-
279+
262280
- **Alternative 2:** Disregard deleting the image file from program directory.
263281
- Pros:
264282
- Easier to implement
265283
- Cons:
266284
- Application will take up increasingly more unnecessary storage during
267285
its lifetime of usage
286+
## Import Contacts Feature
287+
### Import Contacts Implementation
288+
The import feature is facilitated by the classes `ImportCommand`, `ImportCommandParser`,
289+
`SocContacts` and `ChsContacts`. The `ImportCommandParser` first parses through the user
290+
command to obtain the desired faculty to be imported. An instance of
291+
a `ImportCommand` containing the desired faculty from either `SocContacts` or
292+
`ChsContacts` is then returned. `ImportCommand#execute` is then called,
293+
which calls `Model#addPerson` to add the unique contacts into BookFace.
294+
295+
Given below is an example usage scenario for how the import mechanism behaves.
296+
297+
Step 1: User starts up the application and sees their list of contacts.
298+
299+
Step 2: User decides to import contacts from faculty SOC and input
300+
`import soc`. `ImportCommandParser#parse` is then called to parse
301+
this input for the desired faculty.
302+
303+
> **Note**: If the user inputs a faculty that does not exist,
304+
> an error will be returned to the user
305+
>
306+
307+
Step 3: If the faculty was valid, `ImportCommand#execute` is called
308+
with the valid faculty that was parsed
309+
310+
Step 4: `Model#addPerson` is called for however
311+
many non-duplicate contacts are to be added.
312+
313+
314+
The following sequence diagram shows how the import command works.
315+
316+
![ImportSequenceDiagram](images/ImportSequenceDiagram.png)
317+
318+
319+
The following activity diagram summarizes what happens when a user executes an
320+
import command:
321+
322+
![ImportActivityDiagram](images/ImportActivityDiagram.png)
323+
324+
### Design Considerations:
325+
- **Alternative 1 (current choice):** ImportCommand#execute takes in a string to
326+
determine which faculty of in-built contacts to import
327+
- Pros:
328+
- User input is easily parsed (as it is just a string), faster to read and
329+
execute the command
330+
- Cons:
331+
- Possibly bad OOP design, ImportCommand#execute should take in a Faculty object
332+
333+
- **Alternative 2:** ImportCommand#execute takes in a Faculty object instead of a string
334+
to determine which faculty of in-built contacts to import
335+
- Pros:
336+
- Better OOP design then simply taking in a string
337+
- Cons:
338+
- Input will take longer to parse as the string input has to be parsed into
339+
a faculty object to be used as input to ImportCommand#execute
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@startuml
2+
start
3+
:User executes import command;
4+
'Since the beta syntax does not support placing the condition outside the
5+
'diamond we place it as the true branch instead.
6+
7+
if () then ([faculty is valid])
8+
:Faculty contacts are retrieved;
9+
:Non-duplicate contacts are added;
10+
: Display success message;
11+
else ([else])
12+
: Display error message;
13+
endif
14+
stop
15+
@enduml
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
@startuml
2+
!include style.puml
3+
4+
box Logic LOGIC_COLOR_T1
5+
participant ":LogicManager" as LogicManager LOGIC_COLOR
6+
participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR
7+
participant ":ImportCommandParser" as ImportCommandParser LOGIC_COLOR
8+
participant "d:ImportCommand" as ImportCommand LOGIC_COLOR
9+
participant ":CommandResult" as CommandResult LOGIC_COLOR
10+
end box
11+
12+
box Model MODEL_COLOR_T1
13+
participant ":Model" as Model MODEL_COLOR
14+
end box
15+
16+
[-> LogicManager : execute("import soc")
17+
activate LogicManager
18+
19+
LogicManager -> AddressBookParser : parseCommand("import soc")
20+
activate AddressBookParser
21+
22+
create ImportCommandParser
23+
AddressBookParser -> ImportCommandParser
24+
activate ImportCommandParser
25+
26+
AddressBookParser -> ImportCommandParser : parse("soc")
27+
activate ImportCommandParser
28+
29+
create ImportCommand
30+
ImportCommandParser -> ImportCommand
31+
activate ImportCommand
32+
33+
ImportCommand --> ImportCommandParser : d
34+
deactivate ImportCommand
35+
36+
ImportCommandParser --> AddressBookParser : d
37+
deactivate ImportCommandParser
38+
'Hidden arrow to position the destroy marker below the end of the activation bar.
39+
ImportCommandParser -[hidden]-> AddressBookParser
40+
destroy ImportCommandParser
41+
42+
AddressBookParser --> LogicManager : d
43+
deactivate AddressBookParser
44+
45+
LogicManager -> ImportCommand : execute()
46+
activate ImportCommand
47+
48+
49+
ImportCommand -> Model : addPerson(toAdd)
50+
activate Model
51+
52+
Model --> ImportCommand
53+
deactivate Model
54+
55+
create CommandResult
56+
ImportCommand -> CommandResult
57+
activate CommandResult
58+
59+
CommandResult --> ImportCommand
60+
deactivate CommandResult
61+
62+
ImportCommand --> LogicManager : result
63+
deactivate ImportCommand
64+
65+
[<--LogicManager
66+
deactivate LogicManager
67+
@enduml
15.4 KB
Loading
33.4 KB
Loading

src/main/java/seedu/address/logic/commands/ImportCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public CommandResult execute(Model model) throws CommandException {
4343
requireNonNull(model);
4444
String duplicates = "";
4545
String successes = "";
46+
int duplicateCounter = 0;
4647
ArrayList<Person> importList = new ArrayList<Person>();
4748

4849
if (faculty.equalsIgnoreCase("soc")) {
@@ -56,14 +57,15 @@ public CommandResult execute(Model model) throws CommandException {
5657
for (Person toAdd : importList) {
5758
if (model.hasPerson(toAdd)) {
5859
duplicates += toAdd.getName() + MESSAGE_DUPLICATE_IMPORT + "\n";
60+
duplicateCounter++;
5961
continue;
6062
} else {
6163
duplicates += toAdd.getName() + " was successfully imported\n";
6264
successes += "\n" + toAdd.getName();
6365
}
6466
model.addPerson(toAdd);
6567
}
66-
if (duplicates.length() > 0) {
68+
if (duplicateCounter == importList.size()) {
6769
throw new CommandException(duplicates);
6870
}
6971
return new CommandResult(String.format(MESSAGE_SUCCESS + successes));

0 commit comments

Comments
 (0)