From 44e0109aff92e4689fa56cbdecfa64d7f2bae5f9 Mon Sep 17 00:00:00 2001 From: Ow Zhen Wei Date: Mon, 26 Mar 2018 13:07:27 +0800 Subject: [PATCH] Update application to accept job adding command (#73) * 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 * Fix checkstyle error Fix checkstyle error * Update ui classes to remove address field * Rename message constant * Add toSet method in RemarkList class * Update CarviciM to accept jobs (non-persistent) * Update toString method of Job class * Fix checkstyle error * Fix checkstyle error * Update job adding to show on UI * Add test for AddJobCommand * Update authorship * Fix checkstyle errors Fix checkstyle error Fix checkstyle error Remove trailing whitespace Fix error * Rename attributes in classes and add new constructors * Update toSet method in RemarkList * Add two new storage classes for Job * Fix checkstyle error * Add new attribute in XmlSerializableAddressBook class for persitent data for job * Add method in ModelManager to support initialization of running job number * Fix checkstyle error * Fix missing methods --- src/main/java/seedu/address/MainApp.java | 5 +- .../seedu/address/commons/core/Messages.java | 2 +- .../address/logic/commands/AddJobCommand.java | 56 ++++- .../address/logic/commands/DeleteCommand.java | 2 +- .../address/logic/commands/EditCommand.java | 2 +- .../address/logic/commands/SelectCommand.java | 2 +- .../logic/parser/AddJobCommandParser.java | 27 ++- .../address/logic/parser/ParserUtil.java | 13 ++ src/main/java/seedu/address/model/Model.java | 6 + .../seedu/address/model/ModelManager.java | 24 ++ .../java/seedu/address/model/job/Date.java | 14 +- .../java/seedu/address/model/job/Job.java | 25 ++- .../seedu/address/model/job/JobNumber.java | 26 ++- .../java/seedu/address/model/job/Status.java | 12 +- .../address/model/job/VehicleNumber.java | 17 +- .../address/model/remark/RemarkList.java | 9 + .../seedu/address/storage/XmlAdaptedJob.java | 195 +++++++++++++++++ .../address/storage/XmlAdaptedRemark.java | 64 ++++++ .../storage/XmlSerializableAddressBook.java | 9 +- src/main/java/seedu/address/ui/JobCard.java | 17 +- .../java/seedu/address/ui/JobListPanel.java | 2 +- src/main/resources/view/JobListCard.fxml | 26 ++- src/main/resources/view/JobListPanel.fxml | 5 +- .../seedu/address/logic/LogicManagerTest.java | 4 +- .../logic/commands/AddCommandTest.java | 5 + .../logic/commands/AddJobCommandTest.java | 206 ++++++++++++++++++ .../logic/commands/DeleteCommandTest.java | 6 +- .../logic/commands/EditCommandTest.java | 6 +- .../logic/commands/SelectCommandTest.java | 4 +- .../seedu/address/testutil/ClientBuilder.java | 30 +++ .../seedu/address/testutil/JobBuilder.java | 56 +++++ .../systemtests/DeleteCommandSystemTest.java | 6 +- .../systemtests/EditCommandSystemTest.java | 4 +- .../systemtests/SelectCommandSystemTest.java | 8 +- 34 files changed, 808 insertions(+), 87 deletions(-) create mode 100644 src/main/java/seedu/address/storage/XmlAdaptedJob.java create mode 100644 src/main/java/seedu/address/storage/XmlAdaptedRemark.java create mode 100644 src/test/java/seedu/address/logic/commands/AddJobCommandTest.java create mode 100644 src/test/java/seedu/address/testutil/ClientBuilder.java create mode 100644 src/test/java/seedu/address/testutil/JobBuilder.java diff --git a/src/main/java/seedu/address/MainApp.java b/src/main/java/seedu/address/MainApp.java index 41526ae15d58..07c6d80d8304 100644 --- a/src/main/java/seedu/address/MainApp.java +++ b/src/main/java/seedu/address/MainApp.java @@ -25,7 +25,6 @@ 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; @@ -68,15 +67,13 @@ public void init() throws Exception { initLogging(config); model = initModelManager(storage, userPrefs); + model.initJobNumber(); logic = new LogicManager(model); ui = new UiManager(logic, config, userPrefs); initEventsCenter(); - - //Initialize the job number - JobNumber.initialize("0"); } private String getApplicationParameter(String parameterName) { diff --git a/src/main/java/seedu/address/commons/core/Messages.java b/src/main/java/seedu/address/commons/core/Messages.java index 51a27d43be5e..725534fd6e74 100644 --- a/src/main/java/seedu/address/commons/core/Messages.java +++ b/src/main/java/seedu/address/commons/core/Messages.java @@ -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 employee index provided is invalid"; + public static final String MESSAGE_INVALID_EMPLOYEE_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"; diff --git a/src/main/java/seedu/address/logic/commands/AddJobCommand.java b/src/main/java/seedu/address/logic/commands/AddJobCommand.java index c6813af0e08f..683aea16851a 100644 --- a/src/main/java/seedu/address/logic/commands/AddJobCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddJobCommand.java @@ -1,14 +1,31 @@ package seedu.address.logic.commands; import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; 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.ArrayList; +import java.util.List; + +import seedu.address.commons.core.Messages; +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.job.Date; import seedu.address.model.job.Job; +import seedu.address.model.job.JobNumber; +import seedu.address.model.job.Status; +import seedu.address.model.job.VehicleNumber; +import seedu.address.model.person.Employee; +import seedu.address.model.person.Person; +import seedu.address.model.person.UniqueEmployeeList; +import seedu.address.model.person.exceptions.DuplicateEmployeeException; +import seedu.address.model.remark.RemarkList; +//@@author whenzei /** * Adds a job to CarviciM */ @@ -33,14 +50,45 @@ public class AddJobCommand extends UndoableCommand { public static final String MESSAGE_SUCCESS = "New job added: %1$s"; - private final Job toAdd; + private final Person client; + private final VehicleNumber vehicleNumber; + private final ArrayList targetIndices; + private final UniqueEmployeeList assignedEmployees; + + private Job toAdd; /** * Creates an AddJobCommand to add the specified {@code Job} */ - public AddJobCommand(Job job) { - requireNonNull(job); - toAdd = job; + public AddJobCommand(Person client, VehicleNumber vehicleNumber, ArrayList targetIndices) { + requireAllNonNull(client, vehicleNumber, targetIndices); + this.client = client; + this.vehicleNumber = vehicleNumber; + this.targetIndices = targetIndices; + assignedEmployees = new UniqueEmployeeList(); + } + + @Override + protected void preprocessUndoableCommand() throws CommandException { + List lastShownList = model.getFilteredPersonList(); + + //Check for valid employee indices + for (Index targetIndex : targetIndices) { + if (targetIndex.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); + } + } + + try { + for (Index targetIndex : targetIndices) { + assignedEmployees.add(lastShownList.get(targetIndex.getZeroBased())); + } + toAdd = new Job(client, vehicleNumber, new JobNumber(), new Date(), assignedEmployees, + new Status(Status.STATUS_ONGOING), new RemarkList()); + } catch (DuplicateEmployeeException e) { + throw new CommandException("Duplicate employee index"); + } + } @Override diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index b8e853c4f2d1..980ba3df39a4 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -51,7 +51,7 @@ protected void preprocessUndoableCommand() throws CommandException { List lastShownList = model.getFilteredPersonList(); if (targetIndex.getZeroBased() >= lastShownList.size()) { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + throw new CommandException(Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); } employeeToDelete = lastShownList.get(targetIndex.getZeroBased()); diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 13d3f3a2ed7f..be4a23fd6815 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -85,7 +85,7 @@ protected void preprocessUndoableCommand() throws CommandException { List lastShownList = model.getFilteredPersonList(); if (index.getZeroBased() >= lastShownList.size()) { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + throw new CommandException(Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); } employeeToEdit = lastShownList.get(index.getZeroBased()); diff --git a/src/main/java/seedu/address/logic/commands/SelectCommand.java b/src/main/java/seedu/address/logic/commands/SelectCommand.java index 4a9b4e3e68e9..8888cf3faf7d 100644 --- a/src/main/java/seedu/address/logic/commands/SelectCommand.java +++ b/src/main/java/seedu/address/logic/commands/SelectCommand.java @@ -35,7 +35,7 @@ public CommandResult execute() throws CommandException { List lastShownList = model.getFilteredPersonList(); if (targetIndex.getZeroBased() >= lastShownList.size()) { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + throw new CommandException(Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); } EventsCenter.getInstance().post(new JumpToListRequestEvent(targetIndex)); diff --git a/src/main/java/seedu/address/logic/parser/AddJobCommandParser.java b/src/main/java/seedu/address/logic/parser/AddJobCommandParser.java index c028cf4527c5..0e8c7dc5e273 100644 --- a/src/main/java/seedu/address/logic/parser/AddJobCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddJobCommandParser.java @@ -1,15 +1,24 @@ package seedu.address.logic.parser; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; 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.ArrayList; import java.util.stream.Stream; +import seedu.address.commons.core.index.Index; +import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.logic.commands.AddJobCommand; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.job.VehicleNumber; +import seedu.address.model.person.Email; +import seedu.address.model.person.Name; +import seedu.address.model.person.Person; +import seedu.address.model.person.Phone; //@@author whenzei /** @@ -29,10 +38,24 @@ public AddJobCommand parse(String args) throws ParseException { if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_VEHICLE_NUMBER, PREFIX_ASSIGNED_EMPLOYEE)) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddJobCommand.MESSAGE_USAGE)); } - //More to be added - return null; //Stub + try { + 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(); + VehicleNumber vehicleNumber = + ParserUtil.parseVehicleNumber(argMultimap.getValue(PREFIX_VEHICLE_NUMBER)).get(); + ArrayList assignedEmployeeIndices = + ParserUtil.parseIndices(argMultimap.getAllValues(PREFIX_ASSIGNED_EMPLOYEE)); + + Person client = new Person(name, phone, email); + return new AddJobCommand(client, vehicleNumber, assignedEmployeeIndices); + + } catch (IllegalValueException ive) { + throw new ParseException(ive.getMessage(), ive); + } } /** diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 8d0c5b7feb7a..94b0700ac293 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Optional; @@ -62,6 +63,18 @@ public static Index parseIndex(String oneBasedIndex) throws IllegalValueExceptio return Index.fromOneBased(Integer.parseInt(trimmedIndex)); } + /** + * Parses {@code Collection indices} into a {@code Set}. + */ + public static ArrayList parseIndices(Collection indices) throws IllegalValueException { + requireNonNull(indices); + final ArrayList indexList = new ArrayList<>(); + for (String index : indices) { + indexList.add(parseIndex(index)); + } + return indexList; + } + /** * Parses a {@code String name} into a {@code Name}. * Leading and trailing whitespaces will be trimmed. diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index a5b514167c5a..bd5aa20f22c6 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -17,6 +17,9 @@ public interface Model { /** {@code Predicate} that always evaluate to true */ Predicate PREDICATE_SHOW_ALL_PERSONS = unused -> true; + /** {@code Predicate} that always evaluate to true */ + Predicate PREDICATE_SHOW_ALL_JOBS = unused -> true; + /** Clears existing backing model and replaces with the provided new data. */ void resetData(ReadOnlyAddressBook newData, CommandWords newCommandWords); @@ -30,6 +33,9 @@ public interface Model { /** Returns the AddressBook */ ReadOnlyAddressBook getAddressBook(); + /** Initializes the job number based on the list of jobs */ + void initJobNumber(); + /** Adds the given job */ void addJob(Job job); diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index a28ba0b89cdc..1802f1287263 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -14,6 +14,7 @@ import seedu.address.commons.events.model.AddressBookChangedEvent; import seedu.address.logic.commands.CommandWords; import seedu.address.model.job.Job; +import seedu.address.model.job.JobNumber; import seedu.address.model.job.exceptions.JobNotFoundException; import seedu.address.model.person.Employee; import seedu.address.model.person.exceptions.DuplicateEmployeeException; @@ -25,6 +26,7 @@ */ public class ModelManager extends ComponentManager implements Model { private static final Logger logger = LogsCenter.getLogger(ModelManager.class); + private static final String ONE_AS_STRING = "1"; private final AddressBook addressBook; private final FilteredList filteredEmployees; @@ -50,6 +52,25 @@ public ModelManager() { this(new AddressBook(), new UserPrefs()); } + //@@author whenzei + /** + * Initializes the running job number based on the past job numbers. + */ + @Override + public void initJobNumber() { + if (filteredJobs.isEmpty()) { + JobNumber.initialize(ONE_AS_STRING); + return; + } + int largest = filteredJobs.get(0).getJobNumber().asInteger(); + for (Job job : filteredJobs) { + if ( job.getJobNumber().asInteger() > largest) { + largest = job.getJobNumber().asInteger(); + } + } + JobNumber.initialize(largest + 1); + } + @Override public void resetData(ReadOnlyAddressBook newData, CommandWords newCommandWords) { addressBook.resetData(newData); @@ -82,6 +103,9 @@ private void indicateAddressBookChanged() { @Override public synchronized void addJob(Job job) { + addressBook.addJob(job); + updateFilteredJobList(PREDICATE_SHOW_ALL_JOBS); + indicateAddressBookChanged(); } @Override diff --git a/src/main/java/seedu/address/model/job/Date.java b/src/main/java/seedu/address/model/job/Date.java index 10c6f04e4415..2824256cf829 100644 --- a/src/main/java/seedu/address/model/job/Date.java +++ b/src/main/java/seedu/address/model/job/Date.java @@ -10,10 +10,14 @@ public class Date { private static final String DATE_FORMATTER_PATTERN = "MMM d yyy"; - public final String date; + public final String value; public Date() { - date = generateDate(); + value = generateDate(); + } + + public Date(String date) { + value = date; } /** @@ -27,18 +31,18 @@ private String generateDate() { @Override public String toString() { - return date; + return value; } @Override public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof Date // instanceof handles nulls - && this.date.equals(((Date) other).date)); // state check + && this.value.equals(((Date) other).value)); // state check } @Override public int hashCode() { - return date.hashCode(); + return value.hashCode(); } } diff --git a/src/main/java/seedu/address/model/job/Job.java b/src/main/java/seedu/address/model/job/Job.java index 3d7b52a2bd12..f6017020b577 100644 --- a/src/main/java/seedu/address/model/job/Job.java +++ b/src/main/java/seedu/address/model/job/Job.java @@ -73,8 +73,7 @@ public Set getAssignedEmployees() { * if modification is attempted. */ public Set getRemarks() { - //Stub - return null; + return Collections.unmodifiableSet(remarks.toSet()); } @Override @@ -106,20 +105,26 @@ public int hashCode() { @Override public String toString() { final StringBuilder builder = new StringBuilder(); - builder.append("Job Number: ") + builder.append("\nJob Number: ") .append(getJobNumber()) - .append(" Status: ") - .append(getStatus()) + .append("[" + getStatus() + "]") .append(" Start Date: ") .append(getDate()) - .append(" Vehicle ID: ") + .append(" \nVehicle ID: ") .append(getVehicleNumber()) .append(" Client: ") .append(getClient()) - .append(" Remarks: "); - getRemarks().forEach(builder::append); - builder.append(" Assigned Employees: "); - getAssignedEmployees().forEach(builder::append); + .append(" \nRemarks: "); + + for (Remark remark : remarks) { + builder.append("\n" + remark); + } + + builder.append(" \nAssigned Employees:"); + for (Employee assignedEmployee : assignedEmployees) { + builder.append("\n" + assignedEmployee); + } + return builder.toString(); } } diff --git a/src/main/java/seedu/address/model/job/JobNumber.java b/src/main/java/seedu/address/model/job/JobNumber.java index 6659336d5559..022d88ff2ebc 100644 --- a/src/main/java/seedu/address/model/job/JobNumber.java +++ b/src/main/java/seedu/address/model/job/JobNumber.java @@ -7,38 +7,50 @@ public class JobNumber { private static int nextJobNumber; - public final String jobNumber; + public final String value; public JobNumber() { - jobNumber = Integer.toString(nextJobNumber); + value = Integer.toString(nextJobNumber); incrementNextJobNumber(); } + public JobNumber(String jobNumber) { + value = jobNumber; + } + /** * Initialize the next job number of the car servicing manager */ - public static void initialize(String args) { - nextJobNumber = Integer.parseInt(args); + public static void initialize(String arg) { + nextJobNumber = Integer.parseInt(arg); + } + + public static void initialize(int arg) { + nextJobNumber = arg; } public static void incrementNextJobNumber() { nextJobNumber++; } + public int asInteger() { + return Integer.parseInt(value); + } + @Override public String toString() { - return jobNumber; + return value; } @Override public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof JobNumber // instanceof handles nulls - && this.jobNumber.equals(((JobNumber) other).jobNumber)); // state check + && this.value.equals(((JobNumber) other).value)); // state check } @Override public int hashCode() { - return jobNumber.hashCode(); + return value.hashCode(); } } diff --git a/src/main/java/seedu/address/model/job/Status.java b/src/main/java/seedu/address/model/job/Status.java index bccc34d7702f..cbe59088835d 100644 --- a/src/main/java/seedu/address/model/job/Status.java +++ b/src/main/java/seedu/address/model/job/Status.java @@ -8,26 +8,26 @@ public class Status { public static final String STATUS_ONGOING = "ongoing"; public static final String STATUS_CLOSED = "closed"; - public final String status; + public final String value; - public Status(String status) { - this.status = status; + public Status(String value) { + this.value = value; } @Override public String toString() { - return status; + return value; } @Override public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof Status // instanceof handles nulls - && this.status.equals(((Status) other).status)); // state check + && this.value.equals(((Status) other).value)); // state check } @Override public int hashCode() { - return status.hashCode(); + return value.hashCode(); } } diff --git a/src/main/java/seedu/address/model/job/VehicleNumber.java b/src/main/java/seedu/address/model/job/VehicleNumber.java index 9b54b95d5f95..4e89efa1f5d5 100644 --- a/src/main/java/seedu/address/model/job/VehicleNumber.java +++ b/src/main/java/seedu/address/model/job/VehicleNumber.java @@ -8,17 +8,18 @@ * Represents a Vehicle ID in the Job */ public class VehicleNumber { + public static final String DEFAULT_VEHICLE_NUMBER = "SAS123J"; public static final String MESSAGE_VEHICLE_ID_CONSTRAINTS = "Vehicle ID should only contain alphanumeric characters and should not be blank"; public static final String VEHICLE_ID_VALIDATION_REGEX = "[\\p{Alnum}]*"; - public final String vehicleNumber; + public final String value; - public VehicleNumber(String vehicleNumber) { - requireNonNull(vehicleNumber); - checkArgument(isValidVehicleNumber(vehicleNumber), MESSAGE_VEHICLE_ID_CONSTRAINTS); - this.vehicleNumber = vehicleNumber; + public VehicleNumber(String value) { + requireNonNull(value); + checkArgument(isValidVehicleNumber(value), MESSAGE_VEHICLE_ID_CONSTRAINTS); + this.value = value; } /** @@ -30,19 +31,19 @@ public static boolean isValidVehicleNumber(String test) { @Override public String toString() { - return vehicleNumber; + return value; } @Override public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof VehicleNumber // instanceof handles nulls - && this.vehicleNumber.equals(((VehicleNumber) other).vehicleNumber)); // state check + && this.value.equals(((VehicleNumber) other).value)); // state check } @Override public int hashCode() { - return vehicleNumber.hashCode(); + return value.hashCode(); } diff --git a/src/main/java/seedu/address/model/remark/RemarkList.java b/src/main/java/seedu/address/model/remark/RemarkList.java index 1264ae78cd20..b95af99a32a5 100644 --- a/src/main/java/seedu/address/model/remark/RemarkList.java +++ b/src/main/java/seedu/address/model/remark/RemarkList.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -31,6 +32,14 @@ public RemarkList(Set remarks) { internalList.addAll(remarks); } + /** + * Returns all remarks in this list as a Set. + * This set is mutable and change-insulated against the internal list. + */ + public Set toSet() { + return new HashSet<>(internalList); + } + /** * Replaces the remarks in this list with those in the argument remark list * @param remarks diff --git a/src/main/java/seedu/address/storage/XmlAdaptedJob.java b/src/main/java/seedu/address/storage/XmlAdaptedJob.java new file mode 100644 index 000000000000..c7b8f6528889 --- /dev/null +++ b/src/main/java/seedu/address/storage/XmlAdaptedJob.java @@ -0,0 +1,195 @@ +package seedu.address.storage; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; + +import javax.xml.bind.annotation.XmlElement; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.job.Date; +import seedu.address.model.job.Job; +import seedu.address.model.job.JobNumber; +import seedu.address.model.job.Status; +import seedu.address.model.job.VehicleNumber; +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.UniqueEmployeeList; +import seedu.address.model.remark.Remark; +import seedu.address.model.remark.RemarkList; + +//@@author whenzei +/** + * JAXB-friendly version of the Job + */ +public class XmlAdaptedJob { + public static final String MISSING_FIELD_MESSAGE_FORMAT = "Job's %s field is missing!"; + + @XmlElement(required = true) + private String jobNumber; + @XmlElement(required = true) + private String name; + @XmlElement(required = true) + private String phone; + @XmlElement(required = true) + private String email; + @XmlElement(required = true) + private String vehicleNumber; + @XmlElement(required = true) + private String status; + @XmlElement(required = true) + private String date; + + @XmlElement(required = true) + private List assignedEmployees = new ArrayList<>(); + @XmlElement(required = true) + private List remarks = new ArrayList<>(); + + /** + * Constructs an XmlAdaptedJob. + * This is the no-arg constructor that is required by JAXB + */ + public XmlAdaptedJob() {} + + /** + * Constructs an {@code XmlAdaptedJob} with the given job details. + */ + public XmlAdaptedJob(String jobNumber, String name, String phone, String email, String vehicleNumber, + String status, String date, List assignedEmployees, + List remarks) { + + this.jobNumber = jobNumber; + this.name = name; + this.phone = phone; + this.email = email; + this.vehicleNumber = vehicleNumber; + this.status = status; + this.date = date; + if (assignedEmployees != null) { + this.assignedEmployees = new ArrayList<>(assignedEmployees); + } + if (remarks != null) { + this.remarks = new ArrayList<>(remarks); + } + } + + /** + * Converts a given Job into this class for JAXB use. + * + * @param source future changes to this will not affect the created XmlAdaptedEmployee + */ + public XmlAdaptedJob(Job source) { + jobNumber = source.getJobNumber().value; + name = source.getClient().getName().fullName; + phone = source.getClient().getPhone().value; + email = source.getClient().getEmail().value; + status = source.getStatus().value; + vehicleNumber = source.getVehicleNumber().value; + date = source.getDate().value; + for (Employee employee : source.getAssignedEmployees()) { + assignedEmployees.add(new XmlAdaptedEmployee(employee)); + } + for (Remark remark : source.getRemarks()) { + remarks.add(new XmlAdaptedRemark(remark)); + } + } + + /** + * Converts this jaxb-friendly adapted job object into the model's Job object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted job + */ + public Job toModelType() throws IllegalValueException { + final List jobRemarks = new ArrayList<>(); + final List jobAssignedEmployees = new ArrayList<>(); + for (XmlAdaptedRemark remark : remarks) { + jobRemarks.add(remark.toModelType()); + } + for (XmlAdaptedEmployee assignedEmployee : assignedEmployees) { + jobAssignedEmployees.add(assignedEmployee.toModelType()); + } + + if (this.jobNumber == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, + JobNumber.class.getSimpleName())); + } + final JobNumber jobNumber = new JobNumber(this.jobNumber); + + if (this.name == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); + } + if (!Name.isValidName(this.name)) { + throw new IllegalValueException(Name.MESSAGE_NAME_CONSTRAINTS); + } + final Name name = new Name(this.name); + + if (this.phone == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName())); + } + if (!Phone.isValidPhone(this.phone)) { + throw new IllegalValueException(Phone.MESSAGE_PHONE_CONSTRAINTS); + } + final Phone phone = new Phone(this.phone); + + if (this.email == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName())); + } + if (!Email.isValidEmail(this.email)) { + throw new IllegalValueException(Email.MESSAGE_EMAIL_CONSTRAINTS); + } + final Email email = new Email(this.email); + final Person client = new Person(name, phone, email); + + if (this.vehicleNumber == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, + VehicleNumber.class.getSimpleName())); + } + if (!VehicleNumber.isValidVehicleNumber(this.vehicleNumber)) { + throw new IllegalValueException(VehicleNumber.MESSAGE_VEHICLE_ID_CONSTRAINTS); + } + final VehicleNumber vehicleNumber = new VehicleNumber(this.vehicleNumber); + + if (this.status == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Status.class.getSimpleName())); + } + final Status status = new Status(this.status); + + if (this.date == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Date.class.getSimpleName())); + } + final Date date = new Date(this.date); + + + final RemarkList remarks = new RemarkList(new HashSet<>(jobRemarks)); + final UniqueEmployeeList assignedEmployees = new UniqueEmployeeList(); + assignedEmployees.setEmployees(jobAssignedEmployees); + + return new Job(client, vehicleNumber, jobNumber, date, assignedEmployees, status, remarks); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof XmlAdaptedJob)) { + return false; + } + + XmlAdaptedJob otherJob = (XmlAdaptedJob) other; + return Objects.equals(jobNumber, otherJob.jobNumber) + && Objects.equals(name, otherJob.name) + && Objects.equals(phone, otherJob.phone) + && Objects.equals(email, otherJob.email) + && Objects.equals(date, otherJob.date) + && Objects.equals(vehicleNumber, otherJob.vehicleNumber) + && Objects.equals(status, otherJob.status) + && assignedEmployees.equals(otherJob.assignedEmployees) + && remarks.equals(otherJob.remarks); + } +} diff --git a/src/main/java/seedu/address/storage/XmlAdaptedRemark.java b/src/main/java/seedu/address/storage/XmlAdaptedRemark.java new file mode 100644 index 000000000000..0df486e561e2 --- /dev/null +++ b/src/main/java/seedu/address/storage/XmlAdaptedRemark.java @@ -0,0 +1,64 @@ +package seedu.address.storage; + +//@@author whenzei + +import javax.xml.bind.annotation.XmlValue; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.remark.Remark; + +/** + * JAXB-friendly adapted version of the Remark. + */ +public class XmlAdaptedRemark { + + @XmlValue + private String remark; + + /** + * Constructs an XmlAdaptedRemark. + * This is the no-arg constructor that is required by JAXB + */ + public XmlAdaptedRemark() {} + + /** + * Construct a {@code XmlAdaptedRemark} with the given {@code remark}. + */ + public XmlAdaptedRemark(String remark) { + this.remark = remark; + } + + /** + * Converts a given Tag into this class for JAXB use. + * + * @param source future changes to this will not affect the created + */ + public XmlAdaptedRemark(Remark source) { + remark = source.value; + } + + /** + * Converts this jaxb-friendly adapted tag object into the model's Remark object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted job + */ + public Remark toModelType() throws IllegalValueException { + if (!Remark.isValidRemark(remark)) { + throw new IllegalValueException(Remark.MESSAGE_REMARKS_CONSTRAINTS); + } + return new Remark(remark); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof XmlAdaptedRemark)) { + return false; + } + + return remark.equals(((XmlAdaptedRemark) other).remark); + } +} diff --git a/src/main/java/seedu/address/storage/XmlSerializableAddressBook.java b/src/main/java/seedu/address/storage/XmlSerializableAddressBook.java index 6ff719d66341..78d1d78b1cb9 100644 --- a/src/main/java/seedu/address/storage/XmlSerializableAddressBook.java +++ b/src/main/java/seedu/address/storage/XmlSerializableAddressBook.java @@ -21,6 +21,8 @@ public class XmlSerializableAddressBook { private List employees; @XmlElement private List tags; + @XmlElement + private List jobs; /** * Creates an empty XmlSerializableAddressBook. @@ -29,6 +31,7 @@ public class XmlSerializableAddressBook { public XmlSerializableAddressBook() { employees = new ArrayList<>(); tags = new ArrayList<>(); + jobs = new ArrayList<>(); } /** @@ -38,6 +41,7 @@ public XmlSerializableAddressBook(ReadOnlyAddressBook src) { this(); employees.addAll(src.getEmployeeList().stream().map(XmlAdaptedEmployee::new).collect(Collectors.toList())); tags.addAll(src.getTagList().stream().map(XmlAdaptedTag::new).collect(Collectors.toList())); + jobs.addAll(src.getJobList().stream().map(XmlAdaptedJob::new).collect(Collectors.toList())); } /** @@ -54,6 +58,9 @@ public AddressBook toModelType() throws IllegalValueException { for (XmlAdaptedEmployee p : employees) { addressBook.addEmployee(p.toModelType()); } + for (XmlAdaptedJob j : jobs) { + addressBook.addJob(j.toModelType()); + } return addressBook; } @@ -68,6 +75,6 @@ public boolean equals(Object other) { } XmlSerializableAddressBook otherAb = (XmlSerializableAddressBook) other; - return employees.equals(otherAb.employees) && tags.equals(otherAb.tags); + return employees.equals(otherAb.employees) && tags.equals(otherAb.tags) && jobs.equals(otherAb.jobs); } } diff --git a/src/main/java/seedu/address/ui/JobCard.java b/src/main/java/seedu/address/ui/JobCard.java index c1604d22e48a..fe02b9c355ae 100644 --- a/src/main/java/seedu/address/ui/JobCard.java +++ b/src/main/java/seedu/address/ui/JobCard.java @@ -2,7 +2,6 @@ import javafx.fxml.FXML; import javafx.scene.control.Label; -import javafx.scene.layout.FlowPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Region; import seedu.address.model.job.Job; @@ -28,7 +27,7 @@ public class JobCard extends UiPart { @FXML private HBox cardPane; @FXML - private Label customer; + private Label client; @FXML private Label id; @FXML @@ -36,17 +35,21 @@ public class JobCard extends UiPart { @FXML private Label startDate; @FXML - private FlowPane employees; + private Label status; public JobCard(Job job) { super(FXML); this.job = job; - id.setText(job.getJobNumber().toString() + ". "); - customer.setText(job.getClient().getName().toString()); - job.getAssignedEmployees().forEach(employee -> employees.getChildren().add( - new Label(employee.getName().toString()))); + id.setText(job.getJobNumber().toString()); + client.setText(job.getClient().getName().toString()); vehicleNumber.setText(job.getVehicleNumber().toString()); startDate.setText(job.getDate().toString()); + status.setText("[" + job.getStatus().toString() + "]"); + if (job.getStatus().toString().equals("ongoing")) { + status.setStyle("-fx-text-fill: green"); + } else { + status.setStyle("-fx-text-fill: red"); + } // remarks are not supported in this version, might want to expand into new window due to space constraints } diff --git a/src/main/java/seedu/address/ui/JobListPanel.java b/src/main/java/seedu/address/ui/JobListPanel.java index acb9b13c11ea..4859505ecfed 100644 --- a/src/main/java/seedu/address/ui/JobListPanel.java +++ b/src/main/java/seedu/address/ui/JobListPanel.java @@ -22,7 +22,7 @@ //@author yuhongherald /** - * Panel containing the list of persons. + * Panel containing the list of jobs. */ public class JobListPanel extends UiPart { private static final String FXML = "JobListPanel.fxml"; diff --git a/src/main/resources/view/JobListCard.fxml b/src/main/resources/view/JobListCard.fxml index 6b1544d4d7fe..f2de3d7eebb2 100644 --- a/src/main/resources/view/JobListCard.fxml +++ b/src/main/resources/view/JobListCard.fxml @@ -3,34 +3,46 @@ - + - + + - + - + + + + + - - + + + + diff --git a/src/main/resources/view/JobListPanel.fxml b/src/main/resources/view/JobListPanel.fxml index 0182574bd895..ef1f8f25905f 100644 --- a/src/main/resources/view/JobListPanel.fxml +++ b/src/main/resources/view/JobListPanel.fxml @@ -4,6 +4,7 @@ - - + + + diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index 954c1fb04388..2f6e06974b46 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -1,7 +1,7 @@ package seedu.address.logic; import static org.junit.Assert.assertEquals; -import static seedu.address.commons.core.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX; import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; import org.junit.Rule; @@ -35,7 +35,7 @@ public void execute_invalidCommandFormat_throwsParseException() { @Test public void execute_commandExecutionError_throwsCommandException() { String deleteCommand = "delete 9"; - assertCommandException(deleteCommand, MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandException(deleteCommand, MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); assertHistoryCorrect(deleteCommand); } diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index 7fe5e73fa6b2..9dccea95bd1c 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -124,6 +124,11 @@ public CommandWords getCommandWords() { return null; } + @Override + public void initJobNumber() { + fail("This method should never be called"); + } + @Override public String appendCommandKeyToMessage(String message) { fail("This method should never be called"); return null; diff --git a/src/test/java/seedu/address/logic/commands/AddJobCommandTest.java b/src/test/java/seedu/address/logic/commands/AddJobCommandTest.java new file mode 100644 index 000000000000..3b69977eb474 --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/AddJobCommandTest.java @@ -0,0 +1,206 @@ +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.fail; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; +import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import java.util.ArrayList; +import java.util.function.Predicate; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import javafx.collections.ObservableList; +import seedu.address.commons.core.index.Index; +import seedu.address.logic.CommandHistory; +import seedu.address.logic.UndoRedoStack; +import seedu.address.model.AddressBook; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.UserPrefs; +import seedu.address.model.job.Job; +import seedu.address.model.job.JobNumber; +import seedu.address.model.job.VehicleNumber; +import seedu.address.model.job.exceptions.JobNotFoundException; +import seedu.address.model.person.Employee; +import seedu.address.model.person.Person; +import seedu.address.model.person.exceptions.DuplicateEmployeeException; +import seedu.address.model.person.exceptions.EmployeeNotFoundException; +import seedu.address.testutil.ClientBuilder; +import seedu.address.testutil.JobBuilder; + +//@@author whenzei +public class AddJobCommandTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + + @Test + public void constructor_nullAddJobFields_throwsNullPointerException() { + thrown.expect(NullPointerException.class); + new AddJobCommand(null, null, null); + } + + @Test + public void execute_jobAcceptedByModel_addSuccessful() throws Exception { + Person client = new ClientBuilder().build(); + ArrayList indices = generateValidEmployeeIndices(); + AddJobCommand addJobCommand = prepareCommand(client, + new VehicleNumber(VehicleNumber.DEFAULT_VEHICLE_NUMBER), indices); + + CommandResult commandResult = addJobCommand.execute(); + + Job validJob = new JobBuilder(model.getFilteredPersonList()).build(); + + assertEquals(String.format(AddJobCommand.MESSAGE_SUCCESS, validJob), commandResult.feedbackToUser); + } + + + /** + * A default model stub that have all of the methods failing. + */ + private class ModelStub implements Model { + @Override + public void addPerson(Employee employee) throws DuplicateEmployeeException { + fail("This method should not be called."); + } + + @Override + public void resetData(ReadOnlyAddressBook newData, CommandWords newCommandWords) { + fail("This method should not be called."); + } + + @Override + public CommandWords getCommandWords() { + fail("This method should never be called"); + return null; + } + + @Override + public void initJobNumber() { + fail("This method should never be called"); + } + + @Override public String appendCommandKeyToMessage(String message) { + fail("This method should never be called"); + return null; + } + + @Override + public ReadOnlyAddressBook getAddressBook() { + fail("This method should not be called."); + return null; + } + + @Override + public void addJob(Job job) { + fail("This method should not be called."); + } + + @Override + public void closeJob(Job target) throws JobNotFoundException { + fail("This method should not be called."); + } + + @Override + public void deletePerson(Employee target) throws EmployeeNotFoundException { + fail("This method should not be called."); + } + + @Override + public void sortPersonList() { + fail("This method should not be called."); + } + + @Override + public void updatePerson(Employee target, Employee editedEmployee) + throws DuplicateEmployeeException { + fail("This method should not be called."); + } + + @Override + public ObservableList getFilteredPersonList() { + fail("This method should not be called."); + return null; + } + + @Override + public void updateFilteredPersonList(Predicate predicate) { + fail("This method should not be called."); + } + + @Override + public ObservableList getFilteredJobList() { + fail("This method should not be called."); + return null; + } + + @Override + public void updateFilteredJobList(Predicate predicate) { + fail("This method should not be called."); + } + } + + /** + * A Model stub that always throw a DuplicateEmployeeException when trying to add a employee. + */ + private class ModelStubThrowingDuplicatePersonException extends ModelStub { + @Override + public void addPerson(Employee employee) throws DuplicateEmployeeException { + throw new DuplicateEmployeeException(); + } + + @Override + public ReadOnlyAddressBook getAddressBook() { + return new AddressBook(); + } + } + + + /** + * A Model stub that always accept the employee being added. + */ + private class ModelStubAcceptingJobAdded extends ModelStub { + final ArrayList personsAdded = new ArrayList<>(); + + @Override + public void addJob(Job job) { + requireNonNull(job); + personsAdded.add(job); + } + + @Override + public ReadOnlyAddressBook getAddressBook() { + return new AddressBook(); + } + } + + /** + * Generates an Arraylist of valid assigned employee index + */ + private ArrayList generateValidEmployeeIndices() { + ArrayList indices = new ArrayList(); + indices.add(INDEX_FIRST_PERSON); + indices.add(INDEX_SECOND_PERSON); + return indices; + } + + /** + * Returns a {@code AddJobCommand} with the client, vehicleNumber and indices. + * @param client + * @param vehicleNumber + * @param indices + */ + private AddJobCommand prepareCommand(Person client, VehicleNumber vehicleNumber, ArrayList indices) { + JobNumber.initialize("0"); + AddJobCommand addJobCommand = new AddJobCommand(client, vehicleNumber, indices); + addJobCommand.setData(model, new CommandHistory(), new UndoRedoStack()); + return addJobCommand; + } +} diff --git a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java index ffe87f3749c0..4a14f7b64441 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java @@ -49,7 +49,7 @@ public void execute_invalidIndexUnfilteredList_throwsCommandException() throws E Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1); DeleteCommand deleteCommand = prepareCommand(outOfBoundIndex); - assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); } @Test @@ -78,7 +78,7 @@ public void execute_invalidIndexFilteredList_throwsCommandException() { DeleteCommand deleteCommand = prepareCommand(outOfBoundIndex); - assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); } @Test @@ -111,7 +111,7 @@ public void executeUndoRedo_invalidIndexUnfilteredList_failure() { DeleteCommand deleteCommand = prepareCommand(outOfBoundIndex); // execution failed -> deleteCommand not pushed into undoRedoStack - assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); // no COMMANDS in undoRedoStack -> undoCommand and redoCommand fail assertCommandFailure(undoCommand, model, UndoCommand.MESSAGE_FAILURE); diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index bfa76a95b877..10788f864221 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -130,7 +130,7 @@ public void execute_invalidPersonIndexUnfilteredList_failure() { EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build(); EditCommand editCommand = prepareCommand(outOfBoundIndex, descriptor); - assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); } /** @@ -147,7 +147,7 @@ public void execute_invalidPersonIndexFilteredList_failure() { EditCommand editCommand = prepareCommand(outOfBoundIndex, new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build()); - assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); } @Test @@ -183,7 +183,7 @@ public void executeUndoRedo_invalidIndexUnfilteredList_failure() { EditCommand editCommand = prepareCommand(outOfBoundIndex, descriptor); // execution failed -> editCommand not pushed into undoRedoStack - assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); // no COMMANDS in undoRedoStack -> undoCommand and redoCommand fail assertCommandFailure(undoCommand, model, UndoCommand.MESSAGE_FAILURE); diff --git a/src/test/java/seedu/address/logic/commands/SelectCommandTest.java b/src/test/java/seedu/address/logic/commands/SelectCommandTest.java index a3fb7bcc7f26..b8554a0fb3f7 100644 --- a/src/test/java/seedu/address/logic/commands/SelectCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/SelectCommandTest.java @@ -52,7 +52,7 @@ public void execute_validIndexUnfilteredList_success() { public void execute_invalidIndexUnfilteredList_failure() { Index outOfBoundsIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1); - assertExecutionFailure(outOfBoundsIndex, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertExecutionFailure(outOfBoundsIndex, Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); } @Test @@ -70,7 +70,7 @@ public void execute_invalidIndexFilteredList_failure() { // ensures that outOfBoundIndex is still in bounds of address book list assertTrue(outOfBoundsIndex.getZeroBased() < model.getAddressBook().getEmployeeList().size()); - assertExecutionFailure(outOfBoundsIndex, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertExecutionFailure(outOfBoundsIndex, Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); } @Test diff --git a/src/test/java/seedu/address/testutil/ClientBuilder.java b/src/test/java/seedu/address/testutil/ClientBuilder.java new file mode 100644 index 000000000000..463afc3adcba --- /dev/null +++ b/src/test/java/seedu/address/testutil/ClientBuilder.java @@ -0,0 +1,30 @@ +package seedu.address.testutil; + +import seedu.address.model.person.Email; +import seedu.address.model.person.Name; +import seedu.address.model.person.Person; +import seedu.address.model.person.Phone; + +//@@author whenzei +/** + * A utility class to help with building Client objects. + */ +public class ClientBuilder { + public static final String DEFAULT_NAME = "Alice Pauline"; + public static final String DEFAULT_PHONE = "85355255"; + public static final String DEFAULT_EMAIL = "alice@gmail.com"; + + private Name name; + private Phone phone; + private Email email; + + public ClientBuilder() { + name = new Name(DEFAULT_NAME); + phone = new Phone(DEFAULT_PHONE); + email = new Email(DEFAULT_EMAIL); + } + + public Person build() { + return new Person(name, phone, email); + } +} diff --git a/src/test/java/seedu/address/testutil/JobBuilder.java b/src/test/java/seedu/address/testutil/JobBuilder.java new file mode 100644 index 000000000000..f8d96fed88f0 --- /dev/null +++ b/src/test/java/seedu/address/testutil/JobBuilder.java @@ -0,0 +1,56 @@ +package seedu.address.testutil; + +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; +import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; + +import javafx.collections.ObservableList; +import seedu.address.model.job.Date; +import seedu.address.model.job.Job; +import seedu.address.model.job.JobNumber; +import seedu.address.model.job.Status; +import seedu.address.model.job.VehicleNumber; +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.UniqueEmployeeList; +import seedu.address.model.remark.RemarkList; + +//@@author whenzei +/** + * A utility class to help with building Job objects. + */ +public class JobBuilder { + public static final String DEFAULT_NAME = "Alice Pauline"; + public static final String DEFAULT_PHONE = "85355255"; + public static final String DEFAULT_EMAIL = "alice@gmail.com"; + + private Person client; + private VehicleNumber vehicleNumber; + private UniqueEmployeeList assignedEmployees; + private Status status; + private Date date; + private RemarkList remarks; + private JobNumber jobNumber; + + public JobBuilder(ObservableList employees) throws Exception { + Name name = new Name(DEFAULT_NAME); + Phone phone = new Phone(DEFAULT_PHONE); + Email email = new Email(DEFAULT_EMAIL); + JobNumber.initialize("0"); + + client = new Person(name, phone, email); + vehicleNumber = new VehicleNumber(VehicleNumber.DEFAULT_VEHICLE_NUMBER); + status = new Status(Status.STATUS_ONGOING); + date = new Date(); + jobNumber = new JobNumber(); + remarks = new RemarkList(); + assignedEmployees = new UniqueEmployeeList(); + assignedEmployees.add(employees.get(INDEX_FIRST_PERSON.getZeroBased())); + assignedEmployees.add(employees.get(INDEX_SECOND_PERSON.getZeroBased())); + } + public Job build() { + return new Job(client, vehicleNumber, jobNumber, date, assignedEmployees, status, remarks); + } +} diff --git a/src/test/java/systemtests/DeleteCommandSystemTest.java b/src/test/java/systemtests/DeleteCommandSystemTest.java index 2bd861b9d432..bccbbc679b59 100644 --- a/src/test/java/systemtests/DeleteCommandSystemTest.java +++ b/src/test/java/systemtests/DeleteCommandSystemTest.java @@ -1,7 +1,7 @@ package systemtests; import static org.junit.Assert.assertTrue; -import static seedu.address.commons.core.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX; import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; import static seedu.address.logic.commands.DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS; import static seedu.address.testutil.TestUtil.getLastIndex; @@ -71,7 +71,7 @@ public void delete() { showPersonsWithName(KEYWORD_MATCHING_MEIER); int invalidIndex = getModel().getAddressBook().getEmployeeList().size(); command = DeleteCommand.COMMAND_WORD + " " + invalidIndex; - assertCommandFailure(command, MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(command, MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); /* ------------------- Performing delete operation while a employee card is selected ---------------------- */ @@ -100,7 +100,7 @@ public void delete() { Index outOfBoundsIndex = Index.fromOneBased( getModel().getAddressBook().getEmployeeList().size() + 1); command = DeleteCommand.COMMAND_WORD + " " + outOfBoundsIndex.getOneBased(); - assertCommandFailure(command, MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(command, MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); /* Case: invalid arguments (alphabets) -> rejected */ assertCommandFailure(DeleteCommand.COMMAND_WORD + " abc", MESSAGE_INVALID_DELETE_COMMAND_FORMAT); diff --git a/src/test/java/systemtests/EditCommandSystemTest.java b/src/test/java/systemtests/EditCommandSystemTest.java index a776bdf694ec..09a52a4c567d 100644 --- a/src/test/java/systemtests/EditCommandSystemTest.java +++ b/src/test/java/systemtests/EditCommandSystemTest.java @@ -109,7 +109,7 @@ public void edit() throws Exception { showPersonsWithName(KEYWORD_MATCHING_MEIER); int invalidIndex = getModel().getAddressBook().getEmployeeList().size(); assertCommandFailure(EditCommand.COMMAND_WORD + " " + invalidIndex + NAME_DESC_BOB, - Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); /* ------------------- Performing edit operation while a employee card is selected ------------------------ */ @@ -138,7 +138,7 @@ public void edit() throws Exception { /* Case: invalid index (size + 1) -> rejected */ invalidIndex = getModel().getFilteredPersonList().size() + 1; assertCommandFailure(EditCommand.COMMAND_WORD + " " + invalidIndex + NAME_DESC_BOB, - Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); /* Case: missing index -> rejected */ assertCommandFailure(EditCommand.COMMAND_WORD + NAME_DESC_BOB, diff --git a/src/test/java/systemtests/SelectCommandSystemTest.java b/src/test/java/systemtests/SelectCommandSystemTest.java index 20496b24cedd..ba690f165b5d 100644 --- a/src/test/java/systemtests/SelectCommandSystemTest.java +++ b/src/test/java/systemtests/SelectCommandSystemTest.java @@ -2,7 +2,7 @@ import static org.junit.Assert.assertTrue; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.commons.core.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX; import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; import static seedu.address.logic.commands.SelectCommand.MESSAGE_SELECT_PERSON_SUCCESS; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; @@ -58,7 +58,7 @@ public void select() { */ showPersonsWithName(KEYWORD_MATCHING_MEIER); int invalidIndex = getModel().getAddressBook().getEmployeeList().size(); - assertCommandFailure(SelectCommand.COMMAND_WORD + " " + invalidIndex, MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(SelectCommand.COMMAND_WORD + " " + invalidIndex, MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); /* Case: filtered employee list, select index within bounds of address book and employee list -> selected */ Index validIndex = Index.fromOneBased(1); @@ -78,7 +78,7 @@ public void select() { /* Case: invalid index (size + 1) -> rejected */ invalidIndex = getModel().getFilteredPersonList().size() + 1; - assertCommandFailure(SelectCommand.COMMAND_WORD + " " + invalidIndex, MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(SelectCommand.COMMAND_WORD + " " + invalidIndex, MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); /* Case: invalid arguments (alphabets) -> rejected */ assertCommandFailure(SelectCommand.COMMAND_WORD + " abc", @@ -94,7 +94,7 @@ public void select() { /* Case: select from empty address book -> rejected */ deleteAllPersons(); assertCommandFailure(SelectCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased(), - MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + MESSAGE_INVALID_EMPLOYEE_DISPLAYED_INDEX); } /**