Skip to content

Commit

Permalink
Merge with master and fix test case errors
Browse files Browse the repository at this point in the history
  • Loading branch information
garylow2001 committed Oct 29, 2023
1 parent 80be99e commit 87ee989
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import seedu.address.commons.core.index.Index;
Expand Down Expand Up @@ -65,7 +66,7 @@ public CommandResult execute(Model model) throws CommandException {
Email email = personToConvert.getEmail();
Address address = personToConvert.getAddress();
Set<Tag> tags = new HashSet<>(personToConvert.getTags());
MeetingTime meetingTime = new MeetingTime(personToConvert.getMeetingTime().toString());
Optional<MeetingTime> meetingTime = personToConvert.getMeetingTime();

// TODO: Add more fields from client to lead

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import seedu.address.commons.core.index.Index;
Expand Down Expand Up @@ -65,7 +66,7 @@ public CommandResult execute(Model model) throws CommandException {
Email email = personToConvert.getEmail();
Address address = personToConvert.getAddress();
Set<Tag> tags = new HashSet<>(personToConvert.getTags());
MeetingTime meetingTime = new MeetingTime(personToConvert.getMeetingTime().toString());
Optional<MeetingTime> meetingTime = personToConvert.getMeetingTime();
// TODO: Add more fields from lead to client

Client convertedClient = new Client(name, phone, email, address, meetingTime, tags);
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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_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;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_MEETING_TIME + "MEETING_TIME] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
Expand Down Expand Up @@ -146,7 +148,7 @@ public static class EditPersonDescriptor {
private Phone phone;
private Email email;
private Address address;
private MeetingTime meetingTime;
private Optional<MeetingTime> meetingTime = Optional.empty();
private Set<Tag> tags;

public EditPersonDescriptor() {
Expand All @@ -169,7 +171,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, address, meetingTime, tags);
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags) || meetingTime.isPresent();
}

public Optional<Name> getName() {
Expand Down Expand Up @@ -205,10 +207,10 @@ public void setAddress(Address address) {
}

public Optional<MeetingTime> getMeetingTime() {
return Optional.ofNullable(meetingTime);
return meetingTime;
}

public void setMeetingTime(MeetingTime meetingTime) {
public void setMeetingTime(Optional<MeetingTime> meetingTime) {
this.meetingTime = meetingTime;
}

Expand Down Expand Up @@ -245,6 +247,7 @@ public boolean equals(Object other) {
&& Objects.equals(phone, otherEditPersonDescriptor.phone)
&& Objects.equals(email, otherEditPersonDescriptor.email)
&& Objects.equals(address, otherEditPersonDescriptor.address)
&& Objects.equals(meetingTime, otherEditPersonDescriptor.meetingTime)
&& Objects.equals(tags, otherEditPersonDescriptor.tags);
}

Expand All @@ -255,6 +258,7 @@ public String toString() {
.add("phone", phone)
.add("email", email)
.add("address", address)
.add("meetingTime", meetingTime)
.add("tags", tags)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,9 @@ public AddClientCommand parse(String args) throws ParseException {
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Optional<MeetingTime> meetingTime = argMultimap.getValue(PREFIX_MEETING_TIME)
.map(mt -> {
try {
return ParserUtil.parseMeetingTime(mt);
} catch (ParseException e) {
return null;
}
});
Optional<MeetingTime> meetingTime = argMultimap.getValue(PREFIX_MEETING_TIME).isPresent()
? Optional.of(ParserUtil.parseMeetingTime(argMultimap.getValue(PREFIX_MEETING_TIME).get()))
: Optional.empty();
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

// TODO: temporary fix, implement add Client and Lead commands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,15 @@ public AddLeadCommand parse(String args) throws ParseException {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddLeadCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_MEETING_TIME);
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Optional<MeetingTime> meetingTime = argMultimap.getValue(PREFIX_MEETING_TIME)
.map(mt -> {
try {
return ParserUtil.parseMeetingTime(mt);
} catch (ParseException e) {
return null;
}
});
Optional<MeetingTime> meetingTime = argMultimap.getValue(PREFIX_MEETING_TIME).isPresent()
? Optional.of(ParserUtil.parseMeetingTime(argMultimap.getValue(PREFIX_MEETING_TIME).get()))
: Optional.empty();
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

// TODO: temporary fix, implement add Client and Lead commands
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/seedu/address/logic/parser/EditCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
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_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;
Expand Down Expand Up @@ -32,7 +33,8 @@ public class EditCommandParser implements Parser<EditCommand> {
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_MEETING_TIME, PREFIX_TAG);

Index index;

Expand All @@ -42,7 +44,8 @@ public EditCommand parse(String args) throws ParseException {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe);
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_MEETING_TIME, PREFIX_ADDRESS);

EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();

Expand All @@ -58,6 +61,10 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_ADDRESS).isPresent()) {
editPersonDescriptor.setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()));
}
if (argMultimap.getValue(PREFIX_MEETING_TIME).isPresent()) {
editPersonDescriptor.setMeetingTime(
Optional.of(ParserUtil.parseMeetingTime(argMultimap.getValue(PREFIX_MEETING_TIME).get())));
}
parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags);

if (!editPersonDescriptor.isAnyFieldEdited()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public class CommandTestUtil {
static {
DESC_AMY = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY)
.withPhone(VALID_PHONE_AMY).withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY)
.withTags(VALID_TAG_FRIEND).build();
.withMeetingTime(VALID_MEETING_TIME_AMY).withTags(VALID_TAG_FRIEND).build();
DESC_BOB = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB)
.withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB)
.withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build();
.withMeetingTime(VALID_MEETING_TIME_BOB).withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void constructorNullPersonThrowsNullPointerException() {
public void executeClientConvertToLeadSuccess() throws CommandException {
final String expectedOutput = "Converted Client to Lead: Amy Bee; Phone: 85355255; Email: [email protected]; "
+ "Address: 123, Jurong West Ave 6, #08-111; "
+ "Meeting Time: 10/10/2023 14:30; Tags: ";
+ "Meeting Time: null; Tags: ";

// Step 1: Set up the necessary test data and model stub.
ModelStubAcceptingClientAdded modelStub = new ModelStubAcceptingClientAdded();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void constructor_nullPerson_throwsNullPointerException() {
public void executeLeadConvertToClientAddSuccessfully() throws CommandException {
final String expectedOutput = "Converted Lead to Client: Amy Bee; Phone: 85355255; "
+ "Email: [email protected]; Address: 123, Jurong West Ave 6, #08-111; "
+ "Meeting Time: 10/10/2023 14:30; Tags: ";
+ "Meeting Time: null; Tags: ";
// Step 1: Set up the necessary test data and model stub.
ModelStubAcceptingLeadAdded modelStub = new ModelStubAcceptingLeadAdded();
Lead validPerson = new PersonBuilder().buildLead();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static seedu.address.logic.commands.CommandTestUtil.DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_MEETING_TIME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND;
Expand Down Expand Up @@ -52,6 +53,10 @@ public void equals() {
editedAmy = new EditPersonDescriptorBuilder(DESC_AMY).withAddress(VALID_ADDRESS_BOB).build();
assertFalse(DESC_AMY.equals(editedAmy));

// different meeting time -> returns false
editedAmy = new EditPersonDescriptorBuilder(DESC_AMY).withMeetingTime(VALID_MEETING_TIME_BOB).build();
assertFalse(DESC_AMY.equals(editedAmy));

// different tags -> returns false
editedAmy = new EditPersonDescriptorBuilder(DESC_AMY).withTags(VALID_TAG_HUSBAND).build();
assertFalse(DESC_AMY.equals(editedAmy));
Expand All @@ -64,7 +69,8 @@ public void toStringMethod() {
+ editPersonDescriptor.getName().orElse(null) + ", phone="
+ editPersonDescriptor.getPhone().orElse(null) + ", email="
+ editPersonDescriptor.getEmail().orElse(null) + ", address="
+ editPersonDescriptor.getAddress().orElse(null) + ", tags="
+ editPersonDescriptor.getAddress().orElse(null) + ", meetingTime="
+ editPersonDescriptor.getMeetingTime() + ", tags="
+ editPersonDescriptor.getTags().orElse(null) + "}";
assertEquals(expected, editPersonDescriptor.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND;
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_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.CommandParserTestUtil.assertParseFailure;
Expand Down Expand Up @@ -91,9 +92,11 @@ public void parse_repeatedNonTagValue_failure() {

// multiple fields repeated
assertParseFailure(parser,
validExpectedPersonString + PHONE_DESC_AMY + EMAIL_DESC_AMY + NAME_DESC_AMY + ADDRESS_DESC_AMY
validExpectedPersonString + PHONE_DESC_AMY + EMAIL_DESC_AMY
+ NAME_DESC_AMY + ADDRESS_DESC_AMY + MEETING_TIME_DESC_BOB
+ validExpectedPersonString,
Messages.getErrorMessageForDuplicatePrefixes(PREFIX_NAME, PREFIX_ADDRESS, PREFIX_EMAIL, PREFIX_PHONE));
Messages.getErrorMessageForDuplicatePrefixes(PREFIX_NAME, PREFIX_ADDRESS,
PREFIX_MEETING_TIME, PREFIX_EMAIL, PREFIX_PHONE));

// invalid value followed by valid value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import static seedu.address.logic.commands.CommandTestUtil.INVALID_NAME_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_PHONE_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_TAG_DESC;
import static seedu.address.logic.commands.CommandTestUtil.MEETING_TIME_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_FRIEND;
import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_HUSBAND;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_MEETING_TIME_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB;
Expand Down Expand Up @@ -106,12 +108,12 @@ public void parse_invalidValue_failure() {
@Test
public void parse_allFieldsSpecified_success() {
Index targetIndex = INDEX_SECOND_PERSON;
String userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + TAG_DESC_HUSBAND
+ EMAIL_DESC_AMY + ADDRESS_DESC_AMY + NAME_DESC_AMY + TAG_DESC_FRIEND;
String userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + EMAIL_DESC_AMY + ADDRESS_DESC_AMY
+ MEETING_TIME_DESC_AMY + NAME_DESC_AMY + TAG_DESC_HUSBAND + TAG_DESC_FRIEND;

EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY)
.withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY)
.withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build();
.withMeetingTime(VALID_MEETING_TIME_AMY).withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build();
EditCommand expectedCommand = new EditCommand(targetIndex, descriptor);

assertParseSuccess(parser, userInput, expectedCommand);
Expand Down Expand Up @@ -156,6 +158,12 @@ public void parse_oneFieldSpecified_success() {
expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);

// meeting time
userInput = targetIndex.getOneBased() + MEETING_TIME_DESC_AMY;
descriptor = new EditPersonDescriptorBuilder().withMeetingTime(VALID_MEETING_TIME_AMY).build();
expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);

// tags
userInput = targetIndex.getOneBased() + TAG_DESC_FRIEND;
descriptor = new EditPersonDescriptorBuilder().withTags(VALID_TAG_FRIEND).build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package seedu.address.testutil;

import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import seedu.address.logic.commands.EditCommand.EditPersonDescriptor;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.MeetingTime;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
Expand Down Expand Up @@ -36,6 +38,7 @@ public EditPersonDescriptorBuilder(Person person) {
descriptor.setPhone(person.getPhone());
descriptor.setEmail(person.getEmail());
descriptor.setAddress(person.getAddress());
descriptor.setMeetingTime(person.getMeetingTime());
descriptor.setTags(person.getTags());
}

Expand Down Expand Up @@ -71,6 +74,14 @@ public EditPersonDescriptorBuilder withAddress(String address) {
return this;
}

/**
* Sets the {@code MeetingTime} of the {@code EditPersonDescriptor} that we are building.
*/
public EditPersonDescriptorBuilder withMeetingTime(String meetingTime) {
descriptor.setMeetingTime(Optional.of(new MeetingTime(meetingTime)));
return this;
}

/**
* Parses the {@code tags} into a {@code Set<Tag>} and set it to the {@code EditPersonDescriptor}
* that we are building.
Expand Down

0 comments on commit 87ee989

Please sign in to comment.