-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from chewbum/branch-createmeeting
LGTM!
- Loading branch information
Showing
29 changed files
with
916 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
src/main/java/seedu/address/logic/commands/AddMeetingCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_CLIENT_INDEX; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATETIME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.meeting.Meeting; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Represents a command to add a meeting associated with a specific client in the address book. | ||
* This command adds a new meeting to the address book, ensuring that no duplicate meetings are added. | ||
* A meeting is considered a duplicate if it has the same client, date, and description as an existing meeting. | ||
*/ | ||
public class AddMeetingCommand extends Command { | ||
public static final String COMMAND_WORD = "addMeeting"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a meeting to the " | ||
+ "client identified by the index number. \n" | ||
+ "Parameters: client/ CLIENT_INDEX dt/ DATE_TIME /d DESCRIPTION \n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_CLIENT_INDEX + "1 " | ||
+ PREFIX_DATETIME + "02-01-2024 12:00 " | ||
+ PREFIX_DESCRIPTION + "sign life plan"; | ||
|
||
|
||
public static final String MESSAGE_SUCCESS = "New meeting added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_MEETING = "This meeting already exists in the address book"; | ||
|
||
private final Index clientIndex; | ||
private final LocalDateTime dateTime; | ||
private final String description; | ||
|
||
/** | ||
* Creates an {@code AddMeetingCommand} to add the specified {@code Meeting}. | ||
* | ||
* @param dateTime The date and time of the meeting. | ||
* @param description A description of the meeting. | ||
* @param clientIndex The index of the client in the filtered person list to whom the meeting is to be added. | ||
* @throws NullPointerException if any of the input parameters are null. | ||
*/ | ||
|
||
public AddMeetingCommand(LocalDateTime dateTime, String description, Index clientIndex) { | ||
if (dateTime == null || description == null || clientIndex == null) { | ||
throw new NullPointerException(); | ||
} | ||
this.dateTime = dateTime; | ||
this.description = description; | ||
this.clientIndex = clientIndex; | ||
} | ||
|
||
/** | ||
* Executes the AddMeeting command to add a new meeting associated with a client in the address book. | ||
* <p> | ||
* The method retrieves the client based on the index provided, creates a new meeting with the specified date, time, | ||
* and description, and then adds this meeting to the model if it does not already exist to ensure uniqueness. | ||
* <p> | ||
* If the specified client index is invalid or the meeting already exists, it throws a CommandException. | ||
* | ||
* @param model The model in which the meeting will be added. | ||
* @return A CommandResult object containing the success message. | ||
* @throws CommandException If the client index is invalid or the meeting already exists in the model. | ||
*/ | ||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (clientIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person client = lastShownList.get(clientIndex.getZeroBased()); | ||
Meeting meetingToAdd = new Meeting(description, dateTime, client); | ||
|
||
if (model.hasMeeting(meetingToAdd) && client.hasExistingMeeting(meetingToAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_MEETING); | ||
} | ||
model.addMeeting(meetingToAdd); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(meetingToAdd))); | ||
} | ||
|
||
/** | ||
* Checks if another object is equal to this AddMeetingCommand instance. | ||
* <p> | ||
* The equality check is based on whether the other object is an instance of AddMeetingCommand | ||
* and whether the meetings to be added are the same in terms of client, date, time, and description. | ||
* This ensures that two AddMeetingCommand objects are considered equal if they are attempting | ||
* to add the same meeting. | ||
* <p> | ||
* This method is crucial for command comparisons, especially when testing or when the application | ||
* logic requires comparing different commands. | ||
* | ||
* @param other The object to compare this AddMeetingCommand against. | ||
* @return true if the given object represents an AddMeetingCommand equivalent to this instance, false otherwise. | ||
*/ | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AddMeetingCommand)) { | ||
return false; | ||
} | ||
|
||
AddMeetingCommand otherCommand = (AddMeetingCommand) other; | ||
return dateTime.equals(otherCommand.dateTime) | ||
&& description.equals(otherCommand.description) | ||
&& clientIndex.equals(otherCommand.clientIndex); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/seedu/address/logic/parser/AddMeetingCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_CLIENT_INDEX; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATETIME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DESCRIPTION; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.stream.Stream; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.AddMeetingCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddMeetingCommand object | ||
*/ | ||
public class AddMeetingCommandParser implements Parser<AddMeetingCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the AddMeetingCommand | ||
* and returns an AddMeetingCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public AddMeetingCommand parse(String args) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(args, PREFIX_CLIENT_INDEX, PREFIX_DATETIME, PREFIX_DESCRIPTION); | ||
System.out.println(!arePrefixesPresent(argMultimap, PREFIX_CLIENT_INDEX, PREFIX_DATETIME, PREFIX_DESCRIPTION)); | ||
System.out.println(!argMultimap.getPreamble().isEmpty()); | ||
if (!arePrefixesPresent(argMultimap, PREFIX_CLIENT_INDEX, PREFIX_DATETIME, PREFIX_DESCRIPTION) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddMeetingCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_CLIENT_INDEX, PREFIX_DATETIME, PREFIX_DESCRIPTION); | ||
Index clientIndex = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_CLIENT_INDEX).get()); | ||
LocalDateTime dateTime = ParserUtil.parseDateTime(argMultimap.getValue(PREFIX_DATETIME).get()); | ||
String description = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESCRIPTION).get()); | ||
|
||
|
||
return new AddMeetingCommand(dateTime, description, clientIndex); | ||
} | ||
|
||
/** | ||
* 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) { | ||
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.