From 078c530623663185fab34680e09d54c43d014dc5 Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Fri, 15 Jan 2016 11:54:58 +0100 Subject: [PATCH] SONAR-7135 WS api/measures/component_tree search query must match exactly the component key --- .../sonar/db/component/ComponentMapper.xml | 38 ++++++++++--------- .../sonar/db/component/ComponentDaoTest.java | 4 +- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml index 6d92ed2c932..32087814dbd 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/ComponentMapper.xml @@ -287,17 +287,18 @@ AND p.language = #{query.language} - AND (exists ( - select 1 - from resource_index ri - where - ri.resource_id=p.id - AND ri.qualifier in - - #{qualifier} - - AND ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/') - OR p.kee like #{query.nameOrKeyQueryToSqlForProjectKey} ESCAPE '/') + AND ( + exists ( + select 1 + from resource_index ri + where + ri.resource_id=p.id + AND ri.qualifier in + + #{qualifier} + + AND ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/') + OR p.kee = #{query.nameOrKeyQuery}) @@ -351,13 +352,14 @@ - AND (exists ( - select 1 - from resource_index ri - where - (ri.resource_id=p.id OR ri.resource_id=p.copy_resource_id) - AND ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/') - OR p.kee like #{query.nameOrKeyQueryToSqlForProjectKey} ESCAPE '/') + AND ( + exists ( + select 1 + from resource_index ri + where + (ri.resource_id=p.id OR ri.resource_id=p.copy_resource_id) + AND ri.kee like #{query.nameOrKeyQueryToSqlForResourceIndex} ESCAPE '/') + OR p.kee = #{query.nameOrKeyQuery}) diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java index 9a8e159e4bd..e739cba9096 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java @@ -712,7 +712,7 @@ public class ComponentDaoTest { db.commit(); componentDb.indexProjects(); - ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("project-_%-").setQualifiers(Qualifiers.PROJECT).build(); + ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("project-_%-key").setQualifiers(Qualifiers.PROJECT).build(); List result = underTest.selectByQuery(dbSession, query, 0, 10); assertThat(result).hasSize(1); @@ -782,7 +782,7 @@ public class ComponentDaoTest { componentDb.indexProjects(); ComponentTreeQuery query = newTreeQuery(projectSnapshot) - .setNameOrKeyQuery("file-key").build(); + .setNameOrKeyQuery("file-key-1").build(); List result = underTest.selectDirectChildren(dbSession, query); int count = underTest.countDirectChildren(dbSession, query); -- 2.39.5