Skip to content

Commit

Permalink
Merge pull request #93 from chowyiyin/branch-v1.2
Browse files Browse the repository at this point in the history
Branch v1.2
  • Loading branch information
larrylawl committed Oct 15, 2019
2 parents 6cbebbf + 6c7e77b commit 8ab7105
Show file tree
Hide file tree
Showing 53 changed files with 2,503 additions and 233 deletions.
23 changes: 23 additions & 0 deletions docs/DeveloperGuide.adoc
Expand Up @@ -525,6 +525,29 @@ Use case ends.
+
Use case resumes at step 2.

=== Use case: Merging a duplicate person with different fields

*MSS*

1. User requests to add a person.
2. AddressBook indicates that this person already exists and prompts a merge.
3. User indicates whether or not to edit this profile.
4. A different field is displayed and asks the user whether or not to update this field.
5. Steps 3 and 4 repeat until decisions whether or not to merge different fields have been completed.
+
Use case ends.

*Extensions*

[none]
* *a. User indicates to stop the merging process.
+
[none]
** 3a1. The user inputs an invalid command.
** 3a2. The AddressBook indicates an error and prompts the merge again.
+
Use case resumes at 4.

_{More to be added}_

[appendix]
Expand Down
26 changes: 11 additions & 15 deletions docs/UserGuide.adoc
Expand Up @@ -62,26 +62,22 @@ Format: `help`
=== Adding a person: `add`

Adds a person to the list of people +
Format: `add n/NAME ic/NRIC p/PHONE_NUMBER e/EMAIL a/ADDRESS dob/DATE_OF_BIRTH [pol/POLICY]... [t/TAG]...​`
Format: `add n/NAME ic/NRIC p/PHONE_NUMBER e/EMAIL a/ADDRESS dob/DATE_OF_BIRTH`

****
* A person can have any number of tags (including 0).
* A person can have any number of policies (including 0).
* Birthdays are in the form `DD.MM.YYYY`.
****

Examples:

* `add n/John Doe ic/S9999999J p/98765432 e/johnd@example.com a/John street, block 123, #01-01 b/12.09.1980 pol/1 pol/2 t/diabetic t/smoker`
* `add n/John Doe ic/S9999999J p/98765432 e/johnd@example.com a/John street, block 123, #01-01 dob/12.09.1980`

=== Adding a policy: `addpolicy`

Adds a policy to the list of policies +
Format: `addpolicy n/NAME d/DESCRIPTION c/[days/DAYS_VALID][months/MONTHS_VALID][years/YEARS_VALID] p/PRICE [sa/START_AGE] [ea/END_AGE] [t/TAGS]...[cri/CRITERIA]...`
Format: `addpolicy n/NAME d/DESCRIPTION c/[days/DAYS_VALID][months/MONTHS_VALID][years/YEARS_VALID] p/PRICE [sa/START_AGE] [ea/END_AGE]`

****
* A policy can have any number of tags (including 0).
* A policy can have any number of criteria (including 0).
* Coverage time period is specified in days, years and months, in the format days/D months/M years/Y (e.g. 20 days, 11 months, 5 years is represented by days/20 months/11 years/5)
* Price is specified in dollar ($) units.
****
Expand Down Expand Up @@ -450,7 +446,7 @@ if present.

Examples:

`add n/John Doe ic/Q9999999J p/98765432 e/johnd@example.com a/John street, block 123, #01-01 b/12.09.1980 pol/1 t/high-priority` +
`add n/John Doe ic/Q9999999J p/98765432 e/johnd@example.com a/John street, block 123, #01-01 dob/12.09.1980 pol/1 t/high-priority` +

Expected Output:
```
Expand All @@ -471,7 +467,7 @@ if present.

Examples:

`add n/John Doe ic/S9999999J p/48765432 e/johnd@example.com a/John street, block 123, #01-01 b/12.09.1980 pol/1 t/high-priority` +
`add n/John Doe ic/S9999999J p/48765432 e/johnd@example.com a/John street, block 123, #01-01 dob/12.09.1980 pol/1 t/high-priority` +

Expected Output:
```
Expand All @@ -492,7 +488,7 @@ if present.

Examples:

`add n/John Doe ic/S9999999J p/98765432 e/@example.com a/John street, block 123, #01-01 b/12.09.1980 pol/SeniorCare t/high-priority` +
`add n/John Doe ic/S9999999J p/98765432 e/@example.com a/John street, block 123, #01-01 dob/12.09.1980` +

Expected Output:
```
Expand All @@ -512,7 +508,7 @@ Returns a warning message to inform the user of a potential typo in email addres

Examples:

`add n/John Doe ic/Q9999999J p/48765432 e/johnd@gmal.com a/John street, block 123, #01-01 b/12.09.1980 pol/SeniorCare t/high-priority` +
`add n/John Doe ic/Q9999999J p/48765432 e/johnd@gmal.com a/John street, block 123, #01-01 dob/12.09.1980` +

Expected Output:
```
Expand Down Expand Up @@ -569,7 +565,7 @@ For each different attribute, there will be a prompt to suggest a change from th

Examples:

`add n/John Doe ic/S9999999J p/91234567 e/johndoe@example.com a/John street, block 123, #01-01 age/30 pol/SeniorCare`
`add n/John Doe ic/S9999999J p/91234567 e/johndoe@example.com a/John street, block 123, #01-01 age/30`

Expected Output:
```
Expand Down Expand Up @@ -807,9 +803,9 @@ _{explain how the user can enable/disable data encryption}_

== Command Summary

* *Add Person* `add n/NAME ic/NRIC p/PHONE_NUMBER e/EMAIL a/ADDRESS dob/DATE_OF_BIRTH [t/TAG]…​` +
e.g. `add n/John Doe ic/S9999999J p/98765432 e/johnd@example.com a/John street, block 123, #01-01 b/12.09.1980 t/high-priority`
* *Add Policy* `addpolicy add pol n/NAME d/DESCRIPTION c/c/[days/DAYS_VALID][months/MONTHS_VALID][years/YEARS_VALID] p/PRICE [sa/START_AGE] [ea/END_AGE]... [t/TAGS]...` +
* *Add Person* `add n/NAME ic/NRIC p/PHONE_NUMBER e/EMAIL a/ADDRESS dob/DATE_OF_BIRTH​` +
e.g. `add n/John Doe ic/S9999999J p/98765432 e/johnd@example.com a/John street, block 123, #01-01 dob/12.09.1980`
* *Add Policy* `addpolicy addpolicy n/NAME d/DESCRIPTION c/[days/DAYS_VALID][months/MONTHS_VALID][years/YEARS_VALID] p/PRICE [sa/START_AGE] [ea/END_AGE]...` +
e.g. `add pol n/SeniorCare d/care for seniors c/months/10 p/$50000 [sa/50 ea/75]`
* *List People* : `listpeople`
* *List Policy* : `listpolicy`
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Expand Up @@ -10,5 +10,7 @@ public class Messages {
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_INVALID_POLICY_DISPLAYED_INDEX = "The policy index provided is invalid";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_UNKNOWN_MERGE_COMMAND = "Unknown command. %1$s. If you wish to stop merging"
+ " this profile, please type stop.";

}
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Expand Up @@ -15,6 +15,17 @@
* API of the Logic component
*/
public interface Logic {
/**
* Executes the command and returns the result. This method is used to differentiate between
* an invalid merge command input by the user and a system called merge command.
* @param commandText The command as entered by the user.
* @param isSystemInput Whether the command was invoked by user or the program.
* @return the result of the command execution.
* @throws CommandException If an error occurs during command execution.
* @throws ParseException If an error occurs during parsing.
*/
CommandResult execute(String commandText, boolean isSystemInput) throws CommandException, ParseException;

/**
* Executes the command and returns the result.
* @param commandText The command as entered by the user.
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Expand Up @@ -52,6 +52,23 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
return commandResult;
}

@Override
public CommandResult execute(String commandText, boolean isSystemInput) throws CommandException, ParseException {
logger.info("----------------[USER COMMAND][" + commandText + "]");

CommandResult commandResult;
Command command = addressBookParser.parseCommand(commandText, isSystemInput);
commandResult = command.execute(model);

try {
storage.saveAddressBook(model.getAddressBook());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}

return commandResult;
}

@Override
public ReadOnlyAddressBook getAddressBook() {
return model.getAddressBook();
Expand Down
59 changes: 43 additions & 16 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Expand Up @@ -7,10 +7,9 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_POLICY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import seedu.address.logic.commands.exceptions.DuplicatePersonException;
import seedu.address.logic.commands.exceptions.DuplicatePersonWithMergeException;
import seedu.address.logic.commands.exceptions.DuplicatePersonWithoutMergeException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

Expand All @@ -28,23 +27,20 @@ public class AddCommand extends Command {
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_DATE_OF_BIRTH + "DATE OF BIRTH "
+ "[" + PREFIX_POLICY + "POLICY]...\n"
+ "[" + PREFIX_TAG + "TAG]...\n"
+ PREFIX_DATE_OF_BIRTH + "DATE OF BIRTH\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_NRIC + "S000001J "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "johnd@example.com "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_DATE_OF_BIRTH + "12.12.1912 "
+ PREFIX_POLICY + "Senior Care "
+ PREFIX_TAG + "diabetic "
+ PREFIX_TAG + "elderly ";
+ PREFIX_DATE_OF_BIRTH + "12.12.1912 ";

public static final String MESSAGE_SUCCESS = "New person added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book\n";
public static final String MESSAGE_INPUT_INFORMATION_HEADER = "Your input:\n%1$s";
public static final String DUPLICATE_PERSON_MERGE_PROMPT = "Do you wish to edit this person's profile?";
public static final String NEW_LINE = "\n";

private final Person toAdd;

Expand All @@ -57,21 +53,52 @@ public AddCommand(Person person) {
}

@Override
public CommandResult execute(Model model) throws DuplicatePersonException {
public CommandResult execute(Model model) throws DuplicatePersonWithoutMergeException,
DuplicatePersonWithMergeException {
requireNonNull(model);

if (model.hasPerson(toAdd)) {
StringBuilder exceptionMessage = new StringBuilder();
exceptionMessage.append(MESSAGE_DUPLICATE_PERSON);
exceptionMessage.append(model.getPerson(toAdd).toString() + "\n");
exceptionMessage.append(DUPLICATE_PERSON_MERGE_PROMPT);
throw new DuplicatePersonException(exceptionMessage.toString());
String exceptionMessage = "";
if (toAdd.hasEqualCompulsoryFields(model.getPerson(toAdd))) {
exceptionMessage = generateExceptionMessageWithoutMergePrompt(model.getPerson(toAdd));
throw new DuplicatePersonWithoutMergeException(exceptionMessage);
} else {
exceptionMessage = generateExceptionMessageWithMergePrompt(model.getPerson(toAdd));
throw new DuplicatePersonWithMergeException(exceptionMessage);
}
}

model.addPerson(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
}

/**
* Generates an exception message with a merge prompt.
* @param original Original person in the addressbook.
* @return The exception message to be thrown.
*/
public String generateExceptionMessageWithMergePrompt(Person original) {
StringBuilder exceptionMessage = new StringBuilder();
exceptionMessage.append(MESSAGE_DUPLICATE_PERSON);
exceptionMessage.append(original.toString() + NEW_LINE);
exceptionMessage.append(String.format(MESSAGE_INPUT_INFORMATION_HEADER, toAdd.toString()) + NEW_LINE);
exceptionMessage.append(DUPLICATE_PERSON_MERGE_PROMPT);
return exceptionMessage.toString();
}

/**
* Generates an exception message without a merge prompt. This method is used if the input person has all the same
* compulsory data fields as the original person.
* @param original Original person in the addressbook.
* @return The exception message to be thrown.
*/
public String generateExceptionMessageWithoutMergePrompt(Person original) {
StringBuilder exceptionMessage = new StringBuilder();
exceptionMessage.append(MESSAGE_DUPLICATE_PERSON);
exceptionMessage.append(original.toString());
return exceptionMessage.toString();
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/seedu/address/logic/commands/DoNotMergeCommand.java
@@ -0,0 +1,47 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import java.util.ArrayList;

import seedu.address.logic.commands.exceptions.DuplicatePersonWithMergeException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

/**
* Adds a person to the address book.
*/
public class DoNotMergeCommand extends Command {

public static final String COMMAND_WORD = "nmerge";

public static final String MESSAGE_SUCCESS = "This profile was not updated : %1$s.";

private final Person inputPerson;
private Person originalPerson;
private ArrayList<String[]> differentFields = new ArrayList<>();


/**
* Creates an Merge Command to update the original {@code Person} to the new {@code Person}
*/
public DoNotMergeCommand(Person inputPerson) {
requireNonNull(inputPerson);
this.inputPerson = inputPerson;
}

@Override
public CommandResult execute(Model model) throws DuplicatePersonWithMergeException {
requireNonNull(model);
StringBuilder prompt = new StringBuilder();
this.originalPerson = model.getPerson(inputPerson);
return new CommandResult(String.format(MESSAGE_SUCCESS, originalPerson));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof DoNotMergeCommand // instanceof handles nulls
&& inputPerson.equals(((DoNotMergeCommand) other).inputPerson));
}
}
19 changes: 19 additions & 0 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Expand Up @@ -68,6 +68,11 @@ public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) {
this.editPersonDescriptor = new EditPersonDescriptor(editPersonDescriptor);
}

protected EditCommand() {
this.index = null;
this.editPersonDescriptor = null;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
Expand All @@ -89,6 +94,20 @@ public CommandResult execute(Model model) throws CommandException {
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedPerson));
}

/**
* Performs an edit of one field of a {@code Person} in the addressbook. This method should only be called by a
* {@code MergeConfirmedCommand}/
* @param person Person in the addressbook.
* @param editPersonDescriptor {@code EditPersonDescriptor} for person with updated field.
* @param model Model that is used for the address book.
* @return The updated {@code Person}.
*/
protected Person executeForMerge(Person person, EditPersonDescriptor editPersonDescriptor, Model model) {
Person editedPerson = createEditedPerson(person, editPersonDescriptor);
model.setPerson(person, editedPerson);
return editedPerson;
}

/**
* Creates and returns a {@code Person} with the details of {@code personToEdit}
* edited with {@code editPersonDescriptor}.
Expand Down

0 comments on commit 8ab7105

Please sign in to comment.