Search in sources :

Example 11 with CeTaskMessageDto

use of org.sonar.db.ce.CeTaskMessageDto in project sonarqube by SonarSource.

the class DismissAnalysisWarningAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    userSession.checkLoggedIn();
    String userLogin = requireNonNull(userSession.getLogin());
    String projectKey = request.mandatoryParam(PARAM_COMPONENT_KEY);
    String messageKey = request.mandatoryParam(PARAM_MESSAGE_KEY);
    try (DbSession dbSession = dbClient.openSession(false)) {
        UserDto user = getUser(dbSession, userLogin);
        ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
        userSession.checkProjectPermission(UserRole.USER, project);
        CeTaskMessageDto messageDto = dbClient.ceTaskMessageDao().selectByUuid(dbSession, messageKey).orElseThrow(() -> new NotFoundException(format(MESSAGE_NOT_FOUND, messageKey)));
        if (!messageDto.getType().isDismissible()) {
            throw new IllegalArgumentException(format(MESSAGE_CANNOT_BE_DISMISSED, messageKey));
        }
        Optional<UserDismissedMessageDto> result = dbClient.userDismissedMessagesDao().selectByUserAndProjectAndMessageType(dbSession, user, project, messageDto.getType());
        if (!result.isPresent()) {
            dbClient.userDismissedMessagesDao().insert(dbSession, new UserDismissedMessageDto().setUuid(Uuids.create()).setUserUuid(user.getUuid()).setProjectUuid(project.getUuid()).setCeMessageType(messageDto.getType()));
            dbSession.commit();
        }
        response.noContent();
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) DbSession(org.sonar.db.DbSession) UserDto(org.sonar.db.user.UserDto) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) UserDismissedMessageDto(org.sonar.db.user.UserDismissedMessageDto)

Example 12 with CeTaskMessageDto

use of org.sonar.db.ce.CeTaskMessageDto in project sonarqube by SonarSource.

the class PurgeDaoTest method insertCeTaskMessages.

private void insertCeTaskMessages(String uuid, int count) {
    IntStream.range(0, count).mapToObj(i -> new CeTaskMessageDto().setUuid(UuidFactoryFast.getInstance().create()).setTaskUuid(uuid).setMessage("key_" + uuid.hashCode() + i).setType(CeTaskMessageType.GENERIC).setCreatedAt(2_333_444L + i)).forEach(dto -> dbClient.ceTaskMessageDao().insert(dbSession, dto));
    dbSession.commit();
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) CeTaskTypes(org.sonar.db.ce.CeTaskTypes) Arrays(java.util.Arrays) STATUS_PROCESSED(org.sonar.db.component.SnapshotDto.STATUS_PROCESSED) PortfolioProjectDto(org.sonar.db.portfolio.PortfolioProjectDto) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) DbSession(org.sonar.db.DbSession) MeasureDto(org.sonar.db.measure.MeasureDto) UserDismissedMessageDto(org.sonar.db.user.UserDismissedMessageDto) Collections.singletonList(java.util.Collections.singletonList) RandomUtils(org.apache.commons.lang.math.RandomUtils) ByteArrayInputStream(java.io.ByteArrayInputStream) Arrays.asList(java.util.Arrays.asList) ComponentTesting(org.sonar.db.component.ComponentTesting) UuidFactoryFast(org.sonar.core.util.UuidFactoryFast) ZoneOffset(java.time.ZoneOffset) NewCodePeriodType(org.sonar.db.newcodeperiod.NewCodePeriodType) DbTester(org.sonar.db.DbTester) IssueChangeDto(org.sonar.db.issue.IssueChangeDto) CeTaskMessageType(org.sonar.db.ce.CeTaskMessageType) ImmutableSet(com.google.common.collect.ImmutableSet) WebhookDto(org.sonar.db.webhook.WebhookDto) System2(org.sonar.api.utils.System2) CloseableIterator(org.sonar.core.util.CloseableIterator) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) ComponentDbTester(org.sonar.db.component.ComponentDbTester) DbClient(org.sonar.db.DbClient) NewCodePeriodDto(org.sonar.db.newcodeperiod.NewCodePeriodDto) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ComponentTesting.newSubPortfolio(org.sonar.db.component.ComponentTesting.newSubPortfolio) Stream(java.util.stream.Stream) ProjectDto(org.sonar.db.project.ProjectDto) UTC(java.time.ZoneOffset.UTC) CATEGORY_VERSION(org.sonar.db.event.EventDto.CATEGORY_VERSION) Optional(java.util.Optional) WebhookDeliveryLiteDto(org.sonar.db.webhook.WebhookDeliveryLiteDto) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) IssueTesting.newCodeReferenceIssue(org.sonar.db.issue.IssueTesting.newCodeReferenceIssue) PropertyDto(org.sonar.db.property.PropertyDto) EventDto(org.sonar.db.event.EventDto) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) BranchDto(org.sonar.db.component.BranchDto) ComponentTesting.newBranchDto(org.sonar.db.component.ComponentTesting.newBranchDto) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) REPORT(org.sonar.db.ce.CeTaskTypes.REPORT) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) LocalDateTime(java.time.LocalDateTime) EventComponentChangeDto(org.sonar.db.event.EventComponentChangeDto) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) CeTaskInputDao(org.sonar.db.ce.CeTaskInputDao) Uuids(org.sonar.core.util.Uuids) CeActivityDto(org.sonar.db.ce.CeActivityDto) SnapshotTesting.newSnapshot(org.sonar.db.component.SnapshotTesting.newSnapshot) DateUtils(org.apache.commons.lang.time.DateUtils) EventTesting(org.sonar.db.event.EventTesting) Status(org.sonar.db.ce.CeQueueDto.Status) ComponentTesting.newProjectCopy(org.sonar.db.component.ComponentTesting.newProjectCopy) CeTaskCharacteristicDto(org.sonar.db.ce.CeTaskCharacteristicDto) WebhookDeliveryTesting.newDto(org.sonar.db.webhook.WebhookDeliveryTesting.newDto) BranchType(org.sonar.db.component.BranchType) Collections.emptySet(java.util.Collections.emptySet) FileSourceDto(org.sonar.db.source.FileSourceDto) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) WebhookDeliveryTesting.selectAllDeliveryUuids(org.sonar.db.webhook.WebhookDeliveryTesting.selectAllDeliveryUuids) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) STATUS_UNPROCESSED(org.sonar.db.component.SnapshotDto.STATUS_UNPROCESSED) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) Issue(org.sonar.api.issue.Issue) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) CeQueueDto(org.sonar.db.ce.CeQueueDto) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) SnapshotDto(org.sonar.db.component.SnapshotDto) Collections(java.util.Collections) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto)

Example 13 with CeTaskMessageDto

use of org.sonar.db.ce.CeTaskMessageDto in project sonarqube by SonarSource.

the class AnalysisStatusActionTest method return_warnings_for_last_analysis_of_pull_request.

@Test
public void return_warnings_for_last_analysis_of_pull_request() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn().setSystemAdministrator().addProjectPermission(UserRole.USER, project);
    ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> {
        b.setBranchType(BranchType.PULL_REQUEST);
        b.setKey(PULL_REQUEST);
    });
    SnapshotDto analysis = db.components().insertSnapshot(pullRequest);
    CeActivityDto activity = insertActivity("task-uuid" + counter++, pullRequest, SUCCESS, analysis, REPORT);
    CeTaskMessageDto taskMessage = createTaskMessage(activity, WARNING_IN_PR);
    Ce.AnalysisStatusWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_PULL_REQUEST, PULL_REQUEST).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
    assertThat(response.getComponent().getWarningsList()).extracting(Warning::getKey, Warning::getMessage, Warning::getDismissable).containsExactly(tuple(taskMessage.getUuid(), WARNING_IN_PR, false));
    SnapshotDto analysis2 = db.components().insertSnapshot(pullRequest);
    insertActivity("task-uuid" + counter++, pullRequest, SUCCESS, analysis2, REPORT);
    insertActivity("task-uuid" + counter++, pullRequest, SUCCESS, null, "PROJECT_EXPORT");
    Ce.AnalysisStatusWsResponse response2 = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_PULL_REQUEST, PULL_REQUEST).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
    assertThat(response2.getComponent().getWarningsList()).isEmpty();
}
Also used : Ce(org.sonarqube.ws.Ce) CeActivityDto(org.sonar.db.ce.CeActivityDto) SnapshotDto(org.sonar.db.component.SnapshotDto) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 14 with CeTaskMessageDto

use of org.sonar.db.ce.CeTaskMessageDto in project sonarqube by SonarSource.

the class AnalysisStatusActionTest method json_example.

@Test
public void json_example() {
    ComponentDto project = db.components().insertPrivateProject(p -> p.setDbKey("com.github.kevinsawicki:http-request-parent").setName("HttpRequest"));
    SnapshotDto analysis = db.components().insertSnapshot(project);
    CeActivityDto activity = insertActivity("task-uuid" + counter++, project, SUCCESS, analysis, REPORT);
    CeTaskMessageDto ceTaskMessage = new CeTaskMessageDto().setUuid("AU-Tpxb--iU5OvuD2FLy").setTaskUuid(activity.getUuid()).setMessage("Property \"sonar.jacoco.reportPaths\" is no longer supported. Use JaCoCo xml report and sonar-jacoco plugin.").setType(CeTaskMessageType.GENERIC).setCreatedAt(counter);
    db.getDbClient().ceTaskMessageDao().insert(db.getSession(), ceTaskMessage);
    db.commit();
    userSession.logIn().setSystemAdministrator().addProjectPermission(UserRole.USER, project);
    String result = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).execute().getInput();
    assertJson(result).isSimilarTo(getClass().getResource("analysis_status-example.json"));
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) SnapshotDto(org.sonar.db.component.SnapshotDto) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 15 with CeTaskMessageDto

use of org.sonar.db.ce.CeTaskMessageDto in project sonarqube by SonarSource.

the class AnalysisStatusActionTest method return_warnings_for_last_analysis_of_main.

@Test
public void return_warnings_for_last_analysis_of_main() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn().setSystemAdministrator().addProjectPermission(UserRole.USER, project);
    SnapshotDto analysis = db.components().insertSnapshot(project);
    CeActivityDto activity = insertActivity("task-uuid" + counter++, project, SUCCESS, analysis, REPORT);
    CeTaskMessageDto taskMessage = createTaskMessage(activity, WARNING_IN_MAIN);
    CeTaskMessageDto taskMessageDismissible = createTaskMessage(activity, "Dismissible warning", CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
    Ce.AnalysisStatusWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
    assertThat(response.getComponent().getWarningsList()).extracting(Warning::getKey, Warning::getMessage, Warning::getDismissable).containsExactly(tuple(taskMessage.getUuid(), WARNING_IN_MAIN, false), tuple(taskMessageDismissible.getUuid(), taskMessageDismissible.getMessage(), true));
    SnapshotDto analysis2 = db.components().insertSnapshot(project);
    insertActivity("task-uuid" + counter++, project, SUCCESS, analysis2, REPORT);
    insertActivity("task-uuid" + counter++, project, SUCCESS, null, "PROJECT_EXPORT");
    Ce.AnalysisStatusWsResponse response2 = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
    assertThat(response2.getComponent().getWarningsList()).isEmpty();
}
Also used : Ce(org.sonarqube.ws.Ce) CeActivityDto(org.sonar.db.ce.CeActivityDto) SnapshotDto(org.sonar.db.component.SnapshotDto) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

CeTaskMessageDto (org.sonar.db.ce.CeTaskMessageDto)17 Test (org.junit.Test)11 CeActivityDto (org.sonar.db.ce.CeActivityDto)10 ComponentDto (org.sonar.db.component.ComponentDto)10 SnapshotDto (org.sonar.db.component.SnapshotDto)10 UserDto (org.sonar.db.user.UserDto)6 Ce (org.sonarqube.ws.Ce)6 Random (java.util.Random)3 DbSession (org.sonar.db.DbSession)2 ProjectDto (org.sonar.db.project.ProjectDto)2 UserDismissedMessageDto (org.sonar.db.user.UserDismissedMessageDto)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 LocalDateTime (java.time.LocalDateTime)1 ZoneOffset (java.time.ZoneOffset)1 UTC (java.time.ZoneOffset.UTC)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1