1
|
package eu.dnetlib.resolver.model;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.Arrays;
|
5
|
import java.util.List;
|
6
|
import java.util.stream.Collectors;
|
7
|
|
8
|
import com.google.common.collect.Lists;
|
9
|
import com.google.gson.Gson;
|
10
|
import eu.dnetlib.miscutils.functional.xml.DnetXsltFunctions;
|
11
|
import eu.dnetlib.resolver.AbstractPIDResolver;
|
12
|
import org.apache.commons.lang3.StringEscapeUtils;
|
13
|
import org.apache.commons.lang3.StringUtils;
|
14
|
|
15
|
/**
|
16
|
* The Class DLIObject.
|
17
|
*/
|
18
|
public class ResolvedObject {
|
19
|
|
20
|
/**
|
21
|
* The doi.
|
22
|
*/
|
23
|
private String pid;
|
24
|
|
25
|
/**
|
26
|
* The pid type.
|
27
|
*/
|
28
|
private String pidType;
|
29
|
|
30
|
/**
|
31
|
* The titles.
|
32
|
*/
|
33
|
private List<String> titles = new ArrayList<>();
|
34
|
|
35
|
/**
|
36
|
* The authors.
|
37
|
*/
|
38
|
private List<String> authors = new ArrayList<>();
|
39
|
|
40
|
/**
|
41
|
* The type.
|
42
|
*/
|
43
|
private ObjectType type;
|
44
|
|
45
|
/**
|
46
|
* Description of the resolved object
|
47
|
*/
|
48
|
private String description;
|
49
|
|
50
|
/**
|
51
|
* The datasources.
|
52
|
*/
|
53
|
private List<ObjectProvenance> datasourceProvenance;
|
54
|
|
55
|
/**
|
56
|
* The completion status.
|
57
|
*/
|
58
|
private String completionStatus;
|
59
|
|
60
|
/**
|
61
|
* The date.
|
62
|
*/
|
63
|
private String date;
|
64
|
|
65
|
/**
|
66
|
* A list of subjects of type scheme term
|
67
|
*/
|
68
|
private List<SubjectType> subjects;
|
69
|
|
70
|
/**
|
71
|
* The related objects.
|
72
|
*/
|
73
|
private List<ObjectRelation> relations;
|
74
|
|
75
|
/**
|
76
|
* Instantiates a new DLI object.
|
77
|
*/
|
78
|
public ResolvedObject() {
|
79
|
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* Instantiates a new DLI object.
|
84
|
*
|
85
|
* @param pid the pid
|
86
|
* @param pidType the pid type
|
87
|
* @param titles the titles
|
88
|
* @param authors the authors
|
89
|
* @param type the type
|
90
|
* @param datasourceProvenance the datasource provenance
|
91
|
* @param relations the relations
|
92
|
* @param status the status
|
93
|
*/
|
94
|
public ResolvedObject(final String pid, final String pidType, final List<String> titles, final List<String> authors, final ObjectType type,
|
95
|
final List<ObjectProvenance> datasourceProvenance, final List<ObjectRelation> relations, final String status) {
|
96
|
super();
|
97
|
if (pid != null) {
|
98
|
this.pid = pid.replace("http://dx.doi.org/", "").replace("http://doi.org/", "").toLowerCase();
|
99
|
}
|
100
|
this.pidType = pidType;
|
101
|
this.titles = titles;
|
102
|
this.authors = authors;
|
103
|
this.type = type;
|
104
|
this.setDatasourceProvenance(datasourceProvenance);
|
105
|
this.relations = relations;
|
106
|
this.setCompletionStatus(status);
|
107
|
}
|
108
|
|
109
|
/**
|
110
|
* Escaped array.
|
111
|
*
|
112
|
* @param inputArray the input array
|
113
|
* @return the string[]
|
114
|
*/
|
115
|
public static List<String> escapedArray(final List<String> inputArray) {
|
116
|
if (inputArray == null || inputArray.size() == 0) return null;
|
117
|
return inputArray.stream().map(input -> input.replaceAll("&", "&")
|
118
|
.replaceAll("\"", """)
|
119
|
.replaceAll("'", "'")
|
120
|
.replaceAll("<", "<")
|
121
|
.replaceAll(">", ">"))
|
122
|
.collect(Collectors.toList());
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* Gets the doi.
|
127
|
*
|
128
|
* @return the doi
|
129
|
*/
|
130
|
public String getPid() {
|
131
|
if (pid != null)
|
132
|
return pid.toLowerCase();
|
133
|
return pid;
|
134
|
}
|
135
|
|
136
|
/**
|
137
|
* Sets the doi.
|
138
|
*
|
139
|
* @param pid the new pid
|
140
|
*/
|
141
|
public void setPid(final String pid) {
|
142
|
if (pid != null) {
|
143
|
this.pid = pid.replace("http://dx.doi.org/", "").replace("http://doi.org/", "");
|
144
|
}
|
145
|
}
|
146
|
|
147
|
/**
|
148
|
* Check not null fields.
|
149
|
*
|
150
|
* @return the string
|
151
|
*/
|
152
|
private String checkNotNullFields() {
|
153
|
|
154
|
final List<String> notNUllFields = Lists.newArrayList();
|
155
|
if (!StringUtils.isEmpty(pid)) {
|
156
|
notNUllFields.add("pid");
|
157
|
}
|
158
|
if (!StringUtils.isEmpty(pidType)) {
|
159
|
notNUllFields.add("pidType");
|
160
|
}
|
161
|
if (titles == null || titles.size() == 0) {
|
162
|
notNUllFields.add("titles");
|
163
|
}
|
164
|
if (authors == null || authors.size() == 0) {
|
165
|
notNUllFields.add("authors");
|
166
|
}
|
167
|
if (!StringUtils.isEmpty(date)) {
|
168
|
notNUllFields.add("date");
|
169
|
}
|
170
|
return new Gson().toJson(notNUllFields);
|
171
|
}
|
172
|
|
173
|
/**
|
174
|
* Fix contribution.
|
175
|
*
|
176
|
* @param provenance the provenance
|
177
|
*/
|
178
|
public void fixContribution(final ObjectProvenance provenance) {
|
179
|
provenance.setDatasourceContribution(checkNotNullFields());
|
180
|
}
|
181
|
|
182
|
public String getResolvedPIDUrl() {
|
183
|
if (pidType == null || StringUtils.isBlank(pidType) || pid == null || StringUtils.isBlank(pid))
|
184
|
return "#";
|
185
|
|
186
|
if (AbstractPIDResolver.resolvedTypes.containsKey(pidType.toLowerCase()))
|
187
|
return String.format(AbstractPIDResolver.resolvedTypes.get(pidType.toLowerCase()), getEscapedXMLPid());
|
188
|
|
189
|
return "#";
|
190
|
}
|
191
|
|
192
|
/**
|
193
|
* Gets the escaped xml pid.
|
194
|
*
|
195
|
* @return the escaped xml pid
|
196
|
*/
|
197
|
public String getEscapedXMLPid() {
|
198
|
return StringEscapeUtils.escapeXml11(pid);
|
199
|
}
|
200
|
|
201
|
/**
|
202
|
* Gets the titles.
|
203
|
*
|
204
|
* @return the titles
|
205
|
*/
|
206
|
public List<String> getTitles() {
|
207
|
return titles;
|
208
|
}
|
209
|
|
210
|
/**
|
211
|
* Sets the titles.
|
212
|
*
|
213
|
* @param titles the new titles
|
214
|
*/
|
215
|
public void setTitles(final List<String> titles) {
|
216
|
this.titles = titles;
|
217
|
}
|
218
|
|
219
|
/**
|
220
|
* Gets the escaped xml titles.
|
221
|
*
|
222
|
* @return the escaped xml titles
|
223
|
*/
|
224
|
public List<String> getEscapedXMLTitles() {
|
225
|
|
226
|
return escapedArray(titles);
|
227
|
}
|
228
|
|
229
|
/**
|
230
|
* Gets the authors.
|
231
|
*
|
232
|
* @return the authors
|
233
|
*/
|
234
|
public List<String> getAuthors() {
|
235
|
return authors;
|
236
|
}
|
237
|
|
238
|
/**
|
239
|
* Sets the authors.
|
240
|
*
|
241
|
* @param authors the new authors
|
242
|
*/
|
243
|
public void setAuthors(final List<String> authors) {
|
244
|
this.authors = authors;
|
245
|
}
|
246
|
|
247
|
/**
|
248
|
* Gets the escaped xml authors.
|
249
|
*
|
250
|
* @return the escaped xml authors
|
251
|
*/
|
252
|
public List<String> getEscapedXMLAuthors() {
|
253
|
return escapedArray(authors);
|
254
|
}
|
255
|
|
256
|
/**
|
257
|
* get All the subjects
|
258
|
*
|
259
|
* @return a list of Subjects
|
260
|
*/
|
261
|
public List<SubjectType> getSubjects() {
|
262
|
return subjects;
|
263
|
}
|
264
|
|
265
|
/**
|
266
|
* Set all the subjects
|
267
|
*
|
268
|
* @param subjects
|
269
|
*/
|
270
|
public void setSubjects(final List<SubjectType> subjects) {
|
271
|
this.subjects = subjects;
|
272
|
}
|
273
|
|
274
|
/**
|
275
|
* Gets the type.
|
276
|
*
|
277
|
* @return the type
|
278
|
*/
|
279
|
public ObjectType getType() {
|
280
|
return type == null ? ObjectType.unknown : type;
|
281
|
}
|
282
|
|
283
|
/**
|
284
|
* Sets the type.
|
285
|
*
|
286
|
* @param type the new type
|
287
|
*/
|
288
|
public void setType(final ObjectType type) {
|
289
|
this.type = type;
|
290
|
}
|
291
|
|
292
|
/**
|
293
|
* Gets the escaped xml type.
|
294
|
*
|
295
|
* @return the escaped xml type
|
296
|
*/
|
297
|
public String getEscapedXMLType() {
|
298
|
if (type != null)
|
299
|
return type.toString();
|
300
|
else return null;
|
301
|
}
|
302
|
|
303
|
/**
|
304
|
* Gets the identifier. withe the form of MD5(pid::pidType)
|
305
|
*
|
306
|
* @return the identifier
|
307
|
*/
|
308
|
public String getIdentifier() {
|
309
|
if (StringUtils.isBlank(pid) || StringUtils.isBlank(pidType))
|
310
|
throw new RuntimeException("Error pid or pidtype cannot be null");
|
311
|
return DnetXsltFunctions.md5(String.format("%s::%s", pid.trim().toLowerCase(), pidType.toLowerCase().trim()));
|
312
|
}
|
313
|
|
314
|
/**
|
315
|
* Gets the relations.
|
316
|
*
|
317
|
* @return the relations
|
318
|
*/
|
319
|
public List<ObjectRelation> getRelations() {
|
320
|
return relations;
|
321
|
}
|
322
|
|
323
|
/**
|
324
|
* Sets the relations.
|
325
|
*
|
326
|
* @param relations the new relations
|
327
|
*/
|
328
|
public void setRelations(final List<ObjectRelation> relations) {
|
329
|
this.relations = relations;
|
330
|
}
|
331
|
|
332
|
/**
|
333
|
* Gets the date.
|
334
|
*
|
335
|
* @return the date
|
336
|
*/
|
337
|
public String getDate() {
|
338
|
return date;
|
339
|
}
|
340
|
|
341
|
/**
|
342
|
* Sets the date.
|
343
|
*
|
344
|
* @param date the date to set
|
345
|
*/
|
346
|
public void setDate(final String date) {
|
347
|
this.date = date;
|
348
|
}
|
349
|
|
350
|
/**
|
351
|
* Gets the pid type.
|
352
|
*
|
353
|
* @return the pidType
|
354
|
*/
|
355
|
public String getPidType() {
|
356
|
return pidType;
|
357
|
}
|
358
|
|
359
|
/**
|
360
|
* Sets the pid type.
|
361
|
*
|
362
|
* @param pidType the pidType to set
|
363
|
*/
|
364
|
public void setPidType(final String pidType) {
|
365
|
this.pidType = pidType;
|
366
|
}
|
367
|
|
368
|
/**
|
369
|
* Gets the completion status.
|
370
|
*
|
371
|
* @return the completion status
|
372
|
*/
|
373
|
public String getCompletionStatus() {
|
374
|
return this.completionStatus;
|
375
|
}
|
376
|
|
377
|
/**
|
378
|
* Sets the completion status.
|
379
|
*
|
380
|
* @param completionStatus the new completion status
|
381
|
*/
|
382
|
public void setCompletionStatus(final String completionStatus) {
|
383
|
this.completionStatus = completionStatus;
|
384
|
}
|
385
|
|
386
|
/**
|
387
|
* Gets the datasource provenance.
|
388
|
*
|
389
|
* @return the datasource provenance
|
390
|
*/
|
391
|
public List<ObjectProvenance> getDatasourceProvenance() {
|
392
|
return datasourceProvenance;
|
393
|
}
|
394
|
|
395
|
/**
|
396
|
* Sets the datasource provenance.
|
397
|
*
|
398
|
* @param datasourceProvenance the new datasource provenance
|
399
|
*/
|
400
|
public void setDatasourceProvenance(final List<ObjectProvenance> datasourceProvenance) {
|
401
|
this.datasourceProvenance = datasourceProvenance;
|
402
|
}
|
403
|
|
404
|
/**
|
405
|
* {@inheritDoc}
|
406
|
*
|
407
|
* @see Object#toString()
|
408
|
*/
|
409
|
@Override
|
410
|
public String toString() {
|
411
|
|
412
|
String s =
|
413
|
"DLIObject \n\t Identifier: %s \n\t Pid:%s \n\t PIDType: %s \n\t Entity Type: %s \n\t Titles:%s \n\t Description:%s \n\t Authors:%s, \n\tProvenance%s";
|
414
|
|
415
|
return String.format(s, this.getIdentifier(), this.getPid(), this.getPidType(), this.getType(), this.getTitles(), this.description,
|
416
|
this.authors, Arrays.toString(this.getDatasourceProvenance().toArray()));
|
417
|
|
418
|
}
|
419
|
|
420
|
public String getDescription() {
|
421
|
return description;
|
422
|
}
|
423
|
|
424
|
public void setDescription(final String description) {
|
425
|
this.description = description;
|
426
|
}
|
427
|
|
428
|
public String getEscapedDescription() {
|
429
|
return StringEscapeUtils.escapeXml11(description);
|
430
|
}
|
431
|
}
|