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:

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

  

Also available in: Unified diff