Project

General

Profile

1
package eu.dnetlib.data.claims.migration.handler;
2

    
3
import eu.dnetlib.data.claims.migration.entity.Result;
4
import eu.dnetlib.data.claims.migration.parser.OafParser;
5
import eu.dnetlib.data.claimsDemo.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, boolean production) throws Exception {
15
        return searchUtils.fetchPublicationXmlFromIndex(id, production);
16
    }
17
    private String fetchSoftwareResult(String id, boolean production) throws Exception {
18
        return  searchUtils.fetchSoftwareXmlFromIndex(id, production);
19
    }
20
    private String fetchOtherResult(String id, boolean production) throws Exception {
21
        return  searchUtils.fetchOtherXmlFromIndex(id, production);
22
    }
23

    
24
    private String fetchDatasetResult(String id, boolean production) throws Exception {
25
        return searchUtils.fetchDatasetXmlFromIndex(id, production);
26
    }
27
//    private String fetchDedupPublicationResult(String id) throws Exception {
28
//        return searchUtils.fetchDedupPublicationXmlFromIndex(id);
29
//    }
30
//
31
//    private String fetchDedupDatasetResult(String id) throws Exception {
32
//        return searchUtils.fetchDedupDatasetXmlFromIndex(id);
33
//    }
34
    /**
35
     *Searches for both publications and datasets
36
     * @param id
37
     * @return Result or null
38
     * @throws Exception
39
     */
40
    public Result fetchResultById(String id, boolean production) throws Exception {
41

    
42
        String oaf = fetchPublicationResult(id, production);
43

    
44
        if (oaf == null) {
45
            oaf = fetchDatasetResult(id, production);
46
        }
47

    
48
        if (oaf == null) {
49
            return null;
50
        }
51

    
52
        return OafParser.oaf2Result(oaf);
53
    }
54
    public Result fetchDedupById(String id, boolean production) throws Exception {
55
        String oaf = searchUtils.fetchDedupXmlFromIndex(id, production);
56
        if (oaf == null) {
57
            return null;
58
        }
59
        return OafParser.oaf2Result(oaf);
60
    }
61
    public Result fetchPublicationById(String id, boolean production) throws Exception {
62

    
63
        String oaf = fetchPublicationResult(id, production);
64

    
65
        if (oaf == null) {
66
            return null;
67
        }
68

    
69
        return OafParser.oaf2Result(oaf);
70
    }
71
    public Result fetchDatasetById(String id, boolean production) throws Exception {
72

    
73
        String oaf = fetchDatasetResult(id, production);
74
        if (oaf == null) {
75
            return null;
76
        }
77

    
78
        return OafParser.oaf2Result(oaf);
79
    }
80
    public Result fetchSoftwareById(String id, boolean production) throws Exception {
81

    
82
        String oaf = fetchSoftwareResult(id, production);
83
        if (oaf == null) {
84
            return null;
85
        }
86
        return OafParser.oaf2Result(oaf);
87
    }
88
    public Result fetchOtherById(String id, boolean production) throws Exception {
89

    
90
        String oaf = fetchOtherResult(id, production);
91
        if (oaf == null) {
92
            return null;
93
        }
94
        return OafParser.oaf2Result(oaf);
95
    }
96
//    public Result fetchDedupResultById(String id) throws Exception {
97
//
98
//        String oaf = fetchDedupPublicationResult(id);
99
//
100
//        if (oaf == null) {
101
//            oaf = fetchDedupDatasetResult(id);
102
//        }
103
//
104
//        if (oaf == null) {
105
//            return null;
106
//        }
107
//
108
//        return OafParser.oaf2Result(oaf);
109
//    }
110
    public SearchUtils getSearchUtils() {
111
        return searchUtils;
112
    }
113

    
114
    public void setSearchUtils(SearchUtils searchUtils) {
115
        this.searchUtils = searchUtils;
116
    }
117
}
(9-9/12)