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>
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;
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();
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;
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;
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();
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) {
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);
}
}
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 {
}
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);
}
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())
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);
}
}
], 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({
ps: this.pageSize,
s: 'FILE_LINE',
asc: true,
- extra_fields: EXTRA_FIELDS,
+ f: FIELDS,
facets: this._facetsFromServer().join()
};
},
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,
});
});
-