From b3092455c6a2ec53d974269a890d48bbc9672906 Mon Sep 17 00:00:00 2001 From: TheGeekTortoise Date: Mon, 19 Oct 2020 19:35:23 +0200 Subject: [PATCH] fix delleted term listing --- .../be/cytomine/ontology/Ontology.groovy | 4 +-- test/functional/be/cytomine/TermTests.groovy | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/grails-app/domain/be/cytomine/ontology/Ontology.groovy b/grails-app/domain/be/cytomine/ontology/Ontology.groovy index b702d9b06..a9266b249 100644 --- a/grails-app/domain/be/cytomine/ontology/Ontology.groovy +++ b/grails-app/domain/be/cytomine/ontology/Ontology.groovy @@ -87,7 +87,7 @@ class Ontology extends CytomineDomain implements Serializable { * @return Term list */ def terms() { - Term.findAllByOntology(this) + Term.findAllByOntologyAndDeletedIsNull(this) } /** @@ -99,7 +99,7 @@ class Ontology extends CytomineDomain implements Serializable { if(!parent) { return [] } else { - return Term.executeQuery('SELECT term FROM Term as term WHERE ontology = :ontology AND term.id NOT IN (SELECT DISTINCT rel.term1.id FROM RelationTerm as rel, Term as t WHERE rel.relation = :relation AND t.ontology = :ontology AND t.id=rel.term1.id)',['ontology':this,'relation':parent]) + return Term.executeQuery('SELECT term FROM Term as term WHERE ontology = :ontology AND deleted IS NULL AND term.id NOT IN (SELECT DISTINCT rel.term1.id FROM RelationTerm as rel, Term as t WHERE rel.relation = :relation AND t.ontology = :ontology AND t.id=rel.term1.id)',['ontology':this,'relation':parent]) } } diff --git a/test/functional/be/cytomine/TermTests.groovy b/test/functional/be/cytomine/TermTests.groovy index 494184128..3d1a998ff 100644 --- a/test/functional/be/cytomine/TermTests.groovy +++ b/test/functional/be/cytomine/TermTests.groovy @@ -40,10 +40,19 @@ class TermTests { void testListOntologyTermByOntologyWithCredential() { Ontology ontology = BasicInstanceBuilder.getOntology() + def term = BasicInstanceBuilder.getTermNotExist(ontology, true) def result = TermAPI.listByOntology(ontology.id, Infos.SUPERADMINLOGIN, Infos.SUPERADMINPASSWORD) assert 200 == result.code def json = JSON.parse(result.data) assert json.collection instanceof JSONArray + int size = json.collection.size() + result = TermAPI.delete(term.id, Infos.SUPERADMINLOGIN, Infos.SUPERADMINPASSWORD) + assert 200 == result.code + result = TermAPI.listByOntology(ontology.id, Infos.SUPERADMINLOGIN, Infos.SUPERADMINPASSWORD) + assert 200 == result.code + json = JSON.parse(result.data) + assert json.collection instanceof JSONArray + assert size == json.collection.size()+1 } void testListTermOntologyByOntologyWithOntologyNotExist() { @@ -53,10 +62,19 @@ class TermTests { void testListOntologyTermByProjectWithCredential() { Project project = BasicInstanceBuilder.getProject() + def term = BasicInstanceBuilder.getTermNotExist(project.ontology, true) def result = TermAPI.listByProject(project.id, Infos.SUPERADMINLOGIN, Infos.SUPERADMINPASSWORD) assert 200 == result.code def json = JSON.parse(result.data) assert json.collection instanceof JSONArray + int size = json.collection.size() + result = TermAPI.delete(term.id, Infos.SUPERADMINLOGIN, Infos.SUPERADMINPASSWORD) + assert 200 == result.code + result = TermAPI.listByProject(project.id, Infos.SUPERADMINLOGIN, Infos.SUPERADMINPASSWORD) + assert 200 == result.code + json = JSON.parse(result.data) + assert json.collection instanceof JSONArray + assert size == json.collection.size()+1 } void testListTermOntologyByProjectWithProjectNotExist() { @@ -66,10 +84,19 @@ class TermTests { void testListTermWithCredential() { + def term = BasicInstanceBuilder.getTermNotExist(BasicInstanceBuilder.getOntology(), true) def result = TermAPI.list(Infos.SUPERADMINLOGIN, Infos.SUPERADMINPASSWORD) assert 200 == result.code def json = JSON.parse(result.data) assert json.collection instanceof JSONArray + int size = json.collection.size() + result = TermAPI.delete(term.id, Infos.SUPERADMINLOGIN, Infos.SUPERADMINPASSWORD) + assert 200 == result.code + result = TermAPI.list(Infos.SUPERADMINLOGIN, Infos.SUPERADMINPASSWORD) + assert 200 == result.code + json = JSON.parse(result.data) + assert json.collection instanceof JSONArray + assert size == json.collection.size()+1 } void testShowTermWithCredential() {