Search in sources :

Example 1 with WebhookDeliveryLiteDto

use of org.sonar.db.webhook.WebhookDeliveryLiteDto in project sonarqube by SonarSource.

the class WebhookDeliveriesAction method loadFromDatabase.

private Data loadFromDatabase(@Nullable String webhookUuid, @Nullable String ceTaskId, @Nullable String projectKey, int page, int pageSize) {
    Map<String, ProjectDto> projectUuidMap;
    List<WebhookDeliveryLiteDto> deliveries;
    int totalElements;
    try (DbSession dbSession = dbClient.openSession(false)) {
        if (isNotBlank(webhookUuid)) {
            totalElements = dbClient.webhookDeliveryDao().countDeliveriesByWebhookUuid(dbSession, webhookUuid);
            deliveries = dbClient.webhookDeliveryDao().selectByWebhookUuid(dbSession, webhookUuid, offset(page, pageSize), pageSize);
            projectUuidMap = getProjectsDto(dbSession, deliveries);
        } else if (projectKey != null) {
            ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey);
            projectUuidMap = new HashMap<>();
            projectUuidMap.put(project.getUuid(), project);
            totalElements = dbClient.webhookDeliveryDao().countDeliveriesByComponentUuid(dbSession, project.getUuid());
            deliveries = dbClient.webhookDeliveryDao().selectOrderedByComponentUuid(dbSession, project.getUuid(), offset(page, pageSize), pageSize);
        } else {
            totalElements = dbClient.webhookDeliveryDao().countDeliveriesByCeTaskUuid(dbSession, ceTaskId);
            deliveries = dbClient.webhookDeliveryDao().selectOrderedByCeTaskUuid(dbSession, ceTaskId, offset(page, pageSize), pageSize);
            projectUuidMap = getProjectsDto(dbSession, deliveries);
        }
    }
    return new Data(projectUuidMap, deliveries).withPagingInfo(page, pageSize, totalElements);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) WebhookDeliveryLiteDto(org.sonar.db.webhook.WebhookDeliveryLiteDto) DbSession(org.sonar.db.DbSession) HashMap(java.util.HashMap)

Example 2 with WebhookDeliveryLiteDto

use of org.sonar.db.webhook.WebhookDeliveryLiteDto in project sonarqube by SonarSource.

the class ListAction method addLastDelivery.

private static void addLastDelivery(ListResponseElement.Builder responseElementBuilder, WebhookDto webhook, Map<String, WebhookDeliveryLiteDto> lastDeliveries) {
    if (lastDeliveries.containsKey(webhook.getUuid())) {
        WebhookDeliveryLiteDto delivery = lastDeliveries.get(webhook.getUuid());
        Webhooks.LatestDelivery.Builder builder = responseElementBuilder.getLatestDeliveryBuilder().setId(delivery.getUuid()).setAt(formatDateTime(delivery.getCreatedAt())).setSuccess(delivery.isSuccess());
        if (delivery.getHttpStatus() != null) {
            builder.setHttpStatus(delivery.getHttpStatus());
        }
        if (delivery.getDurationMs() != null) {
            builder.setDurationMs(delivery.getDurationMs());
        }
        builder.build();
    }
}
Also used : WebhookDeliveryLiteDto(org.sonar.db.webhook.WebhookDeliveryLiteDto)

Example 3 with WebhookDeliveryLiteDto

use of org.sonar.db.webhook.WebhookDeliveryLiteDto in project sonarqube by SonarSource.

the class WebhookDeliveriesAction method loadFromDatabase.

private Data loadFromDatabase(@Nullable String ceTaskId, @Nullable String componentKey) {
    ComponentDto component = null;
    List<WebhookDeliveryLiteDto> deliveries;
    try (DbSession dbSession = dbClient.openSession(false)) {
        if (componentKey != null) {
            component = componentFinder.getByKey(dbSession, componentKey);
            deliveries = dbClient.webhookDeliveryDao().selectOrderedByComponentUuid(dbSession, component.uuid());
        } else {
            deliveries = dbClient.webhookDeliveryDao().selectOrderedByCeTaskUuid(dbSession, ceTaskId);
            Optional<String> deliveredComponentUuid = deliveries.stream().map(WebhookDeliveryLiteDto::getComponentUuid).findFirst();
            if (deliveredComponentUuid.isPresent()) {
                component = componentFinder.getByUuid(dbSession, deliveredComponentUuid.get());
            }
        }
    }
    return new Data(component, deliveries);
}
Also used : WebhookDeliveryLiteDto(org.sonar.db.webhook.WebhookDeliveryLiteDto) DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto)

Example 4 with WebhookDeliveryLiteDto

use of org.sonar.db.webhook.WebhookDeliveryLiteDto in project sonarqube by SonarSource.

the class PurgeDaoTest method delete_webhooks_from_project.

@Test
public void delete_webhooks_from_project() {
    ProjectDto project1 = db.components().insertPrivateProjectDto();
    WebhookDto webhook = db.webhooks().insertWebhook(project1);
    db.webhookDelivery().insert(webhook);
    ProjectDto projectNotToBeDeleted = db.components().insertPrivateProjectDto();
    WebhookDto webhookNotDeleted = db.webhooks().insertWebhook(projectNotToBeDeleted);
    WebhookDeliveryLiteDto webhookDeliveryNotDeleted = db.webhookDelivery().insert(webhookNotDeleted);
    underTest.deleteProject(dbSession, project1.getUuid(), project1.getQualifier(), project1.getName(), project1.getKey());
    assertThat(uuidsIn("webhooks")).containsOnly(webhookNotDeleted.getUuid());
    assertThat(uuidsIn("webhook_deliveries")).containsOnly(webhookDeliveryNotDeleted.getUuid());
}
Also used : PortfolioProjectDto(org.sonar.db.portfolio.PortfolioProjectDto) ProjectDto(org.sonar.db.project.ProjectDto) WebhookDto(org.sonar.db.webhook.WebhookDto) WebhookDeliveryLiteDto(org.sonar.db.webhook.WebhookDeliveryLiteDto) Test(org.junit.Test)

Example 5 with WebhookDeliveryLiteDto

use of org.sonar.db.webhook.WebhookDeliveryLiteDto in project sonarqube by SonarSource.

the class ListAction method handle.

@Override
public void handle(Request request, Response response) throws Exception {
    String projectKey = request.param(PROJECT_KEY_PARAM);
    userSession.checkLoggedIn();
    try (DbSession dbSession = dbClient.openSession(true)) {
        List<WebhookDto> webhookDtos = doHandle(dbSession, projectKey);
        Map<String, WebhookDeliveryLiteDto> lastDeliveries = loadLastDeliveriesOf(dbSession, webhookDtos);
        writeResponse(request, response, webhookDtos, lastDeliveries);
    }
}
Also used : WebhookDto(org.sonar.db.webhook.WebhookDto) DbSession(org.sonar.db.DbSession) WebhookDeliveryLiteDto(org.sonar.db.webhook.WebhookDeliveryLiteDto)

Aggregations

WebhookDeliveryLiteDto (org.sonar.db.webhook.WebhookDeliveryLiteDto)5 DbSession (org.sonar.db.DbSession)3 ProjectDto (org.sonar.db.project.ProjectDto)2 WebhookDto (org.sonar.db.webhook.WebhookDto)2 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 ComponentDto (org.sonar.db.component.ComponentDto)1 PortfolioProjectDto (org.sonar.db.portfolio.PortfolioProjectDto)1