Skip to content

Commit

Permalink
Merge pull request #12 from lap82/DS-1252-bte
Browse files Browse the repository at this point in the history
 Some minor changes, fix retrieve data from crossref response
  • Loading branch information
Kostas Stamatis committed Oct 23, 2013
2 parents 74e6773 + 0edac18 commit e2e3be9
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 25 deletions.
Expand Up @@ -79,7 +79,7 @@ private List<Record> search(String query, String arxivid, int max_result)
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
Expand All @@ -100,9 +100,9 @@ private List<Record> search(String query, String arxivid, int max_result)
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());
}

Expand Down
Expand Up @@ -70,13 +70,13 @@ public List<Record> search(Context context, Set<String> dois)
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);
Expand Down Expand Up @@ -113,8 +113,9 @@ public List<Record> search(Context context, Set<String> dois)
.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);
Expand Down Expand Up @@ -142,7 +143,7 @@ public List<Record> search(Context context, Set<String> dois)
}
catch (RuntimeException rt)
{
rt.printStackTrace();
log.error(rt.getMessage(), rt);
}
}
}
Expand Down Expand Up @@ -191,7 +192,7 @@ public List<Record> search(Context context, String title, String authors,

if (statusCode != HttpStatus.SC_OK)
{
throw new RuntimeException("Chiamata http fallita: "
throw new RuntimeException("Http call failed:: "
+ method.getStatusLine());
}

Expand Down
Expand Up @@ -15,14 +15,14 @@
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;
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;

/**
Expand Down Expand Up @@ -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)
*
Expand Down Expand Up @@ -148,7 +141,7 @@ public RecordSet getRecords() throws MalformedSourceException
SubmissionLookupDataLoader provider = (SubmissionLookupDataLoader) genProvider;

// Provider must support DOI
if (provider.getSupportedIdentifiers().contains(
if (!provider.getSupportedIdentifiers().contains(
SubmissionLookupDataLoader.DOI))
{
continue;
Expand All @@ -174,12 +167,24 @@ public RecordSet getRecords() throws MalformedSourceException
{
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)
{
Expand Down
Expand Up @@ -94,7 +94,7 @@ public List<Record> search(String title, String author, int year)
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
Expand Down Expand Up @@ -141,15 +141,19 @@ public List<Record> search(String query) throws IOException, HttpException
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)
Expand Down Expand Up @@ -209,7 +213,7 @@ public List<Record> getByPubmedIDs(List<String> pubmedIDs)
SAXException
{
List<Record> results = new ArrayList<Record>();
if (!ConfigurationManager.getBooleanProperty("remoteservice.demo"))
if (!ConfigurationManager.getBooleanProperty(SubmissionLookupService.CFG_MODULE, "remoteservice.demo"))
{
GetMethod method = null;
try
Expand Down
Expand Up @@ -30,6 +30,7 @@
*/
public class SubmissionLookupService
{
public static final String CFG_MODULE = "submission-lookup";

public static final String SL_NAMESPACE_PREFIX = "http://www.dspace.org/sl/";

Expand Down
11 changes: 11 additions & 0 deletions dspace/config/modules/submission-lookup.cfg
@@ -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
2 changes: 1 addition & 1 deletion dspace/config/spring/api/bte.xml
Expand Up @@ -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>
Expand Down

0 comments on commit e2e3be9

Please sign in to comment.