Browse Source

SONAR-7291 Clean up no more used code related to rails

Remove no more used rails Issue.to_hash
Remove no more used method from InternalRubyIssueService
tags/6.3-RC1
Julien Lancelot 7 years ago
parent
commit
80c4b53f2b

+ 2
- 84
server/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java View File

@@ -20,21 +20,12 @@
package org.sonar.server.issue;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.IssueComment;
import org.sonar.api.server.ServerSide;
import org.sonar.api.web.UserRole;
import org.sonar.core.issue.DefaultIssueComment;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.issue.index.IssueDoc;
import org.sonar.server.issue.index.IssueIndex;
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;
import org.sonarqube.ws.client.issue.IssuesWsParameters;
@@ -49,29 +40,22 @@ import org.sonarqube.ws.client.issue.IssuesWsParameters;
@ServerSide
public class InternalRubyIssueService {

private final IssueIndex issueIndex;
private final IssueService issueService;
private final IssueQueryService issueQueryService;
private final IssueCommentService commentService;
private final IssueChangelogService changelogService;
private final IssueBulkChangeService issueBulkChangeService;
private final ActionService actionService;
private final UserSession userSession;

public InternalRubyIssueService(
IssueIndex issueIndex, IssueService issueService,
IssueQueryService issueQueryService,
IssueService issueService,
IssueCommentService commentService,
IssueChangelogService changelogService,
IssueBulkChangeService issueBulkChangeService,
ActionService actionService, UserSession userSession) {
this.issueIndex = issueIndex;
UserSession userSession) {
this.issueService = issueService;
this.issueQueryService = issueQueryService;
this.commentService = commentService;
this.changelogService = changelogService;
this.issueBulkChangeService = issueBulkChangeService;
this.actionService = actionService;
this.userSession = userSession;
}

@@ -79,34 +63,10 @@ public class InternalRubyIssueService {
return issueService.listTransitions(issueKey);
}

public List<Transition> listTransitions(Issue issue) {
return issueService.listTransitions(issue);
}

public List<String> listStatus() {
return issueService.listStatus();
}

public List<String> listResolutions() {
return Issue.RESOLUTIONS;
}

public IssueChangelog changelog(String issueKey) {
return changelogService.changelog(issueKey);
}

public IssueChangelog changelog(Issue issue) {
return changelogService.changelog(issue);
}

public List<DefaultIssueComment> findComments(String issueKey) {
return commentService.findComments(issueKey);
}

public List<DefaultIssueComment> findCommentsByIssueKeys(Collection<String> issueKeys) {
return commentService.findComments(issueKeys);
}

public Result<IssueComment> addComment(String issueKey, String text) {
Result<IssueComment> result = Result.of();
try {
@@ -131,25 +91,6 @@ public class InternalRubyIssueService {
return result;
}

public IssueComment findComment(String commentKey) {
return commentService.findComment(commentKey);
}

public List<String> listActions(String issueKey) {
return actionService.listAvailableActions(issueKey);
}

public IssueQuery emptyIssueQuery() {
return issueQueryService.createFromMap(Maps.<String, Object>newHashMap());
}

/**
* Execute issue filter from parameters
*/
public List<IssueDoc> execute(Map<String, Object> props) {
return issueIndex.search(issueQueryService.createFromMap(props), toSearchOptions(props)).getDocs();
}

/**
* Execute a bulk change
*/
@@ -158,13 +99,6 @@ public class InternalRubyIssueService {
return issueBulkChangeService.execute(issueBulkChangeQuery, userSession);
}

/**
* Do not make this method static as it's called by rails
*/
public int maxPageSize() {
return QueryContext.MAX_LIMIT;
}

@VisibleForTesting
static SearchOptions toSearchOptions(Map<String, Object> props) {
SearchOptions options = new SearchOptions();
@@ -178,20 +112,4 @@ public class InternalRubyIssueService {
return options;
}

public Collection<String> listTags() {
return issueService.listTags(null, 0);
}

public Map<String, Long> listTagsForComponent(String componentUuid, int pageSize) {
IssueQuery query = issueQueryService.createFromMap(
ImmutableMap.<String, Object>of(
"componentUuids", componentUuid,
"resolved", false));
return issueService.listTagsForComponent(query, pageSize);
}

public boolean isUserIssueAdmin(String projectUuid) {
return userSession.hasComponentUuidPermission(UserRole.ISSUE_ADMIN, projectUuid);
}

}

+ 1
- 5
server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java View File

@@ -29,11 +29,11 @@ import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rules.RuleType;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;
import org.sonar.api.user.User;
import org.sonar.api.user.UserFinder;
@@ -84,10 +84,6 @@ public class IssueService {
this.userSession = userSession;
}

public List<String> listStatus() {
return workflow.statusKeys();
}

/**
* List of available transitions.
* <p>

+ 0
- 1
server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java View File

@@ -60,7 +60,6 @@ public class IssueUpdater {
public static final String RESOLUTION = "resolution";
public static final String STATUS = "status";
public static final String AUTHOR = "author";
public static final String ACTION_PLAN = "actionPlan";
public static final String FILE = "file";

/**

+ 1
- 118
server/sonar-server/src/test/java/org/sonar/server/issue/InternalRubyIssueServiceTest.java View File

@@ -19,27 +19,15 @@
*/
package org.sonar.server.issue;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.user.User;
import org.sonar.api.web.UserRole;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.FieldDiffs;
import org.sonar.db.component.ResourceDao;
import org.sonar.db.component.ResourceDto;
import org.sonar.db.component.ResourceQuery;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.Message;
import org.sonar.server.issue.index.IssueIndex;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.user.ThreadLocalUserSession;

@@ -57,39 +45,23 @@ public class InternalRubyIssueServiceTest {
@Rule
public UserSessionRule userSessionRule = UserSessionRule.standalone();

IssueIndex issueIndex = mock(IssueIndex.class);

IssueService issueService;

IssueQueryService issueQueryService;

IssueCommentService commentService;

IssueChangelogService changelogService;

ResourceDao resourceDao;

IssueBulkChangeService issueBulkChangeService;

ActionService actionService;

InternalRubyIssueService service;

@Before
public void setUp() {
issueService = mock(IssueService.class);
issueQueryService = mock(IssueQueryService.class);
commentService = mock(IssueCommentService.class);
changelogService = mock(IssueChangelogService.class);
resourceDao = mock(ResourceDao.class);
issueBulkChangeService = mock(IssueBulkChangeService.class);
actionService = mock(ActionService.class);

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

service = new InternalRubyIssueService(issueIndex, issueService, issueQueryService, commentService, changelogService,
issueBulkChangeService, actionService, userSessionRule);
service = new InternalRubyIssueService(issueService, commentService, changelogService, issueBulkChangeService, userSessionRule);
}

@Test
@@ -98,36 +70,6 @@ public class InternalRubyIssueServiceTest {
verify(issueService).listTransitions(eq("ABCD"));
}

@Test
public void list_transitions_by_issue() {
Issue issue = new DefaultIssue().setKey("ABCD");
service.listTransitions(issue);
verify(issueService).listTransitions(eq(issue));
}

@Test
public void list_status() {
service.listStatus();
verify(issueService).listStatus();
}

@Test
public void list_resolutions() {
assertThat(service.listResolutions()).isEqualTo(Issue.RESOLUTIONS);
}

@Test
public void find_comments_by_issue_key() {
service.findComments("ABCD");
verify(commentService).findComments("ABCD");
}

@Test
public void find_comments_by_issue_keys() {
service.findCommentsByIssueKeys(newArrayList("ABCD"));
verify(commentService).findComments(newArrayList("ABCD"));
}

@Test
public void test_changelog_from_issue_key() throws Exception {
IssueChangelog changelog = new IssueChangelog(Collections.<FieldDiffs>emptyList(), Collections.<User>emptyList());
@@ -138,18 +80,6 @@ public class InternalRubyIssueServiceTest {
assertThat(result).isSameAs(changelog);
}

@Test
public void test_changelog_from_issue() throws Exception {
Issue issue = new DefaultIssue().setKey("ABCDE");

IssueChangelog changelog = new IssueChangelog(Collections.<FieldDiffs>emptyList(), Collections.<User>emptyList());
when(changelogService.changelog(eq(issue))).thenReturn(changelog);

IssueChangelog result = service.changelog(issue);

assertThat(result).isSameAs(changelog);
}

@Test
public void execute_bulk_change() {
Map<String, Object> params = newHashMap();
@@ -163,11 +93,6 @@ public class InternalRubyIssueServiceTest {
verify(issueBulkChangeService).execute(any(IssueBulkChangeQuery.class), any(ThreadLocalUserSession.class));
}

@Test
public void max_query_size() {
assertThat(service.maxPageSize()).isEqualTo(500);
}

@Test
public void create_context_from_parameters() {
Map<String, Object> map = newHashMap();
@@ -188,46 +113,4 @@ public class InternalRubyIssueServiceTest {
assertThat(searchOptions.getLimit()).isEqualTo(100);
assertThat(searchOptions.getPage()).isEqualTo(1);
}

@Test
public void list_tags() {
List<String> tags = Arrays.asList("tag1", "tag2", "tag3");
when(issueService.listTags(null, 0)).thenReturn(tags);
assertThat(service.listTags()).isEqualTo(tags);
}

@Test
public void list_tags_for_component() {
Map<String, Long> tags = ImmutableMap.of("tag1", 1L, "tag2", 2L, "tag3", 3L);
int pageSize = 42;
IssueQuery query = IssueQuery.builder(userSessionRule).build();
String componentUuid = "polop";
Map<String, Object> params = ImmutableMap.<String, Object>of("componentUuids", componentUuid, "resolved", false);
when(issueQueryService.createFromMap(params)).thenReturn(query);
when(issueService.listTagsForComponent(query, pageSize)).thenReturn(tags);
assertThat(service.listTagsForComponent(componentUuid, pageSize)).isEqualTo(tags);
}

@Test
public void is_user_issue_admin() {
userSessionRule.addProjectUuidPermissions(UserRole.ISSUE_ADMIN, "bcde");
assertThat(service.isUserIssueAdmin("abcd")).isFalse();
assertThat(service.isUserIssueAdmin("bcde")).isTrue();
}

private void checkBadRequestException(Exception e, String key, Object... params) {
BadRequestException exception = (BadRequestException) e;
Message msg = exception.errors().messages().get(0);
assertThat(msg.getKey()).isEqualTo(key);
assertThat(msg.getParams()).containsOnly(params);
}

private String createLongString(int size) {
String result = "";
for (int i = 0; i < size; i++) {
result += "c";
}
return result;
}

}

+ 0
- 5
server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java View File

@@ -105,11 +105,6 @@ public class IssueServiceMediumTest {
assertThat(service.getByKey(issue.getKey())).isNotNull();
}

@Test
public void list_status() {
assertThat(service.listStatus()).containsExactly("OPEN", "CONFIRMED", "REOPENED", "RESOLVED", "CLOSED");
}

@Test
public void list_transitions() {
RuleDto rule = newRule();

+ 0
- 16
server/sonar-web/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb View File

@@ -131,22 +131,6 @@ class Api::IssuesController < Api::ApiController
end
end

#
# GET /api/issues/actions?issue=<key>
#
# -- Example
# curl -v -u admin:admin 'http://localhost:9000/api/issues/actions?issue=9b6f89c0-3347-46f6-a6d1-dd6c761240e0'
#
def actions
require_parameters :issue
issue_key = params[:issue]
render :json => jsonp(
{
:actions => Internal.issues.listActions(issue_key)
}
)
end

#
# Execute a bulk change on a list of issues
#

+ 0
- 33
server/sonar-web/src/main/webapp/WEB-INF/app/models/issue.rb View File

@@ -20,39 +20,6 @@

class Issue

def self.to_hash(issue, extra_params={})
hash = {
:key => issue.key,
:component => issue.componentKey,
:componentUuid => issue.componentUuid,
:project => issue.projectKey,
:rule => issue.ruleKey.toString(),
:status => issue.status
}
hash[:resolution] = issue.resolution if issue.resolution
hash[:severity] = issue.severity if issue.severity
hash[:message] = issue.message if issue.message
hash[:line] = issue.line.to_i if issue.line
hash[:effortToFix] = issue.effortToFix.to_f if issue.effortToFix
hash[:debt] = Internal.durations.encode(issue.effort) if issue.effort
hash[:effort] = Internal.durations.encode(issue.effort) if issue.effort
hash[:assignee] = issue.assignee if issue.assignee
hash[:author] = issue.authorLogin if issue.authorLogin
hash[:creationDate] = Api::Utils.format_datetime(issue.creationDate) if issue.creationDate
hash[:updateDate] = Api::Utils.format_datetime(issue.updateDate) if issue.updateDate
hash[:fUpdateAge] = Api::Utils.age_from_now(issue.updateDate) if issue.updateDate
hash[:closeDate] = Api::Utils.format_datetime(issue.closeDate) if issue.closeDate
hash[:attr] = issue.attributes.to_hash unless issue.attributes.isEmpty()
if issue.comments.size>0
hash[:comments] = issue.comments.map { |c| comment_to_hash(c) }
end
unless extra_params.blank?
hash[:actions] = Internal.issues.listActions(issue).map { |t| t.key() } if extra_params.include? 'actions'
hash[:transitions] = Internal.issues.listTransitions(issue).map { |t| t.key() } if extra_params.include? 'transitions'
end
hash
end

def self.comment_to_hash(comment)
{
:key => comment.key(),

Loading…
Cancel
Save