Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY1718S2#48 from whenzei/main_dev
Browse files Browse the repository at this point in the history
Update classes in Model to support job management features
  • Loading branch information
yuhongherald authored Mar 17, 2018
2 parents dd44cf7 + c3f50a6 commit 13847b7
Show file tree
Hide file tree
Showing 95 changed files with 1,304 additions and 1,088 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ MIT License

Copyright (c) 2016 Software Engineering Education - FOSS Resources

Permission is hereby granted, free of charge, to any person obtaining a copy
Permission is hereby granted, free of charge, to any employee obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
copies of the Software, and to permit employees to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
Expand Down
58 changes: 29 additions & 29 deletions docs/DeveloperGuide.adoc

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ Deletes the 1st employee in the results of the `findE` command.

=== Changing a command word : `set`

Selects the person identified by the index number used in the last person listing. +
Selects the employee identified by the index number used in the last employee listing. +
Format: `set OLD_COMMAND_WORD NEW_COMMAND_WORD`

****
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Messages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The employee index provided is invalid";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_INVALID_THEME_INDEX = "The theme index provided is invalid";
public static final String MESSAGE_INVALID_FILE_PATH = "The file path is invalid";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public AddressBookChangedEvent(ReadOnlyAddressBook data) {

@Override
public String toString() {
return "number of persons " + data.getPersonList().size() + ", number of tags " + data.getTagList().size();
return "number of persons " + data.getEmployeeList().size() + ", number of tags " + data.getTagList().size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import seedu.address.ui.PersonCard;

/**
* Represents a selection change in the Person List Panel
* Represents a selection change in the Employee List Panel
*/
public class PersonPanelSelectionChangedEvent extends BaseEvent {

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Person;
import seedu.address.model.person.Employee;

/**
* API of the Logic component
Expand All @@ -23,7 +23,7 @@ public interface Logic {
String appendCommandKeyToMessage(String message);

/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();
ObservableList<Employee> getFilteredPersonList();

/** Returns the list of input entered by the user, encapsulated in a {@code ListElementPointer} object */
ListElementPointer getHistorySnapshot();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import seedu.address.logic.parser.AddressBookParser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.person.Employee;

/**
* The main LogicManager of the app.
Expand Down Expand Up @@ -50,7 +50,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
}

@Override
public ObservableList<Person> getFilteredPersonList() {
public ObservableList<Employee> getFilteredPersonList() {
return model.getFilteredPersonList();
}

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.person.Person;
import seedu.address.model.person.exceptions.DuplicatePersonException;
import seedu.address.model.person.Employee;
import seedu.address.model.person.exceptions.DuplicateEmployeeException;

/**
* Adds a person to the address book.
* Adds a employee to the address book.
*/
public class AddCommand extends UndoableCommand {

public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a employee to the address book. "
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
Expand All @@ -33,17 +33,17 @@ public class AddCommand extends UndoableCommand {
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

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";
public static final String MESSAGE_SUCCESS = "New employee added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This employee already exists in the address book";

private final Person toAdd;
private final Employee toAdd;

/**
* Creates an AddCommand to add the specified {@code Person}
* Creates an AddCommand to add the specified {@code Employee}
*/
public AddCommand(Person person) {
requireNonNull(person);
toAdd = person;
public AddCommand(Employee employee) {
requireNonNull(employee);
toAdd = employee;
}

@Override
Expand All @@ -52,7 +52,7 @@ public CommandResult executeUndoableCommand() throws CommandException {
try {
model.addPerson(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
} catch (DuplicatePersonException e) {
} catch (DuplicateEmployeeException e) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}

Expand Down
28 changes: 14 additions & 14 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.person.Person;
import seedu.address.model.person.exceptions.PersonNotFoundException;
import seedu.address.model.person.Employee;
import seedu.address.model.person.exceptions.EmployeeNotFoundException;

/**
* Deletes a person identified using it's last displayed index from the address book.
* Deletes a employee identified using it's last displayed index from the address book.
*/
public class DeleteCommand extends UndoableCommand {

public static final String COMMAND_WORD = "delete";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the person identified by the index number used in the last person listing.\n"
+ ": Deletes the employee identified by the index number used in the last employee listing.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";
public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Employee: %1$s";

private final Index targetIndex;

private Person personToDelete;
private Employee employeeToDelete;

public DeleteCommand(Index targetIndex) {
this.targetIndex = targetIndex;
Expand All @@ -36,32 +36,32 @@ public DeleteCommand(Index targetIndex) {

@Override
public CommandResult executeUndoableCommand() {
requireNonNull(personToDelete);
requireNonNull(employeeToDelete);
try {
model.deletePerson(personToDelete);
} catch (PersonNotFoundException pnfe) {
throw new AssertionError("The target person cannot be missing");
model.deletePerson(employeeToDelete);
} catch (EmployeeNotFoundException pnfe) {
throw new AssertionError("The target employee cannot be missing");
}

return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete));
return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, employeeToDelete));
}

@Override
protected void preprocessUndoableCommand() throws CommandException {
List<Person> lastShownList = model.getFilteredPersonList();
List<Employee> lastShownList = model.getFilteredPersonList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

personToDelete = lastShownList.get(targetIndex.getZeroBased());
employeeToDelete = lastShownList.get(targetIndex.getZeroBased());
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof DeleteCommand // instanceof handles nulls
&& this.targetIndex.equals(((DeleteCommand) other).targetIndex) // state check
&& Objects.equals(this.personToDelete, ((DeleteCommand) other).personToDelete));
&& Objects.equals(this.employeeToDelete, ((DeleteCommand) other).employeeToDelete));
}
}
64 changes: 32 additions & 32 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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] "
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/logic/commands/SelectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
import seedu.address.commons.core.index.Index;
import seedu.address.commons.events.ui.JumpToListRequestEvent;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.person.Person;
import seedu.address.model.person.Employee;

/**
* Selects a person identified using it's last displayed index from the address book.
* Selects a employee identified using it's last displayed index from the address book.
*/
public class SelectCommand extends Command {

public static final String COMMAND_WORD = "select";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Selects the person identified by the index number used in the last person listing.\n"
+ ": Selects the employee identified by the index number used in the last employee listing.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_SELECT_PERSON_SUCCESS = "Selected Person: %1$s";
public static final String MESSAGE_SELECT_PERSON_SUCCESS = "Selected Employee: %1$s";

private final Index targetIndex;

Expand All @@ -32,7 +32,7 @@ public SelectCommand(Index targetIndex) {
@Override
public CommandResult execute() throws CommandException {

List<Person> lastShownList = model.getFilteredPersonList();
List<Employee> lastShownList = model.getFilteredPersonList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected void preprocessUndoableCommand() throws CommandException {}

/**
* Reverts the AddressBook to the state before this command
* was executed and updates the filtered person list to
* was executed and updates the filtered employee list to
* show all persons.
*/
protected final void undo() {
Expand All @@ -44,7 +44,7 @@ protected final void undo() {
}

/**
* Executes the command and updates the filtered person
* Executes the command and updates the filtered employee
* list to show all persons.
*/
protected final void redo() {
Expand Down
Loading

0 comments on commit 13847b7

Please sign in to comment.