Skip to content

Commit

Permalink
Alfred Add Command Parsers (#32)
Browse files Browse the repository at this point in the history
* Add Alfred-specific parser classes.

* Modify prefixes.

* Implement Add Command Parsers.
  • Loading branch information
Abhiman2211 authored Oct 2, 2019
1 parent 6a38281 commit 812a9d2
Show file tree
Hide file tree
Showing 40 changed files with 901 additions and 225 deletions.
3 changes: 2 additions & 1 deletion docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ For example in the case of `add {mentor/participant/list}`, you can choose to ty

This command displays a help page in a separate pop-up window. Should you require further information,
the pop-up window also includes links to further references and documentation. +

Format: `help`

=== Adding an Entity: `add {participant/mentor/team}`

Adds an entity for Alfred to keep track of +
Use this command to add an entity for Alfred to keep track of. +
****
* Creates an Entity as specified by you. Each Entity object will have a unique ID autmatically assigned to it.
* As of version 1.1, you must provide all the fields. There are no optional fields.
Expand Down
1 change: 0 additions & 1 deletion docs/tutorials/RemovingFields.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Fortunately, the IntelliJ IDEA provides a robust refactoring tool that can ident
Let's try to use it as much as we can.

=== Assisted refactoring
The `address` field in `Person` is actually an instance of the `seedu.address.model.person.Address` class.
Since removing the `Address` class will break the application, we start by identifying ``Address``'s usages.
This allows us to see code that depends on `Address` to function properly and edit them on a case-by-case basis.
Right-click the `Address` class and select `Refactor` > `Safe Delete` through the menu.
Expand Down
19 changes: 2 additions & 17 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
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;
Expand All @@ -19,7 +18,6 @@
import seedu.address.commons.util.CollectionUtil;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
Expand All @@ -40,7 +38,6 @@ public class EditCommand extends Command {
+ "[" + PREFIX_NAME + "NAME] "
+ "[" + PREFIX_PHONE + "PHONE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
Expand Down Expand Up @@ -96,10 +93,9 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
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());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags);
return new Person(updatedName, updatedPhone, updatedEmail, updatedTags);
}

@Override
Expand Down Expand Up @@ -128,7 +124,6 @@ public static class EditPersonDescriptor {
private Name name;
private Phone phone;
private Email email;
private Address address;
private Set<Tag> tags;

public EditPersonDescriptor() {}
Expand All @@ -141,15 +136,14 @@ 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, tags);
}

public void setName(Name name) {
Expand All @@ -176,14 +170,6 @@ public Optional<Email> getEmail() {
return Optional.ofNullable(email);
}

public void setAddress(Address address) {
this.address = address;
}

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.
Expand Down Expand Up @@ -219,7 +205,6 @@ public boolean equals(Object other) {
return getName().equals(e.getName())
&& getPhone().equals(e.getPhone())
&& getEmail().equals(e.getEmail())
&& getAddress().equals(e.getAddress())
&& getTags().equals(e.getTags());
}
}
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
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;
Expand All @@ -12,7 +11,6 @@

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
Expand All @@ -31,20 +29,19 @@ public class AddCommandParser implements Parser<AddCommand> {
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_TAG);

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

Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
Set<Tag> tagList = AlfredParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Person person = new Person(name, phone, email, address, tagList);
Person person = new Person(name, phone, email, tagList);

return new AddCommand(person);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package seedu.address.logic.parser.AddCommandParsers;

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_ORGANISATION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SPECIALISATION;
import seedu.address.logic.commands.addcommand.AddCommand;
import seedu.address.logic.commands.addcommand.AddMentorCommand;
import seedu.address.logic.parser.ArgumentMultimap;
import seedu.address.logic.parser.ArgumentTokenizer;
import seedu.address.logic.parser.Parser;
import seedu.address.logic.parser.AlfredParserUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.entity.Email;
import seedu.address.model.entity.Id;
import seedu.address.model.entity.Mentor;
import seedu.address.model.entity.Phone;
import seedu.address.model.entity.SubjectName;
import seedu.address.model.entity.Name;
import seedu.address.model.entitylist.MentorList;

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

/**
* 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 AddMentorCommand parse(String args) throws ParseException {

/**
* Added the below code as a placeholder. We will replace it with proper code
* once the Mentor class is finalised.
*/

ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ORGANISATION,
PREFIX_SPECIALISATION);
Name name = AlfredParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = AlfredParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = AlfredParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Name organisation = AlfredParserUtil.parseName(argMultimap.getValue(PREFIX_ORGANISATION).get());
SubjectName subject = AlfredParserUtil.parseSubject(argMultimap.getValue(PREFIX_SPECIALISATION).get());
Id id = new MentorList().generateID();

Mentor mentor = new Mentor(name, id, phone, email, organisation, subject);

return new AddMentorCommand(mentor);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package seedu.address.logic.parser.AddCommandParsers;

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 seedu.address.logic.commands.addcommand.AddParticipantCommand;
import seedu.address.logic.parser.ArgumentMultimap;
import seedu.address.logic.parser.ArgumentTokenizer;
import seedu.address.logic.parser.Parser;
import seedu.address.logic.parser.AlfredParserUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.entity.Email;
import seedu.address.model.entity.Id;
import seedu.address.model.entity.Name;
import seedu.address.model.entity.Participant;
import seedu.address.model.entity.Phone;
import seedu.address.model.entitylist.ParticipantList;

/**
* Parses input arguments and creates a new AddCommand object
*/
public class AddParticipantCommandParser implements Parser<AddParticipantCommand> {

/**
* 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 AddParticipantCommand parse(String args) throws ParseException {

/**
* Added the below code as a placeholder. We will replace it with proper code
* once the Participant class is finalised.
*/

ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL);
Name name = AlfredParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Phone phone = AlfredParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get());
Email email = AlfredParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Id id = new ParticipantList().generateID();

Participant participant = new Participant(name, id, email, phone);

return new AddParticipantCommand(participant);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package seedu.address.logic.parser.AddCommandParsers;

import static seedu.address.logic.parser.CliSyntax.PREFIX_LOCATION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PROJECT_TYPE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SPECIALISATION;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import seedu.address.logic.commands.addcommand.AddCommand;
import seedu.address.logic.commands.addcommand.AddTeamCommand;
import seedu.address.logic.parser.ArgumentMultimap;
import seedu.address.logic.parser.ArgumentTokenizer;
import seedu.address.logic.parser.Parser;
import seedu.address.logic.parser.AlfredParserUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.entity.Id;
import seedu.address.model.entity.Location;
import seedu.address.model.entity.Mentor;
import seedu.address.model.entity.Name;
import seedu.address.model.entity.Participant;
import seedu.address.model.entity.ProjectType;
import seedu.address.model.entity.Score;
import seedu.address.model.entity.SubjectName;
import seedu.address.model.entity.Team;
import seedu.address.model.entitylist.TeamList;

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

/**
* 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 AddTeamCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_SPECIALISATION, PREFIX_PROJECT_NAME,
PREFIX_PROJECT_TYPE, PREFIX_LOCATION);

Name name = AlfredParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
SubjectName subject = AlfredParserUtil.parseSubject(argMultimap.getValue(PREFIX_SPECIALISATION).get());
Name projectName = AlfredParserUtil.parseName(argMultimap.getValue(PREFIX_PROJECT_NAME).get());
ProjectType projectType = AlfredParserUtil.parseProjectType(argMultimap.getValue(PREFIX_PROJECT_TYPE).get());
Location location = AlfredParserUtil.parseLocation(argMultimap.getValue(PREFIX_LOCATION).get());
Id id = new TeamList().generateID();
List<Participant> participants = new LinkedList<>();
Score score = new Score(0);
Optional<Mentor> mentor = Optional.empty();

Team team = new Team(id, name, participants, mentor, subject, score, projectName, projectType, location);

return new AddTeamCommand(team);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AddressBookParser {
/**
* Parses user input into command for execution.
*
* @param userInput full user input string
* @param userInput full input string
* @return the command based on the user input
* @throws ParseException if the user input does not conform the expected format
*/
Expand Down
Loading

0 comments on commit 812a9d2

Please sign in to comment.