diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index e0768156d41..2ed4f6a9814 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -35,6 +35,7 @@ import seedu.address.model.person.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.person.Remark; import seedu.address.model.policy.Company; import seedu.address.model.policy.Policy; import seedu.address.model.policy.PolicyDate; @@ -132,10 +133,11 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Nric updatedNric = editPersonDescriptor.getNric().orElse(personToEdit.getNric()); LicencePlate updatedLicencePlate = editPersonDescriptor.getLicencePlate().orElse(personToEdit.getLicencePlate()); + Remark updatedRemark = personToEdit.getRemark(); // edit command does not allow editing remarks Policy updatedPolicy = getUpdatedPolicy(personToEdit, editPersonDescriptor); return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, updatedNric, - updatedLicencePlate, updatedPolicy); + updatedLicencePlate, updatedRemark, updatedPolicy); } private static Policy getUpdatedPolicy(Person personToEdit, EditPersonDescriptor editPersonDescriptor) { diff --git a/src/main/java/seedu/address/logic/commands/RemarkCommand.java b/src/main/java/seedu/address/logic/commands/RemarkCommand.java new file mode 100644 index 00000000000..246d47f3285 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/RemarkCommand.java @@ -0,0 +1,91 @@ +package seedu.address.logic.commands; + +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; + +import java.util.List; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.person.Person; +import seedu.address.model.person.Remark; + +/** + * Changes the remark of an existing person in the address book. + */ +public class RemarkCommand extends Command { + public static final String COMMAND_WORD = "remark"; + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Edits the remark of the person identified " + + "by the index number used in the last person listing. " + + "Existing remark will be overwritten by the input.\n" + + "Parameters: INDEX (must be a positive integer) " + + "r/ [REMARK]\n" + + "Example: " + COMMAND_WORD + " 1 " + + "r/ Likes to swim."; + public static final String MESSAGE_ARGUMENTS = "Index: %1$d, Remark: %2$s"; + public static final String MESSAGE_ADD_REMARK_SUCCESS = "Added remark to Person: %1$s"; + public static final String MESSAGE_DELETE_REMARK_SUCCESS = "Removed remark from Person: %1$s"; + + private final Index index; + private final Remark remark; + + /** + * @param index of the person in the filtered person list to edit the remark + * @param remark of the person to be updated to + */ + public RemarkCommand(Index index, Remark remark) { + requireAllNonNull(index, remark); + + this.index = index; + this.remark = remark; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + List lastShownList = model.getFilteredPersonList(); + + if (index.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + Person personToEdit = lastShownList.get(index.getZeroBased()); + Person editedPerson = new Person( + personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), + personToEdit.getAddress(), personToEdit.getTags(), personToEdit.getNric(), + personToEdit.getLicencePlate(), remark, personToEdit.getPolicy()); + + model.setPerson(personToEdit, editedPerson); + model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + + return new CommandResult(generateSuccessMessage(editedPerson)); + } + + /** + * Generates a command execution success message based on whether + * the remark is added to or removed from + * {@code personToEdit}. + */ + private String generateSuccessMessage(Person personToEdit) { + String message = !remark.value.isEmpty() ? MESSAGE_ADD_REMARK_SUCCESS : MESSAGE_DELETE_REMARK_SUCCESS; + return String.format(message, personToEdit); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof RemarkCommand)) { + return false; + } + + RemarkCommand e = (RemarkCommand) other; + return index.equals(e.index) + && remark.equals(e.remark); + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 1e3aca49f7f..ebf75992944 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -28,6 +28,7 @@ import seedu.address.model.person.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.person.Remark; import seedu.address.model.policy.Company; import seedu.address.model.policy.Policy; import seedu.address.model.policy.PolicyDate; @@ -87,6 +88,7 @@ public AddCommand parse(String args) throws ParseException { LicencePlate licencePlate = ParserUtil.parseLicencePlate(argMultimap.getValue(PREFIX_LICENCE_PLATE).get()); Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); + Remark remark = new Remark(""); if (!arePrefixesAbsent(argMultimap, PREFIX_COMPANY, PREFIX_POLICY_NUMBER, PREFIX_POLICY_ISSUE_DATE, PREFIX_POLICY_EXPIRY_DATE)) { @@ -127,7 +129,7 @@ public AddCommand parse(String args) throws ParseException { Policy policy = new Policy(company, policyNumber, policyIssueDate, policyExpiryDate); - Person person = new Person(name, phone, email, address, tagList, nric, licencePlate, policy); + Person person = new Person(name, phone, email, address, tagList, nric, licencePlate, remark, policy); return new AddCommand(person); } diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index b0d2f35250d..040087d7ca8 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -18,6 +18,7 @@ import seedu.address.logic.commands.FindCommand; import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.RemarkCommand; import seedu.address.logic.commands.RemindCommand; import seedu.address.logic.commands.SortCommand; import seedu.address.logic.parser.exceptions.ParseException; @@ -89,6 +90,9 @@ public Command parseCommand(String userInput) throws ParseException { case BatchDeleteCommand.COMMAND_WORD: return new BatchDeleteCommandParser().parse(arguments); + case RemarkCommand.COMMAND_WORD: + return new RemarkCommandParser().parse(arguments); + default: logger.finer("This user input caused a ParseException: " + userInput); throw new ParseException(MESSAGE_UNKNOWN_COMMAND); diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 2d77e4f5ac8..edca69b40b1 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -18,4 +18,5 @@ public class CliSyntax { public static final Prefix PREFIX_POLICY_ISSUE_DATE = new Prefix("pi/"); public static final Prefix PREFIX_POLICY_EXPIRY_DATE = new Prefix("pe/"); public static final Prefix PREFIX_DELETE_MONTH = new Prefix("dm/"); + public static final Prefix PREFIX_REMARK = new Prefix("r/"); } diff --git a/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java new file mode 100644 index 00000000000..b640aaabc71 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/RemarkCommandParser.java @@ -0,0 +1,39 @@ +package seedu.address.logic.parser; + +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK; + +import seedu.address.commons.core.index.Index; +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.logic.commands.RemarkCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.Remark; + +/** + * Parses input arguments and creates a new RemarkCommand object + */ +public class RemarkCommandParser { + /** + * Parses the given {@code String} of arguments in the context of the RemarkCommand + * and returns a RemarkCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public RemarkCommand parse(String args) throws ParseException { + requireNonNull(args); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, + PREFIX_REMARK); + + Index index; + try { + index = ParserUtil.parseIndex(argMultimap.getPreamble()); + } catch (IllegalValueException ive) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, + RemarkCommand.MESSAGE_USAGE), ive); + } + + String remark = argMultimap.getValue(PREFIX_REMARK).orElse(""); + + return new RemarkCommand(index, new Remark(remark)); + } +} diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index e14c96ecb61..52a30a41dd2 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -31,14 +31,14 @@ public class Person { private final Nric nric; private final LicencePlate licencePlate; private final Policy policy; - + private final Remark remark; /** * Every field must be present and not null. * In the case of leads with null policy fields, default values will be put in place by the respective classes. */ public Person(Name name, Phone phone, Email email, Address address, Set tags, Nric nric, - LicencePlate licencePlate, Policy policy) { - requireAllNonNull(name, phone, email, nric, licencePlate, address, tags, policy); + LicencePlate licencePlate, Remark remark, Policy policy) { + requireAllNonNull(name, phone, email, nric, licencePlate, address, tags, remark, policy); this.name = name; this.phone = phone; this.email = email; @@ -47,6 +47,7 @@ public Person(Name name, Phone phone, Email email, Address address, Set tag this.nric = nric; this.licencePlate = licencePlate; this.policy = policy; + this.remark = remark; } public Name getName() { @@ -85,6 +86,10 @@ public Policy getPolicy() { return policy; } + public Remark getRemark() { + return remark; + } + /** * Returns true if both persons have the same attributes. * This defines a weaker notion of equality between two persons. @@ -157,13 +162,14 @@ public boolean equals(Object other) { && tags.equals(otherPerson.tags) && nric.equals(otherPerson.nric) && licencePlate.equals(otherPerson.licencePlate) - && policy.equals(otherPerson.policy); + && policy.equals(otherPerson.policy) + && remark.equals(otherPerson.remark); } @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, address, tags, nric, licencePlate, policy); + return Objects.hash(name, phone, email, address, tags, nric, licencePlate, remark, policy); } @Override @@ -176,6 +182,7 @@ public String toString() { .add("tags", tags) .add("nric", nric) .add("licence plate", licencePlate) + .add("remark", remark) .add("policy", policy) .toString(); } diff --git a/src/main/java/seedu/address/model/person/Remark.java b/src/main/java/seedu/address/model/person/Remark.java new file mode 100644 index 00000000000..110ca285a93 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Remark.java @@ -0,0 +1,38 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; + +/** + * Represents a Person's remark in the address book. + * Guarantees: immutable; is always valid + */ +public class Remark { + public final String value; + + /** + * Constructs a {@code Remark}. + * + * @param remark A remark of any format. + */ + public Remark(String remark) { + requireNonNull(remark); + value = remark; + } + + @Override + public String toString() { + return value; + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof Remark // instanceof handles nulls + && value.equals(((Remark) other).value)); // state check + } + + @Override + public int hashCode() { + return value.hashCode(); + } +} diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index b1b5be7e271..b5857960661 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -13,6 +13,7 @@ import seedu.address.model.person.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.person.Remark; import seedu.address.model.policy.Company; import seedu.address.model.policy.Policy; import seedu.address.model.policy.PolicyDate; @@ -23,6 +24,8 @@ * Contains utility methods for populating {@code AddressBook} with sample data. */ public class SampleDataUtil { + public static final Remark EMPTY_REMARK = new Remark(""); + public static Person[] getSamplePersons() { return new Person[]{ new Person( @@ -33,6 +36,7 @@ public static Person[] getSamplePersons() { getTagSet("friends"), new Nric("023A"), new LicencePlate("SNB9538E"), + EMPTY_REMARK, new Policy( new Company("NTUC"), new PolicyNumber("A1231X"), @@ -48,6 +52,7 @@ public static Person[] getSamplePersons() { getTagSet("colleagues", "friends"), new Nric("362D"), new LicencePlate("SLR5E"), + EMPTY_REMARK, new Policy( new Company("InsureMe"), new PolicyNumber("B3425"), @@ -63,6 +68,7 @@ public static Person[] getSamplePersons() { getTagSet("neighbours"), new Nric("743G"), new LicencePlate("SBA1234A"), + EMPTY_REMARK, new Policy( new Company("NTUC"), new PolicyNumber("B3425"), @@ -78,6 +84,7 @@ public static Person[] getSamplePersons() { getTagSet("family"), new Nric("362D"), new LicencePlate("SDN5345A"), + EMPTY_REMARK, new Policy( new Company(Company.DEFAULT_VALUE), new PolicyNumber(PolicyNumber.DEFAULT_VALUE), @@ -93,6 +100,7 @@ public static Person[] getSamplePersons() { getTagSet("classmates"), new Nric("752X"), new LicencePlate("SBP8888T"), + EMPTY_REMARK, new Policy( new Company(Company.DEFAULT_VALUE), new PolicyNumber(PolicyNumber.DEFAULT_VALUE), @@ -108,6 +116,7 @@ public static Person[] getSamplePersons() { getTagSet("colleagues"), new Nric("764J"), new LicencePlate("SJD6453Y"), + EMPTY_REMARK, new Policy( new Company(Company.DEFAULT_VALUE), new PolicyNumber(PolicyNumber.DEFAULT_VALUE), @@ -123,6 +132,7 @@ public static Person[] getSamplePersons() { getTagSet("colleagues"), new Nric("456B"), new LicencePlate("SGP5678Y"), + EMPTY_REMARK, new Policy( new Company("ABC Insurance"), new PolicyNumber("RS67890"), @@ -138,6 +148,7 @@ public static Person[] getSamplePersons() { getTagSet("friends"), new Nric("567C"), new LicencePlate("SGP6789Z"), + EMPTY_REMARK, new Policy( new Company("XYZ Insurance"), new PolicyNumber("TP12345"), @@ -153,6 +164,7 @@ public static Person[] getSamplePersons() { getTagSet("neighbors"), new Nric("123A"), new LicencePlate("SGP1234A"), + EMPTY_REMARK, new Policy( new Company("PQR Insurance"), new PolicyNumber("XY123456"), @@ -168,6 +180,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "colleagues"), new Nric("234B"), new LicencePlate("SGP2345B"), + EMPTY_REMARK, new Policy( new Company("LMN Insurance"), new PolicyNumber("YZ345678"), @@ -183,6 +196,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "shopping"), new Nric("567C"), new LicencePlate("SGP5678C"), + EMPTY_REMARK, new Policy( new Company("ABC Insurance"), new PolicyNumber("ZA987654"), @@ -198,6 +212,7 @@ public static Person[] getSamplePersons() { getTagSet("neighbors"), new Nric("789E"), new LicencePlate("SGP7890E"), + EMPTY_REMARK, new Policy( new Company("DEF Insurance"), new PolicyNumber("UT678901"), @@ -213,6 +228,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "gaming"), new Nric("890F"), new LicencePlate("SGP8901A"), + EMPTY_REMARK, new Policy( new Company("GHI Insurance"), new PolicyNumber("SR123456"), @@ -228,6 +244,7 @@ public static Person[] getSamplePersons() { getTagSet("family", "shopping"), new Nric("901G"), new LicencePlate("SGP9012G"), + EMPTY_REMARK, new Policy( new Company("JKL Insurance"), new PolicyNumber("QP654321"), @@ -243,6 +260,7 @@ public static Person[] getSamplePersons() { getTagSet("colleagues"), new Nric("012H"), new LicencePlate("SGP0123H"), + EMPTY_REMARK, new Policy( new Company("MNO Insurance"), new PolicyNumber("ST987654"), @@ -258,6 +276,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "travel"), new Nric("345K"), new LicencePlate("SGP3456K"), + EMPTY_REMARK, new Policy( new Company("PQR Insurance"), new PolicyNumber("XZ123456"), @@ -273,6 +292,7 @@ public static Person[] getSamplePersons() { getTagSet("family", "movies"), new Nric("456L"), new LicencePlate("SGP4567L"), + EMPTY_REMARK, new Policy( new Company("GHI Insurance"), new PolicyNumber("YX654321"), @@ -288,6 +308,7 @@ public static Person[] getSamplePersons() { getTagSet("neighbors", "reading"), new Nric("567M"), new LicencePlate("SGP5678M"), + EMPTY_REMARK, new Policy( new Company("JKL Insurance"), new PolicyNumber("WV987654"), @@ -303,6 +324,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "sports"), new Nric("678N"), new LicencePlate("SGP6789B"), + EMPTY_REMARK, new Policy( new Company("ABC Insurance"), new PolicyNumber("AB123456"), @@ -318,6 +340,7 @@ public static Person[] getSamplePersons() { getTagSet("family", "cooking"), new Nric("789P"), new LicencePlate("SGP7890P"), + EMPTY_REMARK, new Policy( new Company("XYZ Insurance"), new PolicyNumber("ZY654321"), @@ -333,6 +356,7 @@ public static Person[] getSamplePersons() { getTagSet("neighbors", "gardening"), new Nric("890Q"), new LicencePlate("SGP8901X"), + EMPTY_REMARK, new Policy( new Company("MNO Insurance"), new PolicyNumber("MN987654"), @@ -348,6 +372,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "reading"), new Nric("901R"), new LicencePlate("SGP9012R"), + EMPTY_REMARK, new Policy( new Company("EFG Insurance"), new PolicyNumber("EF123456"), @@ -363,6 +388,7 @@ public static Person[] getSamplePersons() { getTagSet("colleagues", "travel"), new Nric("012S"), new LicencePlate("SGP0123S"), + EMPTY_REMARK, new Policy( new Company("PQR Insurance"), new PolicyNumber("PQ987654"), @@ -378,6 +404,7 @@ public static Person[] getSamplePersons() { getTagSet("neighbors", "cooking"), new Nric("345T"), new LicencePlate("SGP3456T"), + EMPTY_REMARK, new Policy( new Company(Company.DEFAULT_VALUE), new PolicyNumber(PolicyNumber.DEFAULT_VALUE), @@ -393,6 +420,7 @@ public static Person[] getSamplePersons() { getTagSet("neighbors", "sewing"), new Nric("901F"), new LicencePlate("SGP9012G"), + EMPTY_REMARK, new Policy( new Company("DEF Insurance"), new PolicyNumber("DE123456"), @@ -408,6 +436,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "gaming"), new Nric("567Y"), new LicencePlate("SGP5678E"), + EMPTY_REMARK, new Policy( new Company(Company.DEFAULT_VALUE), new PolicyNumber(PolicyNumber.DEFAULT_VALUE), @@ -423,6 +452,7 @@ public static Person[] getSamplePersons() { getTagSet("neighbors", "gardening"), new Nric("901C"), new LicencePlate("SGP9012Z"), + EMPTY_REMARK, new Policy( new Company("GHI Insurance"), new PolicyNumber("GH123456"), @@ -438,6 +468,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "reading"), new Nric("234D"), new LicencePlate("SGP2345E"), + EMPTY_REMARK, new Policy( new Company("JKL Insurance"), new PolicyNumber("JK123456"), @@ -453,6 +484,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "fitness"), new Nric("678G"), new LicencePlate("SGP6789H"), + EMPTY_REMARK, new Policy( new Company(Company.DEFAULT_VALUE), new PolicyNumber(PolicyNumber.DEFAULT_VALUE), @@ -468,6 +500,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "cooking"), new Nric("567L"), new LicencePlate("SGP5678M"), + EMPTY_REMARK, new Policy( new Company("UVW Insurance"), new PolicyNumber("UV123456"), @@ -483,6 +516,7 @@ public static Person[] getSamplePersons() { getTagSet("neighbors", "reading"), new Nric("789M"), new LicencePlate("SGP7890H"), + EMPTY_REMARK, new Policy( new Company("WXY Insurance"), new PolicyNumber("WX123456"), @@ -498,6 +532,7 @@ public static Person[] getSamplePersons() { getTagSet("neighbors", "cooking"), new Nric("901S"), new LicencePlate("SGP9012T"), + EMPTY_REMARK, new Policy( new Company("DEF Insurance"), new PolicyNumber("DE123456"), @@ -513,6 +548,7 @@ public static Person[] getSamplePersons() { getTagSet("family", "movies"), new Nric("234U"), new LicencePlate("SGP2345X"), + EMPTY_REMARK, new Policy( new Company(Company.DEFAULT_VALUE), new PolicyNumber(PolicyNumber.DEFAULT_VALUE), @@ -528,6 +564,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "cricket"), new Nric("345E"), new LicencePlate("SGP3456J"), + EMPTY_REMARK, new Policy( new Company("PQR Insurance"), new PolicyNumber("PQ123456"), @@ -543,6 +580,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "gaming"), new Nric("901V"), new LicencePlate("SGP9012H"), + EMPTY_REMARK, new Policy( new Company("WXY Insurance"), new PolicyNumber("WX123456"), @@ -558,6 +596,7 @@ public static Person[] getSamplePersons() { getTagSet("neighbors", "music"), new Nric("567W"), new LicencePlate("SGP5678X"), + EMPTY_REMARK, new Policy( new Company("XYZ Insurance"), new PolicyNumber("XY123456"), @@ -573,6 +612,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "travel"), new Nric("901X"), new LicencePlate("SGP9012Y"), + EMPTY_REMARK, new Policy( new Company("ABC Insurance"), new PolicyNumber("AB123456"), @@ -588,6 +628,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "sports"), new Nric("567Y"), new LicencePlate("SGP5678Z"), + EMPTY_REMARK, new Policy( new Company("LMN Insurance"), new PolicyNumber("LM123456"), @@ -603,6 +644,7 @@ public static Person[] getSamplePersons() { getTagSet("neighbors", "cooking"), new Nric("345H"), new LicencePlate("SGP3456J"), + EMPTY_REMARK, new Policy( new Company("QRS Insurance"), new PolicyNumber("QR123456"), @@ -618,6 +660,7 @@ public static Person[] getSamplePersons() { getTagSet("family", "music"), new Nric("234M"), new LicencePlate("SGP2345A"), + EMPTY_REMARK, new Policy( new Company("GHI Insurance"), new PolicyNumber("GH123456"), @@ -633,6 +676,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "travel"), new Nric("901Q"), new LicencePlate("SGP9012R"), + EMPTY_REMARK, new Policy( new Company("ABC Insurance"), new PolicyNumber("AB123456"), @@ -648,6 +692,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "pets"), new Nric("678R"), new LicencePlate("SGP6789S"), + EMPTY_REMARK, new Policy( new Company(Company.DEFAULT_VALUE), new PolicyNumber(PolicyNumber.DEFAULT_VALUE), @@ -663,6 +708,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "travelling"), new Nric("901M"), new LicencePlate("SGP9012Z"), + EMPTY_REMARK, new Policy( new Company("DEF Insurance"), new PolicyNumber("DE123456"), @@ -678,6 +724,7 @@ public static Person[] getSamplePersons() { getTagSet("neighbors", "reading"), new Nric("890K"), new LicencePlate("SGP8901L"), + EMPTY_REMARK, new Policy( new Company("PQR Insurance"), new PolicyNumber("PQ123456"), @@ -693,6 +740,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "yoga"), new Nric("567D"), new LicencePlate("SGP5678E"), + EMPTY_REMARK, new Policy( new Company("XYZ Insurance"), new PolicyNumber("XY123456"), @@ -708,6 +756,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "shopping"), new Nric("234H"), new LicencePlate("SGP2345K"), + EMPTY_REMARK, new Policy( new Company("QRS Insurance"), new PolicyNumber("QR123456"), @@ -723,6 +772,7 @@ public static Person[] getSamplePersons() { getTagSet("neighbors", "cooking"), new Nric("678Y"), new LicencePlate("SGP6789H"), + EMPTY_REMARK, new Policy( new Company("ABC Insurance"), new PolicyNumber("AB123456"), @@ -738,6 +788,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "volunteering"), new Nric("901N"), new LicencePlate("SGP9012P"), + EMPTY_REMARK, new Policy( new Company("QRS Insurance"), new PolicyNumber("QR123456"), @@ -753,6 +804,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "fitness"), new Nric("567P"), new LicencePlate("SGP5678H"), + EMPTY_REMARK, new Policy( new Company(Company.DEFAULT_VALUE), new PolicyNumber(PolicyNumber.DEFAULT_VALUE), @@ -768,6 +820,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "travel"), new Nric("345S"), new LicencePlate("SGP3456T"), + EMPTY_REMARK, new Policy( new Company("PQR Insurance"), new PolicyNumber("PQ123456"), @@ -783,6 +836,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "gaming"), new Nric("901Z"), new LicencePlate("SGP9012P"), + EMPTY_REMARK, new Policy( new Company("GHI Insurance"), new PolicyNumber("GH123456"), @@ -798,6 +852,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "cooking"), new Nric("678P"), new LicencePlate("SGP6789J"), + EMPTY_REMARK, new Policy( new Company("QRS Insurance"), new PolicyNumber("QR123456"), @@ -813,6 +868,7 @@ public static Person[] getSamplePersons() { getTagSet("friends", "travelling"), new Nric("678Y"), new LicencePlate("SGP6789Z"), + EMPTY_REMARK, new Policy( new Company("ABC Insurance"), new PolicyNumber("AB123456"), diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index dbd0a82fc6c..c68147ab122 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -17,6 +17,7 @@ import seedu.address.model.person.Nric; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.person.Remark; import seedu.address.model.policy.Company; import seedu.address.model.policy.Policy; import seedu.address.model.policy.PolicyDate; @@ -37,6 +38,7 @@ class JsonAdaptedPerson { private final List tags = new ArrayList<>(); private final String nric; private final String licencePlate; + private final String remark; private final String company; private final String policyNumber; private final String policyIssueDate; @@ -49,7 +51,8 @@ class JsonAdaptedPerson { public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, @JsonProperty("tags") List tags, @JsonProperty("nric") String nric, - @JsonProperty("licencePlate") String licencePlate, @JsonProperty("company") String company, + @JsonProperty("licencePlate") String licencePlate, @JsonProperty("remark") String remark, + @JsonProperty("company") String company, @JsonProperty("policyNumber") String policyNumber, @JsonProperty("policyIssueDate") String policyIssueDate, @JsonProperty("policyExpiryDate") String policyExpiryDate) { @@ -62,6 +65,7 @@ public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone } this.nric = nric; this.licencePlate = licencePlate; + this.remark = remark; this.company = company; this.policyNumber = policyNumber; this.policyIssueDate = policyIssueDate; @@ -81,6 +85,7 @@ public JsonAdaptedPerson(Person source) { .collect(Collectors.toList())); nric = source.getNric().value; licencePlate = source.getLicencePlate().value; + remark = source.getRemark().value; Policy sourcePolicy = source.getPolicy(); company = sourcePolicy.getCompany().value; policyNumber = sourcePolicy.getPolicyNumber().value; @@ -130,6 +135,9 @@ public Person toModelType() throws IllegalValueException { throw new IllegalValueException(Address.MESSAGE_CONSTRAINTS); } final Address modelAddress = new Address(address); + if (remark == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Remark.class.getSimpleName())); + } final Set modelTags = new HashSet<>(personTags); @@ -151,6 +159,8 @@ public Person toModelType() throws IllegalValueException { } final LicencePlate modelLicencePlate = new LicencePlate(licencePlate); + final Remark modelRemark = new Remark(remark); + // Policy fields if (company == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, @@ -196,7 +206,7 @@ public Person toModelType() throws IllegalValueException { ); return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags, - modelNric, modelLicencePlate, modelPolicy); + modelNric, modelLicencePlate, modelRemark, modelPolicy); } } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 4e274ced4d0..5b02faa2dec 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -46,6 +46,8 @@ public class PersonCard extends UiPart { private Label licencePlate; @FXML private Label policy; + @FXML + private Label remark; /** * Creates a {@code PersonCode} with the given {@code Person} and index to display. @@ -64,5 +66,6 @@ public PersonCard(Person person, int displayedIndex) { person.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); + remark.setText(person.getRemark().value); } } diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index 9f69a52e2dc..ac6c14e357b 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -34,6 +34,7 @@