1
|
package eu.dnetlib.data.claims.handler;
|
2
|
|
3
|
import eu.dnetlib.data.claims.entity.Result;
|
4
|
import eu.dnetlib.data.claims.parser.OafParser;
|
5
|
import eu.dnetlib.data.claims.utils.SearchUtils;
|
6
|
import org.apache.log4j.Logger;
|
7
|
|
8
|
/**
|
9
|
* Created by kiatrop on 8/2/2016.
|
10
|
*/
|
11
|
public class IndexResultHandler {
|
12
|
|
13
|
SearchUtils searchUtils;
|
14
|
private Logger log = Logger.getLogger(this.getClass());
|
15
|
|
16
|
private String fetchPublicationResult(String id) throws Exception {
|
17
|
return searchUtils.fetchPublicationXmlFromIndex(id);
|
18
|
}
|
19
|
private String fetchSoftwareResult(String id) throws Exception {
|
20
|
return searchUtils.fetchSoftwareXmlFromIndex(id);
|
21
|
}
|
22
|
private String fetchOtherResult(String id) throws Exception {
|
23
|
return searchUtils.fetchOtherXmlFromIndex(id);
|
24
|
}
|
25
|
|
26
|
private String fetchDatasetResult(String id) throws Exception {
|
27
|
if(searchUtils == null ){
|
28
|
log.debug("searchUtils is null");
|
29
|
}
|
30
|
if(id == null ){
|
31
|
log.debug("id is null");
|
32
|
}
|
33
|
return searchUtils.fetchDatasetXmlFromIndex(id);
|
34
|
}
|
35
|
/**
|
36
|
*Searches for both publications and datasets
|
37
|
* @param id
|
38
|
* @return Result or null
|
39
|
* @throws Exception
|
40
|
*/
|
41
|
public Result fetchResultById(String id) throws Exception {
|
42
|
|
43
|
String oaf = fetchPublicationResult(id);
|
44
|
|
45
|
if (oaf == null) {
|
46
|
oaf = fetchDatasetResult(id);
|
47
|
}
|
48
|
|
49
|
if (oaf == null) {
|
50
|
return null;
|
51
|
}
|
52
|
|
53
|
return OafParser.oaf2Result(oaf);
|
54
|
}
|
55
|
public Result fetchPublicationById(String id) throws Exception {
|
56
|
|
57
|
String oaf = fetchPublicationResult(id);
|
58
|
|
59
|
if (oaf == null) {
|
60
|
return null;
|
61
|
}
|
62
|
|
63
|
return OafParser.oaf2Result(oaf);
|
64
|
}
|
65
|
public Result fetchDatasetById(String id) throws Exception {
|
66
|
|
67
|
String oaf = fetchDatasetResult(id);
|
68
|
if (oaf == null) {
|
69
|
return null;
|
70
|
}
|
71
|
|
72
|
return OafParser.oaf2Result(oaf);
|
73
|
}
|
74
|
public Result fetchSoftwareById(String id) throws Exception {
|
75
|
|
76
|
String oaf = fetchSoftwareResult(id);
|
77
|
if (oaf == null) {
|
78
|
return null;
|
79
|
}
|
80
|
return OafParser.oaf2Result(oaf);
|
81
|
}
|
82
|
public Result fetchOtherById(String id) throws Exception {
|
83
|
|
84
|
String oaf = fetchOtherResult(id);
|
85
|
if (oaf == null) {
|
86
|
return null;
|
87
|
}
|
88
|
return OafParser.oaf2Result(oaf);
|
89
|
}
|
90
|
public SearchUtils getSearchUtils() {
|
91
|
return searchUtils;
|
92
|
}
|
93
|
|
94
|
public void setSearchUtils(SearchUtils searchUtils) {
|
95
|
this.searchUtils = searchUtils;
|
96
|
}
|
97
|
}
|