Commit 5c8c52e22e9c8a1b044025ad1d338edbca4667bb

Authored by Tiago Guimarães

Merge branch 'RenatesTID' into DSpace52++

# Conflicts:
#	dspace-api/src/main/java/pt/uminho/sdum/dspace/submit/lookup/RenatesService.java
#	dspace/config/spring/api/bte.xml
dspace-api/src/main/java/pt/uminho/sdum/dspace/submit/lookup/RenatesOnlineDataLoader.java
... ... @@ -0,0 +1,51 @@
  1 +package pt.uminho.sdum.dspace.submit.lookup;
  2 +
  3 +import gr.ekt.bte.core.Record;
  4 +import org.apache.http.HttpException;
  5 +import org.dspace.core.Context;
  6 +import org.dspace.submit.lookup.NetworkSubmissionLookupDataLoader;
  7 +
  8 +import java.io.IOException;
  9 +import java.util.*;
  10 +
  11 +/**
  12 + * @author tmmguimaraes on 13/05/2016.
  13 + */
  14 +public class RenatesOnlineDataLoader extends NetworkSubmissionLookupDataLoader {
  15 +
  16 + public final static String TID = "tid";
  17 +
  18 + @Override
  19 + public List<String> getSupportedIdentifiers() {
  20 + return Collections.singletonList(TID);
  21 + }
  22 +
  23 + @Override
  24 + public boolean isSearchProvider() {
  25 + return false;
  26 + }
  27 +
  28 + @Override
  29 + public List<Record> search(Context context, String title, String author, int year) throws HttpException, IOException {
  30 + return null;
  31 + }
  32 +
  33 + @Override
  34 + public List<Record> getByIdentifier(Context context, Map<String, Set<String>> keys) throws HttpException, IOException {
  35 + List<Record> results = new ArrayList<>();
  36 + if (keys != null) {
  37 + Set<String> tids = keys.get(TID);
  38 + List<Record> items = new ArrayList<>();
  39 +
  40 + if (tids != null && tids.size() > 0)
  41 + for (String tid : tids)
  42 + items.add(RenatesService.getByTID(tid));
  43 +
  44 + for (Record item : items)
  45 + if(item != null)
  46 + results.add(convertFields(item));
  47 +
  48 + }
  49 + return results;
  50 + }
  51 +}
... ...
dspace-api/src/main/java/pt/uminho/sdum/dspace/submit/lookup/RenatesService.java
... ... @@ -0,0 +1,84 @@
  1 +package pt.uminho.sdum.dspace.submit.lookup;
  2 +
  3 +/**
  4 + * @author tmmguimaraes on 16/05/2016.
  5 + */
  6 +
  7 +import gr.ekt.bte.core.Record;
  8 +import org.apache.commons.lang.StringUtils;
  9 +import org.apache.http.HttpException;
  10 +import org.apache.http.HttpResponse;
  11 +import org.apache.http.HttpStatus;
  12 +import org.apache.http.StatusLine;
  13 +import org.apache.http.client.HttpClient;
  14 +import org.apache.http.client.methods.HttpGet;
  15 +import org.apache.http.client.utils.URIBuilder;
  16 +import org.apache.http.impl.client.HttpClientBuilder;
  17 +import org.apache.log4j.Logger;
  18 +import org.w3c.dom.Document;
  19 +import org.w3c.dom.Element;
  20 +import org.w3c.dom.Node;
  21 +import org.w3c.dom.NodeList;
  22 +
  23 +import javax.xml.parsers.DocumentBuilder;
  24 +import javax.xml.parsers.DocumentBuilderFactory;
  25 +import java.io.IOException;
  26 +import java.net.URISyntaxException;
  27 +
  28 +public class RenatesService {
  29 + private static Logger log = Logger.getLogger(RenatesService.class);
  30 +
  31 + public static Record getByTID(String tid) throws HttpException, IOException {
  32 +
  33 + if (StringUtils.isNotBlank(tid)) {
  34 + Record r = null;
  35 + tid = tid.trim();
  36 + HttpGet method;
  37 + try {
  38 + HttpClient client = HttpClientBuilder.create().build();
  39 +
  40 + try {
  41 + URIBuilder uriBuilder = new URIBuilder("http://renates.dgeec.mec.pt/ws/renatesws.asmx/Tese");
  42 + uriBuilder.addParameter("tid", tid);
  43 +
  44 + method = new HttpGet(uriBuilder.build());
  45 + //log.warn("URI: " + uriBuilder.build());
  46 + } catch (URISyntaxException ex) {
  47 + throw new HttpException(ex.getMessage());
  48 + }
  49 +
  50 + HttpResponse response = client.execute(method);
  51 +
  52 + StatusLine responseStatus = response.getStatusLine();
  53 + int statusCode = responseStatus.getStatusCode();
  54 + if (statusCode != HttpStatus.SC_OK)
  55 + throw new RuntimeException("Http call failed: " + responseStatus);
  56 +
  57 +
  58 + DocumentBuilderFactory factory = DocumentBuilderFactory
  59 + .newInstance();
  60 + factory.setValidating(false);
  61 + factory.setIgnoringComments(true);
  62 + factory.setIgnoringElementContentWhitespace(true);
  63 +
  64 + DocumentBuilder db = factory.newDocumentBuilder();
  65 + Document inDoc = db.parse(response.getEntity().getContent());
  66 +
  67 + log.warn("indoc: " + inDoc.getXmlVersion());
  68 + inDoc.getDocumentElement().normalize();
  69 +
  70 +
  71 + NodeList nList = inDoc.getElementsByTagName("Table");
  72 + Node nNode = nList.item(0);
  73 + if(nNode.getNodeType() == Node.ELEMENT_NODE )
  74 + r = RenatesUtils.convertRenatesDomToRecord((Element) nNode);
  75 +
  76 +
  77 + }catch (Exception e){
  78 + e.printStackTrace();
  79 + }
  80 + return r;
  81 + }else
  82 + return null;
  83 + }
  84 +}
... ...
dspace-api/src/main/java/pt/uminho/sdum/dspace/submit/lookup/RenatesUtils.java
... ... @@ -0,0 +1,97 @@
  1 +package pt.uminho.sdum.dspace.submit.lookup;
  2 +
  3 +import gr.ekt.bte.core.MutableRecord;
  4 +import gr.ekt.bte.core.Record;
  5 +import gr.ekt.bte.core.StringValue;
  6 +import gr.ekt.bte.core.Value;
  7 +import org.dspace.app.util.XMLUtils;
  8 +import org.dspace.submit.util.SubmissionLookupPublication;
  9 +import org.w3c.dom.Element;
  10 +
  11 +import java.util.LinkedList;
  12 +import java.util.List;
  13 +
  14 +/**
  15 + * @author tmmguimaraes on 16/05/2016.
  16 + */
  17 +public class RenatesUtils {
  18 +
  19 + public static Record convertRenatesDomToRecord(Element dataRoot) {
  20 + MutableRecord record = new SubmissionLookupPublication("");
  21 +
  22 +
  23 + String tid = XMLUtils.getElementValue(dataRoot, "TID");
  24 + String curso = XMLUtils.getElementValue(dataRoot, "Curso");
  25 + String tipoTese = XMLUtils.getElementValue(dataRoot, "TipoTese");
  26 + String title = XMLUtils.getElementValue(dataRoot, "TemaTese");
  27 + String author = XMLUtils.getElementValue(dataRoot, "NomeCompleto");
  28 + String keywords = XMLUtils.getElementValue(dataRoot, "Palavras_chave");
  29 + String dataGrau = XMLUtils.getElementValue(dataRoot,"DataGrau");
  30 +
  31 + List<Value> wordList = new LinkedList<>();
  32 + List<Value> authorValues = new LinkedList<>();
  33 +
  34 + if (tid != null)
  35 + record.addValue("tid", new StringValue(tid));
  36 +
  37 + if (curso != null)
  38 + record.addValue("curso", new StringValue(curso));
  39 +
  40 + String ttese = getThesisType(tipoTese);
  41 + if (ttese != null)
  42 + record.addValue("type", new StringValue(ttese));
  43 +
  44 + if (title != null)
  45 + record.addValue("title", new StringValue(title));
  46 +
  47 + if (author != null) {
  48 + authorValues.add(new StringValue(author.trim()));
  49 + record.addField("authors", authorValues);
  50 + }
  51 + if (keywords!= null) {
  52 + String[] words = keywords.split("[,;]");
  53 + for (String word : words)
  54 + if (!word.isEmpty())
  55 + wordList.add(new StringValue(word.trim()));
  56 + record.addField("keywords", wordList);
  57 + }
  58 +
  59 + if (dataGrau != null)
  60 + record.addValue("issued", new StringValue(formatDate(dataGrau)));
  61 +
  62 + return record;
  63 + }
  64 +
  65 + private static String formatDate(String dataGrau) {
  66 + StringBuilder sb = new StringBuilder();
  67 +
  68 + if(dataGrau.length()==4)
  69 + return dataGrau;
  70 + else if(dataGrau.length()==7){
  71 + sb.append(dataGrau.substring(3));
  72 + sb.append("-");
  73 + sb.append(dataGrau.substring(0,2));
  74 + return sb.toString();
  75 + }else if (dataGrau.length()==10){
  76 + sb.append(dataGrau.substring(6));
  77 + sb.append("-");
  78 + sb.append(dataGrau.substring(3,5));
  79 + sb.append("-");
  80 + sb.append(dataGrau.substring(0,2));
  81 + return sb.toString();
  82 + }else
  83 + return null;
  84 + }
  85 +
  86 + private static String getThesisType(String tipoTese) {
  87 + if (tipoTese == null)
  88 + return null;
  89 + else if(tipoTese.trim().equals("Mestrado"))
  90 + return "masterThesis";
  91 + else if(tipoTese.trim().equals("Doutoramento"))
  92 + return "doctoralThesis";
  93 + else return null;
  94 + }
  95 +
  96 +
  97 +}
... ...
dspace-api/src/main/resources/Messages.properties
... ... @@ -1739,6 +1739,8 @@ jsp.submit.start-lookup-submission.tabs.search = Search Form
1739 1739 jsp.submit.start-lookup-submission.tabs.result = Results
1740 1740 jsp.submit.start-lookup-submission.identifiers = Search for identifier
1741 1741  
  1742 +jsp.submit.start-lookup-submission.identifier-tid = TID da Tese ou Disserta&ccedil&atilde;o
  1743 +jsp.submit.start-lookup-submission.identifier-tid.hint = e.g. 201002744
1742 1744 jsp.submit.start-lookup-submission.identifiers.hints = Fill in publication identifiers (DOI is preferable) and then press "Search". A list of all matching publications will be shown to you to select in order to proceed with the submission process.
1743 1745 jsp.submit.start-lookup-submission.identifier-doi = DOI (Digital Object Identifier)
1744 1746 jsp.submit.start-lookup-submission.identifier-doi.hint = e.g. 10.1021/ac0354342
... ...
dspace-api/src/main/resources/Messages_pt_PT.properties
... ... @@ -76,6 +76,8 @@ document.type.scientific.data = Dados Cient&amp;iacute;ficos
76 76  
77 77  
78 78 ###### Lookup (input-forms.xml ativo)
  79 +jsp.submit.start-lookup-submission.identifier-tid = TID da Tese ou Disserta&ccedil&atilde;o
  80 +jsp.submit.start-lookup-submission.identifier-tid.hint = e.g. 201002744
79 81 jsp.submit.start-lookup-submission.heading = Nova submiss&atilde;o: obter dados bibliogr&aacute;ficos de servi&ccedil;o externo
80 82 jsp.submit.start-lookup-submission.noresult = Sem resultados!
81 83 jsp.submit.start-lookup-submission.select.collection.defaultoption = Selecionar...
... ...
dspace-jspui/src/main/webapp/image/submission-lookup-small-renates.jpg

13.9 KB

dspace/config/spring/api/bte.xml
... ... @@ -109,6 +109,7 @@
109 109 <!-- Specify here any data loaders you want to include in the submission lookup process.
110 110 Dataloaders must either extend the "NetworkSubmissionLookupDataLoader" abstract class
111 111 or conform to "FileDataLoader" interface of BTE -->
  112 + <entry key="renates" value-ref="renatesOnlineDataLoader"/>
112 113 <entry key="pubmed" value-ref="pubmedOnlineDataLoader"/>
113 114 <entry key="crossref" value-ref="crossRefOnlineDataLoader"/>
114 115 <entry key="arxiv" value-ref="arXivOnlineDataLoader"/>
... ... @@ -230,6 +231,8 @@
230 231  
231 232 <property name="extraMetadataToKeep">
232 233 <list>
  234 + <value>dc.identifier.tid</value>
  235 + <value>thesis.degree.name</value>
233 236 <value>dc.import.contributorauthor</value>
234 237 <value>dc.import.contributoreditor</value>
235 238 <value>dc.import.contributortranslator</value>
... ... @@ -344,6 +347,28 @@
344 347 </property>
345 348 </bean>
346 349  
  350 + <!-- Renates TID Online data loader -->
  351 + <bean id="renatesOnlineDataLoader" class="pt.uminho.sdum.dspace.submit.lookup.RenatesOnlineDataLoader">
  352 + <property name="fieldMap" ref="renatesInputMap" />
  353 +
  354 + </bean>
  355 +
  356 + <bean name="renatesInputMap" class="java.util.HashMap" scope="prototype">
  357 + <constructor-arg>
  358 + <map key-type="java.lang.String" value-type="java.lang.String">
  359 +
  360 + <entry key="title" value="title" />
  361 + <entry key="authors" value="authors" />
  362 + <entry key="type" value="subtype" />
  363 + <entry key="keywords" value="mesh" />
  364 + <entry key="tid" value="tid" />
  365 + <entry key="curso" value="curso" />
  366 + <entry key="issued" value="issued" />
  367 +
  368 + </map>
  369 + </constructor-arg>
  370 + </bean>
  371 +
347 372 <!-- OAI Data Loader -->
348 373 <bean id="oaipmhDataLoader" class="gr.ekt.bteio.loaders.OAIPMHDataLoader">
349 374 <property name="fieldMap">
... ... @@ -558,12 +583,15 @@
558 583  
559 584 <!--Added -->
560 585 <!--<entry value="publisher" key="dc.publisher" />--> <!-- Already exists-->
  586 + <entry value="publisher" key="dc.publisher" />
561 587 <entry value="titleAlternative" key="dc.title.alternative" />
562 588 <entry value="firstpage" key="degois.publication.firstPage" />
563 589 <entry value="lastpage" key="degois.publication.lastPage" />
564 590 <entry value="volume" key="degois.publication.volume" />
565 591 <entry value="issue" key="degois.publication.issue" />
566 592 <entry value="mesh" key="dc.subject" />
  593 + <entry value="tid" key="dc.identifier.tid" />
  594 + <entry value="curso" key="thesis.degree.name" />
567 595  
568 596 <!-- Not used - new metadata fields need to be declared for them in DSpace registry -->
569 597 <!--
... ...