1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.datamodel.metadata;
20
21 import java.util.Objects;
22 import java.util.function.BiConsumer;
23
24 import org.apache.logging.log4j.LogManager;
25 import org.apache.logging.log4j.Logger;
26 import org.jdom2.Element;
27 import org.mycore.common.MCRException;
28 import org.mycore.common.MCRUtils;
29
30
31
32
33
34
35
36
37
38 public final class MCRMetaPersonName extends MCRMetaDefault {
39
40 private String firstname;
41
42 private String callname;
43
44 private String surname;
45
46 private String fullname;
47
48 private String academic;
49
50 private String peerage;
51
52 private String numeration;
53
54 private String title;
55
56 private String prefix;
57
58 private String affix;
59
60 private static final Logger LOGGER = LogManager.getLogger();
61
62
63
64
65
66
67 public MCRMetaPersonName() {
68 super();
69 lang = DEFAULT_LANGUAGE;
70 firstname = "";
71 callname = "";
72 surname = "";
73 fullname = "";
74 academic = "";
75 peerage = "";
76 numeration = "";
77 title = "";
78 prefix = "";
79 affix = "";
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 public MCRMetaPersonName(String subtag, int inherted) throws MCRException {
97 super(subtag, DEFAULT_LANGUAGE, "", inherted);
98 type = "";
99 firstname = "";
100 callname = "";
101 surname = "";
102 fullname = "";
103 academic = "";
104 peerage = "";
105 numeration = "";
106 title = "";
107 prefix = "";
108 affix = "";
109 }
110
111
112
113
114
115
116 public String getFirstName() {
117 return firstname;
118 }
119
120
121
122
123 public void setFirstName(String firstname) {
124 if (firstname != null) {
125 this.firstname = firstname.trim();
126 } else {
127 this.firstname = "";
128 }
129 }
130
131
132
133
134
135
136 public String getCallName() {
137 return callname;
138 }
139
140
141
142
143 public void setCallName(String callname) {
144 if (callname != null) {
145 this.callname = callname.trim();
146 } else {
147 this.callname = "";
148 }
149 }
150
151
152
153
154
155
156 public String getSurName() {
157 return surname;
158 }
159
160
161
162
163 public void setSurName(String surname) {
164 if (surname != null) {
165 this.surname = surname.trim();
166 } else {
167 this.surname = "";
168 }
169 }
170
171
172
173
174
175
176 public String getFullName() {
177 return fullname;
178 }
179
180
181
182
183 public void setFullName(String fullname) {
184 if (fullname != null) {
185 this.fullname = fullname.trim();
186 } else {
187 this.fullname = "";
188 }
189 }
190
191
192
193
194
195
196 public String getAcademic() {
197 return academic;
198 }
199
200
201
202
203 public void setAcademic(String academic) {
204 if (academic != null) {
205 this.academic = academic.trim();
206 } else {
207 this.academic = "";
208 }
209 }
210
211
212
213
214
215
216 public String getPeerage() {
217 return peerage;
218 }
219
220
221
222
223 public void setPeerage(String peerage) {
224 if (peerage != null) {
225 this.peerage = peerage.trim();
226 } else {
227 this.peerage = "";
228 }
229 }
230
231
232
233
234
235
236 public String getNumeration() {
237 return numeration;
238 }
239
240
241
242
243 public void setNumeration(String numeration) {
244 if (numeration != null) {
245 this.numeration = numeration.trim();
246 } else {
247 this.numeration = "";
248 }
249 }
250
251
252
253
254
255
256 public String getTitle() {
257 return title;
258 }
259
260
261
262
263 public void setTitle(String title) {
264 if (title != null) {
265 this.title = title.trim();
266 } else {
267 this.title = "";
268 }
269 }
270
271
272
273
274
275
276 public String getPrefix() {
277 return prefix;
278 }
279
280
281
282
283 public void setPrefix(String prefix) {
284 if (prefix != null) {
285 this.prefix = prefix.trim();
286 } else {
287 this.prefix = "";
288 }
289 }
290
291
292
293
294
295
296 public String getAffix() {
297 return affix;
298 }
299
300
301
302
303 public void setAffix(String affix) {
304 if (affix != null) {
305 this.affix = affix.trim();
306 } else {
307 this.affix = "";
308 }
309 }
310
311
312
313
314
315
316
317
318 @Override
319 public void setFromDOM(Element element) {
320 super.setFromDOM(element);
321 setFirstName(element.getChildTextTrim("firstname"));
322 setCallName(element.getChildTextTrim("callname"));
323 setSurName(element.getChildTextTrim("surname"));
324 setFullName(element.getChildTextTrim("fullname"));
325 setAcademic(element.getChildTextTrim("academic"));
326 setPeerage(element.getChildTextTrim("peerage"));
327 setNumeration(element.getChildTextTrim("numeration"));
328 setTitle(element.getChildTextTrim("title"));
329 setPrefix(element.getChildTextTrim("prefix"));
330 setAffix(element.getChildTextTrim("affix"));
331 }
332
333
334
335
336
337
338
339
340
341 @Override
342 public Element createXML() throws MCRException {
343 Element elm = super.createXML();
344 BiConsumer<String, String> addContent = (name, value) -> MCRUtils.filterTrimmedNotEmpty(value)
345 .ifPresent(trimmedValue -> elm.addContent(new Element(name).addContent(trimmedValue)));
346 addContent.accept("firstname", firstname);
347 addContent.accept("callname", callname);
348 addContent.accept("fullname", fullname);
349 addContent.accept("surname", surname);
350 addContent.accept("academic", academic);
351 addContent.accept("peerage", peerage);
352 addContent.accept("numeration", numeration);
353 addContent.accept("title", title);
354 addContent.accept("prefix", prefix);
355 addContent.accept("affix", affix);
356
357 return elm;
358 }
359
360
361
362
363
364
365
366
367
368
369
370
371 public void validate() throws MCRException {
372 super.validate();
373 if (firstname == null || callname == null || fullname == null) {
374 throw new MCRException(getSubTag() + ": one of fullname, callname or firstname is null.");
375 }
376 firstname = firstname.trim();
377 if (firstname.length() == 0) {
378 firstname = callname;
379 }
380 callname = callname.trim();
381 if (callname.length() == 0) {
382 callname = firstname;
383 }
384 fullname = fullname.trim();
385 if (fullname.length() == 0) {
386 String sb = academic + ' ' + peerage + ' ' + firstname + ' ' + prefix + ' ' + surname;
387 fullname = sb.trim();
388 if (fullname.length() == 0) {
389 throw new MCRException(getSubTag() + ": full name / first name or surname is empty");
390 }
391 }
392 }
393
394
395
396
397
398
399
400
401 @Override
402 public MCRMetaPersonName clone() {
403 MCRMetaPersonName clone = (MCRMetaPersonName) super.clone();
404
405 clone.firstname = this.firstname;
406 clone.callname = this.callname;
407 clone.surname = this.surname;
408 clone.fullname = this.fullname;
409 clone.academic = this.academic;
410 clone.peerage = this.peerage;
411 clone.numeration = this.numeration;
412 clone.title = this.title;
413 clone.prefix = this.prefix;
414 clone.affix = this.affix;
415
416 return clone;
417 }
418
419
420
421
422 @Override
423 public void debug() {
424 if (LOGGER.isDebugEnabled()) {
425 super.debugDefault();
426 LOGGER.debug("First name = {}", firstname);
427 LOGGER.debug("Call name = {}", callname);
428 LOGGER.debug("Surname = {}", surname);
429 LOGGER.debug("Full name = {}", fullname);
430 LOGGER.debug("Academic = {}", academic);
431 LOGGER.debug("Peerage = {}", peerage);
432 LOGGER.debug("Numeration = {}", numeration);
433 LOGGER.debug("Title = {}", title);
434 LOGGER.debug("Prefix = {}", prefix);
435 LOGGER.debug("Affix = {}", affix);
436 LOGGER.debug("");
437 }
438 }
439
440
441
442
443 @Override
444 public boolean equals(Object obj) {
445 if (!super.equals(obj)) {
446 return false;
447 }
448 final MCRMetaPersonName other = (MCRMetaPersonName) obj;
449 return Objects.equals(this.firstname, other.firstname) && Objects.equals(this.callname, other.callname) &&
450 Objects.equals(this.surname, other.surname) && Objects.equals(this.fullname, other.fullname) &&
451 Objects.equals(this.academic, other.academic) && Objects.equals(this.peerage, other.peerage) &&
452 Objects.equals(this.numeration, other.numeration) && Objects.equals(this.title, other.title) &&
453 Objects.equals(this.prefix, other.prefix) && Objects.equals(this.affix, other.affix);
454 }
455 }