aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBelen Pruvost <belen.pruvost@sonarsource.com>2021-07-01 17:19:49 +0200
committersonartech <sonartech@sonarsource.com>2021-07-01 20:03:19 +0000
commitd2acae081d2d89f936e8ae272bd0cad819ee4c23 (patch)
tree3c353916880b10585c10cc1bb7df83e4c1044277
parent79ecdf7bef85c00ae5b9271ef8d7338306d72881 (diff)
downloadsonarqube-d2acae081d2d89f936e8ae272bd0cad819ee4c23.tar.gz
sonarqube-d2acae081d2d89f936e8ae272bd0cad819ee4c23.zip
SONAR-14605 - Only update Rule facet name for external rules
-rw-r--r--server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java21
-rw-r--r--server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java15
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java8
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java2
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java7
5 files changed, 10 insertions, 43 deletions
diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java
index 60694e9231a..cc4c5afef48 100644
--- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java
+++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java
@@ -53,7 +53,6 @@ import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.rule.RuleDefinitionDto;
-import org.sonar.db.rule.RuleMetadataDto;
import org.sonar.server.issue.SearchRequest;
import org.sonar.server.issue.index.IssueQuery.PeriodStart;
import org.sonar.server.user.UserSession;
@@ -111,11 +110,8 @@ public class IssueQueryFactory {
final ZoneId timeZone = parseTimeZone(request.getTimeZone()).orElse(clock.getZone());
Collection<RuleDefinitionDto> ruleDefinitionDtos = ruleKeysToRuleId(dbSession, request.getRules());
- Collection<RuleMetadataDto> ruleMetadataDtos = ruleKeysToRuleMetadata(dbSession, request.getRules());
Collection<String> ruleUuids = ruleDefinitionDtos.stream().map(RuleDefinitionDto::getUuid).collect(Collectors.toSet());
- ruleDefinitionDtos.stream().forEach(rule -> getRuleName(ruleMetadataDtos, rule));
-
if (request.getRules() != null && request.getRules().stream().collect(toSet()).size() != ruleDefinitionDtos.size()) {
ruleUuids.add("non-existing-uuid");
}
@@ -386,13 +382,6 @@ public class IssueQueryFactory {
return Collections.emptyList();
}
- private Collection<RuleMetadataDto> ruleKeysToRuleMetadata(DbSession dbSession, @Nullable Collection<String> rules) {
- if (rules != null) {
- return dbClient.ruleDao().selectMetadataByKeys(dbSession, transform(rules, RuleKey::parse));
- }
- return Collections.emptyList();
- }
-
private static String toProjectUuid(ComponentDto componentDto) {
String mainBranchProjectUuid = componentDto.getMainBranchProjectUuid();
return mainBranchProjectUuid == null ? componentDto.projectUuid() : mainBranchProjectUuid;
@@ -405,14 +394,4 @@ public class IssueQueryFactory {
|| (branch != null && !branch.equals(component.getBranch()))
|| (pullRequest != null && !pullRequest.equals(component.getPullRequest())));
}
-
- private static void getRuleName(Collection<RuleMetadataDto> ruleMetadataDtos, RuleDefinitionDto rule) {
- if (rule.isAdHoc()) {
- String name = ruleMetadataDtos.stream()
- .filter(m -> m.getRuleUuid().equals(rule.getUuid())).findFirst()
- .map(RuleMetadataDto::getAdHocName)
- .orElse(null);
- rule.setName(name);
- }
- }
}
diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java
index 3d5fba1a828..43531893e05 100644
--- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java
+++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java
@@ -26,7 +26,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
-import java.util.Optional;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -80,7 +79,7 @@ public class IssueQueryFactoryTest {
ComponentDto module = db.components().insertComponent(newModuleDto(project));
ComponentDto file = db.components().insertComponent(newFileDto(project));
- RuleDefinitionDto rule1 = ruleDbTester.insert(r -> r.setIsAdHoc(true));
+ RuleDefinitionDto rule1 = ruleDbTester.insert();
RuleDefinitionDto rule2 = ruleDbTester.insert();
ruleDbTester.insertOrUpdateMetadata(rule1, m -> m.setAdHocName(ruleAdHocName));
ruleDbTester.insertOrUpdateMetadata(rule2, m -> m.setAdHocName(ruleAdHocName));
@@ -131,18 +130,6 @@ public class IssueQueryFactoryTest {
assertThat(query.sort()).isEqualTo(IssueQuery.SORT_BY_CREATION_DATE);
assertThat(query.asc()).isTrue();
- Optional<RuleDefinitionDto> ruleWithMetadata = query.rules().stream()
- .filter(r -> r.getUuid().equals(rule1.getUuid())).findFirst();
- assertThat(ruleWithMetadata).isPresent();
- assertThat(ruleWithMetadata.get().getName()).isEqualTo(ruleAdHocName);
- assertThat(ruleWithMetadata.get().getName()).isNotEqualTo(rule1.getName());
-
- Optional<RuleDefinitionDto> ruleWithMetadata2 = query.rules().stream()
- .filter(r -> r.getUuid().equals(rule2.getUuid())).findFirst();
- assertThat(ruleWithMetadata2).isPresent();
- assertThat(ruleWithMetadata2.get().getName()).isNotEqualTo(ruleAdHocName);
- assertThat(ruleWithMetadata2.get().getName()).isEqualTo(rule2.getName());
-
}
@Test
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
index 8ed2457a9f6..b200d469384 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseFormat.java
@@ -176,13 +176,7 @@ public class SearchResponseFormat {
issueBuilder.setSubProject(subProject.getKey());
}
}
-
- String ruleName = data.getRules().stream()
- .filter(r -> r.isAdHoc() && r.getName() != null && r.getUuid().equals(dto.getRuleUuid()))
- .findFirst()
- .map(RuleDefinitionDto::getName)
- .orElse(dto.getRuleKey().toString());
- issueBuilder.setRule(ruleName);
+ issueBuilder.setRule(dto.getRuleKey().toString());
if (dto.isExternal()) {
issueBuilder.setExternalRuleEngine(engineNameFrom(dto.getRuleKey()));
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java
index cddd95bc4c3..4fb9b30e3a6 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/SearchResponseLoader.java
@@ -169,6 +169,7 @@ public class SearchResponseLoader {
result.addRules(preloadedRules);
Set<String> ruleUuidsToLoad = collector.getRuleUuids();
ruleUuidsToLoad.removeAll(preloadedRules.stream().map(RuleDefinitionDto::getUuid).collect(toList(preloadedRules.size())));
+
List<RuleDefinitionDto> rules = dbClient.ruleDao().selectDefinitionByUuids(dbSession, ruleUuidsToLoad);
getRulesMetadata(dbSession, rules);
@@ -365,4 +366,5 @@ public class SearchResponseLoader {
}
});
}
+
}
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
index 7b7e33030b3..9c7ea76a897 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionTest.java
@@ -231,11 +231,16 @@ public class SearchActionTest {
indexIssues();
SearchWsResponse response = ws.newRequest()
+ .setParam("additionalFields", "rules")
.executeProtobuf(SearchWsResponse.class);
assertThat(response.getIssuesList())
.extracting(Issue::getKey, Issue::getRule, Issue::getExternalRuleEngine)
- .containsExactlyInAnyOrder(tuple(issue.getKey(), ruleMetadata.getAdHocName(), "xoo"));
+ .containsExactlyInAnyOrder(tuple(issue.getKey(), rule.getKey().toString(), "xoo"));
+
+ assertThat(response.getRules().getRulesList())
+ .extracting(Common.Rule::getKey, Common.Rule::getName)
+ .containsExactlyInAnyOrder(tuple(rule.getKey().toString(), ruleMetadata.getAdHocName()));
}
@Test