Skip to content

Commit

Permalink
Update classes for job management and remove address (nus-cs2103-AY17…
Browse files Browse the repository at this point in the history
…18S2#56)

* Create command classes for job management features

* Update Model API to support addJob and closeJob

* Add new prefixes in CliSyntax to support adding of job

* Rename command for remark

* Add closeJob and addJob methods in ModelManager and AddCommandTest class

* Rename attribute in Job class

* Update AddJobCommand class

* Update message in AddJobCommand class

* UserGuide.adoc: update job adding feature format

* Add parse method in ParserUtil class for VehicleNumber

* Add new class  AddJobCommandParser (incomplete)

* Update authorship to classes

* Update Logic and Model component to support job management

* Remove all address parameter for add employee

* Update ui classes to remove address field
  • Loading branch information
whenzei authored Mar 20, 2018
1 parent 360220e commit af35b8d
Show file tree
Hide file tree
Showing 54 changed files with 421 additions and 413 deletions.
7 changes: 4 additions & 3 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ e.g. typing *`help`* and pressing kbd:[Enter] will open the help window.
* Words in `UPPER_CASE` are the parameters to be supplied by the user e.g. in `adde n/NAME`, `NAME` is a parameter which can be used as `adde n/John Doe`.
* Items in square brackets are optional e.g `n/NAME [t/TAG]` can be used as `n/John Doe t/mechanic` or as `n/John Doe`.
* Items with `…`​ after them can be used multiple times including zero times e.g. `[t/TAG]...` can be used as `{nbsp}` (i.e. 0 times), `t/mechanic`, `t/technician` etc.
* Items with `+` after them can be used multiple times but has to be used **at least once** e.g. `w/ASSIGNED_EMPLOYEE_INDEX+` can be used as `w/4`, `w/5` etc.
* Parameters can be in any order e.g. if the command specifies `n/NAME p/PHONE_NUMBER`, `p/PHONE_NUMBER n/NAME` is also acceptable.
====

Expand All @@ -63,12 +64,12 @@ Format: `help`
=== Adding an job entry: `addj`

Adds a job entry to CarviciM +
Format: `addj n/NAME p/PHONE_NUMBER e/EMAIL v/VEHICLE_NUMBER w/EMPLOYEE_INDEX`
Format: `addj n/NAME p/PHONE_NUMBER e/EMAIL v/VEHICLE_NUMBER w/ASSIGNED_EMPLOYEE_INDEX+`

Examples:

* `addj n/John Doe p/98765432 e/[email protected] v/bhj123 w/33`
* `addj n/Betsy Crowe p/93939393 e/[email protected] v/ss888 w/2`
* `addj n/John Doe p/98765432 e/[email protected] v/bhj123 w/3`
* `addj n/Betsy Crowe p/93939393 e/[email protected] v/ss888 w/2 w/3 w/5`

=== Closing a job entry: `closej`

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import seedu.address.model.ModelManager;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.UserPrefs;
import seedu.address.model.job.JobNumber;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.storage.AddressBookStorage;
import seedu.address.storage.JsonUserPrefsStorage;
Expand Down Expand Up @@ -73,6 +74,9 @@ public void init() throws Exception {
ui = new UiManager(logic, config, userPrefs);

initEventsCenter();

//Initialize the job number
JobNumber.initialize("0");
}

private String getApplicationParameter(String parameterName) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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.job.Job;
import seedu.address.model.person.Employee;

/**
Expand All @@ -25,6 +26,9 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Employee> getFilteredPersonList();

/** Returns an unmodifiable view of the filtered list of jobs */
ObservableList<Job> getFilteredJobList();

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

/**
Expand Down Expand Up @@ -54,6 +55,11 @@ public ObservableList<Employee> getFilteredPersonList() {
return model.getFilteredPersonList();
}

@Override
public ObservableList<Job> getFilteredJobList() {
return model.getFilteredJobList();
}

@Override
public ListElementPointer getHistorySnapshot() {
return new ListElementPointer(history.getHistory());
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/seedu/address/logic/commands/AddCommand.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 @@ -23,13 +22,11 @@ public class AddCommand extends UndoableCommand {
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ "[" + PREFIX_TAG + "TAG]...\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";

Expand Down
60 changes: 60 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddJobCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ASSIGNED_EMPLOYEE;
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_VEHICLE_NUMBER;

import seedu.address.model.job.Job;

/**
* Adds a job to CarviciM
*/
public class AddJobCommand extends UndoableCommand {

public static final String COMMAND_WORD = "addj";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a job to the CarviciM. "
+ "Parameters: "
+ PREFIX_NAME + "CLIENT_NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_VEHICLE_NUMBER + "VEHICLE_NUMBER "
+ PREFIX_ASSIGNED_EMPLOYEE + "ASSIGNED_EMPLOYEE_INDEX+\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_VEHICLE_NUMBER + "SHG123A "
+ PREFIX_ASSIGNED_EMPLOYEE + "3 "
+ PREFIX_ASSIGNED_EMPLOYEE + "6 ";

public static final String MESSAGE_SUCCESS = "New job added: %1$s";

private final Job toAdd;

/**
* Creates an AddJobCommand to add the specified {@code Job}
*/
public AddJobCommand(Job job) {
requireNonNull(job);
toAdd = job;
}

@Override
public CommandResult executeUndoableCommand() {
requireNonNull(model);
model.addJob(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));

}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddJobCommand // instanceof handles nulls
&& toAdd.equals(((AddJobCommand) other).toAdd));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package seedu.address.logic.commands;

/**
* Closes an ongoing job in CarviciM
*/
public class CloseJobCommand {
}
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.core.index.Index;
import seedu.address.commons.util.CollectionUtil;
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;
Expand All @@ -42,7 +40,6 @@ public class EditCommand extends UndoableCommand {
+ "[" + 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 @@ -105,10 +102,9 @@ private static Employee createEditedPerson(Employee employeeToEdit, EditPersonDe
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 Employee(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags);
return new Employee(updatedName, updatedPhone, updatedEmail, updatedTags);
}

@Override
Expand Down Expand Up @@ -138,7 +134,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 @@ -151,15 +146,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(this.name, this.phone, this.email, this.address, this.tags);
return CollectionUtil.isAnyNonNull(this.name, this.phone, this.email, this.tags);
}

public void setName(Name name) {
Expand All @@ -186,14 +180,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 @@ -229,7 +215,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
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/logic/commands/RemarkCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package seedu.address.logic.commands;

/**
* Adds a remark to a job in CarviciM
*/
public class RemarkCommand {
}
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 @@ -13,7 +12,6 @@
import seedu.address.commons.exceptions.IllegalValueException;
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.Employee;
import seedu.address.model.person.Name;
Expand All @@ -32,9 +30,9 @@ 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));
}
Expand All @@ -43,10 +41,9 @@ public AddCommand parse(String args) throws ParseException {
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));

Employee employee = new Employee(name, phone, email, address, tagList);
Employee employee = new Employee(name, phone, email, tagList);

return new AddCommand(employee);
} catch (IllegalValueException ive) {
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/seedu/address/logic/parser/AddJobCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package seedu.address.logic.parser;

import static seedu.address.logic.parser.CliSyntax.PREFIX_ASSIGNED_EMPLOYEE;
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_VEHICLE_NUMBER;

import java.util.stream.Stream;

import seedu.address.logic.commands.AddJobCommand;
import seedu.address.logic.parser.exceptions.ParseException;

//@@author whenzei
/**
* Parses the input arguments and creates a new AddJobCommand object
*/
public class AddJobCommandParser implements Parser<AddJobCommand> {

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

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE,
PREFIX_EMAIL, PREFIX_VEHICLE_NUMBER, PREFIX_ASSIGNED_EMPLOYEE)) {
}

//More to be added
return null; //Stub
}

/**
* Returns true if none of the prefixes contains empty {@code Optional} values in the given
* {@code ArgumentMultimap}.
*/
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) {
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.regex.Pattern;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.AddJobCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandWords;
Expand Down Expand Up @@ -120,6 +121,9 @@ public Command parseCommand(String userInput) throws ParseException {

case SetCommand.COMMAND_WORD:
return new SetCommandParser().parse(arguments);

case AddJobCommand.COMMAND_WORD:
return new AddJobCommandParser().parse(arguments);
default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class CliSyntax {
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");

public static final Prefix PREFIX_VEHICLE_NUMBER = new Prefix("v/");
public static final Prefix PREFIX_ASSIGNED_EMPLOYEE = new Prefix("w/");
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.util.Objects.requireNonNull;
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 Down Expand Up @@ -33,7 +32,7 @@ public class EditCommandParser implements Parser<EditCommand> {
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
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);

Index index;

Expand All @@ -48,7 +47,6 @@ public EditCommand parse(String args) throws ParseException {
ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME)).ifPresent(editPersonDescriptor::setName);
ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE)).ifPresent(editPersonDescriptor::setPhone);
ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL)).ifPresent(editPersonDescriptor::setEmail);
ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS)).ifPresent(editPersonDescriptor::setAddress);
parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags);
} catch (IllegalValueException ive) {
throw new ParseException(ive.getMessage(), ive);
Expand Down
Loading

0 comments on commit af35b8d

Please sign in to comment.