use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.
the class CreateAction method doHandle.
private WebhookDto doHandle(DbSession dbSession, @Nullable ProjectDto project, String name, String url, @Nullable String secret) {
WebhookDto dto = new WebhookDto().setUuid(uuidFactory.create()).setName(name).setUrl(url).setSecret(secret);
if (project != null) {
checkNumberOfWebhook(numberOfWebhookOf(dbSession, project), project.getKey());
dto.setProjectUuid(project.getUuid());
} else {
checkNumberOfGlobalWebhooks(dbSession);
}
return dto;
}
use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.
the class CreateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
String name = request.mandatoryParam(NAME_PARAM);
String url = request.mandatoryParam(URL_PARAM);
String projectKey = request.param(PROJECT_KEY_PARAM);
String secret = request.param(SECRET_PARAM);
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto projectDto = null;
if (isNotBlank(projectKey)) {
projectDto = componentFinder.getProjectByKey(dbSession, projectKey);
webhookSupport.checkPermission(projectDto);
} else {
webhookSupport.checkPermission();
}
webhookSupport.checkUrlPattern(url, "Url parameter with value '%s' is not a valid url", url);
WebhookDto dto = doHandle(dbSession, projectDto, name, url, secret);
String projectName = projectDto == null ? null : projectDto.getName();
dbClient.webhookDao().insert(dbSession, dto, projectKey, projectName);
dbSession.commit();
writeResponse(request, response, dto);
}
}
use of org.sonar.db.webhook.WebhookDto 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);
}
}
use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.
the class UpdateAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
String webhookKey = request.param(KEY_PARAM);
String name = request.mandatoryParam(NAME_PARAM);
String url = request.mandatoryParam(URL_PARAM);
String secret = request.param(SECRET_PARAM);
webhookSupport.checkUrlPattern(url, "Url parameter with value '%s' is not a valid url", url);
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<WebhookDto> dtoOptional = dbClient.webhookDao().selectByUuid(dbSession, webhookKey);
WebhookDto webhookDto = checkFoundWithOptional(dtoOptional, "No webhook with key '%s'", webhookKey);
String projectUuid = webhookDto.getProjectUuid();
if (projectUuid != null) {
ProjectDto projectDto = componentFinder.getProjectByUuid(dbSession, projectUuid);
webhookSupport.checkPermission(projectDto);
updateWebhook(dbSession, webhookDto, name, url, secret, projectDto.getKey(), projectDto.getName());
} else {
webhookSupport.checkPermission();
updateWebhook(dbSession, webhookDto, name, url, secret, null, null);
}
dbSession.commit();
}
response.noContent();
}
use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.
the class DeleteAction method handle.
@Override
public void handle(Request request, Response response) throws Exception {
userSession.checkLoggedIn();
String webhookKey = request.param(KEY_PARAM);
try (DbSession dbSession = dbClient.openSession(false)) {
Optional<WebhookDto> dtoOptional = dbClient.webhookDao().selectByUuid(dbSession, webhookKey);
WebhookDto webhookDto = checkFoundWithOptional(dtoOptional, "No webhook with key '%s'", webhookKey);
String projectUuid = webhookDto.getProjectUuid();
if (projectUuid != null) {
Optional<ProjectDto> optionalDto = dbClient.projectDao().selectByUuid(dbSession, projectUuid);
ProjectDto projectDto = checkStateWithOptional(optionalDto, "the requested project '%s' was not found", projectUuid);
webhookSupport.checkPermission(projectDto);
deleteWebhook(dbSession, webhookDto);
} else {
webhookSupport.checkPermission();
deleteWebhook(dbSession, webhookDto);
}
dbSession.commit();
}
response.noContent();
}
Aggregations