From 7b7a2224bff296daee60930faa0ab092c7b910f5 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Oct 2023 18:11:29 +0800 Subject: [PATCH 1/5] Add JsonAdaptedNote with skeleton Note --- .../java/seedu/address/model/note/Note.java | 19 +++++++ .../address/storage/JsonAdaptedNote.java | 50 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/main/java/seedu/address/model/note/Note.java create mode 100644 src/main/java/seedu/address/storage/JsonAdaptedNote.java diff --git a/src/main/java/seedu/address/model/note/Note.java b/src/main/java/seedu/address/model/note/Note.java new file mode 100644 index 00000000000..0b9ff0f3aa8 --- /dev/null +++ b/src/main/java/seedu/address/model/note/Note.java @@ -0,0 +1,19 @@ +package seedu.address.model.note; + +public class Note { + private final String title; + private final String body; + + public Note(String title, String body) { + this.title = title; + this.body = body; + } + + public String getTitle() { + return title; + } + + public String getBody() { + return body; + } +} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedNote.java b/src/main/java/seedu/address/storage/JsonAdaptedNote.java new file mode 100644 index 00000000000..f0f2e6f6fbb --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedNote.java @@ -0,0 +1,50 @@ +package seedu.address.storage; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.note.Note; + +public class JsonAdaptedNote { + public static final String MISSING_FIELD_MESSAGE_FORMAT = "Notes's %s field is missing!"; + + private final String title; + private final String body; + + /** + * Constructs a {@code JsonAdaptedNote} with the given person details. + */ + @JsonCreator + public JsonAdaptedNote(@JsonProperty("title") String title, @JsonProperty("body") String body) { + this.title = title; + this.body = body; + } + + /** + * Converts a given {@code Note} into this class for Jackson use. + */ + public JsonAdaptedNote(Note source) { + title = source.getTitle(); + body = source.getBody(); + + } + + /** + * Converts this Jackson-friendly adapted note object into the model's {@code Note} object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted Note. + */ + public Note toModelType() throws IllegalValueException { + + if (title == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "title")); + } + + if (body == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT,"body")); + } + + return new Note(title, body); + } +} From c6f341d1b0eda73ea9950dfe37d21ce62dd6da51 Mon Sep 17 00:00:00 2001 From: zekone Date: Tue, 10 Oct 2023 19:10:13 +0800 Subject: [PATCH 2/5] Integrate Note to code and fix all dependencies By adding the Note, there were many dependencies that needs to be fixed: 1. Adding a note list to person 2. Changing the constructor of person 3. EditCommand which used the constructor of person 4. Sample data in util. However, these fixes were superficial as Note is not finalised. --- .../address/logic/commands/EditCommand.java | 35 +++++++++++++--- .../logic/parser/AddCommandParser.java | 15 +++++-- .../seedu/address/model/person/Person.java | 24 +++++++++-- .../address/model/util/SampleDataUtil.java | 40 ++++++++++--------- .../address/storage/JsonAdaptedNote.java | 13 ++++-- .../address/storage/JsonAdaptedPerson.java | 23 +++++++++-- 6 files changed, 111 insertions(+), 39 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 4b581c7331e..ab4355adc7a 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -21,6 +21,7 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.note.Note; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; @@ -56,7 +57,7 @@ public class EditCommand extends Command { private final EditPersonDescriptor editPersonDescriptor; /** - * @param index of the person in the filtered person list to edit + * @param index of the person in the filtered person list to edit * @param editPersonDescriptor details to edit the person with */ public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) { @@ -100,8 +101,9 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); + List updatedNotes = editPersonDescriptor.getNotes().orElse(personToEdit.getNotes()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); + return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, updatedNotes); } @Override @@ -129,7 +131,8 @@ public String toString() { } /** - * Stores the details to edit the person with. Each non-empty field value will replace the + * Stores the details to edit the person with. Each non-empty field value will + * replace the * corresponding field value of the person. */ public static class EditPersonDescriptor { @@ -138,8 +141,10 @@ public static class EditPersonDescriptor { private Email email; private Address address; private Set tags; + private List notes; - public EditPersonDescriptor() {} + public EditPersonDescriptor() { + } /** * Copy constructor. @@ -151,6 +156,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { setEmail(toCopy.email); setAddress(toCopy.address); setTags(toCopy.tags); + setNotes(toCopy.notes); } /** @@ -201,7 +207,8 @@ public void setTags(Set tags) { } /** - * Returns an unmodifiable tag set, which throws {@code UnsupportedOperationException} + * Returns an unmodifiable tag set, which throws + * {@code UnsupportedOperationException} * if modification is attempted. * Returns {@code Optional#empty()} if {@code tags} is null. */ @@ -209,6 +216,24 @@ public Optional> getTags() { return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty(); } + /** + * Sets {@code notes} to this object's {@code notes}. + * A defensive copy of {@code notes} is used internally. + */ + public void setNotes(List notes) { + this.notes = (notes != null) ? notes : null; + } + + /** + * Returns an unmodifiable note list, which throws + * {@code UnsupportedOperationException} + * if modification is attempted. + * Returns {@code Optional#empty()} if {@code notes} is null. + */ + public Optional> getNotes() { + return (notes != null) ? Optional.of(Collections.unmodifiableList(notes)) : Optional.empty(); + } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 4ff1a97ed77..d8c91ae6b2c 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -7,11 +7,13 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import java.util.ArrayList; import java.util.Set; import java.util.stream.Stream; import seedu.address.logic.commands.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.note.Note; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; @@ -27,11 +29,12 @@ public class AddCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the AddCommand * and returns an AddCommand object for execution. + * * @throws ParseException if the user input does not conform the expected format */ public AddCommand parse(String args) throws ParseException { - ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_ADDRESS, PREFIX_TAG); if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL) || !argMultimap.getPreamble().isEmpty()) { @@ -45,13 +48,17 @@ public AddCommand parse(String args) throws ParseException { Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Person person = new Person(name, phone, email, address, tagList); + // TODO + ArrayList noteList = new ArrayList(); + + Person person = new Person(name, phone, email, address, tagList, noteList); return new AddCommand(person); } /** - * Returns true if none of the prefixes contains empty {@code Optional} values in the given + * Returns true if none of the prefixes contains empty {@code Optional} values + * in the given * {@code ArgumentMultimap}. */ private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index abe8c46b535..f31e5287048 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -2,17 +2,21 @@ import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Objects; import java.util.Set; import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.note.Note; import seedu.address.model.tag.Tag; /** * Represents a Person in the address book. - * Guarantees: details are present and not null, field values are validated, immutable. + * Guarantees: details are present and not null, field values are validated, + * immutable. */ public class Person { @@ -24,17 +28,19 @@ public class Person { // Data fields private final Address address; private final Set tags = new HashSet<>(); + private final List notes = new ArrayList<>(); /** * Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Address address, Set tags) { - requireAllNonNull(name, phone, email, address, tags); + public Person(Name name, Phone phone, Email email, Address address, Set tags, List notes) { + requireAllNonNull(name, phone, email, address, tags, notes); this.name = name; this.phone = phone; this.email = email; this.address = address; this.tags.addAll(tags); + this.notes.addAll(notes); } public Name getName() { @@ -54,13 +60,23 @@ public Address getAddress() { } /** - * Returns an immutable tag set, which throws {@code UnsupportedOperationException} + * Returns an immutable tag set, which throws + * {@code UnsupportedOperationException} * if modification is attempted. */ public Set getTags() { return Collections.unmodifiableSet(tags); } + /** + * Returns an immutable notes, which throws + * {@code UnsupportedOperationException} + * if modification is attempted. + */ + public List getNotes() { + return Collections.unmodifiableList(notes); + } + /** * Returns true if both persons have the same name. * This defines a weaker notion of equality between two persons. diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 1806da4facf..469e13f6fb3 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -1,11 +1,13 @@ package seedu.address.model.util; +import java.util.ArrayList; import java.util.Arrays; import java.util.Set; import java.util.stream.Collectors; import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.note.Note; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; @@ -18,25 +20,27 @@ */ public class SampleDataUtil { public static Person[] getSamplePersons() { + ArrayList sample = new ArrayList(); + sample.add(new Note("Hello", "Sample body")); return new Person[] { - new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), - new Address("Blk 30 Geylang Street 29, #06-40"), - getTagSet("friends")), - new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), - new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), - getTagSet("colleagues", "friends")), - new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), - new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), - getTagSet("neighbours")), - new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), - new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), - getTagSet("family")), - new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), - new Address("Blk 47 Tampines Street 20, #17-35"), - getTagSet("classmates")), - new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), - new Address("Blk 45 Aljunied Street 85, #11-31"), - getTagSet("colleagues")) + new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), + new Address("Blk 30 Geylang Street 29, #06-40"), + getTagSet("friends"), sample), + new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), + new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), + getTagSet("colleagues", "friends"), sample), + new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), + new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), + getTagSet("neighbours"), sample), + new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), + new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), + getTagSet("family"), sample), + new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), + new Address("Blk 47 Tampines Street 20, #17-35"), + getTagSet("classmates"), sample), + new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), + new Address("Blk 45 Aljunied Street 85, #11-31"), + getTagSet("colleagues"), sample) }; } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedNote.java b/src/main/java/seedu/address/storage/JsonAdaptedNote.java index f0f2e6f6fbb..abe9e75921e 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedNote.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedNote.java @@ -6,6 +6,9 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.note.Note; +/** + * Jackson-friendly version of {@link Note}. + */ public class JsonAdaptedNote { public static final String MISSING_FIELD_MESSAGE_FORMAT = "Notes's %s field is missing!"; @@ -31,9 +34,11 @@ public JsonAdaptedNote(Note source) { } /** - * Converts this Jackson-friendly adapted note object into the model's {@code Note} object. + * Converts this Jackson-friendly adapted note object into the model's + * {@code Note} object. * - * @throws IllegalValueException if there were any data constraints violated in the adapted Note. + * @throws IllegalValueException if there were any data constraints violated in + * the adapted Note. */ public Note toModelType() throws IllegalValueException { @@ -42,9 +47,9 @@ public Note toModelType() throws IllegalValueException { } if (body == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT,"body")); + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "body")); } - + return new Note(title, body); } } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index bd1ca0f56c8..6810ae86641 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.note.Note; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; @@ -29,6 +30,7 @@ class JsonAdaptedPerson { private final String email; private final String address; private final List tags = new ArrayList<>(); + private final List notes = new ArrayList<>(); /** * Constructs a {@code JsonAdaptedPerson} with the given person details. @@ -36,7 +38,7 @@ class JsonAdaptedPerson { @JsonCreator public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, - @JsonProperty("tags") List tags) { + @JsonProperty("tags") List tags, @JsonProperty("notes") List notes) { this.name = name; this.phone = phone; this.email = email; @@ -44,6 +46,9 @@ public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone if (tags != null) { this.tags.addAll(tags); } + if (notes != null) { + this.notes.addAll(notes); + } } /** @@ -57,12 +62,17 @@ public JsonAdaptedPerson(Person source) { tags.addAll(source.getTags().stream() .map(JsonAdaptedTag::new) .collect(Collectors.toList())); + notes.addAll(source.getNotes().stream() + .map(JsonAdaptedNote::new) + .collect(Collectors.toList())); } /** - * Converts this Jackson-friendly adapted person object into the model's {@code Person} object. + * Converts this Jackson-friendly adapted person object into the model's + * {@code Person} object. * - * @throws IllegalValueException if there were any data constraints violated in the adapted person. + * @throws IllegalValueException if there were any data constraints violated in + * the adapted person. */ public Person toModelType() throws IllegalValueException { final List personTags = new ArrayList<>(); @@ -70,6 +80,11 @@ public Person toModelType() throws IllegalValueException { personTags.add(tag.toModelType()); } + final List modelNotes = new ArrayList<>(); + for (JsonAdaptedNote note : notes) { + modelNotes.add(note.toModelType()); + } + if (name == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); } @@ -103,7 +118,7 @@ public Person toModelType() throws IllegalValueException { final Address modelAddress = new Address(address); final Set modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags); + return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags, modelNotes); } } From 3ef5ba499454476e94ff8ab0bc50b1cb350f70d1 Mon Sep 17 00:00:00 2001 From: zekone Date: Tue, 10 Oct 2023 21:47:48 +0800 Subject: [PATCH 3/5] Add Event skeleton and adapt Storage to read and save events --- .../address/logic/commands/EditCommand.java | 25 +++++++- .../logic/parser/AddCommandParser.java | 6 +- .../java/seedu/address/model/event/Event.java | 31 ++++++++++ .../seedu/address/model/person/Person.java | 17 ++++- .../address/model/util/SampleDataUtil.java | 22 ++++--- .../address/storage/JsonAdaptedEvent.java | 62 +++++++++++++++++++ .../address/storage/JsonAdaptedPerson.java | 18 +++++- 7 files changed, 165 insertions(+), 16 deletions(-) create mode 100644 src/main/java/seedu/address/model/event/Event.java create mode 100644 src/main/java/seedu/address/storage/JsonAdaptedEvent.java diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index ab4355adc7a..c1e8ed83f20 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -21,6 +21,7 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.event.Event; import seedu.address.model.note.Note; import seedu.address.model.person.Address; import seedu.address.model.person.Email; @@ -102,8 +103,10 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); List updatedNotes = editPersonDescriptor.getNotes().orElse(personToEdit.getNotes()); + List updatedEvents = editPersonDescriptor.getEvents().orElse(personToEdit.getEvents()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, updatedNotes); + return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, updatedNotes, + updatedEvents); } @Override @@ -142,6 +145,7 @@ public static class EditPersonDescriptor { private Address address; private Set tags; private List notes; + private List events; public EditPersonDescriptor() { } @@ -157,6 +161,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { setAddress(toCopy.address); setTags(toCopy.tags); setNotes(toCopy.notes); + setNotes(toCopy.notes); } /** @@ -234,6 +239,24 @@ public Optional> getNotes() { return (notes != null) ? Optional.of(Collections.unmodifiableList(notes)) : Optional.empty(); } + /** + * Sets {@code events} to this object's {@code events}. + * A defensive copy of {@code events} is used internally. + */ + public void setEvents(List events) { + this.events = (events != null) ? events : null; + } + + /** + * Returns an unmodifiable event list, which throws + * {@code UnsupportedOperationException} + * if modification is attempted. + * Returns {@code Optional#empty()} if {@code notes} is null. + */ + public Optional> getEvents() { + return (events != null) ? Optional.of(Collections.unmodifiableList(events)) : Optional.empty(); + } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index d8c91ae6b2c..116528c27dd 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -13,6 +13,7 @@ import seedu.address.logic.commands.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.event.Event; import seedu.address.model.note.Note; import seedu.address.model.person.Address; import seedu.address.model.person.Email; @@ -47,11 +48,10 @@ public AddCommand parse(String args) throws ParseException { Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - - // TODO ArrayList noteList = new ArrayList(); + ArrayList eventList = new ArrayList(); - Person person = new Person(name, phone, email, address, tagList, noteList); + Person person = new Person(name, phone, email, address, tagList, noteList, eventList); return new AddCommand(person); } diff --git a/src/main/java/seedu/address/model/event/Event.java b/src/main/java/seedu/address/model/event/Event.java new file mode 100644 index 00000000000..64b51ded31c --- /dev/null +++ b/src/main/java/seedu/address/model/event/Event.java @@ -0,0 +1,31 @@ +package seedu.address.model.event; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class Event { + private LocalDateTime start; + private LocalDateTime end; + private String name; + + public Event(String name, String start, String end) { + // Temporary, need update + this.name = name; + this.start = LocalDateTime.now(); + this.end = LocalDateTime.now(); + } + + public String getName() { + return name; + } + + public String getStartString() { + // Temporary, can use Util class instead + return start.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + } + + public String getEndString() { + // Temporary, can use Util class instead + return end.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + } +} diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index f31e5287048..365530e5b77 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -10,6 +10,7 @@ import java.util.Set; import seedu.address.commons.util.ToStringBuilder; +import seedu.address.model.event.Event; import seedu.address.model.note.Note; import seedu.address.model.tag.Tag; @@ -29,18 +30,21 @@ public class Person { private final Address address; private final Set tags = new HashSet<>(); private final List notes = new ArrayList<>(); + private final List events = new ArrayList<>(); /** * Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Address address, Set tags, List notes) { - requireAllNonNull(name, phone, email, address, tags, notes); + public Person(Name name, Phone phone, Email email, Address address, Set tags, List notes, + List events) { + requireAllNonNull(name, phone, email, address, tags, notes, events); this.name = name; this.phone = phone; this.email = email; this.address = address; this.tags.addAll(tags); this.notes.addAll(notes); + this.events.addAll(events); } public Name getName() { @@ -77,6 +81,15 @@ public List getNotes() { return Collections.unmodifiableList(notes); } + /** + * Returns an immutable events, which throws + * {@code UnsupportedOperationException} + * if modification is attempted. + */ + public List getEvents() { + return Collections.unmodifiableList(events); + } + /** * Returns true if both persons have the same name. * This defines a weaker notion of equality between two persons. diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 469e13f6fb3..87a3a9007d9 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -7,6 +7,7 @@ import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.event.Event; import seedu.address.model.note.Note; import seedu.address.model.person.Address; import seedu.address.model.person.Email; @@ -20,27 +21,32 @@ */ public class SampleDataUtil { public static Person[] getSamplePersons() { - ArrayList sample = new ArrayList(); - sample.add(new Note("Hello", "Sample body")); + + ArrayList sampleNotes = new ArrayList(); + sampleNotes.add(new Note("Hello", "Sample body")); + + ArrayList sampleEvents = new ArrayList(); + sampleEvents.add(new Event("Sample event", null, null)); + return new Person[] { new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), new Address("Blk 30 Geylang Street 29, #06-40"), - getTagSet("friends"), sample), + getTagSet("friends"), sampleNotes, sampleEvents), new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), - getTagSet("colleagues", "friends"), sample), + getTagSet("colleagues", "friends"), sampleNotes, sampleEvents), new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), - getTagSet("neighbours"), sample), + getTagSet("neighbours"), sampleNotes, sampleEvents), new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), - getTagSet("family"), sample), + getTagSet("family"), sampleNotes, sampleEvents), new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), new Address("Blk 47 Tampines Street 20, #17-35"), - getTagSet("classmates"), sample), + getTagSet("classmates"), sampleNotes, sampleEvents), new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), new Address("Blk 45 Aljunied Street 85, #11-31"), - getTagSet("colleagues"), sample) + getTagSet("colleagues"), sampleNotes, sampleEvents) }; } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedEvent.java b/src/main/java/seedu/address/storage/JsonAdaptedEvent.java new file mode 100644 index 00000000000..f61c2a42b27 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedEvent.java @@ -0,0 +1,62 @@ +package seedu.address.storage; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.event.Event; + +/** + * Jackson-friendly version of {@link Event}. + */ +public class JsonAdaptedEvent { + public static final String MISSING_FIELD_MESSAGE_FORMAT = "Event's %s field is missing!"; + + private final String name; + private final String start; + private final String end; + + /** + * Constructs a {@code JsonAdaptedEvent} with the given person details. + */ + @JsonCreator + public JsonAdaptedEvent(@JsonProperty("name") String name, + @JsonProperty("start") String start, @JsonProperty("end") String end) { + this.name = name; + this.start = start; + this.end = end; + } + + /** + * Converts a given {@code Event} into this class for Jackson use. + */ + public JsonAdaptedEvent(Event source) { + name = source.getName(); + start = source.getStartString(); + end = source.getEndString(); + } + + /** + * Converts this Jackson-friendly adapted event object into the model's + * {@code Event} object. + * + * @throws IllegalValueException if there were any data constraints violated in + * the adapted event. + */ + public Event toModelType() throws IllegalValueException { + + if (name == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "name")); + } + + if (start == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "start")); + } + + if (end == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "end")); + } + + return new Event(name, start, end); + } +} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index 6810ae86641..1878a14d2aa 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.event.Event; import seedu.address.model.note.Note; import seedu.address.model.person.Address; import seedu.address.model.person.Email; @@ -31,6 +32,7 @@ class JsonAdaptedPerson { private final String address; private final List tags = new ArrayList<>(); private final List notes = new ArrayList<>(); + private final List events = new ArrayList<>(); /** * Constructs a {@code JsonAdaptedPerson} with the given person details. @@ -38,7 +40,8 @@ class JsonAdaptedPerson { @JsonCreator public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, - @JsonProperty("tags") List tags, @JsonProperty("notes") List notes) { + @JsonProperty("tags") List tags, @JsonProperty("notes") List notes, + @JsonProperty("events") List events) { this.name = name; this.phone = phone; this.email = email; @@ -49,6 +52,9 @@ public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone if (notes != null) { this.notes.addAll(notes); } + if (events != null) { + this.events.addAll(events); + } } /** @@ -65,6 +71,9 @@ public JsonAdaptedPerson(Person source) { notes.addAll(source.getNotes().stream() .map(JsonAdaptedNote::new) .collect(Collectors.toList())); + events.addAll(source.getEvents().stream() + .map(JsonAdaptedEvent::new) + .collect(Collectors.toList())); } /** @@ -85,6 +94,11 @@ public Person toModelType() throws IllegalValueException { modelNotes.add(note.toModelType()); } + final List modelEvents = new ArrayList<>(); + for (JsonAdaptedEvent event : events) { + modelEvents.add(event.toModelType()); + } + if (name == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); } @@ -118,7 +132,7 @@ public Person toModelType() throws IllegalValueException { final Address modelAddress = new Address(address); final Set modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags, modelNotes); + return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags, modelNotes, modelEvents); } } From 6b1ad300b6568efeffdb2d41bc1d625c7667948d Mon Sep 17 00:00:00 2001 From: zekone Date: Tue, 10 Oct 2023 22:09:48 +0800 Subject: [PATCH 4/5] AddCommandParser: Fix CI --- src/main/java/seedu/address/logic/parser/AddCommandParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 116528c27dd..67ab4d333ff 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -30,7 +30,7 @@ public class AddCommandParser implements Parser { /** * Parses the given {@code String} of arguments in the context of the AddCommand * and returns an AddCommand object for execution. - * + * * @throws ParseException if the user input does not conform the expected format */ public AddCommand parse(String args) throws ParseException { From 37fb2c4440f0b95f5fe248d150d35de11918851e Mon Sep 17 00:00:00 2001 From: zekone Date: Tue, 10 Oct 2023 22:17:13 +0800 Subject: [PATCH 5/5] SampleDataUtil: Fix CI --- .../address/model/util/SampleDataUtil.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 87a3a9007d9..c881f753931 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -29,24 +29,24 @@ public static Person[] getSamplePersons() { sampleEvents.add(new Event("Sample event", null, null)); return new Person[] { - new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), - new Address("Blk 30 Geylang Street 29, #06-40"), - getTagSet("friends"), sampleNotes, sampleEvents), - new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), - new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), - getTagSet("colleagues", "friends"), sampleNotes, sampleEvents), - new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), - new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), - getTagSet("neighbours"), sampleNotes, sampleEvents), - new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), - new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), - getTagSet("family"), sampleNotes, sampleEvents), - new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), - new Address("Blk 47 Tampines Street 20, #17-35"), - getTagSet("classmates"), sampleNotes, sampleEvents), - new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), - new Address("Blk 45 Aljunied Street 85, #11-31"), - getTagSet("colleagues"), sampleNotes, sampleEvents) + new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), + new Address("Blk 30 Geylang Street 29, #06-40"), + getTagSet("friends"), sampleNotes, sampleEvents), + new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), + new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), + getTagSet("colleagues", "friends"), sampleNotes, sampleEvents), + new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), + new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), + getTagSet("neighbours"), sampleNotes, sampleEvents), + new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), + new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), + getTagSet("family"), sampleNotes, sampleEvents), + new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), + new Address("Blk 47 Tampines Street 20, #17-35"), + getTagSet("classmates"), sampleNotes, sampleEvents), + new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), + new Address("Blk 45 Aljunied Street 85, #11-31"), + getTagSet("colleagues"), sampleNotes, sampleEvents) }; }