forked from AY2324S1-CS2103T-F12-4/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from jason-raiin/mark-command
Mark command
- Loading branch information
Showing
72 changed files
with
1,032 additions
and
353 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,26 @@ | ||
@startuml | ||
!include ../style.puml | ||
skinparam ArrowFontStyle plain | ||
|
||
title Create EditMeetingCommand | ||
|
||
Participant ":LogicManager" as logic LOGIC_COLOR | ||
Participant ":AddressBookParser" as abp LOGIC_COLOR | ||
Participant ":EditMeetingCommandParser" as emcp LOGIC_COLOR | ||
Participant "editMeetingDescriptor:EditMeetingDescriptor" as emd LOGIC_COLOR | ||
Participant "command:EditMeetingCommand" as emc LOGIC_COLOR | ||
|
||
activate logic | ||
logic -> abp ++: parseCommand(commandText) | ||
create emcp | ||
abp -> emcp ++: parse(arguments) | ||
create emd | ||
emcp -> emd ++: EditMeetingDescriptor() | ||
emd --> emcp --: | ||
create emc | ||
emcp -> emc ++: EditMeetingCommand(targetIndex, editMeetingDescriptor) | ||
emc --> emcp --: command | ||
emcp --> abp --: command | ||
abp --> logic --: command | ||
|
||
@enduml |
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,33 @@ | ||
@startuml | ||
!include ../style.puml | ||
skinparam arrowThickness 1.1 | ||
skinparam arrowColor LOGIC_COLOR_T4 | ||
skinparam classBackgroundColor LOGIC_COLOR | ||
|
||
package Parser as ParserPackage { | ||
Class "<<interface>>\nParser" as Parser | ||
Class EditMeetingCommandParser | ||
} | ||
|
||
package Command as CommandPackage { | ||
Class EditMeetingCommand | ||
Class EditMeetingDescriptor | ||
Class "{abstract}\nCommand" as Command | ||
} | ||
|
||
Class Index | ||
Class AddressBookParser | ||
Class LogicManager | ||
|
||
AddressBookParser .down.> EditMeetingCommandParser : creates > | ||
EditMeetingCommandParser ..> EditMeetingCommand : creates > | ||
EditMeetingCommand -down->"1" EditMeetingDescriptor | ||
EditMeetingCommand -down->"1" Index | ||
EditMeetingCommand -left-|> Command | ||
EditMeetingCommandParser .down.|> Parser | ||
EditMeetingCommandParser .left.> EditMeetingDescriptor : creates > | ||
EditMeetingCommandParser .down.> Index : creates > | ||
LogicManager -right->"1" AddressBookParser | ||
LogicManager .down.> EditMeetingCommand : executes > | ||
|
||
@enduml |
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,36 @@ | ||
@startuml | ||
!include ../style.puml | ||
skinparam ArrowFontStyle plain | ||
|
||
title Execute EditMeetingCommand | ||
|
||
box Logic LOGIC_COLOR_T1 | ||
Participant ":LogicManager" as logic LOGIC_COLOR | ||
Participant "command:EditMeetingCommand" as emc LOGIC_COLOR | ||
end box | ||
|
||
box Model MODEL_COLOR_T1 | ||
Participant ":ModelManager" as model MODEL_COLOR | ||
Participant "editedMeeting:Meeting" as meet MODEL_COLOR | ||
end box | ||
|
||
[->logic : execute | ||
activate logic | ||
ref over logic, emc: Create EditMeetingCommand | ||
logic -> emc ++: execute(model) | ||
emc -> model ++: getFilteredMeetingList | ||
model --> emc --: | ||
emc -> emc ++: createEditedMeeting | ||
create meet | ||
emc -> meet ++: Meeting() | ||
meet --> emc --: | ||
emc --> emc --: | ||
emc -> model ++: setMeeting | ||
model --> emc --: | ||
emc -> model ++:updateFilteredMeetingList | ||
model --> emc --: | ||
emc --> logic --: CommandResult | ||
[<--logic | ||
deactivate logic | ||
|
||
@enduml |
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
File renamed without changes.
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
Binary file added
BIN
+25.4 KB
docs/images/edit/CreateEditMeetingCommand-Create_EditMeetingCommand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+26.5 KB
docs/images/edit/EditMeetingSequenceDiagram-Execute_EditMeetingCommand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-19.7 KB
docs/images/tracing/ViewCommandsSequenceDiagram-StoreViewedItemsToModel.png
Binary file not shown.
Binary file removed
BIN
-18.1 KB
...images/tracing/ViewContactCommandSequenceDiagram-ViewContactCommandSequence.png
Binary file not shown.
Binary file added
BIN
+19.9 KB
docs/images/view/CreateViewContactCommand-Create_ViewContactCommand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added
BIN
+17.7 KB
docs/images/view/ViewCommandsSequenceDiagram-StoreViewedItemsToModel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
105 changes: 105 additions & 0 deletions
105
src/main/java/seedu/address/logic/commands/MarkMeetingCommand.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,105 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.meeting.Attendee; | ||
import seedu.address.model.meeting.Meeting; | ||
import seedu.address.model.meeting.MeetingStatus; | ||
import seedu.address.model.person.Person; | ||
|
||
/** | ||
* Marks a meeting as complete. | ||
*/ | ||
public class MarkMeetingCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "mark"; | ||
|
||
public static final String MESSAGE_MARK_MEETING_SUCCESS = "Meeting marked as complete: %1$s"; | ||
|
||
public static final String MESSAGE_MEETING_ALREADY_COMPLETE = "Meeting has already been marked as complete."; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Marks the meeting identified by the index number used in the displayed meetings list as complete.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" + "Example: " + COMMAND_WORD + "1"; | ||
|
||
private final Index targetIndex; | ||
|
||
public MarkMeetingCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Meeting> lastShownList = model.getFilteredMeetingList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_MEETING_DISPLAYED_INDEX); | ||
} | ||
|
||
Meeting meetingToMark = lastShownList.get(targetIndex.getZeroBased()); | ||
Meeting updatedMeeting = markMeeting(meetingToMark); | ||
model.setMeeting(meetingToMark, updatedMeeting); | ||
|
||
Iterator<Attendee> attendeeIterator = meetingToMark.getAttendees().iterator(); | ||
while (attendeeIterator.hasNext()) { | ||
Attendee attendee = attendeeIterator.next(); | ||
Person person = model.getPerson(attendee.getAttendeeName()); | ||
Person updatedPerson = updateLastContactedTime(person, meetingToMark.getEnd()); | ||
model.setPerson(person, updatedPerson); | ||
} | ||
|
||
return new CommandResult(String.format(MESSAGE_MARK_MEETING_SUCCESS, Messages.format(updatedMeeting))); | ||
} | ||
|
||
static Meeting markMeeting(Meeting meeting) throws CommandException { | ||
if (meeting.getStatus().isComplete) { | ||
throw new CommandException(MESSAGE_MEETING_ALREADY_COMPLETE); | ||
} | ||
|
||
Meeting markedMeeting = new Meeting(meeting.getTitle(), meeting.getLocation(), meeting.getStart(), | ||
meeting.getEnd(), meeting.getAttendees(), meeting.getTags(), new MeetingStatus(true)); | ||
|
||
return markedMeeting; | ||
} | ||
|
||
static Person updateLastContactedTime(Person person, LocalDateTime lastContactedTime) { | ||
if (lastContactedTime.isBefore(person.getLastContactedTime())) { | ||
return person; | ||
} | ||
|
||
Person updatedPerson = new Person(person.getName(), person.getPhone(), person.getEmail(), lastContactedTime, | ||
person.getStatus(), person.getRemark(), person.getTags()); | ||
|
||
return updatedPerson; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof MarkMeetingCommand)) { | ||
return false; | ||
} | ||
|
||
MarkMeetingCommand otherMarkMeetingCommand = (MarkMeetingCommand) other; | ||
return targetIndex.equals(otherMarkMeetingCommand.targetIndex); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this).add("targetIndex", targetIndex).toString(); | ||
} | ||
} |
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.