@Test
public void deleteProject_deletes_webhook_deliveries() {
ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- dbClient.webhookDeliveryDao().insert(dbSession, newDto().setComponentUuid(project.uuid()).setUuid("D1").setDurationMs(1000).setWebhookUuid("webhook-uuid"));
- dbClient.webhookDeliveryDao().insert(dbSession, newDto().setComponentUuid("P2").setUuid("D2").setDurationMs(1000).setWebhookUuid("webhook-uuid"));
+ dbClient.webhookDeliveryDao().insert(dbSession, newDto().setProjectUuid(project.uuid()).setUuid("D1").setDurationMs(1000).setWebhookUuid("webhook-uuid"));
+ dbClient.webhookDeliveryDao().insert(dbSession, newDto().setProjectUuid("P2").setUuid("D2").setDurationMs(1000).setWebhookUuid("webhook-uuid"));
underTest.deleteProject(dbSession, project.uuid(), project.qualifier(), project.name(), project.getKey());
public class WebhookDaoIT {
@Rule
- public final DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public final DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private final System2 system2 = System2.INSTANCE;
private final DbClient dbClient = dbTester.getDbClient();
private static final long BEFORE = NOW - 1_000L;
@Rule
- public final DbTester dbTester = DbTester.create(System2.INSTANCE);
-
+ public final DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private final DbClient dbClient = dbTester.getDbClient();
private final DbSession dbSession = dbTester.getSession();
@Test
public void selectOrderedByComponentUuid_returns_empty_if_no_records() {
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1"));
- List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByComponentUuid(dbSession, "ANOTHER_COMPONENT", 0, 10);
+ List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByProjectUuid(dbSession, "ANOTHER_PROJECT", 0, 10);
assertThat(deliveries).isEmpty();
}
@Test
public void selectOrderedByComponentUuid_returns_records_ordered_by_date() {
- WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
- WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(NOW);
- WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_1").setCreatedAt(NOW);
+ WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1").setCreatedAt(BEFORE);
+ WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1").setCreatedAt(NOW);
+ WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "WEBHOOK_UUID_1", "PROJECT_2", "TASK_1").setCreatedAt(NOW);
underTest.insert(dbSession, dto3);
underTest.insert(dbSession, dto2);
underTest.insert(dbSession, dto1);
- List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByComponentUuid(dbSession, "COMPONENT_1", 0, 10);
+ List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByProjectUuid(dbSession, "PROJECT_1", 0, 10);
assertThat(deliveries).extracting(WebhookDeliveryLiteDto::getUuid).containsExactly("D2", "D1");
}
@Test
public void selectOrderedByCeTaskUuid_returns_empty_if_no_records() {
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1"));
List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByCeTaskUuid(dbSession, "ANOTHER_TASK", 0, 10);
@Test
public void selectOrderedByCeTaskUuid_returns_records_ordered_by_date() {
- WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
- WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(NOW);
- WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_2").setCreatedAt(NOW);
+ WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1").setCreatedAt(BEFORE);
+ WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1").setCreatedAt(NOW);
+ WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "WEBHOOK_UUID_1", "PROJECT_2", "TASK_2").setCreatedAt(NOW);
underTest.insert(dbSession, dto3);
underTest.insert(dbSession, dto2);
underTest.insert(dbSession, dto1);
@Test
public void selectByWebhookUuid_returns_empty_if_no_records() {
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1"));
List<WebhookDeliveryLiteDto> deliveries = underTest.selectByWebhookUuid(dbSession, "a-webhook-uuid", 0, 10);
@Test
public void selectByWebhookUuid_returns_records_ordered_by_date() {
- WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME");
- WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
- WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW);
- WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "fake-webhook-uuid", "COMPONENT_2", "TASK_1").setCreatedAt(NOW);
+ WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("PROJECT_1"), "PROJECT_KEY", "PROJECT_NAME");
+ WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "PROJECT_1", "TASK_1").setCreatedAt(BEFORE);
+ WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW);
+ WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "fake-webhook-uuid", "PROJECT_2", "TASK_1").setCreatedAt(NOW);
underTest.insert(dbSession, dto3);
underTest.insert(dbSession, dto2);
underTest.insert(dbSession, dto1);
@Test
public void selectByWebhookUuid_returns_records_according_to_pagination() {
- WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME");
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 5_000L));
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 4_000L));
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D3", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 3_000L));
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D4", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 2_000L));
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D5", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 1_000L));
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D6", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
+ WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("PROJECT_1"), "PROJECT_KEY", "PROJECT_NAME");
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW - 5_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW - 4_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D3", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW - 3_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D4", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW - 2_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D5", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW - 1_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D6", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW));
List<WebhookDeliveryLiteDto> deliveries = underTest.selectByWebhookUuid(dbSession, webhookDto.getUuid(), 2, 2);
@Test
public void selectLatestDelivery_of_a_webhook() {
- WebhookDto webhook1 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME");
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
+ WebhookDto webhook1 = dbWebhooks.insert(newProjectWebhook("PROJECT_1"), "PROJECT_KEY", "PROJECT_NAME");
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "PROJECT_1", "TASK_1").setCreatedAt(BEFORE));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW));
- WebhookDto webhook2 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME");
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
+ WebhookDto webhook2 = dbWebhooks.insert(newProjectWebhook("PROJECT_1"), "PROJECT_KEY", "PROJECT_NAME");
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "PROJECT_1", "TASK_1").setCreatedAt(BEFORE));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(NOW));
Map<String, WebhookDeliveryLiteDto> map = underTest.selectLatestDeliveries(dbSession, of(webhook1, webhook2));
@Test
public void insert_row_with_only_mandatory_columns() {
- WebhookDeliveryDto dto = WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1")
+ WebhookDeliveryDto dto = WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1")
.setDurationMs(1000)
.setHttpStatus(null)
.setErrorStacktrace(null);
@Test
public void insert_row_with_all_columns() {
- WebhookDeliveryDto dto = WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1");
+ WebhookDeliveryDto dto = WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1");
underTest.insert(dbSession, dto);
@Test
public void deleteByWebhook() {
- WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"), "COMPONENT_KEY", "COMPONENT_NAME");
+ WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("PROJECT_1"), "PROJECT_KEY", "PROJECT_NAME");
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(2_000_000L));
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_3", "WONT BE DELETED WEBHOOK_UUID_2", "COMPONENT_2", "TASK_3").setCreatedAt(1_000_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", webhookDto.getUuid(), "PROJECT_1", "TASK_1").setCreatedAt(1_000_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_2", webhookDto.getUuid(), "PROJECT_1", "TASK_2").setCreatedAt(2_000_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_3", "WONT BE DELETED WEBHOOK_UUID_2", "PROJECT_2", "TASK_3").setCreatedAt(1_000_000L));
underTest.deleteByWebhook(dbSession, webhookDto);
@Test
public void deleteComponentBeforeDate_deletes_rows_before_date() {
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_2").setCreatedAt(2_000_000L));
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_3").setCreatedAt(1_000_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1").setCreatedAt(1_000_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_2", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_2").setCreatedAt(2_000_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_3", "WEBHOOK_UUID_1", "PROJECT_2", "TASK_3").setCreatedAt(1_000_000L));
- // should delete the old delivery on COMPONENT_1 and keep the one of COMPONENT_2
- underTest.deleteComponentBeforeDate(dbSession, "COMPONENT_1", 1_500_000L);
+ // should delete the old delivery on PROJECT_1 and keep the one of PROJECT_2
+ underTest.deleteProjectBeforeDate(dbSession, "PROJECT_1", 1_500_000L);
List<Map<String, Object>> uuids = dbTester.select(dbSession, "select uuid as \"uuid\" from webhook_deliveries");
assertThat(uuids).extracting(column -> column.get("uuid")).containsOnly("DELIVERY_2", "DELIVERY_3");
@Test
public void deleteComponentBeforeDate_does_nothing_on_empty_table() {
- underTest.deleteComponentBeforeDate(dbSession, "COMPONENT_1", 1_500_000L);
+ underTest.deleteProjectBeforeDate(dbSession, "PROJECT_1", 1_500_000L);
assertThat(dbTester.countRowsOfTable(dbSession, "webhook_deliveries")).isZero();
}
@Test
public void deleteComponentBeforeDate_does_nothing_on_invalid_uuid() {
- underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "PROJECT_1", "TASK_1").setCreatedAt(1_000_000L));
- underTest.deleteComponentBeforeDate(dbSession, "COMPONENT_2", 1_500_000L);
+ underTest.deleteProjectBeforeDate(dbSession, "PROJECT_2", 1_500_000L);
assertThat(dbTester.countRowsOfTable(dbSession, "webhook_deliveries")).isOne();
}
private void verifyMandatoryFields(WebhookDeliveryDto expected, WebhookDeliveryDto actual) {
assertThat(actual.getUuid()).isEqualTo(expected.getUuid());
- assertThat(actual.getComponentUuid()).isEqualTo(expected.getComponentUuid());
+ assertThat(actual.getProjectUuid()).isEqualTo(expected.getProjectUuid());
assertThat(actual.getCeTaskUuid()).isEqualTo(expected.getCeTaskUuid());
assertThat(actual.getName()).isEqualTo(expected.getName());
assertThat(actual.getUrl()).isEqualTo(expected.getUrl());
return mapper(dbSession).selectByWebhookUuid(webhookUuid, new RowBounds(offset, limit));
}
- public int countDeliveriesByComponentUuid(DbSession dbSession, String componentUuid) {
- return mapper(dbSession).countByComponentUuid(componentUuid);
+ public int countDeliveriesByProjectUuid(DbSession dbSession, String projectUuid) {
+ return mapper(dbSession).countByProjectUuid(projectUuid);
}
/**
- * All the deliveries for the specified component. Results are ordered by descending date.
+ * All the deliveries for the specified project. Results are ordered by descending date.
*/
- public List<WebhookDeliveryLiteDto> selectOrderedByComponentUuid(DbSession dbSession, String componentUuid, int offset, int limit) {
- return mapper(dbSession).selectOrderedByComponentUuid(componentUuid, new RowBounds(offset, limit));
+ public List<WebhookDeliveryLiteDto> selectOrderedByProjectUuid(DbSession dbSession, String projectUuid, int offset, int limit) {
+ return mapper(dbSession).selectOrderedByProjectUuid(projectUuid, new RowBounds(offset, limit));
}
public int countDeliveriesByCeTaskUuid(DbSession dbSession, String ceTaskId) {
mapper(dbSession).insert(dto);
}
- public void deleteComponentBeforeDate(DbSession dbSession, String componentUuid, long beforeDate) {
- mapper(dbSession).deleteComponentBeforeDate(componentUuid, beforeDate);
+ public void deleteProjectBeforeDate(DbSession dbSession, String projectUuid, long beforeDate) {
+ mapper(dbSession).deleteProjectBeforeDate(projectUuid, beforeDate);
}
public Map<String, WebhookDeliveryLiteDto> selectLatestDeliveries(DbSession dbSession, List<WebhookDto> webhooks) {
public String toString() {
return new ToStringBuilder(this)
.append("uuid", uuid)
- .append("componentUuid", componentUuid)
+ .append("projectUuid", projectUuid)
.append("name", name)
.append("success", success)
.append("httpStatus", httpStatus)
protected String uuid;
/** Technical unique identifier, can be null for migration */
protected String webhookUuid;
- /** Component UUID, can't be null */
- protected String componentUuid;
+ /** Project UUID, can't be null */
+ protected String projectUuid;
/** Compute Engine task UUID, can be null */
protected String ceTaskUuid;
/** analysis UUID, can be null */
return (T) this;
}
- public String getComponentUuid() {
- return componentUuid;
+ public String getProjectUuid() {
+ return projectUuid;
}
- public T setComponentUuid(String s) {
- this.componentUuid = s;
+ public T setProjectUuid(String s) {
+ this.projectUuid = s;
return (T) this;
}
public String toString() {
return new ToStringBuilder(this)
.append("uuid", uuid)
- .append("componentUuid", componentUuid)
+ .append("componentUuid", projectUuid)
.append("ceTaskUuid", ceTaskUuid)
.append("name", name)
.append("success", success)
List<WebhookDeliveryLiteDto> selectByWebhookUuid(@Param("webhookUuid") String webhookUuid, RowBounds rowBounds);
- int countByComponentUuid(@Param("componentUuid") String componentUuid);
+ int countByProjectUuid(@Param("projectUuid") String projectUuid);
- List<WebhookDeliveryLiteDto> selectOrderedByComponentUuid(@Param("componentUuid") String componentUuid, RowBounds rowBounds);
+ List<WebhookDeliveryLiteDto> selectOrderedByProjectUuid(@Param("projectUuid") String projectUuid, RowBounds rowBounds);
int countByCeTaskUuid(@Param("ceTaskUuid") String ceTaskId);
void insert(WebhookDeliveryDto dto);
- void deleteComponentBeforeDate(@Param("componentUuid") String componentUuid, @Param("beforeDate") long beforeDate);
+ void deleteProjectBeforeDate(@Param("projectUuid") String projectUuid, @Param("beforeDate") long beforeDate);
void deleteByWebhookUuid(@Param("webhookUuid") String webhookUuid);
}
</delete>
<delete id="deleteWebhookDeliveriesByProjectUuid">
- delete from webhook_deliveries where component_uuid=#{projectUuid,jdbcType=VARCHAR}
+ delete from webhook_deliveries where project_uuid=#{projectUuid,jdbcType=VARCHAR}
</delete>
<delete id="deleteProjectAlmSettingsByProjectUuid">
<sql id="sqlLiteColumns">
uuid,
- component_uuid as componentUuid,
+ project_uuid as projectUuid,
webhook_uuid as webhookUuid,
ce_task_uuid as ceTaskUuid,
name,
order by created_at desc
</select>
- <select id="countByComponentUuid" parameterType="String" resultType="int">
+ <select id="countByProjectUuid" parameterType="String" resultType="int">
select
count(1)
from webhook_deliveries
- where component_uuid = #{componentUuid,jdbcType=VARCHAR}
+ where project_uuid = #{projectUuid,jdbcType=VARCHAR}
</select>
- <select id="selectOrderedByComponentUuid" parameterType="String" resultType="org.sonar.db.webhook.WebhookDeliveryLiteDto">
+ <select id="selectOrderedByProjectUuid" parameterType="String" resultType="org.sonar.db.webhook.WebhookDeliveryLiteDto">
select <include refid="sqlLiteColumns" />
from webhook_deliveries
- where component_uuid = #{componentUuid,jdbcType=VARCHAR}
+ where project_uuid = #{projectUuid,jdbcType=VARCHAR}
order by created_at desc
</select>
insert into webhook_deliveries (
uuid,
webhook_uuid,
- component_uuid,
+ project_uuid,
ce_task_uuid,
analysis_uuid,
name,
) values (
#{uuid,jdbcType=VARCHAR},
#{webhookUuid,jdbcType=VARCHAR},
- #{componentUuid,jdbcType=VARCHAR},
+ #{projectUuid,jdbcType=VARCHAR},
#{ceTaskUuid,jdbcType=VARCHAR},
#{analysisUuid,jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR},
where webhook_uuid = #{webhookUuid,jdbcType=VARCHAR}
</select>
- <delete id="deleteComponentBeforeDate" parameterType="map">
+ <delete id="deleteProjectBeforeDate" parameterType="map">
delete from webhook_deliveries
where
- component_uuid = #{componentUuid,jdbcType=VARCHAR} and
+ project_uuid = #{projectUuid,jdbcType=VARCHAR} and
created_at < #{beforeDate,jdbcType=BIGINT}
</delete>
</mapper>
CREATE TABLE "WEBHOOK_DELIVERIES"(
"UUID" CHARACTER VARYING(40) NOT NULL,
"WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL,
- "COMPONENT_UUID" CHARACTER VARYING(40) NOT NULL,
+ "PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
"CE_TASK_UUID" CHARACTER VARYING(40),
"ANALYSIS_UUID" CHARACTER VARYING(40),
"NAME" CHARACTER VARYING(100) NOT NULL,
"CREATED_AT" BIGINT NOT NULL
);
ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
-CREATE INDEX "COMPONENT_UUID" ON "WEBHOOK_DELIVERIES"("COMPONENT_UUID" NULLS FIRST);
CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST);
CREATE INDEX "IDX_WBHK_DLVRS_WBHK_UUID" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID" NULLS FIRST);
+CREATE INDEX "WD_PROJECT_UUID" ON "WEBHOOK_DELIVERIES"("PROJECT_UUID" NULLS FIRST);
CREATE TABLE "WEBHOOKS"(
"UUID" CHARACTER VARYING(40) NOT NULL,
WebhookDeliveryDto dto = newDto();
stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(dto));
String projectUuid = webhook.getProjectUuid();
- dto.setComponentUuid(Objects.requireNonNull(projectUuid, "Project uuid of webhook cannot be null"));
+ dto.setProjectUuid(Objects.requireNonNull(projectUuid, "Project uuid of webhook cannot be null"));
dto.setWebhookUuid(webhook.getUuid());
dbTester.getDbClient().webhookDeliveryDao().insert(dbTester.getSession(), dto);
dbTester.getSession().commit();
* Build a {@link WebhookDeliveryDto} with all mandatory fields.
* Optional fields are kept null.
*/
- public static WebhookDeliveryDto newDto(String uuid, String webhookUuid, String componentUuid, String ceTaskUuid) {
+ public static WebhookDeliveryDto newDto(String uuid, String webhookUuid, String projectUuid, String ceTaskUuid) {
return newDto()
.setUuid(uuid)
.setWebhookUuid(webhookUuid)
- .setComponentUuid(componentUuid)
+ .setProjectUuid(projectUuid)
.setCeTaskUuid(ceTaskUuid);
}
return new WebhookDeliveryDto()
.setUuid(Uuids.createFast())
.setWebhookUuid(randomAlphanumeric(40))
- .setComponentUuid(randomAlphanumeric(40))
+ .setProjectUuid(randomAlphanumeric(40))
.setCeTaskUuid(randomAlphanumeric(40))
.setAnalysisUuid(randomAlphanumeric(40))
.setName(randomAlphanumeric(10))
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.CreateIndexOnColumn;
+
+public class CreateIndexProjectUuidInWebhookDeliveries extends CreateIndexOnColumn {
+
+ private static final String TABLE_NAME = "webhook_deliveries";
+ private static final String COLUMN_NAME = "project_uuid";
+
+ public CreateIndexProjectUuidInWebhookDeliveries(Database db) {
+ super(db, TABLE_NAME, COLUMN_NAME, false);
+ }
+
+ /**
+ * There is a limit of 30 characters for index name, that's why this one has a different name
+ */
+ @Override
+ public String newIndexName() {
+ return "wd_" + COLUMN_NAME;
+ }
+}
.add(10_2_013, "Drop index on 'components.main_branch_project_uuid", DropIndexOnMainBranchProjectUuid.class)
.add(10_2_014, "Drop column 'main_branch_project_uuid' in the components table", DropMainBranchProjectUuidInComponents.class)
+
+ .add(10_2_015, "Drop index 'component_uuid' in 'webhook_deliveries' table", DropIndexComponentUuidInWebhookDeliveries.class)
+ .add(10_2_016, "Rename 'component_uuid' in 'webhook_deliveries' table to 'project_uuid'", RenameComponentUuidInWebhookDeliveries.class)
+ .add(10_2_017, "Create index 'webhook_deliveries_project_uuid' in 'webhook_deliveries' table", CreateIndexProjectUuidInWebhookDeliveries.class)
+
;
}
+
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DropIndexChange;
+
+public class DropIndexComponentUuidInWebhookDeliveries extends DropIndexChange {
+
+ private static final String TABLE_NAME = "webhook_deliveries";
+ private static final String INDEX_NAME = "component_uuid";
+
+ public DropIndexComponentUuidInWebhookDeliveries(Database db) {
+ super(db, INDEX_NAME, TABLE_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+
+public class RenameComponentUuidInWebhookDeliveries extends RenameVarcharColumnChange {
+
+ private static final String TABLE_NAME = "webhook_deliveries";
+ private static final String OLD_COLUMN_NAME = "component_uuid";
+ private static final String NEW_COLUMN_NAME = "project_uuid";
+
+ public RenameComponentUuidInWebhookDeliveries(Database db) {
+ super(db, TABLE_NAME, OLD_COLUMN_NAME, NEW_COLUMN_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+
+import static java.sql.Types.VARCHAR;
+
+public abstract class RenameVarcharColumnAbstractTest {
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(getClass(), "schema.sql");
+ private final String tableName;
+ private final String columnName;
+ private final boolean isNullable;
+
+ public RenameVarcharColumnAbstractTest(String tableName, String columnName, boolean isNullable) {
+ this.tableName = tableName;
+ this.columnName = columnName;
+ this.isNullable = isNullable;
+ }
+
+ protected void verifyMigrationIsReentrant() throws SQLException {
+ db.assertColumnDoesNotExist(tableName, columnName);
+ getClassUnderTest().execute();
+ getClassUnderTest().execute();
+ db.assertColumnDefinition(tableName, columnName, VARCHAR, 40, isNullable);
+ }
+
+ protected void verifyColumnIsRenamed() throws SQLException {
+ db.assertColumnDoesNotExist(tableName, columnName);
+ getClassUnderTest().execute();
+ db.assertColumnDefinition(tableName, columnName, VARCHAR, 40, isNullable);
+ }
+
+ protected abstract RenameVarcharColumnChange getClassUnderTest();
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class CreateIndexProjectUuidInWebhookDeliveriesTest {
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(CreateIndexProjectUuidInWebhookDeliveriesTest.class, "schema.sql");
+
+ private final CreateIndexProjectUuidInWebhookDeliveries createIndex = new CreateIndexProjectUuidInWebhookDeliveries(db.database());
+
+ @Test
+ public void migration_should_create_index() throws SQLException {
+ db.assertIndexDoesNotExist("webhook_deliveries", "wd_project_uuid");
+
+ createIndex.execute();
+
+ db.assertIndex("webhook_deliveries", "wd_project_uuid", "project_uuid");
+ }
+
+ @Test
+ public void migration_should_be_reentrant() throws SQLException {
+ createIndex.execute();
+ createIndex.execute();
+
+ db.assertIndex("webhook_deliveries", "wd_project_uuid", "project_uuid");
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class DropIndexComponentUuidInWebhookDeliveriesTest {
+
+ private static final String TABLE_NAME = "webhook_deliveries";
+ private static final String COLUMN_NAME = "component_uuid";
+ private static final String INDEX_NAME = "component_uuid";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexComponentUuidInWebhookDeliveriesTest.class, "schema.sql");
+
+ private final DropIndexComponentUuidInWebhookDeliveries underTest = new DropIndexComponentUuidInWebhookDeliveries(db.database());
+
+ @Test
+ public void index_is_dropped() throws SQLException {
+ db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);
+
+ underTest.execute();
+
+ db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ db.assertIndex(TABLE_NAME, INDEX_NAME, COLUMN_NAME);
+
+ underTest.execute();
+ underTest.execute();
+
+ db.assertIndexDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v102;
+
+import java.sql.SQLException;
+import org.junit.Test;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+import org.sonar.server.platform.db.migration.version.RenameVarcharColumnAbstractTest;
+
+public class RenameComponentUuidInWebhookDeliveriesTest extends RenameVarcharColumnAbstractTest {
+
+ public RenameComponentUuidInWebhookDeliveriesTest() {
+ super("webhook_deliveries", "project_uuid", false);
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ super.verifyMigrationIsReentrant();
+ }
+
+ @Test
+ public void column_is_renamed() throws SQLException {
+ super.verifyColumnIsRenamed();
+ }
+
+ @Override
+ protected RenameVarcharColumnChange getClassUnderTest() {
+ return new RenameComponentUuidInWebhookDeliveries(db.database());
+ }
+
+}
--- /dev/null
+CREATE TABLE "WEBHOOK_DELIVERIES"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL,
+ "PROJECT_UUID" CHARACTER VARYING(40) NOT NULL,
+ "CE_TASK_UUID" CHARACTER VARYING(40),
+ "ANALYSIS_UUID" CHARACTER VARYING(40),
+ "NAME" CHARACTER VARYING(100) NOT NULL,
+ "URL" CHARACTER VARYING(2000) NOT NULL,
+ "SUCCESS" BOOLEAN NOT NULL,
+ "HTTP_STATUS" INTEGER,
+ "DURATION_MS" BIGINT NOT NULL,
+ "PAYLOAD" CHARACTER LARGE OBJECT NOT NULL,
+ "ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
+ "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
+CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST);
+CREATE INDEX "IDX_WBHK_DLVRS_WBHK_UUID" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID" NULLS FIRST);
\ No newline at end of file
--- /dev/null
+CREATE TABLE "WEBHOOK_DELIVERIES"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL,
+ "COMPONENT_UUID" CHARACTER VARYING(40) NOT NULL,
+ "CE_TASK_UUID" CHARACTER VARYING(40),
+ "ANALYSIS_UUID" CHARACTER VARYING(40),
+ "NAME" CHARACTER VARYING(100) NOT NULL,
+ "URL" CHARACTER VARYING(2000) NOT NULL,
+ "SUCCESS" BOOLEAN NOT NULL,
+ "HTTP_STATUS" INTEGER,
+ "DURATION_MS" BIGINT NOT NULL,
+ "PAYLOAD" CHARACTER LARGE OBJECT NOT NULL,
+ "ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
+ "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
+CREATE INDEX "COMPONENT_UUID" ON "WEBHOOK_DELIVERIES"("COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST);
+CREATE INDEX "IDX_WBHK_DLVRS_WBHK_UUID" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID" NULLS FIRST);
\ No newline at end of file
--- /dev/null
+CREATE TABLE "WEBHOOK_DELIVERIES"(
+ "UUID" CHARACTER VARYING(40) NOT NULL,
+ "WEBHOOK_UUID" CHARACTER VARYING(40) NOT NULL,
+ "COMPONENT_UUID" CHARACTER VARYING(40) NOT NULL,
+ "CE_TASK_UUID" CHARACTER VARYING(40),
+ "ANALYSIS_UUID" CHARACTER VARYING(40),
+ "NAME" CHARACTER VARYING(100) NOT NULL,
+ "URL" CHARACTER VARYING(2000) NOT NULL,
+ "SUCCESS" BOOLEAN NOT NULL,
+ "HTTP_STATUS" INTEGER,
+ "DURATION_MS" BIGINT NOT NULL,
+ "PAYLOAD" CHARACTER LARGE OBJECT NOT NULL,
+ "ERROR_STACKTRACE" CHARACTER LARGE OBJECT,
+ "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "WEBHOOK_DELIVERIES" ADD CONSTRAINT "PK_WEBHOOK_DELIVERIES" PRIMARY KEY("UUID");
+CREATE INDEX "COMPONENT_UUID" ON "WEBHOOK_DELIVERIES"("COMPONENT_UUID" NULLS FIRST);
+CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES"("CE_TASK_UUID" NULLS FIRST);
+CREATE INDEX "IDX_WBHK_DLVRS_WBHK_UUID" ON "WEBHOOK_DELIVERIES"("WEBHOOK_UUID" NULLS FIRST);
\ No newline at end of file
WebhookDeliveryDto dto = dbClient.webhookDeliveryDao().selectByUuid(dbSession, DELIVERY_UUID).get();
assertThat(dto.getUuid()).isEqualTo(DELIVERY_UUID);
assertThat(dto.getWebhookUuid()).isEqualTo("WEBHOOK_UUID_1");
- assertThat(dto.getComponentUuid()).isEqualTo(delivery.getWebhook().getComponentUuid());
+ assertThat(dto.getProjectUuid()).isEqualTo(delivery.getWebhook().getProjectUuid());
assertThat(dto.getCeTaskUuid()).isEqualTo(delivery.getWebhook().getCeTaskUuid().get());
assertThat(dto.getName()).isEqualTo(delivery.getWebhook().getName());
assertThat(dto.getUrl()).isEqualTo(delivery.getWebhook().getUrl());
private static WebhookDeliveryDto newDto(String uuid, String componentUuid, long at) {
return WebhookDeliveryTesting.newDto()
.setUuid(uuid)
- .setComponentUuid(componentUuid)
+ .setProjectUuid(componentUuid)
.setCreatedAt(at);
}
}
public class Webhook {
private final String uuid;
- private final String componentUuid;
+ private final String projectUuid;
@Nullable
private final String ceTaskUuid;
@Nullable
@Nullable
private final String secret;
- public Webhook(String uuid, String componentUuid, @Nullable String ceTaskUuid,
+ public Webhook(String uuid, String projectUuid, @Nullable String ceTaskUuid,
@Nullable String analysisUuid, String name, String url, @Nullable String secret) {
this.uuid = uuid;
- this.componentUuid = requireNonNull(componentUuid);
+ this.projectUuid = requireNonNull(projectUuid);
this.ceTaskUuid = ceTaskUuid;
this.analysisUuid = analysisUuid;
this.name = requireNonNull(name);
this.secret = secret;
}
- public String getComponentUuid() {
- return componentUuid;
+ public String getProjectUuid() {
+ return projectUuid;
}
public Optional<String> getCeTaskUuid() {
}
}
- public void purge(String componentUuid) {
+ public void purge(String projectUuid) {
long beforeDate = system.now() - ALIVE_DELAY_MS;
try (DbSession dbSession = dbClient.openSession(false)) {
- dbClient.webhookDeliveryDao().deleteComponentBeforeDate(dbSession, componentUuid, beforeDate);
+ dbClient.webhookDeliveryDao().deleteProjectBeforeDate(dbSession, projectUuid, beforeDate);
dbSession.commit();
}
}
WebhookDeliveryDto dto = new WebhookDeliveryDto();
dto.setUuid(uuidFactory.create());
dto.setWebhookUuid(delivery.getWebhook().getUuid());
- dto.setComponentUuid(delivery.getWebhook().getComponentUuid());
+ dto.setProjectUuid(delivery.getWebhook().getProjectUuid());
delivery.getWebhook().getCeTaskUuid().ifPresent(dto::setCeTaskUuid);
delivery.getWebhook().getAnalysisUuid().ifPresent(dto::setAnalysisUuid);
dto.setName(delivery.getWebhook().getName());
@Test
public void webhook_with_only_required_fields() {
- Webhook underTest = new Webhook("a_uuid", "a_component_uuid", null, null, "a_name", "an_url", null);
+ Webhook underTest = new Webhook("a_uuid", "a_project_uuid", null, null, "a_name", "an_url", null);
assertThat(underTest.getUuid()).isEqualTo("a_uuid");
- assertThat(underTest.getComponentUuid()).isEqualTo("a_component_uuid");
+ assertThat(underTest.getProjectUuid()).isEqualTo("a_project_uuid");
assertThat(underTest.getCeTaskUuid()).isEmpty();
assertThat(underTest.getAnalysisUuid()).isEmpty();
assertThat(underTest.getName()).isEqualTo("a_name");
Webhook underTest = new Webhook("a_uuid", "a_component_uuid", "a_task_uuid", "an_analysis", "a_name", "an_url", "a_secret");
assertThat(underTest.getUuid()).isEqualTo("a_uuid");
- assertThat(underTest.getComponentUuid()).isEqualTo("a_component_uuid");
+ assertThat(underTest.getProjectUuid()).isEqualTo("a_component_uuid");
assertThat(underTest.getCeTaskUuid()).hasValue("a_task_uuid");
assertThat(underTest.getAnalysisUuid()).hasValue("an_analysis");
assertThat(underTest.getName()).isEqualTo("a_name");
public UserSessionRule userSession = standalone();
@Rule
- public DbTester db = create();
+ public DbTester db = create(true);
private final DbClient dbClient = db.getDbClient();
private final WebhookDbTester webhookDbTester = db.webhooks();
private final ComponentDbTester componentDbTester = db.components();
@Test
public void create_a_webhook_with_400_length_project_key() {
String longProjectKey = generateStringWithLength(400);
- ComponentDto project = componentDbTester.insertPrivateProject(componentDto -> componentDto.setKey(longProjectKey)).getMainBranchComponent();
+ ProjectDto project = componentDbTester.insertPrivateProject(componentDto -> componentDto.setKey(longProjectKey)).getProjectDto();
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
@Test
public void create_a_webhook_on_project() {
- ComponentDto project = componentDbTester.insertPrivateProject().getMainBranchComponent();
+ ProjectDto project = componentDbTester.insertPrivateProject().getProjectDto();
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
public UserSessionRule userSession = standalone();
@Rule
- public DbTester db = create();
+ public DbTester db = create(true);
private final DbClient dbClient = db.getDbClient();
private final DbSession dbSession = db.getSession();
private final WebhookDbTester webhookDbTester = db.webhooks();
public UserSessionRule userSession = standalone();
@Rule
- public DbTester db = create();
+ public DbTester db = create(true);
private final DbClient dbClient = db.getDbClient();
private final Configuration configuration = mock(Configuration.class);
public UserSessionRule userSession = standalone();
@Rule
- public DbTester db = create();
+ public DbTester db = create(true);
private final DbClient dbClient = db.getDbClient();
private final WebhookDbTester webhookDbTester = db.webhooks();
private final ComponentDbTester componentDbTester = db.components();
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.webhook.WebhookDeliveryDbTester;
import org.sonar.db.webhook.WebhookDeliveryDto;
import org.sonar.server.component.ComponentFinder;
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
private DbClient dbClient = db.getDbClient();
private WebhookDeliveryDbTester webhookDeliveryDbTester = db.webhookDelivery();
private WsActionTester ws;
- private ComponentDto project;
- private ComponentDto otherProject;
+ private ProjectDto project;
+ private ProjectDto otherProject;
@Before
public void setUp() {
ComponentFinder componentFinder = TestComponentFinder.from(db);
WebhookDeliveriesAction underTest = new WebhookDeliveriesAction(dbClient, userSession, componentFinder);
ws = new WsActionTester(underTest);
- project = db.components().insertPrivateProject(c -> c.setKey("my-project")).getMainBranchComponent();
- otherProject = db.components().insertPrivateProject(c -> c.setKey("other-project")).getMainBranchComponent();
+ project = db.components().insertPrivateProject(c -> c.setKey("my-project")).getProjectDto();
+ otherProject = db.components().insertPrivateProject(c -> c.setKey("other-project")).getProjectDto();
}
@Test
public void search_by_component_and_return_records_of_example() {
WebhookDeliveryDto dto = newDto()
.setUuid("d1")
- .setComponentUuid(project.uuid())
+ .setProjectUuid(project.getUuid())
.setCeTaskUuid("task-1")
.setName("Jenkins")
.setUrl("http://jenkins")
@Test
public void search_by_task_and_return_records() {
- WebhookDeliveryDto dto1 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1");
- WebhookDeliveryDto dto2 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1");
- WebhookDeliveryDto dto3 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t2");
+ WebhookDeliveryDto dto1 = newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t1");
+ WebhookDeliveryDto dto2 = newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t1");
+ WebhookDeliveryDto dto3 = newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t2");
dbClient.webhookDeliveryDao().insert(db.getSession(), dto1);
dbClient.webhookDeliveryDao().insert(db.getSession(), dto2);
dbClient.webhookDeliveryDao().insert(db.getSession(), dto3);
@Test
public void search_by_webhook_and_return_records() {
- WebhookDeliveryDto dto1 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid");
- WebhookDeliveryDto dto2 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid");
- WebhookDeliveryDto dto3 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t2").setWebhookUuid("wh-2-uuid");
+ WebhookDeliveryDto dto1 = newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid");
+ WebhookDeliveryDto dto2 = newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid");
+ WebhookDeliveryDto dto3 = newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t2").setWebhookUuid("wh-2-uuid");
- WebhookDeliveryDto dto4 = newDto().setComponentUuid(otherProject.uuid()).setCeTaskUuid("t4").setWebhookUuid("wh-1-uuid");
- WebhookDeliveryDto dto5 = newDto().setComponentUuid(otherProject.uuid()).setCeTaskUuid("t5").setWebhookUuid("wh-1-uuid");
+ WebhookDeliveryDto dto4 = newDto().setProjectUuid(otherProject.getUuid()).setCeTaskUuid("t4").setWebhookUuid("wh-1-uuid");
+ WebhookDeliveryDto dto5 = newDto().setProjectUuid(otherProject.getUuid()).setCeTaskUuid("t5").setWebhookUuid("wh-1-uuid");
dbClient.webhookDeliveryDao().insert(db.getSession(), dto1);
dbClient.webhookDeliveryDao().insert(db.getSession(), dto2);
public void validate_default_pagination() {
for (int i = 0; i < 15; i++) {
- webhookDeliveryDbTester.insert(newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid"));
+ webhookDeliveryDbTester.insert(newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid"));
}
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
public void validate_pagination_first_page() {
for (int i = 0; i < 12; i++) {
- webhookDeliveryDbTester.insert(newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid"));
+ webhookDeliveryDbTester.insert(newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid"));
}
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
public void validate_pagination_last_page() {
for (int i = 0; i < 12; i++) {
- webhookDeliveryDbTester.insert(newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid"));
+ webhookDeliveryDbTester.insert(newDto().setProjectUuid(project.getUuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid"));
}
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
@Test
public void search_by_component_and_throw_ForbiddenException_if_not_admin_of_project() {
WebhookDeliveryDto dto = newDto()
- .setComponentUuid(project.uuid());
+ .setProjectUuid(project.getUuid());
dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
db.commit();
userSession.logIn().addProjectPermission(UserRole.USER, project);
@Test
public void search_by_task_and_throw_ForbiddenException_if_not_admin_of_project() {
WebhookDeliveryDto dto = newDto()
- .setComponentUuid(project.uuid());
+ .setProjectUuid(project.getUuid());
dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
db.commit();
userSession.logIn().addProjectPermission(UserRole.USER, project);
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.server.ws.WebService;
-import org.sonar.api.utils.System2;
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.webhook.WebhookDeliveryDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.component.TestComponentFinder;
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(true);
private DbClient dbClient = db.getDbClient();
private WsActionTester ws;
- private ComponentDto project;
+ private ProjectDto project;
@Before
public void setUp() {
ComponentFinder componentFinder = TestComponentFinder.from(db);
WebhookDeliveryAction underTest = new WebhookDeliveryAction(dbClient, userSession, componentFinder);
ws = new WsActionTester(underTest);
- project = db.components().insertPrivateProject(c -> c.setKey("my-project")).getMainBranchComponent();
+ project = db.components().insertPrivateProject(c -> c.setKey("my-project")).getProjectDto();
}
@Test
public void load_the_delivery_of_example() {
WebhookDeliveryDto dto = newDto()
.setUuid("d1")
- .setComponentUuid(project.uuid())
+ .setProjectUuid(project.getUuid())
.setCeTaskUuid("task-1")
.setName("Jenkins")
.setUrl("http://jenkins")
@Test
public void return_delivery_that_failed_to_be_sent() {
WebhookDeliveryDto dto = newDto()
- .setComponentUuid(project.uuid())
+ .setProjectUuid(project.getUuid())
.setSuccess(false)
.setHttpStatus(null)
.setErrorStacktrace("IOException -> can not connect");
@Test
public void return_delivery_with_none_of_optional_fields() {
WebhookDeliveryDto dto = newDto()
- .setComponentUuid(project.uuid())
+ .setProjectUuid(project.getUuid())
.setCeTaskUuid(null)
.setHttpStatus(null)
.setErrorStacktrace(null)
@Test
public void throw_ForbiddenException_if_not_admin_of_project() {
WebhookDeliveryDto dto = newDto()
- .setComponentUuid(project.uuid());
+ .setProjectUuid(project.getUuid());
dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
db.commit();
userSession.logIn().addProjectPermission(UserRole.USER, project);
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);
+ totalElements = dbClient.webhookDeliveryDao().countDeliveriesByProjectUuid(dbSession, project.getUuid());
+ deliveries = dbClient.webhookDeliveryDao().selectOrderedByProjectUuid(dbSession, project.getUuid(), offset(page, pageSize), pageSize);
} else {
totalElements = dbClient.webhookDeliveryDao().countDeliveriesByCeTaskUuid(dbSession, ceTaskId);
deliveries = dbClient.webhookDeliveryDao().selectOrderedByCeTaskUuid(dbSession, ceTaskId, offset(page, pageSize), pageSize);
private Map<String, ProjectDto> getProjectsDto(DbSession dbSession, List<WebhookDeliveryLiteDto> deliveries) {
Map<String, String> deliveredComponentUuid = deliveries
.stream()
- .collect(Collectors.toMap(WebhookDeliveryLiteDto::getUuid, WebhookDeliveryLiteDto::getComponentUuid));
+ .collect(Collectors.toMap(WebhookDeliveryLiteDto::getUuid, WebhookDeliveryLiteDto::getProjectUuid));
if (!deliveredComponentUuid.isEmpty()) {
return dbClient.projectDao().selectByUuids(dbSession, new HashSet<>(deliveredComponentUuid.values()))
Webhooks.DeliveriesWsResponse.Builder responseBuilder = Webhooks.DeliveriesWsResponse.newBuilder();
Webhooks.Delivery.Builder deliveryBuilder = Webhooks.Delivery.newBuilder();
for (WebhookDeliveryLiteDto dto : deliveryDtos) {
- ProjectDto project = projectUuidMap.get(dto.getComponentUuid());
+ ProjectDto project = projectUuidMap.get(dto.getProjectUuid());
copyDtoToProtobuf(project, dto, deliveryBuilder);
responseBuilder.addDeliveries(deliveryBuilder);
}
try (DbSession dbSession = dbClient.openSession(false)) {
WebhookDeliveryDto delivery = dbClient.webhookDeliveryDao().selectByUuid(dbSession, deliveryUuid)
.orElseThrow(() -> new NotFoundException("Webhook delivery not found"));
- ProjectDto project = componentFinder.getProjectByUuid(dbSession, delivery.getComponentUuid());
+ ProjectDto project = componentFinder.getProjectByUuid(dbSession, delivery.getProjectUuid());
return new Data(project, delivery);
}
}