Skip to content

Commit

Permalink
Merge branch 'master' into branch-delete-contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
CJ-Lee01 committed Oct 17, 2023
2 parents 70d7ca0 + 26c02bf commit 7fbe9a7
Show file tree
Hide file tree
Showing 31 changed files with 1,011 additions and 98 deletions.
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ public static String getErrorMessageForDuplicateFlags(Flag... duplicateFlags) {
public static String format(Contact contact) {
final StringBuilder builder = new StringBuilder();
builder.append(contact.getName())
.append("; Id: ")
.append(contact.getId())
.append("; Phone: ")
.append(contact.getPhone())
.append("; Email: ")
.append(contact.getEmail())
.append("; Url: ")
.append(contact.getUrl())
.append("; Address: ")
.append(contact.getAddress())
.append("; Tags: ");
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import static java.util.Objects.requireNonNull;
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_ID;
import static seedu.address.logic.parser.CliSyntax.FLAG_NAME;
import static seedu.address.logic.parser.CliSyntax.FLAG_PHONE;
import static seedu.address.logic.parser.CliSyntax.FLAG_TAG;

import java.util.logging.Logger;

import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
Expand All @@ -23,6 +27,7 @@ public class AddCommand extends Command {
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a contact to the address book. "
+ "Parameters: "
+ FLAG_NAME + " NAME "
+ FLAG_ID + " ID "
+ FLAG_PHONE + " PHONE "
+ FLAG_EMAIL + " EMAIL "
+ FLAG_ADDRESS + " ADDRESS "
Expand All @@ -38,6 +43,8 @@ public class AddCommand extends Command {
public static final String MESSAGE_SUCCESS = "New contact added: %1$s";
public static final String MESSAGE_DUPLICATE_CONTACT = "This contact already exists in the address book";

private static final Logger logger = LogsCenter.getLogger(AddCommand.class);

private final Contact toAdd;

/**
Expand All @@ -50,6 +57,8 @@ public AddCommand(Contact contact) {

@Override
public CommandResult execute(Model model) throws CommandException {
logger.fine(String.format("Adding contact: %s", 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);
}

}
26 changes: 25 additions & 1 deletion src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import seedu.address.model.person.Address;
import seedu.address.model.person.Contact;
import seedu.address.model.person.Email;
import seedu.address.model.person.Id;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Url;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -96,12 +98,14 @@ private static Contact createEditedContact(Contact contactToEdit, EditContactDes
assert contactToEdit != null;

Name updatedName = editContactDescriptor.getName().orElse(contactToEdit.getName());
Id updatedId = editContactDescriptor.getId().orElse(contactToEdit.getId());
Phone updatedPhone = editContactDescriptor.getPhone().orElse(contactToEdit.getPhone());
Email updatedEmail = editContactDescriptor.getEmail().orElse(contactToEdit.getEmail());
Url updatedUrl = editContactDescriptor.getUrl().orElse(contactToEdit.getUrl());
Address updatedAddress = editContactDescriptor.getAddress().orElse(contactToEdit.getAddress());
Set<Tag> updatedTags = editContactDescriptor.getTags().orElse(contactToEdit.getTags());

return new Contact(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags);
return new Contact(updatedName, updatedId, updatedPhone, updatedEmail, updatedUrl, updatedAddress, updatedTags);
}

@Override
Expand Down Expand Up @@ -134,8 +138,10 @@ public String toString() {
*/
public static class EditContactDescriptor {
private Name name;
private Id id;
private Phone phone;
private Email email;
private Url url;
private Address address;
private Set<Tag> tags;

Expand All @@ -147,8 +153,10 @@ public EditContactDescriptor() {}
*/
public EditContactDescriptor(EditContactDescriptor toCopy) {
setName(toCopy.name);
setId(toCopy.id);
setPhone(toCopy.phone);
setEmail(toCopy.email);
setUrl(toCopy.url);
setAddress(toCopy.address);
setTags(toCopy.tags);
}
Expand All @@ -168,6 +176,14 @@ public Optional<Name> getName() {
return Optional.ofNullable(name);
}

public Optional<Id> getId() {
return Optional.ofNullable(id);
}

public void setId(Id id) {
this.id = id;
}

public void setPhone(Phone phone) {
this.phone = phone;
}
Expand All @@ -184,6 +200,14 @@ public Optional<Email> getEmail() {
return Optional.ofNullable(email);
}

public Optional<Url> getUrl() {
return Optional.ofNullable(url);
}

public void setUrl(Url url) {
this.url = url;
}

public void setAddress(Address address) {
this.address = address;
}
Expand Down
83 changes: 78 additions & 5 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,33 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
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_ID;
import static seedu.address.logic.parser.CliSyntax.FLAG_NAME;
import static seedu.address.logic.parser.CliSyntax.FLAG_ORGANIZATION;
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.NoSuchElementException;
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.Id;
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.person.Url;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -31,25 +44,85 @@ 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_ID, FLAG_STATUS, FLAG_POSITION,
FLAG_ORGANIZATION, 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));
}

argMultimap.verifyNoDuplicateFlagsFor(FLAG_NAME, FLAG_PHONE, FLAG_EMAIL, FLAG_ADDRESS);
argMultimap.verifyNoDuplicateFlagsFor(FLAG_NAME, FLAG_ID, FLAG_PHONE, FLAG_EMAIL, FLAG_URL, FLAG_ADDRESS);

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

// Deprecated contact format. Will be removed in future versions.
Name name = ParserUtil.parseName(argMultimap.getValue(FLAG_NAME).get());
Id id;
try {
id = ParserUtil.parseId(argMultimap.getValue(FLAG_ID).get());
} catch (NoSuchElementException e) {
id = new Id();
}
Phone phone = ParserUtil.parsePhone(argMultimap.getValue(FLAG_PHONE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(FLAG_EMAIL).get());
Url url;
try {
url = ParserUtil.parseUrl(argMultimap.getValue(FLAG_URL).get());
} catch (NoSuchElementException e) {
url = new Url();
}
Address address = ParserUtil.parseAddress(argMultimap.getValue(FLAG_ADDRESS).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(FLAG_TAG));

Contact contact = new Contact(name, phone, email, address, tagList);
Contact contact = new Contact(name, id, phone, email, url, address, tagList);

return new AddCommand(contact);
}

private Organization parseAsOrganization(ArgumentMultimap argMultimap) throws ParseException {
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());
Id id;
try {
id = ParserUtil.parseId(argMultimap.getValue(FLAG_ID).get());
} catch (NoSuchElementException e) {
id = new Id();
}

Url url;
try {
url = ParserUtil.parseUrl(argMultimap.getValue(FLAG_URL).get());
} catch (NoSuchElementException e) {
url = new Url();
}

Position position;
try {
position = ParserUtil.parsePosition(argMultimap.getValue(FLAG_POSITION).get());
} catch (NoSuchElementException e) {
position = new Position();
}

Status status;
try {
status = ParserUtil.parseStatus(argMultimap.getValue(FLAG_STATUS).get());
} catch (NoSuchElementException e) {
status = new Status();
}

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

/**
* Returns true if none of the flags contains empty {@code Optional} values in the given
* {@code ArgumentMultimap}.
Expand Down
8 changes: 8 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,13 @@ 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_ORGANIZATION = 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");
public static final Flag FLAG_ID = new Flag("id");



}
64 changes: 64 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
import seedu.address.model.person.Address;
import seedu.address.model.person.ContactId;
import seedu.address.model.person.Email;
import seedu.address.model.person.Id;
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.person.Url;
import seedu.address.model.tag.Tag;

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

/**
* Parses a {@code String id} into a {@code Status}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code id} is invalid.
*/
public static Id parseId(String id) throws ParseException {
requireNonNull(id);
String trimmedId = id.trim();
if (!Id.isValidId(id)) {
throw new ParseException(Id.MESSAGE_CONSTRAINTS);
}
return new Id(trimmedId);
}

/**
* Parses a {@code String status} 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 (!Status.isValidStatus(status)) {
throw new ParseException(Name.MESSAGE_CONSTRAINTS);
}
return new Status(trimmedStatus);
}

/**
* Parses a {@code String position} into a {@code Position}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code position} 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 All @@ -66,6 +115,21 @@ public static Phone parsePhone(String phone) throws ParseException {
return new Phone(trimmedPhone);
}

/**
* Parses a {@code String url} into an {@code Url}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code url} is invalid.
*/
public static Url parseUrl(String url) throws ParseException {
requireNonNull(url);
String trimmedUrl = url.trim();
if (!Url.isValidUrl(trimmedUrl)) {
throw new ParseException(Url.MESSAGE_CONSTRAINTS);
}
return new Url(trimmedUrl);
}

/**
* Parses a {@code String address} into an {@code Address}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
Loading

0 comments on commit 7fbe9a7

Please sign in to comment.