From a79072c663bf9ab7e10eec0c987de88f5fd614c2 Mon Sep 17 00:00:00 2001 From: nixonwidjaja Date: Fri, 29 Sep 2023 16:46:05 +0800 Subject: [PATCH 1/7] Add person attributes, add command --- .../java/seedu/address/logic/Messages.java | 10 ++- .../address/logic/commands/AddCommand.java | 20 +++-- .../address/logic/commands/EditCommand.java | 2 +- .../logic/parser/AddCommandParser.java | 19 ++++- .../seedu/address/logic/parser/CliSyntax.java | 5 +- .../address/logic/parser/ParserUtil.java | 48 ++++++++++++ .../seedu/address/model/person/Birthday.java | 72 +++++++++++++++++ .../address/model/person/Department.java | 59 ++++++++++++++ .../seedu/address/model/person/Money.java | 78 +++++++++++++++++++ .../java/seedu/address/model/person/Name.java | 16 +--- .../seedu/address/model/person/Person.java | 40 ++++++++-- .../address/model/util/SampleDataUtil.java | 42 ++++------ .../address/storage/JsonAdaptedPerson.java | 75 ++++++++++++------ .../java/seedu/address/ui/PersonCard.java | 21 +++-- src/main/resources/view/PersonListCard.fxml | 4 + 15 files changed, 422 insertions(+), 89 deletions(-) create mode 100644 src/main/java/seedu/address/model/person/Birthday.java create mode 100644 src/main/java/seedu/address/model/person/Department.java create mode 100644 src/main/java/seedu/address/model/person/Money.java diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index ecd32c31b53..7f9e17148e7 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -43,8 +43,14 @@ public static String format(Person person) { .append(person.getEmail()) .append("; Address: ") .append(person.getAddress()) - .append("; Tags: "); - person.getTags().forEach(builder::append); + .append("; Salary: ") + .append(person.getSalary()) + .append("; Claim budget: ") + .append(person.getClaimBudget()) + .append("; Department: ") + .append(person.getDepartment()) + .append("; DOB: ") + .append(person.getDob()); return builder.toString(); } diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 5d7185a9680..505239c9268 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -2,10 +2,13 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_BUDGET; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DEPARTMENT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB; 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_TAG; +import static seedu.address.logic.parser.CliSyntax.PREFIX_SALARY; import seedu.address.commons.util.ToStringBuilder; import seedu.address.logic.Messages; @@ -20,22 +23,27 @@ public class AddCommand extends Command { public static final String COMMAND_WORD = "add"; - public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. " + public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an employee to the employee list.\n" + "Parameters: " + PREFIX_NAME + "NAME " + PREFIX_PHONE + "PHONE " + PREFIX_EMAIL + "EMAIL " + PREFIX_ADDRESS + "ADDRESS " - + "[" + PREFIX_TAG + "TAG]...\n" + + PREFIX_SALARY + "SALARY " + + PREFIX_CLAIM_BUDGET + "CLAIM BUDGET " + + PREFIX_DEPARTMENT + "DEPARTMENT " + + PREFIX_DOB + "BIRTHDATE (YYYY-MM-DD)\n" + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "John Doe " + PREFIX_PHONE + "98765432 " + PREFIX_EMAIL + "johnd@example.com " + PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " - + PREFIX_TAG + "friends " - + PREFIX_TAG + "owesMoney"; + + PREFIX_SALARY + "7000 " + + PREFIX_CLAIM_BUDGET + "1500 " + + PREFIX_DEPARTMENT + "Engineering " + + PREFIX_DOB + "1999-07-23"; - public static final String MESSAGE_SUCCESS = "New person added: %1$s"; + public static final String MESSAGE_SUCCESS = "New employee added: %1$s"; public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book"; private final Person toAdd; diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 4b581c7331e..f5b3d7b7452 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -101,7 +101,7 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags); + return null; } @Override diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 4ff1a97ed77..97fb4fb2f19 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -2,9 +2,13 @@ import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_BUDGET; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DEPARTMENT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB; 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_SALARY; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import java.util.Set; @@ -13,7 +17,10 @@ import seedu.address.logic.commands.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.Address; +import seedu.address.model.person.Birthday; +import seedu.address.model.person.Department; import seedu.address.model.person.Email; +import seedu.address.model.person.Money; import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; @@ -31,9 +38,11 @@ public class AddCommandParser implements Parser { */ 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_ADDRESS, + PREFIX_SALARY, PREFIX_CLAIM_BUDGET, PREFIX_DEPARTMENT, PREFIX_DOB); - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL) + if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, + PREFIX_SALARY, PREFIX_CLAIM_BUDGET, PREFIX_DEPARTMENT, PREFIX_DOB) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } @@ -43,9 +52,13 @@ public AddCommand parse(String args) throws ParseException { 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()); + Money salary = ParserUtil.parseMoney(argMultimap.getValue(PREFIX_SALARY).get()); + Money claimBudget = ParserUtil.parseMoney(argMultimap.getValue(PREFIX_CLAIM_BUDGET).get()); + Department department = ParserUtil.parseDepartment(argMultimap.getValue(PREFIX_DEPARTMENT).get()); + Birthday dob = ParserUtil.parseDob(argMultimap.getValue(PREFIX_DOB).get()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Person person = new Person(name, phone, email, address, tagList); + Person person = new Person(name, phone, email, address, salary, claimBudget, department, dob); return new AddCommand(person); } diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 75b1a9bf119..be594563301 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -10,6 +10,9 @@ public class CliSyntax { public static final Prefix PREFIX_PHONE = new Prefix("p/"); public static final Prefix PREFIX_EMAIL = new Prefix("e/"); public static final Prefix PREFIX_ADDRESS = new Prefix("a/"); + public static final Prefix PREFIX_SALARY = new Prefix("s/"); + public static final Prefix PREFIX_CLAIM_BUDGET = new Prefix("b/"); + public static final Prefix PREFIX_DEPARTMENT = new Prefix("d/"); + public static final Prefix PREFIX_DOB = new Prefix("dob/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); - } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index b117acb9c55..803d4a36344 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -10,7 +10,10 @@ import seedu.address.commons.util.StringUtil; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.Address; +import seedu.address.model.person.Birthday; +import seedu.address.model.person.Department; import seedu.address.model.person.Email; +import seedu.address.model.person.Money; import seedu.address.model.person.Name; import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; @@ -95,6 +98,51 @@ public static Email parseEmail(String email) throws ParseException { return new Email(trimmedEmail); } + /** + * Parses a {@code String dollar amount} into a {@code Money}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code dollar amount} is invalid. + */ + public static Money parseMoney(String money) throws ParseException { + requireNonNull(money); + String trimmed = money.trim(); + if (!Money.isValidMoney(trimmed)) { + throw new ParseException(Money.MESSAGE_CONSTRAINTS); + } + return new Money(trimmed); + } + + /** + * Parses a {@code String department} into a {@code Department}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code department} is invalid. + */ + public static Department parseDepartment(String department) throws ParseException { + requireNonNull(department); + String trimmed = department.trim(); + if (!Department.isValidDepartment(trimmed)) { + throw new ParseException(Department.MESSAGE_CONSTRAINTS); + } + return new Department(trimmed); + } + + /** + * Parses a {@code String dob into a {@code Birthday}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code dob} is invalid. + */ + public static Birthday parseDob(String dob) throws ParseException { + requireNonNull(dob); + String trimmed = dob.trim(); + if (!Birthday.isValidDob(trimmed)) { + throw new ParseException(Birthday.MESSAGE_CONSTRAINTS); + } + return new Birthday(trimmed); + } + /** * Parses a {@code String tag} into a {@code Tag}. * Leading and trailing whitespaces will be trimmed. diff --git a/src/main/java/seedu/address/model/person/Birthday.java b/src/main/java/seedu/address/model/person/Birthday.java new file mode 100644 index 00000000000..2c0375243ff --- /dev/null +++ b/src/main/java/seedu/address/model/person/Birthday.java @@ -0,0 +1,72 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; + +import java.time.DateTimeException; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * Represents a Person's dob. + */ +public class Birthday { + public static final String MESSAGE_CONSTRAINTS = + "Invalid date of birth. Please provide date of birth with format: YYYY-MM-DD"; + + public final String dob; + + /** + * Constructs a {@code Birthday}. + * + * @param dateStr A valid dob. + */ + public Birthday(String dateStr) { + requireNonNull(dateStr); + dateStr = dateStr.trim(); + try { + LocalDate.parse(dateStr); + dob = dateStr; + } catch (DateTimeException e) { + throw new IllegalArgumentException(MESSAGE_CONSTRAINTS); + } + } + + /** + * Returns true if a given string is a valid dob. + */ + public static boolean isValidDob(String test) { + String dateStr = test.trim(); + try { + LocalDate.parse(dateStr); + } catch (DateTimeException e) { + return false; + } + return true; + } + + @Override + public String toString() { + return LocalDate.parse(dob).format(DateTimeFormatter.ofPattern("d MMM yyyy")); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof Birthday)) { + return false; + } + + Birthday otherDate = (Birthday) other; + return dob.equals(otherDate.dob); + } + + @Override + public int hashCode() { + return dob.hashCode(); + } + +} diff --git a/src/main/java/seedu/address/model/person/Department.java b/src/main/java/seedu/address/model/person/Department.java new file mode 100644 index 00000000000..a68237299a7 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Department.java @@ -0,0 +1,59 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Person's department. + */ +public class Department { + + public static final String MESSAGE_CONSTRAINTS = "Departments should not be blank"; + + public final String department; + + /** + * Constructs a {@code Department}. + * + * @param dep A valid department. + */ + public Department(String dep) { + requireNonNull(dep); + dep = dep.trim(); + checkArgument(isValidDepartment(dep), MESSAGE_CONSTRAINTS); + department = dep; + } + + /** + * Returns true if a given string is a valid department. + */ + public static boolean isValidDepartment(String test) { + return !test.trim().equals(""); + } + + @Override + public String toString() { + return department; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof Department)) { + return false; + } + + Department otherDep = (Department) other; + return department.equals(otherDep.department); + } + + @Override + public int hashCode() { + return department.hashCode(); + } + +} diff --git a/src/main/java/seedu/address/model/person/Money.java b/src/main/java/seedu/address/model/person/Money.java new file mode 100644 index 00000000000..74e4ea30fb9 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Money.java @@ -0,0 +1,78 @@ +package seedu.address.model.person; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +/** + * Represents a Person's salary and claim budget. + */ +public class Money { + + public static final String MESSAGE_CONSTRAINTS = "Dollar amount should be a positive integer"; + + public final String amount; + + /** + * Constructs a {@code Money}. + * + * @param numStr A valid dollar amount. + */ + public Money(String numStr) { + requireNonNull(numStr); + try { + Integer num = Integer.valueOf(numStr); + checkArgument(num >= 0, MESSAGE_CONSTRAINTS); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(MESSAGE_CONSTRAINTS); + } + amount = numStr; + } + + /** + * Returns true if a given string is a valid dollar amount. + */ + public static boolean isValidMoney(String test) { + try { + Integer num = Integer.valueOf(test); + checkArgument(num >= 0, MESSAGE_CONSTRAINTS); + } catch (NumberFormatException e) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder rev = new StringBuilder(amount).reverse(); + String money = ""; + for (int i = 0; i < rev.length(); i++) { + if (i > 0 && i % 3 == 0) { + money += ","; + } + money += rev.charAt(i); + } + money += "$"; + return new StringBuilder(money).reverse().toString(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof Money)) { + return false; + } + + Money otherMoney = (Money) other; + return amount.equals(otherMoney.amount); + } + + @Override + public int hashCode() { + return amount.hashCode(); + } + +} diff --git a/src/main/java/seedu/address/model/person/Name.java b/src/main/java/seedu/address/model/person/Name.java index 173f15b9b00..2e201dbbad4 100644 --- a/src/main/java/seedu/address/model/person/Name.java +++ b/src/main/java/seedu/address/model/person/Name.java @@ -4,19 +4,11 @@ import static seedu.address.commons.util.AppUtil.checkArgument; /** - * Represents a Person's name in the address book. + * Represents a Person's name. * Guarantees: immutable; is valid as declared in {@link #isValidName(String)} */ public class Name { - - public static final String MESSAGE_CONSTRAINTS = - "Names should only contain alphanumeric characters and spaces, and it should not be blank"; - - /* - * The first character of the address must not be a whitespace, - * otherwise " " (a blank string) becomes a valid input. - */ - public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + public static final String MESSAGE_CONSTRAINTS = "Names should not be blank"; public final String fullName; @@ -27,6 +19,7 @@ public class Name { */ public Name(String name) { requireNonNull(name); + name = name.trim(); checkArgument(isValidName(name), MESSAGE_CONSTRAINTS); fullName = name; } @@ -35,10 +28,9 @@ public Name(String name) { * Returns true if a given string is a valid name. */ public static boolean isValidName(String test) { - return test.matches(VALIDATION_REGEX); + return !test.trim().equals(""); } - @Override public String toString() { return fullName; diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index abe8c46b535..790dd97b657 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -23,18 +23,26 @@ public class Person { // Data fields private final Address address; + private final Money salary; + private final Money claimBudget; + private final Department department; + private final Birthday dob; private final Set tags = new HashSet<>(); /** * Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Address address, Set tags) { - requireAllNonNull(name, phone, email, address, tags); + public Person(Name name, Phone phone, Email email, Address address, + Money salary, Money claimBudget, Department dep, Birthday dob) { + requireAllNonNull(name, phone, email, address, salary, claimBudget, dep, dob); this.name = name; this.phone = phone; this.email = email; this.address = address; - this.tags.addAll(tags); + this.salary = salary; + this.claimBudget = claimBudget; + this.department = dep; + this.dob = dob; } public Name getName() { @@ -53,6 +61,22 @@ public Address getAddress() { return address; } + public Money getSalary() { + return salary; + } + + public Money getClaimBudget() { + return claimBudget; + } + + public Department getDepartment() { + return department; + } + + public Birthday getDob() { + return dob; + } + /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. @@ -93,14 +117,13 @@ public boolean equals(Object other) { return name.equals(otherPerson.name) && phone.equals(otherPerson.phone) && email.equals(otherPerson.email) - && address.equals(otherPerson.address) - && tags.equals(otherPerson.tags); + && address.equals(otherPerson.address); } @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(name, phone, email, address, tags); + return Objects.hash(name, phone, email, address, salary, claimBudget, department, dob); } @Override @@ -110,7 +133,10 @@ public String toString() { .add("phone", phone) .add("email", email) .add("address", address) - .add("tags", tags) + .add("salary", salary) + .add("claimBudget", claimBudget) + .add("department", department) + .add("dob", dob) .toString(); } diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 1806da4facf..146027551a8 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -1,17 +1,15 @@ package seedu.address.model.util; -import java.util.Arrays; -import java.util.Set; -import java.util.stream.Collectors; - import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.person.Address; +import seedu.address.model.person.Birthday; +import seedu.address.model.person.Department; import seedu.address.model.person.Email; +import seedu.address.model.person.Money; import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; -import seedu.address.model.tag.Tag; /** * Contains utility methods for populating {@code AddressBook} with sample data. @@ -20,23 +18,23 @@ public class SampleDataUtil { public static Person[] getSamplePersons() { return new Person[] { new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), - new Address("Blk 30 Geylang Street 29, #06-40"), - getTagSet("friends")), + new Address("Blk 30 Geylang Street 29, #06-40"), new Money("10000"), new Money("4000"), + new Department("Engineering"), new Birthday("2000-01-01")), new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), - new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), - getTagSet("colleagues", "friends")), + new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), new Money("5000"), new Money("1000"), + new Department("HR"), new Birthday("1990-03-20")), new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), - new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), - getTagSet("neighbours")), + new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), new Money("7000"), new Money("1500"), + new Department("Sales"), new Birthday("1996-04-17")), new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), - new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), - getTagSet("family")), + new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), new Money("9000"), new Money("3600"), + new Department("Engineering"), new Birthday("1992-09-07")), new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), - new Address("Blk 47 Tampines Street 20, #17-35"), - getTagSet("classmates")), + new Address("Blk 47 Tampines Street 20, #17-35"), new Money("8200"), new Money("500"), + new Department("IT"), new Birthday("1994-12-05")), new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), - new Address("Blk 45 Aljunied Street 85, #11-31"), - getTagSet("colleagues")) + new Address("Blk 45 Aljunied Street 85, #11-31"), new Money("6500"), new Money("1200"), + new Department("Sales"), new Birthday("2001-07-31")) }; } @@ -47,14 +45,4 @@ public static ReadOnlyAddressBook getSampleAddressBook() { } return sampleAb; } - - /** - * Returns a tag set containing the list of strings given. - */ - public static Set getTagSet(String... strings) { - return Arrays.stream(strings) - .map(Tag::new) - .collect(Collectors.toSet()); - } - } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index bd1ca0f56c8..e7949b7d0ca 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -1,34 +1,33 @@ package seedu.address.storage; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.person.Address; +import seedu.address.model.person.Birthday; +import seedu.address.model.person.Department; import seedu.address.model.person.Email; +import seedu.address.model.person.Money; import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; -import seedu.address.model.tag.Tag; /** * Jackson-friendly version of {@link Person}. */ class JsonAdaptedPerson { - public static final String MISSING_FIELD_MESSAGE_FORMAT = "Person's %s field is missing!"; + public static final String MISSING_FIELD_MESSAGE_FORMAT = "Employee's %s field is missing!"; private final String name; private final String phone; private final String email; private final String address; - private final List tags = new ArrayList<>(); + private final String salary; + private final String claimBudget; + private final String department; + private final String dob; /** * Constructs a {@code JsonAdaptedPerson} with the given person details. @@ -36,14 +35,16 @@ class JsonAdaptedPerson { @JsonCreator public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, - @JsonProperty("tags") List tags) { + @JsonProperty("salary") String salary, @JsonProperty("claimBudget") String claimBudget, + @JsonProperty("department") String department, @JsonProperty("dob") String dob) { this.name = name; this.phone = phone; this.email = email; this.address = address; - if (tags != null) { - this.tags.addAll(tags); - } + this.salary = salary; + this.claimBudget = claimBudget; + this.department = department; + this.dob = dob; } /** @@ -54,9 +55,10 @@ public JsonAdaptedPerson(Person source) { phone = source.getPhone().value; email = source.getEmail().value; address = source.getAddress().value; - tags.addAll(source.getTags().stream() - .map(JsonAdaptedTag::new) - .collect(Collectors.toList())); + salary = source.getSalary().amount; + claimBudget = source.getClaimBudget().amount; + department = source.getDepartment().department; + dob = source.getDob().dob; } /** @@ -65,11 +67,6 @@ public JsonAdaptedPerson(Person source) { * @throws IllegalValueException if there were any data constraints violated in the adapted person. */ public Person toModelType() throws IllegalValueException { - final List personTags = new ArrayList<>(); - for (JsonAdaptedTag tag : tags) { - personTags.add(tag.toModelType()); - } - if (name == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); } @@ -102,8 +99,40 @@ public Person toModelType() throws IllegalValueException { } final Address modelAddress = new Address(address); - final Set modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags); + if (salary == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Money.class.getSimpleName())); + } + if (!Money.isValidMoney(salary)) { + throw new IllegalValueException(Money.MESSAGE_CONSTRAINTS); + } + final Money modelSalary = new Money(salary); + + if (claimBudget == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Money.class.getSimpleName())); + } + if (!Money.isValidMoney(claimBudget)) { + throw new IllegalValueException(Money.MESSAGE_CONSTRAINTS); + } + final Money modelClaimBudget = new Money(claimBudget); + + if (department == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Department.class.getSimpleName())); + } + if (!Department.isValidDepartment(department)) { + throw new IllegalValueException(Department.MESSAGE_CONSTRAINTS); + } + final Department modelDepartment = new Department(department); + + if (dob == null) { + throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Birthday.class.getSimpleName())); + } + if (!Birthday.isValidDob(dob)) { + throw new IllegalValueException(Birthday.MESSAGE_CONSTRAINTS); + } + final Birthday modelDob = new Birthday(dob); + + return new Person(modelName, modelPhone, modelEmail, modelAddress, modelSalary, + modelClaimBudget, modelDepartment, modelDob); } } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 094c42cda82..2e2ee338f9f 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -39,7 +39,13 @@ public class PersonCard extends UiPart { @FXML private Label email; @FXML - private FlowPane tags; + private Label salary; + @FXML + private Label claimBudget; + @FXML + private Label department; + @FXML + private Label dob; /** * Creates a {@code PersonCode} with the given {@code Person} and index to display. @@ -49,11 +55,12 @@ public PersonCard(Person person, int displayedIndex) { this.person = person; id.setText(displayedIndex + ". "); name.setText(person.getName().fullName); - phone.setText(person.getPhone().value); - address.setText(person.getAddress().value); - email.setText(person.getEmail().value); - person.getTags().stream() - .sorted(Comparator.comparing(tag -> tag.tagName)) - .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); + phone.setText("Phone: " + person.getPhone().value); + address.setText("Address: " + person.getAddress().value); + email.setText("Email: " + person.getEmail().value); + salary.setText("Salary: " + person.getSalary().toString()); + claimBudget.setText("Claim budget: " + person.getClaimBudget().toString()); + department.setText("Department: " + person.getDepartment().toString()); + dob.setText("DOB: " + person.getDob().toString()); } } diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index f5e812e25e6..8c3a537d753 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -31,6 +31,10 @@