aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-09-25 15:38:34 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-09-25 15:38:34 +0200
commit02afc20bf8abe198abb54eccd72552c3d1874358 (patch)
treed69dc27ee92c27a70ea824f2d4cb8bb1566dff68
parentf76df3e934c7b76141c58f24ac3303ae358cdcf4 (diff)
downloadsonarqube-02afc20bf8abe198abb54eccd72552c3d1874358.tar.gz
sonarqube-02afc20bf8abe198abb54eccd72552c3d1874358.zip
SONAR-5531 Return issues attributes in issues search WS
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueNormalizer.java20
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java14
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java14
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issue_with_attributes.json10
5 files changed, 53 insertions, 15 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java
index f025ccbd874..0abaa1b88d1 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java
@@ -28,7 +28,6 @@ import org.sonar.server.search.IndexUtils;
import javax.annotation.CheckForNull;
-import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -126,14 +125,12 @@ public class IssueDoc extends BaseDoc implements Issue {
@Override
@CheckForNull
public String attribute(String key) {
- // TODO get the actual value
- return null;
+ return attributes().get(key);
}
@Override
public Map<String, String> attributes() {
- // TODO get the actual value
- return Collections.emptyMap();
+ return getField(IssueNormalizer.IssueField.ATTRIBUTES.field());
}
@Override
@@ -150,8 +147,7 @@ public class IssueDoc extends BaseDoc implements Issue {
@Override
public List<IssueComment> comments() {
- // TODO get the actual value
- return Collections.emptyList();
+ throw new IllegalStateException("Comments are not availables in index");
}
@Override
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueNormalizer.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueNormalizer.java
index 42f9a0b79a8..d57cd5eb1bd 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueNormalizer.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueNormalizer.java
@@ -21,6 +21,7 @@ package org.sonar.server.issue.index;
import com.google.common.collect.ImmutableList;
import org.elasticsearch.action.update.UpdateRequest;
+import org.sonar.api.utils.KeyValueFormat;
import org.sonar.core.issue.db.IssueDto;
import org.sonar.server.db.DbClient;
import org.sonar.server.search.BaseNormalizer;
@@ -29,7 +30,12 @@ import org.sonar.server.search.IndexField;
import org.sonar.server.search.Indexable;
import java.lang.reflect.Field;
-import java.util.*;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static com.google.common.collect.Maps.newHashMap;
public class IssueNormalizer extends BaseNormalizer<IssueDto, String> {
@@ -45,7 +51,7 @@ public class IssueNormalizer extends BaseNormalizer<IssueDto, String> {
public static final IndexField ACTION_PLAN = add(IndexField.Type.STRING, "actionPlan");
public static final IndexField ASSIGNEE = addSortable(IndexField.Type.STRING, "assignee");
- public static final IndexField ATTRIBUTE = add(IndexField.Type.OBJECT, "attributes");
+ public static final IndexField ATTRIBUTES = add(IndexField.Type.OBJECT, "attributes");
public static final IndexField AUTHOR_LOGIN = add(IndexField.Type.STRING, "authorLogin");
public static final IndexField COMPONENT = add(IndexField.Type.STRING, "component");
public static final IndexField DEBT = add(IndexField.Type.NUMERIC, "debt");
@@ -91,7 +97,7 @@ public class IssueNormalizer extends BaseNormalizer<IssueDto, String> {
@Override
public List<UpdateRequest> normalize(IssueDto dto) {
- Map<String, Object> update = new HashMap<String, Object>();
+ Map<String, Object> update = newHashMap();
update.put("_parent", dto.getRootComponentKey());
update.put(IssueField.KEY.field(), dto.getKey());
@@ -99,6 +105,7 @@ public class IssueNormalizer extends BaseNormalizer<IssueDto, String> {
update.put(IssueField.CREATED_AT.field(), dto.getCreatedAt());
update.put(IssueField.ACTION_PLAN.field(), dto.getActionPlanKey());
+ update.put(IssueField.ATTRIBUTES.field(), KeyValueFormat.parse(dto.getIssueAttributes()));
update.put(IssueField.ASSIGNEE.field(), dto.getAssignee());
update.put(IssueField.AUTHOR_LOGIN.field(), dto.getAuthorLogin());
update.put(IssueField.ISSUE_CLOSE_DATE.field(), dto.getIssueCloseDate());
@@ -117,16 +124,13 @@ public class IssueNormalizer extends BaseNormalizer<IssueDto, String> {
update.put(IssueField.LANGUAGE.field(), dto.getLanguage());
update.put(IssueField.RULE_KEY.field(), dto.getRuleKey().toString());
- // TODO Not yet normalized
- // issueDoc.attributes();
-
/** Upsert elements */
Map<String, Object> upsert = getUpsertFor(IssueField.ALL_FIELDS, update);
- upsert.put(IssueField.KEY.field(), dto.getKey().toString());
+ upsert.put(IssueField.KEY.field(), dto.getKey());
return ImmutableList.of(
new UpdateRequest()
- .id(dto.getKey().toString())
+ .id(dto.getKey())
.routing(dto.getRootComponentKey())
.parent(dto.getRootComponentKey())
.doc(update)
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java
index 8555facf6bc..3e6ae8fbf7d 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexMediumTest.java
@@ -20,6 +20,7 @@
package org.sonar.server.issue.index;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
@@ -29,6 +30,7 @@ import org.sonar.api.issue.IssueQuery;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.security.DefaultGroups;
import org.sonar.api.utils.DateUtils;
+import org.sonar.api.utils.KeyValueFormat;
import org.sonar.api.web.UserRole;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.issue.db.IssueDto;
@@ -117,6 +119,18 @@ public class IssueIndexMediumTest {
IssueTesting.assertIsEquivalent(issue, result);
}
+ @Test
+ public void get_by_key_with_attributes() throws Exception {
+ IssueDto issue = createIssue();
+ db.issueDao().insert(session, issue).setIssueAttributes(KeyValueFormat.format(ImmutableMap.of("jira-issue-key", "SONAR-1234")));
+ session.commit();
+
+ Issue result = index.getByKey(issue.getKey());
+ IssueTesting.assertIsEquivalent(issue, result);
+
+ assertThat(result.attribute("jira-issue-key")).isEqualTo("SONAR-1234");
+ }
+
@Test(expected = IllegalStateException.class)
public void is_new_field_is_not_available() throws Exception {
IssueDto issue = createIssue();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
index 3e515920e2e..99a8f221463 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
@@ -20,6 +20,7 @@
package org.sonar.server.issue.ws;
+import com.google.common.collect.ImmutableMap;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
@@ -27,6 +28,7 @@ import org.junit.Test;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.security.DefaultGroups;
import org.sonar.api.utils.DateUtils;
+import org.sonar.api.utils.KeyValueFormat;
import org.sonar.api.web.UserRole;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.issue.db.*;
@@ -194,6 +196,18 @@ public class SearchActionMediumTest {
}
@Test
+ public void issue_with_attributes() throws Exception {
+ IssueDto issue = IssueTesting.newDto(rule, file, project)
+ .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")
+ .setIssueAttributes(KeyValueFormat.format(ImmutableMap.of("jira-issue-key", "SONAR-1234")));
+ db.issueDao().insert(session, issue);
+ session.commit();
+
+ WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).execute();
+ result.assertJson(this.getClass(), "issue_with_attributes.json", false);
+ }
+
+ @Test
public void issue_with_extra_fields() throws Exception {
db.userDao().insert(session, new UserDto().setLogin("simon").setName("Simon").setEmail("simon@email.com"));
db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issue_with_attributes.json b/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issue_with_attributes.json
new file mode 100644
index 00000000000..0a295c585f4
--- /dev/null
+++ b/server/sonar-server/src/test/resources/org/sonar/server/issue/ws/SearchActionMediumTest/issue_with_attributes.json
@@ -0,0 +1,10 @@
+{
+ "issues": [
+ {
+ "key": "82fd47d4-b650-4037-80bc-7b112bd4eac2",
+ "attr": {
+ "jira-issue-key": "SONAR-1234"
+ }
+ }
+ ]
+}