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

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

    
39
        String oaf = fetchPublicationResult(id, production);
40

    
41
        if (oaf == null) {
42
            oaf = fetchDatasetResult(id, production);
43
        }
44

    
45
        if (oaf == null) {
46
            return null;
47
        }
48

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

    
60
        String oaf = fetchPublicationResult(id, production);
61

    
62
        if (oaf == null) {
63
            return null;
64
        }
65

    
66
        return OafParser.oaf2Result(oaf);
67
    }
68
    public Result fetchDatasetById(String id, boolean production) throws Exception {
69

    
70
        String oaf = fetchDatasetResult(id, production);
71
        if (oaf == null) {
72
            return null;
73
        }
74

    
75
        return OafParser.oaf2Result(oaf);
76
    }
77
    public Result fetchSoftwareById(String id, boolean production) throws Exception {
78

    
79
        String oaf = fetchSoftwareResult(id, production);
80
        if (oaf == null) {
81
            return null;
82
        }
83
        return OafParser.oaf2Result(oaf);
84
    }
85
//    public Result fetchDedupResultById(String id) throws Exception {
86
//
87
//        String oaf = fetchDedupPublicationResult(id);
88
//
89
//        if (oaf == null) {
90
//            oaf = fetchDedupDatasetResult(id);
91
//        }
92
//
93
//        if (oaf == null) {
94
//            return null;
95
//        }
96
//
97
//        return OafParser.oaf2Result(oaf);
98
//    }
99
    public SearchUtils getSearchUtils() {
100
        return searchUtils;
101
    }
102

    
103
    public void setSearchUtils(SearchUtils searchUtils) {
104
        this.searchUtils = searchUtils;
105
    }
106
}
(9-9/12)