]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6195 Adjust UI to request fields as needed 396/head
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 24 Jun 2015 07:55:53 +0000 (09:55 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Thu, 25 Jun 2015 08:36:56 +0000 (10:36 +0200)
server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/IssueJsonWriter.java
server/sonar-server/src/main/java/org/sonar/server/user/ws/UserJsonWriter.java
server/sonar-server/src/main/java/org/sonar/server/ws/JsonWriterUtils.java
server/sonar-web/src/main/js/apps/issues/controller.js
server/sonar-web/src/main/js/components/source-viewer/main.js

index 12379d164aa508b7a7eb1dee6426b208940bce07..9f01f119669613e9793325cab63d8c41aebcf73e 100644 (file)
@@ -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();
index ef04b6d8f14fa5cc9a2f48d4a19f233a15b13061..8e6da6672afb8d4a8b763674fcccccab1cf111bf 100644 (file)
@@ -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);
     }
   }
index 0152c1b5a72a514fb427e84d9d1ef14324240fb9..5f788ee293767a7ddb601585ef8d28df082b0666 100644 (file)
@@ -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())
index 2db3c9213255c9431d081eedd20e609ad7d7ecb1..16cc16e990686b12d00fc430c72302ee4af7a2f0 100644 (file)
@@ -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);
   }
 }
index 1ddcdb180bf7959c572de39ac4889337a021c288..8c4993ad2dc26fcd7b4407d9c8ce763d83488b9e 100644 (file)
@@ -5,7 +5,9 @@ define([
 ], function (Controller, ComponentViewer, HomeView) {
 
   var $ = jQuery,
-      EXTRA_FIELDS = 'actions,transitions,actionPlanName',
+      FIELDS = 'component,componentId,project,subProject,rule,status,resolution,author,reporter,assignee,debt,line,' +
+        'message,severity,actionPlan,creationDate,updateDate,closeDate,tags,comments,attr,actions,transitions,' +
+        'actionPlanName',
       FACET_DATA_FIELDS = ['components', 'projects', 'users', 'rules', 'actionPlans', 'languages'];
 
   return Controller.extend({
@@ -21,7 +23,7 @@ define([
         ps: this.pageSize,
         s: 'FILE_LINE',
         asc: true,
-        extra_fields: EXTRA_FIELDS,
+        f: FIELDS,
         facets: this._facetsFromServer().join()
       };
     },
index 67ad617c9d2628f708e80aa45c987fdb58e8ad97..523d76e63ddc0bad84e6fa78899b852206bceaca 100644 (file)
@@ -274,7 +274,9 @@ define([
               options = {
                 data: {
                   componentUuids: this.model.id,
-                  extra_fields: 'actions,transitions,actionPlanName',
+                  f: 'component,componentId,project,subProject,rule,status,resolution,author,reporter,assignee,debt,' +
+                    'line,message,severity,actionPlan,creationDate,updateDate,closeDate,tags,comments,attr,actions,' +
+                    'transitions,actionPlanName',
                   resolved: false,
                   s: 'FILE_LINE',
                   asc: true,
@@ -712,4 +714,3 @@ define([
       });
 
     });
-