Project

General

Profile

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

    
7
/**
8
 * Created by kiatrop on 8/2/2016.
9
 */
10
public class IndexResultHandler {
11

    
12
    SearchUtils searchUtils;
13

    
14
    private String fetchPublicationResult(String id) throws Exception {
15
        return searchUtils.fetchPublicationXmlFromIndex(id);
16
    }
17
    private String fetchSoftwareResult(String id) throws Exception {
18
        return  searchUtils.fetchSoftwareXmlFromIndex(id);
19
    }
20
    private String fetchOtherResult(String id) throws Exception {
21
        return  searchUtils.fetchOtherXmlFromIndex(id);
22
    }
23

    
24
    private String fetchDatasetResult(String id) throws Exception {
25
        return searchUtils.fetchDatasetXmlFromIndex(id);
26
    }
27
    /**
28
     *Searches for both publications and datasets
29
     * @param id
30
     * @return Result or null
31
     * @throws Exception
32
     */
33
    public Result fetchResultById(String id) throws Exception {
34

    
35
        String oaf = fetchPublicationResult(id);
36

    
37
        if (oaf == null) {
38
            oaf = fetchDatasetResult(id);
39
        }
40

    
41
        if (oaf == null) {
42
            return null;
43
        }
44

    
45
        return OafParser.oaf2Result(oaf);
46
    }
47
    public Result fetchPublicationById(String id) throws Exception {
48

    
49
        String oaf = fetchPublicationResult(id);
50

    
51
        if (oaf == null) {
52
            return null;
53
        }
54

    
55
        return OafParser.oaf2Result(oaf);
56
    }
57
    public Result fetchDatasetById(String id) throws Exception {
58

    
59
        String oaf = fetchDatasetResult(id);
60
        if (oaf == null) {
61
            return null;
62
        }
63

    
64
        return OafParser.oaf2Result(oaf);
65
    }
66
    public Result fetchSoftwareById(String id) throws Exception {
67

    
68
        String oaf = fetchSoftwareResult(id);
69
        if (oaf == null) {
70
            return null;
71
        }
72
        return OafParser.oaf2Result(oaf);
73
    }
74
    public Result fetchOtherById(String id) throws Exception {
75

    
76
        String oaf = fetchOtherResult(id);
77
        if (oaf == null) {
78
            return null;
79
        }
80
        return OafParser.oaf2Result(oaf);
81
    }
82
    public SearchUtils getSearchUtils() {
83
        return searchUtils;
84
    }
85

    
86
    public void setSearchUtils(SearchUtils searchUtils) {
87
        this.searchUtils = searchUtils;
88
    }
89
}
(9-9/12)