-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Made new ReassignTaskCommand #78
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,6 +200,16 @@ Format: `assign task/task title by/dd-MM-yyyy HHmm to/INDEX` | |
Examples: | ||
* `assign task/Complete Project Proposal by/20-04-2024 2359 to/1` Assign the 'Complete Project Proposal' task to the first person in the address book. | ||
|
||
### Reassigning a task: `reassign` | ||
|
||
Reassign a specific task from one person to another. | ||
|
||
Format `reassign from/FROMINDEX to/TONDEX` | ||
|
||
* Assigns the task, which was previously assigned to person at the specified `FROMINDEX`, to the person at the specified `TOINDEX` | ||
* The index refers to the index number shown in the displayed employee list. | ||
* The index **must be a positive integer** 1, 2, 3, … | ||
|
||
### Marking a task : `mark` | ||
|
||
Mark the specified task as done. | ||
|
@@ -286,6 +296,7 @@ Action | Format, Examples | |
**Delete** | `delete INDEX`<br> e.g., `delete 3` | ||
**Edit** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [d/DEPARTMENT] [t/TAG]…`<br> e.g.,`edit 2 n/James Lee e/[email protected]` | ||
**Assign Task** | `assign task/TASK TITLE by/dd-MM-yyyy to/INDEX`<br> e.g., `assign task/Complete Project Proposal by/22-05-2023 2359 to/1` | ||
**Reassign Task** | `reassign from/FROMINDEX to/TOINDEX`<br> e.g., `reassign from/2 to/1` | ||
**Mark Task** | `mark task/TASK o/INDEX` <br> e.g. `mark task/Complete Project Proposal o/1` | ||
**Find** | `find KEYWORD [MORE_KEYWORDS]`<br> e.g., `find James Jake` | ||
**List** | `list` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_FROM; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TO; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.task.Task; | ||
|
||
/** | ||
* Reassigns task to another person | ||
*/ | ||
public class ReassignTaskCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "reassign"; | ||
|
||
public static final String MESSAGE_REASSIGN_TASK_SUCCESS = "Reassigned task %1$s from %2$s to %3$s successfully"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Reassigns a task to a person identified by index number.\n" | ||
+ "Parameters: " | ||
+ PREFIX_FROM + "INDEX (must be a positive integer) " | ||
+ PREFIX_TO + "INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_FROM + "2 " | ||
+ PREFIX_TO + "1"; | ||
public static final String MESSAGE_PERSON_IS_BUSY = "A task has already been assigned for %1$s. " | ||
+ "Please select another person."; | ||
public static final String MESSAGE_TASK_DOES_NOT_EXIST = "%s has not been assigned a task. " | ||
+ "Please select another Task"; | ||
private final Index fromIndex; | ||
private final Index toIndex; | ||
|
||
/** | ||
* Reassigns a task from one person to another. | ||
* @param fromIndex | ||
* @param toIndex | ||
*/ | ||
public ReassignTaskCommand(Index fromIndex, Index toIndex) { | ||
requireAllNonNull(fromIndex, toIndex); | ||
this.fromIndex = fromIndex; | ||
this.toIndex = toIndex; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. code does not seem to be covered by test |
||
|
||
@Override | ||
public CommandResult execute(Model model, CommandHistory commandHistory) throws CommandException { | ||
requireNonNull(model); | ||
List<Person> personList = model.getFilteredPersonList(); | ||
|
||
if ((fromIndex.getZeroBased() >= personList.size() || toIndex.getZeroBased() >= personList.size())) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person assignedFrom = personList.get(fromIndex.getZeroBased()); | ||
Person assignedTo = personList.get(toIndex.getZeroBased()); | ||
|
||
if (assignedTo.isBusy()) { | ||
throw new CommandException(String.format(MESSAGE_PERSON_IS_BUSY, Messages.printName(assignedTo))); | ||
} | ||
Task task = assignedFrom.getTask(); | ||
if (task == null) { | ||
throw new CommandException(String.format(MESSAGE_TASK_DOES_NOT_EXIST, Messages.printName(assignedFrom))); | ||
} | ||
|
||
model.reassignTask(task, assignedFrom, assignedTo); | ||
model.commitAddressBook(); | ||
|
||
return new CommandResult(String.format(MESSAGE_REASSIGN_TASK_SUCCESS, | ||
Messages.printTask(task), Messages.printName(assignedFrom), Messages.printName(assignedTo))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof ReassignTaskCommand)) { | ||
return false; | ||
} | ||
|
||
ReassignTaskCommand otherReassignCommand = (ReassignTaskCommand) other; | ||
return fromIndex.equals(otherReassignCommand.fromIndex) | ||
&& toIndex.equals(otherReassignCommand.toIndex); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import seedu.address.logic.commands.HistoryCommand; | ||
import seedu.address.logic.commands.ListCommand; | ||
import seedu.address.logic.commands.MarkTaskCommand; | ||
import seedu.address.logic.commands.ReassignTaskCommand; | ||
import seedu.address.logic.commands.RedoCommand; | ||
import seedu.address.logic.commands.UndoCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
@@ -106,10 +107,12 @@ public Command parseCommand(String userInput) throws ParseException { | |
case FilterEfficiencyCommand.COMMAND_WORD: | ||
return new FilterEfficiencyCommandParser().parse(arguments); | ||
|
||
case ReassignTaskCommand.COMMAND_WORD: | ||
return new ReassignTaskCommandParser().parse(arguments); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the method in this file is not covered with testing too |
||
|
||
case EditDeadlineCommand.COMMAND_WORD: | ||
return new EditDeadlineCommandParser().parse(arguments); | ||
|
||
|
||
default: | ||
logger.finer("This user input caused a ParseException: " + userInput); | ||
throw new ParseException(MESSAGE_UNKNOWN_COMMAND); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ public class CliSyntax { | |
public static final Prefix PREFIX_TASK = new Prefix("task/"); | ||
public static final Prefix PREFIX_DEADLINE = new Prefix("by/"); | ||
public static final Prefix PREFIX_TO = new Prefix("to/"); | ||
public static final Prefix PREFIX_FROM = new Prefix("from/"); | ||
public static final Prefix PREFIX_EFFICIENCY = new Prefix("eff/"); | ||
public static final Prefix PREFIX_TASK_OWNER = new Prefix("o/"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the prefix could be better. Maybe something like by instead of o as o is quite vague |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_FROM; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TO; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.ReassignTaskCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parse input arguments and create a new ReassignTaskCommand object. | ||
*/ | ||
public class ReassignTaskCommandParser implements Parser<ReassignTaskCommand> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the method in this file is not covered by tests |
||
|
||
@Override | ||
public ReassignTaskCommand parse(String userInput) throws ParseException { | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(userInput, PREFIX_FROM, PREFIX_TO); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_FROM, PREFIX_TO) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ReassignTaskCommand.MESSAGE_USAGE)); | ||
} | ||
Index fromIndex = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_FROM).get()); | ||
Index toIndex = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_TO).get()); | ||
|
||
return new ReassignTaskCommand(fromIndex, toIndex); | ||
|
||
} | ||
|
||
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static seedu.address.testutil.Assert.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class MarkTaskCommandTest { | ||
|
||
@Test | ||
public void constructor_nullTask_throwsNullPointerException() { | ||
assertThrows(NullPointerException.class, () -> new MarkTaskCommand(null, null)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static seedu.address.testutil.Assert.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class ReassignTaskCommandTest { | ||
@Test | ||
public void constructor_nullTask_throwsNullPointerException() { | ||
assertThrows(NullPointerException.class, () -> new ReassignTaskCommand(null, null)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat formatting!