From e038819de15b38df7bee21c44278abf06f75b32a Mon Sep 17 00:00:00 2001 From: Thing1Thing2 <93027319+Thing1Thing2@users.noreply.github.com> Date: Tue, 25 Oct 2022 11:10:32 +0800 Subject: [PATCH 1/5] Fix edit commands --- .../logic/commands/AddMeetingCommand.java | 7 +- ...ditCommand.java => EditClientCommand.java} | 34 ++- .../logic/commands/EditMeetingCommand.java | 215 ++++++++++++++++++ ...rser.java => EditClientCommandParser.java} | 20 +- .../parser/EditMeetingCommandParser.java | 68 ++++++ .../address/logic/parser/MyInsuRecParser.java | 10 +- src/main/java/seedu/address/model/Model.java | 13 ++ .../seedu/address/model/ModelManager.java | 14 ++ .../java/seedu/address/model/MyInsuRec.java | 23 +- .../model/meeting/NoConflictMeetingList.java | 8 + .../java/seedu/address/ui/ClientCard.java | 12 +- .../seedu/address/ui/ClientDetailedView.java | 10 +- .../logic/commands/AddClientCommandTest.java | 10 + .../logic/commands/AddProductCommandTest.java | 10 + .../logic/commands/CommandTestUtil.java | 4 +- ...ndTest.java => EditClientCommandTest.java} | 44 ++-- .../commands/EditClientDescriptorTest.java | 2 +- .../logic/parser/EditCommandParserTest.java | 32 +-- .../logic/parser/MyInsuRecParserTest.java | 8 +- .../seedu/address/testutil/ClientUtil.java | 2 +- .../testutil/EditClientDescriptorBuilder.java | 2 +- .../address/testutil/MeetingBuilder.java | 23 +- .../address/testutil/TypicalClients.java | 5 +- 23 files changed, 483 insertions(+), 93 deletions(-) rename src/main/java/seedu/address/logic/commands/{EditCommand.java => EditClientCommand.java} (87%) create mode 100644 src/main/java/seedu/address/logic/commands/EditMeetingCommand.java rename src/main/java/seedu/address/logic/parser/{EditCommandParser.java => EditClientCommandParser.java} (85%) create mode 100644 src/main/java/seedu/address/logic/parser/EditMeetingCommandParser.java rename src/test/java/seedu/address/logic/commands/{EditCommandTest.java => EditClientCommandTest.java} (78%) diff --git a/src/main/java/seedu/address/logic/commands/AddMeetingCommand.java b/src/main/java/seedu/address/logic/commands/AddMeetingCommand.java index 51150b7b59e..71b377b7a8d 100644 --- a/src/main/java/seedu/address/logic/commands/AddMeetingCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddMeetingCommand.java @@ -31,8 +31,9 @@ public class AddMeetingCommand extends Command { + PREFIX_START_TIME + "START TIME " + PREFIX_END_TIME + "END TIME " + PREFIX_DESCRIPTION + "DESCRIPTION "; - public static final String MESSAGE_DUPLICATE_MEETING = "This meeting already exists in MyInsuRec"; - public static final String MESSAGE_CLIENT_NOT_FOUND = "A client named %s could not be found"; + public static final String MESSAGE_CONFLICTING_MEETING = + "This meeting conflicts with another that exists in MyInsuRec"; + public static final String MESSAGE_MEETING_NOT_FOUND = "A meeting %s could not be found"; private final MeetingDate meetingDate; private final MeetingTime meetingStartTime; @@ -63,7 +64,7 @@ public CommandResult execute(Model model) throws CommandException { Meeting meetingToAdd = new Meeting(clientToUpdate, description, meetingDate, meetingStartTime, meetingEndTime); if (model.hasMeeting(meetingToAdd)) { - throw new CommandException(MESSAGE_DUPLICATE_MEETING); + throw new CommandException(MESSAGE_CONFLICTING_MEETING); } clientToUpdate.addMeeting(meetingToAdd); diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditClientCommand.java similarity index 87% rename from src/main/java/seedu/address/logic/commands/EditCommand.java rename to src/main/java/seedu/address/logic/commands/EditClientCommand.java index 296ee51542d..7f2b7ec5929 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditClientCommand.java @@ -10,6 +10,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_PRODUCT; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_CLIENTS; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_MEETING; import java.util.Collections; import java.util.HashSet; @@ -28,14 +29,15 @@ import seedu.address.model.client.Email; import seedu.address.model.client.Name; import seedu.address.model.client.Phone; +import seedu.address.model.meeting.Meeting; import seedu.address.model.product.Product; /** * Edits the details of an existing client in MyInsuRec. */ -public class EditCommand extends Command { +public class EditClientCommand extends Command { - public static final String COMMAND_WORD = "edit"; + public static final String COMMAND_WORD = "editClient"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the client identified " + "by the index number used in the displayed client list. " @@ -63,7 +65,7 @@ public class EditCommand extends Command { * @param index of the client in the filtered client list to edit * @param editClientDescriptor details to edit the client with */ - public EditCommand(Index index, EditClientDescriptor editClientDescriptor) { + public EditClientCommand(Index index, EditClientDescriptor editClientDescriptor) { requireNonNull(index); requireNonNull(editClientDescriptor); @@ -94,9 +96,15 @@ public CommandResult execute(Model model) throws CommandException { throw new CommandException(MESSAGE_NON_EXISTING_PRODUCT); } + model.setClient(clientToEdit, editedClient); model.updateFilteredClientList(PREDICATE_SHOW_ALL_CLIENTS); - return new CommandResult(String.format(MESSAGE_EDIT_CLIENT_SUCCESS, editedClient)); + clientToEdit.getMeetings().forEach(meeting -> + model.deleteMeeting(meeting)); + editedClient.getMeetings().forEach(meeting -> + model.addMeeting(meeting)); + model.updateFilteredMeetingList(PREDICATE_SHOW_ALL_MEETING); + return new CommandResult(String.format(MESSAGE_EDIT_CLIENT_SUCCESS, editedClient), CommandSpecific.CLIENT); } /** @@ -119,8 +127,20 @@ private static Client createEditedClient(Client clientToEdit, EditClientDescript : editClientDescriptor.getBirthday(); Set updatedProducts = editClientDescriptor.getProducts().orElse(clientToEdit.getProducts()); - return new Client(updatedName, updatedPhone, updatedEmail, updatedAddress, + Client client = new Client(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedBirthday, updatedProducts); + + // update client in each meeting this client has + List meetings = clientToEdit.getMeetings(); + Meeting meeting; + Meeting updatedMeeting; + for (int i = 0; i < meetings.size(); i++) { + meeting = meetings.get(i); + updatedMeeting = new Meeting(client, meeting.getDescription(), meeting.getMeetingDate(), + meeting.getMeetingStartTime(), meeting.getMeetingEndTime()); + client.addMeeting(updatedMeeting); + } + return client; } @Override @@ -131,12 +151,12 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof EditCommand)) { + if (!(other instanceof EditClientCommand)) { return false; } // state check - EditCommand e = (EditCommand) other; + EditClientCommand e = (EditClientCommand) other; return index.equals(e.index) && editClientDescriptor.equals(e.editClientDescriptor); } diff --git a/src/main/java/seedu/address/logic/commands/EditMeetingCommand.java b/src/main/java/seedu/address/logic/commands/EditMeetingCommand.java new file mode 100644 index 00000000000..85fdbced59a --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/EditMeetingCommand.java @@ -0,0 +1,215 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.core.Messages.MESSAGE_END_TIME_BEFORE_START_TIME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION; +import static seedu.address.logic.parser.CliSyntax.PREFIX_END_TIME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_INDEX; +import static seedu.address.logic.parser.CliSyntax.PREFIX_START_TIME; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_CLIENTS; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_MEETING; + +import java.util.List; +import java.util.Optional; + +import seedu.address.commons.core.Messages; +import seedu.address.commons.core.index.Index; +import seedu.address.commons.util.CollectionUtil; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.meeting.Description; +import seedu.address.model.meeting.Meeting; +import seedu.address.model.meeting.MeetingDate; +import seedu.address.model.meeting.MeetingTime; + + +/** + * Edits the details of an existing meeting in MyInsuRec. + */ +public class EditMeetingCommand extends Command { + + public static final String COMMAND_WORD = "editMeeting"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the meeting identified " + + "by the index number used in the displayed meeting list. \n" + + "Existing values will be overwritten by the input values.\n" + + "Parameters: INDEX (must be a positive integer) \n" + + "[" + PREFIX_DATE + "DATE] " + + "[" + PREFIX_START_TIME + "START TIME] " + + "[" + PREFIX_END_TIME + "END TIME] " + + "[" + PREFIX_DESCRIPTION + "DESCRIPTION]\n" + + "Example: " + COMMAND_WORD + " " + + PREFIX_INDEX + "1 " + + PREFIX_DATE + "23122022 "; + + public static final String MESSAGE_EDIT_MEETING_SUCCESS = "Edited Meeting: %1$s"; + public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; + public static final String MESSAGE_DUPLICATE_MEETING = "This meeting already exists in MyInsuRec."; + + private final Index index; + private final EditMeetingDescriptor editMeetingDescriptor; + + /** + * @param index of the meeting in the filtered meeting list to edit + * @param editMeetingDescriptor details to edit the meeting with + */ + public EditMeetingCommand(Index index, EditMeetingDescriptor editMeetingDescriptor) { + requireNonNull(index); + requireNonNull(editMeetingDescriptor); + + this.index = index; + this.editMeetingDescriptor = new EditMeetingDescriptor(editMeetingDescriptor); + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + List lastShownList = model.getFilteredMeetingList(); + + if (index.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_MEETING_DISPLAYED_INDEX); + } + + Meeting meetingToEdit = lastShownList.get(index.getZeroBased()); + Meeting editedMeeting = createEditedMeeting(meetingToEdit, editMeetingDescriptor); + + if (!meetingToEdit.equals(editedMeeting) && model.hasSpecificMeeting(editedMeeting)) { + throw new CommandException(MESSAGE_DUPLICATE_MEETING); + } + + // update meeting list + model.setMeeting(meetingToEdit, editedMeeting); + model.updateFilteredMeetingList(PREDICATE_SHOW_ALL_MEETING); + + // update client list + model.setClient(meetingToEdit.getClient(), editedMeeting.getClient()); + model.updateFilteredClientList(PREDICATE_SHOW_ALL_CLIENTS); + + return new CommandResult(String.format(MESSAGE_EDIT_MEETING_SUCCESS, editedMeeting), CommandSpecific.MEETING); + } + + /** + * Creates and returns a {@code Meeting} with the details of {@code meetingToEdit} + * edited with {@code EditMeetingDescriptor}. + */ + private static Meeting createEditedMeeting(Meeting meetingToEdit, EditMeetingDescriptor editMeetingDescriptor) + throws CommandException { + assert meetingToEdit != null; + + MeetingDate updatedDate = editMeetingDescriptor.getDate().orElse(meetingToEdit.getMeetingDate()); + Description updatedDescription = editMeetingDescriptor.getDescription().orElse(meetingToEdit.getDescription()); + MeetingTime updatedEndTime = editMeetingDescriptor.getEndTime().orElse(meetingToEdit.getMeetingEndTime()); + MeetingTime updatedStartTime = editMeetingDescriptor.getStartTime().orElse(meetingToEdit.getMeetingStartTime()); + if (updatedEndTime.isBefore(updatedStartTime)) { + throw new CommandException(MESSAGE_END_TIME_BEFORE_START_TIME); + } + Meeting meeting = new Meeting(meetingToEdit.getClient(), updatedDescription, updatedDate, + updatedStartTime, updatedEndTime); + meeting.getClient().removeMeeting(meetingToEdit); + meeting.getClient().addMeeting(meeting); + return meeting; + } + + @Override + public boolean equals(Object other) { + // short circuit if same object + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof EditMeetingCommand)) { + return false; + } + + // state check + EditMeetingCommand e = (EditMeetingCommand) other; + return index.equals(e.index) + && editMeetingDescriptor.equals(e.editMeetingDescriptor); + } + + /** + * Stores the details to edit the meeting with. Each non-empty field value will replace the + * corresponding field value of the meeting. + */ + public static class EditMeetingDescriptor { + private MeetingDate date; + private MeetingTime startTime; + private MeetingTime endTime; + private Description description; + + public EditMeetingDescriptor() {} + + /** + * Copy constructor. + */ + public EditMeetingDescriptor(EditMeetingDescriptor toCopy) { + date = toCopy.date; + startTime = toCopy.startTime; + endTime = toCopy.endTime; + description = toCopy.description; + } + + /** + * Returns true if at least one field is edited. + */ + public boolean isAnyFieldEdited() { + return CollectionUtil.isAnyNonNull(date, startTime, endTime, description); + } + + public void setDate(MeetingDate date) { + this.date = date; + } + + public Optional getDate() { + return Optional.ofNullable(date); + } + + public void setStartTime(MeetingTime startTime) { + this.startTime = startTime; + } + + public Optional getStartTime() { + return Optional.ofNullable(startTime); + } + + public void setEndTime(MeetingTime endTime) { + this.endTime = endTime; + } + + public Optional getEndTime() { + return Optional.ofNullable(endTime); + } + + public void setDescription(Description description) { + this.description = description; + } + + public Optional getDescription() { + return Optional.ofNullable(description); + } + + + @Override + public boolean equals(Object other) { + // short circuit if same object + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof EditMeetingDescriptor)) { + return false; + } + + // state check + EditMeetingDescriptor e = (EditMeetingDescriptor) other; + + return getDate().equals(e.getDate()) + && getEndTime().equals(e.getEndTime()) + && getStartTime().equals(e.getStartTime()) + && getDescription().equals(e.getDescription()); + } + } +} diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditClientCommandParser.java similarity index 85% rename from src/main/java/seedu/address/logic/parser/EditCommandParser.java rename to src/main/java/seedu/address/logic/parser/EditClientCommandParser.java index dc36e412259..59ee3ebea3c 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditClientCommandParser.java @@ -18,23 +18,23 @@ import java.util.Set; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.EditCommand; -import seedu.address.logic.commands.EditCommand.EditClientDescriptor; +import seedu.address.logic.commands.EditClientCommand; +import seedu.address.logic.commands.EditClientCommand.EditClientDescriptor; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.client.Birthday; import seedu.address.model.product.Product; /** - * Parses input arguments and creates a new EditCommand object + * Parses input arguments and creates a new EditClientCommand object */ -public class EditCommandParser implements Parser { +public class EditClientCommandParser implements Parser { /** - * Parses the given {@code String} of arguments in the context of the EditCommand - * and returns an EditCommand object for execution. + * Parses the given {@code String} of arguments in the context of the EditClientCommand + * and returns an EditClientCommand object for execution. * @throws ParseException if the user input does not conform the expected format */ - public EditCommand parse(String args) throws ParseException { + public EditClientCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_INDEX, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, @@ -45,7 +45,7 @@ public EditCommand parse(String args) throws ParseException { try { index = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_INDEX).get()); } catch (ParseException | NoSuchElementException e) { - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), e); + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditClientCommand.MESSAGE_USAGE), e); } EditClientDescriptor editClientDescriptor = new EditClientDescriptor(); @@ -73,10 +73,10 @@ public EditCommand parse(String args) throws ParseException { if (!editClientDescriptor.isAnyFieldEdited()) { - throw new ParseException(EditCommand.MESSAGE_NOT_EDITED); + throw new ParseException(EditClientCommand.MESSAGE_NOT_EDITED); } - return new EditCommand(index, editClientDescriptor); + return new EditClientCommand(index, editClientDescriptor); } /** diff --git a/src/main/java/seedu/address/logic/parser/EditMeetingCommandParser.java b/src/main/java/seedu/address/logic/parser/EditMeetingCommandParser.java new file mode 100644 index 00000000000..2272434d4b5 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/EditMeetingCommandParser.java @@ -0,0 +1,68 @@ +package seedu.address.logic.parser; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION; +import static seedu.address.logic.parser.CliSyntax.PREFIX_END_TIME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_INDEX; +import static seedu.address.logic.parser.CliSyntax.PREFIX_START_TIME; + +import java.util.NoSuchElementException; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.EditMeetingCommand; +import seedu.address.logic.commands.EditMeetingCommand.EditMeetingDescriptor; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.meeting.Description; +import seedu.address.model.meeting.MeetingDate; + + +/** + * Parses input arguments and creates a new EditMeetingCommand object + */ +public class EditMeetingCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the EditMeetingCommand + * and returns an EditMeetingCommand object for execution. + * + * @throws ParseException if the user input does not conform the expected format + */ + public EditMeetingCommand parse(String args) throws ParseException { + requireNonNull(args); + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(args, PREFIX_INDEX, PREFIX_DATE, PREFIX_START_TIME, PREFIX_END_TIME, + PREFIX_DESCRIPTION); + + Index index; + + try { + index = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_INDEX).get()); + } catch (ParseException | NoSuchElementException e) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, + EditMeetingCommand.MESSAGE_USAGE), e); + } + + EditMeetingDescriptor editMeetingDescriptor = new EditMeetingDescriptor(); + if (argMultimap.getValue(PREFIX_DESCRIPTION).isPresent()) { + editMeetingDescriptor.setDescription(new Description(argMultimap.getValue(PREFIX_DESCRIPTION).get())); + } + if (argMultimap.getValue(PREFIX_DATE).isPresent()) { + editMeetingDescriptor.setDate(new MeetingDate(ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get(), + "meeting"))); + } + if (argMultimap.getValue(PREFIX_START_TIME).isPresent()) { + editMeetingDescriptor.setStartTime(ParserUtil.parseTime(argMultimap.getValue(PREFIX_START_TIME).get())); + } + if (argMultimap.getValue(PREFIX_END_TIME).isPresent()) { + editMeetingDescriptor.setEndTime(ParserUtil.parseTime(argMultimap.getValue(PREFIX_END_TIME).get())); + } + + if (!editMeetingDescriptor.isAnyFieldEdited()) { + throw new ParseException(EditMeetingCommand.MESSAGE_NOT_EDITED); + } + + return new EditMeetingCommand(index, editMeetingDescriptor); + } +} diff --git a/src/main/java/seedu/address/logic/parser/MyInsuRecParser.java b/src/main/java/seedu/address/logic/parser/MyInsuRecParser.java index 713e1b21a1e..aa42a03652a 100644 --- a/src/main/java/seedu/address/logic/parser/MyInsuRecParser.java +++ b/src/main/java/seedu/address/logic/parser/MyInsuRecParser.java @@ -14,7 +14,8 @@ import seedu.address.logic.commands.DeleteClientCommand; import seedu.address.logic.commands.DeleteMeetingCommand; import seedu.address.logic.commands.DeleteProductCommand; -import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.commands.EditClientCommand; +import seedu.address.logic.commands.EditMeetingCommand; import seedu.address.logic.commands.ExitCommand; import seedu.address.logic.commands.FindCommand; import seedu.address.logic.commands.HelpCommand; @@ -55,8 +56,11 @@ public Command parseCommand(String userInput) throws ParseException { case AddClientCommand.COMMAND_WORD: return new AddClientCommandParser().parse(arguments); - case EditCommand.COMMAND_WORD: - return new EditCommandParser().parse(arguments); + case EditClientCommand.COMMAND_WORD: + return new EditClientCommandParser().parse(arguments); + + case EditMeetingCommand.COMMAND_WORD: + return new EditMeetingCommandParser().parse(arguments); case DeleteClientCommand.COMMAND_WORD: return new DeleteClientCommandParser().parse(arguments); diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 39f34cff8ae..7e76c438e1d 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -82,12 +82,25 @@ public interface Model { */ boolean hasMeeting(Meeting meeting); + /** + * Returns true if a meeting with the same date, time, and description as {@code meeting} exists in the MyInsuRec. + * This is a stronger version of hasMeeting. + */ + boolean hasSpecificMeeting(Meeting meeting); + /** * Adds the given meeting. * {@code meeting} must not already exist in the MyInsuRec. */ void addMeeting(Meeting meeting); + /** + * Replaces the given meeting {@code target} with {@code editedMeeting}. + * {@code target} must exist in the MyInsuRec. + * The meeting identity of {@code editedMeeting} must not be the same as another existing meeting in the MyInsuRec. + */ + void setMeeting(Meeting target, Meeting editedMeeting); + /** * Adds the given product. * {@code product} must not already exist in the MyInsuRec. diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index ce4e1a74709..c1e90825fe9 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -137,6 +137,20 @@ public boolean hasMeeting(Meeting meeting) { return myInsuRec.hasMeeting(meeting); } + @Override + public boolean hasSpecificMeeting(Meeting meeting) { + requireNonNull(meeting); + return myInsuRec.hasSpecificMeeting(meeting); + } + + @Override + public void setMeeting(Meeting target, Meeting editedMeeting) { + requireAllNonNull(target, editedMeeting); + + myInsuRec.setMeeting(target, editedMeeting); + } + + @Override public void addMeeting(Meeting meeting) { requireNonNull(meeting); diff --git a/src/main/java/seedu/address/model/MyInsuRec.java b/src/main/java/seedu/address/model/MyInsuRec.java index 156bfdc20e7..15fdfa644b0 100644 --- a/src/main/java/seedu/address/model/MyInsuRec.java +++ b/src/main/java/seedu/address/model/MyInsuRec.java @@ -140,12 +140,33 @@ public void removeMeeting(Meeting meeting) { } /** - * Returns true if a meeting with the same identity as {@code meeting} exists in the meetings book. + * Returns true if a meeting with the same date and time as {@code meeting} exists in the meetings book. */ public boolean hasMeeting(Meeting meeting) { return meetings.contains(meeting); } + /** + * Returns true if a meeting with the same date, time, and description + * as {@code meeting} exists in the meetings book. + * This is stronger version of hasMeeting. + */ + public boolean hasSpecificMeeting(Meeting meeting) { + return meetings.containsSpecific(meeting); + } + + /** + * Replaces the given meeting {@code target} in the list with {@code editedMeeting}. + * {@code target} must exist in MyInsuRec. + * The Meeting identity of {@code editedMeeting} must not be the same as + * another existing Meeting in MyInsuRec. + */ + public void setMeeting(Meeting target, Meeting editedMeeting) { + requireNonNull(editedMeeting); + + meetings.setMeeting(target, editedMeeting); + } + //// product-level operations /** diff --git a/src/main/java/seedu/address/model/meeting/NoConflictMeetingList.java b/src/main/java/seedu/address/model/meeting/NoConflictMeetingList.java index faffe6126ae..055af8b3826 100644 --- a/src/main/java/seedu/address/model/meeting/NoConflictMeetingList.java +++ b/src/main/java/seedu/address/model/meeting/NoConflictMeetingList.java @@ -37,6 +37,14 @@ public boolean contains(Meeting toCheck) { return internalList.stream().anyMatch(toCheck::willConflict); } + /** + * Returns true if the list contains an identical meeting as the given argument. + */ + public boolean containsSpecific(Meeting toCheck) { + requireNonNull(toCheck); + return internalList.stream().anyMatch(toCheck::equals); + } + /** * Adds a meeting to the list. * The meeting must not conflict with any meetings in the list. diff --git a/src/main/java/seedu/address/ui/ClientCard.java b/src/main/java/seedu/address/ui/ClientCard.java index 3011494bbcd..6da2c0e25d2 100644 --- a/src/main/java/seedu/address/ui/ClientCard.java +++ b/src/main/java/seedu/address/ui/ClientCard.java @@ -59,8 +59,16 @@ public ClientCard(Client client, int displayedIndex) { id.setText(displayedIndex + ". "); name.setText(client.getName().fullName); phone.setText(client.getPhone().value); - address.setText(client.getAddress().get().toString()); - email.setText(client.getEmail().get().toString()); + if (!client.getAddress().isEmpty()) { + address.setText(client.getAddress().get().toString()); + } else { + address.setText(""); + } + if (!client.getEmail().isEmpty()) { + email.setText(client.getEmail().get().toString()); + } else { + email.setText(""); + } client.getProducts().stream() .sorted(Comparator.comparing(product -> product.productName)) .forEach(product -> products.getChildren().add(new Label(product.productName))); diff --git a/src/main/java/seedu/address/ui/ClientDetailedView.java b/src/main/java/seedu/address/ui/ClientDetailedView.java index 964c9983a90..1b4d420c329 100644 --- a/src/main/java/seedu/address/ui/ClientDetailedView.java +++ b/src/main/java/seedu/address/ui/ClientDetailedView.java @@ -11,6 +11,7 @@ import seedu.address.commons.core.LogsCenter; import seedu.address.model.client.Birthday; import seedu.address.model.client.Client; +import seedu.address.model.client.Email; import seedu.address.model.meeting.Meeting; /** @@ -46,7 +47,14 @@ public ClientDetailedView(Client client) { this.client = client; clientName.setText(client.getName().toString()); phoneNumber.setText(client.getPhone().toString()); - email.setText(client.getEmail().toString()); + + Optional clientEmail = client.getEmail(); + if (clientEmail.isEmpty()) { + email.setText(""); + } else { + email.setText(client.getEmail().toString()); + } + Optional clientBirthday = client.getBirthday(); if (clientBirthday.isEmpty()) { birthday.setText(""); diff --git a/src/test/java/seedu/address/logic/commands/AddClientCommandTest.java b/src/test/java/seedu/address/logic/commands/AddClientCommandTest.java index e40182c67fb..54ab77918ed 100644 --- a/src/test/java/seedu/address/logic/commands/AddClientCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddClientCommandTest.java @@ -151,6 +151,16 @@ public boolean hasMeeting(Meeting meeting) { throw new AssertionError("This method should not be called."); } + @Override + public boolean hasSpecificMeeting(Meeting meeting) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setMeeting(Meeting target, Meeting editedMeeting) { + throw new AssertionError("This method should not be called."); + } + @Override public void addProduct(Product product) { throw new AssertionError("This method should not be called."); diff --git a/src/test/java/seedu/address/logic/commands/AddProductCommandTest.java b/src/test/java/seedu/address/logic/commands/AddProductCommandTest.java index cdf0d90a630..8250efb8596 100644 --- a/src/test/java/seedu/address/logic/commands/AddProductCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddProductCommandTest.java @@ -148,11 +148,21 @@ public void addMeeting(Meeting meeting) { throw new AssertionError("This method should not be called."); } + @Override + public void setMeeting(Meeting target, Meeting editedMeeting) { + + } + @Override public boolean hasMeeting(Meeting meeting) { throw new AssertionError("This method should not be called."); } + @Override + public boolean hasSpecificMeeting(Meeting meeting) { + return false; + } + @Override public void addProduct(Product product) { throw new AssertionError("This method should not be called."); diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index a7fbc2fedf3..f526387fc31 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -72,8 +72,8 @@ public class CommandTestUtil { public static final String PREAMBLE_WHITESPACE = "\t \r \n"; public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble"; - public static final EditCommand.EditClientDescriptor DESC_AMY; - public static final EditCommand.EditClientDescriptor DESC_BOB; + public static final EditClientCommand.EditClientDescriptor DESC_AMY; + public static final EditClientCommand.EditClientDescriptor DESC_BOB; static { DESC_AMY = new EditClientDescriptorBuilder().withName(VALID_NAME_AMY) diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditClientCommandTest.java similarity index 78% rename from src/test/java/seedu/address/logic/commands/EditCommandTest.java rename to src/test/java/seedu/address/logic/commands/EditClientCommandTest.java index 018372ce973..336f69813aa 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditClientCommandTest.java @@ -19,7 +19,7 @@ import seedu.address.commons.core.Messages; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.EditCommand.EditClientDescriptor; +import seedu.address.logic.commands.EditClientCommand.EditClientDescriptor; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.MyInsuRec; @@ -29,9 +29,9 @@ import seedu.address.testutil.EditClientDescriptorBuilder; /** - * Contains integration tests (interaction with the Model) and unit tests for EditCommand. + * Contains integration tests (interaction with the Model) and unit tests for EditClientCommand. */ -public class EditCommandTest { +public class EditClientCommandTest { private Model model = new ModelManager(getTypicalMyInsuRec(), new UserPrefs()); @@ -39,9 +39,9 @@ public class EditCommandTest { public void execute_allFieldsSpecifiedUnfilteredList_success() { Client editedClient = new ClientBuilder().build(); EditClientDescriptor descriptor = new EditClientDescriptorBuilder(editedClient).build(); - EditCommand editCommand = new EditCommand(INDEX_FIRST_ELEMENT, descriptor); + EditClientCommand editCommand = new EditClientCommand(INDEX_FIRST_ELEMENT, descriptor); - String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_CLIENT_SUCCESS, editedClient); + String expectedMessage = String.format(EditClientCommand.MESSAGE_EDIT_CLIENT_SUCCESS, editedClient); Model expectedModel = new ModelManager(new MyInsuRec(model.getMyInsuRec()), new UserPrefs()); expectedModel.setClient(model.getFilteredClientList().get(0), editedClient); @@ -59,9 +59,9 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { EditClientDescriptor descriptor = new EditClientDescriptorBuilder().withName(VALID_NAME_BOB) .withPhone(VALID_PHONE_BOB).withProducts(VALID_PRODUCT_2).build(); - EditCommand editCommand = new EditCommand(indexLastClient, descriptor); + EditClientCommand editCommand = new EditClientCommand(indexLastClient, descriptor); - String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_CLIENT_SUCCESS, editedClient); + String expectedMessage = String.format(EditClientCommand.MESSAGE_EDIT_CLIENT_SUCCESS, editedClient); Model expectedModel = new ModelManager(new MyInsuRec(model.getMyInsuRec()), new UserPrefs()); expectedModel.setClient(lastClient, editedClient); @@ -80,7 +80,7 @@ public void execute_invalidProductsUnfilteredList_failure() { EditClientDescriptor descriptor = new EditClientDescriptorBuilder().withName(VALID_NAME_BOB) .withPhone(VALID_PHONE_BOB).withProducts(VALID_PRODUCT_2, INVALID_PRODUCT_1).build(); - EditCommand editCommand = new EditCommand(indexLastClient, descriptor); + EditClientCommand editCommand = new EditClientCommand(indexLastClient, descriptor); String expectedMessage = Messages.MESSAGE_NON_EXISTING_PRODUCT; @@ -89,10 +89,10 @@ public void execute_invalidProductsUnfilteredList_failure() { @Test public void execute_noFieldSpecifiedUnfilteredList_success() { - EditCommand editCommand = new EditCommand(INDEX_FIRST_ELEMENT, new EditClientDescriptor()); + EditClientCommand editCommand = new EditClientCommand(INDEX_FIRST_ELEMENT, new EditClientDescriptor()); Client editedClient = model.getFilteredClientList().get(INDEX_FIRST_ELEMENT.getZeroBased()); - String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_CLIENT_SUCCESS, editedClient); + String expectedMessage = String.format(EditClientCommand.MESSAGE_EDIT_CLIENT_SUCCESS, editedClient); Model expectedModel = new ModelManager(new MyInsuRec(model.getMyInsuRec()), new UserPrefs()); @@ -105,10 +105,10 @@ public void execute_filteredList_success() { Client clientInFilteredList = model.getFilteredClientList().get(INDEX_FIRST_ELEMENT.getZeroBased()); Client editedClient = new ClientBuilder(clientInFilteredList).withName(VALID_NAME_BOB).build(); - EditCommand editCommand = new EditCommand(INDEX_FIRST_ELEMENT, + EditClientCommand editCommand = new EditClientCommand(INDEX_FIRST_ELEMENT, new EditClientDescriptorBuilder().withName(VALID_NAME_BOB).build()); - String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_CLIENT_SUCCESS, editedClient); + String expectedMessage = String.format(EditClientCommand.MESSAGE_EDIT_CLIENT_SUCCESS, editedClient); Model expectedModel = new ModelManager(new MyInsuRec(model.getMyInsuRec()), new UserPrefs()); expectedModel.setClient(model.getFilteredClientList().get(0), editedClient); @@ -120,9 +120,9 @@ public void execute_filteredList_success() { public void execute_duplicateClientUnfilteredList_failure() { Client firstClient = model.getFilteredClientList().get(INDEX_FIRST_ELEMENT.getZeroBased()); EditClientDescriptor descriptor = new EditClientDescriptorBuilder(firstClient).build(); - EditCommand editCommand = new EditCommand(INDEX_SECOND_ELEMENT, descriptor); + EditClientCommand editCommand = new EditClientCommand(INDEX_SECOND_ELEMENT, descriptor); - assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_CLIENT); + assertCommandFailure(editCommand, model, EditClientCommand.MESSAGE_DUPLICATE_CLIENT); } @Test @@ -131,17 +131,17 @@ public void execute_duplicateClientFilteredList_failure() { // edit client in filtered list into a duplicate in MyInsuRec Client clientInList = model.getMyInsuRec().getClientList().get(INDEX_SECOND_ELEMENT.getZeroBased()); - EditCommand editCommand = new EditCommand(INDEX_FIRST_ELEMENT, + EditClientCommand editCommand = new EditClientCommand(INDEX_FIRST_ELEMENT, new EditClientDescriptorBuilder(clientInList).build()); - assertCommandFailure(editCommand, model, EditCommand.MESSAGE_DUPLICATE_CLIENT); + assertCommandFailure(editCommand, model, EditClientCommand.MESSAGE_DUPLICATE_CLIENT); } @Test public void execute_invalidClientIndexUnfilteredList_failure() { Index outOfBoundIndex = Index.fromOneBased(model.getFilteredClientList().size() + 1); EditClientDescriptor descriptor = new EditClientDescriptorBuilder().withName(VALID_NAME_BOB).build(); - EditCommand editCommand = new EditCommand(outOfBoundIndex, descriptor); + EditClientCommand editCommand = new EditClientCommand(outOfBoundIndex, descriptor); assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_CLIENT_DISPLAYED_INDEX); } @@ -157,7 +157,7 @@ public void execute_invalidClientIndexFilteredList_failure() { // ensures that outOfBoundIndex is still in bounds of client list assertTrue(outOfBoundIndex.getZeroBased() < model.getMyInsuRec().getClientList().size()); - EditCommand editCommand = new EditCommand(outOfBoundIndex, + EditClientCommand editCommand = new EditClientCommand(outOfBoundIndex, new EditClientDescriptorBuilder().withName(VALID_NAME_BOB).build()); assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_CLIENT_DISPLAYED_INDEX); @@ -165,11 +165,11 @@ public void execute_invalidClientIndexFilteredList_failure() { @Test public void equals() { - final EditCommand standardCommand = new EditCommand(INDEX_FIRST_ELEMENT, DESC_AMY); + final EditClientCommand standardCommand = new EditClientCommand(INDEX_FIRST_ELEMENT, DESC_AMY); // same values -> returns true EditClientDescriptor copyDescriptor = new EditClientDescriptor(DESC_AMY); - EditCommand commandWithSameValues = new EditCommand(INDEX_FIRST_ELEMENT, copyDescriptor); + EditClientCommand commandWithSameValues = new EditClientCommand(INDEX_FIRST_ELEMENT, copyDescriptor); assertTrue(standardCommand.equals(commandWithSameValues)); // same object -> returns true @@ -182,10 +182,10 @@ public void equals() { assertFalse(standardCommand.equals(new ClearCommand())); // different index -> returns false - assertFalse(standardCommand.equals(new EditCommand(INDEX_SECOND_ELEMENT, DESC_AMY))); + assertFalse(standardCommand.equals(new EditClientCommand(INDEX_SECOND_ELEMENT, DESC_AMY))); // different descriptor -> returns false - assertFalse(standardCommand.equals(new EditCommand(INDEX_FIRST_ELEMENT, DESC_BOB))); + assertFalse(standardCommand.equals(new EditClientCommand(INDEX_FIRST_ELEMENT, DESC_BOB))); } } diff --git a/src/test/java/seedu/address/logic/commands/EditClientDescriptorTest.java b/src/test/java/seedu/address/logic/commands/EditClientDescriptorTest.java index 5d24949c6fa..0d03a26d8c5 100644 --- a/src/test/java/seedu/address/logic/commands/EditClientDescriptorTest.java +++ b/src/test/java/seedu/address/logic/commands/EditClientDescriptorTest.java @@ -12,7 +12,7 @@ import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.EditCommand.EditClientDescriptor; +import seedu.address.logic.commands.EditClientCommand.EditClientDescriptor; import seedu.address.testutil.EditClientDescriptorBuilder; public class EditClientDescriptorTest { diff --git a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java index 15810e1a6de..7daf02ee683 100644 --- a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java @@ -34,8 +34,8 @@ import org.junit.jupiter.api.Test; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.EditCommand; -import seedu.address.logic.commands.EditCommand.EditClientDescriptor; +import seedu.address.logic.commands.EditClientCommand; +import seedu.address.logic.commands.EditClientCommand.EditClientDescriptor; import seedu.address.model.client.Address; import seedu.address.model.client.Email; import seedu.address.model.client.Name; @@ -48,9 +48,9 @@ public class EditCommandParserTest { private static final String Product_EMPTY = " " + PREFIX_PRODUCT; private static final String MESSAGE_INVALID_FORMAT = - String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE); + String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditClientCommand.MESSAGE_USAGE); - private EditCommandParser parser = new EditCommandParser(); + private EditClientCommandParser parser = new EditClientCommandParser(); @Test public void parse_missingParts_failure() { @@ -58,7 +58,7 @@ public void parse_missingParts_failure() { assertParseFailure(parser, VALID_NAME_AMY, MESSAGE_INVALID_FORMAT); // no field specified - assertParseFailure(parser, " i/1", EditCommand.MESSAGE_NOT_EDITED); + assertParseFailure(parser, " i/1", EditClientCommand.MESSAGE_NOT_EDITED); // no index and no field specified assertParseFailure(parser, "", MESSAGE_INVALID_FORMAT); @@ -108,7 +108,7 @@ public void parse_allFieldsSpecified_success() { EditClientDescriptor descriptor = new EditClientDescriptorBuilder().withName(VALID_NAME_AMY) .withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY) .withProducts(VALID_PRODUCT_2, VALID_PRODUCT_1).build(); - EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); + EditClientCommand expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); } @@ -120,7 +120,7 @@ public void parse_someFieldsSpecified_success() { EditClientDescriptor descriptor = new EditClientDescriptorBuilder().withPhone(VALID_PHONE_BOB) .withEmail(VALID_EMAIL_AMY).build(); - EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); + EditClientCommand expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); } @@ -131,31 +131,31 @@ public void parse_oneFieldSpecified_success() { Index targetIndex = INDEX_THIRD_ELEMENT; String userInput = " i/" + targetIndex.getOneBased() + NAME_DESC_AMY; EditClientDescriptor descriptor = new EditClientDescriptorBuilder().withName(VALID_NAME_AMY).build(); - EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); + EditClientCommand expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); // phone userInput = " i/" + targetIndex.getOneBased() + PHONE_DESC_AMY; descriptor = new EditClientDescriptorBuilder().withPhone(VALID_PHONE_AMY).build(); - expectedCommand = new EditCommand(targetIndex, descriptor); + expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); // email userInput = " i/" + targetIndex.getOneBased() + EMAIL_DESC_AMY; descriptor = new EditClientDescriptorBuilder().withEmail(VALID_EMAIL_AMY).build(); - expectedCommand = new EditCommand(targetIndex, descriptor); + expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); // address userInput = " i/" + targetIndex.getOneBased() + ADDRESS_DESC_AMY; descriptor = new EditClientDescriptorBuilder().withAddress(VALID_ADDRESS_AMY).build(); - expectedCommand = new EditCommand(targetIndex, descriptor); + expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); // Products userInput = " i/" + targetIndex.getOneBased() + PRODUCT_DESC_PRODUCT1; descriptor = new EditClientDescriptorBuilder().withProducts(VALID_PRODUCT_1).build(); - expectedCommand = new EditCommand(targetIndex, descriptor); + expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); } @@ -169,7 +169,7 @@ public void parse_multipleRepeatedFields_acceptsLast() { EditClientDescriptor descriptor = new EditClientDescriptorBuilder().withPhone(VALID_PHONE_BOB) .withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB) .withProducts(VALID_PRODUCT_1, VALID_PRODUCT_2).build(); - EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); + EditClientCommand expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); } @@ -180,7 +180,7 @@ public void parse_invalidValueFollowedByValidValue_success() { Index targetIndex = INDEX_FIRST_ELEMENT; String userInput = " i/" + targetIndex.getOneBased() + INVALID_PHONE_DESC + PHONE_DESC_BOB; EditClientDescriptor descriptor = new EditClientDescriptorBuilder().withPhone(VALID_PHONE_BOB).build(); - EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); + EditClientCommand expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); // other valid values specified @@ -188,7 +188,7 @@ public void parse_invalidValueFollowedByValidValue_success() { + PHONE_DESC_BOB; descriptor = new EditClientDescriptorBuilder().withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB) .withAddress(VALID_ADDRESS_BOB).build(); - expectedCommand = new EditCommand(targetIndex, descriptor); + expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); } @@ -198,7 +198,7 @@ public void parse_resetProducts_success() { String userInput = " i/" + targetIndex.getOneBased() + Product_EMPTY; EditClientDescriptor descriptor = new EditClientDescriptorBuilder().withProducts().build(); - EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); + EditClientCommand expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); } diff --git a/src/test/java/seedu/address/logic/parser/MyInsuRecParserTest.java b/src/test/java/seedu/address/logic/parser/MyInsuRecParserTest.java index 50e3a6c115e..f1e915f05f3 100644 --- a/src/test/java/seedu/address/logic/parser/MyInsuRecParserTest.java +++ b/src/test/java/seedu/address/logic/parser/MyInsuRecParserTest.java @@ -16,8 +16,8 @@ import seedu.address.logic.commands.AddClientCommand; import seedu.address.logic.commands.ClearCommand; import seedu.address.logic.commands.DeleteClientCommand; -import seedu.address.logic.commands.EditCommand; -import seedu.address.logic.commands.EditCommand.EditClientDescriptor; +import seedu.address.logic.commands.EditClientCommand; +import seedu.address.logic.commands.EditClientCommand.EditClientDescriptor; import seedu.address.logic.commands.ExitCommand; import seedu.address.logic.commands.FindCommand; import seedu.address.logic.commands.HelpCommand; @@ -57,9 +57,9 @@ public void parseCommand_delete() throws Exception { public void parseCommand_edit() throws Exception { Client client = new ClientBuilder().build(); EditClientDescriptor descriptor = new EditClientDescriptorBuilder(client).build(); - EditCommand command = (EditCommand) parser.parseCommand(EditCommand.COMMAND_WORD + " i/" + EditClientCommand command = (EditClientCommand) parser.parseCommand(EditClientCommand.COMMAND_WORD + " i/" + INDEX_FIRST_ELEMENT.getOneBased() + " " + ClientUtil.getEditClientDescriptorDetails(descriptor)); - assertEquals(new EditCommand(INDEX_FIRST_ELEMENT, descriptor), command); + assertEquals(new EditClientCommand(INDEX_FIRST_ELEMENT, descriptor), command); } @Test diff --git a/src/test/java/seedu/address/testutil/ClientUtil.java b/src/test/java/seedu/address/testutil/ClientUtil.java index 49c397bb051..d87b9d02ff5 100644 --- a/src/test/java/seedu/address/testutil/ClientUtil.java +++ b/src/test/java/seedu/address/testutil/ClientUtil.java @@ -9,7 +9,7 @@ import java.util.Set; import seedu.address.logic.commands.AddClientCommand; -import seedu.address.logic.commands.EditCommand.EditClientDescriptor; +import seedu.address.logic.commands.EditClientCommand.EditClientDescriptor; import seedu.address.model.client.Client; import seedu.address.model.product.Product; diff --git a/src/test/java/seedu/address/testutil/EditClientDescriptorBuilder.java b/src/test/java/seedu/address/testutil/EditClientDescriptorBuilder.java index 08913a9adbd..00ba521719b 100644 --- a/src/test/java/seedu/address/testutil/EditClientDescriptorBuilder.java +++ b/src/test/java/seedu/address/testutil/EditClientDescriptorBuilder.java @@ -6,7 +6,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import seedu.address.logic.commands.EditCommand.EditClientDescriptor; +import seedu.address.logic.commands.EditClientCommand.EditClientDescriptor; import seedu.address.model.client.Address; import seedu.address.model.client.Birthday; import seedu.address.model.client.Client; diff --git a/src/test/java/seedu/address/testutil/MeetingBuilder.java b/src/test/java/seedu/address/testutil/MeetingBuilder.java index c31f24a9da8..d6d42236af3 100644 --- a/src/test/java/seedu/address/testutil/MeetingBuilder.java +++ b/src/test/java/seedu/address/testutil/MeetingBuilder.java @@ -1,22 +1,16 @@ package seedu.address.testutil; +import static seedu.address.testutil.TypicalClients.ALICE; + import java.time.LocalDate; import java.time.LocalTime; -import java.util.HashSet; -import java.util.Optional; -import java.util.Set; -import seedu.address.model.client.Address; -import seedu.address.model.client.Birthday; import seedu.address.model.client.Client; -import seedu.address.model.client.Email; -import seedu.address.model.client.Name; -import seedu.address.model.client.Phone; import seedu.address.model.meeting.Description; import seedu.address.model.meeting.Meeting; import seedu.address.model.meeting.MeetingDate; import seedu.address.model.meeting.MeetingTime; -import seedu.address.model.product.Product; + /** * A utility class to help with building Meeting objects. @@ -26,12 +20,7 @@ public class MeetingBuilder { public static final LocalDate DEFAULT_MEETING_DATE = LocalDate.of(2020, 1, 8); public static final LocalTime DEFAULT_MEETING_START_TIME = LocalTime.of(7, 20, 45, 342123342); public static final LocalTime DEFAULT_MEETING_END_TIME = LocalTime.of(8, 20, 45, 342123342); - public static final String DEFAULT_NAME = "Amy Bee"; - public static final String DEFAULT_PHONE = "85355255"; - public static final String DEFAULT_EMAIL = "amy@gmail.com"; - public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111"; - public static final LocalDate DEFAULT_BIRTHDAY = LocalDate.of(2000, 1, 1); - private static final Set DEFAULT_PRODUCTS = new HashSet<>(); + public static final Client DEFAULT_CLIENT = ALICE; private Description description; private Client client; @@ -47,9 +36,7 @@ public MeetingBuilder() { meetingDate = new MeetingDate(DEFAULT_MEETING_DATE); meetingStartTime = new MeetingTime(DEFAULT_MEETING_START_TIME); meetingEndTime = new MeetingTime(DEFAULT_MEETING_END_TIME); - client = new Client(new Name(DEFAULT_NAME), new Phone(DEFAULT_PHONE), - Optional.of(new Email(DEFAULT_EMAIL)), Optional.of(new Address(DEFAULT_ADDRESS)), - Optional.of(new Birthday(DEFAULT_BIRTHDAY)), DEFAULT_PRODUCTS); + client = DEFAULT_CLIENT; } /** diff --git a/src/test/java/seedu/address/testutil/TypicalClients.java b/src/test/java/seedu/address/testutil/TypicalClients.java index 57d2a5f2c88..595e9029da2 100644 --- a/src/test/java/seedu/address/testutil/TypicalClients.java +++ b/src/test/java/seedu/address/testutil/TypicalClients.java @@ -26,7 +26,9 @@ public class TypicalClients { public static final Client ALICE = new ClientBuilder().withName("Alice Pauline") .withAddress("123, Jurong West Ave 6, #08-111").withEmail("alice@example.com") .withPhone("94351253") - .withProducts("Product1").build(); + .withProducts("Product1") + .build(); + public static final Client BENSON = new ClientBuilder().withName("Benson Meier") .withAddress("311, Clementi Ave 2, #02-25") .withEmail("johnd@example.com").withPhone("98765432") @@ -69,6 +71,7 @@ public static MyInsuRec getTypicalMyInsuRec() { MyInsuRec myInsuRec = new MyInsuRec(); for (Client client : getTypicalClients()) { myInsuRec.addClient(client); + client.getMeetings().forEach(meeting -> myInsuRec.addMeeting(meeting)); } for (Product product : getTypicalProducts()) { myInsuRec.addProduct(product); From 38587900c7761f6d1f6f739d5a05fa0cbc2e71d6 Mon Sep 17 00:00:00 2001 From: sikai00 Date: Fri, 28 Oct 2022 01:18:27 +0800 Subject: [PATCH 2/5] Fix editMeeting not checking for conflicts --- .../address/logic/commands/EditMeetingCommand.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/EditMeetingCommand.java b/src/main/java/seedu/address/logic/commands/EditMeetingCommand.java index 951acba00f6..6240ae58144 100644 --- a/src/main/java/seedu/address/logic/commands/EditMeetingCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditMeetingCommand.java @@ -16,6 +16,7 @@ import seedu.address.commons.util.CollectionUtil; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.client.Client; import seedu.address.model.meeting.Description; import seedu.address.model.meeting.Meeting; import seedu.address.model.meeting.MeetingDate; @@ -72,15 +73,17 @@ public CommandResult execute(Model model) throws CommandException { Meeting meetingToEdit = lastShownList.get(index.getZeroBased()); Meeting editedMeeting = createEditedMeeting(meetingToEdit, editMeetingDescriptor); - if (!meetingToEdit.equals(editedMeeting) && model.hasSpecificMeeting(editedMeeting)) { + if (model.hasMeeting(editedMeeting)) { throw new CommandException(MESSAGE_DUPLICATE_MEETING); } // update meeting list model.setMeeting(meetingToEdit, editedMeeting); - // update client list - model.setClient(meetingToEdit.getClient(), editedMeeting.getClient()); + // update meeting in client + Client client = meetingToEdit.getClient(); + client.removeMeeting(meetingToEdit); + client.addMeeting(editedMeeting); return new CommandResult(String.format(MESSAGE_EDIT_MEETING_SUCCESS, editedMeeting), CommandSpecific.MEETING); } @@ -102,8 +105,6 @@ private static Meeting createEditedMeeting(Meeting meetingToEdit, EditMeetingDes } Meeting meeting = new Meeting(meetingToEdit.getClient(), updatedDescription, updatedDate, updatedStartTime, updatedEndTime); - meeting.getClient().removeMeeting(meetingToEdit); - meeting.getClient().addMeeting(meeting); return meeting; } From 802261ab642f8265d89b83a4b7b5d6925cbac438 Mon Sep 17 00:00:00 2001 From: ThomasHoooo Date: Fri, 28 Oct 2022 01:38:52 +0800 Subject: [PATCH 3/5] Update JavaFX versions --- src/main/resources/view/ClientDetailedView.fxml | 2 +- src/main/resources/view/ClientDetailedViewPanel.fxml | 2 +- src/main/resources/view/ClientListCard.fxml | 2 +- src/main/resources/view/ClientListPanel.fxml | 2 +- src/main/resources/view/MainWindow.fxml | 2 +- src/main/resources/view/MeetingDetailedView.fxml | 2 +- src/main/resources/view/MeetingListCard.fxml | 2 +- src/main/resources/view/MeetingListPanel.fxml | 2 +- src/main/resources/view/ProductListCard.fxml | 2 +- src/main/resources/view/ResultDisplay.fxml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/resources/view/ClientDetailedView.fxml b/src/main/resources/view/ClientDetailedView.fxml index bbae110a6b8..0a05fd8707f 100644 --- a/src/main/resources/view/ClientDetailedView.fxml +++ b/src/main/resources/view/ClientDetailedView.fxml @@ -14,7 +14,7 @@ - + diff --git a/src/main/resources/view/ClientDetailedViewPanel.fxml b/src/main/resources/view/ClientDetailedViewPanel.fxml index 41edaf76fec..daf9bf588d0 100644 --- a/src/main/resources/view/ClientDetailedViewPanel.fxml +++ b/src/main/resources/view/ClientDetailedViewPanel.fxml @@ -3,6 +3,6 @@ - + diff --git a/src/main/resources/view/ClientListCard.fxml b/src/main/resources/view/ClientListCard.fxml index d6a6b9bea33..0e9cda9dab6 100644 --- a/src/main/resources/view/ClientListCard.fxml +++ b/src/main/resources/view/ClientListCard.fxml @@ -8,7 +8,7 @@ - + diff --git a/src/main/resources/view/ClientListPanel.fxml b/src/main/resources/view/ClientListPanel.fxml index d6eac874221..d7b8006f628 100644 --- a/src/main/resources/view/ClientListPanel.fxml +++ b/src/main/resources/view/ClientListPanel.fxml @@ -9,7 +9,7 @@ - +