Skip to content
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

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
requireNonNull(model);
List<Person> personList = model.getFilteredPersonList();

if (index.getOneBased() >= personList.size()) {
if (index.getZeroBased() >= personList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Expand Down
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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat formatting!

+ "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;
}

Choose a reason for hiding this comment

The 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
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Choose a reason for hiding this comment

The 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);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/");

Choose a reason for hiding this comment

The 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


Expand Down
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> {

Choose a reason for hiding this comment

The 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());
}

}
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/model/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ public void assignTask(Task task, Person pic) {
indicateModified();
}

/**
* Reassigns a task from one person to another person.
*/
public void reassignTask(Task task, Person oldPic, Person pic) {
task.setPersonInCharge(pic);
pic.setTask(task);
oldPic.setTask(null);
indicateModified();
}

/**
* Marks an assigned task as done.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public interface Model {
*/
void assignTask(Task task, Person person);

/**
* Reassigns task from one person to another.
*/
void reassignTask(Task task, Person assignedFrom, Person assignedTo);

/**
* Marks an assigned task as done.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ public void assignTask(Task task, Person assignedTo) {
versionedAddressBook.assignTask(task, assignedTo);
}

@Override
public void reassignTask(Task task, Person assignedFrom, Person assignedTo) {
requireAllNonNull(task, assignedFrom, assignedTo);
versionedAddressBook.reassignTask(task, assignedFrom, assignedTo);

}

@Override
public void markTask(Task task) {
requireNonNull(task);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ public void assignTask(Task task, Person person) {
throw new AssertionError("This method should not be called.");
}

@Override
public void reassignTask(Task task, Person assignedFrom, Person assignedTo) {
throw new AssertionError("This method should not be called.");
}

@Override
public void markTask(Task task) {
throw new AssertionError("This method should not be called.");
Expand Down
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));
}
}
Loading