Skip to content

Commit

Permalink
Merge bf98801 into 0675147
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenngoclinhchi committed Oct 23, 2018
2 parents 0675147 + bf98801 commit cd73f31
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
Binary file modified docs/diagrams/DeleteByDateEntrySequenceDiagram.pptx
Binary file not shown.
Binary file added docs/diagrams/ExportExcelSequenceDiagram.pptx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
public class DeleteCommandByDateEntry extends Command {
public static final String COMMAND_WORD = "delete_date";
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Delete the all records identified by the date number used in the displayed record list.\n"
+ ": Deletes the all records identified by the date number used in the displayed record list.\n"
+ "PARAMERERS: DATE (Must follow the format dd-mm-yyyy).\n"
+ "Example: "
+ COMMAND_WORD
+ "31-03-1999";
+ " 31-03-1999";

public static final String MESSAGE_DELETE_RECORD_SUCCESS = "Deleted all records whose date is %1$s";
public static final String MESSAGE_DELETE_RECORDS_SUCCESS = "Deleted all records whose date is %1$s";

private static final Logger logger = LogsCenter.getLogger(DeleteCommandByDateEntry.class);

Expand All @@ -38,23 +38,25 @@ public DeleteCommandByDateEntry(Date targetDate) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
List<Record> lastShownList = model.getFilteredRecordList();
Boolean targetRecordExist = Boolean.FALSE;
for (Record targetRecord : lastShownList) {
requireNonNull(model);
List<Record> lastShownList = model.getFilteredRecordList();
for (int i = lastShownList.size() - 1; i >= 0; i--) {
Record targetRecord = lastShownList.get(i);
logger.info(String.format(
"The date required is: %1$s, the date shown is %2$s\n",
"---------------------------------------------The date required is: %1$s, the date shown is %2$s\n",
targetDate.getValue(), targetRecord.getDate().getValue()));
if (targetRecord.isSameDateRecord(targetDate)) {
model.deleteRecord(targetRecord);
model.commitFinancialPlanner();
targetRecordExist = Boolean.TRUE;
}
}
if (!targetRecordExist) {
logger.info("The record does not exist.\n");
throw new CommandException(Messages.MESSAGE_NONEXISTENT_RECORD_DISPLAYED_DATE);
} else {
return new CommandResult(String.format(MESSAGE_DELETE_RECORD_SUCCESS, targetDate.value));
model.commitFinancialPlanner();
return new CommandResult(String.format(MESSAGE_DELETE_RECORDS_SUCCESS, targetDate.value));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@ public class DeleteCommandByDateEntryTest {

@Test
public void execute_validDateUnfilteredList_success() {
List<Record> recordsToDelete = listAllRecordToDelete(model, TypicalDates.DATE_FIRST_INDEX_DATE);
Date targetDate = TypicalDates.DATE_FIRST_INDEX_DATE;
List<Record> records = filteredRecordList(model);

DeleteCommandByDateEntry deleteCommandByDateEntry =
new DeleteCommandByDateEntry(TypicalDates.DATE_FIRST_INDEX_DATE);

String expectedMessage = String.format(
DeleteCommandByDateEntry.MESSAGE_DELETE_RECORD_SUCCESS, TypicalDates.DATE_FIRST_INDEX_DATE);
DeleteCommandByDateEntry.MESSAGE_DELETE_RECORDS_SUCCESS, TypicalDates.DATE_FIRST_INDEX_DATE);

ModelManager expectedModel = new ModelManager(model.getFinancialPlanner(), new UserPrefs());
expectedModel.deleteListRecord(recordsToDelete);
expectedModel.commitFinancialPlanner();

for (int i = records.size() - 1; i >= 0; i--) {
if (records.get(i).getDate().equals(targetDate)) {
expectedModel.deleteRecord(records.get(i));
expectedModel.commitFinancialPlanner();
}
}
CommandTestUtil.assertCommandSuccess(
deleteCommandByDateEntry, model, commandHistory, expectedMessage, expectedModel);
}
Expand Down Expand Up @@ -71,12 +75,18 @@ public void execute_invalidIndexFilteredList_throwsCommandException() {

@Test
public void executeUndoRedo_validIndexUnfilteredList_success() throws Exception {
List<Record> recordsToDelete = listAllRecordToDelete(model, TypicalDates.DATE_FIRST_INDEX_DATE);
Date targetDate = TypicalDates.DATE_FIRST_INDEX_DATE;
List<Record> recordsToDelete = listAllRecordToDelete(model, targetDate);

DeleteCommandByDateEntry deleteCommandByDateEntry =
new DeleteCommandByDateEntry(TypicalDates.DATE_FIRST_INDEX_DATE);

Model expectedModel = new ModelManager(model.getFinancialPlanner(), new UserPrefs());
expectedModel.deleteListRecord(recordsToDelete);

for (Record record : recordsToDelete) {
expectedModel.deleteRecord(record);
}

expectedModel.commitFinancialPlanner();

//delete the Records have required date
Expand Down Expand Up @@ -116,13 +126,19 @@ public void executeUndoRedo_nonexistentDateUnfilteredList_failure() {
*/

@Test
public void executeUndoRedo_exsistentDateFilteredList_sameRecordDeleted()
throws Exception {
public void executeUndoRedo_exsistentDateFilteredList_sameRecordDeleted() throws Exception {
DeleteCommandByDateEntry deleteCommandByDateEntry =
new DeleteCommandByDateEntry(TypicalDates.DATE_FIRST_INDEX_DATE);
Model expectedModel = new ModelManager(model.getFinancialPlanner(), new UserPrefs());
List<Record> recordsToDelete = listAllRecordToDelete(model, TypicalDates.DATE_FIRST_INDEX_DATE);
expectedModel.deleteListRecord(recordsToDelete);

Date date = TypicalDates.DATE_FIRST_INDEX_DATE;

List<Record> records = filteredRecordList(model);
List<Record> recordsToDelete = listAllRecordToDelete(model, date);

for (Record record : recordsToDelete) {
expectedModel.deleteRecord(record);
}
expectedModel.commitFinancialPlanner();

// delete -> deletes second record in unfiltered record list / first record in filtered record list
Expand Down

0 comments on commit cd73f31

Please sign in to comment.