Skip to content

Commit

Permalink
SONAR-6582 Revert to old serialization format for search, start putti…
Browse files Browse the repository at this point in the history
…ng referential data in write action responses
  • Loading branch information
jblievremont committed Jun 19, 2015
1 parent ef9cd05 commit 0eaa521
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 52 deletions.
Expand Up @@ -75,6 +75,7 @@
import org.sonar.server.search.QueryContext; import org.sonar.server.search.QueryContext;
import org.sonar.server.user.UserSession; import org.sonar.server.user.UserSession;
import org.sonar.server.user.index.UserIndex; import org.sonar.server.user.index.UserIndex;
import org.sonar.server.user.ws.UserJsonWriter;
import org.sonar.server.util.RubyUtils; import org.sonar.server.util.RubyUtils;
import org.sonar.server.util.Validation; import org.sonar.server.util.Validation;


Expand Down Expand Up @@ -112,6 +113,7 @@ public class InternalRubyIssueService {
private final UserIndex userIndex; private final UserIndex userIndex;
private final DbClient dbClient; private final DbClient dbClient;
private final UserSession userSession; private final UserSession userSession;
private final UserJsonWriter userWriter;


public InternalRubyIssueService( public InternalRubyIssueService(
IssueService issueService, IssueService issueService,
Expand All @@ -121,7 +123,7 @@ public InternalRubyIssueService(
ResourceDao resourceDao, ActionService actionService, ResourceDao resourceDao, ActionService actionService,
IssueFilterService issueFilterService, IssueBulkChangeService issueBulkChangeService, IssueFilterService issueFilterService, IssueBulkChangeService issueBulkChangeService,
IssueJsonWriter issueWriter, IssueComponentHelper issueComponentHelper, UserIndex userIndex, DbClient dbClient, IssueJsonWriter issueWriter, IssueComponentHelper issueComponentHelper, UserIndex userIndex, DbClient dbClient,
UserSession userSession) { UserSession userSession, UserJsonWriter userWriter) {
this.issueService = issueService; this.issueService = issueService;
this.issueQueryService = issueQueryService; this.issueQueryService = issueQueryService;
this.commentService = commentService; this.commentService = commentService;
Expand All @@ -136,6 +138,7 @@ public InternalRubyIssueService(
this.userIndex = userIndex; this.userIndex = userIndex;
this.dbClient = dbClient; this.dbClient = dbClient;
this.userSession = userSession; this.userSession = userSession;
this.userWriter = userWriter;
} }


public Issue getIssueByKey(String issueKey) { public Issue getIssueByKey(String issueKey) {
Expand Down Expand Up @@ -699,7 +702,11 @@ public boolean isUserIssueAdmin(String projectUuid) {
* @param issue * @param issue
* @return the JSON representation of the modified issue, as a ready to use string * @return the JSON representation of the modified issue, as a ready to use string
*/ */
public String writeIssueJson(Issue issue) { public String writeIssueJson(@Nullable Issue issue) {
if (issue == null) {
return "{}";
}

StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
JsonWriter json = JsonWriter.of(writer); JsonWriter json = JsonWriter.of(writer);
DbSession dbSession = dbClient.openSession(false); DbSession dbSession = dbClient.openSession(false);
Expand Down Expand Up @@ -738,6 +745,14 @@ public String writeIssueJson(Issue issue) {
ImmutableMultimap.<String, DefaultIssueComment>of(), ImmutableMultimap.<String, DefaultIssueComment>of(),
ImmutableMap.<String, ActionPlan>of(), ImmutableMap.<String, ActionPlan>of(),
ImmutableList.of(IssueJsonWriter.ACTIONS_EXTRA_FIELD, IssueJsonWriter.TRANSITIONS_EXTRA_FIELD)); ImmutableList.of(IssueJsonWriter.ACTIONS_EXTRA_FIELD, IssueJsonWriter.TRANSITIONS_EXTRA_FIELD));

json.name("users").beginArray();
String assignee = issue.assignee();
if (assignee != null && usersByLogin.containsKey(assignee)) {
userWriter.write(json, usersByLogin.get(assignee));
}
json.endArray();

json.endObject().close(); json.endObject().close();
} finally { } finally {
MyBatis.closeQuietly(dbSession); MyBatis.closeQuietly(dbSession);
Expand All @@ -748,11 +763,13 @@ public String writeIssueJson(Issue issue) {


private Map<String, User> getIssueUsersByLogin(Issue issue) { private Map<String, User> getIssueUsersByLogin(Issue issue) {
Map<String, User> usersByLogin = Maps.newHashMap(); Map<String, User> usersByLogin = Maps.newHashMap();
if (issue.assignee() != null) { String assignee = issue.assignee();
usersByLogin.put(issue.assignee(), userIndex.getByLogin(issue.assignee())); if (assignee != null) {
usersByLogin.put(assignee, userIndex.getByLogin(assignee));
} }
if (issue.reporter() != null) { String reporter = issue.reporter();
usersByLogin.put(issue.reporter(), userIndex.getByLogin(issue.reporter())); if (reporter != null) {
usersByLogin.put(reporter, userIndex.getByLogin(reporter));
} }
return usersByLogin; return usersByLogin;
} }
Expand Down
Expand Up @@ -42,7 +42,6 @@
import org.sonar.core.component.ComponentDto; import org.sonar.core.component.ComponentDto;
import org.sonar.markdown.Markdown; import org.sonar.markdown.Markdown;
import org.sonar.server.user.UserSession; import org.sonar.server.user.UserSession;
import org.sonar.server.user.ws.UserJsonWriter;


public class IssueJsonWriter { public class IssueJsonWriter {


Expand All @@ -57,14 +56,12 @@ public class IssueJsonWriter {
private final I18n i18n; private final I18n i18n;
private final Durations durations; private final Durations durations;
private final UserSession userSession; private final UserSession userSession;
private final UserJsonWriter userWriter;
private final IssueActionsWriter actionsWriter; private final IssueActionsWriter actionsWriter;


public IssueJsonWriter(I18n i18n, Durations durations, UserSession userSession, UserJsonWriter userWriter, IssueActionsWriter actionsWriter) { public IssueJsonWriter(I18n i18n, Durations durations, UserSession userSession, IssueActionsWriter actionsWriter) {
this.i18n = i18n; this.i18n = i18n;
this.durations = durations; this.durations = durations;
this.userSession = userSession; this.userSession = userSession;
this.userWriter = userWriter;
this.actionsWriter = actionsWriter; this.actionsWriter = actionsWriter;
} }


Expand Down Expand Up @@ -98,18 +95,14 @@ public void write(JsonWriter json, Issue issue, Map<String, User> usersByLogin,
.prop("message", issue.message()) .prop("message", issue.message())
.prop("line", issue.line()) .prop("line", issue.line())
.prop("debt", debt != null ? durations.encode(debt) : null) .prop("debt", debt != null ? durations.encode(debt) : null)
.prop("assignee", issue.assignee())
.prop("reporter", issue.reporter()) .prop("reporter", issue.reporter())
.prop("author", issue.authorLogin()) .prop("author", issue.authorLogin())
.prop("actionPlan", actionPlanKey) .prop("actionPlan", actionPlanKey)
.prop("creationDate", isoDate(issue.creationDate())) .prop("creationDate", isoDate(issue.creationDate()))
.prop("updateDate", isoDate(updateDate)) .prop("updateDate", isoDate(updateDate))
// TODO Remove as part of Front-end rework on Issue Domain
.prop("fUpdateAge", formatAgeDate(updateDate))
.prop("closeDate", isoDate(issue.closeDate())); .prop("closeDate", isoDate(issue.closeDate()));


json.name("assignee");
userWriter.write(json, usersByLogin.get(issue.assignee()));

writeTags(issue, json); writeTags(issue, json);
writeIssueComments(commentsByIssues.get(issue.key()), usersByLogin, json); writeIssueComments(commentsByIssues.get(issue.key()), usersByLogin, json);
writeIssueAttributes(issue, json); writeIssueAttributes(issue, json);
Expand Down
Expand Up @@ -54,6 +54,7 @@
import org.sonar.server.tester.UserSessionRule; import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.ThreadLocalUserSession; import org.sonar.server.user.ThreadLocalUserSession;
import org.sonar.server.user.index.UserIndex; import org.sonar.server.user.index.UserIndex;
import org.sonar.server.user.ws.UserJsonWriter;


import static com.google.common.collect.Lists.newArrayList; import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap; import static com.google.common.collect.Maps.newHashMap;
Expand Down Expand Up @@ -101,6 +102,8 @@ public class InternalRubyIssueServiceTest {


DbSession dbSession; DbSession dbSession;


UserJsonWriter userWriter;

@Before @Before
public void setUp() { public void setUp() {
issueService = mock(IssueService.class); issueService = mock(IssueService.class);
Expand All @@ -117,12 +120,13 @@ public void setUp() {
userIndex = mock(UserIndex.class); userIndex = mock(UserIndex.class);
dbClient = mock(DbClient.class); dbClient = mock(DbClient.class);
dbSession = mock(DbSession.class); dbSession = mock(DbSession.class);
userWriter = mock(UserJsonWriter.class);


ResourceDto project = new ResourceDto().setKey("org.sonar.Sample"); ResourceDto project = new ResourceDto().setKey("org.sonar.Sample");
when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(project); when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(project);


service = new InternalRubyIssueService(issueService, issueQueryService, commentService, changelogService, actionPlanService, resourceDao, actionService, service = new InternalRubyIssueService(issueService, issueQueryService, commentService, changelogService, actionPlanService, resourceDao, actionService,
issueFilterService, issueBulkChangeService, issueWriter, issueComponentHelper, userIndex, dbClient, userSessionRule); issueFilterService, issueBulkChangeService, issueWriter, issueComponentHelper, userIndex, dbClient, userSessionRule, userWriter);
} }


@Test @Test
Expand Down
Expand Up @@ -8,8 +8,7 @@
"status": "OPEN", "status": "OPEN",
"resolution": "OPEN", "resolution": "OPEN",
"severity": "MAJOR", "severity": "MAJOR",
"updateDate": "2017-12-04T00:00:00+0100", "updateDate": "2017-12-04T00:00:00+0100"
"fUpdateAge": "less than a minute"
}, },
{ {
"key": "92fd47d4-b650-4037-80bc-7b112bd4eac2", "key": "92fd47d4-b650-4037-80bc-7b112bd4eac2",
Expand All @@ -19,8 +18,7 @@
"status": "OPEN", "status": "OPEN",
"resolution": "OPEN", "resolution": "OPEN",
"severity": "MAJOR", "severity": "MAJOR",
"updateDate": "2017-12-04T00:00:00+0100", "updateDate": "2017-12-04T00:00:00+0100"
"fUpdateAge": "less than a minute"
} }
], ],
"components": [ "components": [
Expand Down
Expand Up @@ -8,10 +8,7 @@
"status": "OPEN", "status": "OPEN",
"severity": "MAJOR", "severity": "MAJOR",
"debt": "10min", "debt": "10min",
"fUpdateAge": "less than a minute", "assignee": "alice"
"assignee": {
"login": "alice"
}
} }
], ],
"facets": [ "facets": [
Expand Down
Expand Up @@ -7,8 +7,7 @@
"rule": "xoo:x1", "rule": "xoo:x1",
"status": "OPEN", "status": "OPEN",
"severity": "MAJOR", "severity": "MAJOR",
"debt": "10min", "debt": "10min"
"fUpdateAge": "less than a minute"
} }
], ],
"facets": [ "facets": [
Expand Down
Expand Up @@ -7,8 +7,7 @@
"rule": "xoo:x1", "rule": "xoo:x1",
"status": "OPEN", "status": "OPEN",
"severity": "MAJOR", "severity": "MAJOR",
"debt": "10min", "debt": "10min"
"fUpdateAge": "less than a minute"
} }
], ],
"facets": [ "facets": [
Expand Down
Expand Up @@ -8,10 +8,7 @@
"status": "OPEN", "status": "OPEN",
"severity": "MAJOR", "severity": "MAJOR",
"debt": "10min", "debt": "10min",
"fUpdateAge": "less than a minute", "assignee": "john"
"assignee": {
"login": "john"
}
} }
], ],
"facets": [ "facets": [
Expand Down
Expand Up @@ -7,8 +7,7 @@
"rule": "xoo:x1", "rule": "xoo:x1",
"status": "OPEN", "status": "OPEN",
"severity": "MAJOR", "severity": "MAJOR",
"debt": "10min", "debt": "10min"
"fUpdateAge": "less than a minute"
} }
], ],
"rules": [] "rules": []
Expand Down
Expand Up @@ -13,16 +13,10 @@
"severity": "MAJOR", "severity": "MAJOR",
"debt": "10min", "debt": "10min",
"author": "John", "author": "John",
"assignee": { "assignee": "simon",
"login": "simon",
"name": "Simon",
"active": true,
"email": "simon@email.com"
},
"reporter": "fabrice", "reporter": "fabrice",
"actionPlan": "AP-ABCD", "actionPlan": "AP-ABCD",
"updateDate": "2017-12-04T00:00:00+0100", "updateDate": "2017-12-04T00:00:00+0100"
"fUpdateAge": "less than a minute"
} }
], ],
"rules": [ "rules": [
Expand Down
Expand Up @@ -8,8 +8,7 @@
"status": "OPEN", "status": "OPEN",
"resolution": "OPEN", "resolution": "OPEN",
"severity": "MAJOR", "severity": "MAJOR",
"updateDate": "2017-12-04T00:00:00+0100", "updateDate": "2017-12-04T00:00:00+0100"
"fUpdateAge": "less than a minute"
} }
], ],
"components": [ "components": [
Expand Down
Expand Up @@ -2,12 +2,7 @@
"issues": [ "issues": [
{ {
"key": "82fd47d4-b650-4037-80bc-7b112bd4eac2", "key": "82fd47d4-b650-4037-80bc-7b112bd4eac2",
"assignee": { "assignee": "simon",
"login": "simon",
"name": "Simon",
"active": true,
"email": "simon@email.com"
},
"reporter": "fabrice", "reporter": "fabrice",
"reporterName": "Fabrice", "reporterName": "Fabrice",
"actionPlan": "AP-ABCD", "actionPlan": "AP-ABCD",
Expand Down
Expand Up @@ -17,8 +17,7 @@
"author": "John", "author": "John",
"assignee": "simon", "assignee": "simon",
"reporter": "fabrice", "reporter": "fabrice",
"updateDate": "2014-12-04T00:00:00+0100", "updateDate": "2014-12-04T00:00:00+0100"
"fUpdateAge": "less than a minute"
} }
], ],
"rules": [ "rules": [
Expand Down

0 comments on commit 0eaa521

Please sign in to comment.