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);
}
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();
}
}
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);
}
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());
}
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);
}
}
Aggregations