Search in sources :

Example 81 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class IssueUpdater method saveIssueAndPreloadSearchResponseData.

public SearchResponseData saveIssueAndPreloadSearchResponseData(DbSession dbSession, DefaultIssue issue, IssueChangeContext context, boolean refreshMeasures) {
    Optional<RuleDefinitionDto> rule = getRuleByKey(dbSession, issue.getRuleKey());
    ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, issue.projectUuid());
    BranchDto branch = getBranch(dbSession, issue, issue.projectUuid());
    ComponentDto component = getComponent(dbSession, issue, issue.componentUuid());
    IssueDto issueDto = doSaveIssue(dbSession, issue, context, rule, project, branch);
    SearchResponseData result = new SearchResponseData(issueDto);
    rule.ifPresent(r -> result.addRules(singletonList(r)));
    result.addComponents(singleton(project));
    result.addComponents(singleton(component));
    if (refreshMeasures) {
        List<DefaultIssue> changedIssues = result.getIssues().stream().map(IssueDto::toDefaultIssue).collect(MoreCollectors.toList(result.getIssues().size()));
        issueChangePostProcessor.process(dbSession, changedIssues, singleton(component));
    }
    return result;
}
Also used : BranchDto(org.sonar.db.component.BranchDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue)

Example 82 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class SearchResponseFormat method formatOperation.

Operation formatOperation(SearchResponseData data) {
    Operation.Builder response = Operation.newBuilder();
    if (data.getIssues().size() == 1) {
        Issue.Builder issueBuilder = Issue.newBuilder();
        IssueDto dto = data.getIssues().get(0);
        formatIssue(issueBuilder, dto, data);
        formatIssueActions(data, issueBuilder, dto);
        formatIssueTransitions(data, issueBuilder, dto);
        formatIssueComments(data, issueBuilder, dto);
        response.setIssue(issueBuilder.build());
    }
    response.addAllComponents(formatComponents(data));
    response.addAllRules(formatRules(data).getRulesList());
    response.addAllUsers(formatUsers(data).getUsersList());
    return response.build();
}
Also used : Issue(org.sonarqube.ws.Issues.Issue) IssueDto(org.sonar.db.issue.IssueDto) Operation(org.sonarqube.ws.Issues.Operation)

Example 83 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class ChangelogAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    try (DbSession dbSession = dbClient.openSession(false)) {
        IssueDto issue = issueFinder.getByKey(dbSession, request.mandatoryParam(PARAM_ISSUE));
        ChangelogWsResponse build = handle(dbSession, issue);
        writeProtobuf(build, request, response);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ChangelogWsResponse(org.sonarqube.ws.Issues.ChangelogWsResponse) IssueDto(org.sonar.db.issue.IssueDto)

Example 84 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class SearchResponseLoader method loadActionsAndTransitions.

private void loadActionsAndTransitions(SearchResponseData result, Set<SearchAdditionalField> fields) {
    if (fields.contains(ACTIONS) || fields.contains(TRANSITIONS)) {
        Map<String, ComponentDto> componentsByProjectUuid = result.getComponents().stream().filter(ComponentDto::isRootProject).collect(MoreCollectors.uniqueIndex(ComponentDto::projectUuid));
        for (IssueDto issueDto : result.getIssues()) {
            // so that IssueDto can be used.
            if (fields.contains(ACTIONS)) {
                ComponentDto project = componentsByProjectUuid.get(issueDto.getProjectUuid());
                result.addActions(issueDto.getKey(), listAvailableActions(issueDto, project));
            }
            if (fields.contains(TRANSITIONS) && !issueDto.isExternal()) {
                // TODO workflow and action engines must not depend on org.sonar.api.issue.Issue but on a generic interface
                DefaultIssue issue = issueDto.toDefaultIssue();
                result.addTransitions(issue.key(), transitionService.listTransitions(issue));
            }
        }
    }
}
Also used : ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue)

Example 85 with IssueDto

use of org.sonar.db.issue.IssueDto in project sonarqube by SonarSource.

the class SetTagsAction method setTags.

private SearchResponseData setTags(String issueKey, List<String> tags) {
    userSession.checkLoggedIn();
    try (DbSession session = dbClient.openSession(false)) {
        IssueDto issueDto = issueFinder.getByKey(session, issueKey);
        DefaultIssue issue = issueDto.toDefaultIssue();
        IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getUuid());
        if (issueFieldsSetter.setTags(issue, tags, context)) {
            return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, false);
        }
        return new SearchResponseData(issueDto);
    }
}
Also used : DbSession(org.sonar.db.DbSession) IssueChangeContext(org.sonar.core.issue.IssueChangeContext) IssueDto(org.sonar.db.issue.IssueDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date)

Aggregations

IssueDto (org.sonar.db.issue.IssueDto)478 Test (org.junit.Test)425 ComponentDto (org.sonar.db.component.ComponentDto)324 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)213 UserDto (org.sonar.db.user.UserDto)136 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)77 TestRequest (org.sonar.server.ws.TestRequest)66 Date (java.util.Date)60 Hotspots (org.sonarqube.ws.Hotspots)57 DefaultIssue (org.sonar.core.issue.DefaultIssue)55 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)53 NotFoundException (org.sonar.server.exceptions.NotFoundException)51 DbClient (org.sonar.db.DbClient)50 List (java.util.List)49 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)49 Rule (org.junit.Rule)49 System2 (org.sonar.api.utils.System2)49 DbTester (org.sonar.db.DbTester)49 RuleDto (org.sonar.db.rule.RuleDto)49 IntStream (java.util.stream.IntStream)48