Code formatted with DSpace conventions

This commit is contained in:
Pascarelli Luigi Andrea
2013-10-22 12:37:50 +02:00
parent 02dd97da40
commit 6c2fb7a781
31 changed files with 3588 additions and 2773 deletions

View File

@@ -39,106 +39,133 @@ import gr.ekt.bte.exceptions.MalformedSourceException;
* @author Kostas Stamatis
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*
*
*/
public class ArXivFileDataLoader extends FileDataLoader {
public class ArXivFileDataLoader extends FileDataLoader
{
private static Logger log = Logger.getLogger(ArXivFileDataLoader.class);
Map<String, String> fieldMap; //mapping between service fields and local intermediate fields
/**
* Empty constructor
*/
public ArXivFileDataLoader() {
}
private static Logger log = Logger.getLogger(ArXivFileDataLoader.class);
/**
* @param filename
*/
public ArXivFileDataLoader(String filename) {
super(filename);
}
Map<String, String> fieldMap; // mapping between service fields and local
// intermediate fields
/* (non-Javadoc)
* @see gr.ekt.bte.core.DataLoader#getRecords()
*/
@Override
public RecordSet getRecords() throws MalformedSourceException {
RecordSet recordSet = new RecordSet();
/**
* Empty constructor
*/
public ArXivFileDataLoader()
{
}
try {
InputStream inputStream = new FileInputStream(new File(filename));
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
/**
* @param filename
*/
public ArXivFileDataLoader(String filename)
{
super(filename);
}
DocumentBuilder db = factory.newDocumentBuilder();
Document inDoc = db.parse(inputStream);
/*
* (non-Javadoc)
*
* @see gr.ekt.bte.core.DataLoader#getRecords()
*/
@Override
public RecordSet getRecords() throws MalformedSourceException
{
Element xmlRoot = inDoc.getDocumentElement();
List<Element> dataRoots = XMLUtils.getElementList(xmlRoot,
"entry");
RecordSet recordSet = new RecordSet();
for (Element dataRoot : dataRoots)
{
Record record = ArxivUtils.convertArxixDomToRecord(dataRoot);
if (record != null)
{
recordSet.addRecord(convertFields(record));
}
}
} catch (FileNotFoundException e) {
log.error(e.getMessage(), e);
} catch (ParserConfigurationException e) {
log.error(e.getMessage(), e);
} catch (SAXException e) {
log.error(e.getMessage(), e);
} catch (IOException e) {
log.error(e.getMessage(), e);
}
return recordSet;
}
try
{
InputStream inputStream = new FileInputStream(new File(filename));
/* (non-Javadoc)
* @see gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
*/
@Override
public RecordSet getRecords(DataLoadingSpec spec)
throws MalformedSourceException {
return getRecords();
}
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
public Record convertFields(Record publication) {
for (String fieldName : fieldMap.keySet()) {
String md = null;
if (fieldMap!=null){
md = this.fieldMap.get(fieldName);
}
DocumentBuilder db = factory.newDocumentBuilder();
Document inDoc = db.parse(inputStream);
if (StringUtils.isBlank(md)) {
continue;
} else {
md = md.trim();
}
Element xmlRoot = inDoc.getDocumentElement();
List<Element> dataRoots = XMLUtils.getElementList(xmlRoot, "entry");
if (publication.isMutable()){
List<Value> values = publication.getValues(fieldName);
publication.makeMutable().removeField(fieldName);
publication.makeMutable().addField(md, values);
}
}
return publication;
}
for (Element dataRoot : dataRoots)
{
Record record = ArxivUtils.convertArxixDomToRecord(dataRoot);
if (record != null)
{
recordSet.addRecord(convertFields(record));
}
}
}
catch (FileNotFoundException e)
{
log.error(e.getMessage(), e);
}
catch (ParserConfigurationException e)
{
log.error(e.getMessage(), e);
}
catch (SAXException e)
{
log.error(e.getMessage(), e);
}
catch (IOException e)
{
log.error(e.getMessage(), e);
}
public void setFieldMap(Map<String, String> fieldMap) {
this.fieldMap = fieldMap;
}
return recordSet;
}
/*
* (non-Javadoc)
*
* @see
* gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
*/
@Override
public RecordSet getRecords(DataLoadingSpec spec)
throws MalformedSourceException
{
return getRecords();
}
public Record convertFields(Record publication)
{
for (String fieldName : fieldMap.keySet())
{
String md = null;
if (fieldMap != null)
{
md = this.fieldMap.get(fieldName);
}
if (StringUtils.isBlank(md))
{
continue;
}
else
{
md = md.trim();
}
if (publication.isMutable())
{
List<Value> values = publication.getValues(fieldName);
publication.makeMutable().removeField(fieldName);
publication.makeMutable().addField(md, values);
}
}
return publication;
}
public void setFieldMap(Map<String, String> fieldMap)
{
this.fieldMap = fieldMap;
}
}

View File

@@ -25,60 +25,74 @@ import org.dspace.core.Context;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class ArXivOnlineDataLoader extends NetworkSubmissionLookupDataLoader {
private ArXivService arXivService = new ArXivService();
private boolean searchProvider = true;
public class ArXivOnlineDataLoader extends NetworkSubmissionLookupDataLoader
{
private ArXivService arXivService = new ArXivService();
public void setArXivService(ArXivService arXivService) {
this.arXivService = arXivService;
}
private boolean searchProvider = true;
@Override
public List<String> getSupportedIdentifiers() {
return Arrays.asList(new String[] { ARXIV, DOI });
}
public void setArXivService(ArXivService arXivService)
{
this.arXivService = arXivService;
}
public void setSearchProvider(boolean searchProvider) {
this.searchProvider = searchProvider;
}
@Override
public List<String> getSupportedIdentifiers()
{
return Arrays.asList(new String[] { ARXIV, DOI });
}
@Override
public boolean isSearchProvider() {
return searchProvider;
}
public void setSearchProvider(boolean searchProvider)
{
this.searchProvider = searchProvider;
}
@Override
public List<Record> getByIdentifier(Context context,
Map<String, Set<String>> keys) throws HttpException, IOException {
List<Record> results = new ArrayList<Record>();
if (keys != null) {
Set<String> dois = keys.get(DOI);
Set<String> arxivids = keys.get(ARXIV);
List<Record> items = new ArrayList<Record>();
if (dois != null && dois.size() > 0) {
items.addAll(arXivService.getByDOIs(dois));
}
if (arxivids != null && arxivids.size() > 0) {
for (String arxivid : arxivids) {
items.add(arXivService.getByArXivIDs(arxivid));
}
}
@Override
public boolean isSearchProvider()
{
return searchProvider;
}
for (Record item : items) {
results.add(convertFields(item));
}
}
return results;
}
@Override
public List<Record> getByIdentifier(Context context,
Map<String, Set<String>> keys) throws HttpException, IOException
{
List<Record> results = new ArrayList<Record>();
if (keys != null)
{
Set<String> dois = keys.get(DOI);
Set<String> arxivids = keys.get(ARXIV);
List<Record> items = new ArrayList<Record>();
if (dois != null && dois.size() > 0)
{
items.addAll(arXivService.getByDOIs(dois));
}
if (arxivids != null && arxivids.size() > 0)
{
for (String arxivid : arxivids)
{
items.add(arXivService.getByArXivIDs(arxivid));
}
}
@Override
public List<Record> search(Context context, String title, String author,
int year) throws HttpException, IOException {
List<Record> results = new ArrayList<Record>();
List<Record> items = arXivService.searchByTerm(title, author, year);
for (Record item : items) {
results.add(convertFields(item));
}
return results;
}
for (Record item : items)
{
results.add(convertFields(item));
}
}
return results;
}
@Override
public List<Record> search(Context context, String title, String author,
int year) throws HttpException, IOException
{
List<Record> results = new ArrayList<Record>();
List<Record> items = arXivService.searchByTerm(title, author, year);
for (Record item : items)
{
results.add(convertFields(item));
}
return results;
}
}

View File

@@ -123,7 +123,8 @@ public class ArXivService
for (Element dataRoot : dataRoots)
{
Record crossitem = ArxivUtils.convertArxixDomToRecord(dataRoot);
Record crossitem = ArxivUtils
.convertArxixDomToRecord(dataRoot);
if (crossitem != null)
{
results.add(crossitem);
@@ -168,7 +169,8 @@ public class ArXivService
"entry");
for (Element dataRoot : dataRoots)
{
Record crossitem = ArxivUtils.convertArxixDomToRecord(dataRoot);
Record crossitem = ArxivUtils
.convertArxixDomToRecord(dataRoot);
if (crossitem != null)
{
@@ -193,8 +195,7 @@ public class ArXivService
return results;
}
public Record getByArXivIDs(String raw) throws HttpException,
IOException
public Record getByArXivIDs(String raw) throws HttpException, IOException
{
if (StringUtils.isNotBlank(raw))
{

View File

@@ -28,72 +28,79 @@ import org.w3c.dom.Element;
* @author Kostas Stamatis
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*
*
*/
public class ArxivUtils {
public class ArxivUtils
{
public static Record convertArxixDomToRecord(Element dataRoot){
MutableRecord record = new SubmissionLookupPublication("");
String articleTitle = XMLUtils.getElementValue(dataRoot, "title");
if (articleTitle!=null)
record.addValue("articleTitle", new StringValue(articleTitle));
String summary = XMLUtils.getElementValue(dataRoot, "summary");
if (summary!=null)
record.addValue("summary", new StringValue(summary));
String year = XMLUtils.getElementValue(dataRoot, "published");
if (year!=null)
record.addValue("year", new StringValue(year));
String splashPageUrl = XMLUtils.getElementValue(dataRoot, "id");
if (splashPageUrl!=null)
record.addValue("splashPageUrl", new StringValue(splashPageUrl));
String comment = XMLUtils.getElementValue(dataRoot, "arxiv:comment");
if (comment!=null)
record.addValue("comment", new StringValue(comment));
public static Record convertArxixDomToRecord(Element dataRoot)
{
MutableRecord record = new SubmissionLookupPublication("");
String articleTitle = XMLUtils.getElementValue(dataRoot, "title");
if (articleTitle != null)
record.addValue("articleTitle", new StringValue(articleTitle));
String summary = XMLUtils.getElementValue(dataRoot, "summary");
if (summary != null)
record.addValue("summary", new StringValue(summary));
String year = XMLUtils.getElementValue(dataRoot, "published");
if (year != null)
record.addValue("year", new StringValue(year));
String splashPageUrl = XMLUtils.getElementValue(dataRoot, "id");
if (splashPageUrl != null)
record.addValue("splashPageUrl", new StringValue(splashPageUrl));
String comment = XMLUtils.getElementValue(dataRoot, "arxiv:comment");
if (comment != null)
record.addValue("comment", new StringValue(comment));
List<Element> links = XMLUtils.getElementList(dataRoot, "link");
if (links != null)
{
for (Element link : links)
{
if ("related".equals(link.getAttribute("rel")) && "pdf".equals(link.getAttribute("title")))
if ("related".equals(link.getAttribute("rel"))
&& "pdf".equals(link.getAttribute("title")))
{
String pdfUrl = link.getAttribute("href");
if (pdfUrl!=null)
record.addValue("pdfUrl", new StringValue(pdfUrl));
String pdfUrl = link.getAttribute("href");
if (pdfUrl != null)
record.addValue("pdfUrl", new StringValue(pdfUrl));
}
}
}
String doi = XMLUtils.getElementValue(dataRoot, "arxiv:doi");
if (doi!=null)
record.addValue("doi", new StringValue(doi));
String journalRef = XMLUtils.getElementValue(dataRoot, "arxiv:journal_ref");
if (journalRef!=null)
record.addValue("journalRef", new StringValue(journalRef));
List<String> primaryCategory = new LinkedList<String>();
List<Element> primaryCategoryList = XMLUtils.getElementList(dataRoot, "arxiv:primary_category");
if (doi != null)
record.addValue("doi", new StringValue(doi));
String journalRef = XMLUtils.getElementValue(dataRoot,
"arxiv:journal_ref");
if (journalRef != null)
record.addValue("journalRef", new StringValue(journalRef));
List<String> primaryCategory = new LinkedList<String>();
List<Element> primaryCategoryList = XMLUtils.getElementList(dataRoot,
"arxiv:primary_category");
if (primaryCategoryList != null)
{
for (Element primaryCategoryElement : primaryCategoryList)
{
primaryCategory.add(primaryCategoryElement.getAttribute("term"));
primaryCategory
.add(primaryCategoryElement.getAttribute("term"));
}
}
if (primaryCategory.size()>0){
List<Value> values = new LinkedList<Value>();
for (String s : primaryCategory){
values.add(new StringValue(s));
}
record.addField("primaryCategory", values);
}
List<String> category = new LinkedList<String>();
List<Element> categoryList = XMLUtils.getElementList(dataRoot, "category");
if (primaryCategory.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String s : primaryCategory)
{
values.add(new StringValue(s));
}
record.addField("primaryCategory", values);
}
List<String> category = new LinkedList<String>();
List<Element> categoryList = XMLUtils.getElementList(dataRoot,
"category");
if (categoryList != null)
{
for (Element categoryElement : categoryList)
@@ -101,15 +108,17 @@ public class ArxivUtils {
category.add(categoryElement.getAttribute("term"));
}
}
if (category.size()>0){
List<Value> values = new LinkedList<Value>();
for (String s : category){
values.add(new StringValue(s));
}
record.addField("category", values);
}
if (category.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String s : category)
{
values.add(new StringValue(s));
}
record.addField("category", values);
}
List<String[]> authors = new LinkedList<String[]>();
List<Element> authorList = XMLUtils.getElementList(dataRoot, "author");
if (authorList != null)
@@ -124,7 +133,7 @@ public class ArxivUtils {
{
String senzaPunti = nomeCompleto.replace("\\.", "");
String[] tmp = senzaPunti.split("\\s+");
int start = 1;
if (tmp.length == nomeSplit.length)
{
@@ -154,19 +163,21 @@ public class ArxivUtils {
{
cognome = nomeCompleto;
}
authors.add(new String[]{nome, cognome});
authors.add(new String[] { nome, cognome });
}
}
if (authors.size()>0){
List<Value> values = new LinkedList<Value>();
for (String[] sArray : authors){
values.add(new StringValue(sArray[1]+", "+sArray[0]));
}
record.addField("authors", values);
}
return record;
}
if (authors.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String[] sArray : authors)
{
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
}
record.addField("authors", values);
}
return record;
}
}

View File

@@ -39,96 +39,125 @@ import gr.ekt.bte.exceptions.MalformedSourceException;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class CrossRefFileDataLoader extends FileDataLoader {
public class CrossRefFileDataLoader extends FileDataLoader
{
Map<String, String> fieldMap; //mapping between service fields and local intermediate fields
/**
Map<String, String> fieldMap; // mapping between service fields and local
// intermediate fields
/**
*
*/
public CrossRefFileDataLoader() {
}
public CrossRefFileDataLoader()
{
}
/**
* @param filename
*/
public CrossRefFileDataLoader(String filename) {
super(filename);
}
/**
* @param filename
*/
public CrossRefFileDataLoader(String filename)
{
super(filename);
}
/* (non-Javadoc)
* @see gr.ekt.bte.core.DataLoader#getRecords()
*/
@Override
public RecordSet getRecords() throws MalformedSourceException {
RecordSet recordSet = new RecordSet();
try {
InputStream inputStream = new FileInputStream(new File(filename));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
/*
* (non-Javadoc)
*
* @see gr.ekt.bte.core.DataLoader#getRecords()
*/
@Override
public RecordSet getRecords() throws MalformedSourceException
{
DocumentBuilder db = factory.newDocumentBuilder();
Document inDoc = db.parse(inputStream);
RecordSet recordSet = new RecordSet();
Element xmlRoot = inDoc.getDocumentElement();
Element dataRoot = XMLUtils.getSingleElement(xmlRoot, "query");
Record record = CrossRefUtils.convertCrossRefDomToRecord(dataRoot);
recordSet.addRecord(convertFields(record));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return recordSet;
}
try
{
InputStream inputStream = new FileInputStream(new File(filename));
/* (non-Javadoc)
* @see gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
*/
@Override
public RecordSet getRecords(DataLoadingSpec spec)
throws MalformedSourceException {
return getRecords();
}
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
public Record convertFields(Record publication) {
for (String fieldName : fieldMap.keySet()) {
String md = null;
if (fieldMap!=null){
md = this.fieldMap.get(fieldName);
}
DocumentBuilder db = factory.newDocumentBuilder();
Document inDoc = db.parse(inputStream);
if (StringUtils.isBlank(md)) {
continue;
} else {
md = md.trim();
}
Element xmlRoot = inDoc.getDocumentElement();
Element dataRoot = XMLUtils.getSingleElement(xmlRoot, "query");
if (publication.isMutable()){
List<Value> values = publication.getValues(fieldName);
publication.makeMutable().removeField(fieldName);
publication.makeMutable().addField(md, values);
}
}
return publication;
}
Record record = CrossRefUtils.convertCrossRefDomToRecord(dataRoot);
recordSet.addRecord(convertFields(record));
public void setFieldMap(Map<String, String> fieldMap) {
this.fieldMap = fieldMap;
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (ParserConfigurationException e)
{
e.printStackTrace();
}
catch (SAXException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return recordSet;
}
/*
* (non-Javadoc)
*
* @see
* gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
*/
@Override
public RecordSet getRecords(DataLoadingSpec spec)
throws MalformedSourceException
{
return getRecords();
}
public Record convertFields(Record publication)
{
for (String fieldName : fieldMap.keySet())
{
String md = null;
if (fieldMap != null)
{
md = this.fieldMap.get(fieldName);
}
if (StringUtils.isBlank(md))
{
continue;
}
else
{
md = md.trim();
}
if (publication.isMutable())
{
List<Value> values = publication.getValues(fieldName);
publication.makeMutable().removeField(fieldName);
publication.makeMutable().addField(md, values);
}
}
return publication;
}
public void setFieldMap(Map<String, String> fieldMap)
{
this.fieldMap = fieldMap;
}
}

View File

@@ -29,58 +29,74 @@ import org.xml.sax.SAXException;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class CrossRefOnlineDataLoader extends NetworkSubmissionLookupDataLoader {
private CrossRefService crossrefService = new CrossRefService();
public class CrossRefOnlineDataLoader extends NetworkSubmissionLookupDataLoader
{
private CrossRefService crossrefService = new CrossRefService();
private boolean searchProvider = true;
public void setSearchProvider(boolean searchProvider)
private boolean searchProvider = true;
public void setSearchProvider(boolean searchProvider)
{
this.searchProvider = searchProvider;
}
public void setCrossrefService(CrossRefService crossrefService) {
this.crossrefService = crossrefService;
}
@Override
public List<String> getSupportedIdentifiers() {
return Arrays.asList(new String[] { DOI });
}
public void setCrossrefService(CrossRefService crossrefService)
{
this.crossrefService = crossrefService;
}
@Override
public List<Record> getByIdentifier(Context context,
Map<String, Set<String>> keys) throws HttpException, IOException {
if (keys != null && keys.containsKey(DOI)) {
Set<String> dois = keys.get(DOI);
List<Record> items = null;
List<Record> results = new ArrayList<Record>();
try {
items = crossrefService.search(context, dois);
} 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);
}
for (Record record : items){
results.add(convertFields(record));
}
return results;
}
return null;
}
@Override
public List<String> getSupportedIdentifiers()
{
return Arrays.asList(new String[] { DOI });
}
@Override
public List<Record> search(Context context, String title,
String author, int year) throws HttpException, IOException {
List<Record> items = crossrefService.search(context, title, author, year, 10);
return items;
}
@Override
public List<Record> getByIdentifier(Context context,
Map<String, Set<String>> keys) throws HttpException, IOException
{
if (keys != null && keys.containsKey(DOI))
{
Set<String> dois = keys.get(DOI);
List<Record> items = null;
List<Record> results = new ArrayList<Record>();
try
{
items = crossrefService.search(context, dois);
}
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);
}
for (Record record : items)
{
results.add(convertFields(record));
}
return results;
}
return null;
}
@Override
public boolean isSearchProvider() {
return searchProvider;
}
@Override
public List<Record> search(Context context, String title, String author,
int year) throws HttpException, IOException
{
List<Record> items = crossrefService.search(context, title, author,
year, 10);
return items;
}
@Override
public boolean isSearchProvider()
{
return searchProvider;
}
}

View File

@@ -46,146 +46,181 @@ import com.google.gson.reflect.TypeToken;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class CrossRefService {
public class CrossRefService
{
private static final Logger log = Logger.getLogger(CrossRefService.class);
private int timeout = 1000;
public void setTimeout(int timeout) {
this.timeout = timeout;
}
public List<Record> search(Context context, Set<String> dois) throws HttpException,
IOException, JDOMException, ParserConfigurationException,
SAXException {
List<Record> results = new ArrayList<Record>();
if (dois != null && dois.size() > 0) {
for (String record : dois) {
try
{
if (!ConfigurationManager
.getBooleanProperty("remoteservice.demo")) {
GetMethod method = null;
try {
String apiKey = ConfigurationManager
.getProperty("crossref.api-key");
HttpClient client = new HttpClient();
client.setConnectionTimeout(timeout);
method = new GetMethod(
"http://www.crossref.org/openurl/");
NameValuePair pid = new NameValuePair("pid", apiKey);
NameValuePair noredirect = new NameValuePair(
"noredirect", "true");
NameValuePair id = new NameValuePair("id", record);
method.setQueryString(new NameValuePair[] { pid,
noredirect, id });
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
throw new RuntimeException(
"Http call failed: "
+ method.getStatusLine());
}
Record crossitem;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilder db = factory.newDocumentBuilder();
Document inDoc = db.parse(method.getResponseBodyAsStream());
private int timeout = 1000;
Element xmlRoot = inDoc.getDocumentElement();
Element dataRoot = XMLUtils.getSingleElement(xmlRoot, "query");
crossitem = CrossRefUtils.convertCrossRefDomToRecord(dataRoot);
results.add(crossitem);
} catch (Exception e) {
log.warn(LogManager
.getHeader(
context,
"retrieveRecordDOI",
record
+ " DOI is not valid or not exist: "
+ e.getMessage()));
}
} finally {
if (method != null) {
method.releaseConnection();
}
}
}
}
catch (RuntimeException rt)
{
rt.printStackTrace();
}
}
}
return results;
}
public void setTimeout(int timeout)
{
this.timeout = timeout;
}
public NameValuePair[] buildQueryPart(String title, String author, int year, int count) {
StringBuffer sb = new StringBuffer();
if (StringUtils.isNotBlank(title)) {
sb.append(title);
}
sb.append(" ");
if (StringUtils.isNotBlank(author)) {
sb.append(author);
}
String q = sb.toString().trim();
NameValuePair qParam = new NameValuePair("q", title);
NameValuePair yearParam = new NameValuePair("year",
year != -1?String.valueOf(year):"");
NameValuePair countParam = new NameValuePair("rows",
count!= -1?String.valueOf(count):"");
NameValuePair[] query = new NameValuePair[] { qParam,
yearParam, countParam };
return query;
}
public List<Record> search(Context context, Set<String> dois)
throws HttpException, IOException, JDOMException,
ParserConfigurationException, SAXException
{
List<Record> results = new ArrayList<Record>();
if (dois != null && dois.size() > 0)
{
for (String record : dois)
{
try
{
if (!ConfigurationManager
.getBooleanProperty("remoteservice.demo"))
{
GetMethod method = null;
try
{
String apiKey = ConfigurationManager
.getProperty("crossref.api-key");
public List<Record> search(Context context, String title, String authors, int year,
int count) throws IOException, HttpException {
GetMethod method = null;
try {
NameValuePair[] query = buildQueryPart(title, authors, year, count);
HttpClient client = new HttpClient();
client.setTimeout(timeout);
method = new GetMethod("http://search.labs.crossref.org/dois");
HttpClient client = new HttpClient();
client.setConnectionTimeout(timeout);
method = new GetMethod(
"http://www.crossref.org/openurl/");
method.setQueryString(query);
// Execute the method.
int statusCode = client.executeMethod(method);
NameValuePair pid = new NameValuePair("pid", apiKey);
NameValuePair noredirect = new NameValuePair(
"noredirect", "true");
NameValuePair id = new NameValuePair("id", record);
method.setQueryString(new NameValuePair[] { pid,
noredirect, id });
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
throw new RuntimeException("Chiamata http fallita: "
+ method.getStatusLine());
}
if (statusCode != HttpStatus.SC_OK)
{
throw new RuntimeException("Http call failed: "
+ method.getStatusLine());
}
Gson gson = new Gson();
Type listType = new TypeToken<ArrayList<Map>>(){}.getType();
List<Map> json = gson.fromJson(method.getResponseBodyAsString(),listType);
Set<String> dois = new HashSet<String>();
for (Map r : json) {
dois.add(SubmissionLookupUtils.normalizeDOI((String) r.get("doi")));
}
method.releaseConnection();
Record crossitem;
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
return search(context, dois);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
} finally {
if (method != null) {
method.releaseConnection();
}
}
}
DocumentBuilder db = factory
.newDocumentBuilder();
Document inDoc = db.parse(method
.getResponseBodyAsStream());
Element xmlRoot = inDoc.getDocumentElement();
Element dataRoot = XMLUtils.getSingleElement(
xmlRoot, "query");
crossitem = CrossRefUtils
.convertCrossRefDomToRecord(dataRoot);
results.add(crossitem);
}
catch (Exception e)
{
log.warn(LogManager
.getHeader(
context,
"retrieveRecordDOI",
record
+ " DOI is not valid or not exist: "
+ e.getMessage()));
}
}
finally
{
if (method != null)
{
method.releaseConnection();
}
}
}
}
catch (RuntimeException rt)
{
rt.printStackTrace();
}
}
}
return results;
}
public NameValuePair[] buildQueryPart(String title, String author,
int year, int count)
{
StringBuffer sb = new StringBuffer();
if (StringUtils.isNotBlank(title))
{
sb.append(title);
}
sb.append(" ");
if (StringUtils.isNotBlank(author))
{
sb.append(author);
}
String q = sb.toString().trim();
NameValuePair qParam = new NameValuePair("q", title);
NameValuePair yearParam = new NameValuePair("year",
year != -1 ? String.valueOf(year) : "");
NameValuePair countParam = new NameValuePair("rows",
count != -1 ? String.valueOf(count) : "");
NameValuePair[] query = new NameValuePair[] { qParam, yearParam,
countParam };
return query;
}
public List<Record> search(Context context, String title, String authors,
int year, int count) throws IOException, HttpException
{
GetMethod method = null;
try
{
NameValuePair[] query = buildQueryPart(title, authors, year, count);
HttpClient client = new HttpClient();
client.setTimeout(timeout);
method = new GetMethod("http://search.labs.crossref.org/dois");
method.setQueryString(query);
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK)
{
throw new RuntimeException("Chiamata http fallita: "
+ method.getStatusLine());
}
Gson gson = new Gson();
Type listType = new TypeToken<ArrayList<Map>>()
{
}.getType();
List<Map> json = gson.fromJson(method.getResponseBodyAsString(),
listType);
Set<String> dois = new HashSet<String>();
for (Map r : json)
{
dois.add(SubmissionLookupUtils.normalizeDOI((String) r
.get("doi")));
}
method.releaseConnection();
return search(context, dois);
}
catch (Exception e)
{
throw new RuntimeException(e.getMessage(), e);
}
finally
{
if (method != null)
{
method.releaseConnection();
}
}
}
}

View File

@@ -29,164 +29,189 @@ import org.w3c.dom.Element;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class CrossRefUtils {
public class CrossRefUtils
{
/**
/**
*
*/
public CrossRefUtils() {
// TODO Auto-generated constructor stub
}
public CrossRefUtils()
{
// TODO Auto-generated constructor stub
}
public static Record convertCrossRefDomToRecord(Element dataRoot) {
MutableRecord record = new SubmissionLookupPublication("");
public static Record convertCrossRefDomToRecord(Element dataRoot)
{
MutableRecord record = new SubmissionLookupPublication("");
String status = dataRoot.getAttribute("status");
if (!"resolved".equals(status)) {
String msg = XMLUtils.getElementValue(dataRoot, "msg");
String exMsg = status + " - " + msg;
throw new RuntimeException(exMsg);
}
String status = dataRoot.getAttribute("status");
if (!"resolved".equals(status))
{
String msg = XMLUtils.getElementValue(dataRoot, "msg");
String exMsg = status + " - " + msg;
throw new RuntimeException(exMsg);
}
String doi = XMLUtils.getElementValue(dataRoot, "doi");
if (doi != null)
record.addValue("doi", new StringValue(doi));
String doi = XMLUtils.getElementValue(dataRoot, "doi");
if (doi != null)
record.addValue("doi", new StringValue(doi));
String itemType = doi != null ? XMLUtils.getElementAttribute(dataRoot,
"doi", "type") : "unspecified";
if (itemType != null)
record.addValue("itemType", new StringValue(itemType));
String itemType = doi != null ? XMLUtils.getElementAttribute(dataRoot,
"doi", "type") : "unspecified";
if (itemType != null)
record.addValue("itemType", new StringValue(itemType));
List<Element> identifier = XMLUtils.getElementList(dataRoot, "issn");
for (Element ident : identifier) {
if ("print".equalsIgnoreCase(ident.getAttribute("type"))
|| StringUtils.isNotBlank(ident.getAttribute("type"))) {
String issn = ident.getTextContent().trim();
if (issn != null)
record.addValue("issn", new StringValue(issn));
} else {
String eissn = ident.getTextContent().trim();
if (eissn != null)
record.addValue("eissn", new StringValue(eissn));
}
}
List<Element> identifier = XMLUtils.getElementList(dataRoot, "issn");
for (Element ident : identifier)
{
if ("print".equalsIgnoreCase(ident.getAttribute("type"))
|| StringUtils.isNotBlank(ident.getAttribute("type")))
{
String issn = ident.getTextContent().trim();
if (issn != null)
record.addValue("issn", new StringValue(issn));
}
else
{
String eissn = ident.getTextContent().trim();
if (eissn != null)
record.addValue("eissn", new StringValue(eissn));
}
}
String isbn = XMLUtils.getElementValue(dataRoot, "isbn");
if (isbn != null)
record.addValue("isbn", new StringValue(isbn));
String isbn = XMLUtils.getElementValue(dataRoot, "isbn");
if (isbn != null)
record.addValue("isbn", new StringValue(isbn));
String editionNumber = XMLUtils.getElementValue(dataRoot,
"editionNumber");
if (editionNumber != null)
record.addValue("volume", new StringValue(editionNumber));
String editionNumber = XMLUtils.getElementValue(dataRoot,
"editionNumber");
if (editionNumber != null)
record.addValue("volume", new StringValue(editionNumber));
String volume = XMLUtils.getElementValue(dataRoot, "volume");
if (volume != null)
record.addValue("volume", new StringValue(volume));
String volume = XMLUtils.getElementValue(dataRoot, "volume");
if (volume != null)
record.addValue("volume", new StringValue(volume));
String issue = XMLUtils.getElementValue(dataRoot, "issue");
if (issue != null)
record.addValue("issue", new StringValue(issue));
String issue = XMLUtils.getElementValue(dataRoot, "issue");
if (issue != null)
record.addValue("issue", new StringValue(issue));
String year = XMLUtils.getElementValue(dataRoot, "year");
if (year != null)
record.addValue("year", new StringValue(year));
String year = XMLUtils.getElementValue(dataRoot, "year");
if (year != null)
record.addValue("year", new StringValue(year));
String firstPage = XMLUtils.getElementValue(dataRoot, "first_page");
if (firstPage != null)
record.addValue("firstPage", new StringValue(firstPage));
String firstPage = XMLUtils.getElementValue(dataRoot, "first_page");
if (firstPage != null)
record.addValue("firstPage", new StringValue(firstPage));
String lastPage = XMLUtils.getElementValue(dataRoot, "last_page");
if (lastPage != null)
record.addValue("lastPage", new StringValue(lastPage));
String lastPage = XMLUtils.getElementValue(dataRoot, "last_page");
if (lastPage != null)
record.addValue("lastPage", new StringValue(lastPage));
String seriesTitle = XMLUtils.getElementValue(dataRoot, "series_title");
if (seriesTitle != null)
record.addValue("seriesTitle", new StringValue(seriesTitle));
String seriesTitle = XMLUtils.getElementValue(dataRoot, "series_title");
if (seriesTitle != null)
record.addValue("seriesTitle", new StringValue(seriesTitle));
String journalTitle = XMLUtils.getElementValue(dataRoot,
"journal_title");
if (journalTitle != null)
record.addValue("journalTitle", new StringValue(journalTitle));
String journalTitle = XMLUtils.getElementValue(dataRoot,
"journal_title");
if (journalTitle != null)
record.addValue("journalTitle", new StringValue(journalTitle));
String volumeTitle = XMLUtils.getElementValue(dataRoot, "volume_title");
if (volumeTitle != null)
record.addValue("volumeTitle", new StringValue(volumeTitle));
String volumeTitle = XMLUtils.getElementValue(dataRoot, "volume_title");
if (volumeTitle != null)
record.addValue("volumeTitle", new StringValue(volumeTitle));
String articleTitle = XMLUtils.getElementValue(dataRoot,
"article_title");
if (articleTitle != null)
record.addValue("articleTitle", new StringValue(articleTitle));
String articleTitle = XMLUtils.getElementValue(dataRoot,
"article_title");
if (articleTitle != null)
record.addValue("articleTitle", new StringValue(articleTitle));
String publicationType = XMLUtils.getElementValue(dataRoot,
"pubblication_type");
if (publicationType != null)
record.addValue("publicationType", new StringValue(publicationType));
String publicationType = XMLUtils.getElementValue(dataRoot,
"pubblication_type");
if (publicationType != null)
record.addValue("publicationType", new StringValue(publicationType));
List<String[]> authors = new LinkedList<String[]>();
List<String[]> editors = new LinkedList<String[]>();
List<String[]> translators = new LinkedList<String[]>();
List<String[]> chairs = new LinkedList<String[]>();
List<String[]> authors = new LinkedList<String[]>();
List<String[]> editors = new LinkedList<String[]>();
List<String[]> translators = new LinkedList<String[]>();
List<String[]> chairs = new LinkedList<String[]>();
List<Element> contributors = XMLUtils.getElementList(dataRoot,
"contributors");
List<Element> contributor = null;
if (contributors != null && contributors.size() > 0) {
contributor = XMLUtils.getElementList(contributors.get(0),
"contributor");
List<Element> contributors = XMLUtils.getElementList(dataRoot,
"contributors");
List<Element> contributor = null;
if (contributors != null && contributors.size() > 0)
{
contributor = XMLUtils.getElementList(contributors.get(0),
"contributor");
for (Element contrib : contributor) {
for (Element contrib : contributor)
{
String givenName = XMLUtils.getElementValue(contrib,
"given_name");
String surname = XMLUtils.getElementValue(contrib, "surname");
String givenName = XMLUtils.getElementValue(contrib,
"given_name");
String surname = XMLUtils.getElementValue(contrib, "surname");
if ("editor".equalsIgnoreCase(contrib
.getAttribute("contributor_role"))) {
editors.add(new String[] { givenName, surname });
} else if ("chair".equalsIgnoreCase(contrib
.getAttribute("contributor_role"))) {
chairs.add(new String[] { givenName, surname });
} else if ("translator".equalsIgnoreCase(contrib
.getAttribute("contributor_role"))) {
translators.add(new String[] { givenName, surname });
} else {
authors.add(new String[] { givenName, surname });
}
}
}
if ("editor".equalsIgnoreCase(contrib
.getAttribute("contributor_role")))
{
editors.add(new String[] { givenName, surname });
}
else if ("chair".equalsIgnoreCase(contrib
.getAttribute("contributor_role")))
{
chairs.add(new String[] { givenName, surname });
}
else if ("translator".equalsIgnoreCase(contrib
.getAttribute("contributor_role")))
{
translators.add(new String[] { givenName, surname });
}
else
{
authors.add(new String[] { givenName, surname });
}
}
}
if (authors.size() > 0) {
List<Value> values = new LinkedList<Value>();
for (String[] sArray : authors) {
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
}
record.addField("authors", values);
}
if (authors.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String[] sArray : authors)
{
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
}
record.addField("authors", values);
}
if (editors.size() > 0) {
List<Value> values = new LinkedList<Value>();
for (String[] sArray : editors) {
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
}
record.addField("editors", values);
}
if (editors.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String[] sArray : editors)
{
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
}
record.addField("editors", values);
}
if (translators.size() > 0) {
List<Value> values = new LinkedList<Value>();
for (String[] sArray : translators) {
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
}
record.addField("translators", values);
}
if (translators.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String[] sArray : translators)
{
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
}
record.addField("translators", values);
}
if (chairs.size() > 0) {
List<Value> values = new LinkedList<Value>();
for (String[] sArray : chairs) {
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
}
record.addField("chairs", values);
}
return record;
}
if (chairs.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String[] sArray : chairs)
{
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
}
record.addField("chairs", values);
}
return record;
}
}

View File

@@ -38,223 +38,292 @@ import org.dspace.content.WorkspaceItem;
import org.dspace.core.Context;
import org.dspace.submit.util.ItemSubmissionLookupDTO;
/**
* @author Andrea Bollini
* @author Kostas Stamatis
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class DSpaceWorkspaceItemOutputGenerator implements OutputGenerator {
private static Logger log = Logger.getLogger(DSpaceWorkspaceItemOutputGenerator.class);
private Context context;
private String formName;
private List<WorkspaceItem> witems;
private ItemSubmissionLookupDTO dto;
private Collection collection;
Map<String, String> outputMap;
private List<String> extraMetadataToKeep;
public class DSpaceWorkspaceItemOutputGenerator implements OutputGenerator
{
private static Logger log = Logger
.getLogger(DSpaceWorkspaceItemOutputGenerator.class);
private Context context;
private String formName;
private List<WorkspaceItem> witems;
private ItemSubmissionLookupDTO dto;
private Collection collection;
Map<String, String> outputMap;
private List<String> extraMetadataToKeep;
@Override
public List<String> generateOutput(RecordSet recordSet) {
log.info("BTE OutputGenerator started. Records to output: " + recordSet.getRecords().size());
//Printing debug message
String totalString = "";
for (Record record : recordSet.getRecords()){
totalString += SubmissionLookupUtils.getPrintableString(record)+"\n";
}
log.debug("Records to output:\n"+totalString);
witems = new ArrayList<WorkspaceItem>();
for(Record rec : recordSet.getRecords()) {
try {
WorkspaceItem wi = WorkspaceItem.create(context, collection, true);
merge(formName, wi.getItem(), rec);
witems.add(wi);
} catch (AuthorizeException e) {
log.error(e.getMessage(), e);
} catch (SQLException e) {
log.error(e.getMessage(), e);
} catch (IOException e) {
log.error(e.getMessage(), e);
}
public List<String> generateOutput(RecordSet recordSet)
{
log.info("BTE OutputGenerator started. Records to output: "
+ recordSet.getRecords().size());
// Printing debug message
String totalString = "";
for (Record record : recordSet.getRecords())
{
totalString += SubmissionLookupUtils.getPrintableString(record)
+ "\n";
}
log.debug("Records to output:\n" + totalString);
witems = new ArrayList<WorkspaceItem>();
for (Record rec : recordSet.getRecords())
{
try
{
WorkspaceItem wi = WorkspaceItem.create(context, collection,
true);
merge(formName, wi.getItem(), rec);
witems.add(wi);
}
catch (AuthorizeException e)
{
log.error(e.getMessage(), e);
}
catch (SQLException e)
{
log.error(e.getMessage(), e);
}
catch (IOException e)
{
log.error(e.getMessage(), e);
}
}
return new ArrayList<String>();
}
@Override
public List<String> generateOutput(RecordSet records, DataOutputSpec spec) {
public List<String> generateOutput(RecordSet records, DataOutputSpec spec)
{
return generateOutput(records);
}
public List<WorkspaceItem> getWitems() {
return witems;
}
public List<WorkspaceItem> getWitems()
{
return witems;
}
public void setContext(Context context) {
this.context = context;
}
public void setContext(Context context)
{
this.context = context;
}
public void setFormName(String formName) {
this.formName = formName;
}
public void setDto(ItemSubmissionLookupDTO dto) {
this.dto = dto;
}
public void setFormName(String formName)
{
this.formName = formName;
}
public void setOutputMap(Map<String, String> outputMap) {
//Reverse the key-value pairs
this.outputMap = new HashMap<String, String>();
for (String key : outputMap.keySet()){
this.outputMap.put(outputMap.get(key), key);
}
}
public void setDto(ItemSubmissionLookupDTO dto)
{
this.dto = dto;
}
public void setCollection(Collection collection) {
this.collection = collection;
}
public void setOutputMap(Map<String, String> outputMap)
{
// Reverse the key-value pairs
this.outputMap = new HashMap<String, String>();
for (String key : outputMap.keySet())
{
this.outputMap.put(outputMap.get(key), key);
}
}
public void setExtraMetadataToKeep(List<String> extraMetadataToKeep) {
this.extraMetadataToKeep = extraMetadataToKeep;
}
public void setCollection(Collection collection)
{
this.collection = collection;
}
//Methods
public void merge(String formName, Item item, Record record) {
public void setExtraMetadataToKeep(List<String> extraMetadataToKeep)
{
this.extraMetadataToKeep = extraMetadataToKeep;
}
// Methods
public void merge(String formName, Item item, Record record)
{
Record itemLookup = record;
Set<String> addedMetadata = new HashSet<String>();
for (String field : itemLookup.getFields()) {
String metadata = getMetadata(formName, itemLookup, field);
if (StringUtils.isBlank(metadata)) {
continue;
}
if (item.getMetadata(metadata).length == 0
|| addedMetadata.contains(metadata)) {
addedMetadata.add(metadata);
String[] md = splitMetadata(metadata);
if (isValidMetadata(formName, md)) { //if in extra metadata or in the spefific form
List<Value> values = itemLookup.getValues(field);
if (values != null && values.size()>0){
if (isRepeatableMetadata(formName, md)) { //if metadata is repeatable in form
for (Value value : values) {
String[] splitValue = splitValue(value.getAsString());
if (splitValue[3] != null) {
item.addMetadata(md[0], md[1], md[2], md[3],
splitValue[0], splitValue[1],
Integer.parseInt(splitValue[2]));
} else {
item.addMetadata(md[0], md[1], md[2], md[3],
value.getAsString());
}
}
} else {
String value = values.iterator().next().getAsString();
String[] splitValue = splitValue(value);
if (splitValue[3] != null) {
item.addMetadata(md[0], md[1], md[2], md[3],
splitValue[0], splitValue[1],
Integer.parseInt(splitValue[2]));
} else {
item.addMetadata(md[0], md[1], md[2], md[3], value);
}
}
}
}
}
}
try {
item.update();
} catch (SQLException e) {
log.error(e.getMessage(), e);
} catch (AuthorizeException e) {
log.error(e.getMessage(), e);
}
}
private String getMetadata(String formName,
Record itemLookup, String name) {
String type = SubmissionLookupService.getType(itemLookup);
String md = outputMap.get(type + "." + name);
if (StringUtils.isBlank(md)){
md = outputMap.get(formName + "." + name);
if (StringUtils.isBlank(md)){
md = outputMap.get(name);
}
}
//KSTA:ToDo: Make this a modifier
if (md != null && md.contains("|")) {
String[] cond = md.trim().split("\\|");
for (int idx = 1; idx < cond.length; idx++) {
boolean temp = itemLookup.getFields().contains(cond[idx]);
if (temp) {
return null;
}
}
return cond[0];
}
return md;
}
private String[] splitMetadata(String metadata) {
String[] mdSplit = new String[3];
if (StringUtils.isNotBlank(metadata)) {
String tmpSplit[] = metadata.split("\\.");
if (tmpSplit.length == 4) {
mdSplit = new String[4];
mdSplit[0] = tmpSplit[0];
mdSplit[1] = tmpSplit[1];
mdSplit[2] = tmpSplit[2];
mdSplit[3] = tmpSplit[3];
} else if (tmpSplit.length == 3) {
mdSplit = new String[4];
mdSplit[0] = tmpSplit[0];
mdSplit[1] = tmpSplit[1];
mdSplit[2] = tmpSplit[2];
mdSplit[3] = null;
} else if (tmpSplit.length == 2) {
mdSplit = new String[4];
mdSplit[0] = tmpSplit[0];
mdSplit[1] = tmpSplit[1];
mdSplit[2] = null;
mdSplit[3] = null;
}
}
return mdSplit;
}
private boolean isValidMetadata(String formName, String[] md) {
try {
if (extraMetadataToKeep != null
&& extraMetadataToKeep.contains(StringUtils.join(
Arrays.copyOfRange(md, 0, 3), "."))) {
return true;
}
return getDCInput(formName, md[0], md[1], md[2])!=null;
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return false;
}
private DCInput getDCInput(String formName, String schema,
String element, String qualifier) throws DCInputsReaderException
Set<String> addedMetadata = new HashSet<String>();
for (String field : itemLookup.getFields())
{
String metadata = getMetadata(formName, itemLookup, field);
if (StringUtils.isBlank(metadata))
{
continue;
}
if (item.getMetadata(metadata).length == 0
|| addedMetadata.contains(metadata))
{
addedMetadata.add(metadata);
String[] md = splitMetadata(metadata);
if (isValidMetadata(formName, md))
{ // if in extra metadata or in the spefific form
List<Value> values = itemLookup.getValues(field);
if (values != null && values.size() > 0)
{
if (isRepeatableMetadata(formName, md))
{ // if metadata is repeatable in form
for (Value value : values)
{
String[] splitValue = splitValue(value
.getAsString());
if (splitValue[3] != null)
{
item.addMetadata(md[0], md[1], md[2],
md[3], splitValue[0],
splitValue[1],
Integer.parseInt(splitValue[2]));
}
else
{
item.addMetadata(md[0], md[1], md[2],
md[3], value.getAsString());
}
}
}
else
{
String value = values.iterator().next()
.getAsString();
String[] splitValue = splitValue(value);
if (splitValue[3] != null)
{
item.addMetadata(md[0], md[1], md[2], md[3],
splitValue[0], splitValue[1],
Integer.parseInt(splitValue[2]));
}
else
{
item.addMetadata(md[0], md[1], md[2], md[3],
value);
}
}
}
}
}
}
try
{
item.update();
}
catch (SQLException e)
{
log.error(e.getMessage(), e);
}
catch (AuthorizeException e)
{
log.error(e.getMessage(), e);
}
}
private String getMetadata(String formName, Record itemLookup, String name)
{
String type = SubmissionLookupService.getType(itemLookup);
String md = outputMap.get(type + "." + name);
if (StringUtils.isBlank(md))
{
md = outputMap.get(formName + "." + name);
if (StringUtils.isBlank(md))
{
md = outputMap.get(name);
}
}
// KSTA:ToDo: Make this a modifier
if (md != null && md.contains("|"))
{
String[] cond = md.trim().split("\\|");
for (int idx = 1; idx < cond.length; idx++)
{
boolean temp = itemLookup.getFields().contains(cond[idx]);
if (temp)
{
return null;
}
}
return cond[0];
}
return md;
}
private String[] splitMetadata(String metadata)
{
String[] mdSplit = new String[3];
if (StringUtils.isNotBlank(metadata))
{
String tmpSplit[] = metadata.split("\\.");
if (tmpSplit.length == 4)
{
mdSplit = new String[4];
mdSplit[0] = tmpSplit[0];
mdSplit[1] = tmpSplit[1];
mdSplit[2] = tmpSplit[2];
mdSplit[3] = tmpSplit[3];
}
else if (tmpSplit.length == 3)
{
mdSplit = new String[4];
mdSplit[0] = tmpSplit[0];
mdSplit[1] = tmpSplit[1];
mdSplit[2] = tmpSplit[2];
mdSplit[3] = null;
}
else if (tmpSplit.length == 2)
{
mdSplit = new String[4];
mdSplit[0] = tmpSplit[0];
mdSplit[1] = tmpSplit[1];
mdSplit[2] = null;
mdSplit[3] = null;
}
}
return mdSplit;
}
private boolean isValidMetadata(String formName, String[] md)
{
try
{
if (extraMetadataToKeep != null
&& extraMetadataToKeep.contains(StringUtils.join(
Arrays.copyOfRange(md, 0, 3), ".")))
{
return true;
}
return getDCInput(formName, md[0], md[1], md[2]) != null;
}
catch (Exception e)
{
log.error(e.getMessage(), e);
}
return false;
}
private DCInput getDCInput(String formName, String schema, String element,
String qualifier) throws DCInputsReaderException
{
DCInputSet dcinputset = new DCInputsReader().getInputs(formName);
for (int idx = 0; idx < dcinputset.getNumberPages(); idx++)
@@ -273,76 +342,98 @@ public class DSpaceWorkspaceItemOutputGenerator implements OutputGenerator {
}
return null;
}
private boolean isRepeatableMetadata(String formName, String[] md) {
try {
DCInput dcinput = getDCInput(formName, md[0], md[1], md[2]);
if (dcinput != null) {
return dcinput.isRepeatable();
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
private String[] splitValue(String value) {
String[] splitted = value.split(SubmissionLookupService.SEPARATOR_VALUE_REGEX);
String[] result = new String[6];
result[0] = splitted[0];
result[2] = "-1";
result[3] = "-1";
result[4] = "-1";
if (splitted.length > 1) {
result[5] = "splitted";
if (StringUtils.isNotBlank(splitted[1])) {
result[1] = splitted[1];
}
if (splitted.length > 2) {
result[2] = String.valueOf(Integer.parseInt(splitted[2]));
if (splitted.length > 3) {
result[3] = String.valueOf(Integer.parseInt(splitted[3]));
if (splitted.length > 4) {
result[4] = String.valueOf(Integer
.parseInt(splitted[4]));
}
}
}
}
return result;
}
private boolean isRepeatableMetadata(String formName, String[] md)
{
try
{
DCInput dcinput = getDCInput(formName, md[0], md[1], md[2]);
if (dcinput != null)
{
return dcinput.isRepeatable();
}
return true;
}
catch (Exception e)
{
e.printStackTrace();
}
return false;
}
private String[] splitValue(String value)
{
String[] splitted = value
.split(SubmissionLookupService.SEPARATOR_VALUE_REGEX);
String[] result = new String[6];
result[0] = splitted[0];
result[2] = "-1";
result[3] = "-1";
result[4] = "-1";
if (splitted.length > 1)
{
result[5] = "splitted";
if (StringUtils.isNotBlank(splitted[1]))
{
result[1] = splitted[1];
}
if (splitted.length > 2)
{
result[2] = String.valueOf(Integer.parseInt(splitted[2]));
if (splitted.length > 3)
{
result[3] = String.valueOf(Integer.parseInt(splitted[3]));
if (splitted.length > 4)
{
result[4] = String.valueOf(Integer
.parseInt(splitted[4]));
}
}
}
}
return result;
}
private void makeSureMetadataExist(Context context, String schema,
String element, String qualifier) {
try {
context.turnOffAuthorisationSystem();
boolean create = false;
MetadataSchema mdschema = MetadataSchema.find(context, schema);
MetadataField mdfield = null;
if (mdschema == null) {
mdschema = new MetadataSchema(SubmissionLookupService.SL_NAMESPACE_PREFIX + schema,
schema);
mdschema.create(context);
create = true;
} else {
mdfield = MetadataField.findByElement(context,
mdschema.getSchemaID(), element, qualifier);
}
String element, String qualifier)
{
try
{
context.turnOffAuthorisationSystem();
boolean create = false;
MetadataSchema mdschema = MetadataSchema.find(context, schema);
MetadataField mdfield = null;
if (mdschema == null)
{
mdschema = new MetadataSchema(
SubmissionLookupService.SL_NAMESPACE_PREFIX + schema,
schema);
mdschema.create(context);
create = true;
}
else
{
mdfield = MetadataField.findByElement(context,
mdschema.getSchemaID(), element, qualifier);
}
if (mdfield == null) {
mdfield = new MetadataField(mdschema, element, qualifier,
"Campo utilizzato per la cache del provider submission-lookup: "
+ schema);
mdfield.create(context);
create = true;
}
if (create) {
context.commit();
}
context.restoreAuthSystemState();
} catch (Exception e) {
e.printStackTrace();
}
}
if (mdfield == null)
{
mdfield = new MetadataField(mdschema, element, qualifier,
"Campo utilizzato per la cache del provider submission-lookup: "
+ schema);
mdfield.create(context);
create = true;
}
if (create)
{
context.commit();
}
context.restoreAuthSystemState();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

View File

@@ -22,43 +22,54 @@ import java.util.Map;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class FieldMergeModifier extends AbstractModifier {
public class FieldMergeModifier extends AbstractModifier
{
private Map<String, List<String>> mergeFieldMap;
public FieldMergeModifier() {
public FieldMergeModifier()
{
super("FieldMergeModifier");
}
@Override
public Record modify(MutableRecord rec) {
if (mergeFieldMap!=null){
for (String target_field : mergeFieldMap.keySet()) {
List<String> source_fields = mergeFieldMap.get(target_field);
for (String source_field : source_fields) {
List<Value> values = rec.getValues(source_field);
if (values != null && values.size() > 0) {
for (Value value : values) {
rec.addValue(target_field, value);
}
}
//rec.removeField(source_field);
}
}
}
public Record modify(MutableRecord rec)
{
if (mergeFieldMap != null)
{
for (String target_field : mergeFieldMap.keySet())
{
List<String> source_fields = mergeFieldMap.get(target_field);
for (String source_field : source_fields)
{
List<Value> values = rec.getValues(source_field);
if (values != null && values.size() > 0)
{
for (Value value : values)
{
rec.addValue(target_field, value);
}
}
// rec.removeField(source_field);
}
}
}
return rec;
}
/**
* @return the merge_field_map
*/
public Map<String, List<String>> getMergeFieldMap() {
public Map<String, List<String>> getMergeFieldMap()
{
return mergeFieldMap;
}
/**
* @param merge_field_map the merge_field_map to set
* @param merge_field_map
* the merge_field_map to set
*/
public void setMergeFieldMap(Map<String, List<String>> merge_field_map) {
public void setMergeFieldMap(Map<String, List<String>> merge_field_map)
{
this.mergeFieldMap = merge_field_map;
}
}

View File

@@ -16,20 +16,30 @@ import java.util.List;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class LookupProvidersCheck {
private List<String> providersOk = new ArrayList<String>();
private List<String> providersErr = new ArrayList<String>();
public List<String> getProvidersOk() {
return providersOk;
}
public void setProvidersOk(List<String> providersOk) {
this.providersOk = providersOk;
}
public List<String> getProvidersErr() {
return providersErr;
}
public void setProvidersErr(List<String> providersErr) {
this.providersErr = providersErr;
}
public class LookupProvidersCheck
{
private List<String> providersOk = new ArrayList<String>();
private List<String> providersErr = new ArrayList<String>();
public List<String> getProvidersOk()
{
return providersOk;
}
public void setProvidersOk(List<String> providersOk)
{
this.providersOk = providersOk;
}
public List<String> getProvidersErr()
{
return providersErr;
}
public void setProvidersErr(List<String> providersErr)
{
this.providersErr = providersErr;
}
}

View File

@@ -26,108 +26,126 @@ import gr.ekt.bte.core.Value;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class MapConverterModifier extends AbstractModifier {
public class MapConverterModifier extends AbstractModifier
{
String filename; //The properties filename
Map<String, String> mapping;
String defaultValue = "";
String filename; // The properties filename
List<String> fieldKeys;
Map<String, String> mapping;
private Map<String, String> regexConfig = new HashMap<String, String>();
String defaultValue = "";
public final String REGEX_PREFIX = "regex.";
List<String> fieldKeys;
/**
* @param name
*/
public MapConverterModifier(String name) {
super(name);
}
private Map<String, String> regexConfig = new HashMap<String, String>();
/* (non-Javadoc)
* @see gr.ekt.bte.core.AbstractModifier#modify(gr.ekt.bte.core.MutableRecord)
*/
@Override
public Record modify(MutableRecord record) {
if (mapping != null && fieldKeys != null) {
for (String key : fieldKeys){
List<Value> values = record.getValues(key);
public final String REGEX_PREFIX = "regex.";
if (values==null) continue;
List<Value> newValues = new ArrayList<Value>();
/**
* @param name
*/
public MapConverterModifier(String name)
{
super(name);
}
for (Value value : values){
String stringValue = value.getAsString();
/*
* (non-Javadoc)
*
* @see
* gr.ekt.bte.core.AbstractModifier#modify(gr.ekt.bte.core.MutableRecord)
*/
@Override
public Record modify(MutableRecord record)
{
if (mapping != null && fieldKeys != null)
{
for (String key : fieldKeys)
{
List<Value> values = record.getValues(key);
String tmp = "";
if (mapping.containsKey(stringValue))
{
tmp = mapping.get(stringValue);
}
else
{
tmp = defaultValue;
for (String regex : regexConfig.keySet())
{
if (stringValue != null && stringValue.matches(regex))
{
tmp = stringValue.replaceAll(regex, regexConfig.get(regex));
}
}
}
if (values == null)
continue;
if ("@@ident@@".equals(tmp))
{
newValues.add(new StringValue(stringValue));
}
else if (StringUtils.isNotBlank(tmp))
{
newValues.add(new StringValue(tmp));
}
else
newValues.add(new StringValue(stringValue));
}
List<Value> newValues = new ArrayList<Value>();
record.updateField(key, newValues);
}
}
for (Value value : values)
{
String stringValue = value.getAsString();
return record;
}
String tmp = "";
if (mapping.containsKey(stringValue))
{
tmp = mapping.get(stringValue);
}
else
{
tmp = defaultValue;
for (String regex : regexConfig.keySet())
{
if (stringValue != null
&& stringValue.matches(regex))
{
tmp = stringValue.replaceAll(regex,
regexConfig.get(regex));
}
}
}
public void setMapping(Map<String, String> mapping) {
this.mapping = mapping;
for (String keyS : mapping.keySet())
{
if (keyS.startsWith(REGEX_PREFIX))
{
String regex = keyS.substring(REGEX_PREFIX.length());
String regReplace = mapping.get(keyS);
if (regReplace == null)
{
regReplace = "";
}
else if (regReplace.equalsIgnoreCase("@ident@"))
{
regReplace = "$0";
}
regexConfig.put(regex,regReplace);
}
}
}
if ("@@ident@@".equals(tmp))
{
newValues.add(new StringValue(stringValue));
}
else if (StringUtils.isNotBlank(tmp))
{
newValues.add(new StringValue(tmp));
}
else
newValues.add(new StringValue(stringValue));
}
public void setFilename(String filename) {
this.filename = filename;
}
record.updateField(key, newValues);
}
}
public void setFieldKeys(List<String> fieldKeys) {
this.fieldKeys = fieldKeys;
}
return record;
}
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
public void setMapping(Map<String, String> mapping)
{
this.mapping = mapping;
for (String keyS : mapping.keySet())
{
if (keyS.startsWith(REGEX_PREFIX))
{
String regex = keyS.substring(REGEX_PREFIX.length());
String regReplace = mapping.get(keyS);
if (regReplace == null)
{
regReplace = "";
}
else if (regReplace.equalsIgnoreCase("@ident@"))
{
regReplace = "$0";
}
regexConfig.put(regex, regReplace);
}
}
}
public void setFilename(String filename)
{
this.filename = filename;
}
public void setFieldKeys(List<String> fieldKeys)
{
this.fieldKeys = fieldKeys;
}
public void setDefaultValue(String defaultValue)
{
this.defaultValue = defaultValue;
}
}

View File

@@ -31,226 +31,304 @@ import gr.ekt.bte.exceptions.MalformedSourceException;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class MultipleSubmissionLookupDataLoader implements DataLoader {
public class MultipleSubmissionLookupDataLoader implements DataLoader
{
private static Logger log = Logger.getLogger(MultipleSubmissionLookupDataLoader.class);
private static final String NOT_FOUND_DOI = "NOT-FOUND-DOI";
private static Logger log = Logger
.getLogger(MultipleSubmissionLookupDataLoader.class);
Map<String, DataLoader> dataloadersMap;
private static final String NOT_FOUND_DOI = "NOT-FOUND-DOI";
//Depending on these values, the multiple data loader loads data from the appropriate providers
Map<String, Set<String>> identifiers = null; //Searching by identifiers (DOI ...)
Map<String, Set<String>> searchTerms = null; //Searching by author, title, date
String filename = null; //Uploading file
String type = null; //the type of the upload file (bibtex, etc.)
/**
* Default constructor
*/
public MultipleSubmissionLookupDataLoader() {
}
Map<String, DataLoader> dataloadersMap;
/* (non-Javadoc)
* @see gr.ekt.bte.core.DataLoader#getRecords()
*/
@Override
public RecordSet getRecords() throws MalformedSourceException {
// Depending on these values, the multiple data loader loads data from the
// appropriate providers
Map<String, Set<String>> identifiers = null; // Searching by identifiers
// (DOI ...)
RecordSet recordSet = new RecordSet();
Map<String, Set<String>> searchTerms = null; // Searching by author, title,
// date
//KSTA:ToDo: Support timeout (problematic) providers
//List<String> timeoutProviders = new ArrayList<String>();
for (String providerName : filterProviders().keySet()) {
DataLoader provider = dataloadersMap.get(providerName);
RecordSet subRecordSet = provider.getRecords();
recordSet.addAll(subRecordSet);
//Add in each record the provider name... a new provider doesn't need to know about it!
for (Record record: subRecordSet.getRecords()){
if (record.isMutable()){
record.makeMutable().addValue(SubmissionLookupService.PROVIDER_NAME_FIELD, new StringValue(providerName));
}
}
}
String filename = null; // Uploading file
//Question: Do we want that in case of file data loader?
//for each publication in the record set, if it has a DOI, try to find extra pubs from the other providers
if (searchTerms!=null || (identifiers!=null && !identifiers.containsKey(SubmissionLookupDataLoader.DOI))){ //Extend
Map<String, Set<String>> provider2foundDOIs = new HashMap<String, Set<String>>();
List<String> foundDOIs = new ArrayList<String>();
String type = null; // the type of the upload file (bibtex, etc.)
for (Record publication : recordSet.getRecords()) {
String providerName = SubmissionLookupUtils.getFirstValue(publication, SubmissionLookupService.PROVIDER_NAME_FIELD);
/**
* Default constructor
*/
public MultipleSubmissionLookupDataLoader()
{
}
String doi = null;
/*
* (non-Javadoc)
*
* @see gr.ekt.bte.core.DataLoader#getRecords()
*/
@Override
public RecordSet getRecords() throws MalformedSourceException
{
if (publication.getValues(SubmissionLookupDataLoader.DOI) != null && publication.getValues(SubmissionLookupDataLoader.DOI).size()>0)
doi = publication.getValues(SubmissionLookupDataLoader.DOI).iterator().next().getAsString();
if (doi == null) {
doi = NOT_FOUND_DOI;
} else {
doi = SubmissionLookupUtils.normalizeDOI(doi);
if (!foundDOIs.contains(doi))
{
foundDOIs.add(doi);
}
Set<String> tmp = provider2foundDOIs.get(providerName);
if (tmp == null) {
tmp = new HashSet<String>();
provider2foundDOIs.put(providerName, tmp);
}
tmp.add(doi);
}
}
RecordSet recordSet = new RecordSet();
for (String providerName : dataloadersMap.keySet()) {
DataLoader genProvider = dataloadersMap.get(providerName);
if (! (genProvider instanceof SubmissionLookupDataLoader)){
continue;
}
SubmissionLookupDataLoader provider = (SubmissionLookupDataLoader)genProvider;
//Provider must support DOI
if (provider.getSupportedIdentifiers().contains(SubmissionLookupDataLoader.DOI)){
continue;
}
//if (evictProviders != null
// && evictProviders.contains(provider.getShortName())) {
// continue;
//}
Set<String> doiToSearch = new HashSet<String>();
Set<String> alreadyFoundDOIs = provider2foundDOIs.get(providerName);
for (String doi : foundDOIs) {
if (alreadyFoundDOIs == null
|| !alreadyFoundDOIs.contains(doi)) {
doiToSearch.add(doi);
}
}
List<Record> pPublications = null;
try {
if (doiToSearch.size() > 0) {
pPublications = provider
.getByDOIs(null, doiToSearch);
}
} catch (Exception e) {
e.printStackTrace();
}
if (pPublications != null) {
for (Record rec : pPublications){
recordSet.addRecord(rec);
}
}
}
}
// KSTA:ToDo: Support timeout (problematic) providers
// List<String> timeoutProviders = new ArrayList<String>();
for (String providerName : filterProviders().keySet())
{
DataLoader provider = dataloadersMap.get(providerName);
RecordSet subRecordSet = provider.getRecords();
recordSet.addAll(subRecordSet);
// Add in each record the provider name... a new provider doesn't
// need to know about it!
for (Record record : subRecordSet.getRecords())
{
if (record.isMutable())
{
record.makeMutable().addValue(
SubmissionLookupService.PROVIDER_NAME_FIELD,
new StringValue(providerName));
}
}
}
log.info("BTE DataLoader finished. Items loaded: " + recordSet.getRecords().size());
//Printing debug message
String totalString = "";
for (Record record : recordSet.getRecords()){
totalString += SubmissionLookupUtils.getPrintableString(record)+"\n";
}
log.debug("Records loaded:\n"+totalString);
return recordSet;
}
// Question: Do we want that in case of file data loader?
// for each publication in the record set, if it has a DOI, try to find
// extra pubs from the other providers
if (searchTerms != null
|| (identifiers != null && !identifiers
.containsKey(SubmissionLookupDataLoader.DOI)))
{ // Extend
Map<String, Set<String>> provider2foundDOIs = new HashMap<String, Set<String>>();
List<String> foundDOIs = new ArrayList<String>();
/* (non-Javadoc)
* @see gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
*/
@Override
public RecordSet getRecords(DataLoadingSpec loadingSpec)
throws MalformedSourceException {
for (Record publication : recordSet.getRecords())
{
String providerName = SubmissionLookupUtils.getFirstValue(
publication,
SubmissionLookupService.PROVIDER_NAME_FIELD);
if (loadingSpec.getOffset()>0) //Identify the end of loading
return new RecordSet();
return getRecords();
}
String doi = null;
public Map<String, DataLoader> getProvidersMap() {
return dataloadersMap;
}
if (publication.getValues(SubmissionLookupDataLoader.DOI) != null
&& publication
.getValues(SubmissionLookupDataLoader.DOI)
.size() > 0)
doi = publication.getValues(SubmissionLookupDataLoader.DOI)
.iterator().next().getAsString();
if (doi == null)
{
doi = NOT_FOUND_DOI;
}
else
{
doi = SubmissionLookupUtils.normalizeDOI(doi);
if (!foundDOIs.contains(doi))
{
foundDOIs.add(doi);
}
Set<String> tmp = provider2foundDOIs.get(providerName);
if (tmp == null)
{
tmp = new HashSet<String>();
provider2foundDOIs.put(providerName, tmp);
}
tmp.add(doi);
}
}
public void setDataloadersMap(Map<String, DataLoader> providersMap) {
this.dataloadersMap = providersMap;
}
for (String providerName : dataloadersMap.keySet())
{
DataLoader genProvider = dataloadersMap.get(providerName);
public void setIdentifiers(Map<String, Set<String>> identifiers) {
this.identifiers = identifiers;
this.filename = null;
this.searchTerms = null;
if (dataloadersMap!=null){
for (String providerName : dataloadersMap.keySet()) {
DataLoader provider = dataloadersMap.get(providerName);
if (provider instanceof NetworkSubmissionLookupDataLoader){
((NetworkSubmissionLookupDataLoader)provider).setIdentifiers(identifiers);
}
}
}
}
if (!(genProvider instanceof SubmissionLookupDataLoader))
{
continue;
}
public void setSearchTerms(Map<String, Set<String>> searchTerms) {
this.searchTerms = searchTerms;
this.identifiers = null;
this.filename = null;
if (dataloadersMap!=null){
for (String providerName : dataloadersMap.keySet()) {
DataLoader provider = dataloadersMap.get(providerName);
if (provider instanceof NetworkSubmissionLookupDataLoader){
((NetworkSubmissionLookupDataLoader)provider).setSearchTerms(searchTerms);
}
}
}
}
SubmissionLookupDataLoader provider = (SubmissionLookupDataLoader) genProvider;
public void setFile(String filename, String type) {
this.filename = filename;
this.type = type;
this.identifiers = null;
this.searchTerms = null;
if (dataloadersMap!=null){
for (String providerName : dataloadersMap.keySet()) {
DataLoader provider = dataloadersMap.get(providerName);
if (provider instanceof FileDataLoader){
((FileDataLoader)provider).setFilename(filename);
}
}
}
}
public Map<String, DataLoader> filterProviders(){
Map<String, DataLoader> result = new HashMap<String, DataLoader>();
for (String providerName : dataloadersMap.keySet()) {
DataLoader dataLoader = dataloadersMap.get(providerName);
if (searchTerms != null && identifiers == null && filename == null){
if (dataLoader instanceof SubmissionLookupDataLoader &&
((SubmissionLookupDataLoader)dataLoader).isSearchProvider()){
result.put(providerName, dataLoader);
}
}
else if (searchTerms == null && identifiers != null && filename == null){
if (dataLoader instanceof SubmissionLookupDataLoader){
result.put(providerName, dataLoader);
}
}
else if (searchTerms == null && identifiers == null && filename != null){
if (dataLoader instanceof FileDataLoader){
if (providerName.endsWith(type)) //add only the one that we are interested in
result.put(providerName, dataLoader);
}
}
}
return result;
}
// Provider must support DOI
if (provider.getSupportedIdentifiers().contains(
SubmissionLookupDataLoader.DOI))
{
continue;
}
// if (evictProviders != null
// && evictProviders.contains(provider.getShortName())) {
// continue;
// }
Set<String> doiToSearch = new HashSet<String>();
Set<String> alreadyFoundDOIs = provider2foundDOIs
.get(providerName);
for (String doi : foundDOIs)
{
if (alreadyFoundDOIs == null
|| !alreadyFoundDOIs.contains(doi))
{
doiToSearch.add(doi);
}
}
List<Record> pPublications = null;
try
{
if (doiToSearch.size() > 0)
{
pPublications = provider.getByDOIs(null, doiToSearch);
}
}
catch (Exception e)
{
e.printStackTrace();
}
if (pPublications != null)
{
for (Record rec : pPublications)
{
recordSet.addRecord(rec);
}
}
}
}
log.info("BTE DataLoader finished. Items loaded: "
+ recordSet.getRecords().size());
// Printing debug message
String totalString = "";
for (Record record : recordSet.getRecords())
{
totalString += SubmissionLookupUtils.getPrintableString(record)
+ "\n";
}
log.debug("Records loaded:\n" + totalString);
return recordSet;
}
/*
* (non-Javadoc)
*
* @see
* gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
*/
@Override
public RecordSet getRecords(DataLoadingSpec loadingSpec)
throws MalformedSourceException
{
if (loadingSpec.getOffset() > 0) // Identify the end of loading
return new RecordSet();
return getRecords();
}
public Map<String, DataLoader> getProvidersMap()
{
return dataloadersMap;
}
public void setDataloadersMap(Map<String, DataLoader> providersMap)
{
this.dataloadersMap = providersMap;
}
public void setIdentifiers(Map<String, Set<String>> identifiers)
{
this.identifiers = identifiers;
this.filename = null;
this.searchTerms = null;
if (dataloadersMap != null)
{
for (String providerName : dataloadersMap.keySet())
{
DataLoader provider = dataloadersMap.get(providerName);
if (provider instanceof NetworkSubmissionLookupDataLoader)
{
((NetworkSubmissionLookupDataLoader) provider)
.setIdentifiers(identifiers);
}
}
}
}
public void setSearchTerms(Map<String, Set<String>> searchTerms)
{
this.searchTerms = searchTerms;
this.identifiers = null;
this.filename = null;
if (dataloadersMap != null)
{
for (String providerName : dataloadersMap.keySet())
{
DataLoader provider = dataloadersMap.get(providerName);
if (provider instanceof NetworkSubmissionLookupDataLoader)
{
((NetworkSubmissionLookupDataLoader) provider)
.setSearchTerms(searchTerms);
}
}
}
}
public void setFile(String filename, String type)
{
this.filename = filename;
this.type = type;
this.identifiers = null;
this.searchTerms = null;
if (dataloadersMap != null)
{
for (String providerName : dataloadersMap.keySet())
{
DataLoader provider = dataloadersMap.get(providerName);
if (provider instanceof FileDataLoader)
{
((FileDataLoader) provider).setFilename(filename);
}
}
}
}
public Map<String, DataLoader> filterProviders()
{
Map<String, DataLoader> result = new HashMap<String, DataLoader>();
for (String providerName : dataloadersMap.keySet())
{
DataLoader dataLoader = dataloadersMap.get(providerName);
if (searchTerms != null && identifiers == null && filename == null)
{
if (dataLoader instanceof SubmissionLookupDataLoader
&& ((SubmissionLookupDataLoader) dataLoader)
.isSearchProvider())
{
result.put(providerName, dataLoader);
}
}
else if (searchTerms == null && identifiers != null
&& filename == null)
{
if (dataLoader instanceof SubmissionLookupDataLoader)
{
result.put(providerName, dataLoader);
}
}
else if (searchTerms == null && identifiers == null
&& filename != null)
{
if (dataLoader instanceof FileDataLoader)
{
if (providerName.endsWith(type)) // add only the one that we
// are interested in
result.put(providerName, dataLoader);
}
}
}
return result;
}
}

View File

@@ -30,121 +30,156 @@ import org.apache.commons.lang.StringUtils;
import org.dspace.core.Context;
import org.dspace.submit.util.SubmissionLookupPublication;
/**
* @author Andrea Bollini
* @author Kostas Stamatis
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public abstract class NetworkSubmissionLookupDataLoader implements SubmissionLookupDataLoader {
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
String providerName;
@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);
}
public abstract class NetworkSubmissionLookupDataLoader implements
SubmissionLookupDataLoader
{
//BTE Data Loader interface methods
@Override
public RecordSet getRecords() throws MalformedSourceException {
Map<String, Set<String>> identifiers; // Searching by identifiers (DOI ...)
RecordSet recordSet = new RecordSet();
Map<String, Set<String>> searchTerms; // Searching by author, title, date
List<Record> results = null;
Map<String, String> fieldMap; // mapping between service fields and local
// intermediate fields
try {
if (getIdentifiers()!=null){ //Search by identifiers
results = getByIdentifier(null, getIdentifiers());
}
else {
String title = getSearchTerms().get("title")!=null?getSearchTerms().get("title").iterator().next():null;
String authors = getSearchTerms().get("authors")!=null?getSearchTerms().get("authors").iterator().next():null;
String year = getSearchTerms().get("year")!=null?getSearchTerms().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();
}
String providerName;
if (results != null){
for (Record record : results){
recordSet.addRecord(record);
}
}
@Override
public List<Record> getByDOIs(Context context, Set<String> doiToSearch)
throws HttpException, IOException
{
return recordSet;
}
Map<String, Set<String>> keys = new HashMap<String, Set<String>>();
keys.put(DOI, doiToSearch);
@Override
public RecordSet getRecords(DataLoadingSpec arg0)
throws MalformedSourceException {
return getRecords();
}
public Map<String, Set<String>> getIdentifiers() {
return identifiers;
}
return getByIdentifier(context, keys);
}
public void setIdentifiers(Map<String, Set<String>> identifiers) {
this.identifiers = identifiers;
}
// BTE Data Loader interface methods
@Override
public RecordSet getRecords() throws MalformedSourceException
{
public Map<String, Set<String>> getSearchTerms() {
return searchTerms;
}
RecordSet recordSet = new RecordSet();
public void setSearchTerms(Map<String, Set<String>> searchTerms) {
this.searchTerms = searchTerms;
}
public Map<String, String> getFieldMap() {
return fieldMap;
}
List<Record> results = null;
public void setFieldMap(Map<String, String> fieldMap) {
this.fieldMap = fieldMap;
}
try
{
if (getIdentifiers() != null)
{ // Search by identifiers
results = getByIdentifier(null, getIdentifiers());
}
else
{
String title = getSearchTerms().get("title") != null ? getSearchTerms()
.get("title").iterator().next()
: null;
String authors = getSearchTerms().get("authors") != null ? getSearchTerms()
.get("authors").iterator().next()
: null;
String year = getSearchTerms().get("year") != null ? getSearchTerms()
.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();
}
public void setProviderName(String providerName) {
this.providerName = providerName;
}
public Record convertFields(Record publication) {
for (String fieldName : fieldMap.keySet()) {
String md = null;
if (fieldMap!=null){
md = this.fieldMap.get(fieldName);
}
if (results != null)
{
for (Record record : results)
{
recordSet.addRecord(record);
}
}
if (StringUtils.isBlank(md)) {
continue;
} else {
md = md.trim();
}
return recordSet;
}
if (publication.isMutable()){
List<Value> values = publication.getValues(fieldName);
publication.makeMutable().removeField(fieldName);
publication.makeMutable().addField(md, values);
}
}
return publication;
}
@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 void setProviderName(String providerName)
{
this.providerName = providerName;
}
public Record convertFields(Record publication)
{
for (String fieldName : fieldMap.keySet())
{
String md = null;
if (fieldMap != null)
{
md = this.fieldMap.get(fieldName);
}
if (StringUtils.isBlank(md))
{
continue;
}
else
{
md = md.trim();
}
if (publication.isMutable())
{
List<Value> values = publication.getValues(fieldName);
publication.makeMutable().removeField(fieldName);
publication.makeMutable().addField(md, values);
}
}
return publication;
}
}

View File

@@ -39,104 +39,136 @@ import org.xml.sax.SAXException;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class PubmedFileDataLoader extends FileDataLoader {
public class PubmedFileDataLoader extends FileDataLoader
{
Map<String, String> fieldMap; //mapping between service fields and local intermediate fields
Map<String, String> fieldMap; // mapping between service fields and local
// intermediate fields
/**
/**
*
*/
public PubmedFileDataLoader() {
}
public PubmedFileDataLoader()
{
}
/**
* @param filename
*/
public PubmedFileDataLoader(String filename) {
super(filename);
}
/**
* @param filename
*/
public PubmedFileDataLoader(String filename)
{
super(filename);
}
/* (non-Javadoc)
* @see gr.ekt.bte.core.DataLoader#getRecords()
*/
@Override
public RecordSet getRecords() throws MalformedSourceException {
/*
* (non-Javadoc)
*
* @see gr.ekt.bte.core.DataLoader#getRecords()
*/
@Override
public RecordSet getRecords() throws MalformedSourceException
{
RecordSet recordSet = new RecordSet();
RecordSet recordSet = new RecordSet();
try {
InputStream inputStream = new FileInputStream(new File(filename));
try
{
InputStream inputStream = new FileInputStream(new File(filename));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document inDoc = builder.parse(inputStream);
DocumentBuilder builder = factory.newDocumentBuilder();
Document inDoc = builder.parse(inputStream);
Element xmlRoot = inDoc.getDocumentElement();
List<Element> pubArticles = XMLUtils
.getElementList(xmlRoot, "PubmedArticle");
Element xmlRoot = inDoc.getDocumentElement();
List<Element> pubArticles = XMLUtils.getElementList(xmlRoot,
"PubmedArticle");
for (Element xmlArticle : pubArticles)
{
Record record = null;
try {
record = PubmedUtils.convertCrossRefDomToRecord(xmlArticle);
recordSet.addRecord(convertFields(record));
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
for (Element xmlArticle : pubArticles)
{
Record record = null;
try
{
record = PubmedUtils.convertCrossRefDomToRecord(xmlArticle);
recordSet.addRecord(convertFields(record));
}
catch (Exception e)
{
throw new RuntimeException(e.getMessage(), e);
}
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (ParserConfigurationException e)
{
e.printStackTrace();
}
catch (SAXException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return recordSet;
return recordSet;
}
}
/* (non-Javadoc)
* @see gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
*/
@Override
public RecordSet getRecords(DataLoadingSpec spec)
throws MalformedSourceException {
/*
* (non-Javadoc)
*
* @see
* gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
*/
@Override
public RecordSet getRecords(DataLoadingSpec spec)
throws MalformedSourceException
{
return getRecords();
}
return getRecords();
}
public Record convertFields(Record publication) {
for (String fieldName : fieldMap.keySet()) {
String md = null;
if (fieldMap!=null){
md = this.fieldMap.get(fieldName);
}
public Record convertFields(Record publication)
{
for (String fieldName : fieldMap.keySet())
{
String md = null;
if (fieldMap != null)
{
md = this.fieldMap.get(fieldName);
}
if (StringUtils.isBlank(md)) {
continue;
} else {
md = md.trim();
}
if (StringUtils.isBlank(md))
{
continue;
}
else
{
md = md.trim();
}
if (publication.isMutable()){
List<Value> values = publication.getValues(fieldName);
publication.makeMutable().removeField(fieldName);
publication.makeMutable().addField(md, values);
}
}
if (publication.isMutable())
{
List<Value> values = publication.getValues(fieldName);
publication.makeMutable().removeField(fieldName);
publication.makeMutable().addField(md, values);
}
}
return publication;
}
return publication;
}
public void setFieldMap(Map<String, String> fieldMap) {
this.fieldMap = fieldMap;
}
public void setFieldMap(Map<String, String> fieldMap)
{
this.fieldMap = fieldMap;
}
}

View File

@@ -27,91 +27,113 @@ import org.dspace.core.LogManager;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class PubmedOnlineDataLoader extends NetworkSubmissionLookupDataLoader {
public class PubmedOnlineDataLoader extends NetworkSubmissionLookupDataLoader
{
private boolean searchProvider = true;
private static Logger log = Logger.getLogger(PubmedOnlineDataLoader.class);
private PubmedService pubmedService = new PubmedService();
public void setPubmedService(PubmedService pubmedService) {
this.pubmedService = pubmedService;
}
@Override
public List<String> getSupportedIdentifiers() {
return Arrays.asList(new String[] { PUBMED, DOI });
}
public void setPubmedService(PubmedService pubmedService)
{
this.pubmedService = pubmedService;
}
public void setSearchProvider(boolean searchProvider)
@Override
public List<String> getSupportedIdentifiers()
{
return Arrays.asList(new String[] { PUBMED, DOI });
}
public void setSearchProvider(boolean searchProvider)
{
this.searchProvider = searchProvider;
}
@Override
public boolean isSearchProvider() {
return searchProvider;
}
@Override
public List<Record> getByIdentifier(Context context,
Map<String, Set<String>> keys) throws HttpException, IOException {
Set<String> pmids = keys != null ? keys.get(PUBMED) : null;
Set<String> dois = keys != null ? keys.get(DOI) : null;
List<Record> results = new ArrayList<Record>();
if (pmids != null && pmids.size()>0 && (dois == null || dois.size()==0)) {
for (String pmid : pmids){
Record p = null;
try
{
p = pubmedService.getByPubmedID(pmid);
}
catch (Exception e)
{
log.error(LogManager.getHeader(context, "getByIdentifier", "pmid="+pmid), e);
}
if (p != null)
results.add(convertFields(p));
}
}
else if (dois != null && dois.size()>0 && (pmids == null || pmids.size()==0)) {
StringBuffer query = new StringBuffer();
for (String d : dois) {
if (query.length() > 0) {
query.append(" OR ");
}
query.append(d).append("[AI]");
}
@Override
public boolean isSearchProvider()
{
return searchProvider;
}
List<Record> pubmedResults = pubmedService.search(query.toString());
for (Record p : pubmedResults) {
results.add(convertFields(p));
}
}
else if (dois != null && dois.size()>0 && pmids != null && pmids.size()>0)
{
//EKT:ToDo: support list of dois and pmids in the search method of pubmedService
List<Record> pubmedResults = pubmedService.search(dois.iterator().next(), pmids.iterator().next());
if (pubmedResults != null) {
for (Record p : pubmedResults) {
results.add(convertFields(p));
}
}
}
return results;
}
@Override
public List<Record> getByIdentifier(Context context,
Map<String, Set<String>> keys) throws HttpException, IOException
{
Set<String> pmids = keys != null ? keys.get(PUBMED) : null;
Set<String> dois = keys != null ? keys.get(DOI) : null;
List<Record> results = new ArrayList<Record>();
if (pmids != null && pmids.size() > 0
&& (dois == null || dois.size() == 0))
{
for (String pmid : pmids)
{
Record p = null;
try
{
p = pubmedService.getByPubmedID(pmid);
}
catch (Exception e)
{
log.error(LogManager.getHeader(context, "getByIdentifier",
"pmid=" + pmid), e);
}
if (p != null)
results.add(convertFields(p));
}
}
else if (dois != null && dois.size() > 0
&& (pmids == null || pmids.size() == 0))
{
StringBuffer query = new StringBuffer();
for (String d : dois)
{
if (query.length() > 0)
{
query.append(" OR ");
}
query.append(d).append("[AI]");
}
@Override
public List<Record> search(Context context, String title,
String author, int year) throws HttpException, IOException {
List<Record> pubmedResults = pubmedService.search(title, author,
year);
List<Record> results = new ArrayList<Record>();
if (pubmedResults != null) {
for (Record p : pubmedResults) {
results.add(convertFields(p));
}
}
return results;
}
List<Record> pubmedResults = pubmedService.search(query.toString());
for (Record p : pubmedResults)
{
results.add(convertFields(p));
}
}
else if (dois != null && dois.size() > 0 && pmids != null
&& pmids.size() > 0)
{
// EKT:ToDo: support list of dois and pmids in the search method of
// pubmedService
List<Record> pubmedResults = pubmedService.search(dois.iterator()
.next(), pmids.iterator().next());
if (pubmedResults != null)
{
for (Record p : pubmedResults)
{
results.add(convertFields(p));
}
}
}
return results;
}
@Override
public List<Record> search(Context context, String title, String author,
int year) throws HttpException, IOException
{
List<Record> pubmedResults = pubmedService.search(title, author, year);
List<Record> results = new ArrayList<Record>();
if (pubmedResults != null)
{
for (Record p : pubmedResults)
{
results.add(convertFields(p));
}
}
return results;
}
}

View File

@@ -39,256 +39,315 @@ import org.xml.sax.SAXException;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class PubmedService {
private static Logger log = Logger.getLogger(PubmedService.class);
private int timeout = 1000;
public void setTimeout(int timeout) {
this.timeout = timeout;
}
public Record getByPubmedID(String pubmedid) throws HttpException,
IOException, ParserConfigurationException, SAXException {
List<String> ids = new ArrayList<String>();
ids.add(pubmedid.trim());
List<Record> items = getByPubmedIDs(ids);
if (items != null && items.size() > 0)
{
return items.get(0);
}
return null;
}
public class PubmedService
{
public List<Record> search(String title, String author, int year)
throws HttpException, IOException {
StringBuffer query = new StringBuffer();
if (StringUtils.isNotBlank(title)) {
query.append("((").append(title).append("[TI]) OR (");
// [TI] non funziona sempre, titolo di capitoli di libro
query.append("(").append(title).append("[book]))");
}
if (StringUtils.isNotBlank(author)) {
// [FAU]
if (query.length() > 0)
query.append(" AND ");
query.append("(").append(author).append("[AU])");
}
if (year != -1)
{
// [DP]
if (query.length() > 0)
query.append(" AND ");
query.append(year).append("[DP]");
}
return search(query.toString());
}
private static Logger log = Logger.getLogger(PubmedService.class);
public List<Record> search(String query) throws IOException,
HttpException {
List<Record> results = null;
if (!ConfigurationManager.getBooleanProperty("remoteservice.demo")) {
GetMethod method = null;
try {
HttpClient client = new HttpClient();
client.setTimeout(timeout);
method = new GetMethod(
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi");
private int timeout = 1000;
NameValuePair db = new NameValuePair("db", "pubmed");
NameValuePair datetype = new NameValuePair("datetype", "edat");
NameValuePair retmax = new NameValuePair("retmax", "10");
NameValuePair queryParam = new NameValuePair("term",
query.toString());
method.setQueryString(new NameValuePair[] { db, queryParam,
retmax, datetype });
// Execute the method.
int statusCode = client.executeMethod(method);
public void setTimeout(int timeout)
{
this.timeout = timeout;
}
if (statusCode != HttpStatus.SC_OK) {
throw new RuntimeException(
"WS call failed: "
+ method.getStatusLine());
}
public Record getByPubmedID(String pubmedid) throws HttpException,
IOException, ParserConfigurationException, SAXException
{
List<String> ids = new ArrayList<String>();
ids.add(pubmedid.trim());
List<Record> items = getByPubmedIDs(ids);
if (items != null && items.size() > 0)
{
return items.get(0);
}
return null;
}
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
public List<Record> search(String title, String author, int year)
throws HttpException, IOException
{
StringBuffer query = new StringBuffer();
if (StringUtils.isNotBlank(title))
{
query.append("((").append(title).append("[TI]) OR (");
// [TI] non funziona sempre, titolo di capitoli di libro
query.append("(").append(title).append("[book]))");
}
if (StringUtils.isNotBlank(author))
{
// [FAU]
if (query.length() > 0)
query.append(" AND ");
query.append("(").append(author).append("[AU])");
}
if (year != -1)
{
// [DP]
if (query.length() > 0)
query.append(" AND ");
query.append(year).append("[DP]");
}
return search(query.toString());
}
DocumentBuilder builder;
try {
builder = factory.newDocumentBuilder();
public List<Record> search(String query) throws IOException, HttpException
{
List<Record> results = null;
if (!ConfigurationManager.getBooleanProperty("remoteservice.demo"))
{
GetMethod method = null;
try
{
HttpClient client = new HttpClient();
client.setTimeout(timeout);
method = new GetMethod(
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi");
Document inDoc = builder.parse(method
.getResponseBodyAsStream());
NameValuePair db = new NameValuePair("db", "pubmed");
NameValuePair datetype = new NameValuePair("datetype", "edat");
NameValuePair retmax = new NameValuePair("retmax", "10");
NameValuePair queryParam = new NameValuePair("term",
query.toString());
method.setQueryString(new NameValuePair[] { db, queryParam,
retmax, datetype });
// Execute the method.
int statusCode = client.executeMethod(method);
Element xmlRoot = inDoc.getDocumentElement();
Element idList = XMLUtils.getSingleElement(xmlRoot,
"IdList");
List<String> pubmedIDs = XMLUtils.getElementValueList(
idList, "Id");
results = getByPubmedIDs(pubmedIDs);
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
catch (SAXException e1) {
log.error(e1.getMessage(), e1);
}
} finally {
if (method != null) {
method.releaseConnection();
}
}
} else {
InputStream stream = null;
try {
File file = new File(
ConfigurationManager.getProperty("dspace.dir")
+ "/config/crosswalks/demo/pubmed-search.xml");
stream = new FileInputStream(file);
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
if (statusCode != HttpStatus.SC_OK)
{
throw new RuntimeException("WS call failed: "
+ method.getStatusLine());
}
DocumentBuilder builder = factory.newDocumentBuilder();
Document inDoc = builder.parse(stream);
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
Element xmlRoot = inDoc.getDocumentElement();
Element idList = XMLUtils.getSingleElement(xmlRoot, "IdList");
List<String> pubmedIDs = XMLUtils.getElementValueList(idList,
"Id");
results = getByPubmedIDs(pubmedIDs);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
return results;
}
DocumentBuilder builder;
try
{
builder = factory.newDocumentBuilder();
public List<Record> getByPubmedIDs(List<String> pubmedIDs)
throws HttpException, IOException, ParserConfigurationException, SAXException {
List<Record> results = new ArrayList<Record>();
if (!ConfigurationManager.getBooleanProperty("remoteservice.demo")) {
GetMethod method = null;
try {
HttpClient client = new HttpClient();
client.setTimeout(5 * timeout);
method = new GetMethod(
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi");
Document inDoc = builder.parse(method
.getResponseBodyAsStream());
NameValuePair db = new NameValuePair("db", "pubmed");
NameValuePair retmode = new NameValuePair("retmode", "xml");
NameValuePair rettype = new NameValuePair("rettype", "full");
NameValuePair id = new NameValuePair("id", StringUtils.join(pubmedIDs.iterator(), ","));
method.setQueryString(new NameValuePair[] { db, retmode,
rettype, id });
// Execute the method.
int statusCode = client.executeMethod(method);
Element xmlRoot = inDoc.getDocumentElement();
Element idList = XMLUtils.getSingleElement(xmlRoot,
"IdList");
List<String> pubmedIDs = XMLUtils.getElementValueList(
idList, "Id");
results = getByPubmedIDs(pubmedIDs);
}
catch (ParserConfigurationException e)
{
e.printStackTrace();
}
catch (SAXException e1)
{
log.error(e1.getMessage(), e1);
}
}
finally
{
if (method != null)
{
method.releaseConnection();
}
}
}
else
{
InputStream stream = null;
try
{
File file = new File(
ConfigurationManager.getProperty("dspace.dir")
+ "/config/crosswalks/demo/pubmed-search.xml");
stream = new FileInputStream(file);
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
if (statusCode != HttpStatus.SC_OK) {
throw new RuntimeException(
"WS call failed: "
+ method.getStatusLine());
}
DocumentBuilder builder = factory.newDocumentBuilder();
Document inDoc = builder.parse(stream);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
Element xmlRoot = inDoc.getDocumentElement();
Element idList = XMLUtils.getSingleElement(xmlRoot, "IdList");
List<String> pubmedIDs = XMLUtils.getElementValueList(idList,
"Id");
results = getByPubmedIDs(pubmedIDs);
}
catch (Exception e)
{
throw new RuntimeException(e.getMessage(), e);
}
finally
{
if (stream != null)
{
try
{
stream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
return results;
}
DocumentBuilder builder = factory.newDocumentBuilder();
Document inDoc = builder.parse(method.getResponseBodyAsStream());
public List<Record> getByPubmedIDs(List<String> pubmedIDs)
throws HttpException, IOException, ParserConfigurationException,
SAXException
{
List<Record> results = new ArrayList<Record>();
if (!ConfigurationManager.getBooleanProperty("remoteservice.demo"))
{
GetMethod method = null;
try
{
HttpClient client = new HttpClient();
client.setTimeout(5 * timeout);
method = new GetMethod(
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi");
Element xmlRoot = inDoc.getDocumentElement();
List<Element> pubArticles = XMLUtils
.getElementList(xmlRoot, "PubmedArticle");
NameValuePair db = new NameValuePair("db", "pubmed");
NameValuePair retmode = new NameValuePair("retmode", "xml");
NameValuePair rettype = new NameValuePair("rettype", "full");
NameValuePair id = new NameValuePair("id", StringUtils.join(
pubmedIDs.iterator(), ","));
method.setQueryString(new NameValuePair[] { db, retmode,
rettype, id });
// Execute the method.
int statusCode = client.executeMethod(method);
for (Element xmlArticle : pubArticles)
{
Record pubmedItem = null;
try {
pubmedItem = PubmedUtils.convertCrossRefDomToRecord(xmlArticle);
results.add(pubmedItem);
} catch (Exception e) {
throw new RuntimeException(
"PubmedID is not valid or not exist: "+e.getMessage(), e);
}
}
if (statusCode != HttpStatus.SC_OK)
{
throw new RuntimeException("WS call failed: "
+ method.getStatusLine());
}
return results;
} finally {
if (method != null) {
method.releaseConnection();
}
}
} else {
InputStream stream = null;
try {
File file = new File(
ConfigurationManager.getProperty("dspace.dir")
+ "/config/crosswalks/demo/pubmed.xml");
stream = new FileInputStream(file);
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document inDoc = builder
.parse(method.getResponseBodyAsStream());
DocumentBuilder builder = factory.newDocumentBuilder();
Document inDoc = builder.parse(stream);
Element xmlRoot = inDoc.getDocumentElement();
List<Element> pubArticles = XMLUtils.getElementList(xmlRoot,
"PubmedArticle");
Element xmlRoot = inDoc.getDocumentElement();
List<Element> pubArticles = XMLUtils
.getElementList(xmlRoot, "PubmedArticle");
for (Element xmlArticle : pubArticles)
{
Record pubmedItem = null;
try
{
pubmedItem = PubmedUtils
.convertCrossRefDomToRecord(xmlArticle);
results.add(pubmedItem);
}
catch (Exception e)
{
throw new RuntimeException(
"PubmedID is not valid or not exist: "
+ e.getMessage(), e);
}
}
for (Element xmlArticle : pubArticles)
{
Record pubmedItem = null;
try {
pubmedItem = PubmedUtils.convertCrossRefDomToRecord(xmlArticle);
results.add(pubmedItem);
} catch (Exception e) {
throw new RuntimeException(
"PubmedID is not valid or not exist: "+e.getMessage(), e);
}
}
return results;
}
finally
{
if (method != null)
{
method.releaseConnection();
}
}
}
else
{
InputStream stream = null;
try
{
File file = new File(
ConfigurationManager.getProperty("dspace.dir")
+ "/config/crosswalks/demo/pubmed.xml");
stream = new FileInputStream(file);
return results;
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
} finally {
if (stream != null) {
stream.close();
}
}
}
}
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
public List<Record> search(String doi, String pmid) throws HttpException, IOException {
StringBuffer query = new StringBuffer();
if (StringUtils.isNotBlank(doi)) {
query.append(doi);
query.append("[AID]");
}
if (StringUtils.isNotBlank(pmid)) {
// [FAU]
if (query.length() > 0)
query.append(" OR ");
query.append(pmid).append("[PMID]");
}
return search(query.toString());
}
DocumentBuilder builder = factory.newDocumentBuilder();
Document inDoc = builder.parse(stream);
Element xmlRoot = inDoc.getDocumentElement();
List<Element> pubArticles = XMLUtils.getElementList(xmlRoot,
"PubmedArticle");
for (Element xmlArticle : pubArticles)
{
Record pubmedItem = null;
try
{
pubmedItem = PubmedUtils
.convertCrossRefDomToRecord(xmlArticle);
results.add(pubmedItem);
}
catch (Exception e)
{
throw new RuntimeException(
"PubmedID is not valid or not exist: "
+ e.getMessage(), e);
}
}
return results;
}
catch (Exception e)
{
throw new RuntimeException(e.getMessage(), e);
}
finally
{
if (stream != null)
{
stream.close();
}
}
}
}
public List<Record> search(String doi, String pmid) throws HttpException,
IOException
{
StringBuffer query = new StringBuffer();
if (StringUtils.isNotBlank(doi))
{
query.append(doi);
query.append("[AID]");
}
if (StringUtils.isNotBlank(pmid))
{
// [FAU]
if (query.length() > 0)
query.append(" OR ");
query.append(pmid).append("[PMID]");
}
return search(query.toString());
}
}

View File

@@ -31,12 +31,14 @@ import org.w3c.dom.Element;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class PubmedUtils {
public class PubmedUtils
{
public static Record convertCrossRefDomToRecord(Element pubArticle){
MutableRecord record = new SubmissionLookupPublication("");
Map<String, String> mounthToNum = new HashMap<String, String>();
public static Record convertCrossRefDomToRecord(Element pubArticle)
{
MutableRecord record = new SubmissionLookupPublication("");
Map<String, String> mounthToNum = new HashMap<String, String>();
mounthToNum.put("Jan", "01");
mounthToNum.put("Feb", "02");
mounthToNum.put("Mar", "03");
@@ -49,16 +51,19 @@ public class PubmedUtils {
mounthToNum.put("Oct", "10");
mounthToNum.put("Nov", "11");
mounthToNum.put("Dec", "12");
Element medline = XMLUtils.getSingleElement(pubArticle, "MedlineCitation");
Element medline = XMLUtils.getSingleElement(pubArticle,
"MedlineCitation");
Element article = XMLUtils.getSingleElement(medline, "Article");
Element pubmed = XMLUtils.getSingleElement(pubArticle, "PubmedData");
Element identifierList = XMLUtils.getSingleElement(pubmed, "ArticleIdList");
Element identifierList = XMLUtils.getSingleElement(pubmed,
"ArticleIdList");
if (identifierList != null)
{
List<Element> identifiers = XMLUtils.getElementList(identifierList, "ArticleId");
List<Element> identifiers = XMLUtils.getElementList(identifierList,
"ArticleId");
if (identifiers != null)
{
for (Element id : identifiers)
@@ -66,67 +71,79 @@ public class PubmedUtils {
if ("pubmed".equals(id.getAttribute("IdType")))
{
String pubmedID = id.getTextContent().trim();
if (pubmedID!=null)
record.addValue("pubmedID", new StringValue(pubmedID));
if (pubmedID != null)
record.addValue("pubmedID", new StringValue(
pubmedID));
}
else if ("doi".equals(id.getAttribute("IdType")))
{
String doi = id.getTextContent().trim();
if (doi!=null)
record.addValue("doi", new StringValue(doi));
if (doi != null)
record.addValue("doi", new StringValue(doi));
}
}
}
}
String status = XMLUtils.getElementValue(pubmed, "PublicationStatus");
if (status!=null)
record.addValue("status", new StringValue(status));
String pubblicationModel = XMLUtils.getElementAttribute(medline, "Article", "PubModel");
if (pubblicationModel!=null)
record.addValue("pubblicationModel", new StringValue(pubblicationModel));
if (status != null)
record.addValue("status", new StringValue(status));
String pubblicationModel = XMLUtils.getElementAttribute(medline,
"Article", "PubModel");
if (pubblicationModel != null)
record.addValue("pubblicationModel", new StringValue(
pubblicationModel));
String title = XMLUtils.getElementValue(article, "ArticleTitle");
if (title!=null)
record.addValue("title", new StringValue(title));
Element abstractElement = XMLUtils.getSingleElement(medline, "Abstract");
if (title != null)
record.addValue("title", new StringValue(title));
Element abstractElement = XMLUtils
.getSingleElement(medline, "Abstract");
if (abstractElement == null)
{
abstractElement = XMLUtils.getSingleElement(medline, "OtherAbstract");
abstractElement = XMLUtils.getSingleElement(medline,
"OtherAbstract");
}
if (abstractElement != null)
{
String summary = XMLUtils.getElementValue(abstractElement, "AbstractText");
if (summary!=null)
record.addValue("summary", new StringValue(summary));
String summary = XMLUtils.getElementValue(abstractElement,
"AbstractText");
if (summary != null)
record.addValue("summary", new StringValue(summary));
}
List<String[]> authors = new LinkedList<String[]>();
Element authorList = XMLUtils.getSingleElement(article, "AuthorList");
if (authorList != null)
{
List<Element> authorsElement = XMLUtils.getElementList(authorList, "Author");
List<Element> authorsElement = XMLUtils.getElementList(authorList,
"Author");
if (authorsElement != null)
{
for (Element author : authorsElement)
{
if (StringUtils.isBlank(XMLUtils.getElementValue(author, "CollectiveName")))
if (StringUtils.isBlank(XMLUtils.getElementValue(author,
"CollectiveName")))
{
authors.add(new String[]{XMLUtils.getElementValue(author, "ForeName"),XMLUtils.getElementValue(author, "LastName")});
authors.add(new String[] {
XMLUtils.getElementValue(author, "ForeName"),
XMLUtils.getElementValue(author, "LastName") });
}
}
}
}
if (authors.size()>0){
List<Value> values = new LinkedList<Value>();
for (String[] sArray : authors){
values.add(new StringValue(sArray[1]+", "+sArray[0]));
}
record.addField("authors", values);
}
if (authors.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String[] sArray : authors)
{
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
}
record.addField("authors", values);
}
Element journal = XMLUtils.getSingleElement(article, "Journal");
if (journal != null)
{
@@ -138,43 +155,50 @@ public class PubmedUtils {
if ("Print".equals(jnumber.getAttribute("IssnType")))
{
String issn = jnumber.getTextContent().trim();
if (issn!=null)
record.addValue("issn", new StringValue(issn));
if (issn != null)
record.addValue("issn", new StringValue(issn));
}
else
{
String eissn = jnumber.getTextContent().trim();
if (eissn!=null)
record.addValue("eissn", new StringValue(eissn));
if (eissn != null)
record.addValue("eissn", new StringValue(eissn));
}
}
}
String journalTitle = XMLUtils.getElementValue(journal, "Title");
if (journalTitle!=null)
record.addValue("journalTitle", new StringValue(journalTitle));
Element journalIssueElement = XMLUtils.getSingleElement(journal, "JournalIssue");
if (journalTitle != null)
record.addValue("journalTitle", new StringValue(journalTitle));
Element journalIssueElement = XMLUtils.getSingleElement(journal,
"JournalIssue");
if (journalIssueElement != null)
{
String volume = XMLUtils.getElementValue(journalIssueElement, "Volume");
if (volume!=null)
record.addValue("volume", new StringValue(volume));
String issue = XMLUtils.getElementValue(journalIssueElement, "Issue");
if (issue!=null)
record.addValue("issue", new StringValue(issue));
Element pubDataElement = XMLUtils.getSingleElement(journalIssueElement, "PubDate");
String volume = XMLUtils.getElementValue(journalIssueElement,
"Volume");
if (volume != null)
record.addValue("volume", new StringValue(volume));
String issue = XMLUtils.getElementValue(journalIssueElement,
"Issue");
if (issue != null)
record.addValue("issue", new StringValue(issue));
Element pubDataElement = XMLUtils.getSingleElement(
journalIssueElement, "PubDate");
String year = null;
if (pubDataElement != null)
{
year = XMLUtils.getElementValue(pubDataElement, "Year");
String mounth = XMLUtils.getElementValue(pubDataElement, "Month");
String day = XMLUtils.getElementValue(pubDataElement, "Day");
if (StringUtils.isNotBlank(mounth) && mounthToNum.containsKey(mounth))
String mounth = XMLUtils.getElementValue(pubDataElement,
"Month");
String day = XMLUtils
.getElementValue(pubDataElement, "Day");
if (StringUtils.isNotBlank(mounth)
&& mounthToNum.containsKey(mounth))
{
year += "-" + mounthToNum.get(mounth);
if (StringUtils.isNotBlank(day))
@@ -183,38 +207,44 @@ public class PubmedUtils {
}
}
}
if (year!=null)
record.addValue("year", new StringValue(year));
if (year != null)
record.addValue("year", new StringValue(year));
}
String language = XMLUtils.getElementValue(article, "Language");
if (language!=null)
record.addValue("language", new StringValue(language));
if (language != null)
record.addValue("language", new StringValue(language));
List<String> type = new LinkedList<String>();
Element publicationTypeList = XMLUtils.getSingleElement(article, "PublicationTypeList");
Element publicationTypeList = XMLUtils.getSingleElement(article,
"PublicationTypeList");
if (publicationTypeList != null)
{
List<Element> publicationTypes = XMLUtils.getElementList(publicationTypeList, "PublicationType");
List<Element> publicationTypes = XMLUtils.getElementList(
publicationTypeList, "PublicationType");
for (Element publicationType : publicationTypes)
{
type.add(publicationType.getTextContent().trim());
}
}
if (type.size()>0){
List<Value> values = new LinkedList<Value>();
for (String s : type){
values.add(new StringValue(s));
}
record.addField("type", values);
}
if (type.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String s : type)
{
values.add(new StringValue(s));
}
record.addField("type", values);
}
List<String> primaryKeywords = new LinkedList<String>();
List<String> secondaryKeywords = new LinkedList<String>();
Element keywordsList = XMLUtils.getSingleElement(medline, "KeywordList");
Element keywordsList = XMLUtils.getSingleElement(medline,
"KeywordList");
if (keywordsList != null)
{
List<Element> keywords = XMLUtils.getElementList(keywordsList, "Keyword");
List<Element> keywords = XMLUtils.getElementList(keywordsList,
"Keyword");
for (Element keyword : keywords)
{
if ("Y".equals(keyword.getAttribute("MajorTopicYN")))
@@ -227,71 +257,88 @@ public class PubmedUtils {
}
}
}
if (primaryKeywords.size()>0){
List<Value> values = new LinkedList<Value>();
for (String s : primaryKeywords){
values.add(new StringValue(s));
}
record.addField("primaryKeywords", values);
}
if (secondaryKeywords.size()>0){
List<Value> values = new LinkedList<Value>();
for (String s : secondaryKeywords){
values.add(new StringValue(s));
}
record.addField("secondaryKeywords", values);
}
if (primaryKeywords.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String s : primaryKeywords)
{
values.add(new StringValue(s));
}
record.addField("primaryKeywords", values);
}
if (secondaryKeywords.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String s : secondaryKeywords)
{
values.add(new StringValue(s));
}
record.addField("secondaryKeywords", values);
}
List<String> primaryMeshHeadings = new LinkedList<String>();
List<String> secondaryMeshHeadings = new LinkedList<String>();
Element meshHeadingsList = XMLUtils.getSingleElement(medline, "MeshHeadingList");
Element meshHeadingsList = XMLUtils.getSingleElement(medline,
"MeshHeadingList");
if (meshHeadingsList != null)
{
List<Element> meshHeadings = XMLUtils.getElementList(meshHeadingsList, "MeshHeading");
List<Element> meshHeadings = XMLUtils.getElementList(
meshHeadingsList, "MeshHeading");
for (Element meshHeading : meshHeadings)
{
if ("Y".equals(XMLUtils.getElementAttribute(meshHeading, "DescriptorName", "MajorTopicYN")))
if ("Y".equals(XMLUtils.getElementAttribute(meshHeading,
"DescriptorName", "MajorTopicYN")))
{
primaryMeshHeadings.add(XMLUtils.getElementValue(meshHeading, "DescriptorName"));
primaryMeshHeadings.add(XMLUtils.getElementValue(
meshHeading, "DescriptorName"));
}
else
{
secondaryMeshHeadings.add(XMLUtils.getElementValue(meshHeading, "DescriptorName"));
secondaryMeshHeadings.add(XMLUtils.getElementValue(
meshHeading, "DescriptorName"));
}
}
}
if (primaryMeshHeadings.size()>0){
List<Value> values = new LinkedList<Value>();
for (String s : primaryMeshHeadings){
values.add(new StringValue(s));
}
record.addField("primaryMeshHeadings", values);
}
if (secondaryMeshHeadings.size()>0){
List<Value> values = new LinkedList<Value>();
for (String s : secondaryMeshHeadings){
values.add(new StringValue(s));
}
record.addField("secondaryMeshHeadings", values);
}
Element paginationElement = XMLUtils.getSingleElement(article, "Pagination");
if (primaryMeshHeadings.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String s : primaryMeshHeadings)
{
values.add(new StringValue(s));
}
record.addField("primaryMeshHeadings", values);
}
if (secondaryMeshHeadings.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String s : secondaryMeshHeadings)
{
values.add(new StringValue(s));
}
record.addField("secondaryMeshHeadings", values);
}
Element paginationElement = XMLUtils.getSingleElement(article,
"Pagination");
if (paginationElement != null)
{
String startPage = XMLUtils.getElementValue(paginationElement, "StartPage");
String endPage = XMLUtils.getElementValue(paginationElement, "EndPage");
String startPage = XMLUtils.getElementValue(paginationElement,
"StartPage");
String endPage = XMLUtils.getElementValue(paginationElement,
"EndPage");
if (StringUtils.isBlank(startPage))
{
startPage = XMLUtils.getElementValue(paginationElement, "MedlinePgn");
startPage = XMLUtils.getElementValue(paginationElement,
"MedlinePgn");
}
if (startPage!=null)
record.addValue("startPage", new StringValue(startPage));
if (endPage!=null)
record.addValue("endPage", new StringValue(endPage));
if (startPage != null)
record.addValue("startPage", new StringValue(startPage));
if (endPage != null)
record.addValue("endPage", new StringValue(endPage));
}
}
return record;
}
return record;
}
}

View File

@@ -25,50 +25,63 @@ import gr.ekt.bte.core.Value;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class RemoveLastDotModifier extends AbstractModifier {
public class RemoveLastDotModifier extends AbstractModifier
{
List<String> fieldKeys;
List<String> fieldKeys;
/**
* @param name
*/
public RemoveLastDotModifier(String name) {
super(name);
}
/**
* @param name
*/
public RemoveLastDotModifier(String name)
{
super(name);
}
/* (non-Javadoc)
* @see gr.ekt.bte.core.AbstractModifier#modify(gr.ekt.bte.core.MutableRecord)
*/
@Override
public Record modify(MutableRecord record) {
if (fieldKeys != null) {
for (String key : fieldKeys){
List<Value> values = record.getValues(key);
/*
* (non-Javadoc)
*
* @see
* gr.ekt.bte.core.AbstractModifier#modify(gr.ekt.bte.core.MutableRecord)
*/
@Override
public Record modify(MutableRecord record)
{
if (fieldKeys != null)
{
for (String key : fieldKeys)
{
List<Value> values = record.getValues(key);
List<Value> newValues = new ArrayList<Value>();
List<Value> newValues = new ArrayList<Value>();
if (values != null){
for (Value value : values){
String valueString = value.getAsString();
if (StringUtils.isNotBlank(valueString) && valueString.endsWith("."))
{
newValues.add(new StringValue(valueString.substring(0, valueString.length() - 1)));
}
else
{
newValues.add(new StringValue(valueString));
}
}
if (values != null)
{
for (Value value : values)
{
String valueString = value.getAsString();
if (StringUtils.isNotBlank(valueString)
&& valueString.endsWith("."))
{
newValues.add(new StringValue(valueString
.substring(0, valueString.length() - 1)));
}
else
{
newValues.add(new StringValue(valueString));
}
}
record.updateField(key, newValues);
}
}
}
record.updateField(key, newValues);
}
}
}
return record;
}
return record;
}
public void setFieldKeys(List<String> fieldKeys) {
this.fieldKeys = fieldKeys;
}
public void setFieldKeys(List<String> fieldKeys)
{
this.fieldKeys = fieldKeys;
}
}

View File

@@ -19,51 +19,63 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.dspace.submit.util.ItemSubmissionLookupDTO;
/**
* @author Andrea Bollini
* @author Kostas Stamatis
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class SubmissionItemDataLoader implements DataLoader {
public class SubmissionItemDataLoader implements DataLoader
{
private List<ItemSubmissionLookupDTO> dtoList;
List<DataLoader> providers;
private static Logger log = Logger.getLogger(SubmissionItemDataLoader.class);
public SubmissionItemDataLoader() {
private static Logger log = Logger
.getLogger(SubmissionItemDataLoader.class);
public SubmissionItemDataLoader()
{
dtoList = null;
providers = null;
}
@Override
public RecordSet getRecords() throws MalformedSourceException {
if (dtoList == null) {
public RecordSet getRecords() throws MalformedSourceException
{
if (dtoList == null)
{
throw new MalformedSourceException("dtoList not initialized");
}
RecordSet ret = new RecordSet();
for (ItemSubmissionLookupDTO dto : dtoList) {
for (ItemSubmissionLookupDTO dto : dtoList)
{
Record rec = dto.getTotalPublication(providers);
ret.addRecord(rec);
}
log.info("BTE DataLoader finished. Items loaded: " + ret.getRecords().size());
//Printing debug message
String totalString = "";
for (Record record : ret.getRecords()){
totalString += SubmissionLookupUtils.getPrintableString(record)+"\n";
}
log.debug("Records loaded:\n"+totalString);
log.info("BTE DataLoader finished. Items loaded: "
+ ret.getRecords().size());
// Printing debug message
String totalString = "";
for (Record record : ret.getRecords())
{
totalString += SubmissionLookupUtils.getPrintableString(record)
+ "\n";
}
log.debug("Records loaded:\n" + totalString);
return ret;
}
@Override
public RecordSet getRecords(DataLoadingSpec spec) throws MalformedSourceException {
if(spec.getOffset() > 0) {
public RecordSet getRecords(DataLoadingSpec spec)
throws MalformedSourceException
{
if (spec.getOffset() > 0)
{
return new RecordSet();
}
@@ -73,28 +85,34 @@ public class SubmissionItemDataLoader implements DataLoader {
/**
* @return the dtoList
*/
public List<ItemSubmissionLookupDTO> getDtoList() {
public List<ItemSubmissionLookupDTO> getDtoList()
{
return dtoList;
}
/**
* @param dtoList the dtoList to set
* @param dtoList
* the dtoList to set
*/
public void setDtoList(List<ItemSubmissionLookupDTO> dtoList) {
public void setDtoList(List<ItemSubmissionLookupDTO> dtoList)
{
this.dtoList = dtoList;
}
/**
* @return the providers
*/
public List<DataLoader> getProviders() {
public List<DataLoader> getProviders()
{
return providers;
}
/**
* @param providers the providers to set
* @param providers
* the providers to set
*/
public void setProviders(List<DataLoader> providers) {
public void setProviders(List<DataLoader> providers)
{
this.providers = providers;
}
}

View File

@@ -18,32 +18,38 @@ import org.dspace.core.Context;
import gr.ekt.bte.core.DataLoader;
import gr.ekt.bte.core.Record;
/**
* @author Andrea Bollini
* @author Kostas Stamatis
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public interface SubmissionLookupDataLoader extends DataLoader {
public interface SubmissionLookupDataLoader extends DataLoader
{
public final static String DOI = "doi";
public final static String PUBMED = "pubmed";
public final static String ARXIV = "arxiv";
public final static String REPEC = "repec";
public final static String SCOPUSEID = "scopuseid";
public final static String TYPE = "type";
public final static String DOI = "doi";
List<String> getSupportedIdentifiers();
public final static String PUBMED = "pubmed";
boolean isSearchProvider();
public final static String ARXIV = "arxiv";
List<Record> search(Context context, String title, String author,
int year) throws HttpException, IOException;
public final static String REPEC = "repec";
List<Record> getByIdentifier(Context context, Map<String, Set<String>> keys)
throws HttpException, IOException;
public final static String SCOPUSEID = "scopuseid";
List<Record> getByDOIs(Context context, Set<String> doiToSearch) throws HttpException, IOException;
public final static String TYPE = "type";
List<String> getSupportedIdentifiers();
boolean isSearchProvider();
List<Record> search(Context context, String title, String author, int year)
throws HttpException, IOException;
List<Record> getByIdentifier(Context context, Map<String, Set<String>> keys)
throws HttpException, IOException;
List<Record> getByDOIs(Context context, Set<String> doiToSearch)
throws HttpException, IOException;
}

View File

@@ -20,73 +20,88 @@ import java.util.Map;
import org.dspace.submit.util.ItemSubmissionLookupDTO;
/**
* @author Andrea Bollini
* @author Kostas Stamatis
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class SubmissionLookupOutputGenerator implements OutputGenerator {
public class SubmissionLookupOutputGenerator implements OutputGenerator
{
private List<ItemSubmissionLookupDTO> dtoList;
private static final String DOI_FIELD = "doi";
private static final String NOT_FOUND_DOI = "NOT-FOUND-DOI";
public SubmissionLookupOutputGenerator() {
public SubmissionLookupOutputGenerator()
{
}
@Override
public List<String> generateOutput(RecordSet records) {
dtoList = new ArrayList<ItemSubmissionLookupDTO>();
public List<String> generateOutput(RecordSet records)
{
dtoList = new ArrayList<ItemSubmissionLookupDTO>();
Map<String, List<Record>> record_sets = new HashMap<String, List<Record>>();
int counter = 0;
for(Record rec : records) {
for (Record rec : records)
{
String current_doi = NOT_FOUND_DOI;
List<Value> values = rec.getValues(DOI_FIELD);
if (values != null && values.size() > 0) {
if (values != null && values.size() > 0)
{
current_doi = values.get(0).getAsString();
}
else {
current_doi = NOT_FOUND_DOI + "_" + counter;
else
{
current_doi = NOT_FOUND_DOI + "_" + counter;
}
if(record_sets.keySet().contains(current_doi)) {
if (record_sets.keySet().contains(current_doi))
{
record_sets.get(current_doi).add(rec);
}
else {
else
{
ArrayList<Record> publication = new ArrayList<Record>();
publication.add(rec);
record_sets.put(current_doi, publication);
}
counter++;
}
for(Map.Entry<String, List<Record>> entry : record_sets.entrySet()) {
ItemSubmissionLookupDTO dto = new ItemSubmissionLookupDTO(entry.getValue());
for (Map.Entry<String, List<Record>> entry : record_sets.entrySet())
{
ItemSubmissionLookupDTO dto = new ItemSubmissionLookupDTO(
entry.getValue());
dtoList.add(dto);
}
return new ArrayList<String>();
}
@Override
public List<String> generateOutput(RecordSet records, DataOutputSpec spec) {
public List<String> generateOutput(RecordSet records, DataOutputSpec spec)
{
return generateOutput(records);
}
/**
* @return the items
*/
public List<ItemSubmissionLookupDTO> getDtoList() {
public List<ItemSubmissionLookupDTO> getDtoList()
{
return dtoList;
}
/**
* @param items the items to set
* @param items
* the items to set
*/
public void setDtoList(List<ItemSubmissionLookupDTO> items) {
public void setDtoList(List<ItemSubmissionLookupDTO> items)
{
this.dtoList = items;
}
}

View File

@@ -28,151 +28,187 @@ import org.dspace.submit.util.SubmissionLookupDTO;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class SubmissionLookupService {
public class SubmissionLookupService
{
public static final String SL_NAMESPACE_PREFIX = "http://www.dspace.org/sl/";
public static final String SL_NAMESPACE_PREFIX = "http://www.dspace.org/sl/";
public static final String MANUAL_USER_INPUT = "manual";
public static final String MANUAL_USER_INPUT = "manual";
public static final String PROVIDER_NAME_FIELD = "provider_name_field";
private static Logger log = Logger.getLogger(SubmissionLookupService.class);
public static final String PROVIDER_NAME_FIELD = "provider_name_field";
public static final String SEPARATOR_VALUE = "#######";
private static Logger log = Logger.getLogger(SubmissionLookupService.class);
public static final String SEPARATOR_VALUE_REGEX = SEPARATOR_VALUE;
public static final String SEPARATOR_VALUE = "#######";
private List<DataLoader> providers;
public static final String SEPARATOR_VALUE_REGEX = SEPARATOR_VALUE;
private Map<String, List<String>> idents2provs;
private List<DataLoader> providers;
private List<String> searchProviders;
private List<String> fileProviders;
private Map<String, List<String>> idents2provs;
private TransformationEngine phase1TransformationEngine;
private TransformationEngine phase2TransformationEngine;
private List<String> searchProviders;
private List<String> fileProviders;
public void setPhase2TransformationEngine(TransformationEngine phase2TransformationEngine) {
this.phase2TransformationEngine = phase2TransformationEngine;
}
public void setPhase1TransformationEngine(TransformationEngine phase1TransformationEngine) {
this.phase1TransformationEngine = phase1TransformationEngine;
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader)phase1TransformationEngine.getDataLoader();
this.idents2provs = new HashMap<String, List<String>>();
this.searchProviders = new ArrayList<String>();
this.fileProviders = new ArrayList<String>();
private TransformationEngine phase1TransformationEngine;
if (providers == null) {
this.providers = new ArrayList<DataLoader>();
for (String providerName : dataLoader.getProvidersMap().keySet()) {
DataLoader p = dataLoader.getProvidersMap().get(providerName);
this.providers.add(p);
//Do not do that for file providers
if (p instanceof FileDataLoader){
this.fileProviders.add(providerName);
}
else if (p instanceof NetworkSubmissionLookupDataLoader){
NetworkSubmissionLookupDataLoader p2 = (NetworkSubmissionLookupDataLoader)p;
private TransformationEngine phase2TransformationEngine;
p2.setProviderName(providerName);
if (p2.isSearchProvider()) {
searchProviders.add(providerName);
}
List<String> suppIdentifiers = p2.getSupportedIdentifiers();
if (suppIdentifiers != null) {
for (String ident : suppIdentifiers) {
List<String> tmp = idents2provs
.get(ident);
if (tmp == null) {
tmp = new ArrayList<String>();
idents2provs.put(ident, tmp);
}
tmp.add(providerName);
}
}
}
}
}
}
public TransformationEngine getPhase1TransformationEngine() {
return phase1TransformationEngine;
}
public TransformationEngine getPhase2TransformationEngine() {
return phase2TransformationEngine;
}
public List<String> getIdentifiers() {
List<String> allSupportedIdentifiers = new ArrayList<String>();
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader)phase1TransformationEngine.getDataLoader();
for (String providerName : dataLoader.getProvidersMap().keySet()) {
DataLoader provider = dataLoader.getProvidersMap().get(providerName);
if (provider instanceof SubmissionLookupDataLoader){
for (String identifier : ((SubmissionLookupDataLoader)provider).getSupportedIdentifiers()){
if (!allSupportedIdentifiers.contains(identifier)){
allSupportedIdentifiers.add(identifier);
}
}
}
}
return allSupportedIdentifiers;
}
public Map<String, List<String>> getProvidersIdentifiersMap() {
return idents2provs;
}
public SubmissionLookupDTO getSubmissionLookupDTO(
HttpServletRequest request, String uuidSubmission) {
SubmissionLookupDTO dto = (SubmissionLookupDTO) request.getSession()
.getAttribute("submission_lookup_" + uuidSubmission);
if (dto == null) {
dto = new SubmissionLookupDTO();
storeDTOs(request, uuidSubmission, dto);
}
return dto;
}
public void invalidateDTOs(HttpServletRequest request, String uuidSubmission) {
request.getSession().removeAttribute(
"submission_lookup_" + uuidSubmission);
}
public void storeDTOs(HttpServletRequest request, String uuidSubmission,
SubmissionLookupDTO dto) {
request.getSession().setAttribute(
"submission_lookup_" + uuidSubmission, dto);
}
public List<String> getSearchProviders() {
return searchProviders;
}
public List<DataLoader> getProviders() {
return providers;
}
public static String getProviderName(Record rec) {
return SubmissionLookupUtils.getFirstValue(rec, SubmissionLookupService.PROVIDER_NAME_FIELD);
public void setPhase2TransformationEngine(
TransformationEngine phase2TransformationEngine)
{
this.phase2TransformationEngine = phase2TransformationEngine;
}
public static String getType(Record rec) {
return SubmissionLookupUtils.getFirstValue(rec, SubmissionLookupDataLoader.TYPE);
public void setPhase1TransformationEngine(
TransformationEngine phase1TransformationEngine)
{
this.phase1TransformationEngine = phase1TransformationEngine;
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) phase1TransformationEngine
.getDataLoader();
this.idents2provs = new HashMap<String, List<String>>();
this.searchProviders = new ArrayList<String>();
this.fileProviders = new ArrayList<String>();
if (providers == null)
{
this.providers = new ArrayList<DataLoader>();
for (String providerName : dataLoader.getProvidersMap().keySet())
{
DataLoader p = dataLoader.getProvidersMap().get(providerName);
this.providers.add(p);
// Do not do that for file providers
if (p instanceof FileDataLoader)
{
this.fileProviders.add(providerName);
}
else if (p instanceof NetworkSubmissionLookupDataLoader)
{
NetworkSubmissionLookupDataLoader p2 = (NetworkSubmissionLookupDataLoader) p;
p2.setProviderName(providerName);
if (p2.isSearchProvider())
{
searchProviders.add(providerName);
}
List<String> suppIdentifiers = p2.getSupportedIdentifiers();
if (suppIdentifiers != null)
{
for (String ident : suppIdentifiers)
{
List<String> tmp = idents2provs.get(ident);
if (tmp == null)
{
tmp = new ArrayList<String>();
idents2provs.put(ident, tmp);
}
tmp.add(providerName);
}
}
}
}
}
}
public List<String> getFileProviders() {
return this.fileProviders;
}
public TransformationEngine getPhase1TransformationEngine()
{
return phase1TransformationEngine;
}
public TransformationEngine getPhase2TransformationEngine()
{
return phase2TransformationEngine;
}
public List<String> getIdentifiers()
{
List<String> allSupportedIdentifiers = new ArrayList<String>();
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) phase1TransformationEngine
.getDataLoader();
for (String providerName : dataLoader.getProvidersMap().keySet())
{
DataLoader provider = dataLoader.getProvidersMap()
.get(providerName);
if (provider instanceof SubmissionLookupDataLoader)
{
for (String identifier : ((SubmissionLookupDataLoader) provider)
.getSupportedIdentifiers())
{
if (!allSupportedIdentifiers.contains(identifier))
{
allSupportedIdentifiers.add(identifier);
}
}
}
}
return allSupportedIdentifiers;
}
public Map<String, List<String>> getProvidersIdentifiersMap()
{
return idents2provs;
}
public SubmissionLookupDTO getSubmissionLookupDTO(
HttpServletRequest request, String uuidSubmission)
{
SubmissionLookupDTO dto = (SubmissionLookupDTO) request.getSession()
.getAttribute("submission_lookup_" + uuidSubmission);
if (dto == null)
{
dto = new SubmissionLookupDTO();
storeDTOs(request, uuidSubmission, dto);
}
return dto;
}
public void invalidateDTOs(HttpServletRequest request, String uuidSubmission)
{
request.getSession().removeAttribute(
"submission_lookup_" + uuidSubmission);
}
public void storeDTOs(HttpServletRequest request, String uuidSubmission,
SubmissionLookupDTO dto)
{
request.getSession().setAttribute(
"submission_lookup_" + uuidSubmission, dto);
}
public List<String> getSearchProviders()
{
return searchProviders;
}
public List<DataLoader> getProviders()
{
return providers;
}
public static String getProviderName(Record rec)
{
return SubmissionLookupUtils.getFirstValue(rec,
SubmissionLookupService.PROVIDER_NAME_FIELD);
}
public static String getType(Record rec)
{
return SubmissionLookupUtils.getFirstValue(rec,
SubmissionLookupDataLoader.TYPE);
}
public List<String> getFileProviders()
{
return this.fileProviders;
}
}

View File

@@ -28,118 +28,135 @@ import org.dspace.core.Context;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class SubmissionLookupUtils {
private static Logger log = Logger.getLogger(SubmissionLookupUtils.class);
public class SubmissionLookupUtils
{
private static Logger log = Logger.getLogger(SubmissionLookupUtils.class);
/** Location of config file */
private static final String configFilePath = ConfigurationManager
.getProperty("dspace.dir")
+ File.separator
+ "config"
+ File.separator + "crosswalks" + File.separator;
/** Location of config file */
private static final String configFilePath = ConfigurationManager
.getProperty("dspace.dir")
+ File.separator
+ "config"
+ File.separator + "crosswalks" + File.separator;
// Patter to extract the converter name if any
private static final Pattern converterPattern = Pattern
.compile(".*\\((.*)\\)");
// Patter to extract the converter name if any
private static final Pattern converterPattern = Pattern
.compile(".*\\((.*)\\)");
public static LookupProvidersCheck getProvidersCheck(Context context,
Item item, String dcSchema, String dcElement, String dcQualifier) {
try {
LookupProvidersCheck check = new LookupProvidersCheck();
MetadataSchema[] schemas = MetadataSchema.findAll(context);
DCValue[] values = item.getMetadata(dcSchema, dcElement, dcQualifier, Item.ANY);
for (MetadataSchema schema : schemas)
{
boolean error = false;
if (schema.getNamespace().startsWith(SubmissionLookupService.SL_NAMESPACE_PREFIX))
{
DCValue[] slCache = item.getMetadata(schema.getName(), dcElement, dcQualifier, Item.ANY);
if (slCache.length == 0)
continue;
if (slCache.length != values.length)
{
error = true;
}
else
{
for (int idx = 0; idx < values.length; idx++)
{
DCValue v = values[idx];
DCValue sl = slCache[idx];
// FIXME gestire authority e possibilita' multiple:
// match non sicuri, affiliation, etc.
if (!v.value.equals(sl.value))
{
error = true;
break;
}
}
}
if (error)
{
check.getProvidersErr().add(schema.getName());
}
else
{
check.getProvidersOk().add(schema.getName());
}
}
}
return check;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
public static LookupProvidersCheck getProvidersCheck(Context context,
Item item, String dcSchema, String dcElement, String dcQualifier)
{
try
{
LookupProvidersCheck check = new LookupProvidersCheck();
MetadataSchema[] schemas = MetadataSchema.findAll(context);
DCValue[] values = item.getMetadata(dcSchema, dcElement,
dcQualifier, Item.ANY);
}
for (MetadataSchema schema : schemas)
{
boolean error = false;
if (schema.getNamespace().startsWith(
SubmissionLookupService.SL_NAMESPACE_PREFIX))
{
DCValue[] slCache = item.getMetadata(schema.getName(),
dcElement, dcQualifier, Item.ANY);
if (slCache.length == 0)
continue;
public static String normalizeDOI(String doi) {
if (doi != null)
{
return doi.trim().replaceAll("^http://dx.doi.org/", "")
.replaceAll("^doi:", "");
}
return null;
}
if (slCache.length != values.length)
{
error = true;
}
else
{
for (int idx = 0; idx < values.length; idx++)
{
DCValue v = values[idx];
DCValue sl = slCache[idx];
// FIXME gestire authority e possibilita' multiple:
// match non sicuri, affiliation, etc.
if (!v.value.equals(sl.value))
{
error = true;
break;
}
}
}
if (error)
{
check.getProvidersErr().add(schema.getName());
}
else
{
check.getProvidersOk().add(schema.getName());
}
}
}
return check;
}
catch (Exception e)
{
log.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
public static String getFirstValue(Record rec, String field) {
List<Value> values = rec.getValues(field);
String value = null;
if (values != null && values.size() > 0) {
value = values.get(0).getAsString();
}
return value;
}
}
public static List<String> getValues(Record rec, String field) {
List<String> result = new ArrayList<String>();
List<Value> values = rec.getValues(field);
if (values != null && values.size() > 0) {
for (Value value : values){
result.add( value.getAsString());
}
}
return result;
}
public static String normalizeDOI(String doi)
{
if (doi != null)
{
return doi.trim().replaceAll("^http://dx.doi.org/", "")
.replaceAll("^doi:", "");
}
return null;
public static String getPrintableString(Record record){
StringBuilder result = new StringBuilder();
result.append("\nPublication {\n");
for (String field: record.getFields()){
result.append("--"+field + ":\n");
List<Value> values = record.getValues(field);
for (Value value : values){
result.append("\t"+value.getAsString()+"\n");
}
}
result.append("}\n");
return result.toString();
}
}
public static String getFirstValue(Record rec, String field)
{
List<Value> values = rec.getValues(field);
String value = null;
if (values != null && values.size() > 0)
{
value = values.get(0).getAsString();
}
return value;
}
public static List<String> getValues(Record rec, String field)
{
List<String> result = new ArrayList<String>();
List<Value> values = rec.getValues(field);
if (values != null && values.size() > 0)
{
for (Value value : values)
{
result.add(value.getAsString());
}
}
return result;
}
public static String getPrintableString(Record record)
{
StringBuilder result = new StringBuilder();
result.append("\nPublication {\n");
for (String field : record.getFields())
{
result.append("--" + field + ":\n");
List<Value> values = record.getValues(field);
for (Value value : values)
{
result.append("\t" + value.getAsString() + "\n");
}
}
result.append("}\n");
return result.toString();
}
}

View File

@@ -26,25 +26,33 @@ import org.apache.commons.lang.StringUtils;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class ValueConcatenationModifier extends AbstractModifier {
public class ValueConcatenationModifier extends AbstractModifier
{
private String field;
private String separator = ",";
private boolean whitespaceAfter = true;
public ValueConcatenationModifier() {
public ValueConcatenationModifier()
{
super("ValueConcatenationModifier");
}
@Override
public Record modify(MutableRecord rec) {
public Record modify(MutableRecord rec)
{
List<Value> values = rec.getValues(field);
if(values != null) {
if (values != null)
{
List<String> converted_values = new ArrayList<String>();
for (Value val : values) {
for (Value val : values)
{
converted_values.add(val.getAsString());
}
List<Value> final_value = new ArrayList<Value>();
String v = StringUtils.join(converted_values.iterator(), separator + (whitespaceAfter ? " " : ""));
String v = StringUtils.join(converted_values.iterator(), separator
+ (whitespaceAfter ? " " : ""));
final_value.add(new StringValue(v));
rec.updateField(field, final_value);
}
@@ -55,42 +63,51 @@ public class ValueConcatenationModifier extends AbstractModifier {
/**
* @return the field
*/
public String getField() {
public String getField()
{
return field;
}
/**
* @param field the field to set
* @param field
* the field to set
*/
public void setField(String field) {
public void setField(String field)
{
this.field = field;
}
/**
* @return the separator
*/
public String getSeparator() {
public String getSeparator()
{
return separator;
}
/**
* @param separator the separator to set
* @param separator
* the separator to set
*/
public void setSeparator(String separator) {
public void setSeparator(String separator)
{
this.separator = separator;
}
/**
* @return the whiteSpaceAfter
*/
public boolean isWhitespaceAfter() {
public boolean isWhitespaceAfter()
{
return whitespaceAfter;
}
/**
* @param whiteSpaceAfter the whiteSpaceAfter to set
* @param whiteSpaceAfter
* the whiteSpaceAfter to set
*/
public void setWhitespaceAfter(boolean whiteSpaceAfter) {
public void setWhitespaceAfter(boolean whiteSpaceAfter)
{
this.whitespaceAfter = whiteSpaceAfter;
}
}

View File

@@ -7,7 +7,6 @@
*/
package org.dspace.submit.step;
import edu.emory.mathcs.backport.java.util.Arrays;
import gr.ekt.bte.core.Record;
import gr.ekt.bte.core.TransformationEngine;
import gr.ekt.bte.core.TransformationSpec;
@@ -26,7 +25,6 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hwpf.model.Ffn;
import org.dspace.app.util.DCInputSet;
import org.dspace.app.util.DCInputsReader;
import org.dspace.app.util.SubmissionInfo;
@@ -45,19 +43,23 @@ import org.dspace.submit.util.SubmissionLookupPublication;
import org.dspace.utils.DSpace;
/**
* SelectCollection Step which processes the collection that the user selected
* in that step of the DSpace Submission process
* <P>
* This class performs all the behind-the-scenes processing that
* this particular step requires. This class's methods are utilized
* by both the JSP-UI and the Manakin XML-UI
* StartSubmissionLookupStep is used when you want enabled the user to auto fill
* the item in submission with metadata retrieved from external bibliographic
* services (like pubmed, arxiv, and so on...)
*
* <p>
* At the moment this step is only available for JSPUI
* </p>
*
* @see org.dspace.app.util.SubmissionConfig
* @see org.dspace.app.util.SubmissionStepConfig
* @see org.dspace.submit.AbstractProcessingStep
*
* @author Tim Donohue
* @version $Revision: 3738 $
* @author Andrea Bollini
* @author Kostas Stamatis
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
* @version $Revision$
*/
public class StartSubmissionLookupStep extends AbstractProcessingStep
{
@@ -73,18 +75,19 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
// invalid collection or error finding collection
public static final int STATUS_INVALID_COLLECTION = 2;
public static final int STATUS_NO_SUUID = 3;
public static final int STATUS_SUBMISSION_EXPIRED = 4;
private SubmissionLookupService slService = new DSpace()
.getServiceManager().getServiceByName(
SubmissionLookupService.class.getCanonicalName(),
SubmissionLookupService.class);
private SubmissionLookupService slService = new DSpace()
.getServiceManager().getServiceByName(
SubmissionLookupService.class.getCanonicalName(),
SubmissionLookupService.class);
/** log4j logger */
private static Logger log = Logger.getLogger(StartSubmissionLookupStep.class);
private static Logger log = Logger
.getLogger(StartSubmissionLookupStep.class);
/**
* Do any processing of the information input by the user, and/or perform
@@ -122,29 +125,32 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
String uuidSubmission = request.getParameter("suuid");
String uuidLookup = request.getParameter("iuuid");
String fuuidLookup = request.getParameter("fuuid");
if (StringUtils.isBlank(uuidSubmission))
{
return STATUS_NO_SUUID;
return STATUS_NO_SUUID;
}
SubmissionLookupDTO submissionDTO = slService.getSubmissionLookupDTO(
request, uuidSubmission);
SubmissionLookupDTO submissionDTO = slService.getSubmissionLookupDTO(
request, uuidSubmission);
if (submissionDTO == null)
{
return STATUS_SUBMISSION_EXPIRED;
return STATUS_SUBMISSION_EXPIRED;
}
ItemSubmissionLookupDTO itemLookup = null;
if (fuuidLookup == null || fuuidLookup.isEmpty()) {
if (StringUtils.isNotBlank(uuidLookup)) {
itemLookup = submissionDTO.getLookupItem(uuidLookup);
if (itemLookup == null) {
return STATUS_SUBMISSION_EXPIRED;
}
}
}
if (fuuidLookup == null || fuuidLookup.isEmpty())
{
if (StringUtils.isNotBlank(uuidLookup))
{
itemLookup = submissionDTO.getLookupItem(uuidLookup);
if (itemLookup == null)
{
return STATUS_SUBMISSION_EXPIRED;
}
}
}
// if the user didn't select a collection,
// send him/her back to "select a collection" page
if (id < 0)
@@ -164,80 +170,101 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
{
// create our new Workspace Item
DCInputSet inputSet = null;
try {
inputSet = new DCInputsReader().getInputs(col.getHandle());
} catch (Exception e) {
e.printStackTrace();
}
List<ItemSubmissionLookupDTO> dto = new ArrayList<ItemSubmissionLookupDTO>();
try
{
inputSet = new DCInputsReader().getInputs(col.getHandle());
}
catch (Exception e)
{
e.printStackTrace();
}
List<ItemSubmissionLookupDTO> dto = new ArrayList<ItemSubmissionLookupDTO>();
if (itemLookup != null)
{
dto.add(itemLookup);
} else if (fuuidLookup != null) {
String[] ss = fuuidLookup.split(",");
for(String s : ss) {
itemLookup = submissionDTO.getLookupItem(s);
if (itemLookup == null) {
return STATUS_SUBMISSION_EXPIRED;
}
dto.add(itemLookup);
}
} else {
SubmissionLookupPublication manualPub = new SubmissionLookupPublication(
SubmissionLookupService.MANUAL_USER_INPUT);
manualPub.add("title", titolo);
manualPub.add("year", date);
manualPub.add("allauthors", autori);
Enumeration e = request.getParameterNames();
while (e.hasMoreElements()) {
String parameterName = (String) e.nextElement();
String parameterValue = request.getParameter(parameterName);
if (parameterName.startsWith("identifier_")
&& StringUtils.isNotBlank(parameterValue)) {
manualPub.add(
parameterName.substring("identifier_".length()),
parameterValue);
}
}
List<Record> publications = new ArrayList<Record>();
publications.add(manualPub);
dto.add(new ItemSubmissionLookupDTO(publications));
dto.add(itemLookup);
}
List<WorkspaceItem> result = null;
TransformationEngine transformationEngine = slService.getPhase2TransformationEngine();
if (transformationEngine != null){
SubmissionItemDataLoader dataLoader = (SubmissionItemDataLoader)transformationEngine.getDataLoader();
dataLoader.setDtoList(dto);
//dataLoader.setProviders()
else if (fuuidLookup != null)
{
String[] ss = fuuidLookup.split(",");
for (String s : ss)
{
itemLookup = submissionDTO.getLookupItem(s);
if (itemLookup == null)
{
return STATUS_SUBMISSION_EXPIRED;
}
dto.add(itemLookup);
}
}
else
{
SubmissionLookupPublication manualPub = new SubmissionLookupPublication(
SubmissionLookupService.MANUAL_USER_INPUT);
manualPub.add("title", titolo);
manualPub.add("year", date);
manualPub.add("allauthors", autori);
DSpaceWorkspaceItemOutputGenerator outputGenerator = (DSpaceWorkspaceItemOutputGenerator)transformationEngine.getOutputGenerator();
outputGenerator.setCollection(col);
outputGenerator.setContext(context);
outputGenerator.setFormName(inputSet.getFormName());
outputGenerator.setDto(dto.get(0));
try {
transformationEngine.transform(new TransformationSpec());
result = outputGenerator.getWitems();
} catch (BadTransformationSpec e1) {
e1.printStackTrace();
} catch (MalformedSourceException e1) {
e1.printStackTrace();
}
}
if (result != null && result.size()>0) {
// update Submission Information with this Workspace Item
subInfo.setSubmissionItem(result.iterator().next());
}
Enumeration e = request.getParameterNames();
while (e.hasMoreElements())
{
String parameterName = (String) e.nextElement();
String parameterValue = request.getParameter(parameterName);
if (parameterName.startsWith("identifier_")
&& StringUtils.isNotBlank(parameterValue))
{
manualPub
.add(parameterName.substring("identifier_"
.length()), parameterValue);
}
}
List<Record> publications = new ArrayList<Record>();
publications.add(manualPub);
dto.add(new ItemSubmissionLookupDTO(publications));
}
List<WorkspaceItem> result = null;
TransformationEngine transformationEngine = slService
.getPhase2TransformationEngine();
if (transformationEngine != null)
{
SubmissionItemDataLoader dataLoader = (SubmissionItemDataLoader) transformationEngine
.getDataLoader();
dataLoader.setDtoList(dto);
// dataLoader.setProviders()
DSpaceWorkspaceItemOutputGenerator outputGenerator = (DSpaceWorkspaceItemOutputGenerator) transformationEngine
.getOutputGenerator();
outputGenerator.setCollection(col);
outputGenerator.setContext(context);
outputGenerator.setFormName(inputSet.getFormName());
outputGenerator.setDto(dto.get(0));
try
{
transformationEngine.transform(new TransformationSpec());
result = outputGenerator.getWitems();
}
catch (BadTransformationSpec e1)
{
e1.printStackTrace();
}
catch (MalformedSourceException e1)
{
e1.printStackTrace();
}
}
if (result != null && result.size() > 0)
{
// update Submission Information with this Workspace Item
subInfo.setSubmissionItem(result.iterator().next());
}
// commit changes to database
context.commit();
@@ -252,7 +279,7 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
return STATUS_COMPLETE;
}
/**
/**
* Retrieves the number of pages that this "step" extends over. This method
* is used to build the progress bar.
* <P>

View File

@@ -28,74 +28,84 @@ import org.dspace.submit.lookup.SubmissionLookupService;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class ItemSubmissionLookupDTO implements Serializable {
private static final long serialVersionUID = 1;
public class ItemSubmissionLookupDTO implements Serializable
{
private static final long serialVersionUID = 1;
private static final String MERGED_PUBLICATION_PROVIDER = "merged";
private static final String MERGED_PUBLICATION_PROVIDER = "merged";
private static final String UNKNOWN_PROVIDER_STRING = "UNKNOWN-PROVIDER";
private List<Record> publications;
private String uuid;
public ItemSubmissionLookupDTO(List<Record> publications) {
this.uuid = UUID.randomUUID().toString();
this.publications = publications;
}
private String uuid;
public List<Record> getPublications() {
return publications;
}
public Set<String> getProviders() {
Set<String> orderedProviders = new LinkedHashSet<String>();
public ItemSubmissionLookupDTO(List<Record> publications)
{
this.uuid = UUID.randomUUID().toString();
this.publications = publications;
}
public List<Record> getPublications()
{
return publications;
}
public Set<String> getProviders()
{
Set<String> orderedProviders = new LinkedHashSet<String>();
for (Record p : publications)
{
{
orderedProviders.add(SubmissionLookupService.getProviderName(p));
}
return orderedProviders;
}
}
return orderedProviders;
}
public String getUUID() {
return uuid;
}
public String getUUID()
{
return uuid;
}
public Record getTotalPublication(List<DataLoader> providers) {
if (publications == null)
{
return null;
}
else if (publications.size() == 1)
{
return publications.get(0);
}
else
{
MutableRecord pub = new SubmissionLookupPublication(MERGED_PUBLICATION_PROVIDER);
//for (SubmissionLookupProvider prov : providers)
//{
for (Record p : publications)
{
//if (!SubmissionLookupService.getProviderName(p).equals(prov.getShortName()))
//{
// continue;
//}
for (String field : p.getFields())
{
List<Value> values = p.getValues(field);
if (values != null && values.size() > 0)
{
if (!pub.getFields().contains(field))
{
for (Value v : values)
{
pub.addValue(field, v);
}
}
}
}
}
//}
return pub;
}
}
public Record getTotalPublication(List<DataLoader> providers)
{
if (publications == null)
{
return null;
}
else if (publications.size() == 1)
{
return publications.get(0);
}
else
{
MutableRecord pub = new SubmissionLookupPublication(
MERGED_PUBLICATION_PROVIDER);
// for (SubmissionLookupProvider prov : providers)
// {
for (Record p : publications)
{
// if
// (!SubmissionLookupService.getProviderName(p).equals(prov.getShortName()))
// {
// continue;
// }
for (String field : p.getFields())
{
List<Value> values = p.getValues(field);
if (values != null && values.size() > 0)
{
if (!pub.getFields().contains(field))
{
for (Value v : values)
{
pub.addValue(field, v);
}
}
}
}
}
// }
return pub;
}
}
}

View File

@@ -17,32 +17,36 @@ import java.util.UUID;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class SubmissionLookupDTO implements Serializable {
private static final long serialVersionUID = 1;
private String uuid;
public class SubmissionLookupDTO implements Serializable
{
private static final long serialVersionUID = 1;
private List<ItemSubmissionLookupDTO> items;
private String uuid;
public SubmissionLookupDTO() {
this.uuid = UUID.randomUUID().toString();
}
public void setItems(List<ItemSubmissionLookupDTO> items) {
this.items = items;
}
private List<ItemSubmissionLookupDTO> items;
public ItemSubmissionLookupDTO getLookupItem(String uuidLookup) {
if (items != null)
{
for (ItemSubmissionLookupDTO item : items)
{
if (item.getUUID().equals(uuidLookup))
{
return item;
}
}
}
return null;
}
public SubmissionLookupDTO()
{
this.uuid = UUID.randomUUID().toString();
}
public void setItems(List<ItemSubmissionLookupDTO> items)
{
this.items = items;
}
public ItemSubmissionLookupDTO getLookupItem(String uuidLookup)
{
if (items != null)
{
for (ItemSubmissionLookupDTO item : items)
{
if (item.getUUID().equals(uuidLookup))
{
return item;
}
}
}
return null;
}
}

View File

@@ -27,167 +27,205 @@ import org.dspace.submit.lookup.SubmissionLookupDataLoader;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class SubmissionLookupPublication implements MutableRecord, Serializable {
private String providerName;
public class SubmissionLookupPublication implements MutableRecord, Serializable
{
private String providerName;
private Map<String, List<String>> storage = new HashMap<String, List<String>>();
private Map<String, List<String>> storage = new HashMap<String, List<String>>();
public SubmissionLookupPublication(String providerName) {
this.providerName = providerName;
}
public SubmissionLookupPublication(String providerName)
{
this.providerName = providerName;
}
// needed to serialize it with JSON
public Map<String, List<String>> getStorage() {
return storage;
}
public Set<String> getFields() {
return storage.keySet();
}
// needed to serialize it with JSON
public Map<String, List<String>> getStorage()
{
return storage;
}
public List<String> remove(String md) {
return storage.remove(md);
}
public Set<String> getFields()
{
return storage.keySet();
}
public void add(String md, String nValue) {
if (StringUtils.isNotBlank(nValue))
{
List<String> tmp = storage.get(md);
if (tmp == null) {
tmp = new ArrayList<String>();
storage.put(md, tmp);
}
tmp.add(nValue);
}
}
public List<String> remove(String md)
{
return storage.remove(md);
}
public String getFirstValue(String md) {
List<String> tmp = storage.get(md);
if (tmp == null || tmp.size() == 0) {
return null;
}
return tmp.get(0);
}
public void add(String md, String nValue)
{
if (StringUtils.isNotBlank(nValue))
{
List<String> tmp = storage.get(md);
if (tmp == null)
{
tmp = new ArrayList<String>();
storage.put(md, tmp);
}
tmp.add(nValue);
}
}
public String getProviderName() {
return providerName;
}
public String getFirstValue(String md)
{
List<String> tmp = storage.get(md);
if (tmp == null || tmp.size() == 0)
{
return null;
}
return tmp.get(0);
}
public String getType() {
return getFirstValue(SubmissionLookupDataLoader.TYPE);
}
public String getProviderName()
{
return providerName;
}
//BTE Record interface methods
@Override
public boolean hasField(String md) {
return storage.containsKey(md);
}
public String getType()
{
return getFirstValue(SubmissionLookupDataLoader.TYPE);
}
@Override
public List<Value> getValues(String md) {
List<String> stringValues = storage.get(md);
if (stringValues == null){
return null;
}
List<Value> values = new ArrayList<Value>();
for (String value : stringValues){
values.add(new StringValue(value));
}
return values;
}
// BTE Record interface methods
@Override
public boolean hasField(String md)
{
return storage.containsKey(md);
}
@Override
public boolean isMutable() {
return true;
}
@Override
public List<Value> getValues(String md)
{
List<String> stringValues = storage.get(md);
if (stringValues == null)
{
return null;
}
List<Value> values = new ArrayList<Value>();
for (String value : stringValues)
{
values.add(new StringValue(value));
}
return values;
}
@Override
public MutableRecord makeMutable() {
return this;
}
@Override
public boolean isMutable()
{
return true;
}
@Override
public boolean addField(String md, List<Value> values) {
if (storage.containsKey(md)){
List<String> stringValues = storage.get(md);
if (values != null){
for (Value value : values){
stringValues.add(value.getAsString());
}
}
}
else {
List<String> tmp = new ArrayList<String>();
if (values != null){
for (Value value : values){
tmp.add(value.getAsString());
}
}
storage.put(md, tmp);
}
return true;
}
@Override
public MutableRecord makeMutable()
{
return this;
}
@Override
public boolean addValue(String md, Value value) {
if (storage.containsKey(md)){
List<String> stringValues = storage.get(md);
stringValues.add(value.getAsString());
}
else {
List<String> tmp = new ArrayList<String>();
tmp.add(value.getAsString());
storage.put(md, tmp);
}
return true;
}
@Override
public boolean addField(String md, List<Value> values)
{
if (storage.containsKey(md))
{
List<String> stringValues = storage.get(md);
if (values != null)
{
for (Value value : values)
{
stringValues.add(value.getAsString());
}
}
}
else
{
List<String> tmp = new ArrayList<String>();
if (values != null)
{
for (Value value : values)
{
tmp.add(value.getAsString());
}
}
storage.put(md, tmp);
}
@Override
public boolean removeField(String md) {
if (storage.containsKey(md)){
storage.remove(md);
}
return false;
}
return true;
}
@Override
public boolean removeValue(String md, Value value) {
if (storage.containsKey(md)){
List<String> stringValues = storage.get(md);
stringValues.remove(value.getAsString());
}
return true;
}
@Override
public boolean addValue(String md, Value value)
{
if (storage.containsKey(md))
{
List<String> stringValues = storage.get(md);
stringValues.add(value.getAsString());
}
else
{
List<String> tmp = new ArrayList<String>();
tmp.add(value.getAsString());
@Override
public boolean updateField(String md, List<Value> values) {
List<String> stringValues = new ArrayList<String>();
for (Value value : values){
stringValues.add(value.getAsString());
}
storage.put(md, stringValues);
storage.put(md, tmp);
}
return true;
}
return true;
}
@Override
public boolean updateValue(String md, Value valueOld, Value valueNew) {
if (storage.containsKey(md)){
List<String> stringValues = storage.get(md);
List<String> newStringValues = storage.get(md);
for (String s : stringValues){
if (s.equals(valueOld.getAsString())){
newStringValues.add(valueNew.getAsString());
}
else {
newStringValues.add(s);
}
}
storage.put(md, newStringValues);
}
return true;
}
@Override
public boolean removeField(String md)
{
if (storage.containsKey(md))
{
storage.remove(md);
}
return false;
}
@Override
public boolean removeValue(String md, Value value)
{
if (storage.containsKey(md))
{
List<String> stringValues = storage.get(md);
stringValues.remove(value.getAsString());
}
return true;
}
@Override
public boolean updateField(String md, List<Value> values)
{
List<String> stringValues = new ArrayList<String>();
for (Value value : values)
{
stringValues.add(value.getAsString());
}
storage.put(md, stringValues);
return true;
}
@Override
public boolean updateValue(String md, Value valueOld, Value valueNew)
{
if (storage.containsKey(md))
{
List<String> stringValues = storage.get(md);
List<String> newStringValues = storage.get(md);
for (String s : stringValues)
{
if (s.equals(valueOld.getAsString()))
{
newStringValues.add(valueNew.getAsString());
}
else
{
newStringValues.add(s);
}
}
storage.put(md, newStringValues);
}
return true;
}
}

View File

@@ -62,290 +62,344 @@ import com.google.gson.JsonObject;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class SubmissionLookupJSONRequest extends JSONRequest {
public class SubmissionLookupJSONRequest extends JSONRequest
{
private SubmissionLookupService service = new DSpace().getServiceManager()
.getServiceByName(SubmissionLookupService.class.getName(),
SubmissionLookupService.class);
private SubmissionLookupService service = new DSpace().getServiceManager()
.getServiceByName(SubmissionLookupService.class.getName(),
SubmissionLookupService.class);
private static Logger log = Logger
.getLogger(SubmissionLookupJSONRequest.class);
private static Logger log = Logger
.getLogger(SubmissionLookupJSONRequest.class);
@Override
public void doJSONRequest(Context context, HttpServletRequest req,
HttpServletResponse resp) throws AuthorizeException, IOException {
Gson json = new Gson();
String suuid = req.getParameter("s_uuid");
SubmissionLookupDTO subDTO = service.getSubmissionLookupDTO(req, suuid);
// Check that we have a file upload request
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
if ("identifiers".equalsIgnoreCase(req.getParameter("type"))) {
Map<String, Set<String>> identifiers = new HashMap<String, Set<String>>();
Enumeration e = req.getParameterNames();
@Override
public void doJSONRequest(Context context, HttpServletRequest req,
HttpServletResponse resp) throws AuthorizeException, IOException
{
Gson json = new Gson();
String suuid = req.getParameter("s_uuid");
SubmissionLookupDTO subDTO = service.getSubmissionLookupDTO(req, suuid);
// Check that we have a file upload request
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
if ("identifiers".equalsIgnoreCase(req.getParameter("type")))
{
Map<String, Set<String>> identifiers = new HashMap<String, Set<String>>();
Enumeration e = req.getParameterNames();
while (e.hasMoreElements()) {
String parameterName = (String) e.nextElement();
String parameterValue = req.getParameter(parameterName);
while (e.hasMoreElements())
{
String parameterName = (String) e.nextElement();
String parameterValue = req.getParameter(parameterName);
if (parameterName.startsWith("identifier_")
&& StringUtils.isNotBlank(parameterValue)) {
Set<String> set = new HashSet<String>();
set.add(parameterValue);
identifiers.put(
parameterName.substring("identifier_".length()),
set);
}
}
if (parameterName.startsWith("identifier_")
&& StringUtils.isNotBlank(parameterValue))
{
Set<String> set = new HashSet<String>();
set.add(parameterValue);
identifiers.put(
parameterName.substring("identifier_".length()),
set);
}
}
List<ItemSubmissionLookupDTO> result = new ArrayList<ItemSubmissionLookupDTO>();
List<ItemSubmissionLookupDTO> result = new ArrayList<ItemSubmissionLookupDTO>();
TransformationEngine transformationEngine = service
.getPhase1TransformationEngine();
if (transformationEngine != null) {
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
.getDataLoader();
dataLoader.setIdentifiers(identifiers);
TransformationEngine transformationEngine = service
.getPhase1TransformationEngine();
if (transformationEngine != null)
{
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
.getDataLoader();
dataLoader.setIdentifiers(identifiers);
try {
log.debug("BTE transformation is about to start!");
transformationEngine.transform(new TransformationSpec());
log.debug("BTE transformation finished!");
try
{
log.debug("BTE transformation is about to start!");
transformationEngine.transform(new TransformationSpec());
log.debug("BTE transformation finished!");
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
.getOutputGenerator();
result = outputGenerator.getDtoList();
} catch (BadTransformationSpec e1) {
log.error(e1.getMessage(), e1);
} catch (MalformedSourceException e1) {
log.error(e1.getMessage(), e1);
}
}
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
.getOutputGenerator();
result = outputGenerator.getDtoList();
}
catch (BadTransformationSpec e1)
{
log.error(e1.getMessage(), e1);
}
catch (MalformedSourceException e1)
{
log.error(e1.getMessage(), e1);
}
}
subDTO.setItems(result);
service.storeDTOs(req, suuid, subDTO);
List<Map<String, Object>> dto = getLightResultList(result);
JsonElement tree = json.toJsonTree(dto);
JsonObject jo = new JsonObject();
jo.add("result", tree);
resp.getWriter().write(jo.toString());
} else if ("search".equalsIgnoreCase(req.getParameter("type"))) {
String title = req.getParameter("title");
String author = req.getParameter("authors");
int year = UIUtil.getIntParameter(req, "year");
subDTO.setItems(result);
service.storeDTOs(req, suuid, subDTO);
List<Map<String, Object>> dto = getLightResultList(result);
JsonElement tree = json.toJsonTree(dto);
JsonObject jo = new JsonObject();
jo.add("result", tree);
resp.getWriter().write(jo.toString());
Map<String, Set<String>> searchTerms = new HashMap<String, Set<String>>();
Set<String> tmp1 = new HashSet<String>();
tmp1.add(title);
Set<String> tmp2 = new HashSet<String>();
tmp2.add(author);
Set<String> tmp3 = new HashSet<String>();
tmp3.add(String.valueOf(year));
searchTerms.put("title", tmp1);
searchTerms.put("authors", tmp2);
searchTerms.put("year", tmp3);
}
else if ("search".equalsIgnoreCase(req.getParameter("type")))
{
String title = req.getParameter("title");
String author = req.getParameter("authors");
int year = UIUtil.getIntParameter(req, "year");
List<ItemSubmissionLookupDTO> result = new ArrayList<ItemSubmissionLookupDTO>();
Map<String, Set<String>> searchTerms = new HashMap<String, Set<String>>();
Set<String> tmp1 = new HashSet<String>();
tmp1.add(title);
Set<String> tmp2 = new HashSet<String>();
tmp2.add(author);
Set<String> tmp3 = new HashSet<String>();
tmp3.add(String.valueOf(year));
searchTerms.put("title", tmp1);
searchTerms.put("authors", tmp2);
searchTerms.put("year", tmp3);
TransformationEngine transformationEngine = service
.getPhase1TransformationEngine();
if (transformationEngine != null) {
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
.getDataLoader();
dataLoader.setSearchTerms(searchTerms);
List<ItemSubmissionLookupDTO> result = new ArrayList<ItemSubmissionLookupDTO>();
try {
transformationEngine.transform(new TransformationSpec());
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
.getOutputGenerator();
result = outputGenerator.getDtoList();
} catch (BadTransformationSpec e1) {
log.error(e1.getMessage(), e1);
} catch (MalformedSourceException e1) {
log.error(e1.getMessage(), e1);
}
}
TransformationEngine transformationEngine = service
.getPhase1TransformationEngine();
if (transformationEngine != null)
{
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
.getDataLoader();
dataLoader.setSearchTerms(searchTerms);
subDTO.setItems(result);
service.storeDTOs(req, suuid, subDTO);
List<Map<String, Object>> dto = getLightResultList(result);
JsonElement tree = json.toJsonTree(dto);
JsonObject jo = new JsonObject();
jo.add("result", tree);
resp.getWriter().write(jo.toString());
} else if ("details".equalsIgnoreCase(req.getParameter("type"))) {
String i_uuid = req.getParameter("i_uuid");
Map<String, Object> dto = getDetails(subDTO.getLookupItem(i_uuid),
context);
JsonElement tree = json.toJsonTree(dto);
JsonObject jo = new JsonObject();
jo.add("result", tree);
resp.getWriter().write(jo.toString());
} else if (isMultipart) {
try
{
transformationEngine.transform(new TransformationSpec());
// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
Map<String, String> valueMap = new HashMap<String, String>();
InputStream io = null;
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
.getOutputGenerator();
result = outputGenerator.getDtoList();
}
catch (BadTransformationSpec e1)
{
log.error(e1.getMessage(), e1);
}
catch (MalformedSourceException e1)
{
log.error(e1.getMessage(), e1);
}
}
// Parse the request
List<FileItem> iter;
subDTO.setItems(result);
service.storeDTOs(req, suuid, subDTO);
List<Map<String, Object>> dto = getLightResultList(result);
JsonElement tree = json.toJsonTree(dto);
JsonObject jo = new JsonObject();
jo.add("result", tree);
resp.getWriter().write(jo.toString());
}
else if ("details".equalsIgnoreCase(req.getParameter("type")))
{
String i_uuid = req.getParameter("i_uuid");
Map<String, Object> dto = getDetails(subDTO.getLookupItem(i_uuid),
context);
JsonElement tree = json.toJsonTree(dto);
JsonObject jo = new JsonObject();
jo.add("result", tree);
resp.getWriter().write(jo.toString());
}
else if (isMultipart)
{
// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
Map<String, String> valueMap = new HashMap<String, String>();
InputStream io = null;
// Parse the request
List<FileItem> iter;
String filename = null;
try {
iter = upload.parseRequest(req);
for(FileItem item : iter) {
String name = item.getFieldName();
InputStream stream = item.getInputStream();
if (item.isFormField()) {
String value = Streams.asString(stream);
valueMap.put(name, value);
} else {
io = stream;
}
}
} catch (FileUploadException e) {
throw new IOException(e);
}
try
{
iter = upload.parseRequest(req);
for (FileItem item : iter)
{
String name = item.getFieldName();
InputStream stream = item.getInputStream();
if (item.isFormField())
{
String value = Streams.asString(stream);
valueMap.put(name, value);
}
else
{
io = stream;
}
}
}
catch (FileUploadException e)
{
throw new IOException(e);
}
suuid = valueMap.get("s_uuid");
subDTO = service.getSubmissionLookupDTO(req, suuid);
suuid = valueMap.get("s_uuid");
subDTO = service.getSubmissionLookupDTO(req, suuid);
List<ItemSubmissionLookupDTO> result = new ArrayList<ItemSubmissionLookupDTO>();
List<ItemSubmissionLookupDTO> result = new ArrayList<ItemSubmissionLookupDTO>();
TransformationEngine transformationEngine = service
.getPhase1TransformationEngine();
if (transformationEngine != null) {
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
.getDataLoader();
String tempDir = (ConfigurationManager.getProperty("upload.temp.dir") != null)
? ConfigurationManager.getProperty("upload.temp.dir") : System.getProperty("java.io.tmpdir");
File file = new File(tempDir + System.getProperty("file.separator") + "submissionlookup-loader.temp");
BufferedOutputStream out = new BufferedOutputStream(
TransformationEngine transformationEngine = service
.getPhase1TransformationEngine();
if (transformationEngine != null)
{
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
.getDataLoader();
String tempDir = (ConfigurationManager
.getProperty("upload.temp.dir") != null) ? ConfigurationManager
.getProperty("upload.temp.dir") : System
.getProperty("java.io.tmpdir");
File file = new File(tempDir
+ System.getProperty("file.separator")
+ "submissionlookup-loader.temp");
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(file));
Utils.bufferedCopy(io, out);
dataLoader.setFile(file.getAbsolutePath(), valueMap.get("provider_loader"));
try {
transformationEngine.transform(new TransformationSpec());
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
.getOutputGenerator();
result = outputGenerator.getDtoList();
} catch (BadTransformationSpec e1) {
log.error(e1.getMessage(), e1);
} catch (MalformedSourceException e1) {
log.error(e1.getMessage(), e1);
}
Utils.bufferedCopy(io, out);
dataLoader.setFile(file.getAbsolutePath(),
valueMap.get("provider_loader"));
try
{
transformationEngine.transform(new TransformationSpec());
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
.getOutputGenerator();
result = outputGenerator.getDtoList();
}
catch (BadTransformationSpec e1)
{
log.error(e1.getMessage(), e1);
}
catch (MalformedSourceException e1)
{
log.error(e1.getMessage(), e1);
}
file.delete();
}
subDTO.setItems(result);
service.storeDTOs(req, suuid, subDTO);
List<Map<String, Object>> dto = getLightResultList(result);
if (valueMap.containsKey("skip_loader")) {
if (valueMap.get("skip_loader").equals("true")) {
Map<String, Object> skip = new HashMap<String, Object>();
skip.put(
"skip",
Boolean.TRUE);
skip.put(
"uuid",
valueMap.containsKey("s_uuid") ? suuid
: -1);
skip.put(
"collectionid",
valueMap.containsKey("select-collection-file") ? valueMap
.get("select-collection-file") : -1);
dto.add(skip);
}
}
JsonElement tree = json.toJsonTree(dto);
JsonObject jo = new JsonObject();
jo.add("result", tree);
resp.getWriter().write(jo.toString());
resp.setContentType("text/plain");
}
}
}
subDTO.setItems(result);
service.storeDTOs(req, suuid, subDTO);
List<Map<String, Object>> dto = getLightResultList(result);
if (valueMap.containsKey("skip_loader"))
{
if (valueMap.get("skip_loader").equals("true"))
{
Map<String, Object> skip = new HashMap<String, Object>();
skip.put("skip", Boolean.TRUE);
skip.put("uuid", valueMap.containsKey("s_uuid") ? suuid
: -1);
skip.put(
"collectionid",
valueMap.containsKey("select-collection-file") ? valueMap
.get("select-collection-file") : -1);
dto.add(skip);
}
}
JsonElement tree = json.toJsonTree(dto);
JsonObject jo = new JsonObject();
jo.add("result", tree);
resp.getWriter().write(jo.toString());
resp.setContentType("text/plain");
}
}
private Map<String, Object> getDetails(ItemSubmissionLookupDTO item,
Context context) {
List<String> fieldOrder = getFieldOrderFromConfiguration();
Record totalData = item.getTotalPublication(service.getProviders());
Set<String> availableFields = totalData.getFields();
List<String[]> fieldsLabels = new ArrayList<String[]>();
for (String f : fieldOrder) {
if (availableFields.contains(f)) {
try {
fieldsLabels.add(new String[] {
f,
I18nUtil.getMessage("jsp.submission-lookup.detail."
+ f, context) });
} catch (MissingResourceException e) {
fieldsLabels.add(new String[] { f, f });
}
}
}
Map<String, Object> data = new HashMap<String, Object>();
String uuid = item.getUUID();
Record pub = item.getTotalPublication(service.getProviders());
Map<String, List<String>> publication1 = new HashMap<String, List<String>>();
for (String field : pub.getFields()){
publication1.put(field, SubmissionLookupUtils.getValues(pub, field));
}
data.put("uuid", uuid);
data.put("providers", item.getProviders());
data.put("publication", publication1);
data.put("fieldsLabels", fieldsLabels);
return data;
}
private Map<String, Object> getDetails(ItemSubmissionLookupDTO item,
Context context)
{
List<String> fieldOrder = getFieldOrderFromConfiguration();
Record totalData = item.getTotalPublication(service.getProviders());
Set<String> availableFields = totalData.getFields();
List<String[]> fieldsLabels = new ArrayList<String[]>();
for (String f : fieldOrder)
{
if (availableFields.contains(f))
{
try
{
fieldsLabels.add(new String[] {
f,
I18nUtil.getMessage("jsp.submission-lookup.detail."
+ f, context) });
}
catch (MissingResourceException e)
{
fieldsLabels.add(new String[] { f, f });
}
}
}
Map<String, Object> data = new HashMap<String, Object>();
String uuid = item.getUUID();
private List<String> getFieldOrderFromConfiguration() {
String config = ConfigurationManager
.getProperty("submission-lookup.detail.fields");
if (config == null) {
config = "title,authors,editors,years,doi,pmid,eid,arxiv,journal,jissn,jeissn,volume,issue,serie,sissn,seissn,abstract,mesh,keywords,subtype";
}
List<String> result = new ArrayList<String>();
String[] split = config.split(",");
for (String s : split) {
if (StringUtils.isNotBlank(s)) {
result.add(s.trim());
}
}
return result;
}
Record pub = item.getTotalPublication(service.getProviders());
Map<String, List<String>> publication1 = new HashMap<String, List<String>>();
for (String field : pub.getFields())
{
publication1
.put(field, SubmissionLookupUtils.getValues(pub, field));
}
private List<Map<String, Object>> getLightResultList(
List<ItemSubmissionLookupDTO> result) {
List<Map<String, Object>> publications = new ArrayList<Map<String, Object>>();
if (result != null && result.size() > 0) {
for (ItemSubmissionLookupDTO item : result) {
String uuid = item.getUUID();
Record pub = item.getTotalPublication(service.getProviders());
Map<String, Object> data = new HashMap<String, Object>();
data.put("uuid", uuid);
data.put("providers", item.getProviders());
data.put("title",
SubmissionLookupUtils.getFirstValue(pub, "title"));
data.put(
"authors",
pub.getValues("authors") != null ? StringUtils.join(
SubmissionLookupUtils.getValues(pub, "authors")
.iterator(), ", ") : "");
data.put("issued",
SubmissionLookupUtils.getFirstValue(pub, "issued"));
data.put("uuid", uuid);
data.put("providers", item.getProviders());
data.put("publication", publication1);
data.put("fieldsLabels", fieldsLabels);
return data;
}
publications.add(data);
}
}
return publications;
}
private List<String> getFieldOrderFromConfiguration()
{
String config = ConfigurationManager
.getProperty("submission-lookup.detail.fields");
if (config == null)
{
config = "title,authors,editors,years,doi,pmid,eid,arxiv,journal,jissn,jeissn,volume,issue,serie,sissn,seissn,abstract,mesh,keywords,subtype";
}
List<String> result = new ArrayList<String>();
String[] split = config.split(",");
for (String s : split)
{
if (StringUtils.isNotBlank(s))
{
result.add(s.trim());
}
}
return result;
}
private List<Map<String, Object>> getLightResultList(
List<ItemSubmissionLookupDTO> result)
{
List<Map<String, Object>> publications = new ArrayList<Map<String, Object>>();
if (result != null && result.size() > 0)
{
for (ItemSubmissionLookupDTO item : result)
{
String uuid = item.getUUID();
Record pub = item.getTotalPublication(service.getProviders());
Map<String, Object> data = new HashMap<String, Object>();
data.put("uuid", uuid);
data.put("providers", item.getProviders());
data.put("title",
SubmissionLookupUtils.getFirstValue(pub, "title"));
data.put(
"authors",
pub.getValues("authors") != null ? StringUtils.join(
SubmissionLookupUtils.getValues(pub, "authors")
.iterator(), ", ") : "");
data.put("issued",
SubmissionLookupUtils.getFirstValue(pub, "issued"));
publications.add(data);
}
}
return publications;
}
}

View File

@@ -35,21 +35,20 @@ import org.dspace.submit.step.StartSubmissionLookupStep;
import org.dspace.utils.DSpace;
/**
* Step which controls selecting an item from external database service to auto fill metadata
* for DSpace JSP-UI
* Step which controls selecting an item from external database service to auto
* fill metadata for DSpace JSP-UI
* <P>
* This JSPStep class works with the SubmissionController servlet
* for the JSP-UI
* This JSPStep class works with the SubmissionController servlet for the JSP-UI
* <P>
* The following methods are called in this order:
* <ul>
* <li>Call doPreProcessing() method</li>
* <li>If showJSP() was specified from doPreProcessing(), then the JSP
* specified will be displayed</li>
* <li>If showJSP() was specified from doPreProcessing(), then the JSP specified
* will be displayed</li>
* <li>If showJSP() was not specified from doPreProcessing(), then the
* doProcessing() method is called an the step completes immediately</li>
* <li>Call doProcessing() method on appropriate AbstractProcessingStep after the user returns from the JSP, in order
* to process the user input</li>
* <li>Call doProcessing() method on appropriate AbstractProcessingStep after
* the user returns from the JSP, in order to process the user input</li>
* <li>Call doPostProcessing() method to determine if more user interaction is
* required, and if further JSPs need to be called.</li>
* <li>If there are more "pages" in this step then, the process begins again
@@ -71,12 +70,13 @@ public class JSPStartSubmissionLookupStep extends JSPStep
private static final String START_LOOKUP_JSP = "/submit/start-lookup-submission.jsp";
/** log4j logger */
private static Logger log = Logger.getLogger(JSPStartSubmissionLookupStep.class);
private static Logger log = Logger
.getLogger(JSPStartSubmissionLookupStep.class);
SubmissionLookupService slService = new DSpace().getServiceManager()
.getServiceByName(
SubmissionLookupService.class.getCanonicalName(),
SubmissionLookupService.class);
.getServiceByName(SubmissionLookupService.class.getCanonicalName(),
SubmissionLookupService.class);
/**
* Do any pre-processing to determine which JSP (if any) is used to generate
* the UI for this step. This method should include the gathering and
@@ -169,13 +169,11 @@ public class JSPStartSubmissionLookupStep extends JSPStep
// save collections to request for JSP
request.setAttribute("collections", collections);
request.setAttribute("collectionID", collectionID);
Map<String, List<String>> identifiers2providers = slService
.getProvidersIdentifiersMap();
List<String> searchProviders = slService
.getSearchProviders();
List<String> fileProviders = slService
.getFileProviders();
List<String> searchProviders = slService.getSearchProviders();
List<String> fileProviders = slService.getFileProviders();
request.setAttribute("identifiers2providers", identifiers2providers);
request.setAttribute("searchProviders", searchProviders);
request.setAttribute("fileLoaders", fileProviders);
@@ -226,12 +224,12 @@ public class JSPStartSubmissionLookupStep extends JSPStep
}
else if (status == StartSubmissionLookupStep.STATUS_INVALID_COLLECTION)
{
JSPManager.showInvalidIDError(request, response, request
.getParameter("collectionid"), Constants.COLLECTION);
JSPManager.showInvalidIDError(request, response,
request.getParameter("collectionid"), Constants.COLLECTION);
}
else if (status == StartSubmissionLookupStep.STATUS_NO_SUUID)
{
// specify "no suuid" error message should be displayed
// specify "no suuid" error message should be displayed
request.setAttribute("no.suuid", new Boolean(true));
// reload this page, by re-calling doPreProcessing()
@@ -239,25 +237,25 @@ public class JSPStartSubmissionLookupStep extends JSPStep
}
else if (status == StartSubmissionLookupStep.STATUS_SUBMISSION_EXPIRED)
{
// specify "no collection" error message should be displayed
// specify "no collection" error message should be displayed
request.setAttribute("expired", new Boolean(true));
// reload this page, by re-calling doPreProcessing()
doPreProcessing(context, request, response, subInfo);
doPreProcessing(context, request, response, subInfo);
}
else if (status != StartSubmissionLookupStep.STATUS_COMPLETE)
{
// specify "no suuid" error message should be displayed
// specify "no suuid" error message should be displayed
request.setAttribute("no.suuid", new Boolean(true));
// reload this page, by re-calling doPreProcessing()
doPreProcessing(context, request, response, subInfo);
}
}
/**
* Return the URL path (e.g. /submit/review-metadata.jsp) of the JSP
* which will review the information that was gathered in this Step.
* Return the URL path (e.g. /submit/review-metadata.jsp) of the JSP which
* will review the information that was gathered in this Step.
* <P>
* This Review JSP is loaded by the 'Verify' Step, in order to dynamically
* generate a submission verification page consisting of the information
@@ -275,6 +273,7 @@ public class JSPStartSubmissionLookupStep extends JSPStep
public String getReviewJSP(Context context, HttpServletRequest request,
HttpServletResponse response, SubmissionInfo subInfo)
{
return NO_JSP; //at this time, you cannot review what collection you selected.
return NO_JSP; // at this time, you cannot review what collection you
// selected.
}
}