Merge pull request #12 from lap82/DS-1252-bte

Some minor changes, fix retrieve data from crossref response
This commit is contained in:
Kostas Stamatis
2013-10-22 22:29:37 -07:00
7 changed files with 47 additions and 25 deletions

View File

@@ -79,7 +79,7 @@ public class ArXivService
throws IOException, HttpException
{
List<Record> results = new ArrayList<Record>();
if (!ConfigurationManager.getBooleanProperty("remoteservice.demo"))
if (!ConfigurationManager.getBooleanProperty(SubmissionLookupService.CFG_MODULE, "remoteservice.demo"))
{
GetMethod method = null;
try
@@ -100,9 +100,9 @@ public class ArXivService
if (statusCode != HttpStatus.SC_OK)
{
if (statusCode == HttpStatus.SC_BAD_REQUEST)
throw new RuntimeException("Query arXiv non valida");
throw new RuntimeException("arXiv query is not valid");
else
throw new RuntimeException("Chiamata http fallita: "
throw new RuntimeException("Http call failed: "
+ method.getStatusLine());
}

View File

@@ -70,13 +70,13 @@ public class CrossRefService
try
{
if (!ConfigurationManager
.getBooleanProperty("remoteservice.demo"))
.getBooleanProperty(SubmissionLookupService.CFG_MODULE, "remoteservice.demo"))
{
GetMethod method = null;
try
{
String apiKey = ConfigurationManager
.getProperty("crossref.api-key");
.getProperty(SubmissionLookupService.CFG_MODULE, "crossref.api-key");
HttpClient client = new HttpClient();
client.setConnectionTimeout(timeout);
@@ -113,8 +113,9 @@ public class CrossRefService
.getResponseBodyAsStream());
Element xmlRoot = inDoc.getDocumentElement();
Element dataRoot = XMLUtils.getSingleElement(
xmlRoot, "query");
Element queryResult = XMLUtils.getSingleElement(xmlRoot, "query_result");
Element body = XMLUtils.getSingleElement(queryResult, "body");
Element dataRoot = XMLUtils.getSingleElement(body, "query");
crossitem = CrossRefUtils
.convertCrossRefDomToRecord(dataRoot);
@@ -142,7 +143,7 @@ public class CrossRefService
}
catch (RuntimeException rt)
{
rt.printStackTrace();
log.error(rt.getMessage(), rt);
}
}
}
@@ -191,7 +192,7 @@ public class CrossRefService
if (statusCode != HttpStatus.SC_OK)
{
throw new RuntimeException("Chiamata http fallita: "
throw new RuntimeException("Http call failed:: "
+ method.getStatusLine());
}

View File

@@ -15,6 +15,7 @@ import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import org.dspace.core.Context;
import gr.ekt.bte.core.DataLoader;
import gr.ekt.bte.core.DataLoadingSpec;
@@ -22,7 +23,6 @@ import gr.ekt.bte.core.Record;
import gr.ekt.bte.core.RecordSet;
import gr.ekt.bte.core.StringValue;
import gr.ekt.bte.dataloader.FileDataLoader;
import gr.ekt.bte.exceptions.MalformedSourceException;
/**
@@ -53,13 +53,6 @@ public class MultipleSubmissionLookupDataLoader implements DataLoader
String type = null; // the type of the upload file (bibtex, etc.)
/**
* Default constructor
*/
public MultipleSubmissionLookupDataLoader()
{
}
/*
* (non-Javadoc)
*
@@ -148,7 +141,7 @@ public class MultipleSubmissionLookupDataLoader implements DataLoader
SubmissionLookupDataLoader provider = (SubmissionLookupDataLoader) genProvider;
// Provider must support DOI
if (provider.getSupportedIdentifiers().contains(
if (!provider.getSupportedIdentifiers().contains(
SubmissionLookupDataLoader.DOI))
{
continue;
@@ -174,12 +167,24 @@ public class MultipleSubmissionLookupDataLoader implements DataLoader
{
if (doiToSearch.size() > 0)
{
pPublications = provider.getByDOIs(null, doiToSearch);
Context context = null;
try {
context = new Context();
pPublications = provider.getByDOIs(context, doiToSearch);
}
catch (Exception e) {
log.error(e.getMessage(), e);
}
finally {
if(context!=null && context.isValid()) {
context.abort();
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
log.error(e.getMessage(), e);
}
if (pPublications != null)
{

View File

@@ -94,7 +94,7 @@ public class PubmedService
public List<Record> search(String query) throws IOException, HttpException
{
List<Record> results = null;
if (!ConfigurationManager.getBooleanProperty("remoteservice.demo"))
if (!ConfigurationManager.getBooleanProperty(SubmissionLookupService.CFG_MODULE, "remoteservice.demo"))
{
GetMethod method = null;
try
@@ -141,15 +141,19 @@ public class PubmedService
idList, "Id");
results = getByPubmedIDs(pubmedIDs);
}
catch (ParserConfigurationException e)
catch (ParserConfigurationException e1)
{
e.printStackTrace();
log.error(e1.getMessage(), e1);
}
catch (SAXException e1)
{
log.error(e1.getMessage(), e1);
}
}
catch (Exception e1)
{
log.error(e1.getMessage(), e1);
}
finally
{
if (method != null)
@@ -209,7 +213,7 @@ public class PubmedService
SAXException
{
List<Record> results = new ArrayList<Record>();
if (!ConfigurationManager.getBooleanProperty("remoteservice.demo"))
if (!ConfigurationManager.getBooleanProperty(SubmissionLookupService.CFG_MODULE, "remoteservice.demo"))
{
GetMethod method = null;
try

View File

@@ -30,6 +30,7 @@ import org.dspace.submit.util.SubmissionLookupDTO;
*/
public class SubmissionLookupService
{
public static final String CFG_MODULE = "submission-lookup";
public static final String SL_NAMESPACE_PREFIX = "http://www.dspace.org/sl/";

View File

@@ -0,0 +1,11 @@
#---------------------------------------------------------------#
#------------SUBMISSION LOOKUP CONFIGURATIONS-------------------#
#---------------------------------------------------------------#
# This file contains configuration for retrieve external data #
#---------------------------------------------------------------#
# The API key "is" the email address you use to register on CrossRef
crossref.api-key = noapi-key
# Set to true to used a demo service
remoteservice.demo = false

View File

@@ -108,7 +108,7 @@
<!-- Converts an input value to an output one -->
<bean name="mapConverter_arxivSubject" class="org.dspace.submit.lookup.MapConverterModifier">
<constructor-arg value="apConverter_arxivSubject Modifier"/>
<constructor-arg value="mapConverter_arxivSubject Modifier"/>
<property name="mappingFile" value="${dspace.install.dir}/config/crosswalks/mapConverter-arxivSubject.properties"/>
<property name="fieldKeys">
<list>