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

Add Applicant type #46

Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

/**
* Adds an applicant to the talent tracker.
*/
public class AddApplicantCommand extends AddCommand {

public static final String COMMAND_WORD = AddCommand.COMMAND_WORD + "_applicant";
Copy link
Member

Choose a reason for hiding this comment

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

Looks good! Nice way of creating a new class that inherits from the AddCommand.


public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an applicant to the talent tracker. "
+ AddCommand.MESSAGE_USAGE;


public static final String MESSAGE_SUCCESS = "New applicant added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This applicant already exists in the talent tracker";


/**
* Creates an AddApplicantCommand to add the specified {@code Person}
*/
public AddApplicantCommand(Person person) {
super(person);
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.hasPerson(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}

model.addPerson(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)));
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof AddApplicantCommand)) {
return false;
}

AddCommand otherAddCommand = (AddApplicantCommand) other;
return toAdd.equals(otherAddCommand.toAdd);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("toAdd", toAdd)
.toString();
}
}
46 changes: 4 additions & 42 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@
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;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;

/**
* Adds a person to the address book.
* Adds a person to the talent tracker.
*/
public class AddCommand extends Command {
public abstract class AddCommand extends Command {

public static final String COMMAND_WORD = "add";

Copy link
Member

Choose a reason for hiding this comment

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

Changing to abstract class. Will take note!

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
+ "Parameters: "
public static final String MESSAGE_USAGE = "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
Expand All @@ -35,7 +30,7 @@ public class AddCommand extends Command {
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";

private final Person toAdd;
protected final Person toAdd;

/**
* Creates an AddCommand to add the specified {@code Person}
Expand All @@ -45,37 +40,4 @@ public AddCommand(Person person) {
toAdd = person;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.hasPerson(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}

model.addPerson(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)));
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof AddCommand)) {
return false;
}

AddCommand otherAddCommand = (AddCommand) other;
return toAdd.equals(otherAddCommand.toAdd);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("toAdd", toAdd)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@
import java.util.Set;
import java.util.stream.Stream;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.AddApplicantCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Applicant;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Remark;
import seedu.address.model.tag.Tag;

/**
* Parses input arguments and creates a new AddCommand object
* Parses input arguments and creates a new AddApplicantCommand object
*/
public class AddCommandParser implements Parser<AddCommand> {
public class AddApplicantCommandParser implements Parser<AddApplicantCommand> {

/**
* Parses the given {@code String} of arguments in the context of the AddCommand
* and returns an AddCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public AddCommand parse(String args) throws ParseException {
public AddApplicantCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddApplicantCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL);
Expand All @@ -44,9 +44,9 @@ public AddCommand parse(String args) throws ParseException {
Remark remark = new Remark(""); // add command does not allow adding remarks straight away
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Person person = new Person(name, phone, email, remark, tagList);
Applicant applicant = new Applicant(name, phone, email, remark, tagList);

return new AddCommand(person);
return new AddApplicantCommand(applicant);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.AddApplicantCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.DeleteCommand;
Expand Down Expand Up @@ -45,8 +45,8 @@ public Command parseCommand(String userInput) throws ParseException {
final String arguments = matcher.group("arguments");
switch (commandWord) {

case AddCommand.COMMAND_WORD:
return new AddCommandParser().parse(arguments);
case AddApplicantCommand.COMMAND_WORD:
return new AddApplicantCommandParser().parse(arguments);

case EditCommand.COMMAND_WORD:
return new EditCommandParser().parse(arguments);
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/seedu/address/model/person/Applicant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package seedu.address.model.person;

import java.util.Set;

import seedu.address.model.tag.Tag;

/**
* Represents an Applicant in the talent tracker.
* Guarantees: details are present and not null, field values are validated, immutable.
*/
public class Applicant extends Person {

Copy link
Member

Choose a reason for hiding this comment

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

Nice use of inheritance to create a subclass of Persons.

/**
* Every field must be present and not null.
*/
public Applicant(Name name, Phone phone, Email email, Remark remark, Set<Tag> tags) {
super(name, phone, email, remark, tags);
}


@Override
public String toString() {
return "Applicant: " + super.toString();

Check warning on line 23 in src/main/java/seedu/address/model/person/Applicant.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/model/person/Applicant.java#L23

Added line #L23 was not covered by tests
}

}
16 changes: 8 additions & 8 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.AddApplicantCommand;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.exceptions.CommandException;
Expand Down Expand Up @@ -70,14 +70,14 @@ public void execute_validCommand_success() throws Exception {
}

@Test
public void execute_storageThrowsIoException_throwsCommandException() {
assertCommandFailureForExceptionFromStorage(DUMMY_IO_EXCEPTION, String.format(
public void execute_applicantStorageThrowsIoException_throwsCommandException() {
assertApplicantCommandFailureForExceptionFromStorage(DUMMY_IO_EXCEPTION, String.format(
LogicManager.FILE_OPS_ERROR_FORMAT, DUMMY_IO_EXCEPTION.getMessage()));
}

@Test
public void execute_storageThrowsAdException_throwsCommandException() {
assertCommandFailureForExceptionFromStorage(DUMMY_AD_EXCEPTION, String.format(
public void execute_applicantStorageThrowsAdException_throwsCommandException() {
assertApplicantCommandFailureForExceptionFromStorage(DUMMY_AD_EXCEPTION, String.format(
LogicManager.FILE_OPS_PERMISSION_ERROR_FORMAT, DUMMY_AD_EXCEPTION.getMessage()));
}

Expand Down Expand Up @@ -145,7 +145,7 @@ private void assertCommandFailure(String inputCommand, Class<? extends Throwable
* @param e the exception to be thrown by the Storage component
* @param expectedMessage the message expected inside exception thrown by the Logic component
*/
private void assertCommandFailureForExceptionFromStorage(IOException e, String expectedMessage) {
private void assertApplicantCommandFailureForExceptionFromStorage(IOException e, String expectedMessage) {
Path prefPath = temporaryFolder.resolve("ExceptionUserPrefs.json");

// Inject LogicManager with an AddressBookStorage that throws the IOException e when saving
Expand All @@ -164,11 +164,11 @@ public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath)
logic = new LogicManager(model, storage);

// Triggers the saveAddressBook method by executing an add command
String addCommand = AddCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY
String addApplicantCommand = AddApplicantCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY
+ EMAIL_DESC_AMY;
Person expectedPerson = new PersonBuilder(AMY).withTags().build();
ModelManager expectedModel = new ModelManager();
expectedModel.addPerson(expectedPerson);
assertCommandFailure(addCommand, CommandException.class, expectedMessage, expectedModel);
assertCommandFailure(addApplicantCommand, CommandException.class, expectedMessage, expectedModel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import seedu.address.testutil.PersonBuilder;

/**
* Contains integration tests (interaction with the Model) for {@code AddCommand}.
* Contains integration tests (interaction with the Model) for {@code AddApplicantCommand}.
*/
public class AddCommandIntegrationTest {
public class AddApplicantCommandIntegrationTest {

private Model model;

Expand All @@ -33,16 +33,16 @@ public void execute_newPerson_success() {
Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
expectedModel.addPerson(validPerson);

assertCommandSuccess(new AddCommand(validPerson), model,
String.format(AddCommand.MESSAGE_SUCCESS, Messages.format(validPerson)),
assertCommandSuccess(new AddApplicantCommand(validPerson), model,
String.format(AddApplicantCommand.MESSAGE_SUCCESS, Messages.format(validPerson)),
expectedModel);
}

@Test
public void execute_duplicatePerson_throwsCommandException() {
Person personInList = model.getAddressBook().getPersonList().get(0);
assertCommandFailure(new AddCommand(personInList), model,
AddCommand.MESSAGE_DUPLICATE_PERSON);
assertCommandFailure(new AddApplicantCommand(personInList), model,
AddApplicantCommand.MESSAGE_DUPLICATE_PERSON);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,48 @@
import seedu.address.model.person.Person;
import seedu.address.testutil.PersonBuilder;

public class AddCommandTest {
public class AddApplicantCommandTest {

@Test
public void constructor_nullPerson_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> new AddCommand(null));
assertThrows(NullPointerException.class, () -> new AddApplicantCommand(null));
}

@Test
public void execute_personAcceptedByModel_addSuccessful() throws Exception {
ModelStubAcceptingPersonAdded modelStub = new ModelStubAcceptingPersonAdded();
Person validPerson = new PersonBuilder().build();

CommandResult commandResult = new AddCommand(validPerson).execute(modelStub);
CommandResult commandResult = new AddApplicantCommand(validPerson).execute(modelStub);

assertEquals(String.format(AddCommand.MESSAGE_SUCCESS, Messages.format(validPerson)),
assertEquals(String.format(AddApplicantCommand.MESSAGE_SUCCESS, Messages.format(validPerson)),
commandResult.getFeedbackToUser());
assertEquals(Arrays.asList(validPerson), modelStub.personsAdded);
}

@Test
public void execute_duplicatePerson_throwsCommandException() {
Person validPerson = new PersonBuilder().build();
AddCommand addCommand = new AddCommand(validPerson);
AddCommand addCommand = new AddApplicantCommand(validPerson);
ModelStub modelStub = new ModelStubWithPerson(validPerson);

assertThrows(CommandException.class, AddCommand.MESSAGE_DUPLICATE_PERSON, () -> addCommand.execute(modelStub));
assertThrows(CommandException.class,
AddApplicantCommand.MESSAGE_DUPLICATE_PERSON, () -> addCommand.execute(modelStub)
);
}

@Test
public void equals() {
Person alice = new PersonBuilder().withName("Alice").build();
Person bob = new PersonBuilder().withName("Bob").build();
AddCommand addAliceCommand = new AddCommand(alice);
AddCommand addBobCommand = new AddCommand(bob);
AddCommand addAliceCommand = new AddApplicantCommand(alice);
AddCommand addBobCommand = new AddApplicantCommand(bob);

// same object -> returns true
assertTrue(addAliceCommand.equals(addAliceCommand));

// same values -> returns true
AddCommand addAliceCommandCopy = new AddCommand(alice);
AddCommand addAliceCommandCopy = new AddApplicantCommand(alice);
assertTrue(addAliceCommand.equals(addAliceCommandCopy));

// different types -> returns false
Expand All @@ -79,13 +81,13 @@ public void equals() {

@Test
public void toStringMethod() {
AddCommand addCommand = new AddCommand(ALICE);
String expected = AddCommand.class.getCanonicalName() + "{toAdd=" + ALICE + "}";
AddCommand addCommand = new AddApplicantCommand(ALICE);
String expected = AddApplicantCommand.class.getCanonicalName() + "{toAdd=" + ALICE + "}";
assertEquals(expected, addCommand.toString());
}

/**
* A default model stub that have all of the methods failing.
* A default model stub that have all the methods failing.
*/
private class ModelStub implements Model {
@Override
Expand Down
Loading
Loading