Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2021S1#87 from lll-jy/assign-command
Browse files Browse the repository at this point in the history
Implement assign command
  • Loading branch information
T-Fang authored Oct 11, 2020
2 parents be478f7 + 647c1d9 commit d4ed216
Show file tree
Hide file tree
Showing 48 changed files with 511 additions and 86 deletions.
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public class Messages {
public static final String MESSAGE_PROJECTS_LISTED_OVERVIEW = "%1$d projects listed!";
public static final String MESSAGE_INVALID_SCOPE_COMMAND = "The scope status is expected to be %s but you are"
+ " now in %s";

public static final String MESSAGE_MEMBER_NOT_PRESENT = "%s is not a team member of this project.";
public static final String MESSAGE_REASSIGNMENT_OF_SAME_TASK_TO_SAME_PERSON =
"%s is already an assignee of the task.";
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.catalogue;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DEADLINE;
Expand All @@ -8,6 +8,8 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_REPOURL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TASK;

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.Project;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.catalogue;

import static java.util.Objects.requireNonNull;

import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.model.MainCatalogue;
import seedu.address.model.Model;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.catalogue;

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.Project;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.catalogue;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DEADLINE;
Expand All @@ -19,6 +19,8 @@
import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.CollectionUtil;
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.Deadline;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.catalogue;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.core.Messages;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.model.Model;
import seedu.address.model.project.NameContainsKeywordsPredicate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.catalogue;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PROJECTS;

import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.model.Model;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.catalogue;

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.exceptions.InvalidScopeException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.global;

import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.model.Model;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.global;

import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.model.Model;

/**
Expand Down
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
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.project;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.core.Messages;
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.exceptions.InvalidScopeException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.Set;
import java.util.stream.Stream;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.catalogue.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.project.Deadline;
import seedu.address.model.project.Project;
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/seedu/address/logic/parser/AssignCommandParser.java
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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.catalogue.DeleteCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import java.util.Set;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.EditCommand.EditProjectDescriptor;
import seedu.address.logic.commands.catalogue.EditCommand;
import seedu.address.logic.commands.catalogue.EditCommand.EditProjectDescriptor;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.tag.ProjectTag;
import seedu.address.model.task.Task;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.util.Arrays;

import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.catalogue.FindCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.project.NameContainsKeywordsPredicate;

Expand Down
25 changes: 15 additions & 10 deletions src/main/java/seedu/address/logic/parser/MainCatalogueParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.LeaveCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.StartCommand;
import seedu.address.logic.commands.catalogue.AddCommand;
import seedu.address.logic.commands.catalogue.ClearCommand;
import seedu.address.logic.commands.catalogue.DeleteCommand;
import seedu.address.logic.commands.catalogue.EditCommand;
import seedu.address.logic.commands.catalogue.FindCommand;
import seedu.address.logic.commands.catalogue.ListCommand;
import seedu.address.logic.commands.catalogue.StartCommand;
import seedu.address.logic.commands.global.ExitCommand;
import seedu.address.logic.commands.global.HelpCommand;
import seedu.address.logic.commands.project.AssignCommand;
import seedu.address.logic.commands.project.LeaveCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.exceptions.InvalidScopeException;
import seedu.address.model.project.Status;
Expand Down Expand Up @@ -78,6 +79,7 @@ public Command parseCommand(String userInput, Status status) throws ParseExcepti
return new StartCommandParser().parse(arguments);

case LeaveCommand.COMMAND_WORD:
case AssignCommand.COMMAND_WORD:
throw new InvalidScopeException(Status.PROJECT, Status.CATALOGUE);

default:
Expand All @@ -89,6 +91,9 @@ public Command parseCommand(String userInput, Status status) throws ParseExcepti
case LeaveCommand.COMMAND_WORD:
return new LeaveCommand();

case AssignCommand.COMMAND_WORD:
return new AssignCommandParser().parse(arguments);

case ExitCommand.COMMAND_WORD:
return new ExitCommand();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.StartCommand;
import seedu.address.logic.commands.catalogue.StartCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down
Loading

0 comments on commit d4ed216

Please sign in to comment.