mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 06:53:09 +00:00
Code formatted with DSpace conventions
This commit is contained in:
@@ -39,106 +39,133 @@ import gr.ekt.bte.exceptions.MalformedSourceException;
|
|||||||
* @author Kostas Stamatis
|
* @author Kostas Stamatis
|
||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ArXivFileDataLoader extends FileDataLoader {
|
public class ArXivFileDataLoader extends FileDataLoader
|
||||||
|
{
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(ArXivFileDataLoader.class);
|
private static Logger log = Logger.getLogger(ArXivFileDataLoader.class);
|
||||||
|
|
||||||
Map<String, String> fieldMap; //mapping between service fields and local intermediate fields
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Empty constructor
|
|
||||||
*/
|
|
||||||
public ArXivFileDataLoader() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
Map<String, String> fieldMap; // mapping between service fields and local
|
||||||
* @param filename
|
// intermediate fields
|
||||||
*/
|
|
||||||
public ArXivFileDataLoader(String filename) {
|
|
||||||
super(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/**
|
||||||
* @see gr.ekt.bte.core.DataLoader#getRecords()
|
* Empty constructor
|
||||||
*/
|
*/
|
||||||
@Override
|
public ArXivFileDataLoader()
|
||||||
public RecordSet getRecords() throws MalformedSourceException {
|
{
|
||||||
|
}
|
||||||
RecordSet recordSet = new RecordSet();
|
|
||||||
|
|
||||||
try {
|
/**
|
||||||
InputStream inputStream = new FileInputStream(new File(filename));
|
* @param filename
|
||||||
|
*/
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory
|
public ArXivFileDataLoader(String filename)
|
||||||
.newInstance();
|
{
|
||||||
factory.setValidating(false);
|
super(filename);
|
||||||
factory.setIgnoringComments(true);
|
}
|
||||||
factory.setIgnoringElementContentWhitespace(true);
|
|
||||||
|
|
||||||
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();
|
RecordSet recordSet = new RecordSet();
|
||||||
List<Element> dataRoots = XMLUtils.getElementList(xmlRoot,
|
|
||||||
"entry");
|
|
||||||
|
|
||||||
for (Element dataRoot : dataRoots)
|
try
|
||||||
{
|
{
|
||||||
Record record = ArxivUtils.convertArxixDomToRecord(dataRoot);
|
InputStream inputStream = new FileInputStream(new File(filename));
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
DocumentBuilderFactory factory = DocumentBuilderFactory
|
||||||
* @see gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
|
.newInstance();
|
||||||
*/
|
factory.setValidating(false);
|
||||||
@Override
|
factory.setIgnoringComments(true);
|
||||||
public RecordSet getRecords(DataLoadingSpec spec)
|
factory.setIgnoringElementContentWhitespace(true);
|
||||||
throws MalformedSourceException {
|
|
||||||
|
|
||||||
return getRecords();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Record convertFields(Record publication) {
|
DocumentBuilder db = factory.newDocumentBuilder();
|
||||||
for (String fieldName : fieldMap.keySet()) {
|
Document inDoc = db.parse(inputStream);
|
||||||
String md = null;
|
|
||||||
if (fieldMap!=null){
|
|
||||||
md = this.fieldMap.get(fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.isBlank(md)) {
|
Element xmlRoot = inDoc.getDocumentElement();
|
||||||
continue;
|
List<Element> dataRoots = XMLUtils.getElementList(xmlRoot, "entry");
|
||||||
} else {
|
|
||||||
md = md.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (publication.isMutable()){
|
for (Element dataRoot : dataRoots)
|
||||||
List<Value> values = publication.getValues(fieldName);
|
{
|
||||||
publication.makeMutable().removeField(fieldName);
|
Record record = ArxivUtils.convertArxixDomToRecord(dataRoot);
|
||||||
publication.makeMutable().addField(md, values);
|
if (record != null)
|
||||||
}
|
{
|
||||||
}
|
recordSet.addRecord(convertFields(record));
|
||||||
|
}
|
||||||
return publication;
|
}
|
||||||
}
|
}
|
||||||
|
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) {
|
return recordSet;
|
||||||
this.fieldMap = fieldMap;
|
}
|
||||||
}
|
|
||||||
|
/*
|
||||||
|
* (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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,60 +25,74 @@ import org.dspace.core.Context;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class ArXivOnlineDataLoader extends NetworkSubmissionLookupDataLoader {
|
public class ArXivOnlineDataLoader extends NetworkSubmissionLookupDataLoader
|
||||||
private ArXivService arXivService = new ArXivService();
|
{
|
||||||
private boolean searchProvider = true;
|
private ArXivService arXivService = new ArXivService();
|
||||||
|
|
||||||
public void setArXivService(ArXivService arXivService) {
|
private boolean searchProvider = true;
|
||||||
this.arXivService = arXivService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public void setArXivService(ArXivService arXivService)
|
||||||
public List<String> getSupportedIdentifiers() {
|
{
|
||||||
return Arrays.asList(new String[] { ARXIV, DOI });
|
this.arXivService = arXivService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSearchProvider(boolean searchProvider) {
|
@Override
|
||||||
this.searchProvider = searchProvider;
|
public List<String> getSupportedIdentifiers()
|
||||||
}
|
{
|
||||||
|
return Arrays.asList(new String[] { ARXIV, DOI });
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
public void setSearchProvider(boolean searchProvider)
|
||||||
public boolean isSearchProvider() {
|
{
|
||||||
return searchProvider;
|
this.searchProvider = searchProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Record> getByIdentifier(Context context,
|
public boolean isSearchProvider()
|
||||||
Map<String, Set<String>> keys) throws HttpException, IOException {
|
{
|
||||||
List<Record> results = new ArrayList<Record>();
|
return searchProvider;
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Record item : items) {
|
@Override
|
||||||
results.add(convertFields(item));
|
public List<Record> getByIdentifier(Context context,
|
||||||
}
|
Map<String, Set<String>> keys) throws HttpException, IOException
|
||||||
}
|
{
|
||||||
return results;
|
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
|
for (Record item : items)
|
||||||
public List<Record> search(Context context, String title, String author,
|
{
|
||||||
int year) throws HttpException, IOException {
|
results.add(convertFields(item));
|
||||||
List<Record> results = new ArrayList<Record>();
|
}
|
||||||
List<Record> items = arXivService.searchByTerm(title, author, year);
|
}
|
||||||
for (Record item : items) {
|
return results;
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -123,7 +123,8 @@ public class ArXivService
|
|||||||
|
|
||||||
for (Element dataRoot : dataRoots)
|
for (Element dataRoot : dataRoots)
|
||||||
{
|
{
|
||||||
Record crossitem = ArxivUtils.convertArxixDomToRecord(dataRoot);
|
Record crossitem = ArxivUtils
|
||||||
|
.convertArxixDomToRecord(dataRoot);
|
||||||
if (crossitem != null)
|
if (crossitem != null)
|
||||||
{
|
{
|
||||||
results.add(crossitem);
|
results.add(crossitem);
|
||||||
@@ -168,7 +169,8 @@ public class ArXivService
|
|||||||
"entry");
|
"entry");
|
||||||
for (Element dataRoot : dataRoots)
|
for (Element dataRoot : dataRoots)
|
||||||
{
|
{
|
||||||
Record crossitem = ArxivUtils.convertArxixDomToRecord(dataRoot);
|
Record crossitem = ArxivUtils
|
||||||
|
.convertArxixDomToRecord(dataRoot);
|
||||||
|
|
||||||
if (crossitem != null)
|
if (crossitem != null)
|
||||||
{
|
{
|
||||||
@@ -193,8 +195,7 @@ public class ArXivService
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Record getByArXivIDs(String raw) throws HttpException,
|
public Record getByArXivIDs(String raw) throws HttpException, IOException
|
||||||
IOException
|
|
||||||
{
|
{
|
||||||
if (StringUtils.isNotBlank(raw))
|
if (StringUtils.isNotBlank(raw))
|
||||||
{
|
{
|
||||||
|
@@ -28,72 +28,79 @@ import org.w3c.dom.Element;
|
|||||||
* @author Kostas Stamatis
|
* @author Kostas Stamatis
|
||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ArxivUtils {
|
public class ArxivUtils
|
||||||
|
{
|
||||||
|
|
||||||
public static Record convertArxixDomToRecord(Element dataRoot){
|
public static Record convertArxixDomToRecord(Element dataRoot)
|
||||||
MutableRecord record = new SubmissionLookupPublication("");
|
{
|
||||||
|
MutableRecord record = new SubmissionLookupPublication("");
|
||||||
String articleTitle = XMLUtils.getElementValue(dataRoot, "title");
|
|
||||||
if (articleTitle!=null)
|
String articleTitle = XMLUtils.getElementValue(dataRoot, "title");
|
||||||
record.addValue("articleTitle", new StringValue(articleTitle));
|
if (articleTitle != null)
|
||||||
String summary = XMLUtils.getElementValue(dataRoot, "summary");
|
record.addValue("articleTitle", new StringValue(articleTitle));
|
||||||
if (summary!=null)
|
String summary = XMLUtils.getElementValue(dataRoot, "summary");
|
||||||
record.addValue("summary", new StringValue(summary));
|
if (summary != null)
|
||||||
String year = XMLUtils.getElementValue(dataRoot, "published");
|
record.addValue("summary", new StringValue(summary));
|
||||||
if (year!=null)
|
String year = XMLUtils.getElementValue(dataRoot, "published");
|
||||||
record.addValue("year", new StringValue(year));
|
if (year != null)
|
||||||
String splashPageUrl = XMLUtils.getElementValue(dataRoot, "id");
|
record.addValue("year", new StringValue(year));
|
||||||
if (splashPageUrl!=null)
|
String splashPageUrl = XMLUtils.getElementValue(dataRoot, "id");
|
||||||
record.addValue("splashPageUrl", new StringValue(splashPageUrl));
|
if (splashPageUrl != null)
|
||||||
String comment = XMLUtils.getElementValue(dataRoot, "arxiv:comment");
|
record.addValue("splashPageUrl", new StringValue(splashPageUrl));
|
||||||
if (comment!=null)
|
String comment = XMLUtils.getElementValue(dataRoot, "arxiv:comment");
|
||||||
record.addValue("comment", new StringValue(comment));
|
if (comment != null)
|
||||||
|
record.addValue("comment", new StringValue(comment));
|
||||||
|
|
||||||
|
|
||||||
List<Element> links = XMLUtils.getElementList(dataRoot, "link");
|
List<Element> links = XMLUtils.getElementList(dataRoot, "link");
|
||||||
if (links != null)
|
if (links != null)
|
||||||
{
|
{
|
||||||
for (Element link : links)
|
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");
|
String pdfUrl = link.getAttribute("href");
|
||||||
if (pdfUrl!=null)
|
if (pdfUrl != null)
|
||||||
record.addValue("pdfUrl", new StringValue(pdfUrl));
|
record.addValue("pdfUrl", new StringValue(pdfUrl));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String doi = XMLUtils.getElementValue(dataRoot, "arxiv:doi");
|
String doi = XMLUtils.getElementValue(dataRoot, "arxiv:doi");
|
||||||
if (doi!=null)
|
if (doi != null)
|
||||||
record.addValue("doi", new StringValue(doi));
|
record.addValue("doi", new StringValue(doi));
|
||||||
String journalRef = XMLUtils.getElementValue(dataRoot, "arxiv:journal_ref");
|
String journalRef = XMLUtils.getElementValue(dataRoot,
|
||||||
if (journalRef!=null)
|
"arxiv:journal_ref");
|
||||||
record.addValue("journalRef", new StringValue(journalRef));
|
if (journalRef != null)
|
||||||
|
record.addValue("journalRef", new StringValue(journalRef));
|
||||||
List<String> primaryCategory = new LinkedList<String>();
|
|
||||||
List<Element> primaryCategoryList = XMLUtils.getElementList(dataRoot, "arxiv:primary_category");
|
List<String> primaryCategory = new LinkedList<String>();
|
||||||
|
List<Element> primaryCategoryList = XMLUtils.getElementList(dataRoot,
|
||||||
|
"arxiv:primary_category");
|
||||||
if (primaryCategoryList != null)
|
if (primaryCategoryList != null)
|
||||||
{
|
{
|
||||||
for (Element primaryCategoryElement : primaryCategoryList)
|
for (Element primaryCategoryElement : primaryCategoryList)
|
||||||
{
|
{
|
||||||
primaryCategory.add(primaryCategoryElement.getAttribute("term"));
|
primaryCategory
|
||||||
|
.add(primaryCategoryElement.getAttribute("term"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (primaryCategory.size()>0){
|
if (primaryCategory.size() > 0)
|
||||||
List<Value> values = new LinkedList<Value>();
|
{
|
||||||
for (String s : primaryCategory){
|
List<Value> values = new LinkedList<Value>();
|
||||||
values.add(new StringValue(s));
|
for (String s : primaryCategory)
|
||||||
}
|
{
|
||||||
record.addField("primaryCategory", values);
|
values.add(new StringValue(s));
|
||||||
}
|
}
|
||||||
|
record.addField("primaryCategory", values);
|
||||||
List<String> category = new LinkedList<String>();
|
}
|
||||||
List<Element> categoryList = XMLUtils.getElementList(dataRoot, "category");
|
|
||||||
|
List<String> category = new LinkedList<String>();
|
||||||
|
List<Element> categoryList = XMLUtils.getElementList(dataRoot,
|
||||||
|
"category");
|
||||||
if (categoryList != null)
|
if (categoryList != null)
|
||||||
{
|
{
|
||||||
for (Element categoryElement : categoryList)
|
for (Element categoryElement : categoryList)
|
||||||
@@ -101,15 +108,17 @@ public class ArxivUtils {
|
|||||||
category.add(categoryElement.getAttribute("term"));
|
category.add(categoryElement.getAttribute("term"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (category.size()>0){
|
if (category.size() > 0)
|
||||||
List<Value> values = new LinkedList<Value>();
|
{
|
||||||
for (String s : category){
|
List<Value> values = new LinkedList<Value>();
|
||||||
values.add(new StringValue(s));
|
for (String s : category)
|
||||||
}
|
{
|
||||||
record.addField("category", values);
|
values.add(new StringValue(s));
|
||||||
}
|
}
|
||||||
|
record.addField("category", values);
|
||||||
|
}
|
||||||
|
|
||||||
List<String[]> authors = new LinkedList<String[]>();
|
List<String[]> authors = new LinkedList<String[]>();
|
||||||
List<Element> authorList = XMLUtils.getElementList(dataRoot, "author");
|
List<Element> authorList = XMLUtils.getElementList(dataRoot, "author");
|
||||||
if (authorList != null)
|
if (authorList != null)
|
||||||
@@ -124,7 +133,7 @@ public class ArxivUtils {
|
|||||||
{
|
{
|
||||||
String senzaPunti = nomeCompleto.replace("\\.", "");
|
String senzaPunti = nomeCompleto.replace("\\.", "");
|
||||||
String[] tmp = senzaPunti.split("\\s+");
|
String[] tmp = senzaPunti.split("\\s+");
|
||||||
|
|
||||||
int start = 1;
|
int start = 1;
|
||||||
if (tmp.length == nomeSplit.length)
|
if (tmp.length == nomeSplit.length)
|
||||||
{
|
{
|
||||||
@@ -154,19 +163,21 @@ public class ArxivUtils {
|
|||||||
{
|
{
|
||||||
cognome = nomeCompleto;
|
cognome = nomeCompleto;
|
||||||
}
|
}
|
||||||
authors.add(new String[]{nome, cognome});
|
authors.add(new String[] { nome, cognome });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authors.size()>0){
|
if (authors.size() > 0)
|
||||||
List<Value> values = new LinkedList<Value>();
|
{
|
||||||
for (String[] sArray : authors){
|
List<Value> values = new LinkedList<Value>();
|
||||||
values.add(new StringValue(sArray[1]+", "+sArray[0]));
|
for (String[] sArray : authors)
|
||||||
}
|
{
|
||||||
record.addField("authors", values);
|
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
|
||||||
}
|
}
|
||||||
|
record.addField("authors", values);
|
||||||
return record;
|
}
|
||||||
}
|
|
||||||
|
return record;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -39,96 +39,125 @@ import gr.ekt.bte.exceptions.MalformedSourceException;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @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
|
* @param filename
|
||||||
*/
|
*/
|
||||||
public CrossRefFileDataLoader(String filename) {
|
public CrossRefFileDataLoader(String filename)
|
||||||
super(filename);
|
{
|
||||||
}
|
super(filename);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
* @see gr.ekt.bte.core.DataLoader#getRecords()
|
* (non-Javadoc)
|
||||||
*/
|
*
|
||||||
@Override
|
* @see gr.ekt.bte.core.DataLoader#getRecords()
|
||||||
public RecordSet getRecords() throws MalformedSourceException {
|
*/
|
||||||
|
@Override
|
||||||
RecordSet recordSet = new RecordSet();
|
public RecordSet getRecords() throws MalformedSourceException
|
||||||
|
{
|
||||||
try {
|
|
||||||
InputStream inputStream = new FileInputStream(new File(filename));
|
|
||||||
|
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
||||||
factory.setValidating(false);
|
|
||||||
factory.setIgnoringComments(true);
|
|
||||||
factory.setIgnoringElementContentWhitespace(true);
|
|
||||||
|
|
||||||
DocumentBuilder db = factory.newDocumentBuilder();
|
RecordSet recordSet = new RecordSet();
|
||||||
Document inDoc = db.parse(inputStream);
|
|
||||||
|
|
||||||
Element xmlRoot = inDoc.getDocumentElement();
|
try
|
||||||
Element dataRoot = XMLUtils.getSingleElement(xmlRoot, "query");
|
{
|
||||||
|
InputStream inputStream = new FileInputStream(new File(filename));
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
DocumentBuilderFactory factory = DocumentBuilderFactory
|
||||||
* @see gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
|
.newInstance();
|
||||||
*/
|
factory.setValidating(false);
|
||||||
@Override
|
factory.setIgnoringComments(true);
|
||||||
public RecordSet getRecords(DataLoadingSpec spec)
|
factory.setIgnoringElementContentWhitespace(true);
|
||||||
throws MalformedSourceException {
|
|
||||||
|
|
||||||
return getRecords();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Record convertFields(Record publication) {
|
DocumentBuilder db = factory.newDocumentBuilder();
|
||||||
for (String fieldName : fieldMap.keySet()) {
|
Document inDoc = db.parse(inputStream);
|
||||||
String md = null;
|
|
||||||
if (fieldMap!=null){
|
|
||||||
md = this.fieldMap.get(fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.isBlank(md)) {
|
Element xmlRoot = inDoc.getDocumentElement();
|
||||||
continue;
|
Element dataRoot = XMLUtils.getSingleElement(xmlRoot, "query");
|
||||||
} else {
|
|
||||||
md = md.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (publication.isMutable()){
|
Record record = CrossRefUtils.convertCrossRefDomToRecord(dataRoot);
|
||||||
List<Value> values = publication.getValues(fieldName);
|
recordSet.addRecord(convertFields(record));
|
||||||
publication.makeMutable().removeField(fieldName);
|
|
||||||
publication.makeMutable().addField(md, values);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return publication;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,58 +29,74 @@ import org.xml.sax.SAXException;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class CrossRefOnlineDataLoader extends NetworkSubmissionLookupDataLoader {
|
public class CrossRefOnlineDataLoader extends NetworkSubmissionLookupDataLoader
|
||||||
private CrossRefService crossrefService = new CrossRefService();
|
{
|
||||||
|
private CrossRefService crossrefService = new CrossRefService();
|
||||||
|
|
||||||
private boolean searchProvider = true;
|
private boolean searchProvider = true;
|
||||||
|
|
||||||
public void setSearchProvider(boolean searchProvider)
|
public void setSearchProvider(boolean searchProvider)
|
||||||
{
|
{
|
||||||
this.searchProvider = searchProvider;
|
this.searchProvider = searchProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCrossrefService(CrossRefService crossrefService) {
|
|
||||||
this.crossrefService = crossrefService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public void setCrossrefService(CrossRefService crossrefService)
|
||||||
public List<String> getSupportedIdentifiers() {
|
{
|
||||||
return Arrays.asList(new String[] { DOI });
|
this.crossrefService = crossrefService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Record> getByIdentifier(Context context,
|
public List<String> getSupportedIdentifiers()
|
||||||
Map<String, Set<String>> keys) throws HttpException, IOException {
|
{
|
||||||
if (keys != null && keys.containsKey(DOI)) {
|
return Arrays.asList(new String[] { 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
|
@Override
|
||||||
public List<Record> search(Context context, String title,
|
public List<Record> getByIdentifier(Context context,
|
||||||
String author, int year) throws HttpException, IOException {
|
Map<String, Set<String>> keys) throws HttpException, IOException
|
||||||
List<Record> items = crossrefService.search(context, title, author, year, 10);
|
{
|
||||||
return items;
|
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
|
@Override
|
||||||
public boolean isSearchProvider() {
|
public List<Record> search(Context context, String title, String author,
|
||||||
return searchProvider;
|
int year) throws HttpException, IOException
|
||||||
}
|
{
|
||||||
|
List<Record> items = crossrefService.search(context, title, author,
|
||||||
|
year, 10);
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSearchProvider()
|
||||||
|
{
|
||||||
|
return searchProvider;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -46,146 +46,181 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class CrossRefService {
|
public class CrossRefService
|
||||||
|
{
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger(CrossRefService.class);
|
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();
|
private int timeout = 1000;
|
||||||
Document inDoc = db.parse(method.getResponseBodyAsStream());
|
|
||||||
|
|
||||||
Element xmlRoot = inDoc.getDocumentElement();
|
public void setTimeout(int timeout)
|
||||||
Element dataRoot = XMLUtils.getSingleElement(xmlRoot, "query");
|
{
|
||||||
|
this.timeout = timeout;
|
||||||
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) {
|
public List<Record> search(Context context, Set<String> dois)
|
||||||
StringBuffer sb = new StringBuffer();
|
throws HttpException, IOException, JDOMException,
|
||||||
if (StringUtils.isNotBlank(title)) {
|
ParserConfigurationException, SAXException
|
||||||
sb.append(title);
|
{
|
||||||
}
|
List<Record> results = new ArrayList<Record>();
|
||||||
sb.append(" ");
|
if (dois != null && dois.size() > 0)
|
||||||
if (StringUtils.isNotBlank(author)) {
|
{
|
||||||
sb.append(author);
|
for (String record : dois)
|
||||||
}
|
{
|
||||||
String q = sb.toString().trim();
|
try
|
||||||
NameValuePair qParam = new NameValuePair("q", title);
|
{
|
||||||
NameValuePair yearParam = new NameValuePair("year",
|
if (!ConfigurationManager
|
||||||
year != -1?String.valueOf(year):"");
|
.getBooleanProperty("remoteservice.demo"))
|
||||||
NameValuePair countParam = new NameValuePair("rows",
|
{
|
||||||
count!= -1?String.valueOf(count):"");
|
GetMethod method = null;
|
||||||
|
try
|
||||||
NameValuePair[] query = new NameValuePair[] { qParam,
|
{
|
||||||
yearParam, countParam };
|
String apiKey = ConfigurationManager
|
||||||
return query;
|
.getProperty("crossref.api-key");
|
||||||
}
|
|
||||||
|
|
||||||
public List<Record> search(Context context, String title, String authors, int year,
|
HttpClient client = new HttpClient();
|
||||||
int count) throws IOException, HttpException {
|
client.setConnectionTimeout(timeout);
|
||||||
GetMethod method = null;
|
method = new GetMethod(
|
||||||
try {
|
"http://www.crossref.org/openurl/");
|
||||||
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);
|
NameValuePair pid = new NameValuePair("pid", apiKey);
|
||||||
// Execute the method.
|
NameValuePair noredirect = new NameValuePair(
|
||||||
int statusCode = client.executeMethod(method);
|
"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) {
|
if (statusCode != HttpStatus.SC_OK)
|
||||||
throw new RuntimeException("Chiamata http fallita: "
|
{
|
||||||
+ method.getStatusLine());
|
throw new RuntimeException("Http call failed: "
|
||||||
}
|
+ method.getStatusLine());
|
||||||
|
}
|
||||||
|
|
||||||
Gson gson = new Gson();
|
Record crossitem;
|
||||||
Type listType = new TypeToken<ArrayList<Map>>(){}.getType();
|
try
|
||||||
List<Map> json = gson.fromJson(method.getResponseBodyAsString(),listType);
|
{
|
||||||
Set<String> dois = new HashSet<String>();
|
DocumentBuilderFactory factory = DocumentBuilderFactory
|
||||||
for (Map r : json) {
|
.newInstance();
|
||||||
dois.add(SubmissionLookupUtils.normalizeDOI((String) r.get("doi")));
|
factory.setValidating(false);
|
||||||
}
|
factory.setIgnoringComments(true);
|
||||||
method.releaseConnection();
|
factory.setIgnoringElementContentWhitespace(true);
|
||||||
|
|
||||||
return search(context, dois);
|
DocumentBuilder db = factory
|
||||||
} catch (Exception e) {
|
.newDocumentBuilder();
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
Document inDoc = db.parse(method
|
||||||
} finally {
|
.getResponseBodyAsStream());
|
||||||
if (method != null) {
|
|
||||||
method.releaseConnection();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,164 +29,189 @@ import org.w3c.dom.Element;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class CrossRefUtils {
|
public class CrossRefUtils
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public CrossRefUtils() {
|
public CrossRefUtils()
|
||||||
// TODO Auto-generated constructor stub
|
{
|
||||||
}
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
public static Record convertCrossRefDomToRecord(Element dataRoot) {
|
public static Record convertCrossRefDomToRecord(Element dataRoot)
|
||||||
MutableRecord record = new SubmissionLookupPublication("");
|
{
|
||||||
|
MutableRecord record = new SubmissionLookupPublication("");
|
||||||
|
|
||||||
String status = dataRoot.getAttribute("status");
|
String status = dataRoot.getAttribute("status");
|
||||||
if (!"resolved".equals(status)) {
|
if (!"resolved".equals(status))
|
||||||
String msg = XMLUtils.getElementValue(dataRoot, "msg");
|
{
|
||||||
String exMsg = status + " - " + msg;
|
String msg = XMLUtils.getElementValue(dataRoot, "msg");
|
||||||
throw new RuntimeException(exMsg);
|
String exMsg = status + " - " + msg;
|
||||||
}
|
throw new RuntimeException(exMsg);
|
||||||
|
}
|
||||||
|
|
||||||
String doi = XMLUtils.getElementValue(dataRoot, "doi");
|
String doi = XMLUtils.getElementValue(dataRoot, "doi");
|
||||||
if (doi != null)
|
if (doi != null)
|
||||||
record.addValue("doi", new StringValue(doi));
|
record.addValue("doi", new StringValue(doi));
|
||||||
|
|
||||||
String itemType = doi != null ? XMLUtils.getElementAttribute(dataRoot,
|
String itemType = doi != null ? XMLUtils.getElementAttribute(dataRoot,
|
||||||
"doi", "type") : "unspecified";
|
"doi", "type") : "unspecified";
|
||||||
if (itemType != null)
|
if (itemType != null)
|
||||||
record.addValue("itemType", new StringValue(itemType));
|
record.addValue("itemType", new StringValue(itemType));
|
||||||
|
|
||||||
List<Element> identifier = XMLUtils.getElementList(dataRoot, "issn");
|
List<Element> identifier = XMLUtils.getElementList(dataRoot, "issn");
|
||||||
for (Element ident : identifier) {
|
for (Element ident : identifier)
|
||||||
if ("print".equalsIgnoreCase(ident.getAttribute("type"))
|
{
|
||||||
|| StringUtils.isNotBlank(ident.getAttribute("type"))) {
|
if ("print".equalsIgnoreCase(ident.getAttribute("type"))
|
||||||
String issn = ident.getTextContent().trim();
|
|| StringUtils.isNotBlank(ident.getAttribute("type")))
|
||||||
if (issn != null)
|
{
|
||||||
record.addValue("issn", new StringValue(issn));
|
String issn = ident.getTextContent().trim();
|
||||||
} else {
|
if (issn != null)
|
||||||
String eissn = ident.getTextContent().trim();
|
record.addValue("issn", new StringValue(issn));
|
||||||
if (eissn != null)
|
}
|
||||||
record.addValue("eissn", new StringValue(eissn));
|
else
|
||||||
}
|
{
|
||||||
}
|
String eissn = ident.getTextContent().trim();
|
||||||
|
if (eissn != null)
|
||||||
|
record.addValue("eissn", new StringValue(eissn));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String isbn = XMLUtils.getElementValue(dataRoot, "isbn");
|
String isbn = XMLUtils.getElementValue(dataRoot, "isbn");
|
||||||
if (isbn != null)
|
if (isbn != null)
|
||||||
record.addValue("isbn", new StringValue(isbn));
|
record.addValue("isbn", new StringValue(isbn));
|
||||||
|
|
||||||
String editionNumber = XMLUtils.getElementValue(dataRoot,
|
String editionNumber = XMLUtils.getElementValue(dataRoot,
|
||||||
"editionNumber");
|
"editionNumber");
|
||||||
if (editionNumber != null)
|
if (editionNumber != null)
|
||||||
record.addValue("volume", new StringValue(editionNumber));
|
record.addValue("volume", new StringValue(editionNumber));
|
||||||
|
|
||||||
String volume = XMLUtils.getElementValue(dataRoot, "volume");
|
String volume = XMLUtils.getElementValue(dataRoot, "volume");
|
||||||
if (volume != null)
|
if (volume != null)
|
||||||
record.addValue("volume", new StringValue(volume));
|
record.addValue("volume", new StringValue(volume));
|
||||||
|
|
||||||
String issue = XMLUtils.getElementValue(dataRoot, "issue");
|
String issue = XMLUtils.getElementValue(dataRoot, "issue");
|
||||||
if (issue != null)
|
if (issue != null)
|
||||||
record.addValue("issue", new StringValue(issue));
|
record.addValue("issue", new StringValue(issue));
|
||||||
|
|
||||||
String year = XMLUtils.getElementValue(dataRoot, "year");
|
String year = XMLUtils.getElementValue(dataRoot, "year");
|
||||||
if (year != null)
|
if (year != null)
|
||||||
record.addValue("year", new StringValue(year));
|
record.addValue("year", new StringValue(year));
|
||||||
|
|
||||||
String firstPage = XMLUtils.getElementValue(dataRoot, "first_page");
|
String firstPage = XMLUtils.getElementValue(dataRoot, "first_page");
|
||||||
if (firstPage != null)
|
if (firstPage != null)
|
||||||
record.addValue("firstPage", new StringValue(firstPage));
|
record.addValue("firstPage", new StringValue(firstPage));
|
||||||
|
|
||||||
String lastPage = XMLUtils.getElementValue(dataRoot, "last_page");
|
String lastPage = XMLUtils.getElementValue(dataRoot, "last_page");
|
||||||
if (lastPage != null)
|
if (lastPage != null)
|
||||||
record.addValue("lastPage", new StringValue(lastPage));
|
record.addValue("lastPage", new StringValue(lastPage));
|
||||||
|
|
||||||
String seriesTitle = XMLUtils.getElementValue(dataRoot, "series_title");
|
String seriesTitle = XMLUtils.getElementValue(dataRoot, "series_title");
|
||||||
if (seriesTitle != null)
|
if (seriesTitle != null)
|
||||||
record.addValue("seriesTitle", new StringValue(seriesTitle));
|
record.addValue("seriesTitle", new StringValue(seriesTitle));
|
||||||
|
|
||||||
String journalTitle = XMLUtils.getElementValue(dataRoot,
|
String journalTitle = XMLUtils.getElementValue(dataRoot,
|
||||||
"journal_title");
|
"journal_title");
|
||||||
if (journalTitle != null)
|
if (journalTitle != null)
|
||||||
record.addValue("journalTitle", new StringValue(journalTitle));
|
record.addValue("journalTitle", new StringValue(journalTitle));
|
||||||
|
|
||||||
String volumeTitle = XMLUtils.getElementValue(dataRoot, "volume_title");
|
String volumeTitle = XMLUtils.getElementValue(dataRoot, "volume_title");
|
||||||
if (volumeTitle != null)
|
if (volumeTitle != null)
|
||||||
record.addValue("volumeTitle", new StringValue(volumeTitle));
|
record.addValue("volumeTitle", new StringValue(volumeTitle));
|
||||||
|
|
||||||
String articleTitle = XMLUtils.getElementValue(dataRoot,
|
String articleTitle = XMLUtils.getElementValue(dataRoot,
|
||||||
"article_title");
|
"article_title");
|
||||||
if (articleTitle != null)
|
if (articleTitle != null)
|
||||||
record.addValue("articleTitle", new StringValue(articleTitle));
|
record.addValue("articleTitle", new StringValue(articleTitle));
|
||||||
|
|
||||||
String publicationType = XMLUtils.getElementValue(dataRoot,
|
String publicationType = XMLUtils.getElementValue(dataRoot,
|
||||||
"pubblication_type");
|
"pubblication_type");
|
||||||
if (publicationType != null)
|
if (publicationType != null)
|
||||||
record.addValue("publicationType", new StringValue(publicationType));
|
record.addValue("publicationType", new StringValue(publicationType));
|
||||||
|
|
||||||
List<String[]> authors = new LinkedList<String[]>();
|
List<String[]> authors = new LinkedList<String[]>();
|
||||||
List<String[]> editors = new LinkedList<String[]>();
|
List<String[]> editors = new LinkedList<String[]>();
|
||||||
List<String[]> translators = new LinkedList<String[]>();
|
List<String[]> translators = new LinkedList<String[]>();
|
||||||
List<String[]> chairs = new LinkedList<String[]>();
|
List<String[]> chairs = new LinkedList<String[]>();
|
||||||
|
|
||||||
List<Element> contributors = XMLUtils.getElementList(dataRoot,
|
List<Element> contributors = XMLUtils.getElementList(dataRoot,
|
||||||
"contributors");
|
"contributors");
|
||||||
List<Element> contributor = null;
|
List<Element> contributor = null;
|
||||||
if (contributors != null && contributors.size() > 0) {
|
if (contributors != null && contributors.size() > 0)
|
||||||
contributor = XMLUtils.getElementList(contributors.get(0),
|
{
|
||||||
"contributor");
|
contributor = XMLUtils.getElementList(contributors.get(0),
|
||||||
|
"contributor");
|
||||||
|
|
||||||
for (Element contrib : contributor) {
|
for (Element contrib : contributor)
|
||||||
|
{
|
||||||
|
|
||||||
String givenName = XMLUtils.getElementValue(contrib,
|
String givenName = XMLUtils.getElementValue(contrib,
|
||||||
"given_name");
|
"given_name");
|
||||||
String surname = XMLUtils.getElementValue(contrib, "surname");
|
String surname = XMLUtils.getElementValue(contrib, "surname");
|
||||||
|
|
||||||
if ("editor".equalsIgnoreCase(contrib
|
if ("editor".equalsIgnoreCase(contrib
|
||||||
.getAttribute("contributor_role"))) {
|
.getAttribute("contributor_role")))
|
||||||
editors.add(new String[] { givenName, surname });
|
{
|
||||||
} else if ("chair".equalsIgnoreCase(contrib
|
editors.add(new String[] { givenName, surname });
|
||||||
.getAttribute("contributor_role"))) {
|
}
|
||||||
chairs.add(new String[] { givenName, surname });
|
else if ("chair".equalsIgnoreCase(contrib
|
||||||
} else if ("translator".equalsIgnoreCase(contrib
|
.getAttribute("contributor_role")))
|
||||||
.getAttribute("contributor_role"))) {
|
{
|
||||||
translators.add(new String[] { givenName, surname });
|
chairs.add(new String[] { givenName, surname });
|
||||||
} else {
|
}
|
||||||
authors.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) {
|
if (authors.size() > 0)
|
||||||
List<Value> values = new LinkedList<Value>();
|
{
|
||||||
for (String[] sArray : authors) {
|
List<Value> values = new LinkedList<Value>();
|
||||||
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
|
for (String[] sArray : authors)
|
||||||
}
|
{
|
||||||
record.addField("authors", values);
|
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
|
||||||
}
|
}
|
||||||
|
record.addField("authors", values);
|
||||||
|
}
|
||||||
|
|
||||||
if (editors.size() > 0) {
|
if (editors.size() > 0)
|
||||||
List<Value> values = new LinkedList<Value>();
|
{
|
||||||
for (String[] sArray : editors) {
|
List<Value> values = new LinkedList<Value>();
|
||||||
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
|
for (String[] sArray : editors)
|
||||||
}
|
{
|
||||||
record.addField("editors", values);
|
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
|
||||||
}
|
}
|
||||||
|
record.addField("editors", values);
|
||||||
|
}
|
||||||
|
|
||||||
if (translators.size() > 0) {
|
if (translators.size() > 0)
|
||||||
List<Value> values = new LinkedList<Value>();
|
{
|
||||||
for (String[] sArray : translators) {
|
List<Value> values = new LinkedList<Value>();
|
||||||
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
|
for (String[] sArray : translators)
|
||||||
}
|
{
|
||||||
record.addField("translators", values);
|
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
|
||||||
}
|
}
|
||||||
|
record.addField("translators", values);
|
||||||
|
}
|
||||||
|
|
||||||
if (chairs.size() > 0) {
|
if (chairs.size() > 0)
|
||||||
List<Value> values = new LinkedList<Value>();
|
{
|
||||||
for (String[] sArray : chairs) {
|
List<Value> values = new LinkedList<Value>();
|
||||||
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
|
for (String[] sArray : chairs)
|
||||||
}
|
{
|
||||||
record.addField("chairs", values);
|
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
|
||||||
}
|
}
|
||||||
return record;
|
record.addField("chairs", values);
|
||||||
}
|
}
|
||||||
|
return record;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -38,223 +38,292 @@ import org.dspace.content.WorkspaceItem;
|
|||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.submit.util.ItemSubmissionLookupDTO;
|
import org.dspace.submit.util.ItemSubmissionLookupDTO;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Bollini
|
* @author Andrea Bollini
|
||||||
* @author Kostas Stamatis
|
* @author Kostas Stamatis
|
||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class DSpaceWorkspaceItemOutputGenerator implements OutputGenerator {
|
public class DSpaceWorkspaceItemOutputGenerator implements OutputGenerator
|
||||||
|
{
|
||||||
private static Logger log = Logger.getLogger(DSpaceWorkspaceItemOutputGenerator.class);
|
|
||||||
|
private static Logger log = Logger
|
||||||
private Context context;
|
.getLogger(DSpaceWorkspaceItemOutputGenerator.class);
|
||||||
private String formName;
|
|
||||||
private List<WorkspaceItem> witems;
|
private Context context;
|
||||||
private ItemSubmissionLookupDTO dto;
|
|
||||||
private Collection collection;
|
private String formName;
|
||||||
Map<String, String> outputMap;
|
|
||||||
|
private List<WorkspaceItem> witems;
|
||||||
private List<String> extraMetadataToKeep;
|
|
||||||
|
private ItemSubmissionLookupDTO dto;
|
||||||
|
|
||||||
|
private Collection collection;
|
||||||
|
|
||||||
|
Map<String, String> outputMap;
|
||||||
|
|
||||||
|
private List<String> extraMetadataToKeep;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> generateOutput(RecordSet recordSet) {
|
public List<String> generateOutput(RecordSet recordSet)
|
||||||
|
{
|
||||||
log.info("BTE OutputGenerator started. Records to output: " + recordSet.getRecords().size());
|
|
||||||
|
log.info("BTE OutputGenerator started. Records to output: "
|
||||||
//Printing debug message
|
+ recordSet.getRecords().size());
|
||||||
String totalString = "";
|
|
||||||
for (Record record : recordSet.getRecords()){
|
// Printing debug message
|
||||||
totalString += SubmissionLookupUtils.getPrintableString(record)+"\n";
|
String totalString = "";
|
||||||
}
|
for (Record record : recordSet.getRecords())
|
||||||
log.debug("Records to output:\n"+totalString);
|
{
|
||||||
|
totalString += SubmissionLookupUtils.getPrintableString(record)
|
||||||
|
+ "\n";
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
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>();
|
return new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> generateOutput(RecordSet records, DataOutputSpec spec) {
|
public List<String> generateOutput(RecordSet records, DataOutputSpec spec)
|
||||||
|
{
|
||||||
return generateOutput(records);
|
return generateOutput(records);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<WorkspaceItem> getWitems() {
|
public List<WorkspaceItem> getWitems()
|
||||||
return witems;
|
{
|
||||||
}
|
return witems;
|
||||||
|
}
|
||||||
|
|
||||||
public void setContext(Context context) {
|
public void setContext(Context context)
|
||||||
this.context = context;
|
{
|
||||||
}
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
public void setFormName(String formName) {
|
public void setFormName(String formName)
|
||||||
this.formName = formName;
|
{
|
||||||
}
|
this.formName = formName;
|
||||||
|
}
|
||||||
public void setDto(ItemSubmissionLookupDTO dto) {
|
|
||||||
this.dto = dto;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOutputMap(Map<String, String> outputMap) {
|
public void setDto(ItemSubmissionLookupDTO dto)
|
||||||
//Reverse the key-value pairs
|
{
|
||||||
this.outputMap = new HashMap<String, String>();
|
this.dto = dto;
|
||||||
for (String key : outputMap.keySet()){
|
}
|
||||||
this.outputMap.put(outputMap.get(key), key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCollection(Collection collection) {
|
public void setOutputMap(Map<String, String> outputMap)
|
||||||
this.collection = collection;
|
{
|
||||||
}
|
// 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) {
|
public void setCollection(Collection collection)
|
||||||
this.extraMetadataToKeep = extraMetadataToKeep;
|
{
|
||||||
}
|
this.collection = collection;
|
||||||
|
}
|
||||||
|
|
||||||
//Methods
|
public void setExtraMetadataToKeep(List<String> extraMetadataToKeep)
|
||||||
public void merge(String formName, Item item, Record record) {
|
{
|
||||||
|
this.extraMetadataToKeep = extraMetadataToKeep;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
public void merge(String formName, Item item, Record record)
|
||||||
|
{
|
||||||
|
|
||||||
Record itemLookup = 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 {
|
Set<String> addedMetadata = new HashSet<String>();
|
||||||
item.update();
|
for (String field : itemLookup.getFields())
|
||||||
} catch (SQLException e) {
|
{
|
||||||
log.error(e.getMessage(), e);
|
String metadata = getMetadata(formName, itemLookup, field);
|
||||||
} catch (AuthorizeException e) {
|
if (StringUtils.isBlank(metadata))
|
||||||
log.error(e.getMessage(), e);
|
{
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
}
|
if (item.getMetadata(metadata).length == 0
|
||||||
|
|| addedMetadata.contains(metadata))
|
||||||
private String getMetadata(String formName,
|
{
|
||||||
Record itemLookup, String name) {
|
addedMetadata.add(metadata);
|
||||||
String type = SubmissionLookupService.getType(itemLookup);
|
String[] md = splitMetadata(metadata);
|
||||||
|
if (isValidMetadata(formName, md))
|
||||||
String md = outputMap.get(type + "." + name);
|
{ // if in extra metadata or in the spefific form
|
||||||
if (StringUtils.isBlank(md)){
|
List<Value> values = itemLookup.getValues(field);
|
||||||
md = outputMap.get(formName + "." + name);
|
if (values != null && values.size() > 0)
|
||||||
if (StringUtils.isBlank(md)){
|
{
|
||||||
md = outputMap.get(name);
|
if (isRepeatableMetadata(formName, md))
|
||||||
}
|
{ // if metadata is repeatable in form
|
||||||
}
|
for (Value value : values)
|
||||||
|
{
|
||||||
//KSTA:ToDo: Make this a modifier
|
String[] splitValue = splitValue(value
|
||||||
if (md != null && md.contains("|")) {
|
.getAsString());
|
||||||
String[] cond = md.trim().split("\\|");
|
if (splitValue[3] != null)
|
||||||
for (int idx = 1; idx < cond.length; idx++) {
|
{
|
||||||
boolean temp = itemLookup.getFields().contains(cond[idx]);
|
item.addMetadata(md[0], md[1], md[2],
|
||||||
if (temp) {
|
md[3], splitValue[0],
|
||||||
return null;
|
splitValue[1],
|
||||||
}
|
Integer.parseInt(splitValue[2]));
|
||||||
}
|
}
|
||||||
return cond[0];
|
else
|
||||||
}
|
{
|
||||||
return md;
|
item.addMetadata(md[0], md[1], md[2],
|
||||||
}
|
md[3], value.getAsString());
|
||||||
|
}
|
||||||
private String[] splitMetadata(String metadata) {
|
}
|
||||||
String[] mdSplit = new String[3];
|
}
|
||||||
if (StringUtils.isNotBlank(metadata)) {
|
else
|
||||||
String tmpSplit[] = metadata.split("\\.");
|
{
|
||||||
if (tmpSplit.length == 4) {
|
String value = values.iterator().next()
|
||||||
mdSplit = new String[4];
|
.getAsString();
|
||||||
mdSplit[0] = tmpSplit[0];
|
String[] splitValue = splitValue(value);
|
||||||
mdSplit[1] = tmpSplit[1];
|
if (splitValue[3] != null)
|
||||||
mdSplit[2] = tmpSplit[2];
|
{
|
||||||
mdSplit[3] = tmpSplit[3];
|
item.addMetadata(md[0], md[1], md[2], md[3],
|
||||||
} else if (tmpSplit.length == 3) {
|
splitValue[0], splitValue[1],
|
||||||
mdSplit = new String[4];
|
Integer.parseInt(splitValue[2]));
|
||||||
mdSplit[0] = tmpSplit[0];
|
}
|
||||||
mdSplit[1] = tmpSplit[1];
|
else
|
||||||
mdSplit[2] = tmpSplit[2];
|
{
|
||||||
mdSplit[3] = null;
|
item.addMetadata(md[0], md[1], md[2], md[3],
|
||||||
} else if (tmpSplit.length == 2) {
|
value);
|
||||||
mdSplit = new String[4];
|
}
|
||||||
mdSplit[0] = tmpSplit[0];
|
}
|
||||||
mdSplit[1] = tmpSplit[1];
|
}
|
||||||
mdSplit[2] = null;
|
}
|
||||||
mdSplit[3] = null;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return mdSplit;
|
try
|
||||||
}
|
{
|
||||||
|
item.update();
|
||||||
private boolean isValidMetadata(String formName, String[] md) {
|
}
|
||||||
try {
|
catch (SQLException e)
|
||||||
if (extraMetadataToKeep != null
|
{
|
||||||
&& extraMetadataToKeep.contains(StringUtils.join(
|
log.error(e.getMessage(), e);
|
||||||
Arrays.copyOfRange(md, 0, 3), "."))) {
|
}
|
||||||
return true;
|
catch (AuthorizeException e)
|
||||||
}
|
{
|
||||||
return getDCInput(formName, md[0], md[1], md[2])!=null;
|
log.error(e.getMessage(), e);
|
||||||
} catch (Exception e) {
|
}
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
private String getMetadata(String formName, Record itemLookup, String name)
|
||||||
|
{
|
||||||
private DCInput getDCInput(String formName, String schema,
|
String type = SubmissionLookupService.getType(itemLookup);
|
||||||
String element, String qualifier) throws DCInputsReaderException
|
|
||||||
|
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);
|
DCInputSet dcinputset = new DCInputsReader().getInputs(formName);
|
||||||
for (int idx = 0; idx < dcinputset.getNumberPages(); idx++)
|
for (int idx = 0; idx < dcinputset.getNumberPages(); idx++)
|
||||||
@@ -273,76 +342,98 @@ public class DSpaceWorkspaceItemOutputGenerator implements OutputGenerator {
|
|||||||
}
|
}
|
||||||
return null;
|
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) {
|
private boolean isRepeatableMetadata(String formName, String[] md)
|
||||||
String[] splitted = value.split(SubmissionLookupService.SEPARATOR_VALUE_REGEX);
|
{
|
||||||
String[] result = new String[6];
|
try
|
||||||
result[0] = splitted[0];
|
{
|
||||||
result[2] = "-1";
|
DCInput dcinput = getDCInput(formName, md[0], md[1], md[2]);
|
||||||
result[3] = "-1";
|
if (dcinput != null)
|
||||||
result[4] = "-1";
|
{
|
||||||
if (splitted.length > 1) {
|
return dcinput.isRepeatable();
|
||||||
result[5] = "splitted";
|
}
|
||||||
if (StringUtils.isNotBlank(splitted[1])) {
|
return true;
|
||||||
result[1] = splitted[1];
|
}
|
||||||
}
|
catch (Exception e)
|
||||||
if (splitted.length > 2) {
|
{
|
||||||
result[2] = String.valueOf(Integer.parseInt(splitted[2]));
|
e.printStackTrace();
|
||||||
if (splitted.length > 3) {
|
}
|
||||||
result[3] = String.valueOf(Integer.parseInt(splitted[3]));
|
return false;
|
||||||
if (splitted.length > 4) {
|
}
|
||||||
result[4] = String.valueOf(Integer
|
|
||||||
.parseInt(splitted[4]));
|
private String[] splitValue(String value)
|
||||||
}
|
{
|
||||||
}
|
String[] splitted = value
|
||||||
}
|
.split(SubmissionLookupService.SEPARATOR_VALUE_REGEX);
|
||||||
}
|
String[] result = new String[6];
|
||||||
return result;
|
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,
|
private void makeSureMetadataExist(Context context, String schema,
|
||||||
String element, String qualifier) {
|
String element, String qualifier)
|
||||||
try {
|
{
|
||||||
context.turnOffAuthorisationSystem();
|
try
|
||||||
boolean create = false;
|
{
|
||||||
MetadataSchema mdschema = MetadataSchema.find(context, schema);
|
context.turnOffAuthorisationSystem();
|
||||||
MetadataField mdfield = null;
|
boolean create = false;
|
||||||
if (mdschema == null) {
|
MetadataSchema mdschema = MetadataSchema.find(context, schema);
|
||||||
mdschema = new MetadataSchema(SubmissionLookupService.SL_NAMESPACE_PREFIX + schema,
|
MetadataField mdfield = null;
|
||||||
schema);
|
if (mdschema == null)
|
||||||
mdschema.create(context);
|
{
|
||||||
create = true;
|
mdschema = new MetadataSchema(
|
||||||
} else {
|
SubmissionLookupService.SL_NAMESPACE_PREFIX + schema,
|
||||||
mdfield = MetadataField.findByElement(context,
|
schema);
|
||||||
mdschema.getSchemaID(), element, qualifier);
|
mdschema.create(context);
|
||||||
}
|
create = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mdfield = MetadataField.findByElement(context,
|
||||||
|
mdschema.getSchemaID(), element, qualifier);
|
||||||
|
}
|
||||||
|
|
||||||
if (mdfield == null) {
|
if (mdfield == null)
|
||||||
mdfield = new MetadataField(mdschema, element, qualifier,
|
{
|
||||||
"Campo utilizzato per la cache del provider submission-lookup: "
|
mdfield = new MetadataField(mdschema, element, qualifier,
|
||||||
+ schema);
|
"Campo utilizzato per la cache del provider submission-lookup: "
|
||||||
mdfield.create(context);
|
+ schema);
|
||||||
create = true;
|
mdfield.create(context);
|
||||||
}
|
create = true;
|
||||||
if (create) {
|
}
|
||||||
context.commit();
|
if (create)
|
||||||
}
|
{
|
||||||
context.restoreAuthSystemState();
|
context.commit();
|
||||||
} catch (Exception e) {
|
}
|
||||||
e.printStackTrace();
|
context.restoreAuthSystemState();
|
||||||
}
|
}
|
||||||
}
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,43 +22,54 @@ import java.util.Map;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class FieldMergeModifier extends AbstractModifier {
|
public class FieldMergeModifier extends AbstractModifier
|
||||||
|
{
|
||||||
private Map<String, List<String>> mergeFieldMap;
|
private Map<String, List<String>> mergeFieldMap;
|
||||||
public FieldMergeModifier() {
|
|
||||||
|
public FieldMergeModifier()
|
||||||
|
{
|
||||||
super("FieldMergeModifier");
|
super("FieldMergeModifier");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Record modify(MutableRecord rec) {
|
public Record modify(MutableRecord rec)
|
||||||
if (mergeFieldMap!=null){
|
{
|
||||||
for (String target_field : mergeFieldMap.keySet()) {
|
if (mergeFieldMap != null)
|
||||||
List<String> source_fields = mergeFieldMap.get(target_field);
|
{
|
||||||
for (String source_field : source_fields) {
|
for (String target_field : mergeFieldMap.keySet())
|
||||||
List<Value> values = rec.getValues(source_field);
|
{
|
||||||
if (values != null && values.size() > 0) {
|
List<String> source_fields = mergeFieldMap.get(target_field);
|
||||||
for (Value value : values) {
|
for (String source_field : source_fields)
|
||||||
rec.addValue(target_field, value);
|
{
|
||||||
}
|
List<Value> values = rec.getValues(source_field);
|
||||||
}
|
if (values != null && values.size() > 0)
|
||||||
//rec.removeField(source_field);
|
{
|
||||||
}
|
for (Value value : values)
|
||||||
}
|
{
|
||||||
}
|
rec.addValue(target_field, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// rec.removeField(source_field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return rec;
|
return rec;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the merge_field_map
|
* @return the merge_field_map
|
||||||
*/
|
*/
|
||||||
public Map<String, List<String>> getMergeFieldMap() {
|
public Map<String, List<String>> getMergeFieldMap()
|
||||||
|
{
|
||||||
return mergeFieldMap;
|
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;
|
this.mergeFieldMap = merge_field_map;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,20 +16,30 @@ import java.util.List;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class LookupProvidersCheck {
|
public class LookupProvidersCheck
|
||||||
private List<String> providersOk = new ArrayList<String>();
|
{
|
||||||
private List<String> providersErr = new ArrayList<String>();
|
private List<String> providersOk = new ArrayList<String>();
|
||||||
public List<String> getProvidersOk() {
|
|
||||||
return providersOk;
|
private List<String> providersErr = new ArrayList<String>();
|
||||||
}
|
|
||||||
public void setProvidersOk(List<String> providersOk) {
|
public List<String> getProvidersOk()
|
||||||
this.providersOk = providersOk;
|
{
|
||||||
}
|
return providersOk;
|
||||||
public List<String> getProvidersErr() {
|
}
|
||||||
return providersErr;
|
|
||||||
}
|
public void setProvidersOk(List<String> providersOk)
|
||||||
public void setProvidersErr(List<String> providersErr) {
|
{
|
||||||
this.providersErr = providersErr;
|
this.providersOk = providersOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getProvidersErr()
|
||||||
|
{
|
||||||
|
return providersErr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProvidersErr(List<String> providersErr)
|
||||||
|
{
|
||||||
|
this.providersErr = providersErr;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -26,108 +26,126 @@ import gr.ekt.bte.core.Value;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class MapConverterModifier extends AbstractModifier {
|
public class MapConverterModifier extends AbstractModifier
|
||||||
|
{
|
||||||
|
|
||||||
String filename; //The properties filename
|
String filename; // The properties filename
|
||||||
Map<String, String> mapping;
|
|
||||||
String defaultValue = "";
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
/**
|
private Map<String, String> regexConfig = new HashMap<String, String>();
|
||||||
* @param name
|
|
||||||
*/
|
|
||||||
public MapConverterModifier(String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
public final String REGEX_PREFIX = "regex.";
|
||||||
* @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);
|
|
||||||
|
|
||||||
if (values==null) continue;
|
/**
|
||||||
|
* @param name
|
||||||
List<Value> newValues = new ArrayList<Value>();
|
*/
|
||||||
|
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 (values == null)
|
||||||
if (mapping.containsKey(stringValue))
|
continue;
|
||||||
{
|
|
||||||
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 ("@@ident@@".equals(tmp))
|
List<Value> newValues = new ArrayList<Value>();
|
||||||
{
|
|
||||||
newValues.add(new StringValue(stringValue));
|
|
||||||
}
|
|
||||||
else if (StringUtils.isNotBlank(tmp))
|
|
||||||
{
|
|
||||||
newValues.add(new StringValue(tmp));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
newValues.add(new StringValue(stringValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
if ("@@ident@@".equals(tmp))
|
||||||
this.mapping = mapping;
|
{
|
||||||
|
newValues.add(new StringValue(stringValue));
|
||||||
for (String keyS : mapping.keySet())
|
}
|
||||||
{
|
else if (StringUtils.isNotBlank(tmp))
|
||||||
if (keyS.startsWith(REGEX_PREFIX))
|
{
|
||||||
{
|
newValues.add(new StringValue(tmp));
|
||||||
String regex = keyS.substring(REGEX_PREFIX.length());
|
}
|
||||||
String regReplace = mapping.get(keyS);
|
else
|
||||||
if (regReplace == null)
|
newValues.add(new StringValue(stringValue));
|
||||||
{
|
}
|
||||||
regReplace = "";
|
|
||||||
}
|
|
||||||
else if (regReplace.equalsIgnoreCase("@ident@"))
|
|
||||||
{
|
|
||||||
regReplace = "$0";
|
|
||||||
}
|
|
||||||
regexConfig.put(regex,regReplace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFilename(String filename) {
|
record.updateField(key, newValues);
|
||||||
this.filename = filename;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFieldKeys(List<String> fieldKeys) {
|
return record;
|
||||||
this.fieldKeys = fieldKeys;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void setDefaultValue(String defaultValue) {
|
public void setMapping(Map<String, String> mapping)
|
||||||
this.defaultValue = defaultValue;
|
{
|
||||||
}
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,226 +31,304 @@ import gr.ekt.bte.exceptions.MalformedSourceException;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class MultipleSubmissionLookupDataLoader implements DataLoader {
|
public class MultipleSubmissionLookupDataLoader implements DataLoader
|
||||||
|
{
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(MultipleSubmissionLookupDataLoader.class);
|
private static Logger log = Logger
|
||||||
|
.getLogger(MultipleSubmissionLookupDataLoader.class);
|
||||||
private static final String NOT_FOUND_DOI = "NOT-FOUND-DOI";
|
|
||||||
|
|
||||||
|
|
||||||
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, DataLoader> dataloadersMap;
|
||||||
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() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
// Depending on these values, the multiple data loader loads data from the
|
||||||
* @see gr.ekt.bte.core.DataLoader#getRecords()
|
// appropriate providers
|
||||||
*/
|
Map<String, Set<String>> identifiers = null; // Searching by identifiers
|
||||||
@Override
|
// (DOI ...)
|
||||||
public RecordSet getRecords() throws MalformedSourceException {
|
|
||||||
|
|
||||||
RecordSet recordSet = new RecordSet();
|
Map<String, Set<String>> searchTerms = null; // Searching by author, title,
|
||||||
|
// date
|
||||||
|
|
||||||
//KSTA:ToDo: Support timeout (problematic) providers
|
String filename = null; // Uploading file
|
||||||
//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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Question: Do we want that in case of file data loader?
|
String type = null; // the type of the upload file (bibtex, etc.)
|
||||||
//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>();
|
|
||||||
|
|
||||||
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)
|
RecordSet recordSet = new RecordSet();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String providerName : dataloadersMap.keySet()) {
|
// KSTA:ToDo: Support timeout (problematic) providers
|
||||||
DataLoader genProvider = dataloadersMap.get(providerName);
|
// List<String> timeoutProviders = new ArrayList<String>();
|
||||||
|
for (String providerName : filterProviders().keySet())
|
||||||
if (! (genProvider instanceof SubmissionLookupDataLoader)){
|
{
|
||||||
continue;
|
DataLoader provider = dataloadersMap.get(providerName);
|
||||||
}
|
RecordSet subRecordSet = provider.getRecords();
|
||||||
|
recordSet.addAll(subRecordSet);
|
||||||
SubmissionLookupDataLoader provider = (SubmissionLookupDataLoader)genProvider;
|
// Add in each record the provider name... a new provider doesn't
|
||||||
|
// need to know about it!
|
||||||
//Provider must support DOI
|
for (Record record : subRecordSet.getRecords())
|
||||||
if (provider.getSupportedIdentifiers().contains(SubmissionLookupDataLoader.DOI)){
|
{
|
||||||
continue;
|
if (record.isMutable())
|
||||||
}
|
{
|
||||||
|
record.makeMutable().addValue(
|
||||||
//if (evictProviders != null
|
SubmissionLookupService.PROVIDER_NAME_FIELD,
|
||||||
// && evictProviders.contains(provider.getShortName())) {
|
new StringValue(providerName));
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Question: Do we want that in case of file data loader?
|
||||||
log.info("BTE DataLoader finished. Items loaded: " + recordSet.getRecords().size());
|
// for each publication in the record set, if it has a DOI, try to find
|
||||||
|
// extra pubs from the other providers
|
||||||
//Printing debug message
|
if (searchTerms != null
|
||||||
String totalString = "";
|
|| (identifiers != null && !identifiers
|
||||||
for (Record record : recordSet.getRecords()){
|
.containsKey(SubmissionLookupDataLoader.DOI)))
|
||||||
totalString += SubmissionLookupUtils.getPrintableString(record)+"\n";
|
{ // Extend
|
||||||
}
|
Map<String, Set<String>> provider2foundDOIs = new HashMap<String, Set<String>>();
|
||||||
log.debug("Records loaded:\n"+totalString);
|
List<String> foundDOIs = new ArrayList<String>();
|
||||||
|
|
||||||
return recordSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
for (Record publication : recordSet.getRecords())
|
||||||
* @see gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
|
{
|
||||||
*/
|
String providerName = SubmissionLookupUtils.getFirstValue(
|
||||||
@Override
|
publication,
|
||||||
public RecordSet getRecords(DataLoadingSpec loadingSpec)
|
SubmissionLookupService.PROVIDER_NAME_FIELD);
|
||||||
throws MalformedSourceException {
|
|
||||||
|
|
||||||
if (loadingSpec.getOffset()>0) //Identify the end of loading
|
String doi = null;
|
||||||
return new RecordSet();
|
|
||||||
|
|
||||||
return getRecords();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, DataLoader> getProvidersMap() {
|
if (publication.getValues(SubmissionLookupDataLoader.DOI) != null
|
||||||
return dataloadersMap;
|
&& 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) {
|
for (String providerName : dataloadersMap.keySet())
|
||||||
this.dataloadersMap = providersMap;
|
{
|
||||||
}
|
DataLoader genProvider = dataloadersMap.get(providerName);
|
||||||
|
|
||||||
public void setIdentifiers(Map<String, Set<String>> identifiers) {
|
if (!(genProvider instanceof SubmissionLookupDataLoader))
|
||||||
this.identifiers = identifiers;
|
{
|
||||||
this.filename = null;
|
continue;
|
||||||
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) {
|
SubmissionLookupDataLoader provider = (SubmissionLookupDataLoader) genProvider;
|
||||||
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) {
|
// Provider must support DOI
|
||||||
this.filename = filename;
|
if (provider.getSupportedIdentifiers().contains(
|
||||||
this.type = type;
|
SubmissionLookupDataLoader.DOI))
|
||||||
this.identifiers = null;
|
{
|
||||||
this.searchTerms = null;
|
continue;
|
||||||
|
}
|
||||||
if (dataloadersMap!=null){
|
|
||||||
for (String providerName : dataloadersMap.keySet()) {
|
// if (evictProviders != null
|
||||||
DataLoader provider = dataloadersMap.get(providerName);
|
// && evictProviders.contains(provider.getShortName())) {
|
||||||
if (provider instanceof FileDataLoader){
|
// continue;
|
||||||
((FileDataLoader)provider).setFilename(filename);
|
// }
|
||||||
}
|
Set<String> doiToSearch = new HashSet<String>();
|
||||||
}
|
Set<String> alreadyFoundDOIs = provider2foundDOIs
|
||||||
}
|
.get(providerName);
|
||||||
}
|
for (String doi : foundDOIs)
|
||||||
|
{
|
||||||
public Map<String, DataLoader> filterProviders(){
|
if (alreadyFoundDOIs == null
|
||||||
Map<String, DataLoader> result = new HashMap<String, DataLoader>();
|
|| !alreadyFoundDOIs.contains(doi))
|
||||||
for (String providerName : dataloadersMap.keySet()) {
|
{
|
||||||
DataLoader dataLoader = dataloadersMap.get(providerName);
|
doiToSearch.add(doi);
|
||||||
if (searchTerms != null && identifiers == null && filename == null){
|
}
|
||||||
if (dataLoader instanceof SubmissionLookupDataLoader &&
|
}
|
||||||
((SubmissionLookupDataLoader)dataLoader).isSearchProvider()){
|
List<Record> pPublications = null;
|
||||||
result.put(providerName, dataLoader);
|
try
|
||||||
}
|
{
|
||||||
}
|
if (doiToSearch.size() > 0)
|
||||||
else if (searchTerms == null && identifiers != null && filename == null){
|
{
|
||||||
if (dataLoader instanceof SubmissionLookupDataLoader){
|
pPublications = provider.getByDOIs(null, doiToSearch);
|
||||||
result.put(providerName, dataLoader);
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (Exception e)
|
||||||
else if (searchTerms == null && identifiers == null && filename != null){
|
{
|
||||||
if (dataLoader instanceof FileDataLoader){
|
e.printStackTrace();
|
||||||
if (providerName.endsWith(type)) //add only the one that we are interested in
|
}
|
||||||
result.put(providerName, dataLoader);
|
if (pPublications != null)
|
||||||
}
|
{
|
||||||
}
|
for (Record rec : pPublications)
|
||||||
}
|
{
|
||||||
|
recordSet.addRecord(rec);
|
||||||
return result;
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,121 +30,156 @@ import org.apache.commons.lang.StringUtils;
|
|||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.submit.util.SubmissionLookupPublication;
|
import org.dspace.submit.util.SubmissionLookupPublication;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Bollini
|
* @author Andrea Bollini
|
||||||
* @author Kostas Stamatis
|
* @author Kostas Stamatis
|
||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public abstract class NetworkSubmissionLookupDataLoader implements SubmissionLookupDataLoader {
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
//BTE Data Loader interface methods
|
Map<String, Set<String>> identifiers; // Searching by identifiers (DOI ...)
|
||||||
@Override
|
|
||||||
public RecordSet getRecords() throws MalformedSourceException {
|
|
||||||
|
|
||||||
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 {
|
String providerName;
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (results != null){
|
@Override
|
||||||
for (Record record : results){
|
public List<Record> getByDOIs(Context context, Set<String> doiToSearch)
|
||||||
recordSet.addRecord(record);
|
throws HttpException, IOException
|
||||||
}
|
{
|
||||||
}
|
|
||||||
|
|
||||||
return recordSet;
|
Map<String, Set<String>> keys = new HashMap<String, Set<String>>();
|
||||||
}
|
keys.put(DOI, doiToSearch);
|
||||||
|
|
||||||
@Override
|
return getByIdentifier(context, keys);
|
||||||
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) {
|
// BTE Data Loader interface methods
|
||||||
this.identifiers = identifiers;
|
@Override
|
||||||
}
|
public RecordSet getRecords() throws MalformedSourceException
|
||||||
|
{
|
||||||
|
|
||||||
public Map<String, Set<String>> getSearchTerms() {
|
RecordSet recordSet = new RecordSet();
|
||||||
return searchTerms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSearchTerms(Map<String, Set<String>> searchTerms) {
|
List<Record> results = null;
|
||||||
this.searchTerms = searchTerms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> getFieldMap() {
|
|
||||||
return fieldMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFieldMap(Map<String, String> fieldMap) {
|
try
|
||||||
this.fieldMap = fieldMap;
|
{
|
||||||
}
|
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) {
|
if (results != null)
|
||||||
this.providerName = providerName;
|
{
|
||||||
}
|
for (Record record : results)
|
||||||
|
{
|
||||||
public Record convertFields(Record publication) {
|
recordSet.addRecord(record);
|
||||||
for (String fieldName : fieldMap.keySet()) {
|
}
|
||||||
String md = null;
|
}
|
||||||
if (fieldMap!=null){
|
|
||||||
md = this.fieldMap.get(fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.isBlank(md)) {
|
return recordSet;
|
||||||
continue;
|
}
|
||||||
} else {
|
|
||||||
md = md.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (publication.isMutable()){
|
@Override
|
||||||
List<Value> values = publication.getValues(fieldName);
|
public RecordSet getRecords(DataLoadingSpec arg0)
|
||||||
publication.makeMutable().removeField(fieldName);
|
throws MalformedSourceException
|
||||||
publication.makeMutable().addField(md, values);
|
{
|
||||||
}
|
|
||||||
}
|
return getRecords();
|
||||||
|
}
|
||||||
return publication;
|
|
||||||
}
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,104 +39,136 @@ import org.xml.sax.SAXException;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @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
|
* @param filename
|
||||||
*/
|
*/
|
||||||
public PubmedFileDataLoader(String filename) {
|
public PubmedFileDataLoader(String filename)
|
||||||
super(filename);
|
{
|
||||||
}
|
super(filename);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
* @see gr.ekt.bte.core.DataLoader#getRecords()
|
* (non-Javadoc)
|
||||||
*/
|
*
|
||||||
@Override
|
* @see gr.ekt.bte.core.DataLoader#getRecords()
|
||||||
public RecordSet getRecords() throws MalformedSourceException {
|
*/
|
||||||
|
@Override
|
||||||
|
public RecordSet getRecords() throws MalformedSourceException
|
||||||
|
{
|
||||||
|
|
||||||
RecordSet recordSet = new RecordSet();
|
RecordSet recordSet = new RecordSet();
|
||||||
|
|
||||||
try {
|
try
|
||||||
InputStream inputStream = new FileInputStream(new File(filename));
|
{
|
||||||
|
InputStream inputStream = new FileInputStream(new File(filename));
|
||||||
|
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory factory = DocumentBuilderFactory
|
||||||
factory.setValidating(false);
|
.newInstance();
|
||||||
factory.setIgnoringComments(true);
|
factory.setValidating(false);
|
||||||
factory.setIgnoringElementContentWhitespace(true);
|
factory.setIgnoringComments(true);
|
||||||
|
factory.setIgnoringElementContentWhitespace(true);
|
||||||
|
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
Document inDoc = builder.parse(inputStream);
|
Document inDoc = builder.parse(inputStream);
|
||||||
|
|
||||||
Element xmlRoot = inDoc.getDocumentElement();
|
Element xmlRoot = inDoc.getDocumentElement();
|
||||||
List<Element> pubArticles = XMLUtils
|
List<Element> pubArticles = XMLUtils.getElementList(xmlRoot,
|
||||||
.getElementList(xmlRoot, "PubmedArticle");
|
"PubmedArticle");
|
||||||
|
|
||||||
for (Element xmlArticle : pubArticles)
|
for (Element xmlArticle : pubArticles)
|
||||||
{
|
{
|
||||||
Record record = null;
|
Record record = null;
|
||||||
try {
|
try
|
||||||
record = PubmedUtils.convertCrossRefDomToRecord(xmlArticle);
|
{
|
||||||
recordSet.addRecord(convertFields(record));
|
record = PubmedUtils.convertCrossRefDomToRecord(xmlArticle);
|
||||||
} catch (Exception e) {
|
recordSet.addRecord(convertFields(record));
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
}
|
||||||
}
|
catch (Exception e)
|
||||||
}
|
{
|
||||||
} catch (FileNotFoundException e) {
|
throw new RuntimeException(e.getMessage(), e);
|
||||||
e.printStackTrace();
|
}
|
||||||
} catch (ParserConfigurationException e) {
|
}
|
||||||
e.printStackTrace();
|
}
|
||||||
} catch (SAXException e) {
|
catch (FileNotFoundException e)
|
||||||
e.printStackTrace();
|
{
|
||||||
} catch (IOException e) {
|
e.printStackTrace();
|
||||||
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)
|
* (non-Javadoc)
|
||||||
*/
|
*
|
||||||
@Override
|
* @see
|
||||||
public RecordSet getRecords(DataLoadingSpec spec)
|
* gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
|
||||||
throws MalformedSourceException {
|
*/
|
||||||
|
@Override
|
||||||
|
public RecordSet getRecords(DataLoadingSpec spec)
|
||||||
|
throws MalformedSourceException
|
||||||
|
{
|
||||||
|
|
||||||
return getRecords();
|
return getRecords();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Record convertFields(Record publication) {
|
public Record convertFields(Record publication)
|
||||||
for (String fieldName : fieldMap.keySet()) {
|
{
|
||||||
String md = null;
|
for (String fieldName : fieldMap.keySet())
|
||||||
if (fieldMap!=null){
|
{
|
||||||
md = this.fieldMap.get(fieldName);
|
String md = null;
|
||||||
}
|
if (fieldMap != null)
|
||||||
|
{
|
||||||
|
md = this.fieldMap.get(fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
if (StringUtils.isBlank(md)) {
|
if (StringUtils.isBlank(md))
|
||||||
continue;
|
{
|
||||||
} else {
|
continue;
|
||||||
md = md.trim();
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
md = md.trim();
|
||||||
|
}
|
||||||
|
|
||||||
if (publication.isMutable()){
|
if (publication.isMutable())
|
||||||
List<Value> values = publication.getValues(fieldName);
|
{
|
||||||
publication.makeMutable().removeField(fieldName);
|
List<Value> values = publication.getValues(fieldName);
|
||||||
publication.makeMutable().addField(md, values);
|
publication.makeMutable().removeField(fieldName);
|
||||||
}
|
publication.makeMutable().addField(md, values);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return publication;
|
return publication;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFieldMap(Map<String, String> fieldMap) {
|
public void setFieldMap(Map<String, String> fieldMap)
|
||||||
this.fieldMap = fieldMap;
|
{
|
||||||
}
|
this.fieldMap = fieldMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,91 +27,113 @@ import org.dspace.core.LogManager;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class PubmedOnlineDataLoader extends NetworkSubmissionLookupDataLoader {
|
public class PubmedOnlineDataLoader extends NetworkSubmissionLookupDataLoader
|
||||||
|
{
|
||||||
private boolean searchProvider = true;
|
private boolean searchProvider = true;
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(PubmedOnlineDataLoader.class);
|
private static Logger log = Logger.getLogger(PubmedOnlineDataLoader.class);
|
||||||
|
|
||||||
private PubmedService pubmedService = new PubmedService();
|
private PubmedService pubmedService = new PubmedService();
|
||||||
|
|
||||||
public void setPubmedService(PubmedService pubmedService) {
|
|
||||||
this.pubmedService = pubmedService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public void setPubmedService(PubmedService pubmedService)
|
||||||
public List<String> getSupportedIdentifiers() {
|
{
|
||||||
return Arrays.asList(new String[] { PUBMED, DOI });
|
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;
|
this.searchProvider = searchProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSearchProvider() {
|
|
||||||
return searchProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Record> getByIdentifier(Context context,
|
public boolean isSearchProvider()
|
||||||
Map<String, Set<String>> keys) throws HttpException, IOException {
|
{
|
||||||
Set<String> pmids = keys != null ? keys.get(PUBMED) : null;
|
return searchProvider;
|
||||||
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]");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Record> pubmedResults = pubmedService.search(query.toString());
|
@Override
|
||||||
for (Record p : pubmedResults) {
|
public List<Record> getByIdentifier(Context context,
|
||||||
results.add(convertFields(p));
|
Map<String, Set<String>> keys) throws HttpException, IOException
|
||||||
}
|
{
|
||||||
}
|
Set<String> pmids = keys != null ? keys.get(PUBMED) : null;
|
||||||
else if (dois != null && dois.size()>0 && pmids != null && pmids.size()>0)
|
Set<String> dois = keys != null ? keys.get(DOI) : null;
|
||||||
{
|
List<Record> results = new ArrayList<Record>();
|
||||||
//EKT:ToDo: support list of dois and pmids in the search method of pubmedService
|
if (pmids != null && pmids.size() > 0
|
||||||
List<Record> pubmedResults = pubmedService.search(dois.iterator().next(), pmids.iterator().next());
|
&& (dois == null || dois.size() == 0))
|
||||||
if (pubmedResults != null) {
|
{
|
||||||
for (Record p : pubmedResults) {
|
for (String pmid : pmids)
|
||||||
results.add(convertFields(p));
|
{
|
||||||
}
|
Record p = null;
|
||||||
}
|
try
|
||||||
}
|
{
|
||||||
|
p = pubmedService.getByPubmedID(pmid);
|
||||||
return results;
|
}
|
||||||
}
|
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
|
List<Record> pubmedResults = pubmedService.search(query.toString());
|
||||||
public List<Record> search(Context context, String title,
|
for (Record p : pubmedResults)
|
||||||
String author, int year) throws HttpException, IOException {
|
{
|
||||||
List<Record> pubmedResults = pubmedService.search(title, author,
|
results.add(convertFields(p));
|
||||||
year);
|
}
|
||||||
List<Record> results = new ArrayList<Record>();
|
}
|
||||||
if (pubmedResults != null) {
|
else if (dois != null && dois.size() > 0 && pmids != null
|
||||||
for (Record p : pubmedResults) {
|
&& pmids.size() > 0)
|
||||||
results.add(convertFields(p));
|
{
|
||||||
}
|
// EKT:ToDo: support list of dois and pmids in the search method of
|
||||||
}
|
// pubmedService
|
||||||
return results;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,256 +39,315 @@ import org.xml.sax.SAXException;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class PubmedService {
|
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 List<Record> search(String title, String author, int year)
|
private static Logger log = Logger.getLogger(PubmedService.class);
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Record> search(String query) throws IOException,
|
private int timeout = 1000;
|
||||||
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");
|
|
||||||
|
|
||||||
NameValuePair db = new NameValuePair("db", "pubmed");
|
public void setTimeout(int timeout)
|
||||||
NameValuePair datetype = new NameValuePair("datetype", "edat");
|
{
|
||||||
NameValuePair retmax = new NameValuePair("retmax", "10");
|
this.timeout = timeout;
|
||||||
NameValuePair queryParam = new NameValuePair("term",
|
}
|
||||||
query.toString());
|
|
||||||
method.setQueryString(new NameValuePair[] { db, queryParam,
|
|
||||||
retmax, datetype });
|
|
||||||
// Execute the method.
|
|
||||||
int statusCode = client.executeMethod(method);
|
|
||||||
|
|
||||||
if (statusCode != HttpStatus.SC_OK) {
|
public Record getByPubmedID(String pubmedid) throws HttpException,
|
||||||
throw new RuntimeException(
|
IOException, ParserConfigurationException, SAXException
|
||||||
"WS call failed: "
|
{
|
||||||
+ method.getStatusLine());
|
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
|
public List<Record> search(String title, String author, int year)
|
||||||
.newInstance();
|
throws HttpException, IOException
|
||||||
factory.setValidating(false);
|
{
|
||||||
factory.setIgnoringComments(true);
|
StringBuffer query = new StringBuffer();
|
||||||
factory.setIgnoringElementContentWhitespace(true);
|
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;
|
public List<Record> search(String query) throws IOException, HttpException
|
||||||
try {
|
{
|
||||||
builder = factory.newDocumentBuilder();
|
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
|
NameValuePair db = new NameValuePair("db", "pubmed");
|
||||||
.getResponseBodyAsStream());
|
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();
|
if (statusCode != HttpStatus.SC_OK)
|
||||||
Element idList = XMLUtils.getSingleElement(xmlRoot,
|
{
|
||||||
"IdList");
|
throw new RuntimeException("WS call failed: "
|
||||||
List<String> pubmedIDs = XMLUtils.getElementValueList(
|
+ method.getStatusLine());
|
||||||
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);
|
|
||||||
|
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
DocumentBuilderFactory factory = DocumentBuilderFactory
|
||||||
Document inDoc = builder.parse(stream);
|
.newInstance();
|
||||||
|
factory.setValidating(false);
|
||||||
|
factory.setIgnoringComments(true);
|
||||||
|
factory.setIgnoringElementContentWhitespace(true);
|
||||||
|
|
||||||
Element xmlRoot = inDoc.getDocumentElement();
|
DocumentBuilder builder;
|
||||||
Element idList = XMLUtils.getSingleElement(xmlRoot, "IdList");
|
try
|
||||||
List<String> pubmedIDs = XMLUtils.getElementValueList(idList,
|
{
|
||||||
"Id");
|
builder = factory.newDocumentBuilder();
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Record> getByPubmedIDs(List<String> pubmedIDs)
|
Document inDoc = builder.parse(method
|
||||||
throws HttpException, IOException, ParserConfigurationException, SAXException {
|
.getResponseBodyAsStream());
|
||||||
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");
|
|
||||||
|
|
||||||
NameValuePair db = new NameValuePair("db", "pubmed");
|
Element xmlRoot = inDoc.getDocumentElement();
|
||||||
NameValuePair retmode = new NameValuePair("retmode", "xml");
|
Element idList = XMLUtils.getSingleElement(xmlRoot,
|
||||||
NameValuePair rettype = new NameValuePair("rettype", "full");
|
"IdList");
|
||||||
NameValuePair id = new NameValuePair("id", StringUtils.join(pubmedIDs.iterator(), ","));
|
List<String> pubmedIDs = XMLUtils.getElementValueList(
|
||||||
method.setQueryString(new NameValuePair[] { db, retmode,
|
idList, "Id");
|
||||||
rettype, id });
|
results = getByPubmedIDs(pubmedIDs);
|
||||||
// Execute the method.
|
}
|
||||||
int statusCode = client.executeMethod(method);
|
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) {
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
throw new RuntimeException(
|
Document inDoc = builder.parse(stream);
|
||||||
"WS call failed: "
|
|
||||||
+ method.getStatusLine());
|
|
||||||
}
|
|
||||||
|
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
Element xmlRoot = inDoc.getDocumentElement();
|
||||||
factory.setValidating(false);
|
Element idList = XMLUtils.getSingleElement(xmlRoot, "IdList");
|
||||||
factory.setIgnoringComments(true);
|
List<String> pubmedIDs = XMLUtils.getElementValueList(idList,
|
||||||
factory.setIgnoringElementContentWhitespace(true);
|
"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();
|
public List<Record> getByPubmedIDs(List<String> pubmedIDs)
|
||||||
Document inDoc = builder.parse(method.getResponseBodyAsStream());
|
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();
|
NameValuePair db = new NameValuePair("db", "pubmed");
|
||||||
List<Element> pubArticles = XMLUtils
|
NameValuePair retmode = new NameValuePair("retmode", "xml");
|
||||||
.getElementList(xmlRoot, "PubmedArticle");
|
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)
|
if (statusCode != HttpStatus.SC_OK)
|
||||||
{
|
{
|
||||||
Record pubmedItem = null;
|
throw new RuntimeException("WS call failed: "
|
||||||
try {
|
+ method.getStatusLine());
|
||||||
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;
|
DocumentBuilderFactory factory = DocumentBuilderFactory
|
||||||
} finally {
|
.newInstance();
|
||||||
if (method != null) {
|
factory.setValidating(false);
|
||||||
method.releaseConnection();
|
factory.setIgnoringComments(true);
|
||||||
}
|
factory.setIgnoringElementContentWhitespace(true);
|
||||||
}
|
|
||||||
} 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();
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
factory.setValidating(false);
|
Document inDoc = builder
|
||||||
factory.setIgnoringComments(true);
|
.parse(method.getResponseBodyAsStream());
|
||||||
factory.setIgnoringElementContentWhitespace(true);
|
|
||||||
|
|
||||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
Element xmlRoot = inDoc.getDocumentElement();
|
||||||
Document inDoc = builder.parse(stream);
|
List<Element> pubArticles = XMLUtils.getElementList(xmlRoot,
|
||||||
|
"PubmedArticle");
|
||||||
|
|
||||||
Element xmlRoot = inDoc.getDocumentElement();
|
for (Element xmlArticle : pubArticles)
|
||||||
List<Element> pubArticles = XMLUtils
|
{
|
||||||
.getElementList(xmlRoot, "PubmedArticle");
|
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)
|
return results;
|
||||||
{
|
}
|
||||||
Record pubmedItem = null;
|
finally
|
||||||
try {
|
{
|
||||||
pubmedItem = PubmedUtils.convertCrossRefDomToRecord(xmlArticle);
|
if (method != null)
|
||||||
results.add(pubmedItem);
|
{
|
||||||
} catch (Exception e) {
|
method.releaseConnection();
|
||||||
throw new RuntimeException(
|
}
|
||||||
"PubmedID is not valid or not exist: "+e.getMessage(), e);
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
InputStream stream = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file = new File(
|
||||||
|
ConfigurationManager.getProperty("dspace.dir")
|
||||||
|
+ "/config/crosswalks/demo/pubmed.xml");
|
||||||
|
stream = new FileInputStream(file);
|
||||||
|
|
||||||
return results;
|
DocumentBuilderFactory factory = DocumentBuilderFactory
|
||||||
} catch (Exception e) {
|
.newInstance();
|
||||||
throw new RuntimeException(e.getMessage(), e);
|
factory.setValidating(false);
|
||||||
} finally {
|
factory.setIgnoringComments(true);
|
||||||
if (stream != null) {
|
factory.setIgnoringElementContentWhitespace(true);
|
||||||
stream.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Record> search(String doi, String pmid) throws HttpException, IOException {
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
StringBuffer query = new StringBuffer();
|
Document inDoc = builder.parse(stream);
|
||||||
if (StringUtils.isNotBlank(doi)) {
|
|
||||||
query.append(doi);
|
Element xmlRoot = inDoc.getDocumentElement();
|
||||||
query.append("[AID]");
|
List<Element> pubArticles = XMLUtils.getElementList(xmlRoot,
|
||||||
}
|
"PubmedArticle");
|
||||||
if (StringUtils.isNotBlank(pmid)) {
|
|
||||||
// [FAU]
|
for (Element xmlArticle : pubArticles)
|
||||||
if (query.length() > 0)
|
{
|
||||||
query.append(" OR ");
|
Record pubmedItem = null;
|
||||||
query.append(pmid).append("[PMID]");
|
try
|
||||||
}
|
{
|
||||||
return search(query.toString());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,12 +31,14 @@ import org.w3c.dom.Element;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class PubmedUtils {
|
public class PubmedUtils
|
||||||
|
{
|
||||||
|
|
||||||
public static Record convertCrossRefDomToRecord(Element pubArticle){
|
public static Record convertCrossRefDomToRecord(Element pubArticle)
|
||||||
MutableRecord record = new SubmissionLookupPublication("");
|
{
|
||||||
|
MutableRecord record = new SubmissionLookupPublication("");
|
||||||
Map<String, String> mounthToNum = new HashMap<String, String>();
|
|
||||||
|
Map<String, String> mounthToNum = new HashMap<String, String>();
|
||||||
mounthToNum.put("Jan", "01");
|
mounthToNum.put("Jan", "01");
|
||||||
mounthToNum.put("Feb", "02");
|
mounthToNum.put("Feb", "02");
|
||||||
mounthToNum.put("Mar", "03");
|
mounthToNum.put("Mar", "03");
|
||||||
@@ -49,16 +51,19 @@ public class PubmedUtils {
|
|||||||
mounthToNum.put("Oct", "10");
|
mounthToNum.put("Oct", "10");
|
||||||
mounthToNum.put("Nov", "11");
|
mounthToNum.put("Nov", "11");
|
||||||
mounthToNum.put("Dec", "12");
|
mounthToNum.put("Dec", "12");
|
||||||
|
|
||||||
Element medline = XMLUtils.getSingleElement(pubArticle, "MedlineCitation");
|
Element medline = XMLUtils.getSingleElement(pubArticle,
|
||||||
|
"MedlineCitation");
|
||||||
|
|
||||||
Element article = XMLUtils.getSingleElement(medline, "Article");
|
Element article = XMLUtils.getSingleElement(medline, "Article");
|
||||||
Element pubmed = XMLUtils.getSingleElement(pubArticle, "PubmedData");
|
Element pubmed = XMLUtils.getSingleElement(pubArticle, "PubmedData");
|
||||||
|
|
||||||
Element identifierList = XMLUtils.getSingleElement(pubmed, "ArticleIdList");
|
Element identifierList = XMLUtils.getSingleElement(pubmed,
|
||||||
|
"ArticleIdList");
|
||||||
if (identifierList != null)
|
if (identifierList != null)
|
||||||
{
|
{
|
||||||
List<Element> identifiers = XMLUtils.getElementList(identifierList, "ArticleId");
|
List<Element> identifiers = XMLUtils.getElementList(identifierList,
|
||||||
|
"ArticleId");
|
||||||
if (identifiers != null)
|
if (identifiers != null)
|
||||||
{
|
{
|
||||||
for (Element id : identifiers)
|
for (Element id : identifiers)
|
||||||
@@ -66,67 +71,79 @@ public class PubmedUtils {
|
|||||||
if ("pubmed".equals(id.getAttribute("IdType")))
|
if ("pubmed".equals(id.getAttribute("IdType")))
|
||||||
{
|
{
|
||||||
String pubmedID = id.getTextContent().trim();
|
String pubmedID = id.getTextContent().trim();
|
||||||
if (pubmedID!=null)
|
if (pubmedID != null)
|
||||||
record.addValue("pubmedID", new StringValue(pubmedID));
|
record.addValue("pubmedID", new StringValue(
|
||||||
|
pubmedID));
|
||||||
}
|
}
|
||||||
else if ("doi".equals(id.getAttribute("IdType")))
|
else if ("doi".equals(id.getAttribute("IdType")))
|
||||||
{
|
{
|
||||||
String doi = id.getTextContent().trim();
|
String doi = id.getTextContent().trim();
|
||||||
if (doi!=null)
|
if (doi != null)
|
||||||
record.addValue("doi", new StringValue(doi));
|
record.addValue("doi", new StringValue(doi));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String status = XMLUtils.getElementValue(pubmed, "PublicationStatus");
|
String status = XMLUtils.getElementValue(pubmed, "PublicationStatus");
|
||||||
if (status!=null)
|
if (status != null)
|
||||||
record.addValue("status", new StringValue(status));
|
record.addValue("status", new StringValue(status));
|
||||||
|
|
||||||
String pubblicationModel = XMLUtils.getElementAttribute(medline, "Article", "PubModel");
|
String pubblicationModel = XMLUtils.getElementAttribute(medline,
|
||||||
if (pubblicationModel!=null)
|
"Article", "PubModel");
|
||||||
record.addValue("pubblicationModel", new StringValue(pubblicationModel));
|
if (pubblicationModel != null)
|
||||||
|
record.addValue("pubblicationModel", new StringValue(
|
||||||
|
pubblicationModel));
|
||||||
|
|
||||||
String title = XMLUtils.getElementValue(article, "ArticleTitle");
|
String title = XMLUtils.getElementValue(article, "ArticleTitle");
|
||||||
if (title!=null)
|
if (title != null)
|
||||||
record.addValue("title", new StringValue(title));
|
record.addValue("title", new StringValue(title));
|
||||||
|
|
||||||
Element abstractElement = XMLUtils.getSingleElement(medline, "Abstract");
|
Element abstractElement = XMLUtils
|
||||||
|
.getSingleElement(medline, "Abstract");
|
||||||
if (abstractElement == null)
|
if (abstractElement == null)
|
||||||
{
|
{
|
||||||
abstractElement = XMLUtils.getSingleElement(medline, "OtherAbstract");
|
abstractElement = XMLUtils.getSingleElement(medline,
|
||||||
|
"OtherAbstract");
|
||||||
}
|
}
|
||||||
if (abstractElement != null)
|
if (abstractElement != null)
|
||||||
{
|
{
|
||||||
String summary = XMLUtils.getElementValue(abstractElement, "AbstractText");
|
String summary = XMLUtils.getElementValue(abstractElement,
|
||||||
if (summary!=null)
|
"AbstractText");
|
||||||
record.addValue("summary", new StringValue(summary));
|
if (summary != null)
|
||||||
|
record.addValue("summary", new StringValue(summary));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String[]> authors = new LinkedList<String[]>();
|
List<String[]> authors = new LinkedList<String[]>();
|
||||||
Element authorList = XMLUtils.getSingleElement(article, "AuthorList");
|
Element authorList = XMLUtils.getSingleElement(article, "AuthorList");
|
||||||
if (authorList != null)
|
if (authorList != null)
|
||||||
{
|
{
|
||||||
List<Element> authorsElement = XMLUtils.getElementList(authorList, "Author");
|
List<Element> authorsElement = XMLUtils.getElementList(authorList,
|
||||||
|
"Author");
|
||||||
if (authorsElement != null)
|
if (authorsElement != null)
|
||||||
{
|
{
|
||||||
for (Element author : authorsElement)
|
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){
|
if (authors.size() > 0)
|
||||||
List<Value> values = new LinkedList<Value>();
|
{
|
||||||
for (String[] sArray : authors){
|
List<Value> values = new LinkedList<Value>();
|
||||||
values.add(new StringValue(sArray[1]+", "+sArray[0]));
|
for (String[] sArray : authors)
|
||||||
}
|
{
|
||||||
record.addField("authors", values);
|
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
|
||||||
}
|
}
|
||||||
|
record.addField("authors", values);
|
||||||
|
}
|
||||||
|
|
||||||
Element journal = XMLUtils.getSingleElement(article, "Journal");
|
Element journal = XMLUtils.getSingleElement(article, "Journal");
|
||||||
if (journal != null)
|
if (journal != null)
|
||||||
{
|
{
|
||||||
@@ -138,43 +155,50 @@ public class PubmedUtils {
|
|||||||
if ("Print".equals(jnumber.getAttribute("IssnType")))
|
if ("Print".equals(jnumber.getAttribute("IssnType")))
|
||||||
{
|
{
|
||||||
String issn = jnumber.getTextContent().trim();
|
String issn = jnumber.getTextContent().trim();
|
||||||
if (issn!=null)
|
if (issn != null)
|
||||||
record.addValue("issn", new StringValue(issn));
|
record.addValue("issn", new StringValue(issn));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String eissn = jnumber.getTextContent().trim();
|
String eissn = jnumber.getTextContent().trim();
|
||||||
if (eissn!=null)
|
if (eissn != null)
|
||||||
record.addValue("eissn", new StringValue(eissn));
|
record.addValue("eissn", new StringValue(eissn));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String journalTitle = XMLUtils.getElementValue(journal, "Title");
|
String journalTitle = XMLUtils.getElementValue(journal, "Title");
|
||||||
if (journalTitle!=null)
|
if (journalTitle != null)
|
||||||
record.addValue("journalTitle", new StringValue(journalTitle));
|
record.addValue("journalTitle", new StringValue(journalTitle));
|
||||||
|
|
||||||
Element journalIssueElement = XMLUtils.getSingleElement(journal, "JournalIssue");
|
Element journalIssueElement = XMLUtils.getSingleElement(journal,
|
||||||
|
"JournalIssue");
|
||||||
if (journalIssueElement != null)
|
if (journalIssueElement != null)
|
||||||
{
|
{
|
||||||
String volume = XMLUtils.getElementValue(journalIssueElement, "Volume");
|
String volume = XMLUtils.getElementValue(journalIssueElement,
|
||||||
if (volume!=null)
|
"Volume");
|
||||||
record.addValue("volume", new StringValue(volume));
|
if (volume != null)
|
||||||
|
record.addValue("volume", new StringValue(volume));
|
||||||
String issue = XMLUtils.getElementValue(journalIssueElement, "Issue");
|
|
||||||
if (issue!=null)
|
String issue = XMLUtils.getElementValue(journalIssueElement,
|
||||||
record.addValue("issue", new StringValue(issue));
|
"Issue");
|
||||||
|
if (issue != null)
|
||||||
Element pubDataElement = XMLUtils.getSingleElement(journalIssueElement, "PubDate");
|
record.addValue("issue", new StringValue(issue));
|
||||||
|
|
||||||
|
Element pubDataElement = XMLUtils.getSingleElement(
|
||||||
|
journalIssueElement, "PubDate");
|
||||||
|
|
||||||
String year = null;
|
String year = null;
|
||||||
if (pubDataElement != null)
|
if (pubDataElement != null)
|
||||||
{
|
{
|
||||||
year = XMLUtils.getElementValue(pubDataElement, "Year");
|
year = XMLUtils.getElementValue(pubDataElement, "Year");
|
||||||
|
|
||||||
String mounth = XMLUtils.getElementValue(pubDataElement, "Month");
|
String mounth = XMLUtils.getElementValue(pubDataElement,
|
||||||
String day = XMLUtils.getElementValue(pubDataElement, "Day");
|
"Month");
|
||||||
if (StringUtils.isNotBlank(mounth) && mounthToNum.containsKey(mounth))
|
String day = XMLUtils
|
||||||
|
.getElementValue(pubDataElement, "Day");
|
||||||
|
if (StringUtils.isNotBlank(mounth)
|
||||||
|
&& mounthToNum.containsKey(mounth))
|
||||||
{
|
{
|
||||||
year += "-" + mounthToNum.get(mounth);
|
year += "-" + mounthToNum.get(mounth);
|
||||||
if (StringUtils.isNotBlank(day))
|
if (StringUtils.isNotBlank(day))
|
||||||
@@ -183,38 +207,44 @@ public class PubmedUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (year!=null)
|
if (year != null)
|
||||||
record.addValue("year", new StringValue(year));
|
record.addValue("year", new StringValue(year));
|
||||||
}
|
}
|
||||||
|
|
||||||
String language = XMLUtils.getElementValue(article, "Language");
|
String language = XMLUtils.getElementValue(article, "Language");
|
||||||
if (language!=null)
|
if (language != null)
|
||||||
record.addValue("language", new StringValue(language));
|
record.addValue("language", new StringValue(language));
|
||||||
|
|
||||||
List<String> type = new LinkedList<String>();
|
List<String> type = new LinkedList<String>();
|
||||||
Element publicationTypeList = XMLUtils.getSingleElement(article, "PublicationTypeList");
|
Element publicationTypeList = XMLUtils.getSingleElement(article,
|
||||||
|
"PublicationTypeList");
|
||||||
if (publicationTypeList != null)
|
if (publicationTypeList != null)
|
||||||
{
|
{
|
||||||
List<Element> publicationTypes = XMLUtils.getElementList(publicationTypeList, "PublicationType");
|
List<Element> publicationTypes = XMLUtils.getElementList(
|
||||||
|
publicationTypeList, "PublicationType");
|
||||||
for (Element publicationType : publicationTypes)
|
for (Element publicationType : publicationTypes)
|
||||||
{
|
{
|
||||||
type.add(publicationType.getTextContent().trim());
|
type.add(publicationType.getTextContent().trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type.size()>0){
|
if (type.size() > 0)
|
||||||
List<Value> values = new LinkedList<Value>();
|
{
|
||||||
for (String s : type){
|
List<Value> values = new LinkedList<Value>();
|
||||||
values.add(new StringValue(s));
|
for (String s : type)
|
||||||
}
|
{
|
||||||
record.addField("type", values);
|
values.add(new StringValue(s));
|
||||||
}
|
}
|
||||||
|
record.addField("type", values);
|
||||||
|
}
|
||||||
|
|
||||||
List<String> primaryKeywords = new LinkedList<String>();
|
List<String> primaryKeywords = new LinkedList<String>();
|
||||||
List<String> secondaryKeywords = new LinkedList<String>();
|
List<String> secondaryKeywords = new LinkedList<String>();
|
||||||
Element keywordsList = XMLUtils.getSingleElement(medline, "KeywordList");
|
Element keywordsList = XMLUtils.getSingleElement(medline,
|
||||||
|
"KeywordList");
|
||||||
if (keywordsList != null)
|
if (keywordsList != null)
|
||||||
{
|
{
|
||||||
List<Element> keywords = XMLUtils.getElementList(keywordsList, "Keyword");
|
List<Element> keywords = XMLUtils.getElementList(keywordsList,
|
||||||
|
"Keyword");
|
||||||
for (Element keyword : keywords)
|
for (Element keyword : keywords)
|
||||||
{
|
{
|
||||||
if ("Y".equals(keyword.getAttribute("MajorTopicYN")))
|
if ("Y".equals(keyword.getAttribute("MajorTopicYN")))
|
||||||
@@ -227,71 +257,88 @@ public class PubmedUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (primaryKeywords.size()>0){
|
if (primaryKeywords.size() > 0)
|
||||||
List<Value> values = new LinkedList<Value>();
|
{
|
||||||
for (String s : primaryKeywords){
|
List<Value> values = new LinkedList<Value>();
|
||||||
values.add(new StringValue(s));
|
for (String s : primaryKeywords)
|
||||||
}
|
{
|
||||||
record.addField("primaryKeywords", values);
|
values.add(new StringValue(s));
|
||||||
}
|
}
|
||||||
if (secondaryKeywords.size()>0){
|
record.addField("primaryKeywords", values);
|
||||||
List<Value> values = new LinkedList<Value>();
|
}
|
||||||
for (String s : secondaryKeywords){
|
if (secondaryKeywords.size() > 0)
|
||||||
values.add(new StringValue(s));
|
{
|
||||||
}
|
List<Value> values = new LinkedList<Value>();
|
||||||
record.addField("secondaryKeywords", values);
|
for (String s : secondaryKeywords)
|
||||||
}
|
{
|
||||||
|
values.add(new StringValue(s));
|
||||||
|
}
|
||||||
|
record.addField("secondaryKeywords", values);
|
||||||
|
}
|
||||||
|
|
||||||
List<String> primaryMeshHeadings = new LinkedList<String>();
|
List<String> primaryMeshHeadings = new LinkedList<String>();
|
||||||
List<String> secondaryMeshHeadings = new LinkedList<String>();
|
List<String> secondaryMeshHeadings = new LinkedList<String>();
|
||||||
Element meshHeadingsList = XMLUtils.getSingleElement(medline, "MeshHeadingList");
|
Element meshHeadingsList = XMLUtils.getSingleElement(medline,
|
||||||
|
"MeshHeadingList");
|
||||||
if (meshHeadingsList != null)
|
if (meshHeadingsList != null)
|
||||||
{
|
{
|
||||||
List<Element> meshHeadings = XMLUtils.getElementList(meshHeadingsList, "MeshHeading");
|
List<Element> meshHeadings = XMLUtils.getElementList(
|
||||||
|
meshHeadingsList, "MeshHeading");
|
||||||
for (Element meshHeading : meshHeadings)
|
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
|
else
|
||||||
{
|
{
|
||||||
secondaryMeshHeadings.add(XMLUtils.getElementValue(meshHeading, "DescriptorName"));
|
secondaryMeshHeadings.add(XMLUtils.getElementValue(
|
||||||
|
meshHeading, "DescriptorName"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (primaryMeshHeadings.size()>0){
|
if (primaryMeshHeadings.size() > 0)
|
||||||
List<Value> values = new LinkedList<Value>();
|
{
|
||||||
for (String s : primaryMeshHeadings){
|
List<Value> values = new LinkedList<Value>();
|
||||||
values.add(new StringValue(s));
|
for (String s : primaryMeshHeadings)
|
||||||
}
|
{
|
||||||
record.addField("primaryMeshHeadings", values);
|
values.add(new StringValue(s));
|
||||||
}
|
}
|
||||||
if (secondaryMeshHeadings.size()>0){
|
record.addField("primaryMeshHeadings", values);
|
||||||
List<Value> values = new LinkedList<Value>();
|
}
|
||||||
for (String s : secondaryMeshHeadings){
|
if (secondaryMeshHeadings.size() > 0)
|
||||||
values.add(new StringValue(s));
|
{
|
||||||
}
|
List<Value> values = new LinkedList<Value>();
|
||||||
record.addField("secondaryMeshHeadings", values);
|
for (String s : secondaryMeshHeadings)
|
||||||
}
|
{
|
||||||
|
values.add(new StringValue(s));
|
||||||
Element paginationElement = XMLUtils.getSingleElement(article, "Pagination");
|
}
|
||||||
|
record.addField("secondaryMeshHeadings", values);
|
||||||
|
}
|
||||||
|
|
||||||
|
Element paginationElement = XMLUtils.getSingleElement(article,
|
||||||
|
"Pagination");
|
||||||
if (paginationElement != null)
|
if (paginationElement != null)
|
||||||
{
|
{
|
||||||
String startPage = XMLUtils.getElementValue(paginationElement, "StartPage");
|
String startPage = XMLUtils.getElementValue(paginationElement,
|
||||||
String endPage = XMLUtils.getElementValue(paginationElement, "EndPage");
|
"StartPage");
|
||||||
|
String endPage = XMLUtils.getElementValue(paginationElement,
|
||||||
|
"EndPage");
|
||||||
if (StringUtils.isBlank(startPage))
|
if (StringUtils.isBlank(startPage))
|
||||||
{
|
{
|
||||||
startPage = XMLUtils.getElementValue(paginationElement, "MedlinePgn");
|
startPage = XMLUtils.getElementValue(paginationElement,
|
||||||
|
"MedlinePgn");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startPage!=null)
|
if (startPage != null)
|
||||||
record.addValue("startPage", new StringValue(startPage));
|
record.addValue("startPage", new StringValue(startPage));
|
||||||
if (endPage!=null)
|
if (endPage != null)
|
||||||
record.addValue("endPage", new StringValue(endPage));
|
record.addValue("endPage", new StringValue(endPage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,50 +25,63 @@ import gr.ekt.bte.core.Value;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class RemoveLastDotModifier extends AbstractModifier {
|
public class RemoveLastDotModifier extends AbstractModifier
|
||||||
|
{
|
||||||
|
|
||||||
List<String> fieldKeys;
|
List<String> fieldKeys;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
public RemoveLastDotModifier(String name) {
|
public RemoveLastDotModifier(String name)
|
||||||
super(name);
|
{
|
||||||
}
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
* @see gr.ekt.bte.core.AbstractModifier#modify(gr.ekt.bte.core.MutableRecord)
|
* (non-Javadoc)
|
||||||
*/
|
*
|
||||||
@Override
|
* @see
|
||||||
public Record modify(MutableRecord record) {
|
* gr.ekt.bte.core.AbstractModifier#modify(gr.ekt.bte.core.MutableRecord)
|
||||||
if (fieldKeys != null) {
|
*/
|
||||||
for (String key : fieldKeys){
|
@Override
|
||||||
List<Value> values = record.getValues(key);
|
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){
|
if (values != null)
|
||||||
for (Value value : values){
|
{
|
||||||
String valueString = value.getAsString();
|
for (Value value : values)
|
||||||
if (StringUtils.isNotBlank(valueString) && valueString.endsWith("."))
|
{
|
||||||
{
|
String valueString = value.getAsString();
|
||||||
newValues.add(new StringValue(valueString.substring(0, valueString.length() - 1)));
|
if (StringUtils.isNotBlank(valueString)
|
||||||
}
|
&& valueString.endsWith("."))
|
||||||
else
|
{
|
||||||
{
|
newValues.add(new StringValue(valueString
|
||||||
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) {
|
public void setFieldKeys(List<String> fieldKeys)
|
||||||
this.fieldKeys = fieldKeys;
|
{
|
||||||
}
|
this.fieldKeys = fieldKeys;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,51 +19,63 @@ import java.util.List;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.submit.util.ItemSubmissionLookupDTO;
|
import org.dspace.submit.util.ItemSubmissionLookupDTO;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Bollini
|
* @author Andrea Bollini
|
||||||
* @author Kostas Stamatis
|
* @author Kostas Stamatis
|
||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class SubmissionItemDataLoader implements DataLoader {
|
public class SubmissionItemDataLoader implements DataLoader
|
||||||
|
{
|
||||||
private List<ItemSubmissionLookupDTO> dtoList;
|
private List<ItemSubmissionLookupDTO> dtoList;
|
||||||
|
|
||||||
List<DataLoader> providers;
|
List<DataLoader> providers;
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(SubmissionItemDataLoader.class);
|
private static Logger log = Logger
|
||||||
|
.getLogger(SubmissionItemDataLoader.class);
|
||||||
public SubmissionItemDataLoader() {
|
|
||||||
|
public SubmissionItemDataLoader()
|
||||||
|
{
|
||||||
dtoList = null;
|
dtoList = null;
|
||||||
providers = null;
|
providers = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RecordSet getRecords() throws MalformedSourceException {
|
public RecordSet getRecords() throws MalformedSourceException
|
||||||
if (dtoList == null) {
|
{
|
||||||
|
if (dtoList == null)
|
||||||
|
{
|
||||||
throw new MalformedSourceException("dtoList not initialized");
|
throw new MalformedSourceException("dtoList not initialized");
|
||||||
}
|
}
|
||||||
RecordSet ret = new RecordSet();
|
RecordSet ret = new RecordSet();
|
||||||
|
|
||||||
for (ItemSubmissionLookupDTO dto : dtoList) {
|
for (ItemSubmissionLookupDTO dto : dtoList)
|
||||||
|
{
|
||||||
Record rec = dto.getTotalPublication(providers);
|
Record rec = dto.getTotalPublication(providers);
|
||||||
ret.addRecord(rec);
|
ret.addRecord(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("BTE DataLoader finished. Items loaded: " + ret.getRecords().size());
|
log.info("BTE DataLoader finished. Items loaded: "
|
||||||
|
+ ret.getRecords().size());
|
||||||
//Printing debug message
|
|
||||||
String totalString = "";
|
// Printing debug message
|
||||||
for (Record record : ret.getRecords()){
|
String totalString = "";
|
||||||
totalString += SubmissionLookupUtils.getPrintableString(record)+"\n";
|
for (Record record : ret.getRecords())
|
||||||
}
|
{
|
||||||
log.debug("Records loaded:\n"+totalString);
|
totalString += SubmissionLookupUtils.getPrintableString(record)
|
||||||
|
+ "\n";
|
||||||
|
}
|
||||||
|
log.debug("Records loaded:\n" + totalString);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RecordSet getRecords(DataLoadingSpec spec) throws MalformedSourceException {
|
public RecordSet getRecords(DataLoadingSpec spec)
|
||||||
if(spec.getOffset() > 0) {
|
throws MalformedSourceException
|
||||||
|
{
|
||||||
|
if (spec.getOffset() > 0)
|
||||||
|
{
|
||||||
return new RecordSet();
|
return new RecordSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,28 +85,34 @@ public class SubmissionItemDataLoader implements DataLoader {
|
|||||||
/**
|
/**
|
||||||
* @return the dtoList
|
* @return the dtoList
|
||||||
*/
|
*/
|
||||||
public List<ItemSubmissionLookupDTO> getDtoList() {
|
public List<ItemSubmissionLookupDTO> getDtoList()
|
||||||
|
{
|
||||||
return dtoList;
|
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;
|
this.dtoList = dtoList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the providers
|
* @return the providers
|
||||||
*/
|
*/
|
||||||
public List<DataLoader> getProviders() {
|
public List<DataLoader> getProviders()
|
||||||
|
{
|
||||||
return providers;
|
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;
|
this.providers = providers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,32 +18,38 @@ import org.dspace.core.Context;
|
|||||||
import gr.ekt.bte.core.DataLoader;
|
import gr.ekt.bte.core.DataLoader;
|
||||||
import gr.ekt.bte.core.Record;
|
import gr.ekt.bte.core.Record;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Bollini
|
* @author Andrea Bollini
|
||||||
* @author Kostas Stamatis
|
* @author Kostas Stamatis
|
||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public interface SubmissionLookupDataLoader extends DataLoader {
|
public interface SubmissionLookupDataLoader extends DataLoader
|
||||||
|
{
|
||||||
|
|
||||||
public final static String DOI = "doi";
|
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";
|
|
||||||
|
|
||||||
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,
|
public final static String REPEC = "repec";
|
||||||
int year) throws HttpException, IOException;
|
|
||||||
|
|
||||||
List<Record> getByIdentifier(Context context, Map<String, Set<String>> keys)
|
public final static String SCOPUSEID = "scopuseid";
|
||||||
throws HttpException, IOException;
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -20,73 +20,88 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.dspace.submit.util.ItemSubmissionLookupDTO;
|
import org.dspace.submit.util.ItemSubmissionLookupDTO;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrea Bollini
|
* @author Andrea Bollini
|
||||||
* @author Kostas Stamatis
|
* @author Kostas Stamatis
|
||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class SubmissionLookupOutputGenerator implements OutputGenerator {
|
public class SubmissionLookupOutputGenerator implements OutputGenerator
|
||||||
|
{
|
||||||
private List<ItemSubmissionLookupDTO> dtoList;
|
private List<ItemSubmissionLookupDTO> dtoList;
|
||||||
|
|
||||||
private static final String DOI_FIELD = "doi";
|
private static final String DOI_FIELD = "doi";
|
||||||
|
|
||||||
private static final String NOT_FOUND_DOI = "NOT-FOUND-DOI";
|
private static final String NOT_FOUND_DOI = "NOT-FOUND-DOI";
|
||||||
|
|
||||||
public SubmissionLookupOutputGenerator() {
|
public SubmissionLookupOutputGenerator()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> generateOutput(RecordSet records) {
|
public List<String> generateOutput(RecordSet records)
|
||||||
dtoList = new ArrayList<ItemSubmissionLookupDTO>();
|
{
|
||||||
|
dtoList = new ArrayList<ItemSubmissionLookupDTO>();
|
||||||
|
|
||||||
Map<String, List<Record>> record_sets = new HashMap<String, List<Record>>();
|
Map<String, List<Record>> record_sets = new HashMap<String, List<Record>>();
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for(Record rec : records) {
|
for (Record rec : records)
|
||||||
|
{
|
||||||
String current_doi = NOT_FOUND_DOI;
|
String current_doi = NOT_FOUND_DOI;
|
||||||
List<Value> values = rec.getValues(DOI_FIELD);
|
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();
|
current_doi = values.get(0).getAsString();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
current_doi = NOT_FOUND_DOI + "_" + counter;
|
{
|
||||||
|
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);
|
record_sets.get(current_doi).add(rec);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
ArrayList<Record> publication = new ArrayList<Record>();
|
ArrayList<Record> publication = new ArrayList<Record>();
|
||||||
publication.add(rec);
|
publication.add(rec);
|
||||||
record_sets.put(current_doi, publication);
|
record_sets.put(current_doi, publication);
|
||||||
}
|
}
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
for(Map.Entry<String, List<Record>> entry : record_sets.entrySet()) {
|
for (Map.Entry<String, List<Record>> entry : record_sets.entrySet())
|
||||||
ItemSubmissionLookupDTO dto = new ItemSubmissionLookupDTO(entry.getValue());
|
{
|
||||||
|
ItemSubmissionLookupDTO dto = new ItemSubmissionLookupDTO(
|
||||||
|
entry.getValue());
|
||||||
dtoList.add(dto);
|
dtoList.add(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> generateOutput(RecordSet records, DataOutputSpec spec) {
|
public List<String> generateOutput(RecordSet records, DataOutputSpec spec)
|
||||||
|
{
|
||||||
return generateOutput(records);
|
return generateOutput(records);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the items
|
* @return the items
|
||||||
*/
|
*/
|
||||||
public List<ItemSubmissionLookupDTO> getDtoList() {
|
public List<ItemSubmissionLookupDTO> getDtoList()
|
||||||
|
{
|
||||||
return dtoList;
|
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;
|
this.dtoList = items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,151 +28,187 @@ import org.dspace.submit.util.SubmissionLookupDTO;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @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";
|
public static final String PROVIDER_NAME_FIELD = "provider_name_field";
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(SubmissionLookupService.class);
|
|
||||||
|
|
||||||
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 Map<String, List<String>> idents2provs;
|
||||||
private List<String> fileProviders;
|
|
||||||
|
|
||||||
private TransformationEngine phase1TransformationEngine;
|
private List<String> searchProviders;
|
||||||
private TransformationEngine phase2TransformationEngine;
|
|
||||||
|
|
||||||
|
private List<String> fileProviders;
|
||||||
|
|
||||||
public void setPhase2TransformationEngine(TransformationEngine phase2TransformationEngine) {
|
private TransformationEngine phase1TransformationEngine;
|
||||||
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>();
|
|
||||||
|
|
||||||
if (providers == null) {
|
private TransformationEngine phase2TransformationEngine;
|
||||||
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);
|
public void setPhase2TransformationEngine(
|
||||||
|
TransformationEngine phase2TransformationEngine)
|
||||||
if (p2.isSearchProvider()) {
|
{
|
||||||
searchProviders.add(providerName);
|
this.phase2TransformationEngine = phase2TransformationEngine;
|
||||||
}
|
|
||||||
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 static String getType(Record rec) {
|
public void setPhase1TransformationEngine(
|
||||||
return SubmissionLookupUtils.getFirstValue(rec, SubmissionLookupDataLoader.TYPE);
|
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() {
|
public TransformationEngine getPhase1TransformationEngine()
|
||||||
return this.fileProviders;
|
{
|
||||||
}
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,118 +28,135 @@ import org.dspace.core.Context;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class SubmissionLookupUtils {
|
public class SubmissionLookupUtils
|
||||||
private static Logger log = Logger.getLogger(SubmissionLookupUtils.class);
|
{
|
||||||
|
private static Logger log = Logger.getLogger(SubmissionLookupUtils.class);
|
||||||
|
|
||||||
/** Location of config file */
|
/** Location of config file */
|
||||||
private static final String configFilePath = ConfigurationManager
|
private static final String configFilePath = ConfigurationManager
|
||||||
.getProperty("dspace.dir")
|
.getProperty("dspace.dir")
|
||||||
+ File.separator
|
+ File.separator
|
||||||
+ "config"
|
+ "config"
|
||||||
+ File.separator + "crosswalks" + File.separator;
|
+ File.separator + "crosswalks" + File.separator;
|
||||||
|
|
||||||
// Patter to extract the converter name if any
|
// Patter to extract the converter name if any
|
||||||
private static final Pattern converterPattern = Pattern
|
private static final Pattern converterPattern = Pattern
|
||||||
.compile(".*\\((.*)\\)");
|
.compile(".*\\((.*)\\)");
|
||||||
|
|
||||||
public static LookupProvidersCheck getProvidersCheck(Context context,
|
public static LookupProvidersCheck getProvidersCheck(Context context,
|
||||||
Item item, String dcSchema, String dcElement, String dcQualifier) {
|
Item item, String dcSchema, String dcElement, String dcQualifier)
|
||||||
try {
|
{
|
||||||
LookupProvidersCheck check = new LookupProvidersCheck();
|
try
|
||||||
MetadataSchema[] schemas = MetadataSchema.findAll(context);
|
{
|
||||||
DCValue[] values = item.getMetadata(dcSchema, dcElement, dcQualifier, Item.ANY);
|
LookupProvidersCheck check = new LookupProvidersCheck();
|
||||||
|
MetadataSchema[] schemas = MetadataSchema.findAll(context);
|
||||||
for (MetadataSchema schema : schemas)
|
DCValue[] values = item.getMetadata(dcSchema, dcElement,
|
||||||
{
|
dcQualifier, Item.ANY);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
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 (slCache.length != values.length)
|
||||||
if (doi != null)
|
{
|
||||||
{
|
error = true;
|
||||||
return doi.trim().replaceAll("^http://dx.doi.org/", "")
|
}
|
||||||
.replaceAll("^doi:", "");
|
else
|
||||||
}
|
{
|
||||||
return null;
|
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) {
|
public static String normalizeDOI(String doi)
|
||||||
List<String> result = new ArrayList<String>();
|
{
|
||||||
List<Value> values = rec.getValues(field);
|
if (doi != null)
|
||||||
if (values != null && values.size() > 0) {
|
{
|
||||||
for (Value value : values){
|
return doi.trim().replaceAll("^http://dx.doi.org/", "")
|
||||||
result.add( value.getAsString());
|
.replaceAll("^doi:", "");
|
||||||
}
|
}
|
||||||
}
|
return null;
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getPrintableString(Record record){
|
}
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
|
public static String getFirstValue(Record rec, String field)
|
||||||
result.append("\nPublication {\n");
|
{
|
||||||
|
List<Value> values = rec.getValues(field);
|
||||||
for (String field: record.getFields()){
|
String value = null;
|
||||||
result.append("--"+field + ":\n");
|
if (values != null && values.size() > 0)
|
||||||
List<Value> values = record.getValues(field);
|
{
|
||||||
for (Value value : values){
|
value = values.get(0).getAsString();
|
||||||
result.append("\t"+value.getAsString()+"\n");
|
}
|
||||||
}
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.append("}\n");
|
public static List<String> getValues(Record rec, String field)
|
||||||
|
{
|
||||||
return result.toString();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,25 +26,33 @@ import org.apache.commons.lang.StringUtils;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class ValueConcatenationModifier extends AbstractModifier {
|
public class ValueConcatenationModifier extends AbstractModifier
|
||||||
|
{
|
||||||
private String field;
|
private String field;
|
||||||
|
|
||||||
private String separator = ",";
|
private String separator = ",";
|
||||||
|
|
||||||
private boolean whitespaceAfter = true;
|
private boolean whitespaceAfter = true;
|
||||||
|
|
||||||
public ValueConcatenationModifier() {
|
public ValueConcatenationModifier()
|
||||||
|
{
|
||||||
super("ValueConcatenationModifier");
|
super("ValueConcatenationModifier");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Record modify(MutableRecord rec) {
|
public Record modify(MutableRecord rec)
|
||||||
|
{
|
||||||
List<Value> values = rec.getValues(field);
|
List<Value> values = rec.getValues(field);
|
||||||
if(values != null) {
|
if (values != null)
|
||||||
|
{
|
||||||
List<String> converted_values = new ArrayList<String>();
|
List<String> converted_values = new ArrayList<String>();
|
||||||
for (Value val : values) {
|
for (Value val : values)
|
||||||
|
{
|
||||||
converted_values.add(val.getAsString());
|
converted_values.add(val.getAsString());
|
||||||
}
|
}
|
||||||
List<Value> final_value = new ArrayList<Value>();
|
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));
|
final_value.add(new StringValue(v));
|
||||||
rec.updateField(field, final_value);
|
rec.updateField(field, final_value);
|
||||||
}
|
}
|
||||||
@@ -55,42 +63,51 @@ public class ValueConcatenationModifier extends AbstractModifier {
|
|||||||
/**
|
/**
|
||||||
* @return the field
|
* @return the field
|
||||||
*/
|
*/
|
||||||
public String getField() {
|
public String getField()
|
||||||
|
{
|
||||||
return field;
|
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;
|
this.field = field;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the separator
|
* @return the separator
|
||||||
*/
|
*/
|
||||||
public String getSeparator() {
|
public String getSeparator()
|
||||||
|
{
|
||||||
return separator;
|
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;
|
this.separator = separator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the whiteSpaceAfter
|
* @return the whiteSpaceAfter
|
||||||
*/
|
*/
|
||||||
public boolean isWhitespaceAfter() {
|
public boolean isWhitespaceAfter()
|
||||||
|
{
|
||||||
return whitespaceAfter;
|
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;
|
this.whitespaceAfter = whiteSpaceAfter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.submit.step;
|
package org.dspace.submit.step;
|
||||||
|
|
||||||
import edu.emory.mathcs.backport.java.util.Arrays;
|
|
||||||
import gr.ekt.bte.core.Record;
|
import gr.ekt.bte.core.Record;
|
||||||
import gr.ekt.bte.core.TransformationEngine;
|
import gr.ekt.bte.core.TransformationEngine;
|
||||||
import gr.ekt.bte.core.TransformationSpec;
|
import gr.ekt.bte.core.TransformationSpec;
|
||||||
@@ -26,7 +25,6 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.poi.hwpf.model.Ffn;
|
|
||||||
import org.dspace.app.util.DCInputSet;
|
import org.dspace.app.util.DCInputSet;
|
||||||
import org.dspace.app.util.DCInputsReader;
|
import org.dspace.app.util.DCInputsReader;
|
||||||
import org.dspace.app.util.SubmissionInfo;
|
import org.dspace.app.util.SubmissionInfo;
|
||||||
@@ -45,19 +43,23 @@ import org.dspace.submit.util.SubmissionLookupPublication;
|
|||||||
import org.dspace.utils.DSpace;
|
import org.dspace.utils.DSpace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SelectCollection Step which processes the collection that the user selected
|
* StartSubmissionLookupStep is used when you want enabled the user to auto fill
|
||||||
* in that step of the DSpace Submission process
|
* the item in submission with metadata retrieved from external bibliographic
|
||||||
* <P>
|
* services (like pubmed, arxiv, and so on...)
|
||||||
* This class performs all the behind-the-scenes processing that
|
*
|
||||||
* this particular step requires. This class's methods are utilized
|
* <p>
|
||||||
* by both the JSP-UI and the Manakin XML-UI
|
* At the moment this step is only available for JSPUI
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @see org.dspace.app.util.SubmissionConfig
|
* @see org.dspace.app.util.SubmissionConfig
|
||||||
* @see org.dspace.app.util.SubmissionStepConfig
|
* @see org.dspace.app.util.SubmissionStepConfig
|
||||||
* @see org.dspace.submit.AbstractProcessingStep
|
* @see org.dspace.submit.AbstractProcessingStep
|
||||||
*
|
*
|
||||||
* @author Tim Donohue
|
* @author Andrea Bollini
|
||||||
* @version $Revision: 3738 $
|
* @author Kostas Stamatis
|
||||||
|
* @author Luigi Andrea Pascarelli
|
||||||
|
* @author Panagiotis Koutsourakis
|
||||||
|
* @version $Revision$
|
||||||
*/
|
*/
|
||||||
public class StartSubmissionLookupStep extends AbstractProcessingStep
|
public class StartSubmissionLookupStep extends AbstractProcessingStep
|
||||||
{
|
{
|
||||||
@@ -73,18 +75,19 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
|
|||||||
|
|
||||||
// invalid collection or error finding collection
|
// invalid collection or error finding collection
|
||||||
public static final int STATUS_INVALID_COLLECTION = 2;
|
public static final int STATUS_INVALID_COLLECTION = 2;
|
||||||
|
|
||||||
public static final int STATUS_NO_SUUID = 3;
|
public static final int STATUS_NO_SUUID = 3;
|
||||||
|
|
||||||
public static final int STATUS_SUBMISSION_EXPIRED = 4;
|
public static final int STATUS_SUBMISSION_EXPIRED = 4;
|
||||||
|
|
||||||
private SubmissionLookupService slService = new DSpace()
|
private SubmissionLookupService slService = new DSpace()
|
||||||
.getServiceManager().getServiceByName(
|
.getServiceManager().getServiceByName(
|
||||||
SubmissionLookupService.class.getCanonicalName(),
|
SubmissionLookupService.class.getCanonicalName(),
|
||||||
SubmissionLookupService.class);
|
SubmissionLookupService.class);
|
||||||
|
|
||||||
/** log4j logger */
|
/** 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
|
* 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 uuidSubmission = request.getParameter("suuid");
|
||||||
String uuidLookup = request.getParameter("iuuid");
|
String uuidLookup = request.getParameter("iuuid");
|
||||||
String fuuidLookup = request.getParameter("fuuid");
|
String fuuidLookup = request.getParameter("fuuid");
|
||||||
|
|
||||||
if (StringUtils.isBlank(uuidSubmission))
|
if (StringUtils.isBlank(uuidSubmission))
|
||||||
{
|
{
|
||||||
return STATUS_NO_SUUID;
|
return STATUS_NO_SUUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
SubmissionLookupDTO submissionDTO = slService.getSubmissionLookupDTO(
|
SubmissionLookupDTO submissionDTO = slService.getSubmissionLookupDTO(
|
||||||
request, uuidSubmission);
|
request, uuidSubmission);
|
||||||
|
|
||||||
if (submissionDTO == null)
|
if (submissionDTO == null)
|
||||||
{
|
{
|
||||||
return STATUS_SUBMISSION_EXPIRED;
|
return STATUS_SUBMISSION_EXPIRED;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemSubmissionLookupDTO itemLookup = null;
|
ItemSubmissionLookupDTO itemLookup = null;
|
||||||
if (fuuidLookup == null || fuuidLookup.isEmpty()) {
|
if (fuuidLookup == null || fuuidLookup.isEmpty())
|
||||||
if (StringUtils.isNotBlank(uuidLookup)) {
|
{
|
||||||
itemLookup = submissionDTO.getLookupItem(uuidLookup);
|
if (StringUtils.isNotBlank(uuidLookup))
|
||||||
if (itemLookup == null) {
|
{
|
||||||
return STATUS_SUBMISSION_EXPIRED;
|
itemLookup = submissionDTO.getLookupItem(uuidLookup);
|
||||||
}
|
if (itemLookup == null)
|
||||||
}
|
{
|
||||||
}
|
return STATUS_SUBMISSION_EXPIRED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// if the user didn't select a collection,
|
// if the user didn't select a collection,
|
||||||
// send him/her back to "select a collection" page
|
// send him/her back to "select a collection" page
|
||||||
if (id < 0)
|
if (id < 0)
|
||||||
@@ -164,80 +170,101 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
|
|||||||
{
|
{
|
||||||
// create our new Workspace Item
|
// create our new Workspace Item
|
||||||
DCInputSet inputSet = null;
|
DCInputSet inputSet = null;
|
||||||
try {
|
try
|
||||||
inputSet = new DCInputsReader().getInputs(col.getHandle());
|
{
|
||||||
} catch (Exception e) {
|
inputSet = new DCInputsReader().getInputs(col.getHandle());
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
catch (Exception e)
|
||||||
|
{
|
||||||
List<ItemSubmissionLookupDTO> dto = new ArrayList<ItemSubmissionLookupDTO>();
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ItemSubmissionLookupDTO> dto = new ArrayList<ItemSubmissionLookupDTO>();
|
||||||
|
|
||||||
if (itemLookup != null)
|
if (itemLookup != null)
|
||||||
{
|
{
|
||||||
dto.add(itemLookup);
|
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));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else if (fuuidLookup != null)
|
||||||
List<WorkspaceItem> result = null;
|
{
|
||||||
|
String[] ss = fuuidLookup.split(",");
|
||||||
TransformationEngine transformationEngine = slService.getPhase2TransformationEngine();
|
for (String s : ss)
|
||||||
if (transformationEngine != null){
|
{
|
||||||
SubmissionItemDataLoader dataLoader = (SubmissionItemDataLoader)transformationEngine.getDataLoader();
|
itemLookup = submissionDTO.getLookupItem(s);
|
||||||
dataLoader.setDtoList(dto);
|
if (itemLookup == null)
|
||||||
//dataLoader.setProviders()
|
{
|
||||||
|
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();
|
Enumeration e = request.getParameterNames();
|
||||||
outputGenerator.setCollection(col);
|
|
||||||
outputGenerator.setContext(context);
|
while (e.hasMoreElements())
|
||||||
outputGenerator.setFormName(inputSet.getFormName());
|
{
|
||||||
outputGenerator.setDto(dto.get(0));
|
String parameterName = (String) e.nextElement();
|
||||||
|
String parameterValue = request.getParameter(parameterName);
|
||||||
try {
|
|
||||||
transformationEngine.transform(new TransformationSpec());
|
if (parameterName.startsWith("identifier_")
|
||||||
result = outputGenerator.getWitems();
|
&& StringUtils.isNotBlank(parameterValue))
|
||||||
} catch (BadTransformationSpec e1) {
|
{
|
||||||
e1.printStackTrace();
|
manualPub
|
||||||
} catch (MalformedSourceException e1) {
|
.add(parameterName.substring("identifier_"
|
||||||
e1.printStackTrace();
|
.length()), parameterValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
List<Record> publications = new ArrayList<Record>();
|
||||||
if (result != null && result.size()>0) {
|
publications.add(manualPub);
|
||||||
// update Submission Information with this Workspace Item
|
dto.add(new ItemSubmissionLookupDTO(publications));
|
||||||
subInfo.setSubmissionItem(result.iterator().next());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// commit changes to database
|
||||||
context.commit();
|
context.commit();
|
||||||
@@ -252,7 +279,7 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
|
|||||||
return STATUS_COMPLETE;
|
return STATUS_COMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the number of pages that this "step" extends over. This method
|
* Retrieves the number of pages that this "step" extends over. This method
|
||||||
* is used to build the progress bar.
|
* is used to build the progress bar.
|
||||||
* <P>
|
* <P>
|
||||||
|
@@ -28,74 +28,84 @@ import org.dspace.submit.lookup.SubmissionLookupService;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class ItemSubmissionLookupDTO implements Serializable {
|
public class ItemSubmissionLookupDTO implements Serializable
|
||||||
private static final long serialVersionUID = 1;
|
{
|
||||||
|
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 static final String UNKNOWN_PROVIDER_STRING = "UNKNOWN-PROVIDER";
|
||||||
|
|
||||||
private List<Record> publications;
|
private List<Record> publications;
|
||||||
private String uuid;
|
|
||||||
|
|
||||||
public ItemSubmissionLookupDTO(List<Record> publications) {
|
private String uuid;
|
||||||
this.uuid = UUID.randomUUID().toString();
|
|
||||||
this.publications = publications;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Record> getPublications() {
|
public ItemSubmissionLookupDTO(List<Record> publications)
|
||||||
return publications;
|
{
|
||||||
}
|
this.uuid = UUID.randomUUID().toString();
|
||||||
|
this.publications = publications;
|
||||||
public Set<String> getProviders() {
|
}
|
||||||
Set<String> orderedProviders = new LinkedHashSet<String>();
|
|
||||||
|
public List<Record> getPublications()
|
||||||
|
{
|
||||||
|
return publications;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getProviders()
|
||||||
|
{
|
||||||
|
Set<String> orderedProviders = new LinkedHashSet<String>();
|
||||||
for (Record p : publications)
|
for (Record p : publications)
|
||||||
{
|
{
|
||||||
orderedProviders.add(SubmissionLookupService.getProviderName(p));
|
orderedProviders.add(SubmissionLookupService.getProviderName(p));
|
||||||
}
|
}
|
||||||
return orderedProviders;
|
return orderedProviders;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUUID() {
|
public String getUUID()
|
||||||
return uuid;
|
{
|
||||||
}
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
public Record getTotalPublication(List<DataLoader> providers) {
|
public Record getTotalPublication(List<DataLoader> providers)
|
||||||
if (publications == null)
|
{
|
||||||
{
|
if (publications == null)
|
||||||
return null;
|
{
|
||||||
}
|
return null;
|
||||||
else if (publications.size() == 1)
|
}
|
||||||
{
|
else if (publications.size() == 1)
|
||||||
return publications.get(0);
|
{
|
||||||
}
|
return publications.get(0);
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
MutableRecord pub = new SubmissionLookupPublication(MERGED_PUBLICATION_PROVIDER);
|
{
|
||||||
//for (SubmissionLookupProvider prov : providers)
|
MutableRecord pub = new SubmissionLookupPublication(
|
||||||
//{
|
MERGED_PUBLICATION_PROVIDER);
|
||||||
for (Record p : publications)
|
// for (SubmissionLookupProvider prov : providers)
|
||||||
{
|
// {
|
||||||
//if (!SubmissionLookupService.getProviderName(p).equals(prov.getShortName()))
|
for (Record p : publications)
|
||||||
//{
|
{
|
||||||
// continue;
|
// if
|
||||||
//}
|
// (!SubmissionLookupService.getProviderName(p).equals(prov.getShortName()))
|
||||||
for (String field : p.getFields())
|
// {
|
||||||
{
|
// continue;
|
||||||
List<Value> values = p.getValues(field);
|
// }
|
||||||
if (values != null && values.size() > 0)
|
for (String field : p.getFields())
|
||||||
{
|
{
|
||||||
if (!pub.getFields().contains(field))
|
List<Value> values = p.getValues(field);
|
||||||
{
|
if (values != null && values.size() > 0)
|
||||||
for (Value v : values)
|
{
|
||||||
{
|
if (!pub.getFields().contains(field))
|
||||||
pub.addValue(field, v);
|
{
|
||||||
}
|
for (Value v : values)
|
||||||
}
|
{
|
||||||
}
|
pub.addValue(field, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//}
|
}
|
||||||
return pub;
|
}
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
|
return pub;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,32 +17,36 @@ import java.util.UUID;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class SubmissionLookupDTO implements Serializable {
|
public class SubmissionLookupDTO implements Serializable
|
||||||
private static final long serialVersionUID = 1;
|
{
|
||||||
|
private static final long serialVersionUID = 1;
|
||||||
private String uuid;
|
|
||||||
|
|
||||||
private List<ItemSubmissionLookupDTO> items;
|
private String uuid;
|
||||||
|
|
||||||
public SubmissionLookupDTO() {
|
private List<ItemSubmissionLookupDTO> items;
|
||||||
this.uuid = UUID.randomUUID().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setItems(List<ItemSubmissionLookupDTO> items) {
|
|
||||||
this.items = items;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemSubmissionLookupDTO getLookupItem(String uuidLookup) {
|
public SubmissionLookupDTO()
|
||||||
if (items != null)
|
{
|
||||||
{
|
this.uuid = UUID.randomUUID().toString();
|
||||||
for (ItemSubmissionLookupDTO item : items)
|
}
|
||||||
{
|
|
||||||
if (item.getUUID().equals(uuidLookup))
|
public void setItems(List<ItemSubmissionLookupDTO> items)
|
||||||
{
|
{
|
||||||
return item;
|
this.items = items;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
public ItemSubmissionLookupDTO getLookupItem(String uuidLookup)
|
||||||
return null;
|
{
|
||||||
}
|
if (items != null)
|
||||||
|
{
|
||||||
|
for (ItemSubmissionLookupDTO item : items)
|
||||||
|
{
|
||||||
|
if (item.getUUID().equals(uuidLookup))
|
||||||
|
{
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,167 +27,205 @@ import org.dspace.submit.lookup.SubmissionLookupDataLoader;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class SubmissionLookupPublication implements MutableRecord, Serializable {
|
public class SubmissionLookupPublication implements MutableRecord, Serializable
|
||||||
private String providerName;
|
{
|
||||||
|
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) {
|
public SubmissionLookupPublication(String providerName)
|
||||||
this.providerName = providerName;
|
{
|
||||||
}
|
this.providerName = providerName;
|
||||||
|
}
|
||||||
|
|
||||||
// needed to serialize it with JSON
|
// needed to serialize it with JSON
|
||||||
public Map<String, List<String>> getStorage() {
|
public Map<String, List<String>> getStorage()
|
||||||
return storage;
|
{
|
||||||
}
|
return storage;
|
||||||
|
}
|
||||||
public Set<String> getFields() {
|
|
||||||
return storage.keySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> remove(String md) {
|
public Set<String> getFields()
|
||||||
return storage.remove(md);
|
{
|
||||||
}
|
return storage.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
public void add(String md, String nValue) {
|
public List<String> remove(String md)
|
||||||
if (StringUtils.isNotBlank(nValue))
|
{
|
||||||
{
|
return storage.remove(md);
|
||||||
List<String> tmp = storage.get(md);
|
}
|
||||||
if (tmp == null) {
|
|
||||||
tmp = new ArrayList<String>();
|
|
||||||
storage.put(md, tmp);
|
|
||||||
}
|
|
||||||
tmp.add(nValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFirstValue(String md) {
|
public void add(String md, String nValue)
|
||||||
List<String> tmp = storage.get(md);
|
{
|
||||||
if (tmp == null || tmp.size() == 0) {
|
if (StringUtils.isNotBlank(nValue))
|
||||||
return null;
|
{
|
||||||
}
|
List<String> tmp = storage.get(md);
|
||||||
return tmp.get(0);
|
if (tmp == null)
|
||||||
}
|
{
|
||||||
|
tmp = new ArrayList<String>();
|
||||||
|
storage.put(md, tmp);
|
||||||
|
}
|
||||||
|
tmp.add(nValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getProviderName() {
|
public String getFirstValue(String md)
|
||||||
return providerName;
|
{
|
||||||
}
|
List<String> tmp = storage.get(md);
|
||||||
|
if (tmp == null || tmp.size() == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return tmp.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getProviderName()
|
||||||
return getFirstValue(SubmissionLookupDataLoader.TYPE);
|
{
|
||||||
}
|
return providerName;
|
||||||
|
}
|
||||||
|
|
||||||
//BTE Record interface methods
|
public String getType()
|
||||||
@Override
|
{
|
||||||
public boolean hasField(String md) {
|
return getFirstValue(SubmissionLookupDataLoader.TYPE);
|
||||||
return storage.containsKey(md);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// BTE Record interface methods
|
||||||
public List<Value> getValues(String md) {
|
@Override
|
||||||
List<String> stringValues = storage.get(md);
|
public boolean hasField(String md)
|
||||||
if (stringValues == null){
|
{
|
||||||
return null;
|
return storage.containsKey(md);
|
||||||
}
|
}
|
||||||
List<Value> values = new ArrayList<Value>();
|
|
||||||
for (String value : stringValues){
|
|
||||||
values.add(new StringValue(value));
|
|
||||||
}
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMutable() {
|
public List<Value> getValues(String md)
|
||||||
return true;
|
{
|
||||||
}
|
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
|
@Override
|
||||||
public MutableRecord makeMutable() {
|
public boolean isMutable()
|
||||||
return this;
|
{
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addField(String md, List<Value> values) {
|
public MutableRecord makeMutable()
|
||||||
if (storage.containsKey(md)){
|
{
|
||||||
List<String> stringValues = storage.get(md);
|
return this;
|
||||||
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
|
@Override
|
||||||
public boolean addValue(String md, Value value) {
|
public boolean addField(String md, List<Value> values)
|
||||||
if (storage.containsKey(md)){
|
{
|
||||||
List<String> stringValues = storage.get(md);
|
if (storage.containsKey(md))
|
||||||
stringValues.add(value.getAsString());
|
{
|
||||||
}
|
List<String> stringValues = storage.get(md);
|
||||||
else {
|
if (values != null)
|
||||||
List<String> tmp = new ArrayList<String>();
|
{
|
||||||
tmp.add(value.getAsString());
|
for (Value value : values)
|
||||||
|
{
|
||||||
storage.put(md, tmp);
|
stringValues.add(value.getAsString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
List<String> tmp = new ArrayList<String>();
|
||||||
|
if (values != null)
|
||||||
|
{
|
||||||
|
for (Value value : values)
|
||||||
|
{
|
||||||
|
tmp.add(value.getAsString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
storage.put(md, tmp);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
return true;
|
||||||
public boolean removeField(String md) {
|
}
|
||||||
if (storage.containsKey(md)){
|
|
||||||
storage.remove(md);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeValue(String md, Value value) {
|
public boolean addValue(String md, Value value)
|
||||||
if (storage.containsKey(md)){
|
{
|
||||||
List<String> stringValues = storage.get(md);
|
if (storage.containsKey(md))
|
||||||
stringValues.remove(value.getAsString());
|
{
|
||||||
}
|
List<String> stringValues = storage.get(md);
|
||||||
return true;
|
stringValues.add(value.getAsString());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<String> tmp = new ArrayList<String>();
|
||||||
|
tmp.add(value.getAsString());
|
||||||
|
|
||||||
@Override
|
storage.put(md, tmp);
|
||||||
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateValue(String md, Value valueOld, Value valueNew) {
|
public boolean removeField(String md)
|
||||||
if (storage.containsKey(md)){
|
{
|
||||||
List<String> stringValues = storage.get(md);
|
if (storage.containsKey(md))
|
||||||
List<String> newStringValues = storage.get(md);
|
{
|
||||||
for (String s : stringValues){
|
storage.remove(md);
|
||||||
if (s.equals(valueOld.getAsString())){
|
}
|
||||||
newStringValues.add(valueNew.getAsString());
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
newStringValues.add(s);
|
@Override
|
||||||
}
|
public boolean removeValue(String md, Value value)
|
||||||
}
|
{
|
||||||
storage.put(md, newStringValues);
|
if (storage.containsKey(md))
|
||||||
}
|
{
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -62,290 +62,344 @@ import com.google.gson.JsonObject;
|
|||||||
* @author Luigi Andrea Pascarelli
|
* @author Luigi Andrea Pascarelli
|
||||||
* @author Panagiotis Koutsourakis
|
* @author Panagiotis Koutsourakis
|
||||||
*/
|
*/
|
||||||
public class SubmissionLookupJSONRequest extends JSONRequest {
|
public class SubmissionLookupJSONRequest extends JSONRequest
|
||||||
|
{
|
||||||
|
|
||||||
private SubmissionLookupService service = new DSpace().getServiceManager()
|
private SubmissionLookupService service = new DSpace().getServiceManager()
|
||||||
.getServiceByName(SubmissionLookupService.class.getName(),
|
.getServiceByName(SubmissionLookupService.class.getName(),
|
||||||
SubmissionLookupService.class);
|
SubmissionLookupService.class);
|
||||||
|
|
||||||
private static Logger log = Logger
|
private static Logger log = Logger
|
||||||
.getLogger(SubmissionLookupJSONRequest.class);
|
.getLogger(SubmissionLookupJSONRequest.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doJSONRequest(Context context, HttpServletRequest req,
|
public void doJSONRequest(Context context, HttpServletRequest req,
|
||||||
HttpServletResponse resp) throws AuthorizeException, IOException {
|
HttpServletResponse resp) throws AuthorizeException, IOException
|
||||||
Gson json = new Gson();
|
{
|
||||||
String suuid = req.getParameter("s_uuid");
|
Gson json = new Gson();
|
||||||
SubmissionLookupDTO subDTO = service.getSubmissionLookupDTO(req, suuid);
|
String suuid = req.getParameter("s_uuid");
|
||||||
// Check that we have a file upload request
|
SubmissionLookupDTO subDTO = service.getSubmissionLookupDTO(req, suuid);
|
||||||
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
|
// Check that we have a file upload request
|
||||||
if ("identifiers".equalsIgnoreCase(req.getParameter("type"))) {
|
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
|
||||||
Map<String, Set<String>> identifiers = new HashMap<String, Set<String>>();
|
if ("identifiers".equalsIgnoreCase(req.getParameter("type")))
|
||||||
Enumeration e = req.getParameterNames();
|
{
|
||||||
|
Map<String, Set<String>> identifiers = new HashMap<String, Set<String>>();
|
||||||
|
Enumeration e = req.getParameterNames();
|
||||||
|
|
||||||
while (e.hasMoreElements()) {
|
while (e.hasMoreElements())
|
||||||
String parameterName = (String) e.nextElement();
|
{
|
||||||
String parameterValue = req.getParameter(parameterName);
|
String parameterName = (String) e.nextElement();
|
||||||
|
String parameterValue = req.getParameter(parameterName);
|
||||||
|
|
||||||
if (parameterName.startsWith("identifier_")
|
if (parameterName.startsWith("identifier_")
|
||||||
&& StringUtils.isNotBlank(parameterValue)) {
|
&& StringUtils.isNotBlank(parameterValue))
|
||||||
Set<String> set = new HashSet<String>();
|
{
|
||||||
set.add(parameterValue);
|
Set<String> set = new HashSet<String>();
|
||||||
identifiers.put(
|
set.add(parameterValue);
|
||||||
parameterName.substring("identifier_".length()),
|
identifiers.put(
|
||||||
set);
|
parameterName.substring("identifier_".length()),
|
||||||
}
|
set);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<ItemSubmissionLookupDTO> result = new ArrayList<ItemSubmissionLookupDTO>();
|
List<ItemSubmissionLookupDTO> result = new ArrayList<ItemSubmissionLookupDTO>();
|
||||||
|
|
||||||
TransformationEngine transformationEngine = service
|
TransformationEngine transformationEngine = service
|
||||||
.getPhase1TransformationEngine();
|
.getPhase1TransformationEngine();
|
||||||
if (transformationEngine != null) {
|
if (transformationEngine != null)
|
||||||
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
|
{
|
||||||
.getDataLoader();
|
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
|
||||||
dataLoader.setIdentifiers(identifiers);
|
.getDataLoader();
|
||||||
|
dataLoader.setIdentifiers(identifiers);
|
||||||
|
|
||||||
try {
|
try
|
||||||
log.debug("BTE transformation is about to start!");
|
{
|
||||||
transformationEngine.transform(new TransformationSpec());
|
log.debug("BTE transformation is about to start!");
|
||||||
log.debug("BTE transformation finished!");
|
transformationEngine.transform(new TransformationSpec());
|
||||||
|
log.debug("BTE transformation finished!");
|
||||||
|
|
||||||
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
|
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
|
||||||
.getOutputGenerator();
|
.getOutputGenerator();
|
||||||
result = outputGenerator.getDtoList();
|
result = outputGenerator.getDtoList();
|
||||||
} catch (BadTransformationSpec e1) {
|
}
|
||||||
log.error(e1.getMessage(), e1);
|
catch (BadTransformationSpec e1)
|
||||||
} catch (MalformedSourceException e1) {
|
{
|
||||||
log.error(e1.getMessage(), e1);
|
log.error(e1.getMessage(), e1);
|
||||||
}
|
}
|
||||||
}
|
catch (MalformedSourceException e1)
|
||||||
|
{
|
||||||
|
log.error(e1.getMessage(), e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
subDTO.setItems(result);
|
subDTO.setItems(result);
|
||||||
service.storeDTOs(req, suuid, subDTO);
|
service.storeDTOs(req, suuid, subDTO);
|
||||||
List<Map<String, Object>> dto = getLightResultList(result);
|
List<Map<String, Object>> dto = getLightResultList(result);
|
||||||
JsonElement tree = json.toJsonTree(dto);
|
JsonElement tree = json.toJsonTree(dto);
|
||||||
JsonObject jo = new JsonObject();
|
JsonObject jo = new JsonObject();
|
||||||
jo.add("result", tree);
|
jo.add("result", tree);
|
||||||
resp.getWriter().write(jo.toString());
|
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");
|
|
||||||
|
|
||||||
Map<String, Set<String>> searchTerms = new HashMap<String, Set<String>>();
|
}
|
||||||
Set<String> tmp1 = new HashSet<String>();
|
else if ("search".equalsIgnoreCase(req.getParameter("type")))
|
||||||
tmp1.add(title);
|
{
|
||||||
Set<String> tmp2 = new HashSet<String>();
|
String title = req.getParameter("title");
|
||||||
tmp2.add(author);
|
String author = req.getParameter("authors");
|
||||||
Set<String> tmp3 = new HashSet<String>();
|
int year = UIUtil.getIntParameter(req, "year");
|
||||||
tmp3.add(String.valueOf(year));
|
|
||||||
searchTerms.put("title", tmp1);
|
|
||||||
searchTerms.put("authors", tmp2);
|
|
||||||
searchTerms.put("year", tmp3);
|
|
||||||
|
|
||||||
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
|
List<ItemSubmissionLookupDTO> result = new ArrayList<ItemSubmissionLookupDTO>();
|
||||||
.getPhase1TransformationEngine();
|
|
||||||
if (transformationEngine != null) {
|
|
||||||
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
|
|
||||||
.getDataLoader();
|
|
||||||
dataLoader.setSearchTerms(searchTerms);
|
|
||||||
|
|
||||||
try {
|
TransformationEngine transformationEngine = service
|
||||||
transformationEngine.transform(new TransformationSpec());
|
.getPhase1TransformationEngine();
|
||||||
|
if (transformationEngine != null)
|
||||||
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
|
{
|
||||||
.getOutputGenerator();
|
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
|
||||||
result = outputGenerator.getDtoList();
|
.getDataLoader();
|
||||||
} catch (BadTransformationSpec e1) {
|
dataLoader.setSearchTerms(searchTerms);
|
||||||
log.error(e1.getMessage(), e1);
|
|
||||||
} catch (MalformedSourceException e1) {
|
|
||||||
log.error(e1.getMessage(), e1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
subDTO.setItems(result);
|
try
|
||||||
service.storeDTOs(req, suuid, subDTO);
|
{
|
||||||
List<Map<String, Object>> dto = getLightResultList(result);
|
transformationEngine.transform(new TransformationSpec());
|
||||||
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
|
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
|
||||||
FileItemFactory factory = new DiskFileItemFactory();
|
.getOutputGenerator();
|
||||||
|
result = outputGenerator.getDtoList();
|
||||||
// Create a new file upload handler
|
}
|
||||||
ServletFileUpload upload = new ServletFileUpload(factory);
|
catch (BadTransformationSpec e1)
|
||||||
// Parse the request
|
{
|
||||||
Map<String, String> valueMap = new HashMap<String, String>();
|
log.error(e1.getMessage(), e1);
|
||||||
InputStream io = null;
|
}
|
||||||
|
catch (MalformedSourceException e1)
|
||||||
|
{
|
||||||
|
log.error(e1.getMessage(), e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Parse the request
|
subDTO.setItems(result);
|
||||||
List<FileItem> iter;
|
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;
|
String filename = null;
|
||||||
try {
|
try
|
||||||
iter = upload.parseRequest(req);
|
{
|
||||||
for(FileItem item : iter) {
|
iter = upload.parseRequest(req);
|
||||||
String name = item.getFieldName();
|
for (FileItem item : iter)
|
||||||
InputStream stream = item.getInputStream();
|
{
|
||||||
if (item.isFormField()) {
|
String name = item.getFieldName();
|
||||||
String value = Streams.asString(stream);
|
InputStream stream = item.getInputStream();
|
||||||
valueMap.put(name, value);
|
if (item.isFormField())
|
||||||
} else {
|
{
|
||||||
io = stream;
|
String value = Streams.asString(stream);
|
||||||
}
|
valueMap.put(name, value);
|
||||||
}
|
}
|
||||||
} catch (FileUploadException e) {
|
else
|
||||||
throw new IOException(e);
|
{
|
||||||
}
|
io = stream;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (FileUploadException e)
|
||||||
|
{
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
|
|
||||||
suuid = valueMap.get("s_uuid");
|
suuid = valueMap.get("s_uuid");
|
||||||
subDTO = service.getSubmissionLookupDTO(req, suuid);
|
subDTO = service.getSubmissionLookupDTO(req, suuid);
|
||||||
|
|
||||||
List<ItemSubmissionLookupDTO> result = new ArrayList<ItemSubmissionLookupDTO>();
|
List<ItemSubmissionLookupDTO> result = new ArrayList<ItemSubmissionLookupDTO>();
|
||||||
|
|
||||||
TransformationEngine transformationEngine = service
|
TransformationEngine transformationEngine = service
|
||||||
.getPhase1TransformationEngine();
|
.getPhase1TransformationEngine();
|
||||||
if (transformationEngine != null) {
|
if (transformationEngine != null)
|
||||||
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
|
{
|
||||||
.getDataLoader();
|
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
|
||||||
|
.getDataLoader();
|
||||||
String tempDir = (ConfigurationManager.getProperty("upload.temp.dir") != null)
|
|
||||||
? ConfigurationManager.getProperty("upload.temp.dir") : System.getProperty("java.io.tmpdir");
|
String tempDir = (ConfigurationManager
|
||||||
File file = new File(tempDir + System.getProperty("file.separator") + "submissionlookup-loader.temp");
|
.getProperty("upload.temp.dir") != null) ? ConfigurationManager
|
||||||
BufferedOutputStream out = new BufferedOutputStream(
|
.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));
|
new FileOutputStream(file));
|
||||||
Utils.bufferedCopy(io, out);
|
Utils.bufferedCopy(io, out);
|
||||||
dataLoader.setFile(file.getAbsolutePath(), valueMap.get("provider_loader"));
|
dataLoader.setFile(file.getAbsolutePath(),
|
||||||
|
valueMap.get("provider_loader"));
|
||||||
try {
|
|
||||||
transformationEngine.transform(new TransformationSpec());
|
try
|
||||||
|
{
|
||||||
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
|
transformationEngine.transform(new TransformationSpec());
|
||||||
.getOutputGenerator();
|
|
||||||
result = outputGenerator.getDtoList();
|
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
|
||||||
} catch (BadTransformationSpec e1) {
|
.getOutputGenerator();
|
||||||
log.error(e1.getMessage(), e1);
|
result = outputGenerator.getDtoList();
|
||||||
} catch (MalformedSourceException e1) {
|
}
|
||||||
log.error(e1.getMessage(), e1);
|
catch (BadTransformationSpec e1)
|
||||||
}
|
{
|
||||||
|
log.error(e1.getMessage(), e1);
|
||||||
|
}
|
||||||
|
catch (MalformedSourceException e1)
|
||||||
|
{
|
||||||
|
log.error(e1.getMessage(), e1);
|
||||||
|
}
|
||||||
|
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
subDTO.setItems(result);
|
subDTO.setItems(result);
|
||||||
service.storeDTOs(req, suuid, subDTO);
|
service.storeDTOs(req, suuid, subDTO);
|
||||||
List<Map<String, Object>> dto = getLightResultList(result);
|
List<Map<String, Object>> dto = getLightResultList(result);
|
||||||
if (valueMap.containsKey("skip_loader")) {
|
if (valueMap.containsKey("skip_loader"))
|
||||||
if (valueMap.get("skip_loader").equals("true")) {
|
{
|
||||||
Map<String, Object> skip = new HashMap<String, Object>();
|
if (valueMap.get("skip_loader").equals("true"))
|
||||||
skip.put(
|
{
|
||||||
"skip",
|
Map<String, Object> skip = new HashMap<String, Object>();
|
||||||
Boolean.TRUE);
|
skip.put("skip", Boolean.TRUE);
|
||||||
skip.put(
|
skip.put("uuid", valueMap.containsKey("s_uuid") ? suuid
|
||||||
"uuid",
|
: -1);
|
||||||
valueMap.containsKey("s_uuid") ? suuid
|
skip.put(
|
||||||
: -1);
|
"collectionid",
|
||||||
skip.put(
|
valueMap.containsKey("select-collection-file") ? valueMap
|
||||||
"collectionid",
|
.get("select-collection-file") : -1);
|
||||||
valueMap.containsKey("select-collection-file") ? valueMap
|
dto.add(skip);
|
||||||
.get("select-collection-file") : -1);
|
}
|
||||||
dto.add(skip);
|
}
|
||||||
}
|
JsonElement tree = json.toJsonTree(dto);
|
||||||
}
|
JsonObject jo = new JsonObject();
|
||||||
JsonElement tree = json.toJsonTree(dto);
|
jo.add("result", tree);
|
||||||
JsonObject jo = new JsonObject();
|
resp.getWriter().write(jo.toString());
|
||||||
jo.add("result", tree);
|
resp.setContentType("text/plain");
|
||||||
resp.getWriter().write(jo.toString());
|
}
|
||||||
resp.setContentType("text/plain");
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, Object> getDetails(ItemSubmissionLookupDTO item,
|
private Map<String, Object> getDetails(ItemSubmissionLookupDTO item,
|
||||||
Context context) {
|
Context context)
|
||||||
List<String> fieldOrder = getFieldOrderFromConfiguration();
|
{
|
||||||
Record totalData = item.getTotalPublication(service.getProviders());
|
List<String> fieldOrder = getFieldOrderFromConfiguration();
|
||||||
Set<String> availableFields = totalData.getFields();
|
Record totalData = item.getTotalPublication(service.getProviders());
|
||||||
List<String[]> fieldsLabels = new ArrayList<String[]>();
|
Set<String> availableFields = totalData.getFields();
|
||||||
for (String f : fieldOrder) {
|
List<String[]> fieldsLabels = new ArrayList<String[]>();
|
||||||
if (availableFields.contains(f)) {
|
for (String f : fieldOrder)
|
||||||
try {
|
{
|
||||||
fieldsLabels.add(new String[] {
|
if (availableFields.contains(f))
|
||||||
f,
|
{
|
||||||
I18nUtil.getMessage("jsp.submission-lookup.detail."
|
try
|
||||||
+ f, context) });
|
{
|
||||||
} catch (MissingResourceException e) {
|
fieldsLabels.add(new String[] {
|
||||||
fieldsLabels.add(new String[] { f, f });
|
f,
|
||||||
}
|
I18nUtil.getMessage("jsp.submission-lookup.detail."
|
||||||
}
|
+ f, context) });
|
||||||
}
|
}
|
||||||
Map<String, Object> data = new HashMap<String, Object>();
|
catch (MissingResourceException e)
|
||||||
String uuid = item.getUUID();
|
{
|
||||||
|
fieldsLabels.add(new String[] { f, f });
|
||||||
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));
|
Map<String, Object> data = new HashMap<String, Object>();
|
||||||
}
|
String uuid = item.getUUID();
|
||||||
|
|
||||||
data.put("uuid", uuid);
|
|
||||||
data.put("providers", item.getProviders());
|
|
||||||
data.put("publication", publication1);
|
|
||||||
data.put("fieldsLabels", fieldsLabels);
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> getFieldOrderFromConfiguration() {
|
Record pub = item.getTotalPublication(service.getProviders());
|
||||||
String config = ConfigurationManager
|
Map<String, List<String>> publication1 = new HashMap<String, List<String>>();
|
||||||
.getProperty("submission-lookup.detail.fields");
|
for (String field : pub.getFields())
|
||||||
if (config == null) {
|
{
|
||||||
config = "title,authors,editors,years,doi,pmid,eid,arxiv,journal,jissn,jeissn,volume,issue,serie,sissn,seissn,abstract,mesh,keywords,subtype";
|
publication1
|
||||||
}
|
.put(field, SubmissionLookupUtils.getValues(pub, field));
|
||||||
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(
|
data.put("uuid", uuid);
|
||||||
List<ItemSubmissionLookupDTO> result) {
|
data.put("providers", item.getProviders());
|
||||||
List<Map<String, Object>> publications = new ArrayList<Map<String, Object>>();
|
data.put("publication", publication1);
|
||||||
if (result != null && result.size() > 0) {
|
data.put("fieldsLabels", fieldsLabels);
|
||||||
for (ItemSubmissionLookupDTO item : result) {
|
return data;
|
||||||
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);
|
private List<String> getFieldOrderFromConfiguration()
|
||||||
}
|
{
|
||||||
}
|
String config = ConfigurationManager
|
||||||
return publications;
|
.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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -35,21 +35,20 @@ import org.dspace.submit.step.StartSubmissionLookupStep;
|
|||||||
import org.dspace.utils.DSpace;
|
import org.dspace.utils.DSpace;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Step which controls selecting an item from external database service to auto fill metadata
|
* Step which controls selecting an item from external database service to auto
|
||||||
* for DSpace JSP-UI
|
* fill metadata for DSpace JSP-UI
|
||||||
* <P>
|
* <P>
|
||||||
* This JSPStep class works with the SubmissionController servlet
|
* This JSPStep class works with the SubmissionController servlet for the JSP-UI
|
||||||
* for the JSP-UI
|
|
||||||
* <P>
|
* <P>
|
||||||
* The following methods are called in this order:
|
* The following methods are called in this order:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Call doPreProcessing() method</li>
|
* <li>Call doPreProcessing() method</li>
|
||||||
* <li>If showJSP() was specified from doPreProcessing(), then the JSP
|
* <li>If showJSP() was specified from doPreProcessing(), then the JSP specified
|
||||||
* specified will be displayed</li>
|
* will be displayed</li>
|
||||||
* <li>If showJSP() was not specified from doPreProcessing(), then the
|
* <li>If showJSP() was not specified from doPreProcessing(), then the
|
||||||
* doProcessing() method is called an the step completes immediately</li>
|
* 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
|
* <li>Call doProcessing() method on appropriate AbstractProcessingStep after
|
||||||
* to process the user input</li>
|
* 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
|
* <li>Call doPostProcessing() method to determine if more user interaction is
|
||||||
* required, and if further JSPs need to be called.</li>
|
* required, and if further JSPs need to be called.</li>
|
||||||
* <li>If there are more "pages" in this step then, the process begins again
|
* <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";
|
private static final String START_LOOKUP_JSP = "/submit/start-lookup-submission.jsp";
|
||||||
|
|
||||||
/** log4j logger */
|
/** log4j logger */
|
||||||
private static Logger log = Logger.getLogger(JSPStartSubmissionLookupStep.class);
|
private static Logger log = Logger
|
||||||
|
.getLogger(JSPStartSubmissionLookupStep.class);
|
||||||
|
|
||||||
SubmissionLookupService slService = new DSpace().getServiceManager()
|
SubmissionLookupService slService = new DSpace().getServiceManager()
|
||||||
.getServiceByName(
|
.getServiceByName(SubmissionLookupService.class.getCanonicalName(),
|
||||||
SubmissionLookupService.class.getCanonicalName(),
|
SubmissionLookupService.class);
|
||||||
SubmissionLookupService.class);
|
|
||||||
/**
|
/**
|
||||||
* Do any pre-processing to determine which JSP (if any) is used to generate
|
* 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
|
* 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
|
// save collections to request for JSP
|
||||||
request.setAttribute("collections", collections);
|
request.setAttribute("collections", collections);
|
||||||
request.setAttribute("collectionID", collectionID);
|
request.setAttribute("collectionID", collectionID);
|
||||||
|
|
||||||
Map<String, List<String>> identifiers2providers = slService
|
Map<String, List<String>> identifiers2providers = slService
|
||||||
.getProvidersIdentifiersMap();
|
.getProvidersIdentifiersMap();
|
||||||
List<String> searchProviders = slService
|
List<String> searchProviders = slService.getSearchProviders();
|
||||||
.getSearchProviders();
|
List<String> fileProviders = slService.getFileProviders();
|
||||||
List<String> fileProviders = slService
|
|
||||||
.getFileProviders();
|
|
||||||
request.setAttribute("identifiers2providers", identifiers2providers);
|
request.setAttribute("identifiers2providers", identifiers2providers);
|
||||||
request.setAttribute("searchProviders", searchProviders);
|
request.setAttribute("searchProviders", searchProviders);
|
||||||
request.setAttribute("fileLoaders", fileProviders);
|
request.setAttribute("fileLoaders", fileProviders);
|
||||||
@@ -226,12 +224,12 @@ public class JSPStartSubmissionLookupStep extends JSPStep
|
|||||||
}
|
}
|
||||||
else if (status == StartSubmissionLookupStep.STATUS_INVALID_COLLECTION)
|
else if (status == StartSubmissionLookupStep.STATUS_INVALID_COLLECTION)
|
||||||
{
|
{
|
||||||
JSPManager.showInvalidIDError(request, response, request
|
JSPManager.showInvalidIDError(request, response,
|
||||||
.getParameter("collectionid"), Constants.COLLECTION);
|
request.getParameter("collectionid"), Constants.COLLECTION);
|
||||||
}
|
}
|
||||||
else if (status == StartSubmissionLookupStep.STATUS_NO_SUUID)
|
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));
|
request.setAttribute("no.suuid", new Boolean(true));
|
||||||
|
|
||||||
// reload this page, by re-calling doPreProcessing()
|
// reload this page, by re-calling doPreProcessing()
|
||||||
@@ -239,25 +237,25 @@ public class JSPStartSubmissionLookupStep extends JSPStep
|
|||||||
}
|
}
|
||||||
else if (status == StartSubmissionLookupStep.STATUS_SUBMISSION_EXPIRED)
|
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));
|
request.setAttribute("expired", new Boolean(true));
|
||||||
|
|
||||||
// reload this page, by re-calling doPreProcessing()
|
// reload this page, by re-calling doPreProcessing()
|
||||||
doPreProcessing(context, request, response, subInfo);
|
doPreProcessing(context, request, response, subInfo);
|
||||||
}
|
}
|
||||||
else if (status != StartSubmissionLookupStep.STATUS_COMPLETE)
|
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));
|
request.setAttribute("no.suuid", new Boolean(true));
|
||||||
|
|
||||||
// reload this page, by re-calling doPreProcessing()
|
// reload this page, by re-calling doPreProcessing()
|
||||||
doPreProcessing(context, request, response, subInfo);
|
doPreProcessing(context, request, response, subInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the URL path (e.g. /submit/review-metadata.jsp) of the JSP
|
* Return the URL path (e.g. /submit/review-metadata.jsp) of the JSP which
|
||||||
* which will review the information that was gathered in this Step.
|
* will review the information that was gathered in this Step.
|
||||||
* <P>
|
* <P>
|
||||||
* This Review JSP is loaded by the 'Verify' Step, in order to dynamically
|
* This Review JSP is loaded by the 'Verify' Step, in order to dynamically
|
||||||
* generate a submission verification page consisting of the information
|
* 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,
|
public String getReviewJSP(Context context, HttpServletRequest request,
|
||||||
HttpServletResponse response, SubmissionInfo subInfo)
|
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.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user