forked from nus-cs2103-AY1718S2/addressbook-level4
-
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-AY1718S2#48 from whenzei/main_dev
Update classes in Model to support job management features
- Loading branch information
Showing
95 changed files
with
1,304 additions
and
1,088 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,22 +21,22 @@ | |
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.person.Address; | ||
import seedu.address.model.person.Email; | ||
import seedu.address.model.person.Employee; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.model.person.Phone; | ||
import seedu.address.model.person.exceptions.DuplicatePersonException; | ||
import seedu.address.model.person.exceptions.PersonNotFoundException; | ||
import seedu.address.model.person.exceptions.DuplicateEmployeeException; | ||
import seedu.address.model.person.exceptions.EmployeeNotFoundException; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* Edits the details of an existing person in the address book. | ||
* Edits the details of an existing employee in the address book. | ||
*/ | ||
public class EditCommand extends UndoableCommand { | ||
|
||
public static final String COMMAND_WORD = "edit"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the person identified " | ||
+ "by the index number used in the last person listing. " | ||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the employee identified " | ||
+ "by the index number used in the last employee listing. " | ||
+ "Existing values will be overwritten by the input values.\n" | ||
+ "Parameters: INDEX (must be a positive integer) " | ||
+ "[" + PREFIX_NAME + "NAME] " | ||
|
@@ -48,19 +48,19 @@ public class EditCommand extends UndoableCommand { | |
+ PREFIX_PHONE + "91234567 " | ||
+ PREFIX_EMAIL + "[email protected]"; | ||
|
||
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Person: %1$s"; | ||
public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Employee: %1$s"; | ||
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided."; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book."; | ||
public static final String MESSAGE_DUPLICATE_PERSON = "This employee already exists in the address book."; | ||
|
||
private final Index index; | ||
private final EditPersonDescriptor editPersonDescriptor; | ||
|
||
private Person personToEdit; | ||
private Person editedPerson; | ||
private Employee employeeToEdit; | ||
private Employee editedEmployee; | ||
|
||
/** | ||
* @param index of the person in the filtered person list to edit | ||
* @param editPersonDescriptor details to edit the person with | ||
* @param index of the employee in the filtered employee list to edit | ||
* @param editPersonDescriptor details to edit the employee with | ||
*/ | ||
public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) { | ||
requireNonNull(index); | ||
|
@@ -73,42 +73,42 @@ public EditCommand(Index index, EditPersonDescriptor editPersonDescriptor) { | |
@Override | ||
public CommandResult executeUndoableCommand() throws CommandException { | ||
try { | ||
model.updatePerson(personToEdit, editedPerson); | ||
} catch (DuplicatePersonException dpe) { | ||
model.updatePerson(employeeToEdit, editedEmployee); | ||
} catch (DuplicateEmployeeException dpe) { | ||
throw new CommandException(MESSAGE_DUPLICATE_PERSON); | ||
} catch (PersonNotFoundException pnfe) { | ||
throw new AssertionError("The target person cannot be missing"); | ||
} catch (EmployeeNotFoundException pnfe) { | ||
throw new AssertionError("The target employee cannot be missing"); | ||
} | ||
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); | ||
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedPerson)); | ||
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedEmployee)); | ||
} | ||
|
||
@Override | ||
protected void preprocessUndoableCommand() throws CommandException { | ||
List<Person> lastShownList = model.getFilteredPersonList(); | ||
List<Employee> lastShownList = model.getFilteredPersonList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
|
||
personToEdit = lastShownList.get(index.getZeroBased()); | ||
editedPerson = createEditedPerson(personToEdit, editPersonDescriptor); | ||
employeeToEdit = lastShownList.get(index.getZeroBased()); | ||
editedEmployee = createEditedPerson(employeeToEdit, editPersonDescriptor); | ||
} | ||
|
||
/** | ||
* Creates and returns a {@code Person} with the details of {@code personToEdit} | ||
* Creates and returns a {@code Employee} with the details of {@code employeeToEdit} | ||
* edited with {@code editPersonDescriptor}. | ||
*/ | ||
private static Person createEditedPerson(Person personToEdit, EditPersonDescriptor editPersonDescriptor) { | ||
assert personToEdit != null; | ||
private static Employee createEditedPerson(Employee employeeToEdit, EditPersonDescriptor editPersonDescriptor) { | ||
assert employeeToEdit != null; | ||
|
||
Name updatedName = editPersonDescriptor.getName().orElse(personToEdit.getName()); | ||
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()); | ||
Name updatedName = editPersonDescriptor.getName().orElse(employeeToEdit.getName()); | ||
Phone updatedPhone = editPersonDescriptor.getPhone().orElse(employeeToEdit.getPhone()); | ||
Email updatedEmail = editPersonDescriptor.getEmail().orElse(employeeToEdit.getEmail()); | ||
Address updatedAddress = editPersonDescriptor.getAddress().orElse(employeeToEdit.getAddress()); | ||
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(employeeToEdit.getTags()); | ||
|
||
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); | ||
return new Employee(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); | ||
} | ||
|
||
@Override | ||
|
@@ -127,12 +127,12 @@ public boolean equals(Object other) { | |
EditCommand e = (EditCommand) other; | ||
return index.equals(e.index) | ||
&& editPersonDescriptor.equals(e.editPersonDescriptor) | ||
&& Objects.equals(personToEdit, e.personToEdit); | ||
&& Objects.equals(employeeToEdit, e.employeeToEdit); | ||
} | ||
|
||
/** | ||
* Stores the details to edit the person with. Each non-empty field value will replace the | ||
* corresponding field value of the person. | ||
* Stores the details to edit the employee with. Each non-empty field value will replace the | ||
* corresponding field value of the employee. | ||
*/ | ||
public static class EditPersonDescriptor { | ||
private Name name; | ||
|
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.