forked from spgroup/rgms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finalização da funcionalidade Importação de arquivos Bibtex
- Loading branch information
1 parent
589fec2
commit 95bbfa3
Showing
12 changed files
with
298 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
grails-app/controllers/rgms/publication/BibtexFileController.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package rgms.publication | ||
|
||
import org.springframework.web.multipart.MultipartHttpServletRequest; | ||
import org.springframework.web.multipart.commons.CommonsMultipartFile; | ||
|
||
/** | ||
* | ||
* @author Diogo Vinícius | ||
* | ||
*/ | ||
class BibtexFileController { | ||
|
||
def index() {} | ||
|
||
def upload () { | ||
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest )request | ||
CommonsMultipartFile cmf = (CommonsMultipartFile)multiRequest.getFile("file") | ||
byte[] bytes = cmf.bytes | ||
File file = new File("web-app//uploads//temp.bibtex") | ||
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)) | ||
bos.write(bytes) | ||
bos.close() | ||
|
||
System.out.println("********** " + file.getBytes().size()); | ||
|
||
BibtexFile bibtexFile = transform(file) | ||
|
||
System.out.println("********** " + bibtexFile.getPublications().size()) | ||
for (Publication publication : bibtexFile.getPublications()) { | ||
System.out.println("************* " + publication); | ||
System.out.println("************************** School : " + publication.getSchool()); | ||
System.out.println("************************** Address: " + publication.getAddress()); | ||
System.out.println("************************** Title : " + publication.getTitle()); | ||
System.out.println("************************** Date : " + publication.getPublicationDate()); | ||
if (publication.save(failOnError: true)) { | ||
System.out.println("salvando o objeto"); | ||
} | ||
} | ||
redirect(action: "home") | ||
|
||
} | ||
|
||
def home () { | ||
|
||
} | ||
|
||
def BibtexFile transform(file) { | ||
return new BibtexFile(file) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package rgms.publication | ||
|
||
import java.util.Collection; | ||
|
||
import java.io.BufferedReader | ||
import java.io.File; | ||
import java.io.FileInputStream | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader | ||
import java.io.Reader; | ||
import java.util.ArrayList | ||
import java.util.List | ||
|
||
import org.jbibtex.BibTeXEntry; | ||
import org.jbibtex.Value; | ||
import org.jbibtex.BibTeXDatabase; | ||
import org.jbibtex.BibTeXEntry; | ||
import org.jbibtex.BibTeXParser; | ||
import org.jbibtex.BibTeXString; | ||
import org.jbibtex.Key; | ||
import org.jbibtex.ParseException; | ||
|
||
import rgms.member.Member | ||
|
||
/** | ||
* | ||
* @author Diogo Vinícius | ||
* | ||
*/ | ||
class BibtexFile { | ||
|
||
List<Publication> publications = new ArrayList<Publication>() | ||
Member member | ||
|
||
public BibtexFile(file) { | ||
publications = BibtexParse.generatePublications(file) | ||
} | ||
|
||
public List<Publication> getPublications() { | ||
return this.publications | ||
} | ||
|
||
public List getPublications(Class clazz) { | ||
List publicationsFiltered = new ArrayList() | ||
for (Publication publication : this.getPublications()) { | ||
if (publication.getClass().getName().equals(clazz.getName())) { | ||
publicationsFiltered.add(publication) | ||
} | ||
} | ||
return publicationsFiltered | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package rgms.publication | ||
|
||
import org.jbibtex.BibTeXDatabase | ||
import org.jbibtex.BibTeXEntry; | ||
import org.jbibtex.BibTeXParser | ||
import org.jbibtex.BibTeXString | ||
import org.jbibtex.Key | ||
import org.jbibtex.ParseException | ||
import org.jbibtex.Value | ||
|
||
/** | ||
* | ||
* @author Diogo Vinícius | ||
* | ||
*/ | ||
class BibtexParse { | ||
|
||
public static List<Publication> generatePublications(File file) { | ||
List<Publication> publications = new ArrayList<Publication>() | ||
BibTeXDatabase bibtexDatabase = parseBibTeX(file) | ||
Collection<BibTeXEntry> entries = bibtexDatabase.getEntries().values(); | ||
|
||
for(BibTeXEntry entry : entries){ | ||
//TODO settar todos os atributos de acordo com a classe a ser instanciada | ||
//Para pegar os valores do objeto 'entry' basta seguir o modelo da linha abaixo | ||
//String value = entry.getField(BibTeXEntry.KEY_TITLE).toUserString(); | ||
if (entry.getType().equals(BibTeXEntry.TYPE_ARTICLE)) { | ||
|
||
} | ||
else if (entry.getType().equals(BibTeXEntry.TYPE_BOOK)) { | ||
publications.add(new BookChapter()) | ||
} | ||
else if (entry.getType().equals(BibTeXEntry.TYPE_BOOKLET)) { | ||
|
||
} | ||
else if (entry.getType().equals(BibTeXEntry.TYPE_CONFERENCE)) { | ||
publications.add(new Conferencia()) | ||
} | ||
else if (entry.getType().equals(BibTeXEntry.TYPE_INBOOK)) { | ||
|
||
} | ||
else if (entry.getType().equals(BibTeXEntry.TYPE_INCOLLECTION)) { | ||
|
||
} | ||
else if (entry.getType().equals(BibTeXEntry.TYPE_INPROCEEDINGS)) { | ||
|
||
} | ||
else if (entry.getType().equals(BibTeXEntry.TYPE_MANUAL)) { | ||
|
||
} | ||
else if (entry.getType().equals(BibTeXEntry.TYPE_MASTERSTHESIS)) { | ||
Dissertacao dissertacao = new Dissertacao() | ||
dissertacao.setTitle(entry.getField(BibTeXEntry.KEY_TITLE).toUserString()) | ||
dissertacao.setSchool(entry.getField(BibTeXEntry.KEY_SCHOOL).toUserString()) | ||
dissertacao.setAddress(entry.getField(BibTeXEntry.KEY_ADDRESS).toUserString()) | ||
dissertacao.setPublicationDate(new Date())//TODO transformar o date para setar no objeto | ||
dissertacao.setFile("file")//TODO tirar a obrigatoriedade. futuramente processar a url para importar | ||
publications.add(dissertacao) | ||
} | ||
else if (entry.getType().equals(BibTeXEntry.TYPE_MISC)) { | ||
|
||
} | ||
else if (entry.getType().equals(BibTeXEntry.TYPE_PHDTHESIS)) { | ||
Tese tese = new Tese() | ||
tese.setTitle(entry.getField(BibTeXEntry.KEY_TITLE).toUserString()) | ||
tese.setSchool(entry.getField(BibTeXEntry.KEY_SCHOOL).toUserString()) | ||
tese.setAddress(entry.getField(BibTeXEntry.KEY_ADDRESS).toUserString()) | ||
tese.setPublicationDate(new Date())//TODO transformar o date para setar no objeto | ||
tese.setFile("file")//TODO settar corretamente este atributo | ||
publications.add(tese) | ||
} | ||
else if (entry.getType().equals(BibTeXEntry.TYPE_PROCEEDINGS)) { | ||
|
||
} | ||
else if (entry.getType().equals(BibTeXEntry.TYPE_TECHREPORT)) { | ||
publications.add(new TechnicalReport()) | ||
} | ||
else if (entry.getType().equals(BibTeXEntry.TYPE_UNPUBLISHED)) { | ||
|
||
} | ||
|
||
} | ||
|
||
return publications | ||
|
||
} | ||
|
||
private static BibTeXDatabase parseBibTeX(File file) throws IOException, ParseException { | ||
Reader reader = new FileReader(file); | ||
|
||
try { | ||
BibTeXParser parser = new BibTeXParser(){ | ||
|
||
@Override | ||
public void checkStringResolution(Key key, BibTeXString string){ | ||
|
||
if(string == null){ | ||
System.err.println("Unresolved string: \"" + key.getValue() + "\""); | ||
} | ||
} | ||
|
||
@Override | ||
public void checkCrossReferenceResolution(Key key, BibTeXEntry entry){ | ||
|
||
if(entry == null){ | ||
System.err.println("Unresolved cross-reference: \"" + key.getValue() + "\""); | ||
} | ||
} | ||
}; | ||
|
||
return parser.parse(reader); | ||
} finally { | ||
reader.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%@ page contentType="text/html;charset=UTF-8" %> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> | ||
<meta name="layout" content="main"/> | ||
<title>Insert title here</title> | ||
</head> | ||
<body> | ||
<div class="body"> | ||
<br /> | ||
<g:form controller="BibtexFileController" method="post" action="upload" enctype="multipart/form-data"> | ||
<input type="file" name="file" /> | ||
<input type="submit" /> | ||
</g:form> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,59 @@ | ||
import junit.framework.Test; | ||
import rgms.publication.*; | ||
import cucumber.runtime.PendingException; | ||
import rgms.publication.BibtexFile; | ||
import static cucumber.api.groovy.EN.* | ||
|
||
//You can implement missing steps with the snippets below: | ||
Given(~'^I am on Import Bibtex File Menu$') { -> | ||
// Express the Regexp above with the code you wish you had | ||
throw new PendingException() | ||
} | ||
|
||
When(~'^I click "([^"]*)"$') { String arg1 -> | ||
// Express the Regexp above with the code you wish you had | ||
throw new PendingException() | ||
} | ||
|
||
When(~'^selected a bibtex file and I click "([^"]*)"$') { String arg1 -> | ||
// Express the Regexp above with the code you wish you had | ||
throw new PendingException() | ||
} | ||
|
||
Then(~'^is created all corresponding publications$') { -> | ||
// Express the Regexp above with the code you wish you had | ||
throw new PendingException() | ||
BibtexFileController bibtexFileController = new BibtexFileController() | ||
BibtexFile bibtexFile = bibtexFileController.transform(new File("test//cucumber//steps//sample.bibtex")) | ||
assert bibtexFile.getPublications().size() == 3 | ||
} | ||
|
||
Then(~'^all of then are stored$') { -> | ||
// Express the Regexp above with the code you wish you had | ||
throw new PendingException() | ||
} | ||
|
||
When(~'^selected a bibtex file unformatted and I click "([^"]*)"$') { String arg1 -> | ||
// Express the Regexp above with the code you wish you had | ||
throw new PendingException() | ||
} | ||
|
||
//@Test(expected=RuntimeException.class) | ||
Then(~'^the system output the message error "([^"]*)"$') { String arg1 -> | ||
// Express the Regexp above with the code you wish you had | ||
throw new PendingException() | ||
BibtexFileController bibtexFileController = new BibtexFileController() | ||
BibtexFile bibtexFile = bibtexFileController.transform(new File("test//cucumber//steps//sample.bibtex")) | ||
} | ||
|
||
Then(~'^none publication is stored$') { -> | ||
// Express the Regexp above with the code you wish you had | ||
throw new PendingException() | ||
} | ||
|
||
When(~'^selected a bibtex file with one Book Chapter and two Technical Report and I click "([^"]*)"$') { String arg1 -> | ||
// Express the Regexp above with the code you wish you had | ||
throw new PendingException() | ||
When(~'^selected a bibtex file with one Dissertacao and two Tese and I click "([^"]*)"$') { String arg1 -> | ||
} | ||
|
||
Then(~'^is created one Book Chapter publication$') { -> | ||
// Express the Regexp above with the code you wish you had | ||
throw new PendingException() | ||
Then(~'^is created one Dissertacao publication$') { -> | ||
BibtexFileController bibtexFileController = new BibtexFileController() | ||
BibtexFile bibtexFile = bibtexFileController.transform(new File("test//cucumber//steps//sample.bibtex")) | ||
assert bibtexFile.getPublications(Conferencia.class).isEmpty() | ||
assert bibtexFile.getPublications(Dissertacao.class).size() == 1 | ||
} | ||
|
||
Then(~'^is created two Technical Report publications$') { -> | ||
// Express the Regexp above with the code you wish you had | ||
throw new PendingException() | ||
Then(~'^is created two Tese publications$') { -> | ||
BibtexFileController bibtexFileController = new BibtexFileController() | ||
BibtexFile bibtexFile = bibtexFileController.transform(new File("test//cucumber//steps//sample.bibtex")) | ||
assert bibtexFile.getPublications(TechnicalReport.class).isEmpty() | ||
assert bibtexFile.getPublications(Tese.class).size() == 2 | ||
} | ||
|
||
Then(~'^one Book Chapter is stored and two Technical Report is stored$') { -> | ||
// Express the Regexp above with the code you wish you had | ||
throw new PendingException() | ||
Then(~'^one Dissertacao is stored and two Tese is stored$') { -> | ||
} | ||
|
||
When(~'^I click on "([^"]*)" option at Technical Report list$') { String arg1 -> | ||
// Express the Regexp above with the code you wish you had | ||
throw new PendingException() | ||
} |
Oops, something went wrong.