public void deleteByUuids(DbSession session, Collection<String> uuids) {
QualityGateMapper mapper = mapper(session);
- DatabaseUtils.executeLargeUpdates(uuids, partitionUuids -> {
- mapper.deleteByUuids(partitionUuids);
- mapper.deleteOrgQualityGatesByQualityGateUuids(partitionUuids);
- });
+ DatabaseUtils.executeLargeUpdates(uuids, mapper::deleteByUuids);
+ }
+
+ public void deleteOrgQualityGatesByOrganization(DbSession session, OrganizationDto organization) {
+ mapper(session).deleteOrgQualityGatesByOrganization(organization.getUuid());
}
public void update(QualityGateDto qGate, DbSession session) {
void deleteOrgQualityGatesByQualityGateUuid(String uuid);
- void deleteOrgQualityGatesByQualityGateUuids(@Param("uuids") Collection<String> uuids);
+ void deleteOrgQualityGatesByOrganization(@Param("organizationUuid") String organizationUuid);
void update(QualityGateDto qGate);
delete from org_quality_gates where quality_gate_uuid=#{uuid}
</update>
- <update id="deleteOrgQualityGatesByQualityGateUuids" parameterType="map">
+ <update id="deleteOrgQualityGatesByOrganization" parameterType="String">
delete from org_quality_gates
- where quality_gate_uuid in
- <foreach collection="uuids" open="(" close=")" item="uuid" separator=",">#{uuid, jdbcType=VARCHAR}</foreach>
+ where organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</update>
<update id="update" parameterType="QualityGate">
assertThat(db.countRowsOfTable(dbSession, "quality_gates")).isEqualTo(nbOfQualityGates);
}
+ @Test
+ public void deleteOrgQualityGatesByOrganization() {
+ OrganizationDto organization = db.organizations().insert();
+ qualityGateDbTester.insertQualityGate(organization);
+ OrganizationDto otherOrganization = db.organizations().insert();
+ qualityGateDbTester.insertQualityGate(otherOrganization);
+
+ underTest.deleteOrgQualityGatesByOrganization(dbSession, organization);
+ dbSession.commit();
+
+ assertThat(db.select("select organization_uuid as \"organizationUuid\" from org_quality_gates"))
+ .extracting(row -> (String) row.get("organizationUuid"))
+ .containsOnly(otherOrganization.getUuid());
+ }
+
@Test
public void update() {
OrganizationDto organization = db.organizations().insert();
return builtin;
}
- public void setBuiltInAsDefaultOn(OrganizationDto organizationDto) {
- QualityGateDto builtinQG = dbClient.qualityGateDao().selectBuiltIn(dbSession);
- dbClient.organizationDao().update(dbSession, organizationDto.setDefaultQualityGateUuid(builtinQG.getUuid()));
- if (dbClient.qualityGateDao().selectByOrganizationAndUuid(dbSession, organizationDto, builtinQG.getUuid()) == null) {
- dbClient.qualityGateDao().associate(dbSession, Uuids.createFast(), organizationDto, builtinQG);
- dbSession.commit();
- }
- dbSession.commit();
- }
-
@SafeVarargs
public final QGateWithOrgDto insertQualityGate(OrganizationDto organization, Consumer<QualityGateDto>... dtoPopulators) {
QualityGateDto qualityGate = new QualityGateDto()
db.commit();
}
+ public void associateQualityGateToOrganization(QualityGateDto qualityGate, OrganizationDto organization) {
+ dbClient.qualityGateDao().associate(dbSession, Uuids.createFast(), organization, qualityGate);
+ db.commit();
+ }
+
@SafeVarargs
public final QualityGateDto createDefaultQualityGate(OrganizationDto organization, Consumer<QualityGateDto>... dtoPopulators) {
QualityGateDto defaultQGate = insertQualityGate(organization, dtoPopulators);
.filter(q -> !q.isBuiltIn())
.map(QualityGateDto::getUuid)
.collect(MoreCollectors.toList()));
+ dbClient.qualityGateDao().deleteOrgQualityGatesByOrganization(dbSession, organization);
}
private void deleteOrganization(DbSession dbSession, OrganizationDto organization) {
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.permission.template.PermissionTemplateDto;
import org.sonar.db.qualitygate.QGateWithOrgDto;
+import org.sonar.db.qualitygate.QualityGateDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
@Test
public void delete_quality_gates() {
- OrganizationDto org = db.organizations().insert();
- OrganizationDto otherOrg = db.organizations().insert();
- QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(org);
- QGateWithOrgDto qualityGateInOtherOrg = db.qualityGates().insertQualityGate(otherOrg);
- db.qualityGates().insertBuiltInQualityGate();
- logInAsAdministrator(org);
+ QualityGateDto builtInQualityGate = db.qualityGates().insertBuiltInQualityGate();
+ OrganizationDto organization = db.organizations().insert();
+ db.qualityGates().associateQualityGateToOrganization(builtInQualityGate, organization);
+ OrganizationDto otherOrganization = db.organizations().insert();
+ db.qualityGates().associateQualityGateToOrganization(builtInQualityGate, otherOrganization);
+ QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+ QGateWithOrgDto qualityGateInOtherOrg = db.qualityGates().insertQualityGate(otherOrganization);
+ logInAsAdministrator(organization);
- sendRequest(org);
+ sendRequest(organization);
- verifyOrganizationDoesNotExist(org);
+ verifyOrganizationDoesNotExist(organization);
assertThat(db.select("select uuid as \"uuid\" from quality_gates"))
.extracting(row -> (String) row.get("uuid"))
- .containsOnly(qualityGateInOtherOrg.getUuid(), qualityGateFinder.getBuiltInQualityGate(db.getSession()).getUuid());
-
- // Built-in quality gate must not be destroyed
- assertThat(qualityGateFinder.getBuiltInQualityGate(db.getSession())).isNotNull();
+ .containsExactlyInAnyOrder(qualityGateInOtherOrg.getUuid(), builtInQualityGate.getUuid());
assertThat(db.select("select organization_uuid as \"organizationUuid\" from org_quality_gates"))
.extracting(row -> (String) row.get("organizationUuid"))
- .containsOnly(otherOrg.getUuid());
+ .containsOnly(otherOrganization.getUuid());
+
+ // Check built-in quality gate is still available in other organization
+ assertThat(db.getDbClient().qualityGateDao().selectByOrganizationAndName(db.getSession(), otherOrganization, "Sonar way")).isNotNull();
}
private void verifyOrganizationDoesNotExist(OrganizationDto organization) {