use of uk.ac.ebi.spot.goci.service.exception.PubmedLookupException in project goci by EBISPOT.
the class DefaultPubMedSearchService method findPublicationSummary.
public Study findPublicationSummary(String pubmedId) throws PubmedLookupException {
String summaryString;
if (pubmedRoot != null && pubmedGwasSummary != null) {
summaryString = pubmedRoot.concat(pubmedGwasSummary);
} else {
throw new PubmedLookupException("Unable to search pubmed - no URL configured. " + "Set pubmed.root, pubmed.gwas.summary and pubmed.xml.version in your config!");
}
Document response = null;
// Run query and create study object
try {
response = dispatchSearch(summaryString.replace("{idlist}", pubmedId) + xmlVersion);
NodeList docSumNodes = response.getElementsByTagName("DocumentSummary");
// The document summary is present then we should have a publication
if (docSumNodes.getLength() > 0) {
Study newStudy = new Study();
// Assuming here we only have one document summary as pubmed id should correspond to one publication
Node docSumNode = docSumNodes.item(0);
// Initialize study attributes
String pmid = null;
String title = "";
Date pubDate = null;
String author = "";
String publication = "";
// Get the ID element (should only be one, take first regardless)
Element study = (Element) docSumNode;
pmid = study.getAttribute("uid");
if (study.getElementsByTagName("error").item(0) != null) {
author = null;
title = null;
publication = null;
pubDate = null;
} else {
title = study.getElementsByTagName("Title").item(0).getTextContent();
publication = study.getElementsByTagName("Source").item(0).getTextContent();
author = study.getElementsByTagName("SortFirstAuthor").item(0).getTextContent();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String date = study.getElementsByTagName("SortPubDate").item(0).getTextContent();
if (date.contains("/")) {
date = date.replace("/", "-");
}
java.util.Date studyDate = null;
try {
studyDate = format.parse(date);
} catch (ParseException e1) {
e1.printStackTrace();
}
pubDate = new Date(studyDate.getTime());
}
if (pmid != null) {
if (author != null && pubDate != null && publication != null && title != null) {
newStudy.setAuthor(author);
newStudy.setPubmedId(pmid);
newStudy.setPublication(publication);
newStudy.setTitle(title);
newStudy.setPublicationDate(pubDate);
}
}
return newStudy;
} else {
throw new PubmedLookupException("Couldn't find pubmed id " + pubmedId + " in PubMed");
}
} catch (IOException e) {
throw new PubmedLookupException("Couldn't find pubmed id " + pubmedId + " in PubMed", e);
}
}
Aggregations