Project

General

Profile

« Previous | Next » 

Revision 49865

change migration procedure: search first in beta then in production| add software | change directIndexHandler check for response

View differences:

OafParser.java
59 59
        NodeList nl = (NodeList) xpath.compile("/response/header/total/text()").evaluate(document, XPathConstants.NODESET);
60 60
        if (nl.getLength() > 0) {
61 61
            size= nl.item(0).getNodeValue();
62
        }else{
63
            nl = (NodeList) xpath.compile("//objIdentifier/text()").evaluate(document, XPathConstants.NODESET);
64
            if (nl.getLength() > 0) {
65
//                result.setOpenaireId(nl.item(0).getNodeValue());
66
                size="1";
67
            }
62 68
        }
63 69
        if(size!=null && Integer.parseInt(size)>0){
64 70
            result = new Result();
......
74 80
            if (nl.getLength() > 0) {
75 81
                result.setBestLicense(nl.item(0).getNodeValue());
76 82
            }
83
            nl = (NodeList) xpath.compile("//bestaccessright/@classid").evaluate(document, XPathConstants.NODESET);
84
            if (nl.getLength() > 0) {
85
                result.setBestLicense(nl.item(0).getNodeValue());
86
            }
77 87
            nl = (NodeList) xpath.compile("//embargoenddate/text()").evaluate(document, XPathConstants.NODESET);
78 88
            if (nl.getLength() > 0) {
79 89
                result.setEmbargoEndDate(nl.item(0).getNodeValue());
......
141 151
                    nl.item(0).getParentNode().removeChild(nl.item(0));
142 152
            }
143 153

  
144
            nl = (NodeList) xpath.compile("//rels/rel/to[@class='hasAuthor']").evaluate(document, XPathConstants.NODESET);
154
            nl = (NodeList) xpath.compile("//rel[@class='hasAuthor']").evaluate(document, XPathConstants.NODESET);
155
            System.out.println("Author length"+nl.getLength());
145 156
            if (nl.getLength() > 0) {
146 157
                for (int i = 0; i < nl.getLength(); i++) {
147 158
                    String ranking = ((Element)(nl.item(i).getParentNode())).getElementsByTagName("ranking").item(0).getTextContent();
......
150 161
                }
151 162

  
152 163
            }
164
            nl = (NodeList) xpath.compile("//creator/text()").evaluate(document, XPathConstants.NODESET);
165
            System.out.println("Creator length"+nl.getLength());
166
            if (nl.getLength() > 0) {
167
                for (int i = 0; i < nl.getLength(); i++) {
168
                    String ranking = ((Element)(nl.item(i).getParentNode())).getAttribute("rank");
169
                    String fullname =  (((Element)(nl.item(i).getParentNode())).getTextContent().replace(",", " "));
170
                    result.getAuthors().put(ranking,fullname);
171
                }
153 172

  
173
            }
174

  
154 175
            DOMSource domSource = new DOMSource(document);
155 176
            StringWriter writer = new StringWriter();
156 177
            StreamResult streamResult = new StreamResult(writer);
......
248 269
        return project;
249 270

  
250 271
    }
272
    public static Result oaf2Software(String oaf) throws ParserConfigurationException, IOException, SAXException, XPathExpressionException, TransformerException {
273
        Result result = null;
274
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
275
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
276
        InputSource is = new InputSource(new StringReader(oaf));
277
        Document document= dBuilder.parse(is);
278
        XPathFactory xPathfactory= XPathFactory.newInstance();
279
        XPath xpath = xPathfactory.newXPath();
251 280

  
281
        String size = null;
282
        NodeList nl = (NodeList) xpath.compile("/response/header/total/text()").evaluate(document, XPathConstants.NODESET);
283
        if (nl.getLength() > 0) {
284
            size= nl.item(0).getNodeValue();
285
        }
286
        System.out.println("size:"+size);
287
        if(size!=null && Integer.parseInt(size)>0){
288
            result = new Result();
289
            nl = (NodeList) xpath.compile("//field[@name = \"resultId\"]/@value").evaluate(document, XPathConstants.NODESET);
290
            if (nl.getLength() > 0) {
291
                result.setOpenaireId(nl.item(0).getNodeValue());
292
            }
293
            nl = (NodeList) xpath.compile("//field[@name = \"resulttypeid\"]/@value").evaluate(document, XPathConstants.NODESET);
294
            if (nl.getLength() > 0) {
295
                result.setResultType(nl.item(0).getNodeValue());
296
            }
297
            nl = (NodeList) xpath.compile("//field[@name = \"bestaccessright\"]/@value").evaluate(document, XPathConstants.NODESET);
298
            if (nl.getLength() > 0) {
299
                result.setBestLicense(nl.item(0).getNodeValue());
300
            }
301
            nl = (NodeList) xpath.compile("//field[@name = \"embargoenddate\"]/@value").evaluate(document, XPathConstants.NODESET);
302
            if (nl.getLength() > 0) {
303
                result.setEmbargoEndDate(nl.item(0).getNodeValue());
304
            }
305
            nl = (NodeList) xpath.compile("//field[@name = \"title\"]/@value").evaluate(document, XPathConstants.NODESET);
306
            if (nl.getLength() > 0) {
307
                result.setTitle(nl.item(0).getNodeValue());
308
            }
309
            //
310
            nl = (NodeList) xpath.compile("//field[@name = \"pid\"]").evaluate(document, XPathConstants.NODESET);
311
            System.out.println("size: pid"+nl.getLength());
312
            if (nl.getLength() > 0) {
313
                for (int i = 0; i < nl.getLength(); i++) {
314
                    NodeList list = (NodeList) xpath.compile("./field[@name = \"classid\"]/@value").evaluate(nl.item(i), XPathConstants.NODESET);
315
                    System.out.println("size: classid"+list.getLength());
316

  
317
                    if (list.getLength() > 0 && list.item(0).getNodeValue() !=null ) {
318

  
319
                        if (list.item(0).getNodeValue().equals("doi")) {
320
                            list = (NodeList) xpath.compile("./field[@name = \"value\"]/@value").evaluate(nl.item(i), XPathConstants.NODESET);
321
                            result.setDoi(list.item(0).getNodeValue());
322
                            result.setExternalUrl("http://dx.doi.org/" + result.getDoi());
323

  
324

  
325
                        } else if (list.item(0).getNodeValue().equals("pmc")) {
326
                            list = (NodeList) xpath.compile("./field[@name = \"value\"]/@value").evaluate(nl.item(i), XPathConstants.NODESET);
327
                            result.setDoi(list.item(0).getNodeValue());
328
                            result.setExternalUrl("http://dx.doi.org/" + result.getDoi());
329

  
330

  
331
                        }else if (list.item(0).getNodeValue().equals("orcidworkid")) {
332
                            list = (NodeList) xpath.compile("./field[@name = \"value\"]/@value").evaluate(nl.item(i), XPathConstants.NODESET);
333
                            result.setDoi(list.item(0).getNodeValue());
334
                            result.setExternalUrl("http://dx.doi.org/" + result.getDoi());
335

  
336

  
337
                        }else if (list.item(0).getNodeValue().equals("oai")) {
338
                            list = (NodeList) xpath.compile("./field[@name = \"value\"]/@value").evaluate(nl.item(i), XPathConstants.NODESET);
339
                            result.setDoi(list.item(0).getNodeValue());
340
                            result.setExternalUrl("http://dx.doi.org/" + result.getDoi());
341

  
342

  
343
                        }
344
                    }
345
                }
346
            }
347
            nl = (NodeList) xpath.compile("//rels/rel/to[@class='hasAuthor']").evaluate(document, XPathConstants.NODESET);
348
            if (nl.getLength() > 0) {
349
                for (int i = 0; i < nl.getLength(); i++) {
350
                    String ranking = ((Element)(nl.item(i).getParentNode())).getElementsByTagName("ranking").item(0).getTextContent();
351
                    String fullname =  (((Element)(nl.item(i).getParentNode())).getElementsByTagName("fullname").item(0).getTextContent().replace(",", " "));
352
                    result.getAuthors().put(ranking,fullname);
353
                }
354

  
355
            }
356
            if(result.getExternalUrl()==null){
357
//                nl = (NodeList) xpath.compile("//webresource/url/text()").evaluate(document, XPathConstants.NODESET);
358
//                if (nl.getLength() > 0) {
359
//                    result.setExternalUrl(nl.item(0).getNodeValue());
360
//                }
361
                nl = (NodeList) xpath.compile("//children/instance/licence[@classid='OPEN']").evaluate(document, XPathConstants.NODESET);
362
                if (nl.getLength() > 0) {
363
                    NodeList list = (NodeList) xpath.compile("./webresource/url/text()").evaluate(nl.item(0).getParentNode(), XPathConstants.NODESET);
364
                    if (list.getLength() > 0) {
365
                        result.setExternalUrl(list.item(0).getNodeValue());
366
                    }
367
                }else{
368
                    nl = (NodeList) xpath.compile("//children/instance/licence[@classid='EMBARGO']").evaluate(document, XPathConstants.NODESET);
369
                    if (nl.getLength() > 0) {
370
                        NodeList list = (NodeList) xpath.compile("./webresource/url/text()").evaluate(nl.item(0).getParentNode(), XPathConstants.NODESET);
371
                        if (list.getLength() > 0) {
372
                            result.setExternalUrl(list.item(0).getNodeValue());
373
                        }
374
                    }else{
375
                        nl = (NodeList) xpath.compile("//children/instance/licence[@classid='CLOSED']").evaluate(document, XPathConstants.NODESET);
376
                        if (nl.getLength() > 0) {
377
                            NodeList list = (NodeList) xpath.compile("./webresource/url/text()").evaluate(nl.item(0).getParentNode(), XPathConstants.NODESET);
378
                            if (list.getLength() > 0) {
379
                                result.setExternalUrl(list.item(0).getNodeValue());
380
                            }
381
                        }
382
                    }
383
                }
384
            }
385

  
386

  
387
            nl = (NodeList) xpath.compile("//response/header").evaluate(document, XPathConstants.NODESET);
388
            if(nl.getLength()>0){
389
                nl.item(0).getParentNode().removeChild(nl.item(0));
390
            }
391

  
392

  
393

  
394
            DOMSource domSource = new DOMSource(document);
395
            StringWriter writer = new StringWriter();
396
            StreamResult streamResult = new StreamResult(writer);
397
            TransformerFactory tf = TransformerFactory.newInstance();
398
            Transformer transformer = tf.newTransformer();
399
            transformer.transform(domSource, streamResult);
400
            result.setMetadataRecord(writer.toString());
401
            result.setCollectedFrom(ClaimUtils.COLLECTED_FROM_OPENAIRE);
402
            result.setRecordFormat(ClaimUtils.FORMAT_XML);
403
//            result.setFound(true);
404

  
405
        }
406
        return result;
407
    }
408

  
409

  
252 410
}

Also available in: Unified diff