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