-
Notifications
You must be signed in to change notification settings - Fork 548
/
Copy pathJsonAdaptedPerson.java
201 lines (167 loc) · 7.54 KB
/
JsonAdaptedPerson.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
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.interaction.Interaction;
import seedu.address.model.person.Email;
import seedu.address.model.person.Faculty;
import seedu.address.model.person.Major;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.remark.Remark;
import seedu.address.model.skill.Framework;
import seedu.address.model.skill.Language;
import seedu.address.model.skill.Skill;
import seedu.address.model.tag.Tag;
/**
* Jackson-friendly version of {@link Person}.
*/
class JsonAdaptedPerson {
public static final String MISSING_FIELD_MESSAGE_FORMAT = "Person's %s field is missing!";
private final String name;
private final String email;
private final String faculty;
private final String major;
private final List<JsonAdaptedSkill> skills = new ArrayList<>();
private final List<JsonAdaptedLanguage> languages = new ArrayList<>();
private final List<JsonAdaptedFramework> frameworks = new ArrayList<>();
private final List<JsonAdaptedTag> tagged = new ArrayList<>();
private final List<JsonAdaptedRemark> remarks = new ArrayList<>();
private final List<JsonAdaptedInteractions> interactions = new ArrayList<>();
/**
* Constructs a {@code JsonAdaptedPerson} with the given person details.
*/
@JsonCreator
public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("email") String email,
@JsonProperty("faculty") String faculty,
@JsonProperty("major") String major,
@JsonProperty("skills") List<JsonAdaptedSkill> skills,
@JsonProperty("languages") List<JsonAdaptedLanguage> languages,
@JsonProperty("frameworks") List<JsonAdaptedFramework> frameworks,
@JsonProperty("tagged") List<JsonAdaptedTag> tagged,
@JsonProperty("remarks") List<JsonAdaptedRemark> remarks,
@JsonProperty("interactions") List<JsonAdaptedInteractions> interactions) {
this.name = name;
this.email = email;
this.faculty = faculty;
this.major = major;
if (skills != null) {
this.skills.addAll(skills);
}
if (languages != null) {
this.languages.addAll(languages);
}
if (frameworks != null) {
this.frameworks.addAll(frameworks);
}
if (tagged != null) {
this.tagged.addAll(tagged);
}
if (remarks != null) {
this.remarks.addAll(remarks);
}
if (interactions != null) {
this.interactions.addAll(interactions);
}
}
/**
* Converts a given {@code Person} into this class for Jackson use.
*/
public JsonAdaptedPerson(Person source) {
name = source.getName().fullName;
email = source.getEmail().value;
faculty = source.getFaculty().value;
major = source.getMajor().value;
skills.addAll(source.getSkills().stream()
.map(JsonAdaptedSkill::new)
.collect(Collectors.toList()));
languages.addAll(source.getLanguages().stream()
.map(JsonAdaptedLanguage::new)
.collect(Collectors.toList()));
frameworks.addAll(source.getFrameworks().stream()
.map(JsonAdaptedFramework::new)
.collect(Collectors.toList()));
tagged.addAll(source.getTags().stream()
.map(JsonAdaptedTag::new)
.collect(Collectors.toList()));
remarks.addAll(source.getRemarks().stream()
.map(JsonAdaptedRemark::new)
.collect(Collectors.toList()));
interactions.addAll(source.getInteractions().stream()
.map(JsonAdaptedInteractions::new)
.collect(Collectors.toList()));
}
/**
* Converts this Jackson-friendly adapted person object into the model's {@code Person} object.
*
* @throws IllegalValueException if there were any data constraints violated in the adapted person.
*/
public Person toModelType() throws IllegalValueException {
final List<Skill> personSkills = new ArrayList<>();
for (JsonAdaptedSkill skill : skills) {
personSkills.add(skill.toModelType());
}
final List<Language> personLanguages = new ArrayList<>();
for (JsonAdaptedLanguage language : languages) {
personLanguages.add(language.toModelType());
}
final List<Framework> personFrameworks = new ArrayList<>();
for (JsonAdaptedFramework framework : frameworks) {
personFrameworks.add(framework.toModelType());
}
final List<Tag> personTags = new ArrayList<>();
for (JsonAdaptedTag tag : tagged) {
personTags.add(tag.toModelType());
}
System.out.println(interactions);
final List<Interaction> personInteractions = new ArrayList<>();
for (JsonAdaptedInteractions interaction : interactions) {
personInteractions.add(interaction.toModelType());
}
final List<Remark> personRemarks = new ArrayList<>();
for (JsonAdaptedRemark remark : remarks) {
personRemarks.add(remark.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 (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 (faculty == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Faculty.class.getSimpleName()));
}
if (!Faculty.isValidFaculty(faculty)) {
throw new IllegalValueException(Faculty.MESSAGE_CONSTRAINTS);
}
final Faculty modelFaculty = new Faculty(faculty);
if (major == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Major.class.getSimpleName()));
}
if (!Major.isValidMajor(major)) {
throw new IllegalValueException(Major.MESSAGE_CONSTRAINTS);
}
final Major modelMajor = new Major(major);
final Set<Skill> modelSkills = new HashSet<>(personSkills);
final Set<Language> modelLanguages = new HashSet<>(personLanguages);
final Set<Framework> modelFrameworks = new HashSet<>(personFrameworks);
final Set<Tag> modelTags = new HashSet<>(personTags);
final Set<Remark> modelRemarks = new HashSet<>(personRemarks);
final Set<Interaction> modelInteractions = new HashSet<>(personInteractions);
return new Person(modelName, modelEmail, modelFaculty, modelMajor,
modelSkills, modelLanguages, modelFrameworks, modelTags, modelRemarks, modelInteractions);
}
}