Code formatted with DSpace conventions

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

View File

@@ -41,34 +41,42 @@ import gr.ekt.bte.exceptions.MalformedSourceException;
* @author Panagiotis Koutsourakis
*
*/
public class ArXivFileDataLoader extends FileDataLoader {
public class ArXivFileDataLoader extends FileDataLoader
{
private static Logger log = Logger.getLogger(ArXivFileDataLoader.class);
Map<String, String> fieldMap; //mapping between service fields and local intermediate fields
Map<String, String> fieldMap; // mapping between service fields and local
// intermediate fields
/**
* Empty constructor
*/
public ArXivFileDataLoader() {
public ArXivFileDataLoader()
{
}
/**
* @param filename
*/
public ArXivFileDataLoader(String filename) {
public ArXivFileDataLoader(String filename)
{
super(filename);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see gr.ekt.bte.core.DataLoader#getRecords()
*/
@Override
public RecordSet getRecords() throws MalformedSourceException {
public RecordSet getRecords() throws MalformedSourceException
{
RecordSet recordSet = new RecordSet();
try {
try
{
InputStream inputStream = new FileInputStream(new File(filename));
DocumentBuilderFactory factory = DocumentBuilderFactory
@@ -81,8 +89,7 @@ public class ArXivFileDataLoader extends FileDataLoader {
Document inDoc = db.parse(inputStream);
Element xmlRoot = inDoc.getDocumentElement();
List<Element> dataRoots = XMLUtils.getElementList(xmlRoot,
"entry");
List<Element> dataRoots = XMLUtils.getElementList(xmlRoot, "entry");
for (Element dataRoot : dataRoots)
{
@@ -92,43 +99,62 @@ public class ArXivFileDataLoader extends FileDataLoader {
recordSet.addRecord(convertFields(record));
}
}
} catch (FileNotFoundException e) {
}
catch (FileNotFoundException e)
{
log.error(e.getMessage(), e);
} catch (ParserConfigurationException e) {
}
catch (ParserConfigurationException e)
{
log.error(e.getMessage(), e);
} catch (SAXException e) {
}
catch (SAXException e)
{
log.error(e.getMessage(), e);
} catch (IOException e) {
}
catch (IOException e)
{
log.error(e.getMessage(), e);
}
return recordSet;
}
/* (non-Javadoc)
* @see gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
/*
* (non-Javadoc)
*
* @see
* gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
*/
@Override
public RecordSet getRecords(DataLoadingSpec spec)
throws MalformedSourceException {
throws MalformedSourceException
{
return getRecords();
}
public Record convertFields(Record publication) {
for (String fieldName : fieldMap.keySet()) {
public Record convertFields(Record publication)
{
for (String fieldName : fieldMap.keySet())
{
String md = null;
if (fieldMap!=null){
if (fieldMap != null)
{
md = this.fieldMap.get(fieldName);
}
if (StringUtils.isBlank(md)) {
if (StringUtils.isBlank(md))
{
continue;
} else {
}
else
{
md = md.trim();
}
if (publication.isMutable()){
if (publication.isMutable())
{
List<Value> values = publication.getValues(fieldName);
publication.makeMutable().removeField(fieldName);
publication.makeMutable().addField(md, values);
@@ -138,7 +164,8 @@ public class ArXivFileDataLoader extends FileDataLoader {
return publication;
}
public void setFieldMap(Map<String, String> fieldMap) {
public void setFieldMap(Map<String, String> fieldMap)
{
this.fieldMap = fieldMap;
}
}

View File

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

View File

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

View File

@@ -30,9 +30,11 @@ import org.w3c.dom.Element;
* @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("");
String articleTitle = XMLUtils.getElementValue(dataRoot, "title");
@@ -51,14 +53,13 @@ public class ArxivUtils {
if (comment != null)
record.addValue("comment", new StringValue(comment));
List<Element> links = XMLUtils.getElementList(dataRoot, "link");
if (links != null)
{
for (Element link : links)
{
if ("related".equals(link.getAttribute("rel")) && "pdf".equals(link.getAttribute("title")))
if ("related".equals(link.getAttribute("rel"))
&& "pdf".equals(link.getAttribute("title")))
{
String pdfUrl = link.getAttribute("href");
if (pdfUrl != null)
@@ -70,30 +71,36 @@ public class ArxivUtils {
String doi = XMLUtils.getElementValue(dataRoot, "arxiv:doi");
if (doi != null)
record.addValue("doi", new StringValue(doi));
String journalRef = XMLUtils.getElementValue(dataRoot, "arxiv:journal_ref");
String journalRef = XMLUtils.getElementValue(dataRoot,
"arxiv:journal_ref");
if (journalRef != null)
record.addValue("journalRef", new StringValue(journalRef));
List<String> primaryCategory = new LinkedList<String>();
List<Element> primaryCategoryList = XMLUtils.getElementList(dataRoot, "arxiv:primary_category");
List<Element> primaryCategoryList = XMLUtils.getElementList(dataRoot,
"arxiv:primary_category");
if (primaryCategoryList != null)
{
for (Element primaryCategoryElement : primaryCategoryList)
{
primaryCategory.add(primaryCategoryElement.getAttribute("term"));
primaryCategory
.add(primaryCategoryElement.getAttribute("term"));
}
}
if (primaryCategory.size()>0){
if (primaryCategory.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String s : primaryCategory){
for (String s : primaryCategory)
{
values.add(new StringValue(s));
}
record.addField("primaryCategory", values);
}
List<String> category = new LinkedList<String>();
List<Element> categoryList = XMLUtils.getElementList(dataRoot, "category");
List<Element> categoryList = XMLUtils.getElementList(dataRoot,
"category");
if (categoryList != null)
{
for (Element categoryElement : categoryList)
@@ -102,9 +109,11 @@ public class ArxivUtils {
}
}
if (category.size()>0){
if (category.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String s : category){
for (String s : category)
{
values.add(new StringValue(s));
}
record.addField("category", values);
@@ -158,9 +167,11 @@ public class ArxivUtils {
}
}
if (authors.size()>0){
if (authors.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String[] sArray : authors){
for (String[] sArray : authors)
{
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
}
record.addField("authors", values);

View File

@@ -39,35 +39,44 @@ import gr.ekt.bte.exceptions.MalformedSourceException;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class CrossRefFileDataLoader extends FileDataLoader {
public class CrossRefFileDataLoader extends FileDataLoader
{
Map<String, String> fieldMap; //mapping between service fields and local intermediate fields
Map<String, String> fieldMap; // mapping between service fields and local
// intermediate fields
/**
*
*/
public CrossRefFileDataLoader() {
public CrossRefFileDataLoader()
{
}
/**
* @param filename
*/
public CrossRefFileDataLoader(String filename) {
public CrossRefFileDataLoader(String filename)
{
super(filename);
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see gr.ekt.bte.core.DataLoader#getRecords()
*/
@Override
public RecordSet getRecords() throws MalformedSourceException {
public RecordSet getRecords() throws MalformedSourceException
{
RecordSet recordSet = new RecordSet();
try {
try
{
InputStream inputStream = new FileInputStream(new File(filename));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
@@ -81,13 +90,21 @@ public class CrossRefFileDataLoader extends FileDataLoader {
Record record = CrossRefUtils.convertCrossRefDomToRecord(dataRoot);
recordSet.addRecord(convertFields(record));
} catch (FileNotFoundException e) {
}
catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (ParserConfigurationException e) {
}
catch (ParserConfigurationException e)
{
e.printStackTrace();
} catch (SAXException e) {
}
catch (SAXException e)
{
e.printStackTrace();
} catch (IOException e) {
}
catch (IOException e)
{
e.printStackTrace();
}
@@ -95,30 +112,41 @@ public class CrossRefFileDataLoader extends FileDataLoader {
}
/* (non-Javadoc)
* @see gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
/*
* (non-Javadoc)
*
* @see
* gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
*/
@Override
public RecordSet getRecords(DataLoadingSpec spec)
throws MalformedSourceException {
throws MalformedSourceException
{
return getRecords();
}
public Record convertFields(Record publication) {
for (String fieldName : fieldMap.keySet()) {
public Record convertFields(Record publication)
{
for (String fieldName : fieldMap.keySet())
{
String md = null;
if (fieldMap!=null){
if (fieldMap != null)
{
md = this.fieldMap.get(fieldName);
}
if (StringUtils.isBlank(md)) {
if (StringUtils.isBlank(md))
{
continue;
} else {
}
else
{
md = md.trim();
}
if (publication.isMutable()){
if (publication.isMutable())
{
List<Value> values = publication.getValues(fieldName);
publication.makeMutable().removeField(fieldName);
publication.makeMutable().addField(md, values);
@@ -128,7 +156,8 @@ public class CrossRefFileDataLoader extends FileDataLoader {
return publication;
}
public void setFieldMap(Map<String, String> fieldMap) {
public void setFieldMap(Map<String, String> fieldMap)
{
this.fieldMap = fieldMap;
}
}

View File

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

View File

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

View File

@@ -29,20 +29,24 @@ import org.w3c.dom.Element;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class CrossRefUtils {
public class CrossRefUtils
{
/**
*
*/
public CrossRefUtils() {
public CrossRefUtils()
{
// TODO Auto-generated constructor stub
}
public static Record convertCrossRefDomToRecord(Element dataRoot) {
public static Record convertCrossRefDomToRecord(Element dataRoot)
{
MutableRecord record = new SubmissionLookupPublication("");
String status = dataRoot.getAttribute("status");
if (!"resolved".equals(status)) {
if (!"resolved".equals(status))
{
String msg = XMLUtils.getElementValue(dataRoot, "msg");
String exMsg = status + " - " + msg;
throw new RuntimeException(exMsg);
@@ -58,13 +62,17 @@ public class CrossRefUtils {
record.addValue("itemType", new StringValue(itemType));
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"))) {
|| StringUtils.isNotBlank(ident.getAttribute("type")))
{
String issn = ident.getTextContent().trim();
if (issn != null)
record.addValue("issn", new StringValue(issn));
} else {
}
else
{
String eissn = ident.getTextContent().trim();
if (eissn != null)
record.addValue("eissn", new StringValue(eissn));
@@ -131,58 +139,75 @@ public class CrossRefUtils {
List<Element> contributors = XMLUtils.getElementList(dataRoot,
"contributors");
List<Element> contributor = null;
if (contributors != null && contributors.size() > 0) {
if (contributors != null && contributors.size() > 0)
{
contributor = XMLUtils.getElementList(contributors.get(0),
"contributor");
for (Element contrib : contributor) {
for (Element contrib : contributor)
{
String givenName = XMLUtils.getElementValue(contrib,
"given_name");
String surname = XMLUtils.getElementValue(contrib, "surname");
if ("editor".equalsIgnoreCase(contrib
.getAttribute("contributor_role"))) {
.getAttribute("contributor_role")))
{
editors.add(new String[] { givenName, surname });
} else if ("chair".equalsIgnoreCase(contrib
.getAttribute("contributor_role"))) {
}
else if ("chair".equalsIgnoreCase(contrib
.getAttribute("contributor_role")))
{
chairs.add(new String[] { givenName, surname });
} else if ("translator".equalsIgnoreCase(contrib
.getAttribute("contributor_role"))) {
}
else if ("translator".equalsIgnoreCase(contrib
.getAttribute("contributor_role")))
{
translators.add(new String[] { givenName, surname });
} else {
}
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) {
for (String[] sArray : authors)
{
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) {
for (String[] sArray : editors)
{
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) {
for (String[] sArray : translators)
{
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) {
for (String[] sArray : chairs)
{
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
}
record.addField("chairs", values);

View File

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

View File

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

View File

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

View File

@@ -26,10 +26,13 @@ import gr.ekt.bte.core.Value;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class MapConverterModifier extends AbstractModifier {
public class MapConverterModifier extends AbstractModifier
{
String filename; // The properties filename
Map<String, String> mapping;
String defaultValue = "";
List<String> fieldKeys;
@@ -41,24 +44,33 @@ public class MapConverterModifier extends AbstractModifier {
/**
* @param name
*/
public MapConverterModifier(String name) {
public MapConverterModifier(String name)
{
super(name);
}
/* (non-Javadoc)
* @see gr.ekt.bte.core.AbstractModifier#modify(gr.ekt.bte.core.MutableRecord)
/*
* (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){
public Record modify(MutableRecord record)
{
if (mapping != null && fieldKeys != null)
{
for (String key : fieldKeys)
{
List<Value> values = record.getValues(key);
if (values==null) continue;
if (values == null)
continue;
List<Value> newValues = new ArrayList<Value>();
for (Value value : values){
for (Value value : values)
{
String stringValue = value.getAsString();
String tmp = "";
@@ -71,9 +83,11 @@ public class MapConverterModifier extends AbstractModifier {
tmp = defaultValue;
for (String regex : regexConfig.keySet())
{
if (stringValue != null && stringValue.matches(regex))
if (stringValue != null
&& stringValue.matches(regex))
{
tmp = stringValue.replaceAll(regex, regexConfig.get(regex));
tmp = stringValue.replaceAll(regex,
regexConfig.get(regex));
}
}
}
@@ -97,7 +111,8 @@ public class MapConverterModifier extends AbstractModifier {
return record;
}
public void setMapping(Map<String, String> mapping) {
public void setMapping(Map<String, String> mapping)
{
this.mapping = mapping;
for (String keyS : mapping.keySet())
@@ -119,15 +134,18 @@ public class MapConverterModifier extends AbstractModifier {
}
}
public void setFilename(String filename) {
public void setFilename(String filename)
{
this.filename = filename;
}
public void setFieldKeys(List<String> fieldKeys) {
public void setFieldKeys(List<String> fieldKeys)
{
this.fieldKeys = fieldKeys;
}
public void setDefaultValue(String defaultValue) {
public void setDefaultValue(String defaultValue)
{
this.defaultValue = defaultValue;
}
}

View File

@@ -31,72 +31,104 @@ import gr.ekt.bte.exceptions.MalformedSourceException;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class MultipleSubmissionLookupDataLoader implements DataLoader {
public class MultipleSubmissionLookupDataLoader implements DataLoader
{
private static Logger log = Logger.getLogger(MultipleSubmissionLookupDataLoader.class);
private static Logger log = Logger
.getLogger(MultipleSubmissionLookupDataLoader.class);
private static final String NOT_FOUND_DOI = "NOT-FOUND-DOI";
Map<String, DataLoader> dataloadersMap;
//Depending on these values, the multiple data loader loads data from the appropriate providers
Map<String, Set<String>> identifiers = null; //Searching by identifiers (DOI ...)
Map<String, Set<String>> searchTerms = null; //Searching by author, title, date
// Depending on these values, the multiple data loader loads data from the
// appropriate providers
Map<String, Set<String>> identifiers = null; // Searching by identifiers
// (DOI ...)
Map<String, Set<String>> searchTerms = null; // Searching by author, title,
// date
String filename = null; // Uploading file
String type = null; // the type of the upload file (bibtex, etc.)
/**
* Default constructor
*/
public MultipleSubmissionLookupDataLoader() {
public MultipleSubmissionLookupDataLoader()
{
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see gr.ekt.bte.core.DataLoader#getRecords()
*/
@Override
public RecordSet getRecords() throws MalformedSourceException {
public RecordSet getRecords() throws MalformedSourceException
{
RecordSet recordSet = new RecordSet();
// KSTA:ToDo: Support timeout (problematic) providers
// List<String> timeoutProviders = new ArrayList<String>();
for (String providerName : filterProviders().keySet()) {
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));
// 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?
//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
// 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);
for (Record publication : recordSet.getRecords())
{
String providerName = SubmissionLookupUtils.getFirstValue(
publication,
SubmissionLookupService.PROVIDER_NAME_FIELD);
String doi = null;
if (publication.getValues(SubmissionLookupDataLoader.DOI) != null && publication.getValues(SubmissionLookupDataLoader.DOI).size()>0)
doi = publication.getValues(SubmissionLookupDataLoader.DOI).iterator().next().getAsString();
if (doi == null) {
if (publication.getValues(SubmissionLookupDataLoader.DOI) != null
&& publication
.getValues(SubmissionLookupDataLoader.DOI)
.size() > 0)
doi = publication.getValues(SubmissionLookupDataLoader.DOI)
.iterator().next().getAsString();
if (doi == null)
{
doi = NOT_FOUND_DOI;
} else {
}
else
{
doi = SubmissionLookupUtils.normalizeDOI(doi);
if (!foundDOIs.contains(doi))
{
foundDOIs.add(doi);
}
Set<String> tmp = provider2foundDOIs.get(providerName);
if (tmp == null) {
if (tmp == null)
{
tmp = new HashSet<String>();
provider2foundDOIs.put(providerName, tmp);
}
@@ -104,17 +136,21 @@ public class MultipleSubmissionLookupDataLoader implements DataLoader {
}
}
for (String providerName : dataloadersMap.keySet()) {
for (String providerName : dataloadersMap.keySet())
{
DataLoader genProvider = dataloadersMap.get(providerName);
if (! (genProvider instanceof SubmissionLookupDataLoader)){
if (!(genProvider instanceof SubmissionLookupDataLoader))
{
continue;
}
SubmissionLookupDataLoader provider = (SubmissionLookupDataLoader) genProvider;
// Provider must support DOI
if (provider.getSupportedIdentifiers().contains(SubmissionLookupDataLoader.DOI)){
if (provider.getSupportedIdentifiers().contains(
SubmissionLookupDataLoader.DOI))
{
continue;
}
@@ -123,49 +159,63 @@ public class MultipleSubmissionLookupDataLoader implements DataLoader {
// continue;
// }
Set<String> doiToSearch = new HashSet<String>();
Set<String> alreadyFoundDOIs = provider2foundDOIs.get(providerName);
for (String doi : foundDOIs) {
Set<String> alreadyFoundDOIs = provider2foundDOIs
.get(providerName);
for (String doi : foundDOIs)
{
if (alreadyFoundDOIs == null
|| !alreadyFoundDOIs.contains(doi)) {
|| !alreadyFoundDOIs.contains(doi))
{
doiToSearch.add(doi);
}
}
List<Record> pPublications = null;
try {
if (doiToSearch.size() > 0) {
pPublications = provider
.getByDOIs(null, doiToSearch);
try
{
if (doiToSearch.size() > 0)
{
pPublications = provider.getByDOIs(null, doiToSearch);
}
} catch (Exception e) {
}
catch (Exception e)
{
e.printStackTrace();
}
if (pPublications != null) {
for (Record rec : pPublications){
if (pPublications != null)
{
for (Record rec : pPublications)
{
recordSet.addRecord(rec);
}
}
}
}
log.info("BTE DataLoader finished. Items loaded: " + recordSet.getRecords().size());
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";
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)
/*
* (non-Javadoc)
*
* @see
* gr.ekt.bte.core.DataLoader#getRecords(gr.ekt.bte.core.DataLoadingSpec)
*/
@Override
public RecordSet getRecords(DataLoadingSpec loadingSpec)
throws MalformedSourceException {
throws MalformedSourceException
{
if (loadingSpec.getOffset() > 0) // Identify the end of loading
return new RecordSet();
@@ -173,79 +223,107 @@ public class MultipleSubmissionLookupDataLoader implements DataLoader {
return getRecords();
}
public Map<String, DataLoader> getProvidersMap() {
public Map<String, DataLoader> getProvidersMap()
{
return dataloadersMap;
}
public void setDataloadersMap(Map<String, DataLoader> providersMap) {
public void setDataloadersMap(Map<String, DataLoader> providersMap)
{
this.dataloadersMap = providersMap;
}
public void setIdentifiers(Map<String, Set<String>> identifiers) {
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()) {
if (dataloadersMap != null)
{
for (String providerName : dataloadersMap.keySet())
{
DataLoader provider = dataloadersMap.get(providerName);
if (provider instanceof NetworkSubmissionLookupDataLoader){
((NetworkSubmissionLookupDataLoader)provider).setIdentifiers(identifiers);
if (provider instanceof NetworkSubmissionLookupDataLoader)
{
((NetworkSubmissionLookupDataLoader) provider)
.setIdentifiers(identifiers);
}
}
}
}
public void setSearchTerms(Map<String, Set<String>> searchTerms) {
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()) {
if (dataloadersMap != null)
{
for (String providerName : dataloadersMap.keySet())
{
DataLoader provider = dataloadersMap.get(providerName);
if (provider instanceof NetworkSubmissionLookupDataLoader){
((NetworkSubmissionLookupDataLoader)provider).setSearchTerms(searchTerms);
if (provider instanceof NetworkSubmissionLookupDataLoader)
{
((NetworkSubmissionLookupDataLoader) provider)
.setSearchTerms(searchTerms);
}
}
}
}
public void setFile(String filename, String type) {
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()) {
if (dataloadersMap != null)
{
for (String providerName : dataloadersMap.keySet())
{
DataLoader provider = dataloadersMap.get(providerName);
if (provider instanceof FileDataLoader){
if (provider instanceof FileDataLoader)
{
((FileDataLoader) provider).setFilename(filename);
}
}
}
}
public Map<String, DataLoader> filterProviders(){
public Map<String, DataLoader> filterProviders()
{
Map<String, DataLoader> result = new HashMap<String, DataLoader>();
for (String providerName : dataloadersMap.keySet()) {
for (String providerName : dataloadersMap.keySet())
{
DataLoader dataLoader = dataloadersMap.get(providerName);
if (searchTerms != null && identifiers == null && filename == null){
if (dataLoader instanceof SubmissionLookupDataLoader &&
((SubmissionLookupDataLoader)dataLoader).isSearchProvider()){
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){
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
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);
}
}

View File

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

View File

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

View File

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

View File

@@ -39,18 +39,21 @@ import org.xml.sax.SAXException;
* @author Luigi Andrea Pascarelli
* @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) {
public void setTimeout(int timeout)
{
this.timeout = timeout;
}
public Record getByPubmedID(String pubmedid) throws HttpException,
IOException, ParserConfigurationException, SAXException {
IOException, ParserConfigurationException, SAXException
{
List<String> ids = new ArrayList<String>();
ids.add(pubmedid.trim());
List<Record> items = getByPubmedIDs(ids);
@@ -62,14 +65,17 @@ public class PubmedService {
}
public List<Record> search(String title, String author, int year)
throws HttpException, IOException {
throws HttpException, IOException
{
StringBuffer query = new StringBuffer();
if (StringUtils.isNotBlank(title)) {
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)) {
if (StringUtils.isNotBlank(author))
{
// [FAU]
if (query.length() > 0)
query.append(" AND ");
@@ -85,12 +91,14 @@ public class PubmedService {
return search(query.toString());
}
public List<Record> search(String query) throws IOException,
HttpException {
public List<Record> search(String query) throws IOException, HttpException
{
List<Record> results = null;
if (!ConfigurationManager.getBooleanProperty("remoteservice.demo")) {
if (!ConfigurationManager.getBooleanProperty("remoteservice.demo"))
{
GetMethod method = null;
try {
try
{
HttpClient client = new HttpClient();
client.setTimeout(timeout);
method = new GetMethod(
@@ -106,9 +114,9 @@ public class PubmedService {
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
throw new RuntimeException(
"WS call failed: "
if (statusCode != HttpStatus.SC_OK)
{
throw new RuntimeException("WS call failed: "
+ method.getStatusLine());
}
@@ -119,7 +127,8 @@ public class PubmedService {
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilder builder;
try {
try
{
builder = factory.newDocumentBuilder();
Document inDoc = builder.parse(method
@@ -131,20 +140,29 @@ public class PubmedService {
List<String> pubmedIDs = XMLUtils.getElementValueList(
idList, "Id");
results = getByPubmedIDs(pubmedIDs);
} catch (ParserConfigurationException e) {
}
catch (ParserConfigurationException e)
{
e.printStackTrace();
}
catch (SAXException e1) {
catch (SAXException e1)
{
log.error(e1.getMessage(), e1);
}
} finally {
if (method != null) {
}
finally
{
if (method != null)
{
method.releaseConnection();
}
}
} else {
}
else
{
InputStream stream = null;
try {
try
{
File file = new File(
ConfigurationManager.getProperty("dspace.dir")
+ "/config/crosswalks/demo/pubmed-search.xml");
@@ -163,13 +181,21 @@ public class PubmedService {
List<String> pubmedIDs = XMLUtils.getElementValueList(idList,
"Id");
results = getByPubmedIDs(pubmedIDs);
} catch (Exception e) {
}
catch (Exception e)
{
throw new RuntimeException(e.getMessage(), e);
} finally {
if (stream != null) {
try {
}
finally
{
if (stream != null)
{
try
{
stream.close();
} catch (IOException e) {
}
catch (IOException e)
{
e.printStackTrace();
}
}
@@ -179,11 +205,15 @@ public class PubmedService {
}
public List<Record> getByPubmedIDs(List<String> pubmedIDs)
throws HttpException, IOException, ParserConfigurationException, SAXException {
throws HttpException, IOException, ParserConfigurationException,
SAXException
{
List<Record> results = new ArrayList<Record>();
if (!ConfigurationManager.getBooleanProperty("remoteservice.demo")) {
if (!ConfigurationManager.getBooleanProperty("remoteservice.demo"))
{
GetMethod method = null;
try {
try
{
HttpClient client = new HttpClient();
client.setTimeout(5 * timeout);
method = new GetMethod(
@@ -192,57 +222,72 @@ public class PubmedService {
NameValuePair db = new NameValuePair("db", "pubmed");
NameValuePair retmode = new NameValuePair("retmode", "xml");
NameValuePair rettype = new NameValuePair("rettype", "full");
NameValuePair id = new NameValuePair("id", StringUtils.join(pubmedIDs.iterator(), ","));
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);
if (statusCode != HttpStatus.SC_OK) {
throw new RuntimeException(
"WS call failed: "
if (statusCode != HttpStatus.SC_OK)
{
throw new RuntimeException("WS call failed: "
+ method.getStatusLine());
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document inDoc = builder.parse(method.getResponseBodyAsStream());
Document inDoc = builder
.parse(method.getResponseBodyAsStream());
Element xmlRoot = inDoc.getDocumentElement();
List<Element> pubArticles = XMLUtils
.getElementList(xmlRoot, "PubmedArticle");
List<Element> pubArticles = XMLUtils.getElementList(xmlRoot,
"PubmedArticle");
for (Element xmlArticle : pubArticles)
{
Record pubmedItem = null;
try {
pubmedItem = PubmedUtils.convertCrossRefDomToRecord(xmlArticle);
try
{
pubmedItem = PubmedUtils
.convertCrossRefDomToRecord(xmlArticle);
results.add(pubmedItem);
} catch (Exception e) {
}
catch (Exception e)
{
throw new RuntimeException(
"PubmedID is not valid or not exist: "+e.getMessage(), e);
"PubmedID is not valid or not exist: "
+ e.getMessage(), e);
}
}
return results;
} finally {
if (method != null) {
}
finally
{
if (method != null)
{
method.releaseConnection();
}
}
} else {
}
else
{
InputStream stream = null;
try {
try
{
File file = new File(
ConfigurationManager.getProperty("dspace.dir")
+ "/config/crosswalks/demo/pubmed.xml");
stream = new FileInputStream(file);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
factory.setIgnoringElementContentWhitespace(true);
@@ -251,39 +296,53 @@ public class PubmedService {
Document inDoc = builder.parse(stream);
Element xmlRoot = inDoc.getDocumentElement();
List<Element> pubArticles = XMLUtils
.getElementList(xmlRoot, "PubmedArticle");
List<Element> pubArticles = XMLUtils.getElementList(xmlRoot,
"PubmedArticle");
for (Element xmlArticle : pubArticles)
{
Record pubmedItem = null;
try {
pubmedItem = PubmedUtils.convertCrossRefDomToRecord(xmlArticle);
try
{
pubmedItem = PubmedUtils
.convertCrossRefDomToRecord(xmlArticle);
results.add(pubmedItem);
} catch (Exception e) {
}
catch (Exception e)
{
throw new RuntimeException(
"PubmedID is not valid or not exist: "+e.getMessage(), e);
"PubmedID is not valid or not exist: "
+ e.getMessage(), e);
}
}
return results;
} catch (Exception e) {
}
catch (Exception e)
{
throw new RuntimeException(e.getMessage(), e);
} finally {
if (stream != null) {
}
finally
{
if (stream != null)
{
stream.close();
}
}
}
}
public List<Record> search(String doi, String pmid) throws HttpException, IOException {
public List<Record> search(String doi, String pmid) throws HttpException,
IOException
{
StringBuffer query = new StringBuffer();
if (StringUtils.isNotBlank(doi)) {
if (StringUtils.isNotBlank(doi))
{
query.append(doi);
query.append("[AID]");
}
if (StringUtils.isNotBlank(pmid)) {
if (StringUtils.isNotBlank(pmid))
{
// [FAU]
if (query.length() > 0)
query.append(" OR ");

View File

@@ -31,9 +31,11 @@ import org.w3c.dom.Element;
* @author Luigi Andrea Pascarelli
* @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("");
Map<String, String> mounthToNum = new HashMap<String, String>();
@@ -50,15 +52,18 @@ public class PubmedUtils {
mounthToNum.put("Nov", "11");
mounthToNum.put("Dec", "12");
Element medline = XMLUtils.getSingleElement(pubArticle, "MedlineCitation");
Element medline = XMLUtils.getSingleElement(pubArticle,
"MedlineCitation");
Element article = XMLUtils.getSingleElement(medline, "Article");
Element pubmed = XMLUtils.getSingleElement(pubArticle, "PubmedData");
Element identifierList = XMLUtils.getSingleElement(pubmed, "ArticleIdList");
Element identifierList = XMLUtils.getSingleElement(pubmed,
"ArticleIdList");
if (identifierList != null)
{
List<Element> identifiers = XMLUtils.getElementList(identifierList, "ArticleId");
List<Element> identifiers = XMLUtils.getElementList(identifierList,
"ArticleId");
if (identifiers != null)
{
for (Element id : identifiers)
@@ -67,7 +72,8 @@ public class PubmedUtils {
{
String pubmedID = id.getTextContent().trim();
if (pubmedID != null)
record.addValue("pubmedID", new StringValue(pubmedID));
record.addValue("pubmedID", new StringValue(
pubmedID));
}
else if ("doi".equals(id.getAttribute("IdType")))
{
@@ -83,22 +89,27 @@ public class PubmedUtils {
if (status != null)
record.addValue("status", new StringValue(status));
String pubblicationModel = XMLUtils.getElementAttribute(medline, "Article", "PubModel");
String pubblicationModel = XMLUtils.getElementAttribute(medline,
"Article", "PubModel");
if (pubblicationModel != null)
record.addValue("pubblicationModel", new StringValue(pubblicationModel));
record.addValue("pubblicationModel", new StringValue(
pubblicationModel));
String title = XMLUtils.getElementValue(article, "ArticleTitle");
if (title != null)
record.addValue("title", new StringValue(title));
Element abstractElement = XMLUtils.getSingleElement(medline, "Abstract");
Element abstractElement = XMLUtils
.getSingleElement(medline, "Abstract");
if (abstractElement == null)
{
abstractElement = XMLUtils.getSingleElement(medline, "OtherAbstract");
abstractElement = XMLUtils.getSingleElement(medline,
"OtherAbstract");
}
if (abstractElement != null)
{
String summary = XMLUtils.getElementValue(abstractElement, "AbstractText");
String summary = XMLUtils.getElementValue(abstractElement,
"AbstractText");
if (summary != null)
record.addValue("summary", new StringValue(summary));
}
@@ -107,21 +118,27 @@ public class PubmedUtils {
Element authorList = XMLUtils.getSingleElement(article, "AuthorList");
if (authorList != null)
{
List<Element> authorsElement = XMLUtils.getElementList(authorList, "Author");
List<Element> authorsElement = XMLUtils.getElementList(authorList,
"Author");
if (authorsElement != null)
{
for (Element author : authorsElement)
{
if (StringUtils.isBlank(XMLUtils.getElementValue(author, "CollectiveName")))
if (StringUtils.isBlank(XMLUtils.getElementValue(author,
"CollectiveName")))
{
authors.add(new String[]{XMLUtils.getElementValue(author, "ForeName"),XMLUtils.getElementValue(author, "LastName")});
authors.add(new String[] {
XMLUtils.getElementValue(author, "ForeName"),
XMLUtils.getElementValue(author, "LastName") });
}
}
}
}
if (authors.size()>0){
if (authors.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String[] sArray : authors){
for (String[] sArray : authors)
{
values.add(new StringValue(sArray[1] + ", " + sArray[0]));
}
record.addField("authors", values);
@@ -154,27 +171,34 @@ public class PubmedUtils {
if (journalTitle != null)
record.addValue("journalTitle", new StringValue(journalTitle));
Element journalIssueElement = XMLUtils.getSingleElement(journal, "JournalIssue");
Element journalIssueElement = XMLUtils.getSingleElement(journal,
"JournalIssue");
if (journalIssueElement != null)
{
String volume = XMLUtils.getElementValue(journalIssueElement, "Volume");
String volume = XMLUtils.getElementValue(journalIssueElement,
"Volume");
if (volume != null)
record.addValue("volume", new StringValue(volume));
String issue = XMLUtils.getElementValue(journalIssueElement, "Issue");
String issue = XMLUtils.getElementValue(journalIssueElement,
"Issue");
if (issue != null)
record.addValue("issue", new StringValue(issue));
Element pubDataElement = XMLUtils.getSingleElement(journalIssueElement, "PubDate");
Element pubDataElement = XMLUtils.getSingleElement(
journalIssueElement, "PubDate");
String year = null;
if (pubDataElement != null)
{
year = XMLUtils.getElementValue(pubDataElement, "Year");
String mounth = XMLUtils.getElementValue(pubDataElement, "Month");
String day = XMLUtils.getElementValue(pubDataElement, "Day");
if (StringUtils.isNotBlank(mounth) && mounthToNum.containsKey(mounth))
String mounth = XMLUtils.getElementValue(pubDataElement,
"Month");
String day = XMLUtils
.getElementValue(pubDataElement, "Day");
if (StringUtils.isNotBlank(mounth)
&& mounthToNum.containsKey(mounth))
{
year += "-" + mounthToNum.get(mounth);
if (StringUtils.isNotBlank(day))
@@ -192,18 +216,22 @@ public class PubmedUtils {
record.addValue("language", new StringValue(language));
List<String> type = new LinkedList<String>();
Element publicationTypeList = XMLUtils.getSingleElement(article, "PublicationTypeList");
Element publicationTypeList = XMLUtils.getSingleElement(article,
"PublicationTypeList");
if (publicationTypeList != null)
{
List<Element> publicationTypes = XMLUtils.getElementList(publicationTypeList, "PublicationType");
List<Element> publicationTypes = XMLUtils.getElementList(
publicationTypeList, "PublicationType");
for (Element publicationType : publicationTypes)
{
type.add(publicationType.getTextContent().trim());
}
}
if (type.size()>0){
if (type.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String s : type){
for (String s : type)
{
values.add(new StringValue(s));
}
record.addField("type", values);
@@ -211,10 +239,12 @@ public class PubmedUtils {
List<String> primaryKeywords = new LinkedList<String>();
List<String> secondaryKeywords = new LinkedList<String>();
Element keywordsList = XMLUtils.getSingleElement(medline, "KeywordList");
Element keywordsList = XMLUtils.getSingleElement(medline,
"KeywordList");
if (keywordsList != null)
{
List<Element> keywords = XMLUtils.getElementList(keywordsList, "Keyword");
List<Element> keywords = XMLUtils.getElementList(keywordsList,
"Keyword");
for (Element keyword : keywords)
{
if ("Y".equals(keyword.getAttribute("MajorTopicYN")))
@@ -227,16 +257,20 @@ public class PubmedUtils {
}
}
}
if (primaryKeywords.size()>0){
if (primaryKeywords.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String s : primaryKeywords){
for (String s : primaryKeywords)
{
values.add(new StringValue(s));
}
record.addField("primaryKeywords", values);
}
if (secondaryKeywords.size()>0){
if (secondaryKeywords.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String s : secondaryKeywords){
for (String s : secondaryKeywords)
{
values.add(new StringValue(s));
}
record.addField("secondaryKeywords", values);
@@ -244,45 +278,58 @@ public class PubmedUtils {
List<String> primaryMeshHeadings = new LinkedList<String>();
List<String> secondaryMeshHeadings = new LinkedList<String>();
Element meshHeadingsList = XMLUtils.getSingleElement(medline, "MeshHeadingList");
Element meshHeadingsList = XMLUtils.getSingleElement(medline,
"MeshHeadingList");
if (meshHeadingsList != null)
{
List<Element> meshHeadings = XMLUtils.getElementList(meshHeadingsList, "MeshHeading");
List<Element> meshHeadings = XMLUtils.getElementList(
meshHeadingsList, "MeshHeading");
for (Element meshHeading : meshHeadings)
{
if ("Y".equals(XMLUtils.getElementAttribute(meshHeading, "DescriptorName", "MajorTopicYN")))
if ("Y".equals(XMLUtils.getElementAttribute(meshHeading,
"DescriptorName", "MajorTopicYN")))
{
primaryMeshHeadings.add(XMLUtils.getElementValue(meshHeading, "DescriptorName"));
primaryMeshHeadings.add(XMLUtils.getElementValue(
meshHeading, "DescriptorName"));
}
else
{
secondaryMeshHeadings.add(XMLUtils.getElementValue(meshHeading, "DescriptorName"));
secondaryMeshHeadings.add(XMLUtils.getElementValue(
meshHeading, "DescriptorName"));
}
}
}
if (primaryMeshHeadings.size()>0){
if (primaryMeshHeadings.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String s : primaryMeshHeadings){
for (String s : primaryMeshHeadings)
{
values.add(new StringValue(s));
}
record.addField("primaryMeshHeadings", values);
}
if (secondaryMeshHeadings.size()>0){
if (secondaryMeshHeadings.size() > 0)
{
List<Value> values = new LinkedList<Value>();
for (String s : secondaryMeshHeadings){
for (String s : secondaryMeshHeadings)
{
values.add(new StringValue(s));
}
record.addField("secondaryMeshHeadings", values);
}
Element paginationElement = XMLUtils.getSingleElement(article, "Pagination");
Element paginationElement = XMLUtils.getSingleElement(article,
"Pagination");
if (paginationElement != null)
{
String startPage = XMLUtils.getElementValue(paginationElement, "StartPage");
String endPage = XMLUtils.getElementValue(paginationElement, "EndPage");
String startPage = XMLUtils.getElementValue(paginationElement,
"StartPage");
String endPage = XMLUtils.getElementValue(paginationElement,
"EndPage");
if (StringUtils.isBlank(startPage))
{
startPage = XMLUtils.getElementValue(paginationElement, "MedlinePgn");
startPage = XMLUtils.getElementValue(paginationElement,
"MedlinePgn");
}
if (startPage != null)

View File

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

View File

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

View File

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

View File

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

View File

@@ -28,7 +28,8 @@ import org.dspace.submit.util.SubmissionLookupDTO;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class SubmissionLookupService {
public class SubmissionLookupService
{
public static final String SL_NAMESPACE_PREFIX = "http://www.dspace.org/sl/";
@@ -47,52 +48,65 @@ public class SubmissionLookupService {
private Map<String, List<String>> idents2provs;
private List<String> searchProviders;
private List<String> fileProviders;
private TransformationEngine phase1TransformationEngine;
private TransformationEngine phase2TransformationEngine;
public void setPhase2TransformationEngine(TransformationEngine phase2TransformationEngine) {
public void setPhase2TransformationEngine(
TransformationEngine phase2TransformationEngine)
{
this.phase2TransformationEngine = phase2TransformationEngine;
}
public void setPhase1TransformationEngine(TransformationEngine phase1TransformationEngine) {
public void setPhase1TransformationEngine(
TransformationEngine phase1TransformationEngine)
{
this.phase1TransformationEngine = phase1TransformationEngine;
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader)phase1TransformationEngine.getDataLoader();
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) {
if (providers == null)
{
this.providers = new ArrayList<DataLoader>();
for (String providerName : dataLoader.getProvidersMap().keySet()) {
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){
if (p instanceof FileDataLoader)
{
this.fileProviders.add(providerName);
}
else if (p instanceof NetworkSubmissionLookupDataLoader){
else if (p instanceof NetworkSubmissionLookupDataLoader)
{
NetworkSubmissionLookupDataLoader p2 = (NetworkSubmissionLookupDataLoader) p;
p2.setProviderName(providerName);
if (p2.isSearchProvider()) {
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) {
if (suppIdentifiers != null)
{
for (String ident : suppIdentifiers)
{
List<String> tmp = idents2provs.get(ident);
if (tmp == null)
{
tmp = new ArrayList<String>();
idents2provs.put(ident, tmp);
}
@@ -104,23 +118,33 @@ public class SubmissionLookupService {
}
}
public TransformationEngine getPhase1TransformationEngine() {
public TransformationEngine getPhase1TransformationEngine()
{
return phase1TransformationEngine;
}
public TransformationEngine getPhase2TransformationEngine() {
public TransformationEngine getPhase2TransformationEngine()
{
return phase2TransformationEngine;
}
public List<String> getIdentifiers() {
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)){
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);
}
}
@@ -130,49 +154,61 @@ public class SubmissionLookupService {
return allSupportedIdentifiers;
}
public Map<String, List<String>> getProvidersIdentifiersMap() {
public Map<String, List<String>> getProvidersIdentifiersMap()
{
return idents2provs;
}
public SubmissionLookupDTO getSubmissionLookupDTO(
HttpServletRequest request, String uuidSubmission) {
HttpServletRequest request, String uuidSubmission)
{
SubmissionLookupDTO dto = (SubmissionLookupDTO) request.getSession()
.getAttribute("submission_lookup_" + uuidSubmission);
if (dto == null) {
if (dto == null)
{
dto = new SubmissionLookupDTO();
storeDTOs(request, uuidSubmission, dto);
}
return dto;
}
public void invalidateDTOs(HttpServletRequest request, String uuidSubmission) {
public void invalidateDTOs(HttpServletRequest request, String uuidSubmission)
{
request.getSession().removeAttribute(
"submission_lookup_" + uuidSubmission);
}
public void storeDTOs(HttpServletRequest request, String uuidSubmission,
SubmissionLookupDTO dto) {
SubmissionLookupDTO dto)
{
request.getSession().setAttribute(
"submission_lookup_" + uuidSubmission, dto);
}
public List<String> getSearchProviders() {
public List<String> getSearchProviders()
{
return searchProviders;
}
public List<DataLoader> getProviders() {
public List<DataLoader> getProviders()
{
return providers;
}
public static String getProviderName(Record rec) {
return SubmissionLookupUtils.getFirstValue(rec, SubmissionLookupService.PROVIDER_NAME_FIELD);
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 static String getType(Record rec)
{
return SubmissionLookupUtils.getFirstValue(rec,
SubmissionLookupDataLoader.TYPE);
}
public List<String> getFileProviders() {
public List<String> getFileProviders()
{
return this.fileProviders;
}
}

View File

@@ -28,7 +28,8 @@ import org.dspace.core.Context;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class SubmissionLookupUtils {
public class SubmissionLookupUtils
{
private static Logger log = Logger.getLogger(SubmissionLookupUtils.class);
/** Location of config file */
@@ -43,18 +44,23 @@ public class SubmissionLookupUtils {
.compile(".*\\((.*)\\)");
public static LookupProvidersCheck getProvidersCheck(Context context,
Item item, String dcSchema, String dcElement, String dcQualifier) {
try {
Item item, String dcSchema, String dcElement, String dcQualifier)
{
try
{
LookupProvidersCheck check = new LookupProvidersCheck();
MetadataSchema[] schemas = MetadataSchema.findAll(context);
DCValue[] values = item.getMetadata(dcSchema, dcElement, dcQualifier, Item.ANY);
DCValue[] values = item.getMetadata(dcSchema, dcElement,
dcQualifier, Item.ANY);
for (MetadataSchema schema : schemas)
{
boolean error = false;
if (schema.getNamespace().startsWith(SubmissionLookupService.SL_NAMESPACE_PREFIX))
if (schema.getNamespace().startsWith(
SubmissionLookupService.SL_NAMESPACE_PREFIX))
{
DCValue[] slCache = item.getMetadata(schema.getName(), dcElement, dcQualifier, Item.ANY);
DCValue[] slCache = item.getMetadata(schema.getName(),
dcElement, dcQualifier, Item.ANY);
if (slCache.length == 0)
continue;
@@ -88,14 +94,17 @@ public class SubmissionLookupUtils {
}
}
return check;
} catch (Exception e) {
}
catch (Exception e)
{
log.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
}
public static String normalizeDOI(String doi) {
public static String normalizeDOI(String doi)
{
if (doi != null)
{
return doi.trim().replaceAll("^http://dx.doi.org/", "")
@@ -105,35 +114,43 @@ public class SubmissionLookupUtils {
}
public static String getFirstValue(Record rec, String field) {
public static String getFirstValue(Record rec, String field)
{
List<Value> values = rec.getValues(field);
String value = null;
if (values != null && values.size() > 0) {
if (values != null && values.size() > 0)
{
value = values.get(0).getAsString();
}
return value;
}
public static List<String> getValues(Record rec, String field) {
public static List<String> getValues(Record rec, String field)
{
List<String> result = new ArrayList<String>();
List<Value> values = rec.getValues(field);
if (values != null && values.size() > 0) {
for (Value value : values){
if (values != null && values.size() > 0)
{
for (Value value : values)
{
result.add(value.getAsString());
}
}
return result;
}
public static String getPrintableString(Record record){
public static String getPrintableString(Record record)
{
StringBuilder result = new StringBuilder();
result.append("\nPublication {\n");
for (String field: record.getFields()){
for (String field : record.getFields())
{
result.append("--" + field + ":\n");
List<Value> values = record.getValues(field);
for (Value value : values){
for (Value value : values)
{
result.append("\t" + value.getAsString() + "\n");
}
}

View File

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

View File

@@ -7,7 +7,6 @@
*/
package org.dspace.submit.step;
import edu.emory.mathcs.backport.java.util.Arrays;
import gr.ekt.bte.core.Record;
import gr.ekt.bte.core.TransformationEngine;
import gr.ekt.bte.core.TransformationSpec;
@@ -26,7 +25,6 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hwpf.model.Ffn;
import org.dspace.app.util.DCInputSet;
import org.dspace.app.util.DCInputsReader;
import org.dspace.app.util.SubmissionInfo;
@@ -45,19 +43,23 @@ import org.dspace.submit.util.SubmissionLookupPublication;
import org.dspace.utils.DSpace;
/**
* SelectCollection Step which processes the collection that the user selected
* in that step of the DSpace Submission process
* <P>
* This class performs all the behind-the-scenes processing that
* this particular step requires. This class's methods are utilized
* by both the JSP-UI and the Manakin XML-UI
* StartSubmissionLookupStep is used when you want enabled the user to auto fill
* the item in submission with metadata retrieved from external bibliographic
* services (like pubmed, arxiv, and so on...)
*
* <p>
* At the moment this step is only available for JSPUI
* </p>
*
* @see org.dspace.app.util.SubmissionConfig
* @see org.dspace.app.util.SubmissionStepConfig
* @see org.dspace.submit.AbstractProcessingStep
*
* @author Tim Donohue
* @version $Revision: 3738 $
* @author Andrea Bollini
* @author Kostas Stamatis
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
* @version $Revision$
*/
public class StartSubmissionLookupStep extends AbstractProcessingStep
{
@@ -84,7 +86,8 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
SubmissionLookupService.class);
/** log4j logger */
private static Logger log = Logger.getLogger(StartSubmissionLookupStep.class);
private static Logger log = Logger
.getLogger(StartSubmissionLookupStep.class);
/**
* Do any processing of the information input by the user, and/or perform
@@ -137,10 +140,13 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
}
ItemSubmissionLookupDTO itemLookup = null;
if (fuuidLookup == null || fuuidLookup.isEmpty()) {
if (StringUtils.isNotBlank(uuidLookup)) {
if (fuuidLookup == null || fuuidLookup.isEmpty())
{
if (StringUtils.isNotBlank(uuidLookup))
{
itemLookup = submissionDTO.getLookupItem(uuidLookup);
if (itemLookup == null) {
if (itemLookup == null)
{
return STATUS_SUBMISSION_EXPIRED;
}
}
@@ -164,9 +170,12 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
{
// create our new Workspace Item
DCInputSet inputSet = null;
try {
try
{
inputSet = new DCInputsReader().getInputs(col.getHandle());
} catch (Exception e) {
}
catch (Exception e)
{
e.printStackTrace();
}
@@ -175,16 +184,22 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
if (itemLookup != null)
{
dto.add(itemLookup);
} else if (fuuidLookup != null) {
}
else if (fuuidLookup != null)
{
String[] ss = fuuidLookup.split(",");
for(String s : ss) {
for (String s : ss)
{
itemLookup = submissionDTO.getLookupItem(s);
if (itemLookup == null) {
if (itemLookup == null)
{
return STATUS_SUBMISSION_EXPIRED;
}
dto.add(itemLookup);
}
} else {
}
else
{
SubmissionLookupPublication manualPub = new SubmissionLookupPublication(
SubmissionLookupService.MANUAL_USER_INPUT);
manualPub.add("title", titolo);
@@ -193,15 +208,17 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
Enumeration e = request.getParameterNames();
while (e.hasMoreElements()) {
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);
&& StringUtils.isNotBlank(parameterValue))
{
manualPub
.add(parameterName.substring("identifier_"
.length()), parameterValue);
}
}
List<Record> publications = new ArrayList<Record>();
@@ -212,29 +229,39 @@ public class StartSubmissionLookupStep extends AbstractProcessingStep
List<WorkspaceItem> result = null;
TransformationEngine transformationEngine = slService.getPhase2TransformationEngine();
if (transformationEngine != null){
SubmissionItemDataLoader dataLoader = (SubmissionItemDataLoader)transformationEngine.getDataLoader();
TransformationEngine transformationEngine = slService
.getPhase2TransformationEngine();
if (transformationEngine != null)
{
SubmissionItemDataLoader dataLoader = (SubmissionItemDataLoader) transformationEngine
.getDataLoader();
dataLoader.setDtoList(dto);
// dataLoader.setProviders()
DSpaceWorkspaceItemOutputGenerator outputGenerator = (DSpaceWorkspaceItemOutputGenerator)transformationEngine.getOutputGenerator();
DSpaceWorkspaceItemOutputGenerator outputGenerator = (DSpaceWorkspaceItemOutputGenerator) transformationEngine
.getOutputGenerator();
outputGenerator.setCollection(col);
outputGenerator.setContext(context);
outputGenerator.setFormName(inputSet.getFormName());
outputGenerator.setDto(dto.get(0));
try {
try
{
transformationEngine.transform(new TransformationSpec());
result = outputGenerator.getWitems();
} catch (BadTransformationSpec e1) {
}
catch (BadTransformationSpec e1)
{
e1.printStackTrace();
} catch (MalformedSourceException e1) {
}
catch (MalformedSourceException e1)
{
e1.printStackTrace();
}
}
if (result != null && result.size()>0) {
if (result != null && result.size() > 0)
{
// update Submission Information with this Workspace Item
subInfo.setSubmissionItem(result.iterator().next());
}

View File

@@ -28,25 +28,31 @@ import org.dspace.submit.lookup.SubmissionLookupService;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class ItemSubmissionLookupDTO implements Serializable {
public class ItemSubmissionLookupDTO implements Serializable
{
private static final long serialVersionUID = 1;
private static final String MERGED_PUBLICATION_PROVIDER = "merged";
private static final String UNKNOWN_PROVIDER_STRING = "UNKNOWN-PROVIDER";
private List<Record> publications;
private String uuid;
public ItemSubmissionLookupDTO(List<Record> publications) {
public ItemSubmissionLookupDTO(List<Record> publications)
{
this.uuid = UUID.randomUUID().toString();
this.publications = publications;
}
public List<Record> getPublications() {
public List<Record> getPublications()
{
return publications;
}
public Set<String> getProviders() {
public Set<String> getProviders()
{
Set<String> orderedProviders = new LinkedHashSet<String>();
for (Record p : publications)
{
@@ -55,11 +61,13 @@ public class ItemSubmissionLookupDTO implements Serializable {
return orderedProviders;
}
public String getUUID() {
public String getUUID()
{
return uuid;
}
public Record getTotalPublication(List<DataLoader> providers) {
public Record getTotalPublication(List<DataLoader> providers)
{
if (publications == null)
{
return null;
@@ -70,12 +78,14 @@ public class ItemSubmissionLookupDTO implements Serializable {
}
else
{
MutableRecord pub = new SubmissionLookupPublication(MERGED_PUBLICATION_PROVIDER);
MutableRecord pub = new SubmissionLookupPublication(
MERGED_PUBLICATION_PROVIDER);
// for (SubmissionLookupProvider prov : providers)
// {
for (Record p : publications)
{
//if (!SubmissionLookupService.getProviderName(p).equals(prov.getShortName()))
// if
// (!SubmissionLookupService.getProviderName(p).equals(prov.getShortName()))
// {
// continue;
// }

View File

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

View File

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

View File

@@ -62,7 +62,8 @@ import com.google.gson.JsonObject;
* @author Luigi Andrea Pascarelli
* @author Panagiotis Koutsourakis
*/
public class SubmissionLookupJSONRequest extends JSONRequest {
public class SubmissionLookupJSONRequest extends JSONRequest
{
private SubmissionLookupService service = new DSpace().getServiceManager()
.getServiceByName(SubmissionLookupService.class.getName(),
@@ -73,22 +74,26 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
@Override
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");
SubmissionLookupDTO subDTO = service.getSubmissionLookupDTO(req, suuid);
// Check that we have a file upload request
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
if ("identifiers".equalsIgnoreCase(req.getParameter("type"))) {
if ("identifiers".equalsIgnoreCase(req.getParameter("type")))
{
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);
if (parameterName.startsWith("identifier_")
&& StringUtils.isNotBlank(parameterValue)) {
&& StringUtils.isNotBlank(parameterValue))
{
Set<String> set = new HashSet<String>();
set.add(parameterValue);
identifiers.put(
@@ -101,12 +106,14 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
TransformationEngine transformationEngine = service
.getPhase1TransformationEngine();
if (transformationEngine != null) {
if (transformationEngine != null)
{
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
.getDataLoader();
dataLoader.setIdentifiers(identifiers);
try {
try
{
log.debug("BTE transformation is about to start!");
transformationEngine.transform(new TransformationSpec());
log.debug("BTE transformation finished!");
@@ -114,9 +121,13 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
.getOutputGenerator();
result = outputGenerator.getDtoList();
} catch (BadTransformationSpec e1) {
}
catch (BadTransformationSpec e1)
{
log.error(e1.getMessage(), e1);
} catch (MalformedSourceException e1) {
}
catch (MalformedSourceException e1)
{
log.error(e1.getMessage(), e1);
}
}
@@ -129,7 +140,9 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
jo.add("result", tree);
resp.getWriter().write(jo.toString());
} else if ("search".equalsIgnoreCase(req.getParameter("type"))) {
}
else if ("search".equalsIgnoreCase(req.getParameter("type")))
{
String title = req.getParameter("title");
String author = req.getParameter("authors");
int year = UIUtil.getIntParameter(req, "year");
@@ -149,20 +162,26 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
TransformationEngine transformationEngine = service
.getPhase1TransformationEngine();
if (transformationEngine != null) {
if (transformationEngine != null)
{
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
.getDataLoader();
dataLoader.setSearchTerms(searchTerms);
try {
try
{
transformationEngine.transform(new TransformationSpec());
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
.getOutputGenerator();
result = outputGenerator.getDtoList();
} catch (BadTransformationSpec e1) {
}
catch (BadTransformationSpec e1)
{
log.error(e1.getMessage(), e1);
} catch (MalformedSourceException e1) {
}
catch (MalformedSourceException e1)
{
log.error(e1.getMessage(), e1);
}
}
@@ -174,7 +193,9 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
JsonObject jo = new JsonObject();
jo.add("result", tree);
resp.getWriter().write(jo.toString());
} else if ("details".equalsIgnoreCase(req.getParameter("type"))) {
}
else if ("details".equalsIgnoreCase(req.getParameter("type")))
{
String i_uuid = req.getParameter("i_uuid");
Map<String, Object> dto = getDetails(subDTO.getLookupItem(i_uuid),
context);
@@ -182,7 +203,9 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
JsonObject jo = new JsonObject();
jo.add("result", tree);
resp.getWriter().write(jo.toString());
} else if (isMultipart) {
}
else if (isMultipart)
{
// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();
@@ -196,19 +219,26 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
// Parse the request
List<FileItem> iter;
String filename = null;
try {
try
{
iter = upload.parseRequest(req);
for(FileItem item : iter) {
for (FileItem item : iter)
{
String name = item.getFieldName();
InputStream stream = item.getInputStream();
if (item.isFormField()) {
if (item.isFormField())
{
String value = Streams.asString(stream);
valueMap.put(name, value);
} else {
}
else
{
io = stream;
}
}
} catch (FileUploadException e) {
}
catch (FileUploadException e)
{
throw new IOException(e);
}
@@ -219,27 +249,38 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
TransformationEngine transformationEngine = service
.getPhase1TransformationEngine();
if (transformationEngine != null) {
if (transformationEngine != null)
{
MultipleSubmissionLookupDataLoader dataLoader = (MultipleSubmissionLookupDataLoader) transformationEngine
.getDataLoader();
String tempDir = (ConfigurationManager.getProperty("upload.temp.dir") != null)
? ConfigurationManager.getProperty("upload.temp.dir") : System.getProperty("java.io.tmpdir");
File file = new File(tempDir + System.getProperty("file.separator") + "submissionlookup-loader.temp");
String tempDir = (ConfigurationManager
.getProperty("upload.temp.dir") != null) ? ConfigurationManager
.getProperty("upload.temp.dir") : System
.getProperty("java.io.tmpdir");
File file = new File(tempDir
+ System.getProperty("file.separator")
+ "submissionlookup-loader.temp");
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(file));
Utils.bufferedCopy(io, out);
dataLoader.setFile(file.getAbsolutePath(), valueMap.get("provider_loader"));
dataLoader.setFile(file.getAbsolutePath(),
valueMap.get("provider_loader"));
try {
try
{
transformationEngine.transform(new TransformationSpec());
SubmissionLookupOutputGenerator outputGenerator = (SubmissionLookupOutputGenerator) transformationEngine
.getOutputGenerator();
result = outputGenerator.getDtoList();
} catch (BadTransformationSpec e1) {
}
catch (BadTransformationSpec e1)
{
log.error(e1.getMessage(), e1);
} catch (MalformedSourceException e1) {
}
catch (MalformedSourceException e1)
{
log.error(e1.getMessage(), e1);
}
@@ -248,15 +289,13 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
subDTO.setItems(result);
service.storeDTOs(req, suuid, subDTO);
List<Map<String, Object>> dto = getLightResultList(result);
if (valueMap.containsKey("skip_loader")) {
if (valueMap.get("skip_loader").equals("true")) {
if (valueMap.containsKey("skip_loader"))
{
if (valueMap.get("skip_loader").equals("true"))
{
Map<String, Object> skip = new HashMap<String, Object>();
skip.put(
"skip",
Boolean.TRUE);
skip.put(
"uuid",
valueMap.containsKey("s_uuid") ? suuid
skip.put("skip", Boolean.TRUE);
skip.put("uuid", valueMap.containsKey("s_uuid") ? suuid
: -1);
skip.put(
"collectionid",
@@ -274,19 +313,25 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
}
private Map<String, Object> getDetails(ItemSubmissionLookupDTO item,
Context context) {
Context context)
{
List<String> fieldOrder = getFieldOrderFromConfiguration();
Record totalData = item.getTotalPublication(service.getProviders());
Set<String> availableFields = totalData.getFields();
List<String[]> fieldsLabels = new ArrayList<String[]>();
for (String f : fieldOrder) {
if (availableFields.contains(f)) {
try {
for (String f : fieldOrder)
{
if (availableFields.contains(f))
{
try
{
fieldsLabels.add(new String[] {
f,
I18nUtil.getMessage("jsp.submission-lookup.detail."
+ f, context) });
} catch (MissingResourceException e) {
}
catch (MissingResourceException e)
{
fieldsLabels.add(new String[] { f, f });
}
}
@@ -296,8 +341,10 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
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));
for (String field : pub.getFields())
{
publication1
.put(field, SubmissionLookupUtils.getValues(pub, field));
}
data.put("uuid", uuid);
@@ -307,16 +354,20 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
return data;
}
private List<String> getFieldOrderFromConfiguration() {
private List<String> getFieldOrderFromConfiguration()
{
String config = ConfigurationManager
.getProperty("submission-lookup.detail.fields");
if (config == null) {
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)) {
for (String s : split)
{
if (StringUtils.isNotBlank(s))
{
result.add(s.trim());
}
}
@@ -324,10 +375,13 @@ public class SubmissionLookupJSONRequest extends JSONRequest {
}
private List<Map<String, Object>> getLightResultList(
List<ItemSubmissionLookupDTO> result) {
List<ItemSubmissionLookupDTO> result)
{
List<Map<String, Object>> publications = new ArrayList<Map<String, Object>>();
if (result != null && result.size() > 0) {
for (ItemSubmissionLookupDTO item : result) {
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>();

View File

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