import org.sonar.db.Dao;
import org.sonar.db.DbSession;
import org.sonar.db.Pagination;
+import org.sonar.db.qualitygate.QGateWithOrgDto;
import org.sonar.db.user.GroupDto;
import static java.util.Objects.requireNonNull;
getMapper(dbSession).updateDefaultGroupId(uuid, requireNonNull(defaultGroupId, "Default group id cannot be null"), system2.now());
}
+ public void setDefaultQualityGate(DbSession dbSession, OrganizationDto organization, QGateWithOrgDto qualityGate) {
+ getMapper(dbSession).updateDefaultQualityGate(organization.getUuid(), qualityGate.getUuid(), system2.now());
+ }
+
public boolean getNewProjectPrivate(DbSession dbSession, OrganizationDto organization) {
return getMapper(dbSession).selectNewProjectPrivateByUuid(organization.getUuid());
}
void updateDefaultGroupId(@Param("organizationUuid") String organizationUuid,
@Param("defaultGroupId") int defaultGroupId, @Param("now") long now);
+ void updateDefaultQualityGate(@Param("organizationUuid") String organizationUuid,
+ @Param("defaultQualityGateUuid") String defaultQualityGateUuid, @Param("now") long now);
+
void updateNewProjectPrivate(@Param("organizationUuid") String organizationUuid, @Param("newProjectPrivate") boolean newProjectPrivate, @Param("now") long now);
int deleteByUuid(@Param("uuid") String uuid);
return mapper(session).selectByIdAndOrganization(id, organization.getUuid());
}
+ public QGateWithOrgDto selectDefault(DbSession dbSession, OrganizationDto organization) {
+ return mapper(dbSession).selectDefault(organization.getUuid());
+ }
+
public void delete(QualityGateDto qGate, DbSession session) {
mapper(session).delete(qGate.getId());
}
QGateWithOrgDto selectByIdAndOrganization(@Param("id") long id, @Param("organizationUuid") String organizationUuid);
+ QGateWithOrgDto selectDefault(@Param("organizationUuid") String organizationUuid);
+
QualityGateDto selectBuiltIn();
void delete(long id);
uuid = #{organizationUuid, jdbcType=VARCHAR}
</update>
+ <update id="updateDefaultQualityGate">
+ update organizations
+ set
+ default_quality_gate_uuid = #{defaultQualityGateUuid, jdbcType=INTEGER},
+ updated_at = #{now, jdbcType=BIGINT}
+ where
+ uuid = #{organizationUuid, jdbcType=VARCHAR}
+ </update>
+
<update id="updateNewProjectPrivate">
update organizations
set
is_built_in = ${_true}
</select>
+ <select id="selectDefault" resultType="org.sonar.db.qualitygate.QGateWithOrgDto">
+ SELECT
+ <include refid="qateWithOrgColumns"/>
+ FROM quality_gates qg
+ INNER JOIN org_quality_gates oqg ON oqg.quality_gate_uuid = qg.uuid
+ INNER JOIN organizations o ON o.default_quality_gate_uuid = qg.uuid AND o.uuid=#{organizationUuid, jdbcType=VARCHAR}
+ </select>
+
<update id="delete" parameterType="long">
delete from quality_gates where id=#{id}
</update>
import org.sonar.db.DbTester;
import org.sonar.db.dialect.Dialect;
import org.sonar.db.dialect.Oracle;
+import org.sonar.db.qualitygate.QGateWithOrgDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.GroupTesting;
import org.sonar.db.user.UserDto;
underTest.setDefaultGroupId(dbSession, "uuid", GroupTesting.newGroupDto().setId(null));
}
+ @Test
+ public void setDefaultQualityGate() {
+ when(system2.now()).thenReturn(DATE_3);
+ OrganizationDto organization = dbTester.organizations().insert();
+ QGateWithOrgDto qualityGate = dbTester.qualityGates().insertQualityGate(organization);
+
+ underTest.setDefaultQualityGate(dbSession, organization, qualityGate);
+ dbTester.commit();
+
+ assertThat(dbClient.qualityGateDao().selectDefault(dbSession, organization).getUuid()).isEqualTo(qualityGate.getUuid());
+ verifyOrganizationUpdatedAt(organization.getUuid(), DATE_3);
+ }
+
@Test
public void update_fails_with_NPE_if_OrganizationDto_is_null() {
expectDtoCanNotBeNull();
" guarded as \"guarded\", user_id as \"userId\"," +
" created_at as \"createdAt\", updated_at as \"updatedAt\"," +
" default_perm_template_project as \"projectDefaultPermTemplate\"," +
- " default_perm_template_view as \"viewDefaultPermTemplate\"" +
+ " default_perm_template_view as \"viewDefaultPermTemplate\"," +
+ " default_quality_gate_uuid as \"defaultQualityGateUuid\" " +
" from organizations");
assertThat(rows).hasSize(1);
return rows.get(0);
assertThat(underTest.selectByOrganizationAndId(dbSession, organization, 123L)).isNull();
}
+ @Test
+ public void select_default() {
+ OrganizationDto organization = db.organizations().insert();
+ QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
+ db.getDbClient().organizationDao().setDefaultQualityGate(dbSession, organization, qualityGate);
+ OrganizationDto otherOrganization = db.organizations().insert();
+ QGateWithOrgDto otherQualityGate = db.qualityGates().insertQualityGate(otherOrganization);
+ db.getDbClient().organizationDao().setDefaultQualityGate(dbSession, otherOrganization, otherQualityGate);
+
+ assertThat(underTest.selectDefault(dbSession, organization).getUuid()).isEqualTo(qualityGate.getUuid());
+ assertThat(underTest.selectDefault(dbSession, otherOrganization).getUuid()).isEqualTo(otherQualityGate.getUuid());
+ }
+
@Test
public void delete() {
OrganizationDto organization = db.organizations().insert();