"project_measures",
"project_qprofiles",
"properties",
+ "push_events",
"qprofile_changes",
"qprofile_edit_groups",
"qprofile_edit_users",
import org.sonar.db.property.InternalPropertiesDao;
import org.sonar.db.property.PropertiesDao;
import org.sonar.db.purge.PurgeDao;
+import org.sonar.db.pushevent.PushEventDao;
import org.sonar.db.qualitygate.ProjectQgateAssociationDao;
import org.sonar.db.qualitygate.QualityGateConditionDao;
import org.sonar.db.qualitygate.QualityGateDao;
ProjectQgateAssociationDao.class,
PropertiesDao.class,
PurgeDao.class,
+ PushEventDao.class,
QProfileChangeDao.class,
QProfileEditGroupsDao.class,
QProfileEditUsersDao.class,
import org.sonar.db.property.InternalPropertiesDao;
import org.sonar.db.property.PropertiesDao;
import org.sonar.db.purge.PurgeDao;
+import org.sonar.db.pushevent.PushEventDao;
import org.sonar.db.qualitygate.ProjectQgateAssociationDao;
import org.sonar.db.qualitygate.QualityGateConditionDao;
import org.sonar.db.qualitygate.QualityGateDao;
private final ProjectLinkDao projectLinkDao;
private final EventDao eventDao;
private final EventComponentChangeDao eventComponentChangeDao;
+ private final PushEventDao pushEventDao;
private final PurgeDao purgeDao;
private final QualityGateDao qualityGateDao;
private final QualityGateConditionDao gateConditionDao;
projectLinkDao = getDao(map, ProjectLinkDao.class);
eventDao = getDao(map, EventDao.class);
eventComponentChangeDao = getDao(map, EventComponentChangeDao.class);
+ pushEventDao = getDao(map, PushEventDao.class);
purgeDao = getDao(map, PurgeDao.class);
qualityGateDao = getDao(map, QualityGateDao.class);
qualityGateUserPermissionsDao = getDao(map, QualityGateUserPermissionsDao.class);
return eventComponentChangeDao;
}
+ public PushEventDao pushEventDao() {
+ return pushEventDao;
+ }
+
public PurgeDao purgeDao() {
return purgeDao;
}
import org.sonar.db.property.ScrapPropertyDto;
import org.sonar.db.purge.PurgeMapper;
import org.sonar.db.purge.PurgeableAnalysisDto;
+import org.sonar.db.pushevent.PushEventDto;
+import org.sonar.db.pushevent.PushEventMapper;
import org.sonar.db.qualitygate.ProjectQgateAssociationDto;
import org.sonar.db.qualitygate.ProjectQgateAssociationMapper;
import org.sonar.db.qualitygate.QualityGateConditionDto;
confBuilder.loadAlias("ProjectCountPerAnalysisPropertyValue", ProjectCountPerAnalysisPropertyValue.class);
confBuilder.loadAlias("ProjectMapping", ProjectMappingDto.class);
confBuilder.loadAlias("PurgeableAnalysis", PurgeableAnalysisDto.class);
+ confBuilder.loadAlias("PushEvent", PushEventDto.class);
confBuilder.loadAlias("QualityGateCondition", QualityGateConditionDto.class);
confBuilder.loadAlias("QualityGate", QualityGateDto.class);
confBuilder.loadAlias("Resource", ResourceDto.class);
ProjectQgateAssociationMapper.class,
PropertiesMapper.class,
PurgeMapper.class,
+ PushEventMapper.class,
QProfileChangeMapper.class,
QProfileEditGroupsMapper.class,
QProfileEditUsersMapper.class,
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.db.pushevent;
+
+import org.sonar.api.utils.System2;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.Dao;
+import org.sonar.db.DbSession;
+
+public class PushEventDao implements Dao {
+
+ private final UuidFactory uuidFactory;
+ private final System2 system2;
+
+ public PushEventDao(System2 system2, UuidFactory uuidFactory) {
+ this.system2 = system2;
+ this.uuidFactory = uuidFactory;
+ }
+
+ public PushEventDto insert(DbSession dbSession, PushEventDto event) {
+ if (event.getUuid() == null) {
+ event.setUuid(uuidFactory.create());
+ }
+
+ event.setCreatedAt(system2.now());
+ mapper(dbSession).insert(event);
+ return event;
+ }
+
+ PushEventDto selectByUuid(DbSession dbSession, String uuid) {
+ return mapper(dbSession).selectByUuid(uuid);
+ }
+
+ private static PushEventMapper mapper(DbSession session) {
+ return session.getMapper(PushEventMapper.class);
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.db.pushevent;
+
+public class PushEventDto {
+ private String uuid;
+ private String projectUuid;
+ private byte[] payload;
+ private long createdAt;
+
+ public PushEventDto() {
+ // nothing to do
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public PushEventDto setUuid(String uuid) {
+ this.uuid = uuid;
+ return this;
+ }
+
+ public String getProjectUuid() {
+ return projectUuid;
+ }
+
+ public PushEventDto setProjectUuid(String projectUuid) {
+ this.projectUuid = projectUuid;
+ return this;
+ }
+
+ public byte[] getPayload() {
+ return payload;
+ }
+
+ public PushEventDto setPayload(byte[] payload) {
+ this.payload = payload;
+ return this;
+ }
+
+ public long getCreatedAt() {
+ return createdAt;
+ }
+
+ public PushEventDto setCreatedAt(long createdAt) {
+ this.createdAt = createdAt;
+ return this;
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.db.pushevent;
+
+import javax.annotation.CheckForNull;
+
+public interface PushEventMapper {
+
+ void insert(PushEventDto event);
+
+ @CheckForNull
+ PushEventDto selectByUuid(String uuid);
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis-3-mapper.dtd">
+<mapper namespace="org.sonar.db.pushevent.PushEventMapper">
+
+ <sql id="pushEventColumns">
+ pe.uuid as uuid,
+ pe.project_uuid as projectUuid,
+ pe.payload as payload,
+ pe.created_at as createdAt
+ </sql>
+
+ <insert id="insert" parameterType="map" useGeneratedKeys="false">
+ INSERT INTO push_events (
+ uuid,
+ project_uuid,
+ payload,
+ created_at
+ )
+ VALUES (
+ #{uuid,jdbcType=VARCHAR},
+ #{projectUuid,jdbcType=VARCHAR},
+ #{payload,jdbcType=BLOB},
+ #{createdAt,jdbcType=BIGINT}
+ )
+ </insert>
+
+ <select id="selectByUuid" parameterType="String" resultType="PushEvent">
+ SELECT
+ <include refid="pushEventColumns"/>
+ FROM push_events pe
+ where
+ pe.uuid=#{uuid,jdbcType=VARCHAR}
+ </select>
+
+</mapper>
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 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.db.pushevent;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.impl.utils.TestSystem2;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PushEventDaoTest {
+
+ private final TestSystem2 system2 = new TestSystem2().setNow(1L);
+
+ @Rule
+ public DbTester db = DbTester.create(system2);
+
+ private final DbSession session = db.getSession();
+ private final PushEventDao underTest = db.getDbClient().pushEventDao();
+
+ @Test
+ public void insert_events() {
+ assertThat(db.countRowsOfTable(session, "push_events")).isZero();
+
+ PushEventDto eventDtoFirst = new PushEventDto()
+ .setUuid("test-uuid")
+ .setProjectUuid("project-uuid")
+ .setPayload("some-event".getBytes(UTF_8));
+
+ PushEventDto eventDtoSecond = new PushEventDto()
+ .setProjectUuid("project-uuid")
+ .setPayload("some-event".getBytes(UTF_8));
+
+ underTest.insert(session, eventDtoFirst);
+ var generatedUuid = underTest.insert(session, eventDtoSecond);
+
+ assertThat(db.countRowsOfTable(session, "push_events"))
+ .isEqualTo(2);
+
+ assertThat(underTest.selectByUuid(session, "test-uuid"))
+ .extracting(PushEventDto::getUuid, PushEventDto::getProjectUuid, PushEventDto::getPayload, PushEventDto::getCreatedAt)
+ .containsExactly(eventDtoFirst.getUuid(), eventDtoFirst.getProjectUuid(), eventDtoFirst.getPayload(), eventDtoFirst.getCreatedAt());
+
+ assertThat(underTest.selectByUuid(session, generatedUuid.getUuid()))
+ .extracting(PushEventDto::getUuid, PushEventDto::getProjectUuid, PushEventDto::getPayload, PushEventDto::getCreatedAt)
+ .containsExactly(eventDtoSecond.getUuid(), eventDtoSecond.getProjectUuid(), eventDtoSecond.getPayload(), eventDtoSecond.getCreatedAt());
+
+ }
+
+}