Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Organization class #34

Merged
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public AddCommand(Contact contact) {

@Override
public CommandResult execute(Model model) throws CommandException {
System.out.println("\n" + toAdd);

requireNonNull(model);

if (model.hasContact(toAdd)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package seedu.address.logic.commands;

import seedu.address.model.person.Contact;

/**
* Adds an organisation to the address book.
*/
public class AddOrganizationCommand extends AddCommand {

public AddOrganizationCommand(Contact contact) {
super(contact);
}

}
48 changes: 45 additions & 3 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@
import static seedu.address.logic.parser.CliSyntax.FLAG_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.FLAG_EMAIL;
import static seedu.address.logic.parser.CliSyntax.FLAG_NAME;
import static seedu.address.logic.parser.CliSyntax.FLAG_ORG;
import static seedu.address.logic.parser.CliSyntax.FLAG_PHONE;
import static seedu.address.logic.parser.CliSyntax.FLAG_POSITION;
import static seedu.address.logic.parser.CliSyntax.FLAG_RECRUITER;
import static seedu.address.logic.parser.CliSyntax.FLAG_STATUS;
import static seedu.address.logic.parser.CliSyntax.FLAG_TAG;
import static seedu.address.logic.parser.CliSyntax.FLAG_URL;

import java.util.Set;
import java.util.stream.Stream;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.AddOrganizationCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.Contact;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Organization;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Position;
import seedu.address.model.person.Status;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -31,13 +40,23 @@ public class AddCommandParser implements Parser<AddCommand> {
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, FLAG_NAME, FLAG_PHONE, FLAG_EMAIL, FLAG_ADDRESS, FLAG_TAG);
ArgumentTokenizer.tokenize(args,
FLAG_NAME, FLAG_PHONE, FLAG_EMAIL,
FLAG_ADDRESS, FLAG_TAG, FLAG_URL,
FLAG_STATUS, FLAG_POSITION,
FLAG_ORG, FLAG_RECRUITER);

if (!areFlagsPresent(argMultimap, FLAG_NAME, FLAG_ADDRESS, FLAG_PHONE, FLAG_EMAIL)
|| !argMultimap.getPreamble().isEmpty()) {
if (!areFlagsPresent(argMultimap, FLAG_NAME, FLAG_PHONE, FLAG_EMAIL, FLAG_ADDRESS)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

if (areFlagsPresent(argMultimap, FLAG_ORG)) {
Organization organization = parseAsOrganization(argMultimap);
return new AddOrganizationCommand(organization);
}

// Deprecated contact format. Will be removed in future versions.
argMultimap.verifyNoDuplicateFlagsFor(FLAG_NAME, FLAG_PHONE, FLAG_EMAIL, FLAG_ADDRESS);
Name name = ParserUtil.parseName(argMultimap.getValue(FLAG_NAME).get());
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(FLAG_PHONE).get());
Expand All @@ -50,6 +69,29 @@ public AddCommand parse(String args) throws ParseException {
return new AddCommand(contact);
}

private Organization parseAsOrganization(ArgumentMultimap argMultimap) throws ParseException {
argMultimap.verifyNoDuplicateFlagsFor(FLAG_NAME, FLAG_PHONE, FLAG_EMAIL, FLAG_ADDRESS);
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(FLAG_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(FLAG_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(FLAG_ADDRESS).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(FLAG_TAG));
Name name = ParserUtil.parseName(argMultimap.getValue(FLAG_NAME).get());
Status status;
Position position;
try {
position = ParserUtil.parsePosition(argMultimap.getValue(FLAG_POSITION).get());
} catch (Exception e) {
position = new Position();
}
try {
status = ParserUtil.parseStatus(argMultimap.getValue(FLAG_STATUS).get());
} catch (Exception e) {
status = new Status();
}

return new Organization(name, phone, email, address, tagList, status, position);
}

/**
* Returns true if none of the flags contains empty {@code Optional} values in the given
* {@code ArgumentMultimap}.
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@ public class CliSyntax {
public static final Flag FLAG_EMAIL = new Flag("email");
public static final Flag FLAG_ADDRESS = new Flag("addr");
public static final Flag FLAG_TAG = new Flag("tag");
public static final Flag FLAG_ORG = new Flag("org");
public static final Flag FLAG_RECRUITER = new Flag("rec");
public static final Flag FLAG_URL = new Flag("url");
public static final Flag FLAG_STATUS = new Flag("stat");
public static final Flag FLAG_POSITION = new Flag("pos");



}
34 changes: 34 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Position;
import seedu.address.model.person.Status;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -50,6 +52,38 @@ public static Name parseName(String name) throws ParseException {
return new Name(trimmedName);
}

/**
* Parses a {@code String name} into a {@code Status}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code status} is invalid.
*/
public static Status parseStatus(String status) throws ParseException {
requireNonNull(status);
String trimmedStatus = status.trim();
if (!Name.isValidName(status)) {
throw new ParseException(Name.MESSAGE_CONSTRAINTS);
}
return new Status(trimmedStatus);
}



/**
* Parses a {@code String name} into a {@code Position}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code status} is invalid.
*/
public static Position parsePosition(String position) throws ParseException {
requireNonNull(position);
String trimmedPosition = position.trim();
if (!Name.isValidName(position)) {
throw new ParseException(Name.MESSAGE_CONSTRAINTS);
}
return new Position(trimmedPosition);
}

/**
* Parses a {@code String phone} into a {@code Phone}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/model/person/Contact.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public Contact(Name name, Phone phone, Email email, Address address, Set<Tag> ta
this.tags.addAll(tags);
}

public Type getType() {
// TODO: This should be an abstract method.
return Type.UNKNOWN;
}

public Name getName() {
return name;
}
Expand Down Expand Up @@ -74,6 +79,8 @@ public boolean isSameContact(Contact otherContact) {
&& otherContact.getName().equals(getName());
}



/**
* Returns true if both contacts have the same identity and data fields.
* This defines a stronger notion of equality between two contacts.
Expand Down
109 changes: 109 additions & 0 deletions src/main/java/seedu/address/model/person/Organization.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package seedu.address.model.person;

import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.util.Set;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.model.tag.Tag;

/**
* Represents an Organisation in the address book.
* Guarantees: details are present and not null, field values are validated, immutable.
*/
public class Organization extends Contact {

private final Status status;
private final Position position;
//private final Url url;

// Data fields
//private final Set<Recruiter> tags = new HashSet<>();

/**
* Every field must be present and not null.
*/
public Organization(Name name, Phone phone, Email email, Address address,
Set<Tag> tags, Status status, Position position) {
super(name, phone, email, address, tags);
requireAllNonNull(status, position);
this.status = status;
this.position = position;
}

@Override
public Type getType() {
return Type.ORGANIZATION;
}

public Status getStatus() {
return status;
}

public Position getPosition() {
return position;
}

// public Address getUrl() {
// return url;
// }

// public Set<Recruiter> getTags() {
// return Collections.unmodifiableSet(recruiters);
// }

/**
* Returns true if both contacts have the same name.
* This defines a weaker notion of equality between two contacts.
*/
public boolean isSameOrganization(Organization otherOrganization) {
if (otherOrganization == this) {
return true;
}

return otherOrganization != null
&& otherOrganization.getName().equals(getName());
}

wxwern marked this conversation as resolved.
Show resolved Hide resolved
/**
* Returns true if both contacts have the same identity and data fields.
* This defines a stronger notion of equality between two contacts.
*/
// @Override
// public boolean equals(Object other) {
// if (other == this) {
// return true;
// }
//
// // instanceof handles nulls
// if (!(other instanceof Contact)) {
// return false;
// }
//
// Contact otherContact = (Contact) other;
// return name.equals(otherContact.name)
// && phone.equals(otherContact.phone)
// && email.equals(otherContact.email)
// && address.equals(otherContact.address)
// && tags.equals(otherContact.tags);
// }

// @Override
// public int hashCode() {
// // use this method for custom fields hashing instead of implementing your own
// return Objects.hash(name, phone, email, address, tags);
// }
wxwern marked this conversation as resolved.
Show resolved Hide resolved

@Override
public String toString() {
return new ToStringBuilder(this)
.add("name", super.getName())
.add("phone", super.getPhone())
.add("email", super.getEmail())
.add("address", super.getAddress())
.add("tags", super.getTags())
.add("status", status)
.toString();
}

}
72 changes: 72 additions & 0 deletions src/main/java/seedu/address/model/person/Position.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents an Organisation's position (that the user is applying to) in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidPosition(String)}
*/
public class Position {
public static final String MESSAGE_CONSTRAINTS =
"Positions should only contain alphanumeric characters and spaces";

/*
* 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} ]*";

public final String jobPosition;

/**
* Constructs a {@code Position}.
*
* @param position A valid position.
*/
public Position(String position) {
requireNonNull(position);
checkArgument(isValidPosition(position), MESSAGE_CONSTRAINTS);
jobPosition = position;
}

/**
* Constructs an empty {@code Position}.
*/
public Position() {
jobPosition = "";
}

/**
* Returns true if a given string is a valid name.
*/
public static boolean isValidPosition(String test) {
return test.matches(VALIDATION_REGEX);
}


@Override
public String toString() {
return jobPosition;
}

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

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

Position otherPosition = (Position) other;
return jobPosition.equals(otherPosition.jobPosition);
}

@Override
public int hashCode() {
return jobPosition.hashCode();
}
}
Loading