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