forked from AY2425S1-CS2103T-F15-4/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,091 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 121 additions & 1 deletion
122
src/main/java/seedu/address/storage/JsonAdaptedVendor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,122 @@ | ||
package seedu.address.storage;public class JsonAdaptedVendor { | ||
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.Email; | ||
import seedu.address.model.person.Name; | ||
import seedu.address.model.person.Phone; | ||
import seedu.address.model.person.Vendor; | ||
import seedu.address.model.tag.Tag; | ||
import seedu.address.model.wedding.Wedding; | ||
|
||
class JsonAdaptedVendor { | ||
|
||
public static final String MISSING_FIELD_MESSAGE_FORMAT = "Person's %s field is missing!"; | ||
|
||
private final String name; | ||
private final String phone; | ||
private final String email; | ||
private final String address; | ||
private final List<JsonAdaptedTag> tags = new ArrayList<>(); | ||
private final List<JsonAdaptedWedding> weddings = new ArrayList<>(); | ||
|
||
/** | ||
* Constructs a {@code JsonAdaptedVendor} with the given vendor details. | ||
*/ | ||
@JsonCreator | ||
public JsonAdaptedVendor(@JsonProperty("name") String name, @JsonProperty("phone") String phone, | ||
@JsonProperty("email") String email, @JsonProperty("address") String address, | ||
@JsonProperty("tags") List<JsonAdaptedTag> tags, | ||
@JsonProperty("weddings") List<JsonAdaptedWedding> weddings) { | ||
this.name = name; | ||
this.phone = phone; | ||
this.email = email; | ||
this.address = address; | ||
if (tags != null) { | ||
this.tags.addAll(tags); | ||
} | ||
if (weddings != null) { | ||
this.weddings.addAll(weddings); | ||
} | ||
} | ||
|
||
/** | ||
* Converts a given {@code Vendor} into this class for Jackson use. | ||
*/ | ||
public JsonAdaptedVendor(Vendor source) { | ||
name = source.getName().fullName; | ||
phone = source.getPhone().value; | ||
email = source.getEmail().value; | ||
address = source.getAddress().value; | ||
tags.addAll(source.getTags().stream() | ||
.map(JsonAdaptedTag::new) | ||
.collect(Collectors.toList())); | ||
weddings.addAll(source.getWeddings().stream() | ||
.map(JsonAdaptedWedding::new) | ||
.collect(Collectors.toList())); | ||
} | ||
|
||
/** | ||
* Converts this Jackson-friendly adapted vendor object into the model's {@code Vendor} object. | ||
* | ||
* @throws IllegalValueException if there were any data constraints violated in the adapted vendor. | ||
*/ | ||
public Vendor toModelType() throws IllegalValueException { | ||
final List<Tag> personTags = new ArrayList<>(); | ||
final List<Wedding> personWeddings = new ArrayList<>(); | ||
|
||
for (JsonAdaptedTag tag : tags) { | ||
personTags.add(tag.toModelType()); | ||
} | ||
|
||
for (JsonAdaptedWedding wedding : weddings) { | ||
if (!Wedding.isValidWeddingName(wedding.getWeddingName())) { | ||
throw new IllegalValueException(Wedding.MESSAGE_CONSTRAINTS); | ||
} | ||
personWeddings.add(wedding.toModelType()); | ||
} | ||
|
||
if (name == null) { | ||
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); | ||
} | ||
if (!Name.isValidName(name)) { | ||
throw new IllegalValueException(Name.MESSAGE_CONSTRAINTS); | ||
} | ||
final Name modelName = new Name(name); | ||
|
||
if (phone == null) { | ||
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName())); | ||
} | ||
if (!Phone.isValidPhone(phone)) { | ||
throw new IllegalValueException(Phone.MESSAGE_CONSTRAINTS); | ||
} | ||
final Phone modelPhone = new Phone(phone); | ||
|
||
if (email == null) { | ||
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName())); | ||
} | ||
if (!Email.isValidEmail(email)) { | ||
throw new IllegalValueException(Email.MESSAGE_CONSTRAINTS); | ||
} | ||
final Email modelEmail = new Email(email); | ||
|
||
if (address == null) { | ||
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName())); | ||
} | ||
final Address modelAddress = new Address(address); | ||
|
||
final Set<Tag> modelTags = new HashSet<>(personTags); | ||
final Set<Wedding> modelWeddings = new HashSet<>(personWeddings); | ||
|
||
return new Vendor(modelName, modelPhone, modelEmail, modelAddress, modelTags, modelWeddings); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"email": "[email protected]", | ||
"address": "4th street" | ||
} ], | ||
"vendors": [], | ||
"tags": ["florist"], | ||
"weddings": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"email": "invalid@email!3e", | ||
"address": "4th street" | ||
} ], | ||
"vendors": [], | ||
"tags": ["florist"], | ||
"weddings": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"email": "[email protected]", | ||
"address": "4th street" | ||
} ], | ||
"vendors": [], | ||
"tags": ["florist", " "], | ||
"weddings": ["Wedding 19"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"email": "[email protected]", | ||
"address": "4th street" | ||
} ], | ||
"vendors": [], | ||
"tags": ["florist", "musician"], | ||
"weddings": ["Wedding 19", " "] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.