Skip to content

Commit

Permalink
Merge branch 'quangtdn-ProfilePage'
Browse files Browse the repository at this point in the history
Fix test case bug buy erik, set this as v1.3
  • Loading branch information
erik0704 committed Oct 25, 2017
2 parents a6e8238 + 2402491 commit a587125
Show file tree
Hide file tree
Showing 23 changed files with 287 additions and 120 deletions.
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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_PROFILEPAGE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import seedu.address.logic.commands.exceptions.CommandException;
Expand All @@ -27,13 +28,15 @@ public class AddCommand extends UndoableCommand {
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_BIRTHDAY + "BIRTHDAY "
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_PROFILEPAGE + "PROFILE PAGE "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_BIRTHDAY + "1995/11/03 "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_PROFILEPAGE + "www.facebook.com "
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

Expand Down
25 changes: 17 additions & 8 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_BIRTHDAY;
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.*;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.List;
Expand All @@ -18,6 +13,7 @@
import seedu.address.commons.util.CollectionUtil;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.person.Address;
import seedu.address.model.person.ProfilePage;
import seedu.address.model.person.Birthday;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand All @@ -44,6 +40,7 @@ public class EditCommand extends UndoableCommand {
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_BIRTHDAY + "BIRTHDAY]"
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_PROFILEPAGE + "PROFILE PAGE] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
Expand Down Expand Up @@ -103,9 +100,10 @@ private static Person createEditedPerson(ReadOnlyPerson personToEdit,
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Birthday updateBirthday = editPersonDescriptor.getBirthday().orElse(personToEdit.getBirthday());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
ProfilePage updatedProfile= editPersonDescriptor.getProfilePage().orElse(personToEdit.getProfilePage());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());

return new Person(updatedName, updatedPhone, updatedEmail, updateBirthday, updatedAddress, updatedTags);
return new Person(updatedName, updatedPhone, updatedEmail, updateBirthday, updatedAddress, updatedProfile, updatedTags);
}

@Override
Expand Down Expand Up @@ -136,6 +134,7 @@ public static class EditPersonDescriptor {
private Email email;
private Birthday birthday;
private Address address;
private ProfilePage profile;
private Set<Tag> tags;

public EditPersonDescriptor() {}
Expand All @@ -146,6 +145,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
this.email = toCopy.email;
this.birthday = toCopy.birthday;
this.address = toCopy.address;
this.profile= toCopy.profile;
this.tags = toCopy.tags;
}

Expand All @@ -154,7 +154,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(this.name, this.phone, this.email,
this.birthday, this.address, this.tags);
this.birthday, this.address, this.profile, this.tags);
}

public void setName(Name name) {
Expand Down Expand Up @@ -197,6 +197,14 @@ public Optional<Address> getAddress() {
return Optional.ofNullable(address);
}

public void setProfilePage(ProfilePage profile) {
this.profile = profile;
}

public Optional<ProfilePage> getProfilePage() {
return Optional.ofNullable(profile);
}

public void setTags(Set<Tag> tags) {
this.tags = tags;
}
Expand Down Expand Up @@ -225,6 +233,7 @@ && getPhone().equals(e.getPhone())
&& getEmail().equals(e.getEmail())
&& getBirthday().equals(e.getBirthday())
&& getAddress().equals(e.getAddress())
&& getProfilePage().equals(e.getProfilePage())
&& getTags().equals(e.getTags());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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_PROFILEPAGE;

import java.util.Set;
import java.util.stream.Stream;
Expand All @@ -15,6 +16,7 @@
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.person.Address;
import seedu.address.model.person.ProfilePage;
import seedu.address.model.person.Birthday;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand All @@ -36,10 +38,10 @@ public class AddCommandParser implements Parser<AddCommand> {
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_BIRTHDAY,
PREFIX_ADDRESS, PREFIX_TAG);
PREFIX_ADDRESS, PREFIX_PROFILEPAGE, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME,
PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_BIRTHDAY)) {
PREFIX_ADDRESS, PREFIX_PROFILEPAGE, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_BIRTHDAY)) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

Expand All @@ -49,9 +51,10 @@ public AddCommand parse(String args) throws ParseException {
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL)).get();
Birthday birthday = ParserUtil.parseBirthday(argMultimap.getValue(PREFIX_BIRTHDAY)).get();
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS)).get();
ProfilePage profile = ParserUtil.parseProfilePage(argMultimap.getValue(PREFIX_PROFILEPAGE)).get();
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

ReadOnlyPerson person = new Person(name, phone, email, birthday, address, tagList);
ReadOnlyPerson person = new Person(name, phone, email, birthday, address, profile, tagList);

return new AddCommand(person);
} catch (IllegalValueException ive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.FindTagCommand;
import seedu.address.logic.commands.FindPhoneCommand;
import seedu.address.logic.commands.DeleteListCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.HistoryCommand;
import seedu.address.logic.commands.ListCommand;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class CliSyntax {
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_BIRTHDAY = new Prefix("b/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_PROFILEPAGE = new Prefix("pr/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_DATE = new Prefix("d/");
public static final Prefix PREFIX_DESCRIPTION = new Prefix("de/");
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/seedu/address/logic/parser/EditCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_BIRTHDAY;
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.*;

import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -35,7 +30,7 @@ public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_BIRTHDAY, PREFIX_ADDRESS, PREFIX_TAG);
PREFIX_BIRTHDAY, PREFIX_ADDRESS, PREFIX_PROFILEPAGE, PREFIX_TAG);

Index index;

Expand All @@ -53,6 +48,7 @@ public EditCommand parse(String args) throws ParseException {
ParserUtil.parseBirthday(
argMultimap.getValue(PREFIX_BIRTHDAY)).ifPresent(editPersonDescriptor::setBirthday);
ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS)).ifPresent(editPersonDescriptor::setAddress);
ParserUtil.parseProfilePage(argMultimap.getValue(PREFIX_PROFILEPAGE)).ifPresent(editPersonDescriptor::setProfilePage);
parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags);
} catch (IllegalValueException ive) {
throw new ParseException(ive.getMessage(), ive);
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.commons.util.StringUtil;
import seedu.address.model.event.Dates;
import seedu.address.model.person.Address;
import seedu.address.model.person.Birthday;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.person.*;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -72,6 +68,15 @@ public static Optional<Address> parseAddress(Optional<String> address) throws Il
return address.isPresent() ? Optional.of(new Address(address.get())) : Optional.empty();
}

/**
* Parses a {@code Optional<String> profile} into an {@code Optional<ProfilePage>} if {@code profile} is present.
* See header comment of this class regarding the use of {@code Optional} parameters.
*/
public static Optional<ProfilePage> parseProfilePage(Optional<String> profile) throws IllegalValueException {
requireNonNull(profile);
return profile.isPresent() ? Optional.of(new ProfilePage(profile.get())) : Optional.empty();
}

/**
* Parses a {@code Optional<String> email} into an {@code Optional<Email>} if {@code email} is present.
* See header comment of this class regarding the use of {@code Optional} parameters.
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ public class Person implements ReadOnlyPerson {
private ObjectProperty<Email> email;
private ObjectProperty<Birthday> birthday;
private ObjectProperty<Address> address;
private ObjectProperty<ProfilePage> profile;

private ObjectProperty<UniqueTagList> tags;

/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Birthday birthday, Address address, Set<Tag> tags) {
public Person(Name name, Phone phone, Email email, Birthday birthday, Address address, ProfilePage profile, Set<Tag> tags) {
requireAllNonNull(name, phone, email, birthday, address, tags);
this.name = new SimpleObjectProperty<>(name);
this.phone = new SimpleObjectProperty<>(phone);
this.email = new SimpleObjectProperty<>(email);
this.birthday = new SimpleObjectProperty<>(birthday);
this.address = new SimpleObjectProperty<>(address);
this.profile = new SimpleObjectProperty<>(profile);
// protect internal tags from changes in the arg list
this.tags = new SimpleObjectProperty<>(new UniqueTagList(tags));
}
Expand All @@ -45,7 +47,7 @@ public Person(Name name, Phone phone, Email email, Birthday birthday, Address ad
*/
public Person(ReadOnlyPerson source) {
this(source.getName(), source.getPhone(), source.getEmail(), source.getBirthday(), source.getAddress(),
source.getTags());
source.getProfilePage(), source.getTags());
}

public void setName(Name name) {
Expand Down Expand Up @@ -118,10 +120,20 @@ public Address getAddress() {
return address.get();
}


public void setProfilePage(ProfilePage profile) { this.profile.set(requireNonNull(profile));}

@Override
public ObjectProperty<ProfilePage> profilepageProperty() { return profile; }

@Override
public ProfilePage getProfilePage() {return profile.get(); }

/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
*/

@Override
public Set<Tag> getTags() {
return Collections.unmodifiableSet(tags.get().toSet());
Expand All @@ -148,7 +160,7 @@ public boolean equals(Object other) {
@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(name, phone, email, birthday, address, tags);
return Objects.hash(name, phone, email, birthday, address, profile, tags);
}

@Override
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/seedu/address/model/person/ProfilePage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.exceptions.IllegalValueException;

/**
* Represents a Person's birthday in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidProfilePage(String)}
*/
public class ProfilePage {

public static final String MESSAGE_PROFILEPAGE_CONSTRAINTS =
"Person Profile page should be a valid URL pointing to that person's profile";
public static final String PROFILEPAGE_VALIDATION_REGEX = "^(https?:\\/\\/)?(www\\.)?([\\w]+\\.)+[‌​\\w]{2,63}\\/?$";

public final String value;

/**
* Validates given birthday.
*
* @throws IllegalValueException if given birthday address string is invalid.
*/
public ProfilePage(String profile) throws IllegalValueException {
requireNonNull(profile);
if (!isValidProfilePage(profile)) {
throw new IllegalValueException(MESSAGE_PROFILEPAGE_CONSTRAINTS);
}
this.value = profile;
}

/**
* Returns if a given string is a valid person birthday.
*/
public static boolean isValidProfilePage(String test) {
return test.matches(PROFILEPAGE_VALIDATION_REGEX);
}

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

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof ProfilePage // instanceof handles nulls
&& this.value.equals(((ProfilePage) other).value)); // state check
}

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

}
7 changes: 6 additions & 1 deletion src/main/java/seedu/address/model/person/ReadOnlyPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public interface ReadOnlyPerson {
Birthday getBirthday();
ObjectProperty<Address> addressProperty();
Address getAddress();
ObjectProperty<ProfilePage> profilepageProperty();
ProfilePage getProfilePage();
ObjectProperty<UniqueTagList> tagProperty();
Set<Tag> getTags();

Expand All @@ -35,7 +37,8 @@ default boolean isSameStateAs(ReadOnlyPerson other) {
&& other.getName().equals(this.getName()) // state checks here onwards
&& other.getEmail().equals(this.getEmail())
&& other.getBirthday().equals(this.getBirthday())
&& other.getAddress().equals(this.getAddress()));
&& other.getAddress().equals(this.getAddress()))
&& other.getProfilePage().equals(this.getProfilePage());
}

/**
Expand All @@ -52,6 +55,8 @@ default String getAsText() {
.append(getBirthday())
.append(" Address: ")
.append(getAddress())
.append(" Profile Page: ")
.append(getProfilePage())
.append(" Tags: ");
getTags().forEach(builder::append);
return builder.toString();
Expand Down
Loading

0 comments on commit a587125

Please sign in to comment.