Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equipe 1 - Atividade 3 #346

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
88aeaf9
Definicao de cenários baseados na GUI e nos controladores
tiagonog Mar 30, 2015
5d435f7
Alteracao de cenários baseados na GUI e nos controladores
tiagonog Mar 30, 2015
38e9aa0
New scenarios added:
RomeroBarata Mar 30, 2015
6433722
Merge remote-tracking branch 'origin/dev' into dev
RomeroBarata Mar 30, 2015
a3fa14d
Atividade 3
luisdelgado Mar 31, 2015
338f8c8
Atividade 3:
luisdelgado Mar 31, 2015
dd75fc9
Adicionados novos scenarios a feature Reports
Mar 31, 2015
2681a87
Update Conferencia.feature
Mar 31, 2015
6740394
New Scenarios Conferencia.feature
almeidaeduardo Mar 31, 2015
93acd30
Modificações nos cenários da feature reports
PauloLuna Mar 31, 2015
06e9ffe
Pequenas mudanças e adição de novos cenários para Conferência
Apr 3, 2015
dbb0f39
Pequenas modificações nos cenários em comformidade com os comentários…
Apr 4, 2015
fcf961c
Correcao de cenários em XMLImport
tiagonog Apr 15, 2015
e0f5256
Correcao de cenários em XMLImport
tiagonog Apr 18, 2015
39e3937
Implementacao de testes em XMLImport
tiagonog Apr 18, 2015
e41e8c3
Arquivo para execucao de testes
tiagonog Apr 18, 2015
7e123d6
Ajuste de erro
tiagonog Apr 18, 2015
1be3b45
Correção dos cenários
Apr 19, 2015
41bcb5b
Update Conferencia.feature
Apr 19, 2015
37f62e9
Cenários corrigidos e duas GUIs criadas, pelo fato que não existe cen…
fmcs3 Apr 19, 2015
bed6a6c
Update ConferenciaSteps.groovy
Apr 19, 2015
264898b
Removendo Classe Não Usada
fmcs3 Apr 19, 2015
5d913d7
Merge branch 'dev2' of https://github.com/tiagonog/rgms into dev2
fmcs3 Apr 19, 2015
7c883b1
Cenários corrigidos e duas GUIs criadas, pelo fato que não existe cen…
fmcs3 Apr 19, 2015
eb26cb9
Cenários corrigidos e duas GUIs criadas, pelo fato que não existe cen…
fmcs3 Apr 19, 2015
a151b38
Cenários corrigidos e duas GUIs criadas, pelo fato que não existe cen…
fmcs3 Apr 19, 2015
a08c9e4
Cenários corrigidos e duas GUIs criadas, pelo fato que não existe cen…
fmcs3 Apr 19, 2015
e178ca5
Mudanças em ResearchGroupCreatePage e ResearchGroupListPage
fmcs3 Apr 19, 2015
2fde2d6
- A few modifications on BibtexGenerateFile.feature to comply with Th…
RomeroBarata Apr 19, 2015
50d3540
Merge remote-tracking branch 'origin/dev2' into dev2
RomeroBarata Apr 19, 2015
afaf258
Atividade 5:
luisdelgado Apr 19, 2015
631e737
scenario update
almeidaeduardo Apr 19, 2015
f1b8dea
Update ConferenceSteps
almeidaeduardo Apr 19, 2015
492a125
Merge remote-tracking branch 'origin/dev2' into dev2
luisdelgado Apr 19, 2015
47e38d2
Merge remote-tracking branch 'origin/dev2' into dev2
luisdelgado Apr 19, 2015
b3537ac
modification of scenarios and tests about gui
Apr 20, 2015
7e9dfa6
testes atividade2
PauloLuna Apr 21, 2015
8c98be9
Reorganized the BibTexGenerateFileStesp.groovy because the commits fr…
RomeroBarata Apr 25, 2015
f39164e
Implementacao da Feature "Tolerancia para deteccao de dissertacoes co…
tiagonog May 2, 2015
13eca27
Update ConferenceSteps
almeidaeduardo May 2, 2015
f3ae3eb
Correcao de testes em XMLImport
tiagonog May 2, 2015
5ed146e
- Fixed a few scenarios so they now reflect better how the tests are …
RomeroBarata May 3, 2015
5a457f9
Merge remote-tracking branch 'origin/dev3' into dev3
RomeroBarata May 3, 2015
87e4363
Implementação em ReserachGroup Controller
fmcs3 May 3, 2015
b52317e
Merge remote-tracking branch 'origin/dev3' into dev3
fmcs3 May 3, 2015
a2fb731
Atividade 6:
luisdelgado May 3, 2015
8c5a7da
Merge remote-tracking branch 'origin/dev3' into dev3
luisdelgado May 3, 2015
c965965
Arquivo necessario para testes
tiagonog May 3, 2015
d7144b7
Arquivo necessario para testes
tiagonog May 3, 2015
35e46a0
Merge branch 'dev3' of https://github.com/tiagonog/rgms into dev3
tiagonog May 3, 2015
d4db8cf
Update ConferenceSteps
almeidaeduardo May 3, 2015
7c9bb76
Complemento da atividade 6 que não foi comitado no prazo por bug do I…
luisdelgado May 5, 2015
2abe3d7
Merge branch 'dev3' of https://github.com/tiagonog/rgms into dev3
luisdelgado May 5, 2015
45b6ef6
Retorno dos reportes para a feature ResearchGroup
PauloLuna May 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ grails.project.dependency.resolution = {
grailsHome()
grailsCentral()
mavenCentral()
mavenRepo "http://repo.grails.org/grails/plugins"

// uncomment these to enable remote dependency resolution from public Maven repositories
//mavenCentral()
Expand All @@ -46,6 +47,7 @@ grails.project.dependency.resolution = {
compile('lib:itext-pdfa:5.4.0')
compile('lib:itext-xtra:5.4.0')
compile('lib:twitter4j-core:4.0.1')
compile('commons-codec:commons-codec:1.6')

compile(group: 'org.apache.poi', name: 'poi', version: '3.7') {
excludes 'xmlbeans'
Expand Down
34 changes: 34 additions & 0 deletions grails-app/controllers/rgms/member/ResearchGroupController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class ResearchGroupController {

def save() {
def researchGroupInstance = new ResearchGroup(params)

/* Checando Caracteres Não Permitidos Nos Nomes*/
allowedChar(researchGroupInstance)

//#if($researchGroupHierarchy)
try {
validarChildOf(researchGroupInstance, researchGroupInstance.getChildOf())
Expand Down Expand Up @@ -266,4 +270,34 @@ class ResearchGroupController {
researchGroupInstance.save()
redirect(action: "show", id: researchGroupInstance.id)
}

def allowedChar(researchGroupInstance) {
def caracteres = ['#','%','*','@','!','$','¨','(',')','-','=']

boolean pesquisa
pesquisa = false

/* Procurando Caracteres não permitidos */
for (x in caracteres){
for (y in researchGroupInstance.name){
if(x == y)
pesquisa = true;
}

for (y in researchGroupInstance.twitter){
if(x == y)
pesquisa = true;
}

for (y in researchGroupInstance.sigla){
if(x == y)
pesquisa = true;
}
} /* Fim for */

/* Checando se foi achado caracteres não permitidos */
if (pesquisa){
throw new RuntimeException("Não é possível registrar um grupo com Caracteres Especiais!")
}
} /* Fim allowedChar method*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package rgms.publication

/**
* Created by Luís Delgado on 02/05/15.
*/
class BibTexMainMenuController {

def index() {

}

def list = {
}

}
21 changes: 20 additions & 1 deletion grails-app/controllers/rgms/publication/XMLController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import rgms.member.Member
*/
class XMLController {

static int similarityTolerance = 0

def home() {}

def upload() {
similarityTolerance = Integer.parseInt(params.tolerance)
String flashMessage = 'Publications imported!'
String controller = "Publication"
if (!XMLService.Import(savePublication, returnWithMessage, flashMessage, controller, request))
if (!XMLService.Import(savePublication, returnWithMessage, flashMessage, controller, request, similarityTolerance))
return
}

Expand Down Expand Up @@ -95,6 +98,16 @@ class XMLController {
XMLService.createDissertations(xmlFile)
}

private Closure saveDissertationsWithSimilarityAnalisys = {
Node xmlFile ->
XMLService.createDissertationsWithSimilarityAnalysis(xmlFile, similarityTolerance)
}

def boolean verifyDissertations(String title, Node xmlFile)
{
return XMLService.verifyDissertations(title, xmlFile)
}

def enviarConferenciaXML() {
String flashMessage = message(code: 'default.importedMsg.message')

Expand Down Expand Up @@ -163,4 +176,10 @@ class XMLController {
User user = User.findByUsername(SecurityUtils.getSubject()?.getPrincipal().toString())
return user?.author
}

def setSimilarityTolerance(int value) {
similarityTolerance = value;
}


}
17 changes: 17 additions & 0 deletions grails-app/controllers/rgms/tool/Levenshtein.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package rgms.tool

class Levenshtein {
def static int distance(String str1, String str2) {
def str1_len = str1.length()
def str2_len = str2.length()
int[][] distance = new int[str1_len + 1][str2_len + 1]
(str1_len + 1).times { distance[it][0] = it }
(str2_len + 1).times { distance[0][it] = it }
(1..str1_len).each { i ->
(1..str2_len).each { j ->
distance[i][j] = [distance[i-1][j]+1, distance[i][j-1]+1, str1[i-1]==str2[j-1]?distance[i-1][j-1]:distance[i-1][j-1]+1].min()
}
}
distance[str1_len][str2_len]
}
}
4 changes: 3 additions & 1 deletion grails-app/domain/rgms/member/ResearchGroup.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ResearchGroup {
String name
String description
String twitter
String sigla

//#if($researchGroupHierarchy)
ResearchGroup childOf;
Expand All @@ -15,9 +16,10 @@ class ResearchGroup {
static hasMany = [memberships: Membership, news: News]

static constraints = {
name(maxSize: 10, blank: false, unique: true)
name(maxSize: 15, blank: false, unique: true)
description(maxSize: 1000, blank: false)
twitter(nullable: true)
sigla(maxSize: 10, blank: true, unique: true)

//#if($researchGroupHierarchy)
childOf(nullable: true, blank: true)
Expand Down
11 changes: 11 additions & 0 deletions grails-app/domain/rgms/publication/BibTexMainMenu.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package rgms.publication

/**
* Created by Luís Delgado on 02/05/15.
*/
class BibTexMainMenu {

static constraints = {
}

}
1 change: 1 addition & 0 deletions grails-app/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ orientation.same.members=Um membro nao pode orientar a si mesmo
default.xml.parserror.message=No file uploaded or it wasn't a valid XML
default.xml.structure.message=The XML struct doesn't comply with Lattes
default.xml.unknownerror.message=An unknown error occurred. Contact the administrator
default.xml.similar.dissertation.message = The file was not imported because there is a dissertation with a similar title registered
xml.label=XMLImport

file.already.exist.message=A file has already been saved with the same name
Expand Down
1 change: 1 addition & 0 deletions grails-app/i18n/messages_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ tese.month.label=Mês
tese.arquivo.label=Arquivo
tese.label=Tese
tese.duplicatetitle.failure = Tese não cadastrada porque já existe uma tese com o mesmo título
default.xml.similar.dissertation.message = O arquivo não foi importado porque existe uma dissertação com um título semelhante registrada
#end

#if($news)
Expand Down
124 changes: 122 additions & 2 deletions grails-app/services/rgms/XMLService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,33 @@ import rgms.member.Orientation
import rgms.publication.*
import rgms.researchProject.Funder
import rgms.researchProject.ResearchProject
import rgms.tool.Levenshtein

class XMLService {

/*
saveEntity - closure que salva a classe de domínio que está usando a importação
*/



static boolean Import(Closure saveEntity, Closure returnWithMessage,
String flashMessage, String controller,
javax.servlet.http.HttpServletRequest request) {
javax.servlet.http.HttpServletRequest request, int similarityTolerance) {
boolean errorFound = false

try {
Node xmlFile = parseReceivedFile(request)
saveEntity(xmlFile)
if(!checkExistenceWithSimilarityAnalysis(xmlFile, similarityTolerance))
{
saveEntity(xmlFile)
}
else
{
flashMessage = 'default.xml.similar.dissertation.message'

errorFound = true
}
}
//If file is not XML or if no file was uploaded
catch (SAXParseException) {
Expand Down Expand Up @@ -282,6 +294,52 @@ class XMLService {
createDissertation(doutorado)
}

static void createDissertationsWithSimilarityAnalysis(Node xmlFile, int toleranceLevel) {

List<Dissertacao> dissertations = Dissertacao.findAll();

Node dadosGerais = (Node) xmlFile.children()[0]
Node formacaoAcademica = getNodeFromNode(dadosGerais, "FORMACAO-ACADEMICA-TITULACAO")
Node mestrado = (Node) formacaoAcademica.children()[1]
Node doutorado = (Node) formacaoAcademica.children()[2]

String dissertacaoMestrado = getAttributeValueFromNode(mestrado, "TITULO-DA-DISSERTACAO-TESE")

String dissertacaoDoutorado = getAttributeValueFromNode(doutorado, "TITULO-DA-DISSERTACAO-TESE")

boolean mestradoOK = true
boolean doutoradoOK = true

for (int i = 0; i < dissertations.size(); i++)
{
String current = dissertations.get(i)
int distanciaMestrado = Levenshtein.distance(current, dissertacaoMestrado)
if (( distanciaMestrado> toleranceLevel) && distanciaMestrado <= 10)
{
mestradoOK = false

}

int distanciaDoutorado = Levenshtein.distance(current, dissertacaoDoutorado)
if(distanciaDoutorado > toleranceLevel && distanciaDoutorado <=10)
{
doutoradoOK = false

}
}

if(mestradoOK)
{
createDissertation(mestrado)
}

if(doutoradoOK)
{
createDissertation(doutorado)
}

}

private static void createDissertation(Node xmlNode) {
Dissertacao newDissertation = new Dissertacao()
newDissertation.title = getAttributeValueFromNode(xmlNode, "TITULO-DA-DISSERTACAO-TESE")
Expand All @@ -293,6 +351,68 @@ class XMLService {
newDissertation.save(flush: false)
}

static boolean checkExistenceWithSimilarityAnalysis(Node xmlFile, int toleranceLevel)
{
List<Dissertacao> dissertations = Dissertacao.findAll();

Node dadosGerais = (Node) xmlFile.children()[0]
Node formacaoAcademica = getNodeFromNode(dadosGerais, "FORMACAO-ACADEMICA-TITULACAO")
Node mestrado = (Node) formacaoAcademica.children()[1]
Node doutorado = (Node) formacaoAcademica.children()[2]

String dissertacaoMestrado = getAttributeValueFromNode(mestrado, "TITULO-DA-DISSERTACAO-TESE")

String dissertacaoDoutorado = getAttributeValueFromNode(doutorado, "TITULO-DA-DISSERTACAO-TESE")

for (int i = 0; i < dissertations.size(); i++)
{
String current = dissertations.get(i)
if (Levenshtein.distance(current, dissertacaoMestrado) > toleranceLevel)
{
return true
}
else if(Levenshtein.distance(current, dissertacaoDoutorado) > toleranceLevel)
{
return true
}
}
return false


}

static boolean verifyDissertations (String title, Node xmlFile )
{
Node dadosGerais = (Node) xmlFile.children()[0]
Node formacaoAcademica = getNodeFromNode(dadosGerais, "FORMACAO-ACADEMICA-TITULACAO")
Node mestrado = (Node) formacaoAcademica.children()[1]
Node doutorado = (Node) formacaoAcademica.children()[2]

if(analizeDissertationNode(title, mestrado) || analizeDissertationNode(title, doutorado))
{
return true
}
else
{
return false
}

}

static boolean analizeDissertationNode(String title, Node node)
{
Dissertacao newDissertation = new Dissertacao()
newDissertation.title = getAttributeValueFromNode(node, "TITULO-DA-DISSERTACAO-TESE")
if(newDissertation.title == title)
{
return true
}
else
{
return false
}
}

static void createConferencias(Node xmlFile) {
Node trabalhosEmEventos = (Node) ((Node) xmlFile.children()[1]).children()[0]

Expand Down
3 changes: 2 additions & 1 deletion grails-app/views/XML/home.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
</div>
<br/>
<g:form controller="XML" method="post" action="upload" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="file" id="fileInput" name="file"/>
<g:select id="toleranceSelect" name="tolerance" from="${0..10}" required="" noSelection="['':'-tolerance level-']"/>
<input type="submit"/>
</g:form>
</div>
Expand Down
4 changes: 4 additions & 0 deletions grails-app/views/bibTexMainMenu/_form.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%@ page import="rgms.publication.BibTexMainMenu" %>



Loading