forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2103-AY2324S1#108 from tiif/branch-add-field
Branch add field for Lead's KeyMilestone
- Loading branch information
Showing
37 changed files
with
1,031 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_KEYMILESTONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_MEETING_TIME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; | ||
|
@@ -34,6 +35,7 @@ public class AddLeadCommand extends Command { | |
+ PREFIX_PHONE + "98765432 " | ||
+ PREFIX_EMAIL + "[email protected] " | ||
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " | ||
+ PREFIX_KEYMILESTONE + "2023-10-20 " | ||
+ PREFIX_MEETING_TIME + "10/10/2023 14:30 " | ||
+ PREFIX_TAG + "classmate"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,20 +25,22 @@ | |
import seedu.address.model.person.Address; | ||
import seedu.address.model.person.Client; | ||
import seedu.address.model.person.Email; | ||
import seedu.address.model.person.KeyMilestone; | ||
import seedu.address.model.person.Lead; | ||
import seedu.address.model.person.MeetingTime; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.Phone; | ||
import seedu.address.model.tag.Tag; | ||
|
||
|
||
|
||
/** | ||
* Edits the details of an existing person in the address book. | ||
*/ | ||
public class EditCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "edit"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified " | ||
+ "by the index number used in the displayed person list. " | ||
+ "Existing values will be overwritten by the input values.\n" | ||
|
@@ -54,6 +56,7 @@ public class EditCommand extends Command { | |
+ PREFIX_EMAIL + "[email protected]"; | ||
|
||
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s"; | ||
public static final String MESSAGE_EDIT_LEAD_SUCCESS = "Edited Lead: %1$s"; | ||
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book."; | ||
|
||
|
@@ -86,14 +89,18 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript | |
Optional<MeetingTime> updatedMeetingTime = editPersonDescriptor.getMeetingTime() | ||
.or(personToEdit::getMeetingTime); | ||
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); | ||
|
||
if (personToEdit.isClient()) { | ||
return new Client(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedMeetingTime, updatedTags); | ||
} else { | ||
return new Lead(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedMeetingTime, updatedTags); | ||
//todo: this temporary fix related to the one in editcommandparser | ||
if (personToEdit.isLead()) { | ||
//keyMilestone will not be updated if editLeadCommand is not used | ||
Lead leadToEdit = (Lead) personToEdit; | ||
KeyMilestone keyMilestone = leadToEdit.getKeyMilestone(); | ||
return new Lead(updatedName, updatedPhone, updatedEmail, updatedAddress, keyMilestone, | ||
updatedMeetingTime, updatedTags); | ||
} | ||
return new Client(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedMeetingTime, updatedTags); | ||
} | ||
|
||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
|
@@ -166,7 +173,6 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { | |
setMeetingTime(toCopy.meetingTime); | ||
setTags(toCopy.tags); | ||
} | ||
|
||
/** | ||
* Returns true if at least one field is edited. | ||
*/ | ||
|
@@ -263,4 +269,66 @@ public String toString() { | |
.toString(); | ||
} | ||
} | ||
|
||
/** | ||
* Stores the details to edit the lead with. Each non-empty field value will replace the | ||
* corresponding field value of the lead. | ||
*/ | ||
public static class EditLeadDescriptor extends EditPersonDescriptor { | ||
//This class only used for edit KeyMilestone, for other field of leads like name, editPersonDescriptor | ||
// will be used | ||
private KeyMilestone keyMilestone; | ||
/** | ||
* Copy constructor only for leads. | ||
* A defensive copy of {@code tags} is used internally. | ||
*/ | ||
public EditLeadDescriptor(EditLeadDescriptor toCopy) { | ||
super(toCopy); | ||
setKeyMilestone(toCopy.keyMilestone); | ||
} | ||
|
||
public EditLeadDescriptor() { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isAnyFieldEdited() { | ||
return super.isAnyFieldEdited() || CollectionUtil.isAnyNonNull(keyMilestone); | ||
} | ||
|
||
public Optional<KeyMilestone> getKeyMilestone() { | ||
return Optional.ofNullable(keyMilestone); | ||
} | ||
|
||
public void setKeyMilestone(KeyMilestone keyMilestone) { | ||
this.keyMilestone = keyMilestone; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof EditLeadDescriptor)) { | ||
return false; | ||
} | ||
EditLeadDescriptor otherEditLeadDescriptor = (EditLeadDescriptor) other; | ||
return super.equals(other) && Objects.equals(keyMilestone, otherEditLeadDescriptor.keyMilestone); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("name", super.name) | ||
.add("phone", super.phone) | ||
.add("email", super.email) | ||
.add("address", super.address) | ||
.add("key milestone", keyMilestone) | ||
.add("meeting time", super.meetingTime) | ||
.add("tags", super.tags) | ||
.toString(); | ||
} | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
src/main/java/seedu/address/logic/commands/EditLeadCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_KEYMILESTONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_MEETING_TIME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
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.Email; | ||
import seedu.address.model.person.KeyMilestone; | ||
import seedu.address.model.person.Lead; | ||
import seedu.address.model.person.MeetingTime; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.Phone; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Edits the details of an existing lead in the address book. | ||
*/ | ||
public class EditLeadCommand extends EditCommand { | ||
|
||
public static final String COMMAND_WORD = "edit"; | ||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified " | ||
+ "by the index number used in the displayed person list. " | ||
+ "Existing values will be overwritten by the input values.\n" | ||
+ "Parameters: INDEX (must be a positive integer) " | ||
+ "[" + PREFIX_NAME + "NAME] " | ||
+ "[" + PREFIX_PHONE + "PHONE] " | ||
+ "[" + PREFIX_EMAIL + "EMAIL] " | ||
+ "[" + PREFIX_ADDRESS + "ADDRESS] " | ||
+ "[" + PREFIX_KEYMILESTONE + "KEY MILESTONE] " | ||
+ "[" + PREFIX_MEETING_TIME + "MEETING TIME] " | ||
+ "[" + PREFIX_TAG + "TAG]...\n" | ||
+ "Example: " + COMMAND_WORD + " 1 " | ||
+ PREFIX_PHONE + "91234567 " | ||
+ PREFIX_EMAIL + "[email protected]"; | ||
|
||
|
||
private final Index index; | ||
private final EditLeadDescriptor editLeadDescriptor; | ||
|
||
/** | ||
* @param index of the person in the filtered person list to edit | ||
* @param editLeadDescriptor details to edit the lead with | ||
*/ | ||
public EditLeadCommand(Index index, EditLeadDescriptor editLeadDescriptor) { | ||
super(index, editLeadDescriptor); | ||
requireNonNull(index); | ||
requireNonNull(editLeadDescriptor); | ||
|
||
this.index = index; | ||
this.editLeadDescriptor = new EditLeadDescriptor(editLeadDescriptor); | ||
} | ||
|
||
|
||
private static Lead createEditedLead(Lead leadToEdit, EditLeadDescriptor editLeadDescriptor) { | ||
assert leadToEdit != null; | ||
|
||
Name updatedName = editLeadDescriptor.getName().orElse(leadToEdit.getName()); | ||
Phone updatedPhone = editLeadDescriptor.getPhone().orElse(leadToEdit.getPhone()); | ||
Email updatedEmail = editLeadDescriptor.getEmail().orElse(leadToEdit.getEmail()); | ||
Address updatedAddress = editLeadDescriptor.getAddress().orElse(leadToEdit.getAddress()); | ||
Set<Tag> updatedTags = editLeadDescriptor.getTags().orElse(leadToEdit.getTags()); | ||
KeyMilestone updatedKeyMilestone = editLeadDescriptor.getKeyMilestone() | ||
.orElse(leadToEdit.getKeyMilestone()); | ||
Optional<MeetingTime> updatedMeetingTime = editLeadDescriptor.getMeetingTime() | ||
.or(leadToEdit::getMeetingTime); | ||
|
||
return new Lead(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedKeyMilestone, | ||
updatedMeetingTime, updatedTags); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Lead leadToEdit = (Lead) lastShownList.get(index.getZeroBased()); | ||
assert(leadToEdit.isLead()); | ||
Lead editedLead = createEditedLead((Lead) leadToEdit, editLeadDescriptor); | ||
|
||
if (!leadToEdit.isSamePerson(editedLead) && model.hasPerson(editedLead)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_PERSON); | ||
} | ||
|
||
model.setPerson(leadToEdit, editedLead); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(String.format(MESSAGE_EDIT_LEAD_SUCCESS, Messages.format(editedLead))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof EditLeadCommand)) { | ||
return false; | ||
} | ||
|
||
EditLeadCommand otherEditCommand = (EditLeadCommand) other; | ||
return index.equals(otherEditCommand.index) | ||
&& editLeadDescriptor.equals(otherEditCommand.editLeadDescriptor); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("index", index) | ||
.add("editLeadDescriptor", editLeadDescriptor) | ||
.toString(); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.