forked from AY2324S2-CS2103T-W13-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.
Merge pull request AY2324S2-CS2103T-W13-4#36 from chin-herng/branch-a…
…ssign-tasks Assign Tasks to Persons
- Loading branch information
Showing
42 changed files
with
614 additions
and
342 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.logic.Messages; | ||
|
@@ -25,15 +24,12 @@ public class AddCommand extends Command { | |
+ PREFIX_NAME + "NAME " | ||
+ PREFIX_PHONE + "PHONE " | ||
+ PREFIX_EMAIL + "EMAIL " | ||
+ PREFIX_ADDRESS + "ADDRESS " | ||
+ "[" + PREFIX_TAG + "TAG]...\n" | ||
+ PREFIX_ADDRESS + "ADDRESS\n " | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_NAME + "John Doe " | ||
+ PREFIX_PHONE + "98765432 " | ||
+ PREFIX_EMAIL + "[email protected] " | ||
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " | ||
+ PREFIX_TAG + "friends " | ||
+ PREFIX_TAG + "owesMoney"; | ||
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "; | ||
|
||
public static final String MESSAGE_SUCCESS = "New person added: %1$s"; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; | ||
|
88 changes: 88 additions & 0 deletions
88
src/main/java/seedu/address/logic/commands/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,88 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
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; | ||
|
||
/** | ||
* Assigns an existing task to an existing person in the address book. | ||
*/ | ||
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 last task listing " | ||
+ "to the person identified " | ||
+ "by the index number used in the last person listing. " | ||
+ "Does nothing if the task is already assigned to the person.\n" | ||
+ "Parameters: TASK_INDEX (must be a positive integer) " | ||
+ "to/ [PERSON_INDEX (must be a positive integer)]\n" | ||
+ "Example: " + COMMAND_WORD + " 1 " | ||
+ "to/ 2"; | ||
|
||
public static final String MESSAGE_SUCCESS = "%1$s has been assigned to %2$s."; | ||
|
||
private final Index taskIndex; | ||
private final Index personIndex; | ||
|
||
/** | ||
* @param taskIndex of the task in the filtered task list to be assigned to the person | ||
* @param personIndex of the person in the filtered person list to be assigned the task | ||
*/ | ||
public AssignCommand(Index taskIndex, Index personIndex) { | ||
requireAllNonNull(taskIndex, personIndex); | ||
|
||
this.taskIndex = taskIndex; | ||
this.personIndex = personIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
List<Task> lastShownTaskList = model.getTaskList().getSerializeTaskList(); | ||
List<Person> lastShownPersonList = model.getFilteredPersonList(); | ||
|
||
if (taskIndex.getZeroBased() >= lastShownTaskList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); | ||
} | ||
|
||
if (personIndex.getZeroBased() >= lastShownPersonList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
Person personToBeAssigned = lastShownPersonList.get(personIndex.getZeroBased()); | ||
Task taskToAssign = lastShownTaskList.get(taskIndex.getZeroBased()); | ||
Person assignedPerson = personToBeAssigned.addTask(taskToAssign); | ||
|
||
model.setPerson(personToBeAssigned, assignedPerson); | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
|
||
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.formatTask(taskToAssign), | ||
Messages.format(assignedPerson))); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AssignCommand)) { | ||
return false; | ||
} | ||
|
||
AssignCommand e = (AssignCommand) other; | ||
return taskIndex.equals(e.taskIndex) | ||
&& personIndex.equals(e.personIndex); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -5,11 +5,8 @@ | |
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
@@ -26,7 +23,7 @@ | |
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.Phone; | ||
import seedu.address.model.tag.Tag; | ||
import seedu.address.model.task.Task; | ||
|
||
/** | ||
* Edits the details of an existing person in the address book. | ||
|
@@ -42,8 +39,7 @@ public class EditCommand extends Command { | |
+ "[" + PREFIX_NAME + "NAME] " | ||
+ "[" + PREFIX_PHONE + "PHONE] " | ||
+ "[" + PREFIX_EMAIL + "EMAIL] " | ||
+ "[" + PREFIX_ADDRESS + "ADDRESS] " | ||
+ "[" + PREFIX_TAG + "TAG]...\n" | ||
+ "[" + PREFIX_ADDRESS + "ADDRESS]\n " | ||
+ "Example: " + COMMAND_WORD + " 1 " | ||
+ PREFIX_PHONE + "91234567 " | ||
+ PREFIX_EMAIL + "[email protected]"; | ||
|
@@ -99,9 +95,9 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript | |
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(personToEdit.getPhone()); | ||
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail()); | ||
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); | ||
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); | ||
Set<Task> updatedTasks = personToEdit.getTasks(); // edit command does not allow editing tasks | ||
|
||
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); | ||
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTasks); | ||
} | ||
|
||
@Override | ||
|
@@ -137,27 +133,24 @@ public static class EditPersonDescriptor { | |
private Phone phone; | ||
private Email email; | ||
private Address address; | ||
private Set<Tag> tags; | ||
|
||
public EditPersonDescriptor() {} | ||
|
||
/** | ||
* Copy constructor. | ||
* A defensive copy of {@code tags} is used internally. | ||
*/ | ||
public EditPersonDescriptor(EditPersonDescriptor toCopy) { | ||
setName(toCopy.name); | ||
setPhone(toCopy.phone); | ||
setEmail(toCopy.email); | ||
setAddress(toCopy.address); | ||
setTags(toCopy.tags); | ||
} | ||
|
||
/** | ||
* Returns true if at least one field is edited. | ||
*/ | ||
public boolean isAnyFieldEdited() { | ||
return CollectionUtil.isAnyNonNull(name, phone, email, address, tags); | ||
return CollectionUtil.isAnyNonNull(name, phone, email, address); | ||
} | ||
|
||
public void setName(Name name) { | ||
|
@@ -192,23 +185,6 @@ public Optional<Address> getAddress() { | |
return Optional.ofNullable(address); | ||
} | ||
|
||
/** | ||
* Sets {@code tags} to this object's {@code tags}. | ||
* A defensive copy of {@code tags} is used internally. | ||
*/ | ||
public void setTags(Set<Tag> tags) { | ||
this.tags = (tags != null) ? new HashSet<>(tags) : null; | ||
} | ||
|
||
/** | ||
* Returns an unmodifiable tag set, which throws {@code UnsupportedOperationException} | ||
* if modification is attempted. | ||
* Returns {@code Optional#empty()} if {@code tags} is null. | ||
*/ | ||
public Optional<Set<Tag>> getTags() { | ||
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
|
@@ -224,8 +200,7 @@ public boolean equals(Object other) { | |
return Objects.equals(name, otherEditPersonDescriptor.name) | ||
&& Objects.equals(phone, otherEditPersonDescriptor.phone) | ||
&& Objects.equals(email, otherEditPersonDescriptor.email) | ||
&& Objects.equals(address, otherEditPersonDescriptor.address) | ||
&& Objects.equals(tags, otherEditPersonDescriptor.tags); | ||
&& Objects.equals(address, otherEditPersonDescriptor.address); | ||
} | ||
|
||
@Override | ||
|
@@ -235,7 +210,6 @@ public String toString() { | |
.add("phone", phone) | ||
.add("email", email) | ||
.add("address", address) | ||
.add("tags", tags) | ||
.toString(); | ||
} | ||
} | ||
|
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
39 changes: 39 additions & 0 deletions
39
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,39 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TO; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.exceptions.IllegalValueException; | ||
import seedu.address.logic.commands.AssignCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new {@code AssignCommand} object | ||
*/ | ||
public class AssignCommandParser implements Parser<AssignCommand> { | ||
/** | ||
* Parses the given {@code String} of arguments in the context of the {@code AssignCommand} | ||
* and returns a {@code AssignCommand} object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public AssignCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, | ||
PREFIX_TO); | ||
|
||
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_TO); | ||
Index taskIndex; | ||
Index personIndex; | ||
try { | ||
taskIndex = ParserUtil.parseIndex(argMultimap.getPreamble()); | ||
personIndex = ParserUtil.parseIndex(argMultimap.getValue(PREFIX_TO).orElse("")); | ||
} catch (IllegalValueException ive) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
AssignCommand.MESSAGE_USAGE), ive); | ||
} | ||
|
||
return new AssignCommand(taskIndex, personIndex); | ||
} | ||
} |
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.