From 31dd3a7cd71cd62d8ddaf00bba01820408acafd9 Mon Sep 17 00:00:00 2001 From: LicongHuang Date: Mon, 23 Oct 2023 11:26:36 +0800 Subject: [PATCH 1/6] Change CliSyntax --- .../seedu/address/logic/parser/CliSyntax.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 80fe792becc..e9eceeec974 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -6,16 +6,10 @@ public class CliSyntax { /* Prefix definitions */ - public static final Prefix PREFIX_NAME = new Prefix("n/"); - public static final Prefix PREFIX_PHONE = new Prefix("p/"); - public static final Prefix PREFIX_EMAIL = new Prefix("e/"); - public static final Prefix PREFIX_ADDRESS = new Prefix("a/"); - public static final Prefix PREFIX_TAG = new Prefix("t/"); - - public static final Prefix PREFIX_NAME_TP = new Prefix("--name"); - public static final Prefix PREFIX_PHONE_TP = new Prefix("--phone"); - public static final Prefix PREFIX_EMAIL_TP = new Prefix("--email"); - public static final Prefix PREFIX_ADDRESS_TP = new Prefix("--address"); - public static final Prefix PREFIX_TAG_TP = new Prefix("--tag"); + public static final Prefix PREFIX_NAME = new Prefix("--name"); + public static final Prefix PREFIX_PHONE = new Prefix("--phone"); + public static final Prefix PREFIX_EMAIL = new Prefix("--email"); + public static final Prefix PREFIX_ADDRESS = new Prefix("--address"); + public static final Prefix PREFIX_TAG = new Prefix("--tag"); } From 911dd3db39c9bd3d86765d44a1bd2b5a572bea4d Mon Sep 17 00:00:00 2001 From: LicongHuang Date: Mon, 23 Oct 2023 19:07:51 +0800 Subject: [PATCH 2/6] Add space in CliSyntax --- .../java/seedu/address/logic/parser/CliSyntax.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index e9eceeec974..d724ec31003 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -6,10 +6,10 @@ public class CliSyntax { /* Prefix definitions */ - public static final Prefix PREFIX_NAME = new Prefix("--name"); - public static final Prefix PREFIX_PHONE = new Prefix("--phone"); - public static final Prefix PREFIX_EMAIL = new Prefix("--email"); - public static final Prefix PREFIX_ADDRESS = new Prefix("--address"); - public static final Prefix PREFIX_TAG = new Prefix("--tag"); + public static final Prefix PREFIX_NAME = new Prefix("--name "); + public static final Prefix PREFIX_PHONE = new Prefix("--phone "); + public static final Prefix PREFIX_EMAIL = new Prefix("--email "); + public static final Prefix PREFIX_ADDRESS = new Prefix("--address "); + public static final Prefix PREFIX_TAG = new Prefix("--tag "); } From 1f97cb9e85b5deb2907f320c7dfff3bc3b8528f4 Mon Sep 17 00:00:00 2001 From: LicongHuang Date: Wed, 25 Oct 2023 01:03:09 +0800 Subject: [PATCH 3/6] Implement Convert client to lead --- .../commands/ConvertClientToLeadCommand.java | 89 +++++++++++++++++++ .../commands/ConvertLeadToClientCommand.java | 88 ++++++++++++++++++ .../logic/parser/AddressBookParser.java | 8 ++ .../ConvertClientToLeadCommandParser.java | 39 ++++++++ .../ConvertLeadToClientCommandParser.java | 39 ++++++++ 5 files changed, 263 insertions(+) create mode 100644 src/main/java/seedu/address/logic/commands/ConvertClientToLeadCommand.java create mode 100644 src/main/java/seedu/address/logic/commands/ConvertLeadToClientCommand.java create mode 100644 src/main/java/seedu/address/logic/parser/ConvertClientToLeadCommandParser.java create mode 100644 src/main/java/seedu/address/logic/parser/ConvertLeadToClientCommandParser.java diff --git a/src/main/java/seedu/address/logic/commands/ConvertClientToLeadCommand.java b/src/main/java/seedu/address/logic/commands/ConvertClientToLeadCommand.java new file mode 100644 index 00000000000..e4bfb88c0bb --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/ConvertClientToLeadCommand.java @@ -0,0 +1,89 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +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.Address; +import seedu.address.model.person.Client; +import seedu.address.model.person.Email; +import seedu.address.model.person.Lead; +import seedu.address.model.person.Name; +import seedu.address.model.person.Person; +import seedu.address.model.person.Phone; +import seedu.address.model.tag.Tag; + +/** + * Converts a Client to a Lead in the address book. + */ +public class ConvertClientToLeadCommand extends Command { + public static final String COMMAND_WORD = "converttolead"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Converts a client to a lead by the index " + + "number used in the displayed person list. \n" + + "Parameters: INDEX (must be a positive integer)\n" + + "Example: " + COMMAND_WORD + " 1"; + + public static final String MESSAGE_CONVERT_SUCCESS = "Converted Client to Lead: %1$s"; + + private final Index index; + + public ConvertClientToLeadCommand(Index index) { + requireNonNull(index); + this.index = index; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + List lastShownList = model.getFilteredPersonList(); + + if (index.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + Person personToConvert = lastShownList.get(index.getZeroBased()); + + if (!(personToConvert instanceof Client)) { + throw new CommandException("The person at the specified index is not a Client."); + } + + Name name = personToConvert.getName(); + Phone phone = personToConvert.getPhone(); + Email email = personToConvert.getEmail(); + Address address = personToConvert.getAddress(); + Set tags = new HashSet(); + tags.remove(new Tag("Client")); + tags.add(new Tag("Lead")); + // TODO: Add more fields from client to lead + + + Lead convertedLead = new Lead(name, phone, email, address, tags); + + model.setPerson(personToConvert, convertedLead); + model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + return new CommandResult(String.format(MESSAGE_CONVERT_SUCCESS, Messages.format(convertedLead))); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof ConvertClientToLeadCommand)) { + return false; + } + + ConvertClientToLeadCommand otherConvertCommand = (ConvertClientToLeadCommand) other; + return index.equals(otherConvertCommand.index); + } +} + diff --git a/src/main/java/seedu/address/logic/commands/ConvertLeadToClientCommand.java b/src/main/java/seedu/address/logic/commands/ConvertLeadToClientCommand.java new file mode 100644 index 00000000000..3ae49293f0a --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/ConvertLeadToClientCommand.java @@ -0,0 +1,88 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +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.Address; +import seedu.address.model.person.Client; +import seedu.address.model.person.Email; +import seedu.address.model.person.Lead; +import seedu.address.model.person.Name; +import seedu.address.model.person.Person; +import seedu.address.model.person.Phone; +import seedu.address.model.tag.Tag; + +/** + * Converts a Lead to a Client in the address book. + */ +public class ConvertLeadToClientCommand extends Command { + public static final String COMMAND_WORD = "converttoclient"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Converts a lead to a client by the index " + + "number used in the displayed person list. \n" + + "Parameters: INDEX (must be a positive integer)\n" + + "Example: " + COMMAND_WORD + " 1"; + + public static final String MESSAGE_CONVERT_SUCCESS = "Converted Lead to Client: %1$s"; + + private final Index index; + + public ConvertLeadToClientCommand(Index index) { + requireNonNull(index); + this.index = index; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + List lastShownList = model.getFilteredPersonList(); + + if (index.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + Person personToConvert = lastShownList.get(index.getZeroBased()); + + if (!(personToConvert instanceof Lead)) { + throw new CommandException("The person at the specified index is not a Lead."); + } + + Name name = personToConvert.getName(); + Phone phone = personToConvert.getPhone(); + Email email = personToConvert.getEmail(); + Address address = personToConvert.getAddress(); + Set tags = new HashSet<>(); + tags.remove(new Tag("Lead")); + tags.add(new Tag("Client")); + // TODO: Add more fields from lead to client + + Client convertedClient = new Client(name, phone, email, address, tags); + + model.setPerson(personToConvert, convertedClient); + model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + return new CommandResult(String.format(MESSAGE_CONVERT_SUCCESS, Messages.format(convertedClient))); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof ConvertLeadToClientCommand)) { + return false; + } + + ConvertLeadToClientCommand otherConvertCommand = (ConvertLeadToClientCommand) other; + return index.equals(otherConvertCommand.index); + } +} + diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index c775b97ddf4..ffa037abcab 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -13,6 +13,8 @@ import seedu.address.logic.commands.AddLeadCommand; import seedu.address.logic.commands.ClearCommand; import seedu.address.logic.commands.Command; +import seedu.address.logic.commands.ConvertClientToLeadCommand; +import seedu.address.logic.commands.ConvertLeadToClientCommand; import seedu.address.logic.commands.DeleteCommand; import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.ExitCommand; @@ -93,6 +95,12 @@ public Command parseCommand(String userInput) throws ParseException { case ListLeadCommand.COMMAND_WORD: return new ListLeadCommand(); + case ConvertLeadToClientCommand.COMMAND_WORD: + return new ConvertLeadToClientCommandParser().parse(arguments); + + case ConvertClientToLeadCommand.COMMAND_WORD: + return new ConvertClientToLeadCommandParser().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/ConvertClientToLeadCommandParser.java b/src/main/java/seedu/address/logic/parser/ConvertClientToLeadCommandParser.java new file mode 100644 index 00000000000..c84a342749b --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/ConvertClientToLeadCommandParser.java @@ -0,0 +1,39 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import java.util.Arrays; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.ConvertClientToLeadCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.NameContainsKeywordsPredicate; + +/** + * Parses input arguments and creates a new FindCommand object + */ +public class ConvertClientToLeadCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the FindCommand + * and returns a FindCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + + public ConvertClientToLeadCommand parse(String args) throws ParseException { + String trimmedArgs = args.trim(); + if (trimmedArgs.isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, ConvertClientToLeadCommand.MESSAGE_USAGE)); + } + + try { + Index index = ParserUtil.parseIndex(trimmedArgs); + return new ConvertClientToLeadCommand(index); + } catch (ParseException pe) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, ConvertClientToLeadCommand.MESSAGE_USAGE), pe); + } + } + +} diff --git a/src/main/java/seedu/address/logic/parser/ConvertLeadToClientCommandParser.java b/src/main/java/seedu/address/logic/parser/ConvertLeadToClientCommandParser.java new file mode 100644 index 00000000000..c3256194373 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/ConvertLeadToClientCommandParser.java @@ -0,0 +1,39 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import java.util.Arrays; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.ConvertLeadToClientCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.NameContainsKeywordsPredicate; + +/** + * Parses input arguments and creates a new FindCommand object + */ +public class ConvertLeadToClientCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the FindCommand + * and returns a FindCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + + public ConvertLeadToClientCommand parse(String args) throws ParseException { + String trimmedArgs = args.trim(); + if (trimmedArgs.isEmpty()) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, ConvertLeadToClientCommand.MESSAGE_USAGE)); + } + + try { + Index index = ParserUtil.parseIndex(trimmedArgs); + return new ConvertLeadToClientCommand(index); + } catch (ParseException pe) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, ConvertLeadToClientCommand.MESSAGE_USAGE), pe); + } + } + +} From e623822c44fd40f5f3c5992c8e889ad87071a19d Mon Sep 17 00:00:00 2001 From: LicongHuang Date: Wed, 25 Oct 2023 02:32:11 +0800 Subject: [PATCH 4/6] Add test --- .../ConvertClientToLeadCommandTest.java | 41 +++++++++++++++++++ .../ConvertLeadToClientCommandTest.java | 41 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 src/test/java/seedu/address/logic/commands/ConvertClientToLeadCommandTest.java create mode 100644 src/test/java/seedu/address/logic/commands/ConvertLeadToClientCommandTest.java diff --git a/src/test/java/seedu/address/logic/commands/ConvertClientToLeadCommandTest.java b/src/test/java/seedu/address/logic/commands/ConvertClientToLeadCommandTest.java new file mode 100644 index 00000000000..693f739c9ba --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/ConvertClientToLeadCommandTest.java @@ -0,0 +1,41 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.person.Client; +import seedu.address.model.person.Lead; +import seedu.address.testutil.TypicalPersons; + +public class ConvertClientToLeadCommandTest { + private Model model = new ModelManager(TypicalPersons.getTypicalAddressBook(), new UserPrefs()); + private Model expectedModel = new ModelManager(TypicalPersons.getTypicalAddressBook(), new UserPrefs()); + + @Test + public void execute_validClientIndex_success() { + Client clientToConvert = TypicalPersons.getTypicalClients().get(0); // assuming you have a list of clients + ConvertClientToLeadCommand command = new ConvertClientToLeadCommand(clientToConvert.getIndex()); + + String expectedMessage = String.format(ConvertClientToLeadCommand.MESSAGE_CONVERT_SUCCESS, clientToConvert); + expectedModel.deletePerson(clientToConvert); + expectedModel.addPerson(new Lead(clientToConvert)); // Assuming a constructor for Lead is available + + assertCommandSuccess(command, model, expectedMessage, expectedModel); + } + + @Test + public void execute_invalidClientIndex_failure() { + int outOfBoundIndex = model.getFilteredPersonList().size() + 1; + ConvertClientToLeadCommand command = new ConvertClientToLeadCommand(Index.fromOneBased(outOfBoundIndex)); + + assertCommandFailure(command, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + // Add more test cases for edge cases, if necessary +} + diff --git a/src/test/java/seedu/address/logic/commands/ConvertLeadToClientCommandTest.java b/src/test/java/seedu/address/logic/commands/ConvertLeadToClientCommandTest.java new file mode 100644 index 00000000000..8f738d687bf --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/ConvertLeadToClientCommandTest.java @@ -0,0 +1,41 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.person.Client; +import seedu.address.model.person.Lead; +import seedu.address.testutil.TypicalPersons; + +public class ConvertLeadToClientCommandTest { + private Model model = new ModelManager(TypicalPersons.getTypicalAddressBook(), new UserPrefs()); + private Model expectedModel = new ModelManager(TypicalPersons.getTypicalAddressBook(), new UserPrefs()); + + @Test + public void execute_validLeadIndex_success() { + Lead leadToConvert = TypicalPersons.getTypicalLeads().get(0); // assuming you have a list of leads + ConvertLeadToClientCommand command = new ConvertLeadToClientCommand(leadToConvert.getIndex()); + + String expectedMessage = String.format(ConvertLeadToClientCommand.MESSAGE_CONVERT_SUCCESS, leadToConvert); + expectedModel.deletePerson(leadToConvert); + expectedModel.addPerson(new Client(leadToConvert)); // Assuming a constructor for Client is available + + assertCommandSuccess(command, model, expectedMessage, expectedModel); + } + + @Test + public void execute_invalidLeadIndex_failure() { + int outOfBoundIndex = model.getFilteredPersonList().size() + 1; + ConvertLeadToClientCommand command = new ConvertLeadToClientCommand(Index.fromOneBased(outOfBoundIndex)); + + assertCommandFailure(command, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + // Add more test cases for edge cases, if necessary +} + From 2ce09c298cfe3d4e6b612f9454d3a055ce7e6884 Mon Sep 17 00:00:00 2001 From: LicongHuang Date: Wed, 25 Oct 2023 20:13:40 +0800 Subject: [PATCH 5/6] Test stuff --- docs/new_things | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 docs/new_things diff --git a/docs/new_things b/docs/new_things new file mode 100644 index 00000000000..e69de29bb2d From 5d53ddb2b392083e91d698b6c178bd53e36be21d Mon Sep 17 00:00:00 2001 From: LicongHuang Date: Wed, 25 Oct 2023 20:15:22 +0800 Subject: [PATCH 6/6] Test branch --- docs/new_things | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 docs/new_things diff --git a/docs/new_things b/docs/new_things deleted file mode 100644 index e69de29bb2d..00000000000