diff options
98 files changed, 1561 insertions, 378 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java index e1597caa9e3..3ef9e5d5344 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java @@ -219,7 +219,7 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor org.sonar.ce.task.projectanalysis.qualitygate.QualityGate qualityGate = qualityGateOptional.get(); return new QualityGateImpl( - String.valueOf(qualityGate.getId()), + qualityGate.getUuid(), qualityGate.getName(), convert(qualityGateStatusHolder.getStatus()), convert(qualityGate.getConditions(), qualityGateStatusHolder.getStatusPerConditions())); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGate.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGate.java index 4c44a68f40f..b25d2cf5f64 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGate.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGate.java @@ -28,18 +28,18 @@ import static com.google.common.collect.FluentIterable.from; @Immutable public class QualityGate { - private final long id; + private final String uuid; private final String name; private final Set<Condition> conditions; - public QualityGate(long id, String name, Iterable<Condition> conditions) { - this.id = id; + public QualityGate(String uuid, String name, Iterable<Condition> conditions) { + this.uuid = uuid; this.name = Objects.requireNonNull(name); this.conditions = from(conditions).filter(notNull()).toSet(); } - public long getId() { - return id; + public String getUuid() { + return uuid; } public String getName() { diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateService.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateService.java index e8572e54b81..aa02034c48c 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateService.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateService.java @@ -26,9 +26,9 @@ import org.sonar.server.project.Project; public interface QualityGateService { /** - * Retrieve the {@link QualityGate} from the database with the specified id, if it exists. + * Retrieve the {@link QualityGate} from the database with the specified uuid, if it exists. */ - Optional<QualityGate> findById(long id); + Optional<QualityGate> findByUuid(String uuid); /** * Retrieve the {@link QualityGate} from the database using organization. diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java index 51135a6ec7f..b86fc56d1e5 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImpl.java @@ -43,9 +43,9 @@ public class QualityGateServiceImpl implements QualityGateService { } @Override - public Optional<QualityGate> findById(long id) { + public Optional<QualityGate> findByUuid(String uuid) { try (DbSession dbSession = dbClient.openSession(false)) { - QualityGateDto qualityGateDto = dbClient.qualityGateDao().selectById(dbSession, id); + QualityGateDto qualityGateDto = dbClient.qualityGateDao().selectByUuid(dbSession, uuid); if (qualityGateDto == null) { return Optional.empty(); } @@ -76,7 +76,7 @@ public class QualityGateServiceImpl implements QualityGateService { } private QualityGate toQualityGate(DbSession dbSession, QualityGateDto qualityGateDto) { - Collection<QualityGateConditionDto> dtos = dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getId()); + Collection<QualityGateConditionDto> dtos = dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getUuid()); Iterable<Condition> conditions = dtos.stream() .map(input -> metricRepository.getOptionalByUuid(input.getMetricUuid()) @@ -85,6 +85,6 @@ public class QualityGateServiceImpl implements QualityGateService { .filter(Objects::nonNull) .collect(toList(dtos.size())); - return new QualityGate(qualityGateDto.getId(), qualityGateDto.getName(), conditions); + return new QualityGate(qualityGateDto.getUuid(), qualityGateDto.getName(), conditions); } } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStep.java index 3454d48dc15..fca307772a6 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStep.java @@ -62,7 +62,7 @@ public class LoadQualityGateStep implements ComputationStep { } private static Optional<QualityGate> filterQGForPR(Optional<QualityGate> qualityGate) { - return qualityGate.map(qg -> new QualityGate(qg.getId(), qg.getName(), + return qualityGate.map(qg -> new QualityGate(qg.getUuid(), qg.getName(), qg.getConditions().stream().filter(Condition::useVariation).collect(Collectors.toList()))); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java index 009c10f119d..a30108130da 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java @@ -73,7 +73,7 @@ import static org.mockito.Mockito.when; @RunWith(DataProviderRunner.class) public class PostProjectAnalysisTasksExecutorTest { - private static final long QUALITY_GATE_ID = 98451; + private static final String QUALITY_GATE_UUID = "98451"; private static final String QUALITY_GATE_NAME = "qualityGate name"; private static final Condition CONDITION_1 = createCondition("metric key 1"); private static final Condition CONDITION_2 = createCondition("metric key 2"); @@ -110,7 +110,7 @@ public class PostProjectAnalysisTasksExecutorTest { @Before public void setUp() { - qualityGateHolder.setQualityGate(new QualityGate(QUALITY_GATE_ID, QUALITY_GATE_NAME, of(CONDITION_1, CONDITION_2))); + qualityGateHolder.setQualityGate(new QualityGate(QUALITY_GATE_UUID, QUALITY_GATE_NAME, of(CONDITION_1, CONDITION_2))); qualityGateStatusHolder.setStatus(QualityGateStatus.OK, ImmutableMap.of( CONDITION_1, ConditionStatus.create(ConditionStatus.EvaluationStatus.OK, "value"), CONDITION_2, ConditionStatus.NO_VALUE_STATUS)); @@ -346,7 +346,7 @@ public class PostProjectAnalysisTasksExecutorTest { org.sonar.api.ce.posttask.QualityGate qualityGate = taskContextCaptor.getValue().getProjectAnalysis().getQualityGate(); assertThat(qualityGate.getStatus()).isEqualTo(org.sonar.api.ce.posttask.QualityGate.Status.OK); - assertThat(qualityGate.getId()).isEqualTo(String.valueOf(QUALITY_GATE_ID)); + assertThat(qualityGate.getId()).isEqualTo(String.valueOf(QUALITY_GATE_UUID)); assertThat(qualityGate.getName()).isEqualTo(QUALITY_GATE_NAME); assertThat(qualityGate.getConditions()).hasSize(2); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateHolderImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateHolderImplTest.java index f128eb314d6..f0b6220ac7d 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateHolderImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateHolderImplTest.java @@ -28,7 +28,7 @@ import static org.mockito.Mockito.mock; public class QualityGateHolderImplTest { - private static final QualityGate QUALITY_GATE = new QualityGate(4612, "name", emptyList()); + private static final QualityGate QUALITY_GATE = new QualityGate("4612", "name", emptyList()); @Test(expected = IllegalStateException.class) public void getQualityGate_throws_ISE_if_QualityGate_not_set() { diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java index 2e559ec8d95..50dbc1fc221 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/qualitygate/QualityGateServiceImplTest.java @@ -42,9 +42,9 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class QualityGateServiceImplTest { - private static final long SOME_ID = 123; + private static final String SOME_UUID = "123"; private static final String SOME_NAME = "some name"; - private static final QualityGateDto QUALITY_GATE_DTO = new QualityGateDto().setId(SOME_ID).setName(SOME_NAME); + private static final QualityGateDto QUALITY_GATE_DTO = new QualityGateDto().setUuid(SOME_UUID).setName(SOME_NAME); private static final String METRIC_UUID_1 = "uuid1"; private static final String METRIC_UUID_2 = "uuid2"; private static final Metric METRIC_1 = mock(Metric.class); @@ -71,34 +71,34 @@ public class QualityGateServiceImplTest { @Test public void findById_returns_absent_when_QualityGateDto_does_not_exist() { - assertThat(underTest.findById(SOME_ID)).isNotPresent(); + assertThat(underTest.findByUuid(SOME_UUID)).isNotPresent(); } @Test public void findById_returns_QualityGate_with_empty_set_of_conditions_when_there_is_none_in_DB() { - when(qualityGateDao.selectById(any(), eq(SOME_ID))).thenReturn(QUALITY_GATE_DTO); - when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_ID))).thenReturn(Collections.emptyList()); + when(qualityGateDao.selectByUuid(any(), eq(SOME_UUID))).thenReturn(QUALITY_GATE_DTO); + when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_UUID))).thenReturn(Collections.emptyList()); - Optional<QualityGate> res = underTest.findById(SOME_ID); + Optional<QualityGate> res = underTest.findByUuid(SOME_UUID); assertThat(res).isPresent(); - assertThat(res.get().getId()).isEqualTo(SOME_ID); + assertThat(res.get().getUuid()).isEqualTo(SOME_UUID); assertThat(res.get().getName()).isEqualTo(SOME_NAME); assertThat(res.get().getConditions()).isEmpty(); } @Test public void findById_returns_conditions_when_there_is_some_in_DB() { - when(qualityGateDao.selectById(any(), eq(SOME_ID))).thenReturn(QUALITY_GATE_DTO); - when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_ID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2)); + when(qualityGateDao.selectByUuid(any(), eq(SOME_UUID))).thenReturn(QUALITY_GATE_DTO); + when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_UUID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2)); // metrics are always supposed to be there when(metricRepository.getOptionalByUuid(METRIC_UUID_1)).thenReturn(Optional.of(METRIC_1)); when(metricRepository.getOptionalByUuid(METRIC_UUID_2)).thenReturn(Optional.of(METRIC_2)); - Optional<QualityGate> res = underTest.findById(SOME_ID); + Optional<QualityGate> res = underTest.findByUuid(SOME_UUID); assertThat(res).isPresent(); - assertThat(res.get().getId()).isEqualTo(SOME_ID); + assertThat(res.get().getUuid()).isEqualTo(SOME_UUID); assertThat(res.get().getName()).isEqualTo(SOME_NAME); assertThat(res.get().getConditions()).containsOnly( new Condition(METRIC_1, CONDITION_1.getOperator(), CONDITION_1.getErrorThreshold()), @@ -107,16 +107,16 @@ public class QualityGateServiceImplTest { @Test public void findById_ignores_conditions_on_missing_metrics() { - when(qualityGateDao.selectById(any(), eq(SOME_ID))).thenReturn(QUALITY_GATE_DTO); - when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_ID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2)); + when(qualityGateDao.selectByUuid(any(), eq(SOME_UUID))).thenReturn(QUALITY_GATE_DTO); + when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_UUID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2)); // metrics are always supposed to be there when(metricRepository.getOptionalByUuid(METRIC_UUID_1)).thenReturn(Optional.empty()); when(metricRepository.getOptionalByUuid(METRIC_UUID_2)).thenReturn(Optional.of(METRIC_2)); - Optional<QualityGate> res = underTest.findById(SOME_ID); + Optional<QualityGate> res = underTest.findByUuid(SOME_UUID); assertThat(res).isPresent(); - assertThat(res.get().getId()).isEqualTo(SOME_ID); + assertThat(res.get().getUuid()).isEqualTo(SOME_UUID); assertThat(res.get().getName()).isEqualTo(SOME_NAME); assertThat(res.get().getConditions()).containsOnly( new Condition(METRIC_2, CONDITION_2.getOperator(), CONDITION_2.getErrorThreshold())); @@ -132,17 +132,17 @@ public class QualityGateServiceImplTest { @Test public void findDefaultQualityGate_by_organization_found() { QGateWithOrgDto qGateWithOrgDto = new QGateWithOrgDto(); - qGateWithOrgDto.setId(QUALITY_GATE_DTO.getId()); + qGateWithOrgDto.setUuid(QUALITY_GATE_DTO.getUuid()); qGateWithOrgDto.setName(QUALITY_GATE_DTO.getName()); when(qualityGateDao.selectByOrganizationAndUuid(any(), any(), any())).thenReturn(qGateWithOrgDto); - when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_ID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2)); + when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_UUID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2)); when(metricRepository.getOptionalByUuid(METRIC_UUID_1)).thenReturn(Optional.empty()); when(metricRepository.getOptionalByUuid(METRIC_UUID_2)).thenReturn(Optional.of(METRIC_2)); QualityGate result = underTest.findDefaultQualityGate(mock(Organization.class)); assertThat(result).isNotNull(); - assertThat(result.getId()).isEqualTo(QUALITY_GATE_DTO.getId()); + assertThat(result.getUuid()).isEqualTo(QUALITY_GATE_DTO.getUuid()); assertThat(result.getName()).isNotBlank(); assertThat(result.getName()).isEqualTo(QUALITY_GATE_DTO.getName()); } @@ -157,10 +157,10 @@ public class QualityGateServiceImplTest { @Test public void findQualityGate_by_project_found() { QGateWithOrgDto qGateWithOrgDto = new QGateWithOrgDto(); - qGateWithOrgDto.setId(QUALITY_GATE_DTO.getId()); + qGateWithOrgDto.setUuid(QUALITY_GATE_DTO.getUuid()); qGateWithOrgDto.setName(QUALITY_GATE_DTO.getName()); when(qualityGateDao.selectByProjectUuid(any(), any())).thenReturn(qGateWithOrgDto); - when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_ID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2)); + when(qualityGateConditionDao.selectForQualityGate(any(), eq(SOME_UUID))).thenReturn(ImmutableList.of(CONDITION_1, CONDITION_2)); when(metricRepository.getOptionalByUuid(METRIC_UUID_1)).thenReturn(Optional.empty()); when(metricRepository.getOptionalByUuid(METRIC_UUID_2)).thenReturn(Optional.of(METRIC_2)); @@ -170,7 +170,7 @@ public class QualityGateServiceImplTest { assertThat(result).isNotEmpty(); QualityGate resultData = result.get(); - assertThat(resultData.getId()).isEqualTo(QUALITY_GATE_DTO.getId()); + assertThat(resultData.getUuid()).isEqualTo(QUALITY_GATE_DTO.getUuid()); assertThat(resultData.getName()).isNotBlank(); assertThat(resultData.getName()).isEqualTo(QUALITY_GATE_DTO.getName()); } diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java index 56ccfae2e96..ea942fb5a12 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadQualityGateStepTest.java @@ -67,7 +67,7 @@ public class LoadQualityGateStepTest { Condition condition = new Condition(metric, Condition.Operator.GREATER_THAN.getDbValue(), "1.0"); when(analysisMetadataHolder.isPullRequest()).thenReturn(true); - QualityGate defaultGate = new QualityGate(1, "qg", Arrays.asList(variation, condition)); + QualityGate defaultGate = new QualityGate("1", "qg", Arrays.asList(variation, condition)); when(qualityGateService.findDefaultQualityGate(any(Organization.class))).thenReturn(defaultGate); underTest.execute(new TestComputationStepContext()); @@ -87,7 +87,7 @@ public class LoadQualityGateStepTest { @Test public void execute_sets_QualityGate_if_it_can_be_found_by_service() { - QualityGate qualityGate = new QualityGate(10, "name", emptyList()); + QualityGate qualityGate = new QualityGate("10", "name", emptyList()); when(analysisMetadataHolder.getProject()).thenReturn(mock(Project.class)); when(qualityGateService.findQualityGate(any(Project.class))).thenReturn(Optional.of(qualityGate)); diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java index 2a4f77aec44..6086b7e672f 100644 --- a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java +++ b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateMeasuresStepTest.java @@ -71,7 +71,7 @@ public class QualityGateMeasuresStepTest { private static final int PROJECT_REF = 1; private static final ReportComponent PROJECT_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, PROJECT_REF).build(); - private static final long SOME_QG_ID = 7521551; + private static final String SOME_QG_UUID = "7521551"; private static final String SOME_QG_NAME = "name"; @Rule @@ -150,7 +150,7 @@ public class QualityGateMeasuresStepTest { @Test public void new_measures_are_created_even_if_there_is_no_rawMeasure_for_metric_of_condition() { Condition equals2Condition = createLessThanCondition(INT_METRIC_1, "2"); - qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equals2Condition))); + qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(equals2Condition))); underTest.execute(new TestComputationStepContext()); @@ -175,7 +175,7 @@ public class QualityGateMeasuresStepTest { Condition equals2Condition = createLessThanCondition(INT_METRIC_1, "2"); Measure rawMeasure = newMeasureBuilder().create(rawValue, null); - qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equals2Condition))); + qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(equals2Condition))); measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure); underTest.execute(new TestComputationStepContext()); @@ -204,7 +204,7 @@ public class QualityGateMeasuresStepTest { Condition equalsOneOkCondition = createLessThanCondition(INT_METRIC_2, "2"); Measure rawMeasure = newMeasureBuilder().create(rawValue, null); - qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(equalsOneErrorCondition, equalsOneOkCondition))); + qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(equalsOneErrorCondition, equalsOneOkCondition))); measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, rawMeasure); measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_2_KEY, rawMeasure); @@ -241,7 +241,7 @@ public class QualityGateMeasuresStepTest { Condition fixedCondition = createLessThanCondition(INT_METRIC_1, "4"); Condition periodCondition = createLessThanCondition(INT_METRIC_1, "2"); - qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(fixedCondition, periodCondition))); + qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(fixedCondition, periodCondition))); Measure measure = newMeasureBuilder().create(rawValue, null); measureRepository.addRawMeasure(PROJECT_REF, INT_METRIC_1_KEY, measure); @@ -259,7 +259,7 @@ public class QualityGateMeasuresStepTest { Condition fixedCondition = createLessThanCondition(INT_METRIC_1, "1"); Condition periodCondition = createLessThanCondition(INT_METRIC_1, "1"); - qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_ID, SOME_QG_NAME, of(fixedCondition, periodCondition))); + qualityGateHolder.setQualityGate(new QualityGate(SOME_QG_UUID, SOME_QG_NAME, of(fixedCondition, periodCondition))); Measure measure = newMeasureBuilder() .setVariation(rawValue) .create(rawValue, null); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDto.java index a0a21feb9ab..d309dd4a0eb 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/ProjectQgateAssociationDto.java @@ -30,7 +30,7 @@ public class ProjectQgateAssociationDto { private String uuid; private String key; private String name; - private String gateId; + private String gateUuid; public String getUuid() { return uuid; @@ -60,12 +60,12 @@ public class ProjectQgateAssociationDto { } @CheckForNull - public String getGateId() { - return gateId; + public String getGateUuid() { + return gateUuid; } - public ProjectQgateAssociationDto setGateId(@Nullable String gateId) { - this.gateId = gateId; + public ProjectQgateAssociationDto setGateUuid(@Nullable String gateUuid) { + this.gateUuid = gateUuid; return this; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QGateWithOrgDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QGateWithOrgDto.java index c200851242d..0289a88ca77 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QGateWithOrgDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QGateWithOrgDto.java @@ -44,12 +44,6 @@ public class QGateWithOrgDto extends QualityGateDto { } @Override - public QGateWithOrgDto setId(Long id) { - super.setId(id); - return this; - } - - @Override public QGateWithOrgDto setName(String name) { super.setName(name); return this; diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java index 88163b8eded..949aabf66cb 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDao.java @@ -30,8 +30,8 @@ public class QualityGateConditionDao implements Dao { mapper(session).insert(newQualityGate.setCreatedAt(new Date())); } - public Collection<QualityGateConditionDto> selectForQualityGate(DbSession session, long qGateId) { - return mapper(session).selectForQualityGate(qGateId); + public Collection<QualityGateConditionDto> selectForQualityGate(DbSession session, String qGateUuid) { + return mapper(session).selectForQualityGate(qGateUuid); } public QualityGateConditionDto selectByUuid(String uuid, DbSession session) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java index ed191d46639..232c9ce2da2 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionDto.java @@ -33,7 +33,7 @@ public class QualityGateConditionDto { private String uuid; - private long qualityGateId; + private String qualityGateUuid; private String metricUuid; @@ -56,12 +56,12 @@ public class QualityGateConditionDto { return this; } - public long getQualityGateId() { - return qualityGateId; + public String getQualityGateUuid() { + return qualityGateUuid; } - public QualityGateConditionDto setQualityGateId(long qualityGateId) { - this.qualityGateId = qualityGateId; + public QualityGateConditionDto setQualityGateUuid(String qualityGateUuid) { + this.qualityGateUuid = qualityGateUuid; return this; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java index 0261c1a34fb..48fa5ab1ce6 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateConditionMapper.java @@ -25,7 +25,7 @@ public interface QualityGateConditionMapper { void insert(QualityGateConditionDto newCondition); - List<QualityGateConditionDto> selectForQualityGate(long qGateId); + List<QualityGateConditionDto> selectForQualityGate(String qGateUuid); void update(QualityGateConditionDto newCondition); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java index 02deb13e0ac..4daf6fd17fc 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDao.java @@ -22,6 +22,7 @@ package org.sonar.db.qualitygate; import java.util.Collection; import java.util.Date; import javax.annotation.CheckForNull; +import org.sonar.core.util.UuidFactory; import org.sonar.db.Dao; import org.sonar.db.DatabaseUtils; import org.sonar.db.DbSession; @@ -29,7 +30,14 @@ import org.sonar.db.organization.OrganizationDto; public class QualityGateDao implements Dao { + private final UuidFactory uuidFactory; + + public QualityGateDao(UuidFactory uuidFactory) { + this.uuidFactory = uuidFactory; + } + public QualityGateDto insert(DbSession session, QualityGateDto newQualityGate) { + newQualityGate.setUuid(uuidFactory.create()); mapper(session).insertQualityGate(newQualityGate.setCreatedAt(new Date())); return newQualityGate; @@ -49,11 +57,6 @@ public class QualityGateDao implements Dao { } @CheckForNull - public QualityGateDto selectById(DbSession session, long id) { - return mapper(session).selectById(id); - } - - @CheckForNull public QualityGateDto selectByUuid(DbSession session, String uuid) { return mapper(session).selectByUuid(uuid); } @@ -68,11 +71,6 @@ public class QualityGateDao implements Dao { return mapper(session).selectByNameAndOrganization(name, organization.getUuid()); } - @CheckForNull - public QGateWithOrgDto selectByOrganizationAndId(DbSession session, OrganizationDto organization, long id) { - return mapper(session).selectByIdAndOrganization(id, organization.getUuid()); - } - public QGateWithOrgDto selectDefault(DbSession dbSession, OrganizationDto organization) { return mapper(dbSession).selectDefault(organization.getUuid()); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDto.java index 137ef375d0c..4bf21b29ed0 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateDto.java @@ -26,7 +26,6 @@ import java.util.Date; */ public class QualityGateDto { - private Long id; private String name; private String uuid; private boolean isBuiltIn; @@ -42,15 +41,6 @@ public class QualityGateDto { return this; } - public Long getId() { - return id; - } - - public QualityGateDto setId(Long id) { - this.id = id; - return this; - } - public String getName() { return name; } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateMapper.java index 2741ab34989..b30c4c86cc9 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/qualitygate/QualityGateMapper.java @@ -33,14 +33,10 @@ public interface QualityGateMapper { QualityGateDto selectByName(String name); - QualityGateDto selectById(long id); - QGateWithOrgDto selectByUuidAndOrganization(@Param("qualityGateUuid") String qualityGateUuid, @Param("organizationUuid") String organizationUuid); QGateWithOrgDto selectByNameAndOrganization(@Param("name") String name, @Param("organizationUuid") String organizationUuid); - QGateWithOrgDto selectByIdAndOrganization(@Param("id") long id, @Param("organizationUuid") String organizationUuid); - QGateWithOrgDto selectDefault(@Param("organizationUuid") String organizationUuid); QualityGateDto selectBuiltIn(); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.xml index 1ce91b0da20..baa08b4dc62 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/ProjectQgateAssociationMapper.xml @@ -4,7 +4,7 @@ <mapper namespace="org.sonar.db.qualitygate.ProjectQgateAssociationMapper"> <select id="selectProjects" parameterType="map" resultType="ProjectQgateAssociation"> - SELECT proj.uuid as uuid, proj.kee as "key", proj.name as name, qg.id as gateId + SELECT proj.uuid as uuid, proj.kee as "key", proj.name as name, qg.uuid as gateUuid FROM components proj LEFT JOIN project_qgates prqg ON prqg.project_uuid=proj.uuid AND prqg.quality_gate_uuid = #{query.gateUuid, jdbcType=VARCHAR} LEFT JOIN quality_gates qg ON qg.uuid = prqg.quality_gate_uuid @@ -16,10 +16,10 @@ and proj.organization_uuid=#{query.organizationUuid, jdbcType=VARCHAR} <choose> <when test="query.membership() == 'selected'"> - and qg.id IS NOT NULL + and qg.uuid IS NOT NULL </when> <when test="query.membership() == 'deselected'"> - and qg.id IS NULL + and qg.uuid IS NULL </when> </choose> <if test="query.projectSearch() != null"> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml index 9f3da11eb10..2c57a73d936 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateConditionMapper.xml @@ -4,19 +4,19 @@ <mapper namespace="org.sonar.db.qualitygate.QualityGateConditionMapper"> <insert id="insert" parameterType="QualityGateCondition"> - insert into quality_gate_conditions (uuid, qgate_id, metric_uuid, operator, value_error, created_at, updated_at) - values (#{uuid}, #{qualityGateId}, #{metricUuid}, #{operator}, #{errorThreshold}, #{createdAt}, #{updatedAt}) + insert into quality_gate_conditions (uuid, qgate_uuid, metric_uuid, operator, value_error, created_at, updated_at) + values (#{uuid}, #{qualityGateUuid}, #{metricUuid}, #{operator}, #{errorThreshold}, #{createdAt}, #{updatedAt}) </insert> <sql id="conditionColumns"> - uuid, qgate_id as qualityGateId, metric_uuid as metricUuid, operator, value_error as errorThreshold, + uuid, qgate_uuid as qualityGateUuid, metric_uuid as metricUuid, operator, value_error as errorThreshold, created_at as createdAt, updated_at as updatedAt </sql> - <select id="selectForQualityGate" resultType="QualityGateCondition" parameterType="long"> + <select id="selectForQualityGate" resultType="QualityGateCondition" parameterType="String"> select <include refid="conditionColumns"/> - from quality_gate_conditions where qgate_id=#{qGateId} + from quality_gate_conditions where qgate_uuid=#{qGateUuid} order by created_at asc </select> diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml index 9fbedf68527..00c61babc89 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml @@ -4,11 +4,10 @@ <mapper namespace="org.sonar.db.qualitygate.QualityGateMapper"> <sql id="gateColumns"> - id, name, uuid, is_built_in as isBuiltIn, created_at as createdAt, updated_at as updatedAt + uuid, name, is_built_in as isBuiltIn, created_at as createdAt, updated_at as updatedAt </sql> <sql id="qateWithOrgColumns"> - qg.id as id, qg.uuid as uuid, qg.name as name, qg.is_built_in as isBuiltIn, @@ -17,7 +16,7 @@ qg.updated_at as updatedAd </sql> - <insert id="insertQualityGate" parameterType="QualityGate" keyColumn="id" useGeneratedKeys="true" keyProperty="id"> + <insert id="insertQualityGate" parameterType="QualityGate" useGeneratedKeys="false"> insert into quality_gates (uuid, name, is_built_in, created_at, updated_at) values (#{uuid, jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR}, #{isBuiltIn, jdbcType=BOOLEAN}, #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP}) </insert> @@ -72,17 +71,6 @@ qg.name = #{name, jdbcType=VARCHAR} </select> - <select id="selectByIdAndOrganization" parameterType="Map" 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 AND oqg.organization_uuid = #{organizationUuid, jdbcType=VARCHAR} - WHERE - qg.id = #{id, jdbcType=BIGINT} - </select> - <select id="selectByProjectUuid" parameterType="Map" resultType="org.sonar.db.qualitygate.QualityGateDto"> SELECT <include refid="gateColumns"/> @@ -92,13 +80,6 @@ project_qgates pqg ON pqg.quality_gate_uuid = qg.uuid AND pqg.project_uuid = #{projectUuid, jdbcType=VARCHAR} </select> - <select id="selectById" parameterType="long" resultType="QualityGate"> - select - <include refid="gateColumns"/> - from quality_gates - where id=#{id, jdbcType=BIGINT} - </select> - <select id="selectBuiltIn" resultType="org.sonar.db.qualitygate.QualityGateDto"> SELECT <include refid="gateColumns"/> diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 4712533869b..62d4ba46945 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -769,7 +769,6 @@ CREATE INDEX "QPROFILE_EDIT_USERS_QPROFILE" ON "QPROFILE_EDIT_USERS"("QPROFILE_U CREATE UNIQUE INDEX "QPROFILE_EDIT_USERS_UNIQUE" ON "QPROFILE_EDIT_USERS"("USER_ID", "QPROFILE_UUID"); CREATE TABLE "QUALITY_GATE_CONDITIONS"( - "QGATE_ID" INTEGER, "PERIOD" INTEGER, "OPERATOR" VARCHAR(3), "VALUE_ERROR" VARCHAR(64), @@ -777,20 +776,19 @@ CREATE TABLE "QUALITY_GATE_CONDITIONS"( "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP, "UUID" VARCHAR(40) NOT NULL, - "METRIC_UUID" VARCHAR(40) NOT NULL + "METRIC_UUID" VARCHAR(40) NOT NULL, + "QGATE_UUID" VARCHAR(40) NOT NULL ); ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("UUID"); CREATE TABLE "QUALITY_GATES"( - "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), "UUID" VARCHAR(40) NOT NULL, "NAME" VARCHAR(100) NOT NULL, "IS_BUILT_IN" BOOLEAN NOT NULL, "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP ); -ALTER TABLE "QUALITY_GATES" ADD CONSTRAINT "PK_QUALITY_GATES" PRIMARY KEY("ID"); -CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES_UUID" ON "QUALITY_GATES"("UUID"); +ALTER TABLE "QUALITY_GATES" ADD CONSTRAINT "PK_QUALITY_GATES" PRIMARY KEY("UUID"); CREATE TABLE "RULE_REPOSITORIES"( "KEE" VARCHAR(200) NOT NULL, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java index bf51a18a519..890b72652cc 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java @@ -57,10 +57,10 @@ public class ProjectQgateAssociationDaoTest { .build()); assertThat(result) - .extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getKey, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateId) + .extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getKey, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateUuid) .containsExactlyInAnyOrder( - tuple(project1.uuid(), project1.getKey(), project1.name(), qualityGate1.getId().toString()), - tuple(project2.uuid(), project2.getKey(), project2.name(), qualityGate1.getId().toString()), + tuple(project1.uuid(), project1.getKey(), project1.name(), qualityGate1.getUuid()), + tuple(project2.uuid(), project2.getKey(), project2.name(), qualityGate1.getUuid()), tuple(project3.uuid(), project3.getKey(), project3.name(), null)); } @@ -78,16 +78,16 @@ public class ProjectQgateAssociationDaoTest { .qualityGate(qualityGate) .membership(ProjectQgateAssociationQuery.IN) .build())) - .extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateId) + .extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateUuid) .containsExactlyInAnyOrder( - tuple(project1.uuid(), project1.name(), qualityGate.getId().toString()), - tuple(project2.uuid(), project2.name(), qualityGate.getId().toString())); + tuple(project1.uuid(), project1.name(), qualityGate.getUuid()), + tuple(project2.uuid(), project2.name(), qualityGate.getUuid())); assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder() .qualityGate(qualityGate) .membership(ProjectQgateAssociationQuery.OUT) .build())) - .extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateId) + .extracting(ProjectQgateAssociationDto::getUuid, ProjectQgateAssociationDto::getName, ProjectQgateAssociationDto::getGateUuid) .containsExactlyInAnyOrder(tuple(project3.uuid(), project3.name(), null)); } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java index 3c94e1d57d3..07acebe1be8 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java @@ -44,7 +44,7 @@ public class QualityGateConditionDaoTest { @Test public void testInsert() { - QualityGateConditionDto newCondition = insertQGCondition(1L, "2", "GT", "20"); + QualityGateConditionDto newCondition = insertQGCondition("1", "2", "GT", "20"); assertThat(newCondition.getUuid()).isNotNull(); QualityGateConditionDto actual = underTest.selectByUuid(newCondition.getUuid(), dbSession); @@ -53,15 +53,15 @@ public class QualityGateConditionDaoTest { @Test public void testSelectForQualityGate() { - long qg1Id = 1L; - long qg2Id = 2L; + String qg1Uuid = "1"; + String qg2Uuid = "2"; int qg1Conditions = 2 + new Random().nextInt(5); int qg2Conditions = 10 + new Random().nextInt(5); - IntStream.range(0, qg1Conditions).forEach(i -> insertQGCondition(qg1Id)); - IntStream.range(0, qg2Conditions).forEach(i -> insertQGCondition(qg2Id)); + IntStream.range(0, qg1Conditions).forEach(i -> insertQGCondition(qg1Uuid)); + IntStream.range(0, qg2Conditions).forEach(i -> insertQGCondition(qg2Uuid)); - Collection<QualityGateConditionDto> conditions = underTest.selectForQualityGate(dbSession, qg1Id); + Collection<QualityGateConditionDto> conditions = underTest.selectForQualityGate(dbSession, qg1Uuid); assertThat(conditions).hasSize(qg1Conditions); assertThat(conditions) .extracting("uuid") @@ -69,7 +69,7 @@ public class QualityGateConditionDaoTest { .sorted(Comparator.comparing(QualityGateConditionDto::getCreatedAt)) .map(QualityGateConditionDto::getUuid).toArray()); - conditions = underTest.selectForQualityGate(dbSession, qg2Id); + conditions = underTest.selectForQualityGate(dbSession, qg2Uuid); assertThat(conditions).hasSize(qg2Conditions); assertThat(conditions) .extracting("uuid") @@ -78,12 +78,12 @@ public class QualityGateConditionDaoTest { .map(QualityGateConditionDto::getUuid) .toArray()); - assertThat(underTest.selectForQualityGate(dbSession, 5)).isEmpty(); + assertThat(underTest.selectForQualityGate(dbSession, "5")).isEmpty(); } @Test public void testSelectByUuid() { - QualityGateConditionDto condition = insertQGCondition(1L, "2", "GT", "20"); + QualityGateConditionDto condition = insertQGCondition("1", "2", "GT", "20"); assertEquals(underTest.selectByUuid(condition.getUuid(), dbSession), condition); assertThat(underTest.selectByUuid("uuid1", dbSession)).isNull(); @@ -91,8 +91,8 @@ public class QualityGateConditionDaoTest { @Test public void testDelete() { - QualityGateConditionDto condition1 = insertQGCondition(2L); - QualityGateConditionDto condition2 = insertQGCondition(3L); + QualityGateConditionDto condition1 = insertQGCondition("2"); + QualityGateConditionDto condition2 = insertQGCondition("3"); underTest.delete(condition1, dbSession); dbSession.commit(); @@ -103,12 +103,12 @@ public class QualityGateConditionDaoTest { @Test public void testUpdate() { - QualityGateConditionDto condition1 = insertQGCondition(2L); - QualityGateConditionDto condition2 = insertQGCondition(3L); + QualityGateConditionDto condition1 = insertQGCondition("2"); + QualityGateConditionDto condition2 = insertQGCondition("3"); QualityGateConditionDto newCondition1 = new QualityGateConditionDto() .setUuid(condition1.getUuid()) - .setQualityGateId(condition1.getQualityGateId()) + .setQualityGateUuid(condition1.getQualityGateUuid()) .setMetricUuid("7") .setOperator(">") .setErrorThreshold("80"); @@ -124,9 +124,9 @@ public class QualityGateConditionDaoTest { public void shouldCleanConditions() { MetricDto enabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(true)); MetricDto disabledMetric = dbTester.measures().insertMetric(t -> t.setEnabled(false)); - QualityGateConditionDto condition1 = insertQGCondition(1L, enabledMetric.getUuid()); - QualityGateConditionDto condition2 = insertQGCondition(1L, disabledMetric.getUuid()); - QualityGateConditionDto condition3 = insertQGCondition(1L, "299"); + QualityGateConditionDto condition1 = insertQGCondition("1", enabledMetric.getUuid()); + QualityGateConditionDto condition2 = insertQGCondition("1", disabledMetric.getUuid()); + QualityGateConditionDto condition3 = insertQGCondition("1", "299"); underTest.deleteConditionsWithInvalidMetrics(dbTester.getSession()); dbTester.commit(); @@ -137,18 +137,18 @@ public class QualityGateConditionDaoTest { assertThat(underTest.selectByUuid(condition3.getUuid(), dbSession)).isNull(); } - private QualityGateConditionDto insertQGCondition(long qualityGateId) { - return insertQGCondition(qualityGateId, randomAlphabetic(2)); + private QualityGateConditionDto insertQGCondition(String qualityGateUuid) { + return insertQGCondition(qualityGateUuid, randomAlphabetic(2)); } - private QualityGateConditionDto insertQGCondition(long qualityGateId, String metricUuid) { - return insertQGCondition(qualityGateId, metricUuid, randomAlphabetic(2), randomAlphabetic(3)); + private QualityGateConditionDto insertQGCondition(String qualityGateUuid, String metricUuid) { + return insertQGCondition(qualityGateUuid, metricUuid, randomAlphabetic(2), randomAlphabetic(3)); } - private QualityGateConditionDto insertQGCondition(long qualityGateId, String metricUuid, String operator, String threshold) { + private QualityGateConditionDto insertQGCondition(String qualityGateUuid, String metricUuid, String operator, String threshold) { QualityGateConditionDto res = new QualityGateConditionDto() .setUuid(Uuids.create()) - .setQualityGateId(qualityGateId) + .setQualityGateUuid(qualityGateUuid) .setMetricUuid(metricUuid) .setOperator(operator) .setErrorThreshold(threshold); @@ -158,7 +158,7 @@ public class QualityGateConditionDaoTest { } private void assertEquals(QualityGateConditionDto actual, QualityGateConditionDto expected) { - assertThat(actual.getQualityGateId()).isEqualTo(expected.getQualityGateId()); + assertThat(actual.getQualityGateUuid()).isEqualTo(expected.getQualityGateUuid()); assertThat(actual.getMetricUuid()).isEqualTo(expected.getMetricUuid()); assertThat(actual.getOperator()).isEqualTo(expected.getOperator()); assertThat(actual.getErrorThreshold()).isEqualTo(expected.getErrorThreshold()); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java index f9a502dcc6f..c79b7709359 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java @@ -54,7 +54,7 @@ public class QualityGateDaoTest { underTest.insert(dbSession, newQgate); dbSession.commit(); - QualityGateDto reloaded = underTest.selectById(dbSession, newQgate.getId()); + QualityGateDto reloaded = underTest.selectByUuid(dbSession, newQgate.getUuid()); assertThat(reloaded.getName()).isEqualTo("My Quality Gate"); assertThat(reloaded.getUuid()).isEqualTo(newQgate.getUuid()); assertThat(reloaded.isBuiltIn()).isFalse(); @@ -71,8 +71,8 @@ public class QualityGateDaoTest { assertThat(underTest.selectByOrganizationAndUuid(dbSession, org, qgate.getUuid())).isNotNull(); assertThat(underTest.selectByOrganizationAndUuid(dbSession, org, qgate.getUuid())) - .extracting(QGateWithOrgDto::getId, QGateWithOrgDto::getUuid, QGateWithOrgDto::getOrganizationUuid, QGateWithOrgDto::getName) - .containsExactly(qgate.getId(), qgate.getUuid(), org.getUuid(), qgate.getName()); + .extracting(QGateWithOrgDto::getUuid, QGateWithOrgDto::getUuid, QGateWithOrgDto::getOrganizationUuid, QGateWithOrgDto::getName) + .containsExactly(qgate.getUuid(), qgate.getUuid(), org.getUuid(), qgate.getName()); } @Test @@ -107,8 +107,8 @@ public class QualityGateDaoTest { @Test public void testSelectById() { insertQualityGates(); - assertThat(underTest.selectById(dbSession, underTest.selectByName(dbSession, "Very strict").getId()).getName()).isEqualTo("Very strict"); - assertThat(underTest.selectById(dbSession, -1L)).isNull(); + assertThat(underTest.selectByUuid(dbSession, underTest.selectByName(dbSession, "Very strict").getUuid()).getName()).isEqualTo("Very strict"); + assertThat(underTest.selectByUuid(dbSession, "-1")).isNull(); } @Test @@ -151,9 +151,9 @@ public class QualityGateDaoTest { OrganizationDto otherOrganization = db.organizations().insert(); QGateWithOrgDto qualityGate3 = db.qualityGates().insertQualityGate(otherOrganization); - assertThat(underTest.selectByOrganizationAndId(dbSession, organization, qualityGate1.getId()).getUuid()).isEqualTo(qualityGate1.getUuid()); - assertThat(underTest.selectByOrganizationAndId(dbSession, otherOrganization, qualityGate3.getId()).getUuid()).isEqualTo(qualityGate3.getUuid()); - assertThat(underTest.selectByOrganizationAndId(dbSession, organization, 123L)).isNull(); + assertThat(underTest.selectByOrganizationAndUuid(dbSession, organization, qualityGate1.getUuid()).getUuid()).isEqualTo(qualityGate1.getUuid()); + assertThat(underTest.selectByOrganizationAndUuid(dbSession, otherOrganization, qualityGate3.getUuid()).getUuid()).isEqualTo(qualityGate3.getUuid()); + assertThat(underTest.selectByOrganizationAndUuid(dbSession, organization, "123")).isNull(); } @Test diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java index 68150491124..7008054b1e1 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/qualitygate/QualityGateDbTester.java @@ -93,7 +93,7 @@ public class QualityGateDbTester { @SafeVarargs public final QualityGateConditionDto addCondition(QualityGateDto qualityGate, MetricDto metric, Consumer<QualityGateConditionDto>... dtoPopulators) { - QualityGateConditionDto condition = new QualityGateConditionDto().setQualityGateId(qualityGate.getId()) + QualityGateConditionDto condition = new QualityGateConditionDto().setQualityGateUuid(qualityGate.getUuid()) .setUuid(Uuids.createFast()) .setMetricUuid(metric.getUuid()) .setOperator("GT") diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java index 61d4f7c48a6..a4b69bca187 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/DbVersion83.java @@ -212,6 +212,15 @@ import org.sonar.server.platform.db.migration.version.v83.qualitygateconditions. import org.sonar.server.platform.db.migration.version.v83.qualitygateconditions.DropPrimaryKeyOnIdColumnOfQualityGateConditionsTable; import org.sonar.server.platform.db.migration.version.v83.qualitygateconditions.MakeQualityGateConditionsUuidColumnNotNullable; import org.sonar.server.platform.db.migration.version.v83.qualitygateconditions.PopulateQualityGateConditionsUuid; +import org.sonar.server.platform.db.migration.version.v83.qualitygates.AddPrimaryKeyOnUuidColumnOfQGatesTable; +import org.sonar.server.platform.db.migration.version.v83.qualitygates.AddQGateUuidColumnForQGateConditions; +import org.sonar.server.platform.db.migration.version.v83.qualitygates.DropIdColumnOfQGateTable; +import org.sonar.server.platform.db.migration.version.v83.qualitygates.DropOrphansQGateConditions; +import org.sonar.server.platform.db.migration.version.v83.qualitygates.DropPrimaryKeyOnIdColumnOfQGatesTable; +import org.sonar.server.platform.db.migration.version.v83.qualitygates.DropQGateIdColumnForQGateConditions; +import org.sonar.server.platform.db.migration.version.v83.qualitygates.DropUniqueIndexOnUuidColumnOfQualityGatesTable; +import org.sonar.server.platform.db.migration.version.v83.qualitygates.MakeQGateUuidColumnNotNullableForQGateConditions; +import org.sonar.server.platform.db.migration.version.v83.qualitygates.PopulateQGateUuidColumnForQGateConditions; import org.sonar.server.platform.db.migration.version.v83.rulesparameters.AddPrimaryKeyOnUuidColumnOfRulesParametersTable; import org.sonar.server.platform.db.migration.version.v83.rulesparameters.AddUuidColumnToRulesParameters; import org.sonar.server.platform.db.migration.version.v83.rulesparameters.DropIdColumnOfRulesParametersTable; @@ -606,6 +615,19 @@ public class DbVersion83 implements DbVersion { .add(3624, "Drop column 'group_id' of 'QPROFILE_EDIT_GROUPS' table", DropGroupIdColumnOfQProfileEditGroupsTable.class) .add(3625, "Drop column 'ID' of 'GROUPS' table", DropIdColumnOfGroupsTable.class) + // Migration of QUALITY_GATES_CONDITIONS FK to QUALITY_GATES, switch from qgate_id to qgate_uuid + .add(3626, "Add 'qgate_uuid' column for quality gates conditions", AddQGateUuidColumnForQGateConditions.class) + .add(3627, "Populate 'qgate_uuid' column for quality gates conditions", PopulateQGateUuidColumnForQGateConditions.class) + .add(3628, "drop orphans quality gates conditions", DropOrphansQGateConditions.class) + .add(3629, "Make 'qgate_uuid' column not nullable for quality gates conditions", MakeQGateUuidColumnNotNullableForQGateConditions.class) + .add(3630, "Drop 'qgate_id' column for quality gates conditions", DropQGateIdColumnForQGateConditions.class) + + // Migrations of QUALITY_GATES table + .add(3631, "Drop primary key on 'ID' column of 'QUALITY_GATES' table", DropPrimaryKeyOnIdColumnOfQGatesTable.class) + .add(3632, "drop unique index on 'UUID' column of 'QUALITY_GATES' table", DropUniqueIndexOnUuidColumnOfQualityGatesTable.class) + .add(3633, "Add primary key on 'UUID' column of 'QUALITY_GATES' table", AddPrimaryKeyOnUuidColumnOfQGatesTable.class) + .add(3634, "Drop column 'ID' of 'QUALITY_GATES' table", DropIdColumnOfQGateTable.class) + ; } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddPrimaryKeyOnUuidColumnOfQGatesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddPrimaryKeyOnUuidColumnOfQGatesTable.java new file mode 100644 index 00000000000..39f3a387b03 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddPrimaryKeyOnUuidColumnOfQGatesTable.java @@ -0,0 +1,38 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.version.v83.util.AddPrimaryKeyBuilder; + +public class AddPrimaryKeyOnUuidColumnOfQGatesTable extends DdlChange { + + public AddPrimaryKeyOnUuidColumnOfQGatesTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddPrimaryKeyBuilder("quality_gates", "uuid").build()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddQGateUuidColumnForQGateConditions.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddQGateUuidColumnForQGateConditions.java new file mode 100644 index 00000000000..25d0e2a4818 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddQGateUuidColumnForQGateConditions.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; +import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; +import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class AddQGateUuidColumnForQGateConditions extends DdlChange { + private static final String TABLE = "quality_gate_conditions"; + + private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder() + .setColumnName("qgate_uuid") + .setIsNullable(true) + .setDefaultValue(null) + .setLimit(VarcharColumnDef.UUID_SIZE) + .build(); + + public AddQGateUuidColumnForQGateConditions(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddColumnsBuilder(getDialect(), TABLE) + .addColumn(uuidColumnDefinition) + .build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropIdColumnOfQGateTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropIdColumnOfQGateTable.java new file mode 100644 index 00000000000..852d20f9ca8 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropIdColumnOfQGateTable.java @@ -0,0 +1,31 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.version.v83.common.DropIdColumn; + +public class DropIdColumnOfQGateTable extends DropIdColumn { + private static final String TABLE = "quality_gates"; + + public DropIdColumnOfQGateTable(Database db) { + super(db, TABLE); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropOrphansQGateConditions.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropOrphansQGateConditions.java new file mode 100644 index 00000000000..829d5da8058 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropOrphansQGateConditions.java @@ -0,0 +1,45 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DataChange; +import org.sonar.server.platform.db.migration.step.MassUpdate; + +public class DropOrphansQGateConditions extends DataChange { + + public DropOrphansQGateConditions(Database db) { + super(db); + } + + @Override + protected void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + + massUpdate.select("select uuid from quality_gate_conditions where qgate_uuid is null"); + massUpdate.update("delete from quality_gate_conditions where uuid = ?"); + + massUpdate.execute((row, update) -> { + update.setString(1, row.getString(1)); + return true; + }); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTable.java new file mode 100644 index 00000000000..a74f42db3ff --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTable.java @@ -0,0 +1,34 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.version.v83.common.DropPrimaryKeyOnIdColumn; +import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator; + +public class DropPrimaryKeyOnIdColumnOfQGatesTable extends DropPrimaryKeyOnIdColumn { + + private static final String TABLE_NAME = "quality_gates"; + + public DropPrimaryKeyOnIdColumnOfQGatesTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) { + super(db, dropPrimaryKeySqlGenerator, TABLE_NAME); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropQGateIdColumnForQGateConditions.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropQGateIdColumnForQGateConditions.java new file mode 100644 index 00000000000..a0a4ee4e81b --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropQGateIdColumnForQGateConditions.java @@ -0,0 +1,41 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropQGateIdColumnForQGateConditions extends DdlChange { + + private Database db; + + public DropQGateIdColumnForQGateConditions(Database db) { + super(db); + this.db = db; + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropColumnsBuilder(db.getDialect(), "quality_gate_conditions", "qgate_id").build()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropUniqueIndexOnUuidColumnOfQualityGatesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropUniqueIndexOnUuidColumnOfQualityGatesTable.java new file mode 100644 index 00000000000..d1064194296 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropUniqueIndexOnUuidColumnOfQualityGatesTable.java @@ -0,0 +1,40 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.sql.DropIndexBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class DropUniqueIndexOnUuidColumnOfQualityGatesTable extends DdlChange { + + public DropUniqueIndexOnUuidColumnOfQualityGatesTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new DropIndexBuilder(getDialect()) + .setTable("quality_gates") + .setName("uniq_quality_gates_uuid") + .build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/MakeQGateUuidColumnNotNullableForQGateConditions.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/MakeQGateUuidColumnNotNullableForQGateConditions.java new file mode 100644 index 00000000000..2405199c9da --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/MakeQGateUuidColumnNotNullableForQGateConditions.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; +import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; + +public class MakeQGateUuidColumnNotNullableForQGateConditions extends DdlChange { + private static final String TABLE = "quality_gate_conditions"; + + private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder() + .setColumnName("qgate_uuid") + .setIsNullable(false) + .setDefaultValue(null) + .setLimit(VarcharColumnDef.UUID_SIZE) + .build(); + + public MakeQGateUuidColumnNotNullableForQGateConditions(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AlterColumnsBuilder(getDialect(), TABLE) + .updateColumn(uuidColumnDefinition) + .build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/PopulateQGateUuidColumnForQGateConditions.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/PopulateQGateUuidColumnForQGateConditions.java new file mode 100644 index 00000000000..878309dc341 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/PopulateQGateUuidColumnForQGateConditions.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DataChange; +import org.sonar.server.platform.db.migration.step.MassUpdate; + +public class PopulateQGateUuidColumnForQGateConditions extends DataChange { + + public PopulateQGateUuidColumnForQGateConditions(Database db) { + super(db); + } + + @Override + protected void execute(Context context) throws SQLException { + MassUpdate massUpdate = context.prepareMassUpdate(); + + massUpdate.select("select uuid, id from quality_gates order by id asc"); + massUpdate.update("update quality_gate_conditions set qgate_uuid = ? where qgate_id = ? and qgate_uuid is null"); + + massUpdate.execute((row, update) -> { + update.setString(1, row.getString(1)); + update.setLong(2, row.getLong(2)); + return true; + }); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTableTest.java index 6cc178569c3..8bc1e3fb106 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RemoveDefaultQualityGateFromPropertiesTableTest.java @@ -38,12 +38,12 @@ public class RemoveDefaultQualityGateFromPropertiesTableTest { @Rule public ExpectedException expectedException = ExpectedException.none(); - private RemoveDefaultQualityGateFromPropertiesTable underTest = new RemoveDefaultQualityGateFromPropertiesTable(dbTester.database()); + private final RemoveDefaultQualityGateFromPropertiesTable underTest = new RemoveDefaultQualityGateFromPropertiesTable(dbTester.database()); @Test public void remove_default_quality_gate_property() throws SQLException { for (long i = 1; i <= TOTAL_NUMBER_OF_PROPERTIES; i++) { - insertQualityGateProperty(i, i + 100); + insertQualityGateProperty(i, String.valueOf(i + 100)); } int propertiesCount = dbTester.countRowsOfTable(PROPERTIES_TABLE_NAME); @@ -59,12 +59,12 @@ public class RemoveDefaultQualityGateFromPropertiesTableTest { underTest.execute(); } - private void insertQualityGateProperty(Long projectId, Long qualityGateId) { + private void insertQualityGateProperty(Long projectId, String qualityGateUuid) { dbTester.executeInsert(PROPERTIES_TABLE_NAME, "prop_key", "sonar.qualitygate", "resource_id", projectId, "is_empty", false, - "text_value", Long.toString(qualityGateId), + "text_value", qualityGateUuid, "created_at", Instant.now().toEpochMilli()); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RemoveLeakPeriodPropertiesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RemoveLeakPeriodPropertiesTest.java index 40209e974a5..a1980e73bcb 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RemoveLeakPeriodPropertiesTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/RemoveLeakPeriodPropertiesTest.java @@ -42,7 +42,7 @@ public class RemoveLeakPeriodPropertiesTest { @Test public void remove_default_quality_gate_property() throws SQLException { for (long i = 1; i <= TOTAL_NUMBER_OF_PROPERTIES; i++) { - insertQualityGateProperty(i, i + 100); + insertQualityGateProperty(i, String.valueOf(i + 100)); } int propertiesCount = dbTester.countRowsOfTable(PROPERTIES_TABLE_NAME); @@ -58,12 +58,12 @@ public class RemoveLeakPeriodPropertiesTest { underTest.execute(); } - private void insertQualityGateProperty(Long projectId, Long qualityGateId) { + private void insertQualityGateProperty(Long projectId, String qualityGateUuid) { dbTester.executeInsert(PROPERTIES_TABLE_NAME, "prop_key", "sonar.leak.period", "resource_id", projectId, "is_empty", false, - "text_value", Long.toString(qualityGateId), + "text_value", qualityGateUuid, "created_at", Instant.now().toEpochMilli()); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddPrimaryKeyOnUuidColumnOfQGatesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddPrimaryKeyOnUuidColumnOfQGatesTableTest.java new file mode 100644 index 00000000000..7867c745cc6 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddPrimaryKeyOnUuidColumnOfQGatesTableTest.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class AddPrimaryKeyOnUuidColumnOfQGatesTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfQGatesTableTest.class, "schema.sql"); + + private MigrationStep underTest = new AddPrimaryKeyOnUuidColumnOfQGatesTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertPrimaryKey("quality_gates", "pk_quality_gates", "uuid"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddQGateUuidColumnForQGateConditionsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddQGateUuidColumnForQGateConditionsTest.java new file mode 100644 index 00000000000..1a0c67ad667 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddQGateUuidColumnForQGateConditionsTest.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import java.sql.Types; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class AddQGateUuidColumnForQGateConditionsTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(AddQGateUuidColumnForQGateConditionsTest.class, "schema.sql"); + + private MigrationStep underTest = new AddQGateUuidColumnForQGateConditions(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition("quality_gate_conditions", "qgate_uuid", Types.VARCHAR, 40, true); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropIdColumnOfQGateTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropIdColumnOfQGateTableTest.java new file mode 100644 index 00000000000..bd52e1c149b --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropIdColumnOfQGateTableTest.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class DropIdColumnOfQGateTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfQGateTableTest.class, "schema.sql"); + + private MigrationStep underTest = new DropIdColumnOfQGateTable(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertColumnDoesNotExist("quality_gates", "id"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropOrphansQGateConditionsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropOrphansQGateConditionsTest.java new file mode 100644 index 00000000000..3d4a6ae12ce --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropOrphansQGateConditionsTest.java @@ -0,0 +1,73 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import java.util.stream.Collectors; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DropOrphansQGateConditionsTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropOrphansQGateConditionsTest.class, "schema.sql"); + + private MigrationStep underTest = new DropOrphansQGateConditions(db.database()); + + @Test + public void deleteOrphanQGConditions() throws SQLException { + insertQualityGate(1L, "uuid1", "qualityGate1"); + insertQualityGateCondition("condition_uuid_1", "uuid1"); + insertQualityGateCondition("condition_uuid_2", "uuid1"); + insertQualityGateCondition("condition_uuid_3", null); + + underTest.execute(); + + verifyConditionExist("condition_uuid_1", true); + verifyConditionExist("condition_uuid_2", true); + verifyConditionExist("condition_uuid_3", false); + } + + private void verifyConditionExist(String uuid, boolean exist) { + assertThat(db.select("select count(uuid) as C from quality_gate_conditions where uuid='" + uuid + "'") + .stream() + .map(row -> (Long) row.get("C")) + .collect(Collectors.toList())).containsOnly(exist ? 1L : 0L); + } + + private void insertQualityGate(Long id, String uuid, String name) { + db.executeInsert("quality_gates", + "id", id, + "uuid", uuid, + "name", name, + "is_built_in", true); + } + + private void insertQualityGateCondition(String uuid, String qualityGateUuid) { + db.executeInsert("quality_gate_conditions", + "uuid", uuid, + "qgate_uuid", qualityGateUuid); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTableTest.java new file mode 100644 index 00000000000..e01cb8885d8 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTableTest.java @@ -0,0 +1,56 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; +import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator; +import org.sonar.server.platform.db.migration.version.v83.util.SqlHelper; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class DropPrimaryKeyOnIdColumnOfQGatesTableTest { + + private static final String TABLE_NAME = "quality_gates"; + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfQGatesTableTest.class, "schema.sql"); + + private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database())); + + private MigrationStep underTest = new DropPrimaryKeyOnIdColumnOfQGatesTable(db.database(), dropPrimaryKeySqlGenerator); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertNoPrimaryKey(TABLE_NAME); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropQGateIdColumnForQGateConditionsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropQGateIdColumnForQGateConditionsTest.java new file mode 100644 index 00000000000..d086bca98c0 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropQGateIdColumnForQGateConditionsTest.java @@ -0,0 +1,52 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; +import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator; +import org.sonar.server.platform.db.migration.version.v83.util.SqlHelper; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class DropQGateIdColumnForQGateConditionsTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropQGateIdColumnForQGateConditionsTest.class, "schema.sql"); + + private MigrationStep underTest = new DropQGateIdColumnForQGateConditions(db.database()); + + @Test + public void execute() throws SQLException { + underTest.execute(); + + db.assertColumnDoesNotExist("quality_gate_conditions", "qgate_id"); + } + + @Test + public void migration_is_not_re_entrant() throws SQLException { + underTest.execute(); + + assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropUniqueIndexOnUuidColumnOfQualityGatesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropUniqueIndexOnUuidColumnOfQualityGatesTableTest.java new file mode 100644 index 00000000000..d3837c5ce1b --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropUniqueIndexOnUuidColumnOfQualityGatesTableTest.java @@ -0,0 +1,43 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +public class DropUniqueIndexOnUuidColumnOfQualityGatesTableTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(DropUniqueIndexOnUuidColumnOfQualityGatesTableTest.class, "schema.sql"); + + private MigrationStep underTest = new DropUniqueIndexOnUuidColumnOfQualityGatesTable(db.database()); + + @Test + public void execute_drop_index() throws SQLException { + db.assertUniqueIndex("quality_gates", "uniq_quality_gates_uuid", "uuid"); + + underTest.execute(); + + db.assertIndexDoesNotExist("quality_gates", "uniq_quality_gates_uuid"); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/MakeQGateUuidColumnNotNullableForQGateConditionsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/MakeQGateUuidColumnNotNullableForQGateConditionsTest.java new file mode 100644 index 00000000000..0b403d923f0 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/MakeQGateUuidColumnNotNullableForQGateConditionsTest.java @@ -0,0 +1,43 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.MigrationStep; + +import static java.sql.Types.VARCHAR; + +public class MakeQGateUuidColumnNotNullableForQGateConditionsTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(MakeQGateUuidColumnNotNullableForQGateConditionsTest.class, "schema.sql"); + + private MigrationStep underTest = new MakeQGateUuidColumnNotNullableForQGateConditions(db.database()); + + @Test + public void created_at_and_uuid_columns_are_not_null() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition("quality_gate_conditions", "qgate_uuid", VARCHAR, null, false); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/PopulateQGateUuidColumnForQGateConditionsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/PopulateQGateUuidColumnForQGateConditionsTest.java new file mode 100644 index 00000000000..26e9da4e67f --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/qualitygates/PopulateQGateUuidColumnForQGateConditionsTest.java @@ -0,0 +1,93 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.v83.qualitygates; + +import java.sql.SQLException; +import java.util.stream.Collectors; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DataChange; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PopulateQGateUuidColumnForQGateConditionsTest { + + @Rule + public CoreDbTester db = CoreDbTester.createForSchema(PopulateQGateUuidColumnForQGateConditionsTest.class, "schema.sql"); + + private DataChange underTest = new PopulateQGateUuidColumnForQGateConditions(db.database()); + + @Test + public void populate_qgate_uuids() throws SQLException { + insertQualityGate(1L, "uuid1", "qualityGate1"); + insertQualityGate(2L, "uuid2", "qualityGate2"); + insertQualityGate(3L, "uuid3", "qualityGate3"); + insertQualityGateCondition("condition_uuid_1", "uuid1"); + insertQualityGateCondition("condition_uuid_2", "uuid1"); + insertQualityGateCondition("condition_uuid_3", "uuid2"); + + underTest.execute(); + + verifyUuid("condition_uuid_1", "uuid1"); + verifyUuid("condition_uuid_2", "uuid1"); + verifyUuid("condition_uuid_3", "uuid2"); + } + + @Test + public void migration_is_reentrant() throws SQLException { + insertQualityGate(1L, "uuid1", "qualityGate1"); + insertQualityGate(2L, "uuid2", "qualityGate2"); + insertQualityGate(3L, "uuid3", "qualityGate3"); + insertQualityGateCondition("condition_uuid_1", "uuid1"); + insertQualityGateCondition("condition_uuid_2", "uuid1"); + insertQualityGateCondition("condition_uuid_3", "uuid2"); + + underTest.execute(); + // re-entrant + underTest.execute(); + + verifyUuid("condition_uuid_1", "uuid1"); + verifyUuid("condition_uuid_2", "uuid1"); + verifyUuid("condition_uuid_3", "uuid2"); + } + + private void verifyUuid(String conditionUuid, String expectedUuid) { + assertThat(db.select("select QGATE_UUID from quality_gate_conditions where uuid='" + conditionUuid+"'") + .stream() + .map(row -> row.get("QGATE_UUID")) + .collect(Collectors.toList())).containsOnly(expectedUuid); + } + + private void insertQualityGate(Long id, String uuid, String name) { + db.executeInsert("quality_gates", + "id", id, + "uuid", uuid, + "name", name, + "is_built_in", true); + } + + private void insertQualityGateCondition(String uuid, String qualityGateUuid) { + db.executeInsert("quality_gate_conditions", + "uuid", uuid, + "qgate_uuid", qualityGateUuid); + } + +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddPrimaryKeyOnUuidColumnOfQGatesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddPrimaryKeyOnUuidColumnOfQGatesTableTest/schema.sql new file mode 100644 index 00000000000..11efefb9936 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddPrimaryKeyOnUuidColumnOfQGatesTableTest/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "QUALITY_GATES"( + "ID" INTEGER NOT NULL, + "UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(100) NOT NULL, + "IS_BUILT_IN" BOOLEAN NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES_UUID" ON "QUALITY_GATES"("UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddQGateUuidColumnForQGateConditionsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddQGateUuidColumnForQGateConditionsTest/schema.sql new file mode 100644 index 00000000000..00b6663de81 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/AddQGateUuidColumnForQGateConditionsTest/schema.sql @@ -0,0 +1,23 @@ +CREATE TABLE "QUALITY_GATE_CONDITIONS"( + "QGATE_ID" INTEGER, + "METRIC_ID" INTEGER, + "PERIOD" INTEGER, + "OPERATOR" VARCHAR(3), + "VALUE_ERROR" VARCHAR(64), + "VALUE_WARNING" VARCHAR(64), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP, + "UUID" VARCHAR(40) NOT NULL +); +ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("UUID"); + +CREATE TABLE "QUALITY_GATES"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(100) NOT NULL, + "IS_BUILT_IN" BOOLEAN NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "QUALITY_GATES" ADD CONSTRAINT "PK_QUALITY_GATES" PRIMARY KEY("ID"); +CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES_UUID" ON "QUALITY_GATES"("UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropIdColumnOfQGateTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropIdColumnOfQGateTableTest/schema.sql new file mode 100644 index 00000000000..dfcae5380ea --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropIdColumnOfQGateTableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "QUALITY_GATES"( + "ID" INTEGER NOT NULL, + "UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(100) NOT NULL, + "IS_BUILT_IN" BOOLEAN NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "QUALITY_GATES" ADD CONSTRAINT "PK_QUALITY_GATES" PRIMARY KEY("UUID"); + diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropOrphansQGateConditionsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropOrphansQGateConditionsTest/schema.sql new file mode 100644 index 00000000000..497d17eddf5 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropOrphansQGateConditionsTest/schema.sql @@ -0,0 +1,24 @@ +CREATE TABLE "QUALITY_GATE_CONDITIONS"( + "QGATE_ID" INTEGER, + "QGATE_UUID" VARCHAR(40), + "METRIC_ID" INTEGER, + "PERIOD" INTEGER, + "OPERATOR" VARCHAR(3), + "VALUE_ERROR" VARCHAR(64), + "VALUE_WARNING" VARCHAR(64), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP, + "UUID" VARCHAR(40) NOT NULL +); +ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("UUID"); + +CREATE TABLE "QUALITY_GATES"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(100) NOT NULL, + "IS_BUILT_IN" BOOLEAN NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "QUALITY_GATES" ADD CONSTRAINT "PK_QUALITY_GATES" PRIMARY KEY("ID"); +CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES_UUID" ON "QUALITY_GATES"("UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTableTest/schema.sql new file mode 100644 index 00000000000..5093408fcda --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropPrimaryKeyOnIdColumnOfQGatesTableTest/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE "QUALITY_GATES"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(100) NOT NULL, + "IS_BUILT_IN" BOOLEAN NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "QUALITY_GATES" ADD CONSTRAINT "PK_QUALITY_GATES" PRIMARY KEY("ID"); +CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES_UUID" ON "QUALITY_GATES"("UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropQGateIdColumnForQGateConditionsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropQGateIdColumnForQGateConditionsTest/schema.sql new file mode 100644 index 00000000000..cd2a8e3f853 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropQGateIdColumnForQGateConditionsTest/schema.sql @@ -0,0 +1,13 @@ +CREATE TABLE "QUALITY_GATE_CONDITIONS"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "QGATE_ID" INTEGER, + "QGATE_UUID" VARCHAR(40) NOT NULL, + "METRIC_ID" INTEGER, + "PERIOD" INTEGER, + "OPERATOR" VARCHAR(3), + "VALUE_ERROR" VARCHAR(64), + "VALUE_WARNING" VARCHAR(64), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("ID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropUniqueIndexOnUuidColumnOfQualityGatesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropUniqueIndexOnUuidColumnOfQualityGatesTableTest/schema.sql new file mode 100644 index 00000000000..11efefb9936 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/DropUniqueIndexOnUuidColumnOfQualityGatesTableTest/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE "QUALITY_GATES"( + "ID" INTEGER NOT NULL, + "UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(100) NOT NULL, + "IS_BUILT_IN" BOOLEAN NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES_UUID" ON "QUALITY_GATES"("UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/MakeQGateUuidColumnNotNullableForQGateConditionsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/MakeQGateUuidColumnNotNullableForQGateConditionsTest/schema.sql new file mode 100644 index 00000000000..5fc71ff5b95 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/MakeQGateUuidColumnNotNullableForQGateConditionsTest/schema.sql @@ -0,0 +1,13 @@ +CREATE TABLE "QUALITY_GATE_CONDITIONS"( + "QGATE_ID" INTEGER, + "QGATE_UUID" VARCHAR(40), + "METRIC_ID" INTEGER, + "PERIOD" INTEGER, + "OPERATOR" VARCHAR(3), + "VALUE_ERROR" VARCHAR(64), + "VALUE_WARNING" VARCHAR(64), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP, + "UUID" VARCHAR(40) NOT NULL +); +ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("UUID"); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/PopulateQGateUuidColumnForQGateConditionsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/PopulateQGateUuidColumnForQGateConditionsTest/schema.sql new file mode 100644 index 00000000000..497d17eddf5 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/qualitygates/PopulateQGateUuidColumnForQGateConditionsTest/schema.sql @@ -0,0 +1,24 @@ +CREATE TABLE "QUALITY_GATE_CONDITIONS"( + "QGATE_ID" INTEGER, + "QGATE_UUID" VARCHAR(40), + "METRIC_ID" INTEGER, + "PERIOD" INTEGER, + "OPERATOR" VARCHAR(3), + "VALUE_ERROR" VARCHAR(64), + "VALUE_WARNING" VARCHAR(64), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP, + "UUID" VARCHAR(40) NOT NULL +); +ALTER TABLE "QUALITY_GATE_CONDITIONS" ADD CONSTRAINT "PK_QUALITY_GATE_CONDITIONS" PRIMARY KEY("UUID"); + +CREATE TABLE "QUALITY_GATES"( + "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1), + "UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(100) NOT NULL, + "IS_BUILT_IN" BOOLEAN NOT NULL, + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP +); +ALTER TABLE "QUALITY_GATES" ADD CONSTRAINT "PK_QUALITY_GATES" PRIMARY KEY("ID"); +CREATE UNIQUE INDEX "UNIQ_QUALITY_GATES_UUID" ON "QUALITY_GATES"("UUID"); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateFinderTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateFinderTest.java index 2b90eadeb82..dc402af8bd2 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateFinderTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/QualityGateFinderTest.java @@ -52,7 +52,7 @@ public class QualityGateFinderTest { Optional<QualityGateFinder.QualityGateData> result = underTest.getQualityGate(dbSession, db.getDefaultOrganization(), project); assertThat(result).isPresent(); - assertThat(result.get().getQualityGate().getId()).isEqualTo(dbQualityGate.getId()); + assertThat(result.get().getQualityGate().getUuid()).isEqualTo(dbQualityGate.getUuid()); assertThat(result.get().isDefault()).isTrue(); } @@ -66,7 +66,7 @@ public class QualityGateFinderTest { Optional<QualityGateFinder.QualityGateData> result = underTest.getQualityGate(dbSession, db.getDefaultOrganization(), project); assertThat(result).isPresent(); - assertThat(result.get().getQualityGate().getId()).isEqualTo(dbQualityGate.getId()); + assertThat(result.get().getQualityGate().getUuid()).isEqualTo(dbQualityGate.getUuid()); assertThat(result.get().isDefault()).isFalse(); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java index 310bbeb09bb..03a87e0eaad 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/LiveQualityGateComputerImpl.java @@ -67,7 +67,7 @@ public class LiveQualityGateComputerImpl implements LiveQualityGateComputer { QualityGateDto gateDto = qGateFinder.getQualityGate(dbSession, organization, project) .orElseThrow(() -> new IllegalStateException(format("Quality Gate not found for project %s", project.getKey()))) .getQualityGate(); - Collection<QualityGateConditionDto> conditionDtos = dbClient.gateConditionDao().selectForQualityGate(dbSession, gateDto.getId()); + Collection<QualityGateConditionDto> conditionDtos = dbClient.gateConditionDao().selectForQualityGate(dbSession, gateDto.getUuid()); Set<String> metricUuids = conditionDtos.stream().map(QualityGateConditionDto::getMetricUuid) .collect(toHashSet(conditionDtos.size())); Map<String, MetricDto> metricsByUuid = dbClient.metricDao().selectByUuids(dbSession, metricUuids).stream() @@ -83,7 +83,7 @@ public class LiveQualityGateComputerImpl implements LiveQualityGateComputer { conditions = conditions.filter(Condition::isOnLeakPeriod); } - return new QualityGate(String.valueOf(gateDto.getId()), gateDto.getName(), conditions.collect(toHashSet(conditionDtos.size()))); + return new QualityGate(String.valueOf(gateDto.getUuid()), gateDto.getName(), conditions.collect(toHashSet(conditionDtos.size()))); } @Override diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java index ab5c13bffcf..b2cd443d5fd 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java @@ -90,9 +90,9 @@ public class QualityGateConditionsUpdater { String errorThreshold) { MetricDto metric = getNonNullMetric(dbSession, metricKey); validateCondition(metric, operator, errorThreshold); - checkConditionDoesNotExistOnSameMetric(getConditions(dbSession, qualityGate.getId()), metric); + checkConditionDoesNotExistOnSameMetric(getConditions(dbSession, qualityGate.getUuid()), metric); - QualityGateConditionDto newCondition = new QualityGateConditionDto().setQualityGateId(qualityGate.getId()) + QualityGateConditionDto newCondition = new QualityGateConditionDto().setQualityGateUuid(qualityGate.getUuid()) .setUuid(Uuids.create()) .setMetricUuid(metric.getUuid()).setMetricKey(metric.getKey()) .setOperator(operator) @@ -123,8 +123,8 @@ public class QualityGateConditionsUpdater { return metric; } - private Collection<QualityGateConditionDto> getConditions(DbSession dbSession, long qGateId) { - return dbClient.gateConditionDao().selectForQualityGate(dbSession, qGateId); + private Collection<QualityGateConditionDto> getConditions(DbSession dbSession, String qGateUuid) { + return dbClient.gateConditionDao().selectForQualityGate(dbSession, qGateUuid); } private static void validateCondition(MetricDto metric, String operator, String errorThreshold) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java index 1f978335852..ceee7526d03 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateUpdater.java @@ -55,10 +55,10 @@ public class QualityGateUpdater { QualityGateDto destinationGate = create(dbSession, organizationDto, destinationName); - for (QualityGateConditionDto sourceCondition : dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getId())) { + for (QualityGateConditionDto sourceCondition : dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGateDto.getUuid())) { dbClient.gateConditionDao().insert(new QualityGateConditionDto() .setUuid(Uuids.create()) - .setQualityGateId(destinationGate.getId()) + .setQualityGateUuid(destinationGate.getUuid()) .setMetricUuid(sourceCondition.getMetricUuid()) .setOperator(sourceCondition.getOperator()) .setErrorThreshold(sourceCondition.getErrorThreshold()), diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java index 59ce7781722..cfcef61d58a 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/RegisterQualityGates.java @@ -113,7 +113,7 @@ public class RegisterQualityGates implements Startable { Map<String, String> uuidToKeyMetric = dbClient.metricDao().selectAll(dbSession).stream() .collect(toMap(MetricDto::getUuid, MetricDto::getKey)); - List<QualityGateCondition> qualityGateConditions = qualityGateConditionDao.selectForQualityGate(dbSession, builtin.getId()) + List<QualityGateCondition> qualityGateConditions = qualityGateConditionDao.selectForQualityGate(dbSession, builtin.getUuid()) .stream() .map(dto -> QualityGateCondition.from(dto, uuidToKeyMetric)) .collect(MoreCollectors.toList()); @@ -123,7 +123,7 @@ public class RegisterQualityGates implements Startable { List<QualityGateCondition> qgConditionsToBeDeleted = new ArrayList<>(qualityGateConditions); qgConditionsToBeDeleted.removeAll(QUALITY_GATE_CONDITIONS); qgConditionsToBeDeleted - .forEach(qgc -> qualityGateConditionDao.delete(qgc.toQualityGateDto(builtin.getId()), dbSession)); + .forEach(qgc -> qualityGateConditionDao.delete(qgc.toQualityGateDto(builtin.getUuid()), dbSession)); // Find all conditions that are not present in qualityGateConditions // Those conditions must be created @@ -203,13 +203,13 @@ public class RegisterQualityGates implements Startable { return this; } - public QualityGateConditionDto toQualityGateDto(long qualityGateId) { + public QualityGateConditionDto toQualityGateDto(String qualityGateUuid) { return new QualityGateConditionDto() .setUuid(uuid) .setMetricKey(metricKey) .setOperator(operator) .setErrorThreshold(errorThreshold) - .setQualityGateId(qualityGateId); + .setQualityGateUuid(qualityGateUuid); } // id does not belongs to equals to be able to be compared with builtin diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CopyAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CopyAction.java index 64add697428..1351b083354 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CopyAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CopyAction.java @@ -30,7 +30,6 @@ import org.sonar.server.qualitygate.QualityGateUpdater; import org.sonar.server.user.UserSession; import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_GATES; -import static org.sonar.server.qualitygate.ws.QualityGatesWs.parseId; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ID; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_NAME; import static org.sonar.server.ws.WsUtils.writeProtobuf; @@ -75,19 +74,19 @@ public class CopyAction implements QualityGatesWsAction { @Override public void handle(Request request, Response response) { - Long id = parseId(request, PARAM_ID); + String uuid = request.mandatoryParam(PARAM_ID); String destinationName = request.mandatoryParam(PARAM_NAME); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); userSession.checkPermission(ADMINISTER_QUALITY_GATES, organization); - QualityGateDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, id); + QualityGateDto qualityGate = wsSupport.getByOrganizationAndUuid(dbSession, organization, uuid); QualityGateDto copy = qualityGateUpdater.copy(dbSession, organization, qualityGate, destinationName); dbSession.commit(); writeProtobuf(newBuilder() - .setId(copy.getId()) + .setId(copy.getUuid()) .setName(copy.getName()) .build(), request, response); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CreateAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CreateAction.java index 375bd4220b9..89686dfa71e 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CreateAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CreateAction.java @@ -82,7 +82,7 @@ public class CreateAction implements QualityGatesWsAction { QualityGateDto newQualityGate = qualityGateUpdater.create(dbSession, organizationDto, name); CreateResponse.Builder createResponse = CreateResponse.newBuilder() - .setId(newQualityGate.getId()) + .setId(newQualityGate.getUuid()) .setName(newQualityGate.getName()); dbSession.commit(); writeProtobuf(createResponse.build(), request, response); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CreateConditionAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CreateConditionAction.java index 7931f60c019..299b1c13b41 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CreateConditionAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/CreateConditionAction.java @@ -77,14 +77,14 @@ public class CreateConditionAction implements QualityGatesWsAction { @Override public void handle(Request request, Response response) { - int gateId = request.mandatoryParamAsInt(PARAM_GATE_ID); + String gateUuid = request.mandatoryParam(PARAM_GATE_ID); String metric = request.mandatoryParam(PARAM_METRIC); String operator = request.mandatoryParam(PARAM_OPERATOR); String error = request.mandatoryParam(PARAM_ERROR); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); - QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, gateId); + QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndUuid(dbSession, organization, gateUuid); wsSupport.checkCanEdit(qualityGate); QualityGateConditionDto condition = qualityGateConditionsUpdater.createCondition(dbSession, qualityGate, metric, operator, error); CreateConditionResponse.Builder createConditionResponse = CreateConditionResponse.newBuilder() diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeleteConditionAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeleteConditionAction.java index 7c766d1ccdd..68b57d21444 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeleteConditionAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DeleteConditionAction.java @@ -65,8 +65,8 @@ public class DeleteConditionAction implements QualityGatesWsAction { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QualityGateConditionDto condition = wsSupport.getCondition(dbSession, conditionUuid); - QGateWithOrgDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndId(dbSession, organization, condition.getQualityGateId()); - checkState(qualityGateDto != null, "Condition '%s' is linked to an unknown quality gate '%s'", conditionUuid, condition.getQualityGateId()); + QGateWithOrgDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndUuid(dbSession, organization, condition.getQualityGateUuid()); + checkState(qualityGateDto != null, "Condition '%s' is linked to an unknown quality gate '%s'", conditionUuid, condition.getQualityGateUuid()); wsSupport.checkCanEdit(qualityGateDto); dbClient.gateConditionDao().delete(condition, dbSession); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DestroyAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DestroyAction.java index e695c7f30cd..4b16cd41eab 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DestroyAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/DestroyAction.java @@ -62,12 +62,12 @@ public class DestroyAction implements QualityGatesWsAction { @Override public void handle(Request request, Response response) { - long qualityGateId = request.mandatoryParamAsLong(QualityGatesWsParameters.PARAM_ID); + String qualityGateUuid = request.mandatoryParam(QualityGatesWsParameters.PARAM_ID); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); - QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, qualityGateId); + QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndUuid(dbSession, organization, qualityGateUuid); QualityGateDto defaultQualityGate = finder.getDefault(dbSession, organization); - checkArgument(!defaultQualityGate.getId().equals(qualityGate.getId()), "The default quality gate cannot be removed"); + checkArgument(!defaultQualityGate.getUuid().equals(qualityGate.getUuid()), "The default quality gate cannot be removed"); wsSupport.checkCanEdit(qualityGate); dbClient.projectQgateAssociationDao().deleteByQGateUuid(dbSession, qualityGate.getUuid()); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java index 4109a8596ce..c17cd289bc7 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/GetByProjectAction.java @@ -112,7 +112,7 @@ public class GetByProjectAction implements QualityGatesWsAction { GetByProjectResponse.Builder response = GetByProjectResponse.newBuilder(); response.getQualityGateBuilder() - .setId(qualityGate.getId()) + .setId(qualityGate.getUuid()) .setName(qualityGate.getName()) .setDefault(data.isDefault()); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java index 4510d2dc866..7a12d64b284 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java @@ -76,19 +76,19 @@ public class ListAction implements QualityGatesWsAction { } private ListWsResponse buildResponse(OrganizationDto organization, Collection<QualityGateDto> qualityGates, @Nullable QualityGateDto defaultQualityGate) { - Long defaultId = defaultQualityGate == null ? null : defaultQualityGate.getId(); + String defaultUuid = defaultQualityGate == null ? null : defaultQualityGate.getUuid(); ListWsResponse.Builder builder = ListWsResponse.newBuilder() .setActions(ListWsResponse.RootActions.newBuilder().setCreate(wsSupport.isQualityGateAdmin(organization))) .addAllQualitygates(qualityGates.stream() .map(qualityGate -> QualityGate.newBuilder() - .setId(qualityGate.getId()) + .setId(qualityGate.getUuid()) .setName(qualityGate.getName()) - .setIsDefault(qualityGate.getId().equals(defaultId)) + .setIsDefault(qualityGate.getUuid().equals(defaultUuid)) .setIsBuiltIn(qualityGate.isBuiltIn()) .setActions(wsSupport.getActions(organization, qualityGate, defaultQualityGate)) .build()) .collect(toList())); - ofNullable(defaultId).ifPresent(builder::setDefault); + ofNullable(defaultUuid).ifPresent(builder::setDefault); return builder.build(); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java index 492dac9039f..570ae99a186 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGatesWsSupport.java @@ -19,6 +19,7 @@ */ package org.sonar.server.qualitygate.ws; +import java.util.Objects; import java.util.Optional; import javax.annotation.Nullable; import org.sonar.api.server.ws.Request; @@ -61,10 +62,10 @@ public class QualityGatesWsSupport { this.componentFinder = componentFinder; } - public QGateWithOrgDto getByOrganizationAndId(DbSession dbSession, OrganizationDto organization, long qualityGateId) { + public QGateWithOrgDto getByOrganizationAndUuid(DbSession dbSession, OrganizationDto organization, String qualityGateUuid) { return checkFound( - dbClient.qualityGateDao().selectByOrganizationAndId(dbSession, organization, qualityGateId), - "No quality gate has been found for id %s in organization %s", qualityGateId, organization.getName()); + dbClient.qualityGateDao().selectByOrganizationAndUuid(dbSession, organization, qualityGateUuid), + "No quality gate has been found for id %s in organization %s", qualityGateUuid, organization.getName()); } QualityGateConditionDto getCondition(DbSession dbSession, String uuid) { @@ -86,8 +87,7 @@ public class QualityGatesWsSupport { } Qualitygates.Actions getActions(OrganizationDto organization, QualityGateDto qualityGate, @Nullable QualityGateDto defaultQualityGate) { - Long defaultId = defaultQualityGate == null ? null : defaultQualityGate.getId(); - boolean isDefault = qualityGate.getId().equals(defaultId); + boolean isDefault = defaultQualityGate != null && Objects.equals(defaultQualityGate.getUuid(), qualityGate.getUuid()); boolean isBuiltIn = qualityGate.isBuiltIn(); boolean isQualityGateAdmin = isQualityGateAdmin(organization); return Qualitygates.Actions.newBuilder() diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/RenameAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/RenameAction.java index 0f9e19081f7..df86210c0b2 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/RenameAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/RenameAction.java @@ -70,19 +70,19 @@ public class RenameAction implements QualityGatesWsAction { @Override public void handle(Request request, Response response) { - long id = QualityGatesWs.parseId(request, PARAM_ID); + String uuid = request.mandatoryParam(PARAM_ID); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); - QualityGateDto qualityGate = rename(dbSession, organization, id, request.mandatoryParam(PARAM_NAME)); + QualityGateDto qualityGate = rename(dbSession, organization, uuid, request.mandatoryParam(PARAM_NAME)); writeProtobuf(QualityGate.newBuilder() - .setId(qualityGate.getId()) + .setId(qualityGate.getUuid()) .setName(qualityGate.getName()) .build(), request, response); } } - private QualityGateDto rename(DbSession dbSession, OrganizationDto organization, long id, String name) { - QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, id); + private QualityGateDto rename(DbSession dbSession, OrganizationDto organization, String uuid, String name) { + QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndUuid(dbSession, organization, uuid); wsSupport.checkCanEdit(qualityGate); checkNotAlreadyExists(dbSession, organization, qualityGate, name); qualityGate.setName(name); @@ -93,7 +93,7 @@ public class RenameAction implements QualityGatesWsAction { private void checkNotAlreadyExists(DbSession dbSession, OrganizationDto organization, QualityGateDto qualityGate, String name) { QualityGateDto existingQgate = dbClient.qualityGateDao().selectByOrganizationAndName(dbSession, organization, name); - boolean isModifyingCurrentQgate = existingQgate == null || existingQgate.getId().equals(qualityGate.getId()); + boolean isModifyingCurrentQgate = existingQgate == null || existingQgate.getUuid().equals(qualityGate.getUuid()); checkArgument(isModifyingCurrentQgate, "Name '%s' has already been taken", name); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java index 8316e65bf6b..f42da8a98c0 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java @@ -101,7 +101,7 @@ public class SearchAction implements QualityGatesWsAction { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); - QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, request.mandatoryParamAsLong(PARAM_GATE_ID)); + QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndUuid(dbSession, organization, request.mandatoryParam(PARAM_GATE_ID)); ProjectQgateAssociationQuery projectQgateAssociationQuery = ProjectQgateAssociationQuery.builder() .qualityGate(qualityGate) @@ -128,7 +128,7 @@ public class SearchAction implements QualityGatesWsAction { createResponse.addResultsBuilder() .setName(project.getName()) .setKey(project.getKey()) - .setSelected(project.getGateId() != null); + .setSelected(project.getGateUuid() != null); } writeProtobuf(createResponse.build(), request, response); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java index 6d96aa4e49f..43355abe7eb 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java @@ -74,12 +74,12 @@ public class SelectAction implements QualityGatesWsAction { @Override public void handle(Request request, Response response) { - long gateId = request.mandatoryParamAsLong(PARAM_GATE_ID); + String gateUuid = request.mandatoryParam(PARAM_GATE_ID); String projectKey = request.mandatoryParam(PARAM_PROJECT_KEY); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); - QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, gateId); + QGateWithOrgDto qualityGate = wsSupport.getByOrganizationAndUuid(dbSession, organization, gateUuid); ProjectDto project = wsSupport.getProject(dbSession, organization, projectKey); wsSupport.checkCanAdminProject(organization, project); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SetAsDefaultAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SetAsDefaultAction.java index 91c2123421b..3ae2b14a163 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SetAsDefaultAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SetAsDefaultAction.java @@ -29,7 +29,6 @@ import org.sonar.db.qualitygate.QualityGateDto; import org.sonar.server.user.UserSession; import static org.sonar.db.permission.OrganizationPermission.ADMINISTER_QUALITY_GATES; -import static org.sonar.server.qualitygate.ws.QualityGatesWs.parseId; import static org.sonar.server.qualitygate.ws.QualityGatesWsParameters.PARAM_ID; public class SetAsDefaultAction implements QualityGatesWsAction { @@ -63,12 +62,12 @@ public class SetAsDefaultAction implements QualityGatesWsAction { @Override public void handle(Request request, Response response) { - Long id = parseId(request, PARAM_ID); + String uuid = request.mandatoryParam(PARAM_ID); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); userSession.checkPermission(ADMINISTER_QUALITY_GATES, organization); - QualityGateDto qualityGate = wsSupport.getByOrganizationAndId(dbSession, organization, id); + QualityGateDto qualityGate = wsSupport.getByOrganizationAndUuid(dbSession, organization, uuid); organization.setDefaultQualityGateUuid(qualityGate.getUuid()); dbClient.organizationDao().update(dbSession, organization); dbSession.commit(); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java index ae2806fd8f7..831e85d63cb 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java @@ -86,13 +86,13 @@ public class ShowAction implements QualityGatesWsAction { @Override public void handle(Request request, Response response) { - Long id = request.paramAsLong(PARAM_ID); + String id = request.param(PARAM_ID); String name = request.param(PARAM_NAME); checkOneOfIdOrNamePresent(id, name); try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); - QualityGateDto qualityGate = getByNameOrId(dbSession, organization, name, id); + QualityGateDto qualityGate = getByNameOrUuid(dbSession, organization, name, id); Collection<QualityGateConditionDto> conditions = getConditions(dbSession, qualityGate); Map<String, MetricDto> metricsByUuid = getMetricsByUuid(dbSession, conditions); QualityGateDto defaultQualityGate = qualityGateFinder.getDefault(dbSession, organization); @@ -100,18 +100,18 @@ public class ShowAction implements QualityGatesWsAction { } } - private QualityGateDto getByNameOrId(DbSession dbSession, OrganizationDto organization, @Nullable String name, @Nullable Long id) { + private QualityGateDto getByNameOrUuid(DbSession dbSession, OrganizationDto organization, @Nullable String name, @Nullable String uuid) { if (name != null) { return checkFound(dbClient.qualityGateDao().selectByOrganizationAndName(dbSession, organization, name), "No quality gate has been found for name %s", name); } - if (id != null) { - return wsSupport.getByOrganizationAndId(dbSession, organization, id); + if (uuid != null) { + return wsSupport.getByOrganizationAndUuid(dbSession, organization, uuid); } throw new IllegalArgumentException("No parameter has been set to identify a quality gate"); } public Collection<QualityGateConditionDto> getConditions(DbSession dbSession, QualityGateDto qualityGate) { - return dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId()); + return dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getUuid()); } private Map<String, MetricDto> getMetricsByUuid(DbSession dbSession, Collection<QualityGateConditionDto> conditions) { @@ -124,7 +124,7 @@ public class ShowAction implements QualityGatesWsAction { private ShowWsResponse buildResponse(OrganizationDto organization, QualityGateDto qualityGate, QualityGateDto defaultQualityGate, Collection<QualityGateConditionDto> conditions, Map<String, MetricDto> metricsByUuid) { return ShowWsResponse.newBuilder() - .setId(qualityGate.getId()) + .setId(qualityGate.getUuid()) .setName(qualityGate.getName()) .setIsBuiltIn(qualityGate.isBuiltIn()) .addAllConditions(conditions.stream() @@ -148,7 +148,7 @@ public class ShowAction implements QualityGatesWsAction { }; } - private static void checkOneOfIdOrNamePresent(@Nullable Long qGateId, @Nullable String qGateName) { - checkArgument(qGateId == null ^ qGateName == null, "Either '%s' or '%s' must be provided", PARAM_ID, PARAM_NAME); + private static void checkOneOfIdOrNamePresent(@Nullable String qGateUuid, @Nullable String qGateName) { + checkArgument(qGateUuid == null ^ qGateName == null, "Either '%s' or '%s' must be provided", PARAM_ID, PARAM_NAME); } } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/UpdateConditionAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/UpdateConditionAction.java index f52ba2346c6..98a1946c9be 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/UpdateConditionAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/UpdateConditionAction.java @@ -85,8 +85,8 @@ public class UpdateConditionAction implements QualityGatesWsAction { try (DbSession dbSession = dbClient.openSession(false)) { OrganizationDto organization = wsSupport.getOrganization(dbSession, request); QualityGateConditionDto condition = wsSupport.getCondition(dbSession, id); - QGateWithOrgDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndId(dbSession, organization, condition.getQualityGateId()); - checkState(qualityGateDto != null, "Condition '%s' is linked to an unknown quality gate '%s'", id, condition.getQualityGateId()); + QGateWithOrgDto qualityGateDto = dbClient.qualityGateDao().selectByOrganizationAndUuid(dbSession, organization, condition.getQualityGateUuid()); + checkState(qualityGateDto != null, "Condition '%s' is linked to an unknown quality gate '%s'", id, condition.getQualityGateUuid()); wsSupport.checkCanEdit(qualityGateDto); QualityGateConditionDto updatedCondition = qualityGateConditionsUpdater.updateCondition(dbSession, condition, metric, operator, error); UpdateConditionResponse.Builder updateConditionResponse = UpdateConditionResponse.newBuilder() diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java index 83011027ea9..fb5da6beebf 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/ui/ws/ComponentAction.java @@ -269,7 +269,7 @@ public class ComponentAction implements NavigationWsAction { .orElseThrow(() -> new NotFoundException(format("Quality Gate not found for %s", component.getKey()))); QualityGateDto qualityGateDto = qualityGateData.getQualityGate(); json.name("qualityGate").beginObject() - .prop("key", qualityGateDto.getId()) + .prop("key", qualityGateDto.getUuid()) .prop("name", qualityGateDto.getName()) .prop("isDefault", qualityGateData.isDefault()) .endObject(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java index 4e96db9ff50..9829c51671d 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/LiveQualityGateComputerImplTest.java @@ -97,7 +97,7 @@ public class LiveQualityGateComputerImplTest { QualityGate result = underTest.loadQualityGate(db.getSession(), organization, project, branch); - assertThat(result.getId()).isEqualTo("" + gate.getId()); + assertThat(result.getId()).isEqualTo("" + gate.getUuid()); assertThat(result.getConditions()) .extracting(Condition::getMetricKey, Condition::getOperator, Condition::getErrorThreshold) .containsExactlyInAnyOrder( diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java index 5a0aaf6b582..9ef27363162 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/metric/ws/DeleteActionTest.java @@ -118,8 +118,8 @@ public class DeleteActionTest { newRequest().setParam("keys", "custom-key").execute(); - assertThat(dbClient.gateConditionDao().selectForQualityGate(db.getSession(), qualityGate1.getId())).isEmpty(); - assertThat(dbClient.gateConditionDao().selectForQualityGate(db.getSession(), qualityGate2.getId())) + assertThat(dbClient.gateConditionDao().selectForQualityGate(db.getSession(), qualityGate1.getUuid())).isEmpty(); + assertThat(dbClient.gateConditionDao().selectForQualityGate(db.getSession(), qualityGate2.getUuid())) .extracting(QualityGateConditionDto::getMetricUuid).containsOnly(nonCustomMetric.getUuid()); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/QualityGateConditionsUpdaterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/QualityGateConditionsUpdaterTest.java index 6aed8d789a1..67af28d0249 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/QualityGateConditionsUpdaterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/QualityGateConditionsUpdaterTest.java @@ -393,12 +393,12 @@ public class QualityGateConditionsUpdaterTest { private void verifyCondition(QualityGateConditionDto dto, QualityGateDto qualityGate, MetricDto metric, String operator, String error) { QualityGateConditionDto reloaded = db.getDbClient().gateConditionDao().selectByUuid(dto.getUuid(), db.getSession()); - assertThat(reloaded.getQualityGateId()).isEqualTo(qualityGate.getId()); + assertThat(reloaded.getQualityGateUuid()).isEqualTo(qualityGate.getUuid()); assertThat(reloaded.getMetricUuid()).isEqualTo(metric.getUuid()); assertThat(reloaded.getOperator()).isEqualTo(operator); assertThat(reloaded.getErrorThreshold()).isEqualTo(error); - assertThat(dto.getQualityGateId()).isEqualTo(qualityGate.getId()); + assertThat(dto.getQualityGateUuid()).isEqualTo(qualityGate.getUuid()); assertThat(dto.getMetricUuid()).isEqualTo(metric.getUuid()); assertThat(dto.getOperator()).isEqualTo(operator); assertThat(dto.getErrorThreshold()).isEqualTo(error); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java index 8afbcc0d844..fc5578b59eb 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/RegisterQualityGatesTest.java @@ -207,7 +207,7 @@ public class RegisterQualityGatesTest { underTest.start(); assertThat(qualityGateFinder.getBuiltInQualityGate(dbSession)).isNotNull(); - assertThat(qualityGateFinder.getBuiltInQualityGate(dbSession).getId()).isEqualTo(builtInQualityGate.getId()); + assertThat(qualityGateFinder.getBuiltInQualityGate(dbSession).getUuid()).isEqualTo(builtInQualityGate.getUuid()); } @Test @@ -215,6 +215,7 @@ public class RegisterQualityGatesTest { insertMetrics(); QualityGateConditionDto conditionDto = new QualityGateConditionDto() .setUuid(Uuids.createFast()) + .setQualityGateUuid("qgate_uuid") .setMetricUuid("unknown") // This uuid does not exist .setOperator(OPERATOR_GREATER_THAN) .setErrorThreshold("1"); @@ -253,7 +254,7 @@ public class RegisterQualityGatesTest { assertThat(qualityGateDto).isNotNull(); assertThat(qualityGateDto.getCreatedAt()).isNotNull(); assertThat(qualityGateDto.isBuiltIn()).isTrue(); - assertThat(gateConditionDao.selectForQualityGate(dbSession, qualityGateDto.getId())) + assertThat(gateConditionDao.selectForQualityGate(dbSession, qualityGateDto.getUuid())) .extracting(QualityGateConditionDto::getMetricUuid, QualityGateConditionDto::getOperator, QualityGateConditionDto::getErrorThreshold) .containsExactlyInAnyOrder( diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CopyActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CopyActionTest.java index f5aef0be314..f4052bdf7e7 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CopyActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CopyActionTest.java @@ -106,7 +106,7 @@ public class CopyActionTest { QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric); ws.newRequest() - .setParam(PARAM_ID, qualityGate.getId().toString()) + .setParam(PARAM_ID, qualityGate.getUuid()) .setParam(PARAM_NAME, "new-name") .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute(); @@ -114,10 +114,10 @@ public class CopyActionTest { QGateWithOrgDto actual = db.getDbClient().qualityGateDao().selectByOrganizationAndName(dbSession, organization, "new-name"); assertThat(actual).isNotNull(); assertThat(actual.isBuiltIn()).isFalse(); - assertThat(actual.getId()).isNotEqualTo(qualityGate.getId()); + assertThat(actual.getUuid()).isNotEqualTo(qualityGate.getUuid()); assertThat(actual.getUuid()).isNotEqualTo(qualityGate.getUuid()); - assertThat(db.getDbClient().gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId())) + assertThat(db.getDbClient().gateConditionDao().selectForQualityGate(dbSession, qualityGate.getUuid())) .extracting(QualityGateConditionDto::getMetricUuid, QualityGateConditionDto::getErrorThreshold) .containsExactlyInAnyOrder(tuple(metric.getUuid(), condition.getErrorThreshold())); } @@ -129,7 +129,7 @@ public class CopyActionTest { QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(defaultOrganization); ws.newRequest() - .setParam(PARAM_ID, qualityGate.getId().toString()) + .setParam(PARAM_ID, qualityGate.getUuid()) .setParam(PARAM_NAME, "new-name") .execute(); @@ -145,7 +145,7 @@ public class CopyActionTest { QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qualityGateDto -> qualityGateDto.setBuiltIn(true)); ws.newRequest() - .setParam(PARAM_ID, qualityGate.getId().toString()) + .setParam(PARAM_ID, qualityGate.getUuid()) .setParam(PARAM_NAME, "new-name") .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute(); @@ -161,12 +161,12 @@ public class CopyActionTest { QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization()); QualityGate response = ws.newRequest() - .setParam(PARAM_ID, qualityGate.getId().toString()) + .setParam(PARAM_ID, qualityGate.getUuid()) .setParam(PARAM_NAME, "new-name") .executeProtobuf(QualityGate.class); assertThat(response).isNotNull(); - assertThat(response.getId()).isNotEqualTo(qualityGate.getId()); + assertThat(response.getId()).isNotEqualTo(qualityGate.getUuid()); assertThat(response.getName()).isEqualTo("new-name"); } @@ -184,7 +184,7 @@ public class CopyActionTest { ws.newRequest() .setParam(PARAM_ORGANIZATION, organization2.getKey()) - .setParam(PARAM_ID, qualityGate2.getId().toString()) + .setParam(PARAM_ID, qualityGate2.getUuid()) .setParam(PARAM_NAME, qualityGate1.getName()) .execute(); @@ -201,11 +201,11 @@ public class CopyActionTest { userSession.addPermission(ADMINISTER_QUALITY_GATES, organization2); expectedException.expect(NotFoundException.class); - expectedException.expectMessage(format("No quality gate has been found for id %s in organization %s", qualityGate1.getId(), organization2.getName())); + expectedException.expectMessage(format("No quality gate has been found for id %s in organization %s", qualityGate1.getUuid(), organization2.getName())); ws.newRequest() .setParam(PARAM_ORGANIZATION, organization2.getKey()) - .setParam(PARAM_ID, qualityGate1.getId().toString()) + .setParam(PARAM_ID, qualityGate1.getUuid()) .setParam(PARAM_NAME, "new-name") .execute(); } @@ -220,7 +220,7 @@ public class CopyActionTest { expectedException.expect(ForbiddenException.class); ws.newRequest() - .setParam(PARAM_ID, qualityGate.getId().toString()) + .setParam(PARAM_ID, qualityGate.getUuid()) .setParam(PARAM_NAME, "new-name") .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute(); @@ -265,7 +265,7 @@ public class CopyActionTest { TestRequest request = ws.newRequest() - .setParam(PARAM_ID, qualityGate.getId().toString()) + .setParam(PARAM_ID, qualityGate.getUuid()) .setParam(PARAM_ORGANIZATION, organization.getKey()); ofNullable(nameParameter).ifPresent(t -> request.setParam(PARAM_NAME, t)); @@ -295,7 +295,7 @@ public class CopyActionTest { expectedException.expectMessage("Name has already been taken"); ws.newRequest() - .setParam(PARAM_ID, qualityGate.getId().toString()) + .setParam(PARAM_ID, qualityGate.getUuid()) .setParam(PARAM_NAME, existingQualityGate.getName()) .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateActionTest.java index ea5fb77b074..6ee962f5ad1 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateActionTest.java @@ -118,7 +118,7 @@ public class CreateActionTest { .executeProtobuf(CreateResponse.class); assertThat(response.getName()).isEqualTo(qualityGate.getName()); - assertThat(response.getId()).isNotEqualTo(qualityGate.getId()); + assertThat(response.getId()).isNotEqualTo(qualityGate.getUuid()); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java index 57300d18011..c9e65b68511 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/CreateConditionActionTest.java @@ -84,7 +84,7 @@ public class CreateConditionActionTest { MetricDto metric = insertMetric(); ws.newRequest() - .setParam(PARAM_GATE_ID, qualityGate.getId().toString()) + .setParam(PARAM_GATE_ID, qualityGate.getUuid()) .setParam(PARAM_METRIC, metric.getKey()) .setParam(PARAM_OPERATOR, "LT") .setParam(PARAM_ERROR, "90") @@ -102,7 +102,7 @@ public class CreateConditionActionTest { MetricDto metric = insertMetric(); ws.newRequest() - .setParam(PARAM_GATE_ID, qualityGate.getId().toString()) + .setParam(PARAM_GATE_ID, qualityGate.getUuid()) .setParam(PARAM_METRIC, metric.getKey()) .setParam(PARAM_OPERATOR, "LT") .setParam(PARAM_ERROR, "90") @@ -122,7 +122,7 @@ public class CreateConditionActionTest { MetricDto metric = insertMetric(); ws.newRequest() - .setParam(PARAM_GATE_ID, qualityGate.getId().toString()) + .setParam(PARAM_GATE_ID, qualityGate.getUuid()) .setParam(PARAM_METRIC, metric.getKey()) .setParam(PARAM_OPERATOR, "LT") .setParam(PARAM_ERROR, "10") @@ -142,7 +142,7 @@ public class CreateConditionActionTest { expectedException.expectMessage(format("Operation forbidden for built-in Quality Gate '%s'", qualityGate.getName())); ws.newRequest() - .setParam(PARAM_GATE_ID, qualityGate.getId().toString()) + .setParam(PARAM_GATE_ID, qualityGate.getUuid()) .setParam(PARAM_METRIC, metric.getKey()) .setParam(PARAM_OPERATOR, "LT") .setParam(PARAM_ERROR, "90") @@ -161,7 +161,7 @@ public class CreateConditionActionTest { expectedException.expectMessage("Value of parameter 'op' (ABC) must be one of: [LT, GT]"); ws.newRequest() - .setParam(PARAM_GATE_ID, qualityGate.getId().toString()) + .setParam(PARAM_GATE_ID, qualityGate.getUuid()) .setParam(PARAM_METRIC, metric.getKey()) .setParam(PARAM_OPERATOR, "ABC") .setParam(PARAM_ERROR, "90") @@ -181,7 +181,7 @@ public class CreateConditionActionTest { expectedException.expectMessage(format("Operator %s is not allowed for this metric.", operator)); ws.newRequest() - .setParam(PARAM_GATE_ID, qualityGate.getId().toString()) + .setParam(PARAM_GATE_ID, qualityGate.getUuid()) .setParam(PARAM_METRIC, metric.getKey()) .setParam(PARAM_OPERATOR, operator) .setParam(PARAM_ERROR, "90") @@ -197,14 +197,14 @@ public class CreateConditionActionTest { MetricDto metric = insertMetric(); CreateConditionResponse response = ws.newRequest() - .setParam(PARAM_GATE_ID, qualityGate.getId().toString()) + .setParam(PARAM_GATE_ID, qualityGate.getUuid()) .setParam(PARAM_METRIC, metric.getKey()) .setParam(PARAM_OPERATOR, "LT") .setParam(PARAM_ERROR, "45") .setParam(PARAM_ORGANIZATION, organization.getKey()) .executeProtobuf(CreateConditionResponse.class); - QualityGateConditionDto condition = new ArrayList<>(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId())).get(0); + QualityGateConditionDto condition = new ArrayList<>(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getUuid())).get(0); assertThat(response.getId()).isEqualTo(condition.getUuid()); assertThat(response.getMetric()).isEqualTo(metric.getKey()); assertThat(response.getOp()).isEqualTo("LT"); @@ -222,7 +222,7 @@ public class CreateConditionActionTest { expectedException.expectMessage("Insufficient privileges"); ws.newRequest() - .setParam(PARAM_GATE_ID, qualityGate.getId().toString()) + .setParam(PARAM_GATE_ID, qualityGate.getUuid()) .setParam(PARAM_METRIC, metric.getKey()) .setParam(PARAM_OPERATOR, "LT") .setParam(PARAM_ERROR, "90") @@ -256,10 +256,10 @@ public class CreateConditionActionTest { } private void assertCondition(QualityGateDto qualityGate, MetricDto metric, String operator, String error) { - assertThat(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId())) - .extracting(QualityGateConditionDto::getQualityGateId, QualityGateConditionDto::getMetricUuid, QualityGateConditionDto::getOperator, + assertThat(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getUuid())) + .extracting(QualityGateConditionDto::getQualityGateUuid, QualityGateConditionDto::getMetricUuid, QualityGateConditionDto::getOperator, QualityGateConditionDto::getErrorThreshold) - .containsExactlyInAnyOrder(tuple(qualityGate.getId(), metric.getUuid(), operator, error)); + .containsExactlyInAnyOrder(tuple(qualityGate.getUuid(), metric.getUuid(), operator, error)); } private void logInAsQualityGateAdmin(OrganizationDto organization) { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeleteConditionActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeleteConditionActionTest.java index 15cd608a4f7..aed1dcc18b3 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeleteConditionActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DeleteConditionActionTest.java @@ -175,7 +175,7 @@ public class DeleteConditionActionTest { public void fail_when_condition_match_unknown_quality_gate() { OrganizationDto organization = db.organizations().insert(); userSession.addPermission(ADMINISTER_QUALITY_PROFILES, organization); - QualityGateConditionDto condition = new QualityGateConditionDto().setUuid("uuid").setMetricUuid("metric").setQualityGateId(123L); + QualityGateConditionDto condition = new QualityGateConditionDto().setUuid("uuid").setMetricUuid("metric").setQualityGateUuid("123"); db.getDbClient().gateConditionDao().insert(condition, db.getSession()); db.commit(); @@ -198,7 +198,7 @@ public class DeleteConditionActionTest { QualityGateConditionDto condition = db.qualityGates().addCondition(qualityGate, metric); expectedException.expect(IllegalStateException.class); - expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getUuid(), qualityGate.getId())); + expectedException.expectMessage(format("Condition '%s' is linked to an unknown quality gate '%s'", condition.getUuid(), qualityGate.getUuid())); ws.newRequest() .setParam(PARAM_ID, condition.getUuid()) @@ -207,6 +207,6 @@ public class DeleteConditionActionTest { } private Collection<QualityGateConditionDto> searchConditionsOf(QualityGateDto qualityGate) { - return db.getDbClient().gateConditionDao().selectForQualityGate(db.getSession(), qualityGate.getId()); + return db.getDbClient().gateConditionDao().selectForQualityGate(db.getSession(), qualityGate.getUuid()); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DestroyActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DestroyActionTest.java index 9129c0c8ac3..76158f5ef62 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DestroyActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/DestroyActionTest.java @@ -76,11 +76,11 @@ public class DestroyActionTest { userSession.addPermission(ADMINISTER_QUALITY_GATES, organization); ws.newRequest() - .setParam(PARAM_ID, qualityGate.getId().toString()) + .setParam(PARAM_ID, qualityGate.getUuid()) .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute(); - assertThat(db.getDbClient().qualityGateDao().selectByOrganizationAndId(dbSession, organization, qualityGate.getId())).isNull(); + assertThat(db.getDbClient().qualityGateDao().selectByOrganizationAndUuid(dbSession, organization, qualityGate.getUuid())).isNull(); } @Test @@ -91,11 +91,11 @@ public class DestroyActionTest { userSession.addPermission(ADMINISTER_QUALITY_GATES, organization); ws.newRequest() - .setParam(PARAM_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute(); - assertThat(db.getDbClient().qualityGateDao().selectByOrganizationAndId(dbSession, organization, qualityGate.getId())).isNull(); + assertThat(db.getDbClient().qualityGateDao().selectByOrganizationAndUuid(dbSession, organization, qualityGate.getUuid())).isNull(); } @Test @@ -110,7 +110,7 @@ public class DestroyActionTest { userSession.addPermission(ADMINISTER_QUALITY_GATES, organization); ws.newRequest() - .setParam(PARAM_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute(); @@ -138,7 +138,7 @@ public class DestroyActionTest { expectedException.expectMessage(format("Operation forbidden for built-in Quality Gate '%s'", builtInQualityGate.getName())); ws.newRequest() - .setParam(PARAM_ID, valueOf(builtInQualityGate.getId())) + .setParam(PARAM_ID, valueOf(builtInQualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute(); } @@ -153,26 +153,10 @@ public class DestroyActionTest { QGateWithOrgDto otherQualityGate = db.qualityGates().insertQualityGate(otherOrganization); ws.newRequest() - .setParam(PARAM_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_ID, valueOf(qualityGate.getUuid())) .execute(); - assertThat(db.getDbClient().qualityGateDao().selectByOrganizationAndId(dbSession, defaultOrganization, qualityGate.getId())).isNull(); - } - - @Test - public void fail_when_invalid_id() { - OrganizationDto organization = db.organizations().insert(); - userSession.addPermission(ADMINISTER_QUALITY_GATES, organization); - - String invalidId = "invalid-id"; - - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage(format("The 'id' parameter cannot be parsed as a long value: %s", invalidId)); - - ws.newRequest() - .setParam(PARAM_ID, invalidId) - .setParam(PARAM_ORGANIZATION, organization.getKey()) - .execute(); + assertThat(db.getDbClient().qualityGateDao().selectByOrganizationAndUuid(dbSession, defaultOrganization, qualityGate.getUuid())).isNull(); } @Test @@ -198,7 +182,7 @@ public class DestroyActionTest { expectedException.expectMessage("The default quality gate cannot be removed"); ws.newRequest() - .setParam(PARAM_ID, valueOf(defaultQualityGate.getId())) + .setParam(PARAM_ID, valueOf(defaultQualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute(); } @@ -226,7 +210,7 @@ public class DestroyActionTest { expectedException.expect(ForbiddenException.class); ws.newRequest() - .setParam(PARAM_ID, qualityGate.getId().toString()) + .setParam(PARAM_ID, qualityGate.getUuid()) .setParam(PARAM_ORGANIZATION, organization.getKey()) .execute(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java index fa5761cf847..4f0eb37cf4b 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/GetByProjectActionTest.java @@ -112,7 +112,7 @@ public class GetByProjectActionTest { .executeProtobuf(GetByProjectResponse.class); Qualitygates.QualityGate qualityGate = result.getQualityGate(); - assertThat(Long.valueOf(qualityGate.getId())).isEqualTo(dbQualityGate.getId()); + assertThat(qualityGate.getId()).isEqualTo(dbQualityGate.getUuid()); assertThat(qualityGate.getName()).isEqualTo(dbQualityGate.getName()); assertThat(qualityGate.getDefault()).isTrue(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ListActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ListActionTest.java index 077fd17200a..831674a1db1 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ListActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ListActionTest.java @@ -78,8 +78,8 @@ public class ListActionTest { assertThat(response.getQualitygatesList()) .extracting(QualityGate::getId, QualityGate::getName, QualityGate::getIsDefault) .containsExactlyInAnyOrder( - tuple(defaultQualityGate.getId(), defaultQualityGate.getName(), true), - tuple(otherQualityGate.getId(), otherQualityGate.getName(), false)); + tuple(defaultQualityGate.getUuid(), defaultQualityGate.getName(), true), + tuple(otherQualityGate.getUuid(), otherQualityGate.getName(), false)); } @Test @@ -95,7 +95,7 @@ public class ListActionTest { assertThat(response.getQualitygatesList()) .extracting(QualityGate::getId) - .containsExactlyInAnyOrder(qualityGate.getId()); + .containsExactly(qualityGate.getUuid()); } @Test @@ -112,8 +112,8 @@ public class ListActionTest { assertThat(response.getQualitygatesList()) .extracting(QualityGate::getId, QualityGate::getIsBuiltIn) .containsExactlyInAnyOrder( - tuple(qualityGate1.getId(), true), - tuple(qualityGate2.getId(), false)); + tuple(qualityGate1.getUuid(), true), + tuple(qualityGate2.getUuid(), false)); } @Test @@ -126,7 +126,7 @@ public class ListActionTest { .setParam("organization", organization.getKey()) .executeProtobuf(ListWsResponse.class); - assertThat(response.getDefault()).isEqualTo(defaultQualityGate.getId()); + assertThat(response.getDefault()).isEqualTo(defaultQualityGate.getUuid()); } @Test diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/RenameActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/RenameActionTest.java index 1452a1ca3d1..bb2cd9962ba 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/RenameActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/RenameActionTest.java @@ -77,12 +77,12 @@ public class RenameActionTest { userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES, organization); ws.newRequest() - .setParam("id", qualityGate.getId().toString()) + .setParam("id", qualityGate.getUuid()) .setParam("name", "new name") .setParam("organization", organization.getKey()) .execute(); - assertThat(db.getDbClient().qualityGateDao().selectById(db.getSession(), qualityGate.getId()).getName()).isEqualTo("new name"); + assertThat(db.getDbClient().qualityGateDao().selectByUuid(db.getSession(), qualityGate.getUuid()).getName()).isEqualTo("new name"); } @Test @@ -92,12 +92,12 @@ public class RenameActionTest { QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("old name")); QualityGate result = ws.newRequest() - .setParam("id", qualityGate.getId().toString()) + .setParam("id", qualityGate.getUuid()) .setParam("name", "new name") .setParam("organization", organization.getKey()) .executeProtobuf(QualityGate.class); - assertThat(result.getId()).isEqualTo(qualityGate.getId()); + assertThat(result.getId()).isEqualTo(qualityGate.getUuid()); assertThat(result.getName()).isEqualTo("new name"); } @@ -108,12 +108,12 @@ public class RenameActionTest { QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization, qg -> qg.setName("name")); ws.newRequest() - .setParam("id", qualityGate.getId().toString()) + .setParam("id", qualityGate.getUuid()) .setParam("name", "name") .setParam("organization", organization.getKey()) .execute(); - assertThat(db.getDbClient().qualityGateDao().selectById(db.getSession(), qualityGate.getId()).getName()).isEqualTo("name"); + assertThat(db.getDbClient().qualityGateDao().selectByUuid(db.getSession(), qualityGate.getUuid()).getName()).isEqualTo("name"); } @Test @@ -124,11 +124,11 @@ public class RenameActionTest { userSession.logIn("john").addPermission(ADMINISTER_QUALITY_GATES, db.getDefaultOrganization()); QualityGate result = ws.newRequest() - .setParam("id", qualityGate.getId().toString()) + .setParam("id", qualityGate.getUuid()) .setParam("name", "new name") .executeProtobuf(QualityGate.class); - assertThat(result.getId()).isEqualTo(qualityGate.getId()); + assertThat(result.getId()).isEqualTo(qualityGate.getUuid()); assertThat(result.getName()).isEqualTo("new name"); } @@ -142,7 +142,7 @@ public class RenameActionTest { expectedException.expectMessage(format("Operation forbidden for built-in Quality Gate '%s'", qualityGate.getName())); ws.newRequest() - .setParam("id", qualityGate.getId().toString()) + .setParam("id", qualityGate.getUuid()) .setParam("name", "name") .setParam("organization", organization.getKey()) .execute(); @@ -158,7 +158,7 @@ public class RenameActionTest { expectedException.expectMessage("The 'name' parameter is missing"); ws.newRequest() - .setParam("id", qualityGate.getId().toString()) + .setParam("id", qualityGate.getUuid()) .setParam("name", "") .setParam("organization", organization.getKey()) .execute(); @@ -175,7 +175,7 @@ public class RenameActionTest { expectedException.expectMessage(format("Name '%s' has already been taken", qualityGate2.getName())); ws.newRequest() - .setParam("id", qualityGate1.getId().toString()) + .setParam("id", qualityGate1.getUuid()) .setParam("name", qualityGate2.getName()) .setParam("organization", organization.getKey()) .execute(); @@ -204,7 +204,7 @@ public class RenameActionTest { expectedException.expect(ForbiddenException.class); ws.newRequest() - .setParam("id", qualityGate.getId().toString()) + .setParam("id", qualityGate.getUuid()) .setParam("name", "new name") .setParam("organization", organization.getKey()) .execute(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchActionTest.java index b3a569d29f4..6650f7c483e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SearchActionTest.java @@ -79,7 +79,7 @@ public class SearchActionTest { db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project), qualityGate); SearchResponse response = ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .executeProtobuf(SearchResponse.class); @@ -96,7 +96,7 @@ public class SearchActionTest { db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project), qualityGate); SearchResponse response = ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .executeProtobuf(SearchResponse.class); assertThat(response.getResultsList()) @@ -110,7 +110,7 @@ public class SearchActionTest { QualityGateDto qualityGate = db.qualityGates().insertQualityGate(organization); SearchResponse response = ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .executeProtobuf(SearchResponse.class); @@ -126,7 +126,7 @@ public class SearchActionTest { db.qualityGates().associateProjectToQualityGate(associatedProject, qualityGate); SearchResponse response = ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_SELECTED, ALL.value()) .executeProtobuf(SearchResponse.class); @@ -147,7 +147,7 @@ public class SearchActionTest { db.qualityGates().associateProjectToQualityGate(associatedProject, qualityGate); SearchResponse response = ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_SELECTED, SELECTED.value()) .executeProtobuf(SearchResponse.class); @@ -167,7 +167,7 @@ public class SearchActionTest { db.qualityGates().associateProjectToQualityGate(associatedProject, qualityGate); SearchResponse response = ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_SELECTED, DESELECTED.value()) .executeProtobuf(SearchResponse.class); @@ -190,7 +190,7 @@ public class SearchActionTest { userSession.logIn(user); SearchResponse response = ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_SELECTED, ALL.value()) .executeProtobuf(SearchResponse.class); @@ -209,7 +209,7 @@ public class SearchActionTest { userSession.logIn().setRoot(); SearchResponse response = ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_SELECTED, ALL.value()) .executeProtobuf(SearchResponse.class); @@ -230,7 +230,7 @@ public class SearchActionTest { // Return partial result on first page assertThat(ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_SELECTED, ALL.value()) .setParam(PARAM_PAGE, "1") @@ -242,7 +242,7 @@ public class SearchActionTest { // Return partial result on second page assertThat(ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_SELECTED, ALL.value()) .setParam(PARAM_PAGE, "2") @@ -254,7 +254,7 @@ public class SearchActionTest { // Return partial result on first page assertThat(ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_SELECTED, ALL.value()) .setParam(PARAM_PAGE, "1") @@ -266,7 +266,7 @@ public class SearchActionTest { // Return all result on first page assertThat(ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_SELECTED, ALL.value()) .setParam(PARAM_PAGE, "1") @@ -278,7 +278,7 @@ public class SearchActionTest { // Return no result as page index is off limit assertThat(ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_SELECTED, ALL.value()) .setParam(PARAM_PAGE, "3") @@ -300,7 +300,7 @@ public class SearchActionTest { userSession.addPermission(ADMINISTER_QUALITY_GATES, organization); SearchResponse response = ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_PAGE_SIZE, valueOf(5)) .setParam(PARAM_PAGE, valueOf(2)) @@ -325,7 +325,7 @@ public class SearchActionTest { userSession.addPermission(ADMINISTER_QUALITY_GATES, organization); SearchResponse response = ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_PAGE_SIZE, valueOf(100)) .setParam(PARAM_PAGE, valueOf(1)) @@ -351,7 +351,7 @@ public class SearchActionTest { db.qualityGates().associateProjectToQualityGate(otherProject, otherQualityGate); SearchResponse response = ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .setParam(PARAM_SELECTED, ALL.value()) .executeProtobuf(SearchResponse.class); @@ -381,10 +381,10 @@ public class SearchActionTest { QualityGateDto qualityGate = db.qualityGates().insertQualityGate(otherOrganization); expectedException.expect(NotFoundException.class); - expectedException.expectMessage(format("No quality gate has been found for id %s in organization %s", qualityGate.getId(), organization.getName())); + expectedException.expectMessage(format("No quality gate has been found for id %s in organization %s", qualityGate.getUuid(), organization.getName())); ws.newRequest() - .setParam(PARAM_GATE_ID, valueOf(qualityGate.getId())) + .setParam(PARAM_GATE_ID, valueOf(qualityGate.getUuid())) .setParam(PARAM_ORGANIZATION, organization.getKey()) .executeProtobuf(SearchResponse.class); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java index adcca4d1e5b..58dc9f17953 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/SelectActionTest.java @@ -66,7 +66,7 @@ public class SelectActionTest { ComponentDto project = db.components().insertPrivateProject(organization); ws.newRequest() - .setParam("gateId", qualityGate.getId().toString()) + .setParam("gateId", qualityGate.getUuid()) .setParam("projectKey", project.getKey()) .setParam("organization", organization.getKey()) .execute(); @@ -83,13 +83,13 @@ public class SelectActionTest { ComponentDto project = db.components().insertPrivateProject(organization); ws.newRequest() - .setParam("gateId", initialQualityGate.getId().toString()) + .setParam("gateId", initialQualityGate.getUuid()) .setParam("projectKey", project.getKey()) .setParam("organization", organization.getKey()) .execute(); ws.newRequest() - .setParam("gateId", secondQualityGate.getId().toString()) + .setParam("gateId", secondQualityGate.getUuid()) .setParam("projectKey", project.getKey()) .setParam("organization", organization.getKey()) .execute(); @@ -105,13 +105,13 @@ public class SelectActionTest { ComponentDto project = db.components().insertPrivateProject(organization); ws.newRequest() - .setParam("gateId", initialQualityGate.getId().toString()) + .setParam("gateId", initialQualityGate.getUuid()) .setParam("projectKey", project.getKey()) .setParam("organization", organization.getKey()) .execute(); ws.newRequest() - .setParam("gateId", initialQualityGate.getId().toString()) + .setParam("gateId", initialQualityGate.getUuid()) .setParam("projectKey", project.getKey()) .setParam("organization", organization.getKey()) .execute(); @@ -127,7 +127,7 @@ public class SelectActionTest { userSession.logIn().addProjectPermission(ADMIN, project); ws.newRequest() - .setParam("gateId", qualityGate.getId().toString()) + .setParam("gateId", qualityGate.getUuid()) .setParam("projectKey", project.getKey()) .setParam("organization", organization.getKey()) .execute(); @@ -143,7 +143,7 @@ public class SelectActionTest { ComponentDto project = db.components().insertPrivateProject(organization); ws.newRequest() - .setParam("gateId", qualityGate.getId().toString()) + .setParam("gateId", qualityGate.getUuid()) .setParam("projectKey", project.getKey()) .setParam("organization", organization.getKey()) .execute(); @@ -159,7 +159,7 @@ public class SelectActionTest { ComponentDto project = db.components().insertPrivateProject(organization); ws.newRequest() - .setParam("gateId", qualityGate.getId().toString()) + .setParam("gateId", qualityGate.getUuid()) .setParam("projectKey", project.getKey()) .execute(); @@ -178,7 +178,7 @@ public class SelectActionTest { expectedException.expectMessage(format("Project '%s' doesn't exist in organization '%s'", project.getKey(), organization.getKey())); ws.newRequest() - .setParam("gateId", qualityGate.getId().toString()) + .setParam("gateId", qualityGate.getUuid()) .setParam("projectKey", project.getKey()) .setParam("organization", organization.getKey()) .execute(); @@ -207,7 +207,7 @@ public class SelectActionTest { expectedException.expect(NotFoundException.class); ws.newRequest() - .setParam("gateId", qualityGate.getId().toString()) + .setParam("gateId", qualityGate.getUuid()) .setParam("projectKey", "unknown") .setParam("organization", organization.getKey()) .execute(); @@ -222,7 +222,7 @@ public class SelectActionTest { expectedException.expect(ForbiddenException.class); ws.newRequest() - .setParam("gateId", qualityGate.getId().toString()) + .setParam("gateId", qualityGate.getUuid()) .setParam("projectKey", project.getKey()) .setParam("organization", organization.getKey()) .execute(); @@ -237,7 +237,7 @@ public class SelectActionTest { expectedException.expect(ForbiddenException.class); ws.newRequest() - .setParam("gateId", qualityGate.getId().toString()) + .setParam("gateId", qualityGate.getUuid()) .setParam("projectKey", project.getDbKey()) .setParam("organization", organization.getKey()) .execute(); @@ -252,7 +252,7 @@ public class SelectActionTest { expectedException.expect(ForbiddenException.class); ws.newRequest() - .setParam("gateId", qualityGate.getId().toString()) + .setParam("gateId", qualityGate.getUuid()) .setParam("projectKey", project.getDbKey()) .setParam("organization", organization.getKey()) .execute(); @@ -270,7 +270,7 @@ public class SelectActionTest { expectedException.expectMessage(format("Project '%s' not found", branch.getDbKey())); ws.newRequest() - .setParam("gateId", qualityGate.getId().toString()) + .setParam("gateId", qualityGate.getUuid()) .setParam("projectKey", branch.getDbKey()) .setParam("organization", organization.getKey()) .execute(); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java index afe8370fce4..bbd5ebb8f87 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ShowActionTest.java @@ -82,7 +82,7 @@ public class ShowActionTest { .setParam("organization", organization.getKey()) .executeProtobuf(ShowWsResponse.class); - assertThat(response.getId()).isEqualTo(qualityGate.getId()); + assertThat(response.getId()).isEqualTo(qualityGate.getUuid()); assertThat(response.getName()).isEqualTo(qualityGate.getName()); assertThat(response.getIsBuiltIn()).isFalse(); assertThat(response.getConditionsList()).hasSize(2); @@ -104,7 +104,7 @@ public class ShowActionTest { .setParam("name", qualityGate.getName()) .executeProtobuf(ShowWsResponse.class); - assertThat(response.getId()).isEqualTo(qualityGate.getId()); + assertThat(response.getId()).isEqualTo(qualityGate.getUuid()); } @Test @@ -128,11 +128,11 @@ public class ShowActionTest { db.qualityGates().setDefaultQualityGate(organization, qualityGate); ShowWsResponse response = ws.newRequest() - .setParam("id", qualityGate.getId().toString()) + .setParam("id", qualityGate.getUuid()) .setParam("organization", organization.getKey()) .executeProtobuf(ShowWsResponse.class); - assertThat(response.getId()).isEqualTo(qualityGate.getId()); + assertThat(response.getId()).isEqualTo(qualityGate.getUuid()); assertThat(response.getName()).isEqualTo(qualityGate.getName()); } @@ -147,7 +147,7 @@ public class ShowActionTest { .setParam("organization", organization.getKey()) .executeProtobuf(ShowWsResponse.class); - assertThat(response.getId()).isEqualTo(qualityGate.getId()); + assertThat(response.getId()).isEqualTo(qualityGate.getUuid()); assertThat(response.getName()).isEqualTo(qualityGate.getName()); assertThat(response.getConditionsList()).isEmpty(); } @@ -279,7 +279,7 @@ public class ShowActionTest { ws.newRequest() .setParam("name", qualityGate.getName()) - .setParam("id", qualityGate.getId().toString()) + .setParam("id", qualityGate.getUuid()) .setParam("organization", organization.getKey()) .execute(); } @@ -367,10 +367,10 @@ public class ShowActionTest { QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(otherOrganization); expectedException.expect(NotFoundException.class); - expectedException.expectMessage(format("No quality gate has been found for id %s in organization %s", qualityGate.getId(), organization.getName())); + expectedException.expectMessage(format("No quality gate has been found for id %s in organization %s", qualityGate.getUuid(), organization.getName())); ws.newRequest() - .setParam("id", qualityGate.getId().toString()) + .setParam("id", qualityGate.getUuid()) .setParam("organization", organization.getKey()) .execute(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java index e6d773ad89c..08310d41349 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/UpdateConditionActionTest.java @@ -184,7 +184,7 @@ public class UpdateConditionActionTest { MetricDto metric = insertMetric(); QualityGateConditionDto condition = new QualityGateConditionDto().setUuid("uuid") .setMetricUuid("metric") - .setQualityGateId(123L); + .setQualityGateUuid("123"); db.getDbClient().gateConditionDao().insert(condition, dbSession); db.commit(); @@ -289,10 +289,10 @@ public class UpdateConditionActionTest { } private void assertCondition(QualityGateDto qualityGate, MetricDto metric, String operator, String error) { - assertThat(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getId())) - .extracting(QualityGateConditionDto::getQualityGateId, QualityGateConditionDto::getMetricUuid, QualityGateConditionDto::getOperator, + assertThat(dbClient.gateConditionDao().selectForQualityGate(dbSession, qualityGate.getUuid())) + .extracting(QualityGateConditionDto::getQualityGateUuid, QualityGateConditionDto::getMetricUuid, QualityGateConditionDto::getOperator, QualityGateConditionDto::getErrorThreshold) - .containsExactlyInAnyOrder(tuple(qualityGate.getId(), metric.getUuid(), operator, error)); + .containsExactlyInAnyOrder(tuple(qualityGate.getUuid(), metric.getUuid(), operator, error)); } private MetricDto insertMetric() { diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java index 83d45a54bd5..984282b4370 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java @@ -39,6 +39,7 @@ import org.sonar.core.component.DefaultResourceTypes; import org.sonar.core.extension.CoreExtensionRepository; import org.sonar.core.platform.PluginInfo; import org.sonar.core.platform.PluginRepository; +import org.sonar.core.util.UuidFactoryImpl; import org.sonar.db.DbClient; import org.sonar.db.DbTester; import org.sonar.db.alm.ALM; diff --git a/sonar-ws/build.gradle b/sonar-ws/build.gradle index 13f6597417b..a1640ab28b0 100644 --- a/sonar-ws/build.gradle +++ b/sonar-ws/build.gradle @@ -14,6 +14,7 @@ dependencies { compile 'com.google.protobuf:protobuf-java' compile 'com.squareup.okhttp3:okhttp' + compile 'com.google.code.gson:gson' compileOnly 'com.google.code.findbugs:jsr305' compileOnly 'javax.annotation:javax.annotation-api' diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java index ed2a93fb863..7b138c2a382 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/BaseService.java @@ -42,7 +42,11 @@ public abstract class BaseService { } protected <T extends Message> T call(BaseRequest request, Parser<T> parser) { - request.setMediaType(MediaTypes.PROTOBUF); + return call(request, parser, MediaTypes.PROTOBUF); + } + + protected <T extends Message> T call(BaseRequest request, Parser<T> parser, String mediaType) { + request.setMediaType(mediaType); WsResponse response = call(request); return convert(response, parser); } diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualityGatesServiceCreateResponseJsonParser.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualityGatesServiceCreateResponseJsonParser.java new file mode 100644 index 00000000000..3c60184e4d2 --- /dev/null +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualityGatesServiceCreateResponseJsonParser.java @@ -0,0 +1,188 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 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.sonarqube.ws.client.qualitygates; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.protobuf.ByteString; +import com.google.protobuf.CodedInputStream; +import com.google.protobuf.ExtensionRegistryLite; +import com.google.protobuf.InvalidProtocolBufferException; +import com.google.protobuf.Parser; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import org.sonarqube.ws.Qualitygates; + +public class QualityGatesServiceCreateResponseJsonParser implements Parser<Qualitygates.CreateResponse> { + + @Override + public Qualitygates.CreateResponse parseFrom(CodedInputStream input) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parseFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parsePartialFrom(CodedInputStream input) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parsePartialFrom(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parseFrom(ByteBuffer data) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parseFrom(ByteBuffer data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parseFrom(ByteString data) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parseFrom(ByteString data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parsePartialFrom(ByteString data) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parsePartialFrom(ByteString data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parseFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parseFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parseFrom(byte[] data) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parseFrom(byte[] data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parsePartialFrom(byte[] data, int off, int len) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parsePartialFrom(byte[] data, int off, int len, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parsePartialFrom(byte[] data) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parsePartialFrom(byte[] data, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parseFrom(InputStream input) throws InvalidProtocolBufferException { + Qualitygates.CreateResponse.Builder builder = Qualitygates.CreateResponse.newBuilder(); + String json = readInputStream(input); + JsonObject jobj = new Gson().fromJson(json, JsonObject.class); + builder.setId(jobj.get("id").getAsString()); + builder.setName(jobj.get("name").getAsString()); + return builder.build(); + } + + private String readInputStream(InputStream input) { + StringBuilder textBuilder = new StringBuilder(); + try (Reader reader = new BufferedReader(new InputStreamReader(input, Charset.forName(StandardCharsets.UTF_8.name())))) { + int c = 0; + while ((c = reader.read()) != -1) { + textBuilder.append((char) c); + } + } catch (IOException e) { + throw new IllegalArgumentException(e); + } + return textBuilder.toString(); + } + + @Override + public Qualitygates.CreateResponse parseFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parsePartialFrom(InputStream input) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parsePartialFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parseDelimitedFrom(InputStream input) throws InvalidProtocolBufferException { + return parseFrom(input); + } + + @Override + public Qualitygates.CreateResponse parseDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parsePartialDelimitedFrom(InputStream input) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } + + @Override + public Qualitygates.CreateResponse parsePartialDelimitedFrom(InputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException { + throw new IllegalStateException("not implemented"); + } +} diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualitygatesService.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualitygatesService.java index 3214ba6e92c..e878ab79eca 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualitygatesService.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/qualitygates/QualitygatesService.java @@ -57,8 +57,7 @@ public class QualitygatesService extends BaseService { .setParam("id", request.getId()) .setParam("name", request.getName()) .setParam("organization", request.getOrganization()) - .setMediaType(MediaTypes.JSON) - ).content(); + .setMediaType(MediaTypes.JSON)).content(); } /** @@ -77,6 +76,17 @@ public class QualitygatesService extends BaseService { } /** + * Use this for to use a JSON payload, useful to parse the quality gate as Long or String + */ + public CreateResponse createJson(CreateRequest request) { + return call( + new PostRequest(path("create")) + .setParam("name", request.getName()) + .setParam("organization", request.getOrganization()), + new QualityGatesServiceCreateResponseJsonParser(), MediaTypes.JSON); + } + + /** * This is part of the internal API. * This is a POST request. * @@ -106,8 +116,7 @@ public class QualitygatesService extends BaseService { new PostRequest(path("delete_condition")) .setParam("id", request.getId()) .setParam("organization", request.getOrganization()) - .setMediaType(MediaTypes.JSON) - ).content(); + .setMediaType(MediaTypes.JSON)).content(); } /** @@ -123,8 +132,7 @@ public class QualitygatesService extends BaseService { .setParam("organization", request.getOrganization()) .setParam("projectId", request.getProjectId()) .setParam("projectKey", request.getProjectKey()) - .setMediaType(MediaTypes.JSON) - ).content(); + .setMediaType(MediaTypes.JSON)).content(); } /** @@ -139,8 +147,7 @@ public class QualitygatesService extends BaseService { new PostRequest(path("destroy")) .setParam("id", request.getId()) .setParam("organization", request.getOrganization()) - .setMediaType(MediaTypes.JSON) - ).content(); + .setMediaType(MediaTypes.JSON)).content(); } /** @@ -203,8 +210,7 @@ public class QualitygatesService extends BaseService { .setParam("id", request.getId()) .setParam("name", request.getName()) .setParam("organization", request.getOrganization()) - .setMediaType(MediaTypes.JSON) - ).content(); + .setMediaType(MediaTypes.JSON)).content(); } /** @@ -240,8 +246,7 @@ public class QualitygatesService extends BaseService { .setParam("organization", request.getOrganization()) .setParam("projectId", request.getProjectId()) .setParam("projectKey", request.getProjectKey()) - .setMediaType(MediaTypes.JSON) - ).content(); + .setMediaType(MediaTypes.JSON)).content(); } /** @@ -256,8 +261,7 @@ public class QualitygatesService extends BaseService { new PostRequest(path("set_as_default")) .setParam("id", request.getId()) .setParam("organization", request.getOrganization()) - .setMediaType(MediaTypes.JSON) - ).content(); + .setMediaType(MediaTypes.JSON)).content(); } /** @@ -288,8 +292,7 @@ public class QualitygatesService extends BaseService { public String unsetDefault() { return call( new PostRequest(path("unset_default")) - .setMediaType(MediaTypes.JSON) - ).content(); + .setMediaType(MediaTypes.JSON)).content(); } /** diff --git a/sonar-ws/src/main/protobuf/ws-qualitygates.proto b/sonar-ws/src/main/protobuf/ws-qualitygates.proto index 097e3f56723..ced73a13574 100644 --- a/sonar-ws/src/main/protobuf/ws-qualitygates.proto +++ b/sonar-ws/src/main/protobuf/ws-qualitygates.proto @@ -75,7 +75,7 @@ message GetByProjectResponse { } message QualityGate { - optional int64 id = 1; + optional string id = 1; optional string name = 2; optional bool default = 3; } @@ -96,7 +96,7 @@ message AppResponse { // POST api/qualitygates/create message CreateResponse { - optional int64 id = 1; + optional string id = 1; optional string name = 2; } @@ -118,7 +118,7 @@ message UpdateConditionResponse { // GET api/qualitygates/show message ShowWsResponse { - optional int64 id = 1; + optional string id = 1; optional string name = 2; repeated Condition conditions = 3; optional bool isBuiltIn = 4; @@ -150,11 +150,11 @@ message SearchResponse { message ListWsResponse { repeated QualityGate qualitygates = 1; // Deprecated since 7.0 - optional int64 default = 2; + optional string default = 2; optional RootActions actions = 3; message QualityGate { - optional int64 id = 1; + optional string id = 1; optional string name = 2; optional bool isDefault = 3; optional bool isBuiltIn = 4; |