import org.sonar.core.issue.ActionPlanStats;
import org.sonar.core.issue.DefaultActionPlan;
import org.sonar.core.issue.DefaultIssueComment;
-import org.sonar.core.issue.FieldDiffs;
-import org.sonar.server.issue.workflow.Transition;
import org.sonar.db.component.ResourceDao;
import org.sonar.db.component.ResourceDto;
import org.sonar.db.component.ResourceQuery;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.issue.actionplan.ActionPlanService;
import org.sonar.server.issue.filter.IssueFilterService;
+import org.sonar.server.issue.workflow.Transition;
import org.sonar.server.search.QueryContext;
import org.sonar.server.user.UserSession;
import org.sonar.server.util.RubyUtils;
return changelogService.changelog(issue);
}
- public List<String> formatChangelog(FieldDiffs diffs) {
- return changelogService.formatDiffs(diffs);
- }
-
public List<DefaultIssueComment> findComments(String issueKey) {
return commentService.findComments(issueKey);
}
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.issue;
-
-import java.io.Serializable;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import org.sonar.api.server.ServerSide;
-import org.sonar.api.i18n.I18n;
-import org.sonar.core.issue.FieldDiffs;
-import org.sonar.api.utils.Duration;
-import org.sonar.api.utils.Durations;
-import org.sonar.server.user.UserSession;
-
-import static com.google.common.collect.Lists.newArrayList;
-
-@ServerSide
-public class IssueChangelogFormatter {
-
- private static final String ISSUE_CHANGELOG_FIELD = "issue.changelog.field.";
-
- private final I18n i18n;
- private final Durations durations;
- private final UserSession userSession;
-
- public IssueChangelogFormatter(I18n i18n, Durations durations, UserSession userSession) {
- this.i18n = i18n;
- this.durations = durations;
- this.userSession = userSession;
- }
-
- public List<String> format(Locale locale, FieldDiffs diffs) {
- List<String> result = newArrayList();
- for (Map.Entry<String, FieldDiffs.Diff> entry : diffs.diffs().entrySet()) {
- StringBuilder message = new StringBuilder();
- String key = entry.getKey();
- IssueChangelogDiffFormat diffFormat = format(key, entry.getValue());
- if (diffFormat.newValue() != null) {
- message.append(i18n.message(locale, "issue.changelog.changed_to", null, i18n.message(locale, ISSUE_CHANGELOG_FIELD + key, null), diffFormat.newValue()));
- } else {
- message.append(i18n.message(locale, "issue.changelog.removed", null, i18n.message(locale, ISSUE_CHANGELOG_FIELD + key, null)));
- }
- if (diffFormat.oldValue() != null) {
- message.append(" (");
- message.append(i18n.message(locale, "issue.changelog.was", null, diffFormat.oldValue()));
- message.append(")");
- }
- result.add(message.toString());
- }
- return result;
- }
-
- private IssueChangelogDiffFormat format(String key, FieldDiffs.Diff diff) {
- Serializable newValue = diff.newValue();
- Serializable oldValue = diff.oldValue();
-
- String newValueString = newValue != null && !"".equals(newValue) ? newValue.toString() : null;
- String oldValueString = oldValue != null && !"".equals(oldValue) ? oldValue.toString() : null;
- if (IssueUpdater.TECHNICAL_DEBT.equals(key)) {
- if (newValueString != null) {
- newValueString = durations.format(userSession.locale(), Duration.create(Long.parseLong(newValueString)), Durations.DurationFormat.SHORT);
- }
- if (oldValueString != null) {
- oldValueString = durations.format(userSession.locale(), Duration.create(Long.parseLong(oldValueString)), Durations.DurationFormat.SHORT);
- }
- }
- return new IssueChangelogDiffFormat(oldValueString, newValueString);
- }
-
-}
import java.util.Collection;
import java.util.List;
-import org.sonar.api.server.ServerSide;
import org.sonar.api.issue.Issue;
-import org.sonar.core.issue.FieldDiffs;
+import org.sonar.api.server.ServerSide;
import org.sonar.api.user.User;
import org.sonar.api.user.UserFinder;
+import org.sonar.core.issue.FieldDiffs;
import org.sonar.db.issue.IssueChangeDao;
-import org.sonar.server.user.UserSession;
import static com.google.common.collect.Lists.newArrayList;
private final IssueChangeDao changeDao;
private final UserFinder userFinder;
private final IssueService issueService;
- private final IssueChangelogFormatter formatter;
- private final UserSession userSession;
- public IssueChangelogService(IssueChangeDao changeDao, UserFinder userFinder, IssueService issueService, IssueChangelogFormatter formatter, UserSession userSession) {
+ public IssueChangelogService(IssueChangeDao changeDao, UserFinder userFinder, IssueService issueService) {
this.changeDao = changeDao;
this.userFinder = userFinder;
this.issueService = issueService;
- this.formatter = formatter;
- this.userSession = userSession;
}
public IssueChangelog changelog(String issueKey) {
Collection<User> users = userFinder.findByLogins(logins);
return new IssueChangelog(changes, users);
}
-
- public List<String> formatDiffs(FieldDiffs diffs) {
- return formatter.format(userSession.locale(), diffs);
- }
}
import org.sonar.api.rules.XMLRuleParser;
import org.sonar.api.server.rule.RulesDefinitionXmlLoader;
import org.sonar.core.component.DefaultResourceTypes;
-import org.sonar.server.issue.SetTypeAction;
-import org.sonar.server.issue.IssueUpdater;
-import org.sonar.server.issue.workflow.FunctionExecutor;
-import org.sonar.server.issue.workflow.IssueWorkflow;
import org.sonar.core.timemachine.Periods;
import org.sonar.core.user.DefaultUserFinder;
import org.sonar.core.user.DeprecatedUserFinder;
import org.sonar.server.issue.CommentAction;
import org.sonar.server.issue.InternalRubyIssueService;
import org.sonar.server.issue.IssueBulkChangeService;
-import org.sonar.server.issue.IssueChangelogFormatter;
import org.sonar.server.issue.IssueChangelogService;
import org.sonar.server.issue.IssueCommentService;
import org.sonar.server.issue.IssueQueryService;
import org.sonar.server.issue.IssueService;
+import org.sonar.server.issue.IssueUpdater;
import org.sonar.server.issue.PlanAction;
import org.sonar.server.issue.RemoveTagsAction;
import org.sonar.server.issue.ServerIssueStorage;
import org.sonar.server.issue.SetSeverityAction;
+import org.sonar.server.issue.SetTypeAction;
import org.sonar.server.issue.TransitionAction;
import org.sonar.server.issue.actionplan.ActionPlanService;
import org.sonar.server.issue.actionplan.ActionPlanWs;
import org.sonar.server.issue.notification.NewIssuesEmailTemplate;
import org.sonar.server.issue.notification.NewIssuesNotificationDispatcher;
import org.sonar.server.issue.notification.NewIssuesNotificationFactory;
+import org.sonar.server.issue.workflow.FunctionExecutor;
+import org.sonar.server.issue.workflow.IssueWorkflow;
import org.sonar.server.issue.ws.IssueWsModule;
import org.sonar.server.language.ws.LanguageWs;
import org.sonar.server.measure.MeasureFilterEngine;
ActionService.class,
Actions.class,
IssueBulkChangeService.class,
- IssueChangelogFormatter.class,
WsResponseCommonFormat.class,
IssueWsModule.class,
IssueService.class,
verify(issueBulkChangeService).execute(any(IssueBulkChangeQuery.class), any(ThreadLocalUserSession.class));
}
- @Test
- public void format_changelog() {
- FieldDiffs fieldDiffs = new FieldDiffs();
- service.formatChangelog(fieldDiffs);
- verify(changelogService).formatDiffs(eq(fieldDiffs));
- }
-
@Test
public void max_query_size() {
assertThat(service.maxPageSize()).isEqualTo(500);
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.issue;
-
-import java.util.List;
-import java.util.Locale;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.i18n.I18n;
-import org.sonar.core.issue.FieldDiffs;
-import org.sonar.api.utils.Duration;
-import org.sonar.api.utils.Durations;
-import org.sonar.server.tester.UserSessionRule;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class IssueChangelogFormatterTest {
-
- private static final Locale DEFAULT_LOCALE = Locale.getDefault();
-
- @Rule
- public UserSessionRule userSessionRule = UserSessionRule.standalone();
-
- @Mock
- private I18n i18n;
-
- @Mock
- private Durations durations;
-
-
- private IssueChangelogFormatter formatter;
-
- @Before
- public void before() {
- formatter = new IssueChangelogFormatter(i18n, durations, userSessionRule);
- }
-
- @Test
- public void format_field_diffs_with_new_and_old_value() {
- FieldDiffs diffs = new FieldDiffs();
- diffs.setDiff("severity", "BLOCKER", "INFO");
-
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Severity", "INFO")).thenReturn("Severity changed to INFO");
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "BLOCKER")).thenReturn("was BLOCKER");
-
- List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
- assertThat(result).hasSize(1);
- String message = result.get(0);
- assertThat(message).isEqualTo("Severity changed to INFO (was BLOCKER)");
- }
-
- @Test
- public void format_field_diffs_with_only_new_value() {
- FieldDiffs diffs = new FieldDiffs();
- diffs.setDiff("severity", null, "INFO");
-
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Severity", "INFO")).thenReturn("Severity changed to INFO");
-
- List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
- assertThat(result).hasSize(1);
- String message = result.get(0);
- assertThat(message).isEqualTo("Severity changed to INFO");
- }
-
- @Test
- public void format_field_diffs_with_only_old_value() {
- FieldDiffs diffs = new FieldDiffs();
- diffs.setDiff("severity", "BLOCKER", null);
-
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "BLOCKER")).thenReturn("was BLOCKER");
-
- List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
- assertThat(result).hasSize(1);
- String message = result.get(0);
- assertThat(message).isEqualTo("Severity removed (was BLOCKER)");
- }
-
- @Test
- public void format_field_diffs_without_value() {
- FieldDiffs diffs = new FieldDiffs();
- diffs.setDiff("severity", null, null);
-
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
-
- List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
- assertThat(result).hasSize(1);
- String message = result.get(0);
- assertThat(message).isEqualTo("Severity removed");
- }
-
- @Test
- public void format_field_diffs_with_empty_old_value() {
- FieldDiffs diffs = new FieldDiffs();
- diffs.setDiff("severity", "", null);
-
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
-
- List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
- assertThat(result).hasSize(1);
- String message = result.get(0);
- assertThat(message).isEqualTo("Severity removed");
- }
-
- @Test
- public void format_technical_debt_with_old_and_new_value() {
- FieldDiffs diffs = new FieldDiffs();
- diffs.setDiff("technicalDebt", "18000", "28800");
-
- when(durations.format(any(Locale.class), eq(Duration.create(18000L)), eq(Durations.DurationFormat.SHORT))).thenReturn("5 hours");
- when(durations.format(any(Locale.class), eq(Duration.create(28800L)), eq(Durations.DurationFormat.SHORT))).thenReturn("1 days");
-
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days");
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "5 hours")).thenReturn("was 5 hours");
-
- List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
- assertThat(result).hasSize(1);
- String message = result.get(0);
- assertThat(message).isEqualTo("Technical Debt changed to 1 days (was 5 hours)");
- }
-
- @Test
- public void format_technical_debt_with_new_value_only() {
- FieldDiffs diffs = new FieldDiffs();
- diffs.setDiff("technicalDebt", null, "28800");
-
- when(durations.format(any(Locale.class), eq(Duration.create(28800L)), eq(Durations.DurationFormat.SHORT))).thenReturn("1 days");
-
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days");
-
- List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
- assertThat(result).hasSize(1);
- String message = result.get(0);
- assertThat(message).isEqualTo("Technical Debt changed to 1 days");
- }
-
- @Test
- public void format_technical_debt_without_value() {
- FieldDiffs diffs = new FieldDiffs();
- diffs.setDiff("technicalDebt", null, null);
-
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
- when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Technical Debt")).thenReturn("Technical Debt removed");
-
- List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
- assertThat(result).hasSize(1);
- String message = result.get(0);
- assertThat(message).isEqualTo("Technical Debt removed");
- }
-
-}
package org.sonar.server.issue;
import java.util.Arrays;
-import java.util.Locale;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.sonar.core.issue.FieldDiffs;
import org.sonar.core.user.DefaultUser;
import org.sonar.db.issue.IssueChangeDao;
-import org.sonar.server.tester.UserSessionRule;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class IssueChangelogServiceTest {
- @Rule
- public UserSessionRule userSessionRule = UserSessionRule.standalone();
-
@Mock
IssueChangeDao changeDao;
@Mock
IssueService issueService;
- @Mock
- IssueChangelogFormatter formatter;
-
IssueChangelogService service;
@Before
public void setUp() {
- service = new IssueChangelogService(changeDao, userFinder, issueService, formatter, userSessionRule);
+ service = new IssueChangelogService(changeDao, userFinder, issueService);
}
@Test
assertThat(changelog.changes().get(0).diffs()).containsKeys("effort");
}
- @Test
- public void format_diffs() {
- FieldDiffs diffs = new FieldDiffs().setUserLogin("arthur").setDiff("severity", "MAJOR", "BLOCKER");
- userSessionRule.login();
- service.formatDiffs(diffs);
- verify(formatter).format(any(Locale.class), eq(diffs));
- }
}