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
23 import org.jdom2.Element;
24 import org.mycore.common.MCRException;
25 import org.mycore.common.MCRUtils;
26
27 import com.google.gson.JsonObject;
28
29
30
31
32
33
34
35
36
37 public final class MCRMetaInstitutionName extends MCRMetaDefault {
38
39 private String fullname;
40
41 private String nickname;
42
43 private String property;
44
45
46
47
48
49
50 public MCRMetaInstitutionName() {
51 super();
52 fullname = "";
53 nickname = "";
54 property = "";
55 }
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 public MCRMetaInstitutionName(String subtag, String lang, String type, int inherted,
78 String fullname, String nickname, String property) throws MCRException {
79 super(subtag, lang, type, inherted);
80 this.fullname = "";
81 this.nickname = "";
82 this.property = "";
83 set(fullname, nickname, property);
84 }
85
86
87
88
89
90
91
92
93
94
95
96 public void set(String fullname, String nickname, String property) {
97 if (fullname == null || nickname == null || property == null) {
98 throw new MCRException("One parameter is null.");
99 }
100
101 this.fullname = fullname.trim();
102 this.nickname = nickname.trim();
103 this.property = property.trim();
104 }
105
106
107
108
109
110
111 public String getFullName() {
112 return fullname;
113 }
114
115
116
117
118
119
120 public String getNickname() {
121 return nickname;
122 }
123
124
125
126
127
128
129 public String getProperty() {
130 return property;
131 }
132
133
134
135
136
137
138
139
140 @Override
141 public void setFromDOM(Element element) {
142 super.setFromDOM(element);
143 fullname = element.getChildTextTrim("fullname");
144
145 if (fullname == null) {
146 fullname = "";
147 }
148
149 nickname = element.getChildTextTrim("nickname");
150
151 if (nickname == null) {
152 nickname = "";
153 }
154
155 property = element.getChildTextTrim("property");
156
157 if (property == null) {
158 property = "";
159 }
160 }
161
162
163
164
165
166
167
168
169
170 @Override
171 public Element createXML() throws MCRException {
172 Element elm = super.createXML();
173 elm.addContent(new Element("fullname").addContent(fullname));
174
175 nickname = nickname.trim();
176 if (nickname.length() != 0) {
177 elm.addContent(new Element("nickname").addContent(nickname));
178 }
179
180 property = property.trim();
181 if (property.length() != 0) {
182 elm.addContent(new Element("property").addContent(property));
183 }
184
185 return elm;
186 }
187
188
189
190
191
192
193
194
195
196
197
198
199
200 @Override
201 public JsonObject createJSON() {
202 JsonObject obj = super.createJSON();
203 obj.addProperty("fullname", fullname);
204 if (nickname != null) {
205 obj.addProperty("nickname", nickname);
206 }
207 if (property != null) {
208 obj.addProperty("property", property);
209 }
210 return obj;
211 }
212
213
214
215
216
217
218
219
220
221
222
223
224 public void validate() throws MCRException {
225 super.validate();
226 fullname = MCRUtils.filterTrimmedNotEmpty(fullname)
227 .orElseThrow(() -> new MCRException(getSubTag() + ": fullname is null or empty"));
228 }
229
230
231
232
233
234
235
236
237 @Override
238 public MCRMetaInstitutionName clone() {
239 MCRMetaInstitutionName clone = (MCRMetaInstitutionName) super.clone();
240
241 clone.fullname = this.fullname;
242 clone.nickname = this.nickname;
243 clone.property = this.property;
244
245 return clone;
246 }
247
248 @Override
249 public boolean equals(Object obj) {
250 if (!super.equals(obj)) {
251 return false;
252 }
253 final MCRMetaInstitutionName other = (MCRMetaInstitutionName) obj;
254 return Objects.equals(fullname, other.fullname) && Objects.equals(nickname, other.nickname)
255 && Objects.equals(property, other.property);
256 }
257
258 }