forked from nus-cs2103-AY2021S1/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 nus-cs2103-AY2021S1#87 from lll-jy/assign-command
Implement assign command
- Loading branch information
Showing
48 changed files
with
511 additions
and
86 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
4 changes: 3 additions & 1 deletion
4
.../address/logic/commands/ClearCommand.java → ...ogic/commands/catalogue/ClearCommand.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
4 changes: 3 additions & 1 deletion
4
...address/logic/commands/DeleteCommand.java → ...gic/commands/catalogue/DeleteCommand.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
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
4 changes: 3 additions & 1 deletion
4
...u/address/logic/commands/FindCommand.java → ...logic/commands/catalogue/FindCommand.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
4 changes: 3 additions & 1 deletion
4
...u/address/logic/commands/ListCommand.java → ...logic/commands/catalogue/ListCommand.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
4 changes: 3 additions & 1 deletion
4
.../address/logic/commands/StartCommand.java → ...ogic/commands/catalogue/StartCommand.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
4 changes: 3 additions & 1 deletion
4
...u/address/logic/commands/ExitCommand.java → ...ss/logic/commands/global/ExitCommand.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
4 changes: 3 additions & 1 deletion
4
...u/address/logic/commands/HelpCommand.java → ...ss/logic/commands/global/HelpCommand.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
77 changes: 77 additions & 0 deletions
77
src/main/java/seedu/address/logic/commands/project/AssignCommand.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,77 @@ | ||
package seedu.address.logic.commands.project; | ||
|
||
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.Command; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.project.Participation; | ||
import seedu.address.model.project.Project; | ||
import seedu.address.model.task.Task; | ||
|
||
/** | ||
* Assigns a task to a person with participation in the current project. | ||
*/ | ||
public class AssignCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "assign"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Assigns the task identified by the index number used in the displayed task list to the team member" | ||
+ "that participates in the current project with his/her name.\n" | ||
+ "Parameters: INDEX (must be a positive integer), NAME (must be present in the project)\n" | ||
+ "Example: " + COMMAND_WORD + " 1 Lucas"; | ||
|
||
public static final String MESSAGE_ASSIGN_TASK_SUCCESS = "Assigns task: %1$s to %s"; | ||
|
||
private final Index targetIndex; | ||
private final String assignee; | ||
|
||
/** | ||
* Creates an AssignCommand that assigns the task of the given index to the intended assignee. | ||
*/ | ||
public AssignCommand(Index targetIndex, String assignee) { | ||
this.targetIndex = targetIndex; | ||
this.assignee = assignee; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
Project project = model.getFilteredProjectList().get(0); | ||
List<Task> lastShownTaskList = project.getFilteredTaskList(); | ||
|
||
if (targetIndex.getZeroBased() >= lastShownTaskList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PROJECT_DISPLAYED_INDEX); | ||
} | ||
|
||
Task taskToAssociate = lastShownTaskList.get(targetIndex.getZeroBased()); | ||
|
||
if (!project.hasParticipation(assignee)) { | ||
throw new CommandException(String.format(Messages.MESSAGE_MEMBER_NOT_PRESENT, assignee)); | ||
} | ||
|
||
Participation assignee = project.getParticipation(this.assignee); | ||
|
||
if (assignee.hasTask(taskToAssociate)) { | ||
throw new CommandException(String.format(Messages.MESSAGE_REASSIGNMENT_OF_SAME_TASK_TO_SAME_PERSON, | ||
assignee.getPerson().getPersonName())); | ||
} | ||
assignee.addTask(taskToAssociate); | ||
|
||
return new CommandResult(String.format(MESSAGE_ASSIGN_TASK_SUCCESS, taskToAssociate, assignee)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof AssignCommand // instanceof handles nulls | ||
&& targetIndex.equals(((AssignCommand) other).targetIndex) | ||
&& assignee.equals(((AssignCommand) ((AssignCommand) other)).assignee)); // state check | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
.../address/logic/commands/LeaveCommand.java → .../logic/commands/project/LeaveCommand.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
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
36 changes: 36 additions & 0 deletions
36
src/main/java/seedu/address/logic/parser/AssignCommandParser.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,36 @@ | ||
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.project.AssignCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new AssignCommand object | ||
*/ | ||
public class AssignCommandParser implements Parser<AssignCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the DeleteCommand | ||
* and returns a DeleteCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public AssignCommand parse(String args) throws ParseException { | ||
try { | ||
String input = args.trim(); | ||
int divider = input.indexOf(" "); | ||
if (divider <= 0) { | ||
throw new ParseException(""); | ||
} | ||
String indexString = input.substring(0, divider); | ||
Index index = ParserUtil.parseIndex(indexString); | ||
String name = input.substring(divider + 1); | ||
return new AssignCommand(index, name); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, AssignCommand.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
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
Oops, something went wrong.