Skip to content

Commit

Permalink
Merge branch 'master' into update-add-UG
Browse files Browse the repository at this point in the history
  • Loading branch information
wxwern authored Oct 19, 2023
2 parents 204bff1 + 942eaac commit 64020d3
Show file tree
Hide file tree
Showing 13 changed files with 336 additions and 32 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.Set;

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;
Expand Down Expand Up @@ -63,7 +62,7 @@ public AddCommand parse(String args) throws ParseException {

if (argMultimap.hasFlag(FLAG_ORGANIZATION)) {
Organization organization = parseAsOrganization(argMultimap);
return new AddOrganizationCommand(organization);
return new AddCommand(organization);
} else if (argMultimap.hasFlag(FLAG_RECRUITER)) {
Recruiter recruiter = parseAsRecruiter(argMultimap);
return new AddCommand(recruiter);
Expand Down Expand Up @@ -136,7 +135,8 @@ private Organization parseAsOrganization(ArgumentMultimap argMultimap) throws Pa
Status status = ParserUtil.parseOptionally(
argMultimap.getValue(FLAG_STATUS), ParserUtil::parseStatus);
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(FLAG_TAG));
Set<Id> ridList = Set.of(); // TODO: This should be dynamically determined from oid in Recruiter.

return new Organization(name, id, phone, email, url, address, tagList, status, position);
return new Organization(name, id, phone, email, url, address, tagList, status, position, ridList);
}
}
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public class CliSyntax {
public static final Flag FLAG_ID = new Flag("id");
public static final Flag FLAG_RECURSIVE = new Flag("recursive");
public static final Flag FLAG_ORGANIZATION_ID = new Flag("oid");
public static final Flag FLAG_RECRUITER_ID = new Flag("rid");


}
13 changes: 13 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
return tagSet;
}

/**
* Parses {@code Collection<String> ids} into a {@code Set<Tag>}.
*/
public static Set<Id> parseIds(Collection<String> ids) throws ParseException {
requireNonNull(ids);
final Set<Id> idSet = new HashSet<>();
for (String idName : ids) {
idSet.add(parseId(idName));
}
return idSet;
}


/**
* References a function that parses a string into an expected output within the {@link ParserUtil} utility class.
* @param <R> The return result.
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/seedu/address/model/person/Organization.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.model.person;

import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
Expand All @@ -18,18 +20,23 @@ public class Organization extends Contact {
private final Optional<Status> status;
private final Optional<Position> position;

private final Set<Id> rids = new HashSet<>();


/**
* Name and id fields must be non-null.
* Tags must be non-null but can be empty as well.
* The other fields can be null.
*/
public Organization(
Name name, Id id, Phone phone, Email email, Url url,
Address address, Set<Tag> tags, Status status, Position position
Address address, Set<Tag> tags, Status status, Position position,
Set<Id> rids
) {
super(name, id, phone, email, url, address, tags);
this.status = Optional.ofNullable(status);
this.position = Optional.ofNullable(position);
this.rids.addAll(rids);
}

@Override
Expand All @@ -45,6 +52,13 @@ public Optional<Position> getPosition() {
return position;
}

/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
*/
public Set<Id> getRecruiterIds() {
return Collections.unmodifiableSet(rids);
}
@Override
public boolean equals(Object other) {
if (other == this) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,13 @@ public static Set<Tag> getTagSet(String... strings) {
.collect(Collectors.toSet());
}

/**
* Returns a id set containing the list of strings given.
*/
public static Set<Id> getIdSet(String... strings) {
return Arrays.stream(strings)
.map(Id::new)
.collect(Collectors.toSet());
}

}
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/storage/JsonAdaptedContact.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class JsonAdaptedContact {
private String oid;
private final List<JsonAdaptedTag> tags = new ArrayList<>();


/**
* Constructs a {@code JsonAdaptedContact} with the given contact details.
*/
Expand Down Expand Up @@ -158,6 +159,8 @@ public Contact toModelType() throws IllegalValueException {

switch (modelType) {
case ORGANIZATION: {
final Set<Id> modelRids = new HashSet<>();

if (status != null && !Status.isValidStatus(status)) {
throw new IllegalValueException(Status.MESSAGE_CONSTRAINTS);
}
Expand All @@ -170,7 +173,7 @@ public Contact toModelType() throws IllegalValueException {

return new Organization(
modelName, modelId, modelPhone, modelEmail, modelUrl, modelAddress,
modelTags, modelStatus, modelPosition
modelTags, modelStatus, modelPosition, modelRids
);
}
case RECRUITER: {
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/seedu/address/storage/JsonAdaptedId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package seedu.address.storage;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.person.Id;

/**
* Jackson-friendly version of {@link Id}.
*/
class JsonAdaptedId {

private final String idName;

/**
* Constructs a {@code JsonAdaptedId} with the given {@code idName}.
*/
@JsonCreator
public JsonAdaptedId(String idName) {
this.idName = idName;
}

/**
* Converts a given {@code Id} into this class for Jackson use.
*/
public JsonAdaptedId(Id source) {
idName = source.value;
}

@JsonValue
public String getIdName() {
return idName;
}

/**
* Converts this Jackson-friendly adapted tag object into the model's {@code Id} object.
*
* @throws IllegalValueException if there were any data constraints violated in the adapted tag.
*/
public Id toModelType() throws IllegalValueException {
if (!Id.isValidId(idName)) {
throw new IllegalValueException(Id.MESSAGE_CONSTRAINTS);
}
return new Id(idName);
}

}

106 changes: 106 additions & 0 deletions src/test/java/seedu/address/model/person/OrganizationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package seedu.address.model.person;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalContacts.ALICE;
import static seedu.address.testutil.TypicalContacts.BOB;

import org.junit.jupiter.api.Test;

import seedu.address.testutil.ContactBuilder;

public class OrganizationTest {

@Test
public void asObservableList_modifyList_throwsUnsupportedOperationException() {
Contact contact = new ContactBuilder().build();
assertThrows(UnsupportedOperationException.class, () -> contact.getTags().remove(0));
}

@Test
public void isSameContact() {
// same object -> returns true
assertTrue(ALICE.isSameContact(ALICE));

// null -> returns false
assertFalse(ALICE.isSameContact(null));

// same name, all other attributes different -> returns true
Contact editedAlice = new ContactBuilder(ALICE).withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB)
.withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND).build();
assertTrue(ALICE.isSameContact(editedAlice));

// different name, all other attributes same -> returns false
editedAlice = new ContactBuilder(ALICE).withName(VALID_NAME_BOB).build();
assertFalse(ALICE.isSameContact(editedAlice));

// name differs in case, all other attributes same -> returns false
Contact editedBob = new ContactBuilder(BOB).withName(VALID_NAME_BOB.toLowerCase()).build();
assertFalse(BOB.isSameContact(editedBob));

// name has trailing spaces, all other attributes same -> returns false
String nameWithTrailingSpaces = VALID_NAME_BOB + " ";
editedBob = new ContactBuilder(BOB).withName(nameWithTrailingSpaces).build();
assertFalse(BOB.isSameContact(editedBob));
}

@Test
public void equals() {
// same values -> returns true
Contact aliceCopy = new ContactBuilder(ALICE).build();
assertTrue(ALICE.equals(aliceCopy));

// same object -> returns true
assertTrue(ALICE.equals(ALICE));

// null -> returns false
assertFalse(ALICE.equals(null));

// different type -> returns false
assertFalse(ALICE.equals(5));

// different contact -> returns false
assertFalse(ALICE.equals(BOB));

// different name -> returns false
Contact editedAlice = new ContactBuilder(ALICE).withName(VALID_NAME_BOB).build();
assertFalse(ALICE.equals(editedAlice));

// different phone -> returns false
editedAlice = new ContactBuilder(ALICE).withPhone(VALID_PHONE_BOB).build();
assertFalse(ALICE.equals(editedAlice));

// different email -> returns false
editedAlice = new ContactBuilder(ALICE).withEmail(VALID_EMAIL_BOB).build();
assertFalse(ALICE.equals(editedAlice));

// different address -> returns false
editedAlice = new ContactBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).build();
assertFalse(ALICE.equals(editedAlice));

// different tags -> returns false
editedAlice = new ContactBuilder(ALICE).withTags(VALID_TAG_HUSBAND).build();
assertFalse(ALICE.equals(editedAlice));
}

@Test
public void toStringMethod() {
String expected = Contact.class.getCanonicalName()
+ "{name=" + ALICE.getName()
+ ", type=" + ALICE.getType()
+ ", id=" + ALICE.getId()
+ ", phone=" + ALICE.getPhone()
+ ", email=" + ALICE.getEmail()
+ ", url=" + ALICE.getUrl()
+ ", address=" + ALICE.getAddress()
+ ", tags=" + ALICE.getTags() + "}";
assertEquals(expected, ALICE.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static seedu.address.storage.JsonAdaptedContact.MISSING_FIELD_MESSAGE_FORMAT;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalContacts.BENSON;
import static seedu.address.testutil.TypicalContacts.JESUS;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -41,11 +42,15 @@ public class JsonAdaptedContactTest {
private static final String VALID_URL = BENSON.getUrl().get().value;
private static final String VALID_ADDRESS = BENSON.getAddress().get().value;
private static final String VALID_OID = "78a36caf-6d42-4fd2-a017-7f6a92fa3155";

private static final List<JsonAdaptedTag> VALID_TAGS = BENSON.getTags().stream()
.map(JsonAdaptedTag::new)
.collect(Collectors.toList());


private static final List<JsonAdaptedId> VALID_RIDS = JESUS.getRecruiterIds().stream()
.map(JsonAdaptedId::new)
.collect(Collectors.toList());

@Test
public void toModelType_validContactDetails_returnsContact() throws Exception {
JsonAdaptedContact person = new JsonAdaptedContact(BENSON);
Expand Down
12 changes: 1 addition & 11 deletions src/test/java/seedu/address/testutil/ContactBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import seedu.address.model.person.Id;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Status;
import seedu.address.model.person.Url;
import seedu.address.model.tag.Tag;
import seedu.address.model.util.SampleDataUtil;
Expand All @@ -25,15 +24,13 @@ public class ContactBuilder {
public static final String DEFAULT_EMAIL = "amy@gmail.com";
public static final String DEFAULT_URL = "www.google.com";
public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111";
public static final String DEFAULT_STATUS = "Applied";

private Name name;
private Id id;
private Phone phone;
private Email email;
private Url url;
private Address address;
private Status status;
private Set<Tag> tags;

/**
Expand All @@ -46,7 +43,6 @@ public ContactBuilder() {
email = new Email(DEFAULT_EMAIL);
url = new Url(DEFAULT_URL);
address = new Address(DEFAULT_ADDRESS);
status = new Status(DEFAULT_STATUS);
tags = new HashSet<>();
}

Expand Down Expand Up @@ -79,13 +75,7 @@ public ContactBuilder withId(String id) {
return this;
}

/**
* Sets the {@code Status} of the {@code Contact} that we are building.
*/
public ContactBuilder withStatus(String status) {
this.status = status == null ? null : new Status(status);
return this;
}


/**
* Parses the {@code tags} into a {@code Set<Tag>} and set it to the {@code Contact} that we are building.
Expand Down
Loading

0 comments on commit 64020d3

Please sign in to comment.