aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
diff options
context:
space:
mode:
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-06-24 09:55:53 +0200
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>2015-06-25 10:36:56 +0200
commit5a9eaac4ac4696c88fb9c4e4499e0e5725c5673e (patch)
tree5253259313cf1c4d313f93078ecb6d628c365ec5 /server/sonar-server
parent9273b7fa6ddc25715837e49d6ba083bb888b0c30 (diff)
downloadsonarqube-5a9eaac4ac4696c88fb9c4e4499e0e5725c5673e.tar.gz
sonarqube-5a9eaac4ac4696c88fb9c4e4499e0e5725c5673e.zip
SONAR-6195 Adjust UI to request fields as needed
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java13
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueJsonWriter.java34
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/user/ws/UserJsonWriter.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/ws/JsonWriterUtils.java14
4 files changed, 41 insertions, 26 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
index 12379d164aa..9f01f119669 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
@@ -81,6 +81,7 @@ import org.sonar.server.util.RubyUtils;
import org.sonar.server.util.Validation;
import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Maps.newHashMap;
/**
* Used through ruby code <pre>Internal.issues</pre>
@@ -100,6 +101,8 @@ public class InternalRubyIssueService {
private static final String ACTION_PLANS_ERRORS_ACTION_PLAN_DOES_NOT_EXIST_MESSAGE = "action_plans.errors.action_plan_does_not_exist";
+ private static final List<String> ISSUE_FIELDS = ImmutableList.copyOf(IssueJsonWriter.SELECTABLE_FIELDS);
+
private final IssueService issueService;
private final IssueQueryService issueQueryService;
private final IssueCommentService commentService;
@@ -742,14 +745,20 @@ public class InternalRubyIssueService {
projectsByComponentUuid = issueComponentHelper.prepareComponentsAndProjects(projectUuids, componentUuids, componentsByUuid, componentDtos, subProjectDtos, dbSession);
+ Map<String, ActionPlan> actionPlans = newHashMap();
+ String actionPlanKey = issue.actionPlanKey();
+ if (actionPlanKey != null) {
+ actionPlans.put(actionPlanKey, actionPlanService.findByKey(actionPlanKey, userSession));
+ }
+
json.beginObject().name("issue");
issueWriter.write(json, issue,
usersByLogin,
componentsByUuid,
projectsByComponentUuid,
ImmutableMultimap.<String, DefaultIssueComment>of(),
- ImmutableMap.<String, ActionPlan>of(),
- ImmutableList.copyOf(IssueJsonWriter.SELECTABLE_FIELDS));
+ actionPlans,
+ ISSUE_FIELDS);
json.name("users").beginArray();
String assignee = issue.assignee();
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueJsonWriter.java b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueJsonWriter.java
index ef04b6d8f14..8e6da6672af 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueJsonWriter.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueJsonWriter.java
@@ -32,7 +32,6 @@ import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import org.sonar.api.i18n.I18n;
import org.sonar.api.issue.ActionPlan;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.IssueComment;
@@ -86,13 +85,11 @@ public class IssueJsonWriter {
private static final List<String> SELECTABLE_MINUS_EXTRAS = ImmutableList.copyOf(Sets.difference(SELECTABLE_FIELDS, EXTRA_FIELDS));
- private final I18n i18n;
private final Durations durations;
private final UserSession userSession;
private final IssueActionsWriter actionsWriter;
- public IssueJsonWriter(I18n i18n, Durations durations, UserSession userSession, IssueActionsWriter actionsWriter) {
- this.i18n = i18n;
+ public IssueJsonWriter(Durations durations, UserSession userSession, IssueActionsWriter actionsWriter) {
this.durations = durations;
this.userSession = userSession;
this.actionsWriter = actionsWriter;
@@ -102,12 +99,7 @@ public class IssueJsonWriter {
Map<String, ComponentDto> projectsByComponentUuid, Multimap<String, DefaultIssueComment> commentsByIssues, Map<String, ActionPlan> actionPlanByKeys,
@Nullable List<String> selectedFields) {
- List<String> fields = Lists.newArrayList();
- if (selectedFields == null || selectedFields.isEmpty()) {
- fields.addAll(SELECTABLE_MINUS_EXTRAS);
- } else {
- fields.addAll(selectedFields);
- }
+ List<String> fields = useDefaultFieldsIfNotSpecified(selectedFields);
json.beginObject();
@@ -145,19 +137,29 @@ public class IssueJsonWriter {
writeIfNeeded(json, isoDate(updateDate), FIELD_UPDATE_DATE, fields);
writeIfNeeded(json, isoDate(issue.closeDate()), FIELD_CLOSE_DATE, fields);
- if (JsonWriterUtils.isFieldWanted(FIELD_TAGS, fields)) {
+ if (JsonWriterUtils.isFieldNeeded(FIELD_TAGS, fields)) {
writeTags(issue, json);
}
- if (JsonWriterUtils.isFieldWanted(FIELD_COMMENTS, fields)) {
+ if (JsonWriterUtils.isFieldNeeded(FIELD_COMMENTS, fields)) {
writeIssueComments(commentsByIssues.get(issue.key()), usersByLogin, json);
}
- if (JsonWriterUtils.isFieldWanted(FIELD_ATTRIBUTES, fields)) {
+ if (JsonWriterUtils.isFieldNeeded(FIELD_ATTRIBUTES, fields)) {
writeIssueAttributes(issue, json);
}
writeIssueExtraFields(issue, actionPlanByKeys, fields, json);
json.endObject();
}
+ private List<String> useDefaultFieldsIfNotSpecified(List<String> selectedFields) {
+ List<String> fields = Lists.newArrayList();
+ if (selectedFields == null || selectedFields.isEmpty()) {
+ fields.addAll(SELECTABLE_MINUS_EXTRAS);
+ } else {
+ fields.addAll(selectedFields);
+ }
+ return fields;
+ }
+
@CheckForNull
private static String isoDate(@Nullable Date date) {
if (date != null) {
@@ -211,15 +213,15 @@ public class IssueJsonWriter {
private void writeIssueExtraFields(Issue issue, Map<String, ActionPlan> actionPlanByKeys,
@Nullable List<String> fields, JsonWriter json) {
- if (JsonWriterUtils.isFieldWanted(FIELD_ACTIONS, fields)) {
+ if (JsonWriterUtils.isFieldNeeded(FIELD_ACTIONS, fields)) {
actionsWriter.writeActions(issue, json);
}
- if (JsonWriterUtils.isFieldWanted(FIELD_TRANSITIONS, fields)) {
+ if (JsonWriterUtils.isFieldNeeded(FIELD_TRANSITIONS, fields)) {
actionsWriter.writeTransitions(issue, json);
}
- if (JsonWriterUtils.isFieldWanted(FIELD_ACTION_PLAN_NAME, fields)) {
+ if (JsonWriterUtils.isFieldNeeded(FIELD_ACTION_PLAN_NAME, fields)) {
writeActionPlanName(issue, actionPlanByKeys, json);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/UserJsonWriter.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/UserJsonWriter.java
index 0152c1b5a72..5f788ee2937 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/UserJsonWriter.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/UserJsonWriter.java
@@ -29,7 +29,7 @@ import org.sonar.core.permission.GlobalPermissions;
import org.sonar.server.user.UserSession;
import org.sonar.server.user.index.UserDoc;
-import static org.sonar.server.ws.JsonWriterUtils.isFieldWanted;
+import static org.sonar.server.ws.JsonWriterUtils.isFieldNeeded;
import static org.sonar.server.ws.JsonWriterUtils.writeIfNeeded;
public class UserJsonWriter {
@@ -76,7 +76,7 @@ public class UserJsonWriter {
}
private void writeGroupsIfNeeded(JsonWriter json, Collection<String> groups, @Nullable Collection<String> fields) {
- if (isFieldWanted(FIELD_GROUPS, fields) && userSession.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN)) {
+ if (isFieldNeeded(FIELD_GROUPS, fields) && userSession.hasGlobalPermission(GlobalPermissions.SYSTEM_ADMIN)) {
json.name(FIELD_GROUPS).beginArray();
for (String groupName : groups) {
json.value(groupName);
@@ -86,7 +86,7 @@ public class UserJsonWriter {
}
private static void writeScmAccountsIfNeeded(JsonWriter json, Collection<String> fields, User user) {
- if (isFieldWanted(FIELD_SCM_ACCOUNTS, fields)) {
+ if (isFieldNeeded(FIELD_SCM_ACCOUNTS, fields)) {
json.name(FIELD_SCM_ACCOUNTS)
.beginArray()
.values(((UserDoc) user).scmAccounts())
diff --git a/server/sonar-server/src/main/java/org/sonar/server/ws/JsonWriterUtils.java b/server/sonar-server/src/main/java/org/sonar/server/ws/JsonWriterUtils.java
index 2db3c921325..16cc16e9906 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/ws/JsonWriterUtils.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/ws/JsonWriterUtils.java
@@ -25,31 +25,35 @@ import org.sonar.api.utils.text.JsonWriter;
public class JsonWriterUtils {
+ private JsonWriterUtils() {
+ // Utility class
+ }
+
public static void writeIfNeeded(JsonWriter json, @Nullable String value, String field, Collection<String> fields) {
- if (isFieldWanted(field, fields)) {
+ if (isFieldNeeded(field, fields)) {
json.prop(field, value);
}
}
public static void writeIfNeeded(JsonWriter json, @Nullable Boolean value, String field, Collection<String> fields) {
- if (isFieldWanted(field, fields)) {
+ if (isFieldNeeded(field, fields)) {
json.prop(field, value);
}
}
public static void writeIfNeeded(JsonWriter json, @Nullable Integer value, String field, Collection<String> fields) {
- if (isFieldWanted(field, fields)) {
+ if (isFieldNeeded(field, fields)) {
json.prop(field, value);
}
}
public static void writeIfNeeded(JsonWriter json, @Nullable Long value, String field, Collection<String> fields) {
- if (isFieldWanted(field, fields)) {
+ if (isFieldNeeded(field, fields)) {
json.prop(field, value);
}
}
- public static boolean isFieldWanted(String field, @Nullable Collection<String> fields) {
+ public static boolean isFieldNeeded(String field, @Nullable Collection<String> fields) {
return fields == null || fields.isEmpty() || fields.contains(field);
}
}