forked from AY2122S2-CS2103T-T12-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.
- Loading branch information
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/main/java/seedu/address/logic/commands/GenerateEmailsCommand.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.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.task.Task; | ||
|
||
public class GenerateEmailsCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "gen"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Generates all the emails of the people related to the task " | ||
+ "identified by the index number in the task list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_NO_CONTACTS_ASSIGNED = | ||
"Failed: There are no contacts assigned to the task %1$s"; | ||
|
||
private static final String MESSAGE_GENERATED_EMAILS = "Here are the emails related to the task %1$s:\n" | ||
+ "%2$s"; | ||
|
||
|
||
private final Index targetIndex; | ||
|
||
public GenerateEmailsCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Task> shownTaskList = model.getFilteredTaskList(); | ||
|
||
if (targetIndex.getZeroBased() >= shownTaskList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); | ||
} | ||
|
||
Task task = shownTaskList.get(targetIndex.getZeroBased()); | ||
|
||
if (task.getNoOfPeople() == 0) { | ||
return new CommandResult(String.format(MESSAGE_NO_CONTACTS_ASSIGNED, task)); | ||
} | ||
|
||
return new CommandResult(String.format(MESSAGE_GENERATED_EMAILS, task, task.getEmails())); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/seedu/address/logic/parser/GenerateEmailsCommandParser.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,21 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.GenerateEmailsCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
public class GenerateEmailsCommandParser implements Parser<GenerateEmailsCommand> { | ||
|
||
@Override | ||
public GenerateEmailsCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new GenerateEmailsCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, GenerateEmailsCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
} |
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