Skip to content

Commit a8b3675

Browse files
Merge pull request #102 from KumChaiYin/101-dg-batch-delete
101 dg batch delete
2 parents 61cc7a4 + 6d50cee commit a8b3675

File tree

8 files changed

+150
-3
lines changed

8 files changed

+150
-3
lines changed

docs/DeveloperGuide.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,44 @@ Classes used by multiple components are in the `seedu.addressbook.commons` packa
154154

155155
This section describes some noteworthy details on how certain features are implemented.
156156

157+
<br>
158+
159+
### `batchdelete`
160+
161+
The `batchdelete` command allows users to batch delete people whose policy expiry is in the specified month and year.
162+
163+
<br>
164+
165+
#### Implementation:
166+
The batch delete mechanism is facilitated by `DeleteMonth`
167+
168+
It is also facilitated by the operation:
169+
* `ModelManager#batchDeleteWithPredicate(Predicate<Person> predicate)` - batch delete all people in address book who fulfil the given predicate.
170+
171+
This operation is exposed in the `Model` interface as `Model# batchDeleteWithPredicate(Predicate<Person> predicate)`
172+
173+
**The following sequence diagram shows how the batch delete operation works:**
174+
175+
![BatchDeleteSequenceDiagram1](images/BatchDeleteSequenceDiagram1.png)
176+
177+
* instance of DeleteMonth is constructed to construct a BatchDeleteCommand
178+
179+
<div markdown="span" class="alert alert-info">:information_source: **Note:** The lifeline for `BatchDeleteCommand` and `BatchDeleteCommandParser` should end at the destroy marker (X) but due to a limitation of PlantUML, the lifeline reaches the end of diagram.
180+
181+
</div>
182+
183+
![BatchDeleteSequenceDiagram2](images/BatchDeleteSequenceDiagram2.png)
184+
185+
* Calling method updateFilteredPersonList to get all people in the addressBook
186+
* Using predicate p to get list of people to delete
187+
* Delete all people in the list and return all people left in addressBook
188+
189+
#### Design consideration:
190+
* Users may use batch delete to delete all people whose policy expiry is in the specified month and year. For example, delete people didn’t contact the user to renew their policies for one year.
191+
* Besides, if users leave an insurance company, they may like to delete people purchase policy from that company.
192+
* Therefore, `Model# batchDeleteWithPredicate(Predicate<Person> predicate)` is introduced to allow batch delete by month or company.
193+
194+
157195
### \[Proposed\] Undo/redo feature
158196

159197
#### Proposed Implementation
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
@startuml
2+
!include style.puml
3+
skinparam ArrowFontStyle plain
4+
5+
box Logic LOGIC_COLOR_T1
6+
participant ":LogicManager" as LogicManager LOGIC_COLOR
7+
participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR
8+
participant "bp:BatchDeleteCommandParser" as BatchDeleteCommandParser LOGIC_COLOR
9+
participant "deleteMonth:DeleteMonth" as DeleteMonth LOGIC_COLOR
10+
participant "b:BatchDeleteCommand" as BatchDeleteCommand LOGIC_COLOR
11+
end box
12+
13+
[-> LogicManager : execute(batchDelete dm/09-2022)
14+
activate LogicManager
15+
16+
LogicManager -> AddressBookParser : parseCommand("batchdelete dm/09-2022")
17+
activate AddressBookParser
18+
19+
create BatchDeleteCommandParser
20+
AddressBookParser -> BatchDeleteCommandParser
21+
activate BatchDeleteCommandParser
22+
BatchDeleteCommandParser --> AddressBookParser
23+
deactivate BatchDeleteCommandParser
24+
25+
AddressBookParser -> BatchDeleteCommandParser : parse("batchdelete dm/09-2022")
26+
activate BatchDeleteCommandParser
27+
28+
create DeleteMonth
29+
BatchDeleteCommandParser -> DeleteMonth
30+
activate DeleteMonth
31+
DeleteMonth --> BatchDeleteCommandParser : deleteMonth
32+
deactivate DeleteMonth
33+
34+
create BatchDeleteCommand
35+
BatchDeleteCommandParser -> BatchDeleteCommand : BatchDeleteCommand(deleteMonth)
36+
activate BatchDeleteCommand
37+
38+
BatchDeleteCommand --> BatchDeleteCommandParser : b
39+
deactivate BatchDeleteCommand
40+
BatchDeleteCommandParser --> AddressBookParser : b
41+
deactivate BatchDeleteCommandParser
42+
43+
AddressBookParser --> LogicManager : b
44+
deactivate AddressBookParser
45+
46+
destroy BatchDeleteCommandParser
47+
48+
BatchDeleteCommand -[hidden]-> LogicManager : empty row
49+
ref over LogicManager, BatchDeleteCommand : execute BatchDeleteCommand
50+
51+
BatchDeleteCommand -[hidden]-> LogicManager : empty row
52+
destroy BatchDeleteCommand
53+
54+
[<--LogicManager
55+
deactivate LogicManager
56+
@enduml
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
@startuml
2+
mainframe **sd** execute BatchDeleteCommand
3+
!include style.puml
4+
skinparam ArrowFontStyle plain
5+
6+
box Logic LOGIC_COLOR_T1
7+
participant ":LogicManager" as LogicManager LOGIC_COLOR
8+
participant "b:BatchDeleteCommand" as BatchDeleteCommand LOGIC_COLOR
9+
participant "p:PolicyExpiryInDeleteMonthPredicate" as PolicyExpiryInDeleteMonthPredicate LOGIC_COLOR
10+
end box
11+
12+
box Model MODEL_COLOR_T1
13+
participant ":Model" as Model MODEL_COLOR
14+
participant ":AddressBook" as AddressBook MODEL_COLOR
15+
end box
16+
17+
LogicManager -> BatchDeleteCommand : execute()
18+
activate BatchDeleteCommand
19+
20+
create PolicyExpiryInDeleteMonthPredicate
21+
BatchDeleteCommand -> PolicyExpiryInDeleteMonthPredicate : PolicyExpiryInDeleteMonthPredicate(month)
22+
activate PolicyExpiryInDeleteMonthPredicate
23+
24+
PolicyExpiryInDeleteMonthPredicate --> BatchDeleteCommand : p
25+
deactivate PolicyExpiryInDeleteMonthPredicate
26+
27+
BatchDeleteCommand -> Model : batchDeleteWithPredicate(p)
28+
activate Model
29+
30+
Model -> Model : updateFilteredPersonList()
31+
Model -> Model : updateFilteredPersonList(predicate)
32+
Model -> Model : getFilteredPersonList()
33+
activate Model
34+
Model --> Model : listToDelete
35+
deactivate Model
36+
37+
loop all Person in listToDelete
38+
Model -> AddressBook : removePerson(person)
39+
activate AddressBook
40+
AddressBook --> Model :
41+
deactivate AddressBook
42+
end
43+
44+
Model -> Model : updateFilteredPersonList();
45+
46+
Model --> BatchDeleteCommand
47+
deactivate Model
48+
49+
BatchDeleteCommand --> LogicManager : result
50+
deactivate BatchDeleteCommand
51+
BatchDeleteCommand -[hidden]-> LogicManager : result
52+
53+
54+
@enduml
38.5 KB
Loading
37.8 KB
Loading

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
public class BatchDeleteCommand extends Command {
1919

20-
public static final String COMMAND_WORD = "batchDelete";
20+
public static final String COMMAND_WORD = "batchdelete";
2121

2222
public static final String MESSAGE_USAGE = COMMAND_WORD + ": batch delete people whose policy expiry date "
2323
+ "is in the corresponding month and year. "

src/main/java/seedu/address/logic/parser/RemindCommandParser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public RemindCommand parse(String args) throws ParseException {
2828
throw new ParseException(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT,
2929
Messages.MESSAGE_NOT_POSITIVE_NUMBER));
3030
}
31-
3231
return new RemindCommand(new RemindPredicate(parsedArgs));
3332
} catch (NumberFormatException e) {
3433
throw new ParseException(String.format(Messages.MESSAGE_INVALID_COMMAND_FORMAT,

src/main/java/seedu/address/model/ModelManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void batchDeleteWithPredicate(Predicate<Person> predicate) {
148148
requireNonNull(predicate);
149149
updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
150150

151-
filteredPersons.setPredicate(predicate);
151+
this.updateFilteredPersonList(predicate);
152152
ObservableList<Person> listToDelete = this.getFilteredPersonList();
153153

154154
List<Person> copyList = new ArrayList<>(listToDelete);

0 commit comments

Comments
 (0)