aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2019-11-25 11:09:13 -0600
committerSonarTech <sonartech@sonarsource.com>2019-12-09 20:46:17 +0100
commit7197bceddc7c51d51cd46e22b68cdc71d277aa65 (patch)
tree2ca5296c02e7d6912bb27b2eac105a6750e36284
parentebdae1d5b7916abb7e919c560b04841f0dfd21c6 (diff)
downloadsonarqube-7197bceddc7c51d51cd46e22b68cdc71d277aa65.tar.gz
sonarqube-7197bceddc7c51d51cd46e22b68cdc71d277aa65.zip
SONAR-12748 WS navigation/component always returns 'isFavorite' false for branches
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java9
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java25
2 files changed, 30 insertions, 4 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
index 444d91beb82..c6a0fb07996 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
@@ -164,7 +164,8 @@ public class ComponentAction implements NavigationWsAction {
try (JsonWriter json = response.newJsonWriter()) {
json.beginObject();
- writeComponent(json, session, component, org, analysis.orElse(null));
+ boolean isFavourite = isFavourite(session, rootProject);
+ writeComponent(json, component, org, analysis.orElse(null), isFavourite);
writeAlmDetails(json, session, rootProject);
writeProfiles(json, session, component);
writeQualityGate(json, session, org, rootProject);
@@ -194,7 +195,7 @@ public class ComponentAction implements NavigationWsAction {
private void writeAlmDetails(JsonWriter json, DbSession session, ComponentDto component) {
Optional<ProjectAlmBindingDto> bindingOpt = dbClient.projectAlmBindingsDao().selectByProjectUuid(session, component.uuid());
bindingOpt.ifPresent(b -> {
- String almId = String.valueOf(b.getAlm().getId());
+ String almId = b.getAlm().getId();
json.name("alm").beginObject()
.prop("key", almId)
.prop("url", b.getUrl())
@@ -218,13 +219,13 @@ public class ComponentAction implements NavigationWsAction {
.endObject();
}
- private void writeComponent(JsonWriter json, DbSession session, ComponentDto component, OrganizationDto organizationDto, @Nullable SnapshotDto analysis) {
+ private void writeComponent(JsonWriter json, ComponentDto component, OrganizationDto organizationDto, @Nullable SnapshotDto analysis, boolean isFavourite) {
json.prop("key", component.getKey())
.prop("organization", organizationDto.getKey())
.prop("id", component.uuid())
.prop("name", component.name())
.prop("description", component.description())
- .prop("isFavorite", isFavourite(session, component));
+ .prop("isFavorite", isFavourite);
String branch = component.getBranch();
if (branch != null) {
json.prop("branch", branch);
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java
index 34c6843bbda..ab2ec2d2f22 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java
@@ -153,6 +153,31 @@ public class ComponentActionTest {
}
@Test
+ public void return_favourite_for_branch() {
+ ComponentDto project = insertOrganizationAndProject();
+ ComponentDto branch = componentDbTester.insertProjectBranch(project, b -> b.setKey("feature1").setUuid("xyz")); UserDto user = db.users().insertUser("obiwan");
+ propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(user.getId()));
+ userSession.logIn(user).addProjectPermission(UserRole.USER, project);
+ init();
+
+ String json = ws.newRequest()
+ .setParam("componentKey", project.getKey())
+ .setParam("branch", branch.getBranch())
+ .execute()
+ .getInput();
+
+ assertJson(json).isSimilarTo("{\n" +
+ " \"organization\": \"my-org\",\n" +
+ " \"key\": \"polop\",\n" +
+ " \"isFavorite\": true,\n" +
+ " \"id\": \"xyz\",\n" +
+ " \"branch\": \"feature1\"," +
+ " \"name\": \"Polop\",\n" +
+ " \"description\": \"test project\"\n" +
+ "}\n");
+ }
+
+ @Test
public void return_component_info_when_snapshot() {
ComponentDto project = insertOrganizationAndProject();
db.components().insertSnapshot(project, snapshot -> snapshot