Skip to content

Commit

Permalink
[completed #94151116] Block orientation registry after similarity ana…
Browse files Browse the repository at this point in the history
…lysis
  • Loading branch information
tiagonog committed May 27, 2015
1 parent 9d976e7 commit 653ce1e
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 20 deletions.
10 changes: 10 additions & 0 deletions grails-app/controllers/rgms/publication/XMLController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,21 @@ class XMLController {
XMLService.createDissertationsWithSimilarityAnalysis(xmlFile, similarityTolerance)
}

private Closure saveOrientationsWithSimilarityAnalisys = {
Node xmlFile ->
XMLService.createOrientationsWithSimilarityAnalysis(xmlFile, similarityTolerance)
}

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

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

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

Expand Down
1 change: 1 addition & 0 deletions grails-app/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ 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
default.xml.similar.orientation.message = The file was not imported because there is a orientation 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 @@ -177,6 +177,7 @@ 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
default.xml.similar.orientation.message = O arquivo não foi importado porque existe uma orientação com um título semelhante registrada
#end

#if($news)
Expand Down
163 changes: 151 additions & 12 deletions grails-app/services/rgms/XMLService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ package rgms
import org.springframework.web.multipart.MultipartHttpServletRequest
import org.springframework.web.multipart.commons.CommonsMultipartFile
import rgms.member.Member
import rgms.member.MemberController
import rgms.member.Orientation
import rgms.member.OrientationController
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 final int MAX_TOLERANCE_LEVEL = 10;

static boolean Import(Closure saveEntity, Closure returnWithMessage,
String flashMessage, String controller,
Expand All @@ -24,13 +27,22 @@ class XMLService {

try {
Node xmlFile = parseReceivedFile(request)
if(!checkExistenceWithSimilarityAnalysis(xmlFile, similarityTolerance))
def result = checkExistenceWithSimilarityAnalysis(xmlFile, similarityTolerance)
if(!result.status)
{
saveEntity(xmlFile)
}
else
{
flashMessage = 'default.xml.similar.dissertation.message'
if(result.type == "Dissertation")
{
flashMessage = 'default.xml.similar.dissertation.message'
}
else if(result.type == "Orientation")
{
flashMessage = 'default.xml.similar.orientation.message'
}


errorFound = true
}
Expand Down Expand Up @@ -314,14 +326,14 @@ class XMLService {
{
String current = dissertations.get(i)
int distanciaMestrado = Levenshtein.distance(current, dissertacaoMestrado)
if (( distanciaMestrado> toleranceLevel) && distanciaMestrado <= 10)
if (( distanciaMestrado> toleranceLevel) && distanciaMestrado <= MAX_TOLERANCE_LEVEL)
{
mestradoOK = false

}

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

Expand All @@ -338,6 +350,59 @@ class XMLService {
createDissertation(doutorado)
}

}

static void createOrientationsWithSimilarityAnalysis(Node xmlFile, int toleranceLevel) {

Node outraProducao = (Node) xmlFile.children()[3]
List<Orientation> orientations = Orientation.findAll();
Node orientacoesConcluidas = (Node) getNodeFromNode(outraProducao, "ORIENTACOES-CONCLUIDAS")


for (int i = 0; i < orientacoesConcluidas.children().size(); i++)
{
boolean result = true;
String title = ""

for (int h = 0; h < orientations.size(); h++)
{
String current = orientations.get(h).tituloTese
Node currentInXML = (Node) orientacoesConcluidas.children()[i]
Node infoCurrentInXML = (Node) currentInXML.children()[0]
String titleCurrentInXML = getAttributeValueFromNode(infoCurrentInXML, "TITULO")
title = titleCurrentInXML

int distance = Levenshtein.distance(current, titleCurrentInXML )

if ( distance> toleranceLevel && distance <= MAX_TOLERANCE_LEVEL)
{
result = false
}
}

if(result)
{
def members = [[name: "Rodolfo", username: "usernametest", email: "[email protected]", status: "Graduate Student", university: "UFPE", enabled: true]]
def memberCreater = new Member(members[0])
def cont = new OrientationController()
memberCreater.create()
memberCreater.save()
def member = Member.findByName(memberCreater.name)

cont.params << [tipo: "Mestrado", orientando: "Tomaz", tituloTese: title, anoPublicacao: 2013, instituicao: "UFPE", orientador: member]
cont.request.setContent(new byte[1000]) // Could also vary the request content.
cont.create()
cont.save()
cont.response.reset()

//createOrientations(xmlFile, memberCreater)
}


}



}

private static void createDissertation(Node xmlNode) {
Expand All @@ -351,11 +416,15 @@ class XMLService {
newDissertation.save(flush: false)
}

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

def result = [status: false, type:""]

Node dadosGerais = (Node) xmlFile.children()[0]
Node outraProducao = (Node) xmlFile.children()[3]

List<Dissertacao> dissertations = Dissertacao.findAll();
Node formacaoAcademica = getNodeFromNode(dadosGerais, "FORMACAO-ACADEMICA-TITULACAO")
Node mestrado = (Node) formacaoAcademica.children()[1]
Node doutorado = (Node) formacaoAcademica.children()[2]
Expand All @@ -366,17 +435,60 @@ class XMLService {

for (int i = 0; i < dissertations.size(); i++)
{

String current = dissertations.get(i)
if (Levenshtein.distance(current, dissertacaoMestrado) > toleranceLevel)

int distance1 = Levenshtein.distance(current, dissertacaoMestrado)
int distance2 = Levenshtein.distance(current, dissertacaoDoutorado)
if (distance1 > toleranceLevel && distance1 <= MAX_TOLERANCE_LEVEL)
{
result.status = true
result.type = "Dissertation"
return result
}
else if(distance2 > toleranceLevel && distance2 <= MAX_TOLERANCE_LEVEL)
{
return true
result.status = true
result.type = "Dissertation"
return result
}
else if(Levenshtein.distance(current, dissertacaoDoutorado) > toleranceLevel)
}


List<Orientation> orientations = Orientation.findAll();

Node orientacoesConcluidas = (Node) getNodeFromNode(outraProducao, "ORIENTACOES-CONCLUIDAS")


for (int i = 0; i < orientations.size(); i++)
{

for (int h = 0; h < orientacoesConcluidas.children().size(); h++)
{
return true

String current = orientations.get(i).tituloTese

Node currentInXML = (Node) orientacoesConcluidas.children()[h]

Node infoCurrentInXML = (Node) currentInXML.children()[0]

String titleCurrentInXML = getAttributeValueFromNode(infoCurrentInXML, "TITULO")

int distance = Levenshtein.distance(current, titleCurrentInXML )

if ( distance> toleranceLevel && distance <= MAX_TOLERANCE_LEVEL)
{

result.status = true
result.type = "Orientation"
return result
}
}
}
return false

return result




}
Expand All @@ -399,6 +511,33 @@ class XMLService {

}

static boolean verifyOrientations (String title, Node xmlFile )
{

Node outraProducao = (Node) xmlFile.children()[3]

Node orientacoesConcluidas = (Node) getNodeFromNode(outraProducao, "ORIENTACOES-CONCLUIDAS")

boolean result = false
for(int i=0; i<orientacoesConcluidas.children().size();i++)
{

Node currentInXML = (Node) orientacoesConcluidas.children()[i]

Node infoCurrentInXML = (Node) currentInXML.children()[0]

String titleCurrentInXML = getAttributeValueFromNode(infoCurrentInXML, "TITULO")

if(title == titleCurrentInXML)
{
result = true
return result
}
}
return result

}

static boolean analizeDissertationNode(String title, Node node)
{
Dissertacao newDissertation = new Dissertacao()
Expand Down
12 changes: 6 additions & 6 deletions test/cucumber/XMLImport.feature
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ Feature: XMLImport
And the previously stored orientations do not change
#if($ToleranceLevel)
Scenario: dissertations with similar names should be considered as duplicates, according to the tolerance level
Expand All @@ -341,8 +340,8 @@ Feature: XMLImport
Scenario: orientations with similar names should be considered as duplicates, according to the tolerance level
Given the system has a orientation entitled "Design and Evaluation of an Object-Oriented Formal Specification Language" stored
And the similarity tolerance is configured to "5"
When I upload the file "curriculo5.xml" which contains a orientation entitled "design and evaluation of an object-oriented formal specification Language"
Then the system outputs a list of imported dissertations which contains the orientation entitled "Design and Evaluation of an Object-Oriented Formal Specification Language"
When I upload the file "curriculo5.xml" which contains an orientation entitled "design and evaluation of an object-oriented formal specification Language"
Then the system outputs a list of imported orientations which contains the orientation entitled "Design and Evaluation of an Object-Oriented Formal Specification Language"
And no new orientation entitled "design and evaluation of an object-oriented formal specification Language" is stored by the system
Scenario: show a successful message when the tolerance level is informed and no duplicates were found
Expand All @@ -354,9 +353,10 @@ Feature: XMLImport
Scenario: orientations without similar names should not be considered as duplicates, according to the tolerance level
Given the system has a orientation entitled "Design and Evaluation of an Object-Oriented Formal Specification Language" stored
And the similarity tolerance is configured to "5"
When I upload the file "curriculo5.xml" which contains a orientation entitled "Design and Evaluation of an Object-oriented formal specification Language"
Then the system outputs a list of imported dissertations which contains the orientations "Design and Evaluation of an Object-Oriented Formal Specification Language" and "Design and Evaluation of an Object-oriented formal specification Language"
And the new orientation entitled "Design and Evaluation of an Object-oriented formal specification Language" is stored by the system
When I upload the file "curriculo6.xml" which contains an orientation entitled "Design and Evaluation of an Object-oriented formal Specification Languagee"
Then the system outputs a list of imported orientations which contains the orientations "Design and Evaluation of an Object-Oriented Formal Specification Language" and "Design and Evaluation of an Object-oriented formal Specification Languagee"
And the new orientation entitled "Design and Evaluation of an Object-oriented formal Specification Languagee" is stored by the system
#end
# o que acontece quando o arquivo tem publicações já cadastradas? e
# publicações com mesmos títulos mas outras partes diferentes? e
Expand Down
29 changes: 28 additions & 1 deletion test/cucumber/steps/XMLImportSteps.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,31 @@ When(~'^I click on "upload" without informing the tolerance level$') { ->
Then(~'^the system outputs an error message$') { ->
//qualquer navegador por padrão mostra uma mensagem de erro quando o atributo "required" está configurado
assert page.isRequiredEnabledOnToleranceSelect()
}
}

Given(~'^the system has a orientation entitled "([^"]*)" stored$') { String title->
//TestDataDissertacao.createDissertacao(title, "dissertation.txt", "University of Oxford")
OrientationTestDataAndOperations.createOrientation(title)
//def dissertation = Dissertacao.findByTitle(title);
def orientation = Orientation.findByTituloTese(title);
assert orientation != null
}

When(~'^I upload the file "([^"]*)" which contains an orientation entitled "([^"]*)"$') { String filename, title->

String path = new File(".").getCanonicalPath() + File.separator + "test" + File.separator + "functional" + File.separator + "steps" + File.separator + filename
OrientationTestDataAndOperations.uploadOrientationWithSimilarityAnalisys(path)
boolean result = OrientationTestDataAndOperations.verifyOrientationXML(title, path)
assert result
}

Then(~'^the system outputs a list of imported orientations which contains the orientation entitled "([^"]*)"$') { String title->
def orientation = Orientation.findByTituloTese(title)
assert orientation != null
}

And(~'^no new orientation entitled "([^"]*)" is stored by the system$') { String title->
def orientation = Orientation.findByTituloTese(title)
assert orientation == null
}

18 changes: 18 additions & 0 deletions test/functional/steps/OrientationTestDataAndOperations.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ class OrientationTestDataAndOperations {
createOrientationAux(cont, tituloTese, member)
}

static public void uploadOrientationWithSimilarityAnalisys(filename) {
def cont = new XMLController()
def xml = new File(filename);
def records = new XmlParser()
cont.saveOrientationsWithSimilarityAnalisys(records.parse(xml));
cont.response.reset()
}

private static void createOrientationAux(OrientationController cont, String tituloTese, Member member) {
cont.params << [tipo: "Mestrado", orientando: "Tomaz", tituloTese: tituloTese, anoPublicacao: 2013, instituicao: "UFPE", orientador: member]
cont.request.setContent(new byte[1000]) // Could also vary the request content.
Expand Down Expand Up @@ -84,4 +92,14 @@ class OrientationTestDataAndOperations {
cont.saveOrientations(records.parse(xml));
cont.response.reset()
}

static public boolean verifyOrientationXML(String title, String filename)
{
def cont = new XMLController()
def xml = new File(filename);
def records = new XmlParser()
boolean result = cont.verifyOrientations(title, records.parse(xml));
cont.response.reset()
return result;
}
}
2 changes: 1 addition & 1 deletion test/functional/steps/curriculo5.xml

Large diffs are not rendered by default.

0 comments on commit 653ce1e

Please sign in to comment.