diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 92f9fbaf2e8..a9b21234c49 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -44,7 +44,7 @@ public static String format(Person person) { .append("; Address: ") .append(person.getAddress()) .append("; Meeting Time: ") - .append(person.getMeetingTime()) + .append(person.getMeetingTimeString()) .append("; Tags: "); person.getTags().forEach(builder::append); return builder.toString(); diff --git a/src/main/java/seedu/address/logic/commands/ConvertClientToLeadCommand.java b/src/main/java/seedu/address/logic/commands/ConvertClientToLeadCommand.java index 39dd10a2916..9de63f7135d 100644 --- a/src/main/java/seedu/address/logic/commands/ConvertClientToLeadCommand.java +++ b/src/main/java/seedu/address/logic/commands/ConvertClientToLeadCommand.java @@ -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; @@ -65,7 +66,7 @@ public CommandResult execute(Model model) throws CommandException { Email email = personToConvert.getEmail(); Address address = personToConvert.getAddress(); Set tags = new HashSet<>(personToConvert.getTags()); - MeetingTime meetingTime = new MeetingTime(personToConvert.getMeetingTime().toString()); + Optional meetingTime = personToConvert.getMeetingTime(); // TODO: Add more fields from client to lead diff --git a/src/main/java/seedu/address/logic/commands/ConvertLeadToClientCommand.java b/src/main/java/seedu/address/logic/commands/ConvertLeadToClientCommand.java index 0972bf309b5..58c12225c5a 100644 --- a/src/main/java/seedu/address/logic/commands/ConvertLeadToClientCommand.java +++ b/src/main/java/seedu/address/logic/commands/ConvertLeadToClientCommand.java @@ -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; @@ -65,7 +66,7 @@ public CommandResult execute(Model model) throws CommandException { Email email = personToConvert.getEmail(); Address address = personToConvert.getAddress(); Set tags = new HashSet<>(personToConvert.getTags()); - MeetingTime meetingTime = new MeetingTime(personToConvert.getMeetingTime().toString()); + Optional meetingTime = personToConvert.getMeetingTime(); // TODO: Add more fields from lead to client Client convertedClient = new Client(name, phone, email, address, meetingTime, tags); diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 1df4cb00fe1..c23384aa3a3 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -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; @@ -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 " @@ -81,7 +83,8 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone()); Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); - MeetingTime updatedMeetingTime = editPersonDescriptor.getMeetingTime().orElse(personToEdit.getMeetingTime()); + Optional updatedMeetingTime = editPersonDescriptor.getMeetingTime() + .or(personToEdit::getMeetingTime); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); if (personToEdit.isClient()) { @@ -145,7 +148,7 @@ public static class EditPersonDescriptor { private Phone phone; private Email email; private Address address; - private MeetingTime meetingTime; + private Optional meetingTime = Optional.empty(); private Set tags; public EditPersonDescriptor() { @@ -168,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, tags); + return CollectionUtil.isAnyNonNull(name, phone, email, address, tags) || meetingTime.isPresent(); } public Optional getName() { @@ -204,10 +207,10 @@ public void setAddress(Address address) { } public Optional getMeetingTime() { - return Optional.ofNullable(meetingTime); + return meetingTime; } - public void setMeetingTime(MeetingTime meetingTime) { + public void setMeetingTime(Optional meetingTime) { this.meetingTime = meetingTime; } @@ -244,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); } @@ -254,6 +258,7 @@ public String toString() { .add("phone", phone) .add("email", email) .add("address", address) + .add("meetingTime", meetingTime) .add("tags", tags) .toString(); } diff --git a/src/main/java/seedu/address/logic/parser/AddClientCommandParser.java b/src/main/java/seedu/address/logic/parser/AddClientCommandParser.java index 6a537350fdd..0f2bb91ded5 100644 --- a/src/main/java/seedu/address/logic/parser/AddClientCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddClientCommandParser.java @@ -8,6 +8,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import java.util.Optional; import java.util.Set; import java.util.stream.Stream; @@ -36,8 +37,7 @@ public AddClientCommand parse(String args) throws ParseException { ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_MEETING_TIME, PREFIX_TAG); - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, - PREFIX_EMAIL, PREFIX_MEETING_TIME) //TODO: remove prefix_meeting_time here + if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddClientCommand.MESSAGE_USAGE)); } @@ -48,7 +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()); - MeetingTime meetingTime = ParserUtil.parseMeetingTime(argMultimap.getValue(PREFIX_MEETING_TIME).get()); + Optional meetingTime = argMultimap.getValue(PREFIX_MEETING_TIME).isPresent() + ? Optional.of(ParserUtil.parseMeetingTime(argMultimap.getValue(PREFIX_MEETING_TIME).get())) + : Optional.empty(); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); // TODO: temporary fix, implement add Client and Lead commands diff --git a/src/main/java/seedu/address/logic/parser/AddLeadCommandParser.java b/src/main/java/seedu/address/logic/parser/AddLeadCommandParser.java index 6cb15e7b882..371232c2d36 100644 --- a/src/main/java/seedu/address/logic/parser/AddLeadCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddLeadCommandParser.java @@ -8,6 +8,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import java.util.Optional; import java.util.Set; import java.util.stream.Stream; @@ -41,12 +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()); - MeetingTime meetingTime = ParserUtil.parseMeetingTime(argMultimap.getValue(PREFIX_MEETING_TIME).get()); + Optional meetingTime = argMultimap.getValue(PREFIX_MEETING_TIME).isPresent() + ? Optional.of(ParserUtil.parseMeetingTime(argMultimap.getValue(PREFIX_MEETING_TIME).get())) + : Optional.empty(); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); // TODO: temporary fix, implement add Client and Lead commands diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 46b3309a78b..1306876233a 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -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; @@ -32,7 +33,8 @@ public class EditCommandParser implements Parser { 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; @@ -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(); @@ -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()) { diff --git a/src/main/java/seedu/address/model/person/Client.java b/src/main/java/seedu/address/model/person/Client.java index 3dde120de92..da0b34b8687 100644 --- a/src/main/java/seedu/address/model/person/Client.java +++ b/src/main/java/seedu/address/model/person/Client.java @@ -1,5 +1,6 @@ package seedu.address.model.person; +import java.util.Optional; import java.util.Set; import seedu.address.model.tag.Tag; @@ -13,7 +14,8 @@ public class Client extends Person { /** * Every field must be present and not null. */ - public Client(Name name, Phone phone, Email email, Address address, MeetingTime meetingTime, Set tags) { + public Client(Name name, Phone phone, Email email, Address address, + Optional meetingTime, Set tags) { super(name, phone, email, new Type(TYPE_CLIENT), address, meetingTime, tags); } diff --git a/src/main/java/seedu/address/model/person/Lead.java b/src/main/java/seedu/address/model/person/Lead.java index f166ca6c82e..7cac3b65b4d 100644 --- a/src/main/java/seedu/address/model/person/Lead.java +++ b/src/main/java/seedu/address/model/person/Lead.java @@ -1,5 +1,6 @@ package seedu.address.model.person; +import java.util.Optional; import java.util.Set; import seedu.address.model.tag.Tag; @@ -13,7 +14,8 @@ public class Lead extends Person { /** * Every field must be present and not null. */ - public Lead(Name name, Phone phone, Email email, Address address, MeetingTime meetingTime, Set tags) { + public Lead(Name name, Phone phone, Email email, Address address, + Optional meetingTime, Set tags) { super(name, phone, email, new Type(TYPE_LEAD), address, meetingTime, tags); } diff --git a/src/main/java/seedu/address/model/person/MeetingTime.java b/src/main/java/seedu/address/model/person/MeetingTime.java index dc1310255dc..4968418d281 100644 --- a/src/main/java/seedu/address/model/person/MeetingTime.java +++ b/src/main/java/seedu/address/model/person/MeetingTime.java @@ -1,6 +1,5 @@ package seedu.address.model.person; -import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; import static seedu.address.model.person.MeetingTimeFormatter.DATE_TIME_FORMAT; @@ -22,7 +21,6 @@ public class MeetingTime { * @param meetingTime A valid meeting time. */ public MeetingTime(String meetingTime) { - requireNonNull(meetingTime); checkArgument(isValidMeetingTime(meetingTime), MESSAGE_CONSTRAINTS); this.value = MeetingTimeFormatter.parse(meetingTime); } diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 50885bb4176..f6333bbd4f7 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -5,6 +5,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.Objects; +import java.util.Optional; import java.util.Set; import seedu.address.commons.util.ToStringBuilder; @@ -24,14 +25,14 @@ public abstract class Person { // Data fields private final Address address; - private final MeetingTime meetingTime; + private final Optional meetingTime; private final Set tags = new HashSet<>(); /** * Every field must be present and not null. */ public Person(Name name, Phone phone, Email email, Type type, - Address address, MeetingTime meetingTime, Set tags) { + Address address, Optional meetingTime, Set tags) { requireAllNonNull(name, phone, email, address, meetingTime, tags); this.name = name; this.phone = phone; @@ -62,9 +63,17 @@ public Address getAddress() { return address; } - public MeetingTime getMeetingTime() { + public Optional getMeetingTime() { return meetingTime; } + public String getMeetingTimeString() { + return meetingTime.map(MeetingTime::toString).orElse(null); + } + + public String getMeetingTimeStringForUserInterface() { + return meetingTime.map(meetingTime -> "Meeting on: " + meetingTime) + .orElse(null); + } /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 410bead41f1..64e22b2b0b1 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -1,6 +1,7 @@ package seedu.address.model.util; import java.util.Arrays; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -23,22 +24,25 @@ public class SampleDataUtil { public static Person[] getSamplePersons() { return new Person[] { new Client(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), - new Address("Blk 30 Geylang Street 29, #06-40"), new MeetingTime("10/10/2023 14:30"), + new Address("Blk 30 Geylang Street 29, #06-40"), Optional.of(new MeetingTime("10/10/2023 14:30")), getTagSet("friends")), new Client(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), - new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), new MeetingTime("10/10/2023 14:30"), + new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), + Optional.of(new MeetingTime("10/10/2023 14:30")), getTagSet("colleagues", "friends")), new Client(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), - new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), new MeetingTime("10/10/2023 14:30"), + new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), + Optional.of(new MeetingTime("10/10/2023 14:30")), getTagSet("neighbours")), new Lead(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), - new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), new MeetingTime("10/10/2023 14:30"), + new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), + Optional.of(new MeetingTime("10/10/2023 14:30")), getTagSet("family")), new Lead(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), - new Address("Blk 47 Tampines Street 20, #17-35"), new MeetingTime("10/10/2023 14:30"), + new Address("Blk 47 Tampines Street 20, #17-35"), Optional.of(new MeetingTime("10/10/2023 14:30")), getTagSet("classmates")), new Lead(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), - new Address("Blk 45 Aljunied Street 85, #11-31"), new MeetingTime("10/10/2023 14:30"), + new Address("Blk 45 Aljunied Street 85, #11-31"), Optional.of(new MeetingTime("10/10/2023 14:30")), getTagSet("colleagues")) }; } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index fe93ede985f..6f7ba2f93ea 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -36,7 +37,7 @@ class JsonAdaptedPerson { private final String email; private final String type; private final String address; - private final String meetingTime; + private String meetingTime; private final List tags = new ArrayList<>(); /** @@ -52,7 +53,9 @@ public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone this.email = email; this.type = type; this.address = address; - this.meetingTime = meetingTime; + if (meetingTime != null) { + this.meetingTime = meetingTime; + } if (tags != null) { this.tags.addAll(tags); } @@ -67,7 +70,7 @@ public JsonAdaptedPerson(Person source) { email = source.getEmail().value; address = source.getAddress().value; type = source.getType().value; - meetingTime = source.getMeetingTime().toString(); + meetingTime = source.getMeetingTime().map(MeetingTime::toString).orElse(null); tags.addAll(source.getTags().stream() .map(JsonAdaptedTag::new) .collect(Collectors.toList())); @@ -116,14 +119,15 @@ public Person toModelType() throws IllegalValueException { } final Address modelAddress = new Address(address); + final Optional modelMeetingTime; if (meetingTime == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, - MeetingTime.class.getSimpleName())); - } - if (!MeetingTime.isValidMeetingTime(meetingTime)) { - throw new IllegalValueException(MeetingTime.MESSAGE_CONSTRAINTS); + modelMeetingTime = Optional.empty(); + } else { + if (!MeetingTime.isValidMeetingTime(meetingTime)) { + throw new IllegalValueException(MeetingTime.MESSAGE_CONSTRAINTS); + } + modelMeetingTime = Optional.of(new MeetingTime(meetingTime)); } - final MeetingTime modelMeetingTime = new MeetingTime(meetingTime); final Set modelTags = new HashSet<>(personTags); diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index e5f2869ecac..c9f43a8e0bf 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -53,7 +53,10 @@ public PersonCard(Person person, int displayedIndex) { name.setText(person.getName().fullName); phone.setText(person.getPhone().value); address.setText(person.getAddress().value); - meetingTime.setText("Meeting on: " + person.getMeetingTime().toString()); + if (person.getMeetingTime().isPresent()) { + meetingTime.setManaged(true); + meetingTime.setText(person.getMeetingTimeStringForUserInterface()); + } email.setText(person.getEmail().value); Label label = new Label(person.getType().value); diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index 6cd111e0c1d..3d044bb9007 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -28,7 +28,7 @@