Project

General

Profile

« Previous | Next » 

Revision 57125

Search utils, Project Handler, IndexResultHandler:
get search service url from properties
remove isProduction parameter
remove dedup result methods used in migration

-> update method calls and signatures accordingly

View differences:

modules/uoa-claims/trunk/src/test/java/eu/dnetlib/data/claims/TestClass.java
240 240
    @Test
241 241
    public void testHttpRequest() throws Exception {
242 242
        SearchUtils searchUtils= new SearchUtils();
243
        log.info(searchUtils.fetchPublicationXmlFromIndex("doajarticles::eb8a123eb82b25013b0001d0e2d1842b", false));
244
        log.info(searchUtils.fetchDatasetXmlFromIndex("doajarticles::eb8a123eb82b25013b0001d0e2d1842b", false));
243
        log.info(searchUtils.fetchPublicationXmlFromIndex("doajarticles::eb8a123eb82b25013b0001d0e2d1842b"));
244
        log.info(searchUtils.fetchDatasetXmlFromIndex("doajarticles::eb8a123eb82b25013b0001d0e2d1842b"));
245 245
    }
246 246

  
247 247
    @Test
248 248
    public void testXpath() throws Exception {
249
            Result r=indexResultHandler.fetchResultById("dedup_wf_001::88a1eedd1ffce63dccf51d8ce2053c85", false);
249
            Result r=indexResultHandler.fetchResultById("dedup_wf_001::88a1eedd1ffce63dccf51d8ce2053c85");
250 250
     }
251 251

  
252 252
    @Test
253 253
    public void testSoftwareXpath() throws Exception {
254 254
//        http://scoobydoo.di.uoa.gr:5000/search/software?softwareId=datacite____%3A%3Aabe9e916b29d028789d7ae3c6f79f254
255
        Result r=indexResultHandler.fetchSoftwareById("datacite____::abe9e916b29d028789d7ae3c6f79f254", false);
255
        Result r=indexResultHandler.fetchSoftwareById("datacite____::abe9e916b29d028789d7ae3c6f79f254");
256 256
        if(r!=null){
257 257
            System.out.println(r.toString());
258 258
        }
......
260 260
    }
261 261
    @Test
262 262
    public void testPublicationXpath() throws Exception {
263
        Result r=indexResultHandler.fetchPublicationById("od________18::5acd89ab4df2b877a7a208ea2a123a87", false);
263
        Result r=indexResultHandler.fetchPublicationById("od________18::5acd89ab4df2b877a7a208ea2a123a87");
264 264
        if(r!=null){
265 265
            System.out.println(r.toString());
266 266
        }
......
280 280
    @Test
281 281
    public void buildProject() throws Exception {
282 282
        String id = "arc_________::089188bbc5db213fb2b00a0d93043fc4";
283
        Project pr = projectHandler.fetchProjectByID(id,false);
283
        Project pr = projectHandler.fetchProjectByID(id);
284 284
        log.info(pr.toString());
285 285
        id="corda_______::404d91e07cd4d32fddd8fc636ad4daf7";
286
        pr = projectHandler.fetchProjectByID(id, false);
286
        pr = projectHandler.fetchProjectByID(id);
287 287
        log.info(pr.toString());
288 288

  
289 289
    }
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/utils/SearchUtils.java
27 27
 */
28 28
public class SearchUtils {
29 29
    private static final Logger logger = Logger.getLogger(SearchUtils.class);
30
    public static String searchAPIUrl=null;//"http://beta.services.openaire.eu:8480/search/";
30 31

  
31
    private static String searchUrl="http://beta.services.openaire.eu:8480/search/search?action=search";
32
    private static String apiUrlForResults="http://beta.services.openaire.eu:8480/search/api";//"http://api.openaire.eu/search";
33
//    private static String apiUrlForDedupResults="http://rudie.di.uoa.gr:8080/dnet-functionality-services-1.2.0-SNAPSHOT/api/";
34
    private static String apiUrlForProjects="http://beta.services.openaire.eu:8480/search/api";//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-1.2.0-SNAPSHOT/api/";
35

  
36
    private static String searchUrlProduction="http://services.openaire.eu:8480/search/search?action=search";
37
    private static String apiUrlForResultsProduction="http://services.openaire.eu:8480/search/api";//"http://api.openaire.eu/search";
38
    private static String apiUrlForProjectsProduction="http://services.openaire.eu:8480/search/api";//"http://rudie.di.uoa.gr:8080/dnet-functionality-services-1.2.0-SNAPSHOT/api/";
39

  
40

  
41 32
    private static String crossrefUrl="https://api.crossref.org/works?filter=doi:";
42 33
    private static String dataciteUrl="https://data.datacite.org/application/rdf+xml/";
43 34
    private static String dataciteNewAPIUrl="https://api.datacite.org/works/";
......
53 44

  
54 45
    }
55 46

  
56
    public static String fetchProjectXmlFromIndex(String id, boolean production) throws Exception{
57
            return getRequest(getProjectApiUrl(id, production));
47
    public String fetchProjectXmlFromIndex(String id) throws Exception{
48
            return getRequest(getProjectApiUrl(id));
58 49
    }
59 50

  
60 51
    /**
......
65 56
     * @return xml or null
66 57
     * @throws Exception
67 58
     */
68
    public static String fetchPublicationXmlFromIndex(String id, boolean production) throws Exception{
59
    public static String fetchPublicationXmlFromIndex(String id) throws Exception{
69 60

  
70
        String xml=getRequest(getPublicationApiUrl(id, production));
61
        String xml=getRequest(getPublicationApiUrl(id));
71 62
        if(getNumberOfResultsInAPIXML(xml)==0){
72 63
            xml=null;
73 64
        }
74 65
        return xml;
75 66
    }
76
    public static String fetchDedupXmlFromIndex(String id, boolean production) throws Exception{
77 67

  
78
        String xml= null;
79
            String objId=getResultObjIdentifierFromSearch(id,production);
80
            if(objId!=null){
81
                xml=getRequest(getPublicationApiUrl(objId, production));
82
            }
83
        return xml;
84
    }
85

  
86
    public static String fetchSoftwareXmlFromIndex(String id, boolean production) throws Exception{
87
        String xml=getRequest(getSoftwareApiUrl(id,production));
68
    public static String fetchSoftwareXmlFromIndex(String id) throws Exception{
69
        String xml=getRequest(getSoftwareApiUrl(id));
88 70
         return xml;
89 71
    }
90 72

  
91
    public static String fetchOtherXmlFromIndex(String id, boolean production) throws Exception{
92
        String xml=getRequest(getOtherApiUrl(id,production));
73
    public static String fetchOtherXmlFromIndex(String id) throws Exception{
74
        String xml=getRequest(getOtherApiUrl(id));
93 75
        return xml;
94 76
    }
95 77
    /**
......
101 83
     * @return xml
102 84
     * @throws Exception
103 85
     */
104
    public static String fetchDatasetXmlFromIndex(String id, boolean production) throws Exception{
86
    public String fetchDatasetXmlFromIndex(String id) throws Exception{
105 87

  
106
        String xml=getRequest(getDatasetApiUrl(id, production));
88
        String xml=getRequest(getDatasetApiUrl(id));
107 89
        if(getNumberOfResultsInAPIXML(xml)==0){
108 90
            xml=null;
109 91
        }
......
123 105
        return getRequest(getContextsAPIUrl(production)+suffix);
124 106
    }
125 107

  
126
     public static String getProjectApiUrl(String id, boolean production)  {
108
     public String getProjectApiUrl(String id)  {
127 109

  
128
        return ((production)?apiUrlForProjectsProduction:apiUrlForProjects)+"/projects?openaireProjectID="+id;
110
        return searchAPIUrl+"api/projects?openaireProjectID="+id;
129 111
    }
130 112

  
131
    public static String getDatasetApiUrl(String id, boolean production)  {
113
    public String getDatasetApiUrl(String id)  {
132 114

  
133
        return ((production)?apiUrlForResultsProduction:apiUrlForResults)+"/datasets?openaireDatasetID="+id;
115
        return searchAPIUrl+"api/datasets?openaireDatasetID="+id;
134 116
    }
135 117

  
136
    public static String getPublicationApiUrl(String id, boolean production)  {
118
    public static String getPublicationApiUrl(String id)  {
137 119

  
138
        return ((production)?apiUrlForResultsProduction:apiUrlForResults)+"/publications?openairePublicationID="+id;
120
        return searchAPIUrl+"api/publications?openairePublicationID="+id;
139 121
    }
140
    public static String  getSoftwareApiUrl(String id, boolean production)  {
141
        return ((production)?apiUrlForResultsProduction:apiUrlForResults)+"/software?openaireSoftwareID="+id;
122
    public static String  getSoftwareApiUrl(String id)  {
123
        return searchAPIUrl+"api/software?openaireSoftwareID="+id;
142 124
    }
143
    public static String  getOtherApiUrl(String id, boolean production)  {
144
        return ((production)?apiUrlForResultsProduction:apiUrlForResults)+"/other?openaireOtherID="+id;
125
    public static String  getOtherApiUrl(String id)  {
126
        return searchAPIUrl+"api/other?openaireOtherID="+id;
145 127
    }
146
//    public static String getDedupPublicationApiUrl(String id)  {
147
//
148
//        return apiUrlForDedupResults+"/publications?openairePublicationID="+id;
149
//    }
128

  
150 129
    private static String getDataciteUrl(String id)  {
151 130

  
152 131
        return dataciteNewAPIUrl+id;
......
161 140
        return ((production)?contextsAPIUrlProduction:contextsAPIUrl);
162 141
    }
163 142

  
164
    /**
165
     * Get result and objIdentifier  form openaire Search
166
     * @param resultdupid
167
     * @return
168
     */
169
    private static String getResultXMLByResultdupidSearchByUrl(String resultdupid, boolean production)  {
170
        String url= null;
171
        try {
172
             url = ((production)?searchUrlProduction:searchUrl)+"&sTransformer=results_openaire&query="+
173
                    URLEncoder.encode("(((deletedbyinference = false) AND (oaftype exact result)) )" +
174
                            " and (resultdupid exact " + resultdupid + ")", "UTF-8")
175
                    +"&size=10&locale=en_GB";
176
        } catch (UnsupportedEncodingException e) {
177
            logger.error("UnsupportedEncodingException",e);
178
        }
179
        return url;
180
    }
181
//    private static String getSoftwareXMLByIdSearchByUrl(String id, boolean production)  {
182
//        String url= null;
183
//        try {
184
//            url = ((production)?searchUrlProduction:searchUrl)+"&sTransformer=results_openaire&query="+
185
//                    URLEncoder.encode("(((deletedbyinference = false) AND (resulttypeid exact software) AND (oaftype exact result)) )" +
186
//                            " and (objIdentifier exact " + id + ")", "UTF-8")
187
//                    +"&size=1&locale=en_GB";
188
//        } catch (UnsupportedEncodingException e) {
189
//            logger.error("UnsupportedEncodingException",e);
190
//        }
191
//        return url;
192
//    }
193 143

  
194 144
    // HTTP GET request
195 145
    private static String getRequest(String url) throws Exception {
......
259 209
    }
260 210

  
261 211
    /**
262
     * Search in index for result with resultdupid
263
     * @param  resultdupid  Openaire Id
264
     * @return objIdentifier
265
     */
266
    private static String getResultObjIdentifierFromSearch(String resultdupid, boolean  production) throws Exception {
267
        String xml=getRequest(getResultXMLByResultdupidSearchByUrl(resultdupid,production));
268
        String objIdentifier=null;
269
            String size=null;
270
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
271
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
272
            InputSource inputSource= new InputSource(new StringReader(xml));
273
            Document document=dBuilder.parse(inputSource);
274
             XPathFactory xPathfactory= XPathFactory.newInstance();
275
            XPath xpath = xPathfactory.newXPath();
276
            NodeList nl = (NodeList) xpath.compile("//total/text()").evaluate(document, XPathConstants.NODESET);
277
            if (nl.getLength() > 0) {
278
                size= nl.item(0).getNodeValue();
279
            }
280
            if(size!=null && Integer.parseInt(size)>0){
281
                nl = (NodeList) xpath.compile("//field[@indexId='objIdentifier']/@value").evaluate(document, XPathConstants.NODESET);
282
                if (nl.getLength() > 0) {
283
                    objIdentifier=nl.item(0).getNodeValue();
284
                }
285
            }
286
        return objIdentifier;
287
    }
288

  
289
    /**
290 212
     *
291 213
     * @param xml : API result xml
292 214
     * @return number of results Found
......
321 243
    public void setClaimValidation(ClaimValidation claimValidation) {
322 244
        this.claimValidation = claimValidation;
323 245
    }
246

  
247
    public String getSearchAPIUrl() {
248
        return searchAPIUrl;
249
    }
250

  
251
    public void setSearchAPIUrl(String searchAPIUrl) {
252
        this.searchAPIUrl = searchAPIUrl;
253
    }
324 254
}
325 255

  
326 256

  
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/handler/ClaimHandler.java
181 181
        else if(type.equals(ClaimUtils.CONTEXT)){
182 182
            return ContextUtils.fetchContextById(id, useProductionIndex);
183 183
        }else if (type.equals(ClaimUtils.PROJECT)){
184
            Project project = projectHandler.fetchProjectByID(id, false);
184
            Project project = projectHandler.fetchProjectByID(id);
185 185
            if(project == null){
186
                project = projectHandler.fetchProjectByID(id, true);
186
                project = projectHandler.fetchProjectByID(id);
187 187
            }
188 188
            if(project == null){
189 189
                logger.error("Project with id:"+id + " couldn't be fetched.");
......
226 226
                IndexResultHandler indexResultHandler = new IndexResultHandler();
227 227
                Result result = null;
228 228
                if(type.equals(ClaimUtils.PUBLICATION)){
229
                    result = indexResultHandler.fetchPublicationById(id,useProductionIndex);
229
                    result = indexResultHandler.fetchPublicationById(id);
230 230

  
231 231
                }else if(type.equals(ClaimUtils.DATASET)){
232
                    result = indexResultHandler.fetchDatasetById(id,useProductionIndex);
232
                    result = indexResultHandler.fetchDatasetById(id);
233 233
                }else if(type.equals(ClaimUtils.SOFTWARE)){
234
                    result = indexResultHandler.fetchSoftwareById(id,useProductionIndex);
234
                    result = indexResultHandler.fetchSoftwareById(id);
235 235
                }else if(type.equals(ClaimUtils.OTHER)){
236
                    result = indexResultHandler.fetchOtherById(id,useProductionIndex);
236
                    result = indexResultHandler.fetchOtherById(id);
237 237
                }
238 238
                if(result == null){
239 239
                    logger.error("Record with id:"+id + " and type " + type + " couldn't be fetched from openaire.");
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/handler/IndexResultHandler.java
11 11

  
12 12
    SearchUtils searchUtils;
13 13

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

  
24
    private String fetchDatasetResult(String id, boolean production) throws Exception {
25
        return searchUtils.fetchDatasetXmlFromIndex(id, production);
24
    private String fetchDatasetResult(String id) throws Exception {
25
        return searchUtils.fetchDatasetXmlFromIndex(id);
26 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 27
    /**
35 28
     *Searches for both publications and datasets
36 29
     * @param id
37 30
     * @return Result or null
38 31
     * @throws Exception
39 32
     */
40
    public Result fetchResultById(String id, boolean production) throws Exception {
33
    public Result fetchResultById(String id) throws Exception {
41 34

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

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

  
48 41
        if (oaf == null) {
......
51 44

  
52 45
        return OafParser.oaf2Result(oaf);
53 46
    }
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 {
47
    public Result fetchPublicationById(String id) throws Exception {
62 48

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

  
65 51
        if (oaf == null) {
66 52
            return null;
......
68 54

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

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

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

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

  
90
        String oaf = fetchOtherResult(id, production);
76
        String oaf = fetchOtherResult(id);
91 77
        if (oaf == null) {
92 78
            return null;
93 79
        }
94 80
        return OafParser.oaf2Result(oaf);
95 81
    }
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 82
    public SearchUtils getSearchUtils() {
111 83
        return searchUtils;
112 84
    }
modules/uoa-claims/trunk/src/main/java/eu/dnetlib/data/claims/handler/ProjectHandler.java
22 22

  
23 23
    private static Logger logger = Logger.getLogger(ProjectHandler.class);
24 24

  
25
    private String fetchProjectById(String id, boolean production) throws Exception {
26
        return searchUtils.fetchProjectXmlFromIndex(id, production);
25
    private String fetchProjectById(String id) throws Exception {
26
        return searchUtils.fetchProjectXmlFromIndex(id);
27 27
    }
28 28

  
29
    public Project fetchProjectByID(String id, boolean production) throws Exception {
30
        return fetchProjectByOaf(fetchProjectById(id, production));
29
    public Project fetchProjectByID(String id) throws Exception {
30
        return fetchProjectByOaf(fetchProjectById(id));
31 31
    }
32 32

  
33 33
    public Project fetchProjectByOaf(String oaf) throws Exception {
modules/uoa-claims/trunk/src/main/resources/eu/dnetlib/data/claims/springContext-claims.properties
6 6
services.claims.useProductionIndex = false
7 7

  
8 8
services.claims.communityAPI = https://dev-openaire.d4science.org/openaire/community/
9

  
9
services.claims.searchAPIUrl = http://services.openaire.eu:8480/search/
10 10
#email properties
11 11
## EMAIL SETTINGS
12 12
services.claims.mail.host = smtp.gmail.com
modules/uoa-claims/trunk/src/main/resources/eu/dnetlib/data/claims/springContext-claims.xml
73 73
    <bean id="oafParser" class="eu.dnetlib.data.claims.parser.OafParser"></bean>
74 74
    <bean id="externalRecordParser" class="eu.dnetlib.data.claims.parser.ExternalRecordParser"></bean>
75 75
    <!-- end of Parsers -->
76
    <bean id="searchUtils" class="eu.dnetlib.data.claims.utils.SearchUtils"></bean>
76
    <bean id="searchUtils" class="eu.dnetlib.data.claims.utils.SearchUtils">
77
        <property name="searchAPIUrl" value="${services.claims.searchAPIUrl}"/>
77 78

  
79
    </bean>
80

  
78 81
    <bean id="claimValidation" class="eu.dnetlib.data.claims.utils.ClaimValidation">
79 82
        <property name="pathToSaveReport" value="${services.claims.reports.pathToSaveReport}"/>
80 83
    </bean>

Also available in: Unified diff