Skip to content

Commit

Permalink
bte in submission workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostas Stamatis committed Oct 16, 2013
1 parent f5c57d1 commit 325c862
Show file tree
Hide file tree
Showing 15 changed files with 609 additions and 265 deletions.
12 changes: 6 additions & 6 deletions dspace-api/pom.xml
Expand Up @@ -444,14 +444,14 @@
<version>0.82</version>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.3</version>
<groupId>gr.ekt.bte</groupId>
<artifactId>bte-core</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.jbibtex</groupId>
<artifactId>jbibtex</artifactId>
<version>1.0.0</version>
<groupId>gr.ekt.bte</groupId>
<artifactId>bte-io</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
Expand Down
Expand Up @@ -7,19 +7,18 @@
*/
package org.dspace.submit.lookup;

import gr.ekt.bte.core.Record;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.httpclient.HttpException;
import org.apache.commons.lang.StringUtils;
import org.dspace.core.Context;
import org.dspace.submit.importer.arxiv.ArXivItem;
import org.dspace.submit.util.SubmissionLookupPublication;

public class ArXivLookupProvider extends ConfigurableLookupProvider {
private ArXivService arXivService;
Expand All @@ -45,20 +44,20 @@ public boolean isSearchProvider() {
}

@Override
public List<SubmissionLookupPublication> getByIdentifier(
Context context, Map<String, String> keys) throws HttpException, IOException {
List<SubmissionLookupPublication> results = new ArrayList<SubmissionLookupPublication>();
public List<Record> getByIdentifier(
Context context, Map<String, Set<String>> keys) throws HttpException, IOException {
List<Record> results = new ArrayList<Record>();
if (keys != null) {
String doi = keys.get(DOI);
String arxivid = keys.get(ARXIV);
Set<String> dois = keys.get(DOI);
Set<String> arxivids = keys.get(ARXIV);
List<ArXivItem> items = new ArrayList<ArXivItem>();
if (StringUtils.isNotBlank(doi)) {
Set<String> dois = new HashSet<String>();
dois.add(doi);
if (dois!=null && dois.size()>0) {
items.addAll(arXivService.getByDOIs(dois));
}
if (StringUtils.isNotBlank(arxivid)) {
items.add(arXivService.getByArXivIDs(arxivid));
if (arxivids!=null && arxivids.size()>0) {
for (String arxivid : arxivids){
items.add(arXivService.getByArXivIDs(arxivid));
}
}

for (ArXivItem item : items) {
Expand All @@ -69,9 +68,9 @@ public List<SubmissionLookupPublication> getByIdentifier(
}

@Override
public List<SubmissionLookupPublication> search(Context context, String title,
public List<Record> search(Context context, String title,
String author, int year) throws HttpException, IOException {
List<SubmissionLookupPublication> results = new ArrayList<SubmissionLookupPublication>();
List<Record> results = new ArrayList<Record>();
List<ArXivItem> items = arXivService.searchByTerm(title, author, year);
for (ArXivItem item : items) {
results.add(convert(item));
Expand All @@ -82,19 +81,5 @@ public List<SubmissionLookupPublication> search(Context context, String title,
@Override
public String getShortName() {
return "arxiv";
}

@Override
public List<SubmissionLookupPublication> getByDOIs(Context context, Set<String> doiToSearch)
throws HttpException, IOException {
List<SubmissionLookupPublication> results = new ArrayList<SubmissionLookupPublication>();
if (doiToSearch != null && doiToSearch.size() > 0) {
List<ArXivItem> items = arXivService.getByDOIs(doiToSearch);

for (ArXivItem item : items) {
results.add(convert(item));
}
}
return results;
}
}
}
Expand Up @@ -7,15 +7,186 @@
*/
package org.dspace.submit.lookup;

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.exceptions.MalformedSourceException;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.httpclient.HttpException;
import org.apache.commons.lang.StringUtils;
import org.dspace.core.Context;
import org.dspace.submit.util.SubmissionLookupPublication;


public abstract class ConfigurableLookupProvider implements SubmissionLookupProvider {
protected SubmissionLookupPublication convert(Object bean) {

Map<String, Set<String>> identifiers; //Searching by identifiers (DOI ...)
Map<String, Set<String>> searchTerms; //Searching by author, title, date

Map<String, String> fieldMap; //mapping between service fields and local intermediate fields

protected Record convert(Object bean) {
try {
return SubmissionLookupUtils.convert(getShortName(), bean);
return convert(getShortName(), bean);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}

@Override
public List<Record> getByDOIs(Context context, Set<String> doiToSearch)
throws HttpException, IOException {

Map<String, Set<String>> keys = new HashMap<String, Set<String>>();
keys.put(DOI, doiToSearch);

return getByIdentifier(context, keys);
}

//BTE Data Loader interface methods
@Override
public RecordSet getRecords() throws MalformedSourceException {

RecordSet recordSet = new RecordSet();

List<Record> results = null;

try {
if (getIdentifiers()!=null){ //Search by identifiers
results = getByIdentifier(null, getIdentifiers());
}
else {
String title = getIdentifiers().get("title")!=null?getIdentifiers().get("title").iterator().next():null;
String authors = getIdentifiers().get("authors")!=null?getIdentifiers().get("authors").iterator().next():null;
String year = getIdentifiers().get("year")!=null?getIdentifiers().get("year").iterator().next():null;
int yearInt = Integer.parseInt(year);
results = search(null, title, authors, yearInt);
}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

if (results != null){
for (Record record : results){
recordSet.addRecord(record);
}
}

return recordSet;
}

@Override
public RecordSet getRecords(DataLoadingSpec arg0)
throws MalformedSourceException {

return getRecords();
}

public Map<String, Set<String>> getIdentifiers() {
return identifiers;
}

public void setIdentifiers(Map<String, Set<String>> identifiers) {
this.identifiers = identifiers;
}

public Map<String, Set<String>> getSearchTerms() {
return searchTerms;
}

public void setSearchTerms(Map<String, Set<String>> searchTerms) {
this.searchTerms = searchTerms;
}

public Map<String, String> getFieldMap() {
return fieldMap;
}

public void setFieldMap(Map<String, String> fieldMap) {
this.fieldMap = fieldMap;
}

public Record convert(String shortName,
Object bean) throws SecurityException, NoSuchMethodException,
IllegalArgumentException, IllegalAccessException,
InvocationTargetException {
Record publication = new SubmissionLookupPublication(
shortName);
Field[] fields = bean.getClass().getDeclaredFields();
for (Field field : fields) {
if (field.getType() == String.class) {
Method getter = bean.getClass().getMethod(
"get" + field.getName().substring(0, 1).toUpperCase()
+ field.getName().substring(1));

String value = (String) getter.invoke(bean);

addMetadata(shortName, publication, field.getName(), value);

} else if (field.getType() == List.class) {
ParameterizedType pt = (ParameterizedType) field
.getGenericType();

Method getter = bean.getClass().getMethod(
"get" + field.getName().substring(0, 1).toUpperCase()
+ field.getName().substring(1));

if (pt.getActualTypeArguments()[0] instanceof GenericArrayType) { // nomi
// di
// persone
List<String[]> values = (List<String[]>) getter.invoke(bean);
if (values != null) {
for (String[] nvalue : values) {
String value = nvalue[1] + ", " + nvalue[0];
addMetadata(shortName, publication,
field.getName(), value);
}
}
} else { // metadati ripetibili
List<String> values = (List<String>) getter.invoke(bean);
if (values != null) {
for (String value : values) {
addMetadata(shortName, publication,
field.getName(), value);
}
}
}
}
}
return publication;
}

private void addMetadata(String config, Record publication, String name, String value) {
if (StringUtils.isBlank(value))
return;

String md = null;
if (fieldMap!=null){
md = this.fieldMap.get(name);
}

if (StringUtils.isBlank(md)) {
return;
} else {
md = md.trim();
}

if (publication.isMutable()){
publication.makeMutable().addValue(md, new StringValue(value));
}
}
}
Expand Up @@ -7,10 +7,11 @@
*/
package org.dspace.submit.lookup;

import gr.ekt.bte.core.Record;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -20,7 +21,6 @@
import org.apache.commons.httpclient.HttpException;
import org.dspace.core.Context;
import org.dspace.submit.importer.crossref.CrossrefItem;
import org.dspace.submit.util.SubmissionLookupPublication;
import org.jdom.JDOMException;
import org.xml.sax.SAXException;

Expand All @@ -44,12 +44,11 @@ public List<String> getSupportedIdentifiers() {
}

@Override
public List<SubmissionLookupPublication> getByIdentifier(Context context,
Map<String, String> keys) throws HttpException, IOException {
public List<Record> getByIdentifier(Context context,
Map<String, Set<String>> keys) throws HttpException, IOException {
if (keys != null && keys.containsKey(DOI)) {
Set<String> dois = new HashSet<String>();
dois.add(keys.get(DOI));
List<SubmissionLookupPublication> results = new ArrayList<SubmissionLookupPublication>();
Set<String> dois = keys.get(DOI);
List<Record> results = new ArrayList<Record>();
List<CrossrefItem> items = null;
try {
items = crossrefService.search(context, dois);
Expand All @@ -71,9 +70,9 @@ public List<SubmissionLookupPublication> getByIdentifier(Context context,
}

@Override
public List<SubmissionLookupPublication> search(Context context, String title,
public List<Record> search(Context context, String title,
String author, int year) throws HttpException, IOException {
List<SubmissionLookupPublication> results = new ArrayList<SubmissionLookupPublication>();
List<Record> results = new ArrayList<Record>();
List<CrossrefItem> items = null;
items = crossrefService.search(context, title, author, year, 10);
if (items != null) {
Expand All @@ -94,29 +93,4 @@ public boolean isSearchProvider() {
public String getShortName() {
return "crossref";
}

@Override
public List<SubmissionLookupPublication> getByDOIs(Context context, Set<String> doiToSearch)
throws HttpException, IOException {
if (doiToSearch != null) {
List<SubmissionLookupPublication> results = new ArrayList<SubmissionLookupPublication>();
List<CrossrefItem> items = null;
try {
items = crossrefService.search(context, doiToSearch);
} catch (JDOMException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (ParserConfigurationException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (SAXException e) {
throw new RuntimeException(e.getMessage(), e);
}
if (items != null) {
for (CrossrefItem p : items) {
results.add(convert(p));
}
return results;
}
}
return null;
}
}

0 comments on commit 325c862

Please sign in to comment.