import static org.sonar.db.Pagination.forPage;
import static org.sonar.server.component.ComponentFinder.ParamNames.COMPONENT_ID_AND_COMPONENT;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
-import static org.sonarqube.ws.client.ce.CeWsParameters.DEPRECATED_PARAM_COMPONENT_KEY;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT;
import static org.sonarqube.ws.client.ce.CeWsParameters.PARAM_COMPONENT_ID;
WebService.NewAction action = controller.createAction("component")
.setDescription("Get the pending tasks, in-progress tasks and the last executed task of a given component (usually a project).<br>" +
"Requires the following permission: 'Browse' on the specified component.<br>" +
- "Either '%s' or '%s' must be provided, not both.",
- PARAM_COMPONENT_ID, DEPRECATED_PARAM_COMPONENT_KEY)
+ "Either '%s' or '%s' must be provided.",
+ PARAM_COMPONENT_ID, PARAM_COMPONENT)
.setSince("5.2")
.setResponseExample(getClass().getResource("component-example.json"))
.setChangelog(
import static org.sonar.server.ws.WsUtils.checkRequest;
public class ComponentFinder {
- private static final String MSG_COMPONENT_ID_OR_KEY_TEMPLATE = "Either '%s' or '%s' must be provided, not both";
+ private static final String MSG_COMPONENT_ID_OR_KEY_TEMPLATE = "Either '%s' or '%s' must be provided";
private static final String MSG_PARAMETER_MUST_NOT_BE_EMPTY = "The '%s' parameter must not be empty";
private static final String LABEL_PROJECT = "Project";
private static final String LABEL_COMPONENT = "Component";
private MetricDto searchMetric(DbSession dbSession, Request request) {
Integer metricId = request.paramAsInt(PARAM_METRIC_ID);
String metricKey = request.param(PARAM_METRIC_KEY);
- checkArgument(metricId != null ^ metricKey != null, "The metric id or the metric key must be provided, not both.");
+ checkArgument(metricId != null ^ metricKey != null, "Either the metric id or the metric key must be provided");
if (metricId != null) {
return dbClient.metricDao().selectOrFailById(dbSession, metricId);
}
public static ProjectWsRef newWsProjectRef(@Nullable String uuid, @Nullable String key) {
- checkRequest(uuid == null ^ key == null, MSG_ID_OR_KEY_MUST_BE_PROVIDED);
return new ProjectWsRef(uuid, key);
}
" <li>%s: my_</li>" +
" <li>%s: my_new_</li>" +
"</ul>" +
- "Either '%s' or '%s' must be provided, not both.<br> " +
+ "Either '%s' or '%s' must be provided.<br> " +
"Requires one of the following permissions: " +
"<ul>" +
"<li>'Administer System'</li>" +
public WebService.NewAction doDefine(WebService.NewController context) {
WebService.NewAction action = context.createAction(ACTION_UPDATE_KEY)
.setDescription("Update a project or module key and all its sub-components keys.<br>" +
- "Either '%s' or '%s' must be provided, not both.<br> " +
+ "Either '%s' or '%s' must be provided.<br> " +
"Requires one of the following permissions: " +
"<ul>" +
"<li>'Administer System'</li>" +
private static final String QG_STATUSES_ONE_LINE = Arrays.stream(ProjectStatusWsResponse.Status.values())
.map(Enum::toString)
.collect(Collectors.joining(", "));
- private static final String MSG_ONE_PARAMETER_ONLY = String.format("One (and only one) of the following parameters must be provided '%s', '%s', '%s'",
- PARAM_ANALYSIS_ID, PARAM_PROJECT_ID, PARAM_PROJECT_KEY);
+ private static final String MSG_ONE_PARAMETER_ONLY = String.format("Either '%s', '%s' or '%s' must be provided", PARAM_ANALYSIS_ID, PARAM_PROJECT_ID, PARAM_PROJECT_KEY);
private final DbClient dbClient;
private final ComponentFinder componentFinder;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.db.qualitygate.QualityGateConditionDto;
import org.sonar.db.qualitygate.QualityGateDto;
-import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.qualitygate.QualityGates;
-import org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters;
+
+import static org.sonar.server.ws.WsUtils.checkRequest;
+import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_ID;
+import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_NAME;
public class ShowAction implements QualityGatesWsAction {
.setResponseExample(Resources.getResource(this.getClass(), "example-show.json"))
.setHandler(this);
- action.createParam(QualityGatesWsParameters.PARAM_ID)
+ action.createParam(PARAM_ID)
.setDescription("ID of the quality gate. Either id or name must be set")
.setExampleValue("1");
- action.createParam(QualityGatesWsParameters.PARAM_NAME)
+ action.createParam(PARAM_NAME)
.setDescription("Name of the quality gate. Either id or name must be set")
.setExampleValue("My Quality Gate");
}
@Override
public void handle(Request request, Response response) {
- Long qGateId = request.paramAsLong(QualityGatesWsParameters.PARAM_ID);
- String qGateName = request.param(QualityGatesWsParameters.PARAM_NAME);
+ Long qGateId = request.paramAsLong(PARAM_ID);
+ String qGateName = request.param(PARAM_NAME);
checkOneOfIdOrNamePresent(qGateId, qGateName);
QualityGateDto qGate = qGateId == null ? qualityGates.get(qGateName) : qualityGates.get(qGateId);
try (JsonWriter writer = response.newJsonWriter()) {
writer.beginObject()
- .prop(QualityGatesWsParameters.PARAM_ID, qGate.getId())
- .prop(QualityGatesWsParameters.PARAM_NAME, qGate.getName());
+ .prop(PARAM_ID, qGate.getId())
+ .prop(PARAM_NAME, qGate.getName());
Collection<QualityGateConditionDto> conditions = qualityGates.listConditions(qGateId);
if (!conditions.isEmpty()) {
writer.name("conditions").beginArray();
}
private static void checkOneOfIdOrNamePresent(@Nullable Long qGateId, @Nullable String qGateName) {
- if (qGateId == null && qGateName == null) {
- throw BadRequestException.create("Either one of 'id' or 'name' is required.");
- } else if (qGateId != null && qGateName != null) {
- throw BadRequestException.create("Only one of 'id' or 'name' must be provided.");
- }
+ checkRequest(qGateId == null ^ qGateName == null, "Either '%s' or '%s' must be provided", PARAM_ID, PARAM_NAME);
}
-
}
public void define(WebService.NewController context) {
WebService.NewAction action = context.createAction(ACTION_SET)
.setDescription("Update a setting value.<br>" +
- "Either '%s' or '%s' must be provided, not both.<br> " +
+ "Either '%s' or '%s' must be provided.<br> " +
"Requires one of the following permissions: " +
"<ul>" +
"<li>'Administer System'</li>" +
request.getValue() != null
^ !request.getValues().isEmpty()
^ !request.getFieldValues().isEmpty(),
- "One and only one of '%s', '%s', '%s' must be provided", PARAM_VALUE, PARAM_VALUES, PARAM_FIELD_VALUES);
+ "Either '%s', '%s' or '%s' must be provided", PARAM_VALUE, PARAM_VALUES, PARAM_FIELD_VALUES);
checkRequest(request.getValues().stream().allMatch(StringUtils::isNotBlank), MSG_NO_EMPTY_VALUE);
checkRequest(request.getValue() == null || StringUtils.isNotBlank(request.getValue()), MSG_NO_EMPTY_VALUE);
}
.createAction("list")
.setDescription(String.format(
"Get the list of tests either in a test file or that test a given line of source code.<br /> " +
- "Require Browse permission on the file's project.<br /> " +
+ "Requires 'Browse' permission on the file's project.<br /> " +
"One (and only one) of the following combination of parameters must be provided: " +
"<ul>" +
"<li>%s - get a specific test</li>" +
public class WebhookDeliveriesAction implements WebhooksWsAction {
- private static final String COMPONENT_PARAM = "componentKey";
- private static final String TASK_PARAM = "ceTaskId";
+ private static final String PARAM_COMPONENT = "componentKey";
+ private static final String PARAM_TASK = "ceTaskId";
private final DbClient dbClient;
private final UserSession userSession;
.setResponseExample(Resources.getResource(this.getClass(), "example-deliveries.json"))
.setHandler(this);
- action.createParam(COMPONENT_PARAM)
+ action.createParam(PARAM_COMPONENT)
.setDescription("Key of the project")
.setExampleValue("my-project");
- action.createParam(TASK_PARAM)
+ action.createParam(PARAM_TASK)
.setDescription("Id of the Compute Engine task")
.setExampleValue(Uuids.UUID_EXAMPLE_01);
}
// fail-fast if not logged in
userSession.checkLoggedIn();
- String ceTaskId = request.param(TASK_PARAM);
- String componentKey = request.param(COMPONENT_PARAM);
- checkArgument(ceTaskId != null ^ componentKey != null, "Either parameter '%s' or '%s' must be defined", TASK_PARAM, COMPONENT_PARAM);
+ String ceTaskId = request.param(PARAM_TASK);
+ String componentKey = request.param(PARAM_COMPONENT);
+ checkArgument(ceTaskId != null ^ componentKey != null, "Either '%s' or '%s' must be provided", PARAM_TASK, PARAM_COMPONENT);
Data data = loadFromDatabase(ceTaskId, componentKey);
data.ensureAdminPermission(userSession);
@Test
public void fail_when_the_uuid_and_key_are_null() {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either 'id' or 'key' must be provided, not both");
+ expectedException.expectMessage("Either 'id' or 'key' must be provided");
underTest.getByUuidOrKey(dbSession, null, null, ID_AND_KEY);
}
@Test
public void fail_when_the_uuid_and_key_are_provided() {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either 'id' or 'key' must be provided, not both");
+ expectedException.expectMessage("Either 'id' or 'key' must be provided");
underTest.getByUuidOrKey(dbSession, "project-uuid", "project-key", ID_AND_KEY);
}
@Test
public void fail_if_no_parameter_provided() {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either 'componentId' or 'component' must be provided, not both");
+ expectedException.expectMessage("Either 'componentId' or 'component' must be provided");
ws.newRequest().execute();
}
@Test
public void fail_when_no_base_component_parameter() {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either 'componentId' or 'component' must be provided, not both");
+ expectedException.expectMessage("Either 'componentId' or 'component' must be provided");
ws.newRequest().execute();
}
@Test
public void fail_if_no_parameter_provided() {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either 'uuid' or 'key' must be provided, not both");
+ expectedException.expectMessage("Either 'uuid' or 'key' must be provided");
newBaseRequest().execute();
}
@Test
public void fail_when_project_id_nor_project_key_provided() throws Exception {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided, not both");
+ expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided");
MetricDto metric = insertMetric(STRING);
newRequest()
@Test
public void fail_when_project_id_and_project_key_are_provided() throws Exception {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided, not both");
+ expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided");
MetricDto metric = insertMetric(STRING);
newRequest()
@Test
public void fail_when_metric_id_nor_metric_key_is_provided() throws Exception {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("The metric id or the metric key must be provided, not both.");
+ expectedException.expectMessage("Either the metric id or the metric key must be provided");
insertMetric(STRING);
newRequest()
@Test
public void fail_when_metric_id_and_metric_key_are_provided() throws Exception {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("The metric id or the metric key must be provided, not both.");
+ expectedException.expectMessage("Either the metric id or the metric key must be provided");
MetricDto metric = insertMetric(STRING);
newRequest()
@Test
public void fail_when_project_id_and_project_key_provided() throws Exception {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided, not both");
+ expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided");
newRequest()
.setParam(SearchAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID)
@Test
public void fail_when_project_id_nor_project_key_provided() throws Exception {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided, not both");
+ expectedException.expectMessage("Either 'projectId' or 'projectKey' must be provided");
newRequest().execute();
}
logInAsSystemAdministrator();
expectedException.expect(BadRequestException.class);
- expectedException.expectMessage("One (and only one) of the following parameters must be provided 'analysisId', 'projectId', 'projectKey'");
+ expectedException.expectMessage("Either 'analysisId', 'projectId' or 'projectKey' must be provided");
ws.newRequest()
.setParam(PARAM_ANALYSIS_ID, "analysis-id")
logInAsSystemAdministrator();
expectedException.expect(BadRequestException.class);
- expectedException.expectMessage("One (and only one) of the following parameters must be provided 'analysisId', 'projectId', 'projectKey'");
+ expectedException.expectMessage("Either 'analysisId', 'projectId' or 'projectKey' must be provided");
ws.newRequest().execute().getInput();
}
QProfileDto profile = createProfile(db.getDefaultOrganization(), false);
expectedException.expect(BadRequestException.class);
- expectedException.expectMessage("Either 'key' or 'language' must be provided.");
+ expectedException.expectMessage("Either 'key' or 'language' must be provided");
WsActionTester ws = newWsActionTester(newExporter("polop"), newExporter("palap"));
ws.newRequest()
@Test
public void fail_when_no_value() {
expectedException.expect(BadRequestException.class);
- expectedException.expectMessage("One and only one of 'value', 'values', 'fieldValues' must be provided");
+ expectedException.expectMessage("Either 'value', 'values' or 'fieldValues' must be provided");
callForGlobalSetting("my.key", null);
}
@Test
public void fail_when_single_and_multi_value_provided() {
expectedException.expect(BadRequestException.class);
- expectedException.expectMessage("One and only one of 'value', 'values', 'fieldValues' must be provided");
+ expectedException.expectMessage("Either 'value', 'values' or 'fieldValues' must be provided");
call("my.key", "My Value", newArrayList("Another Value"), null, null);
}
@Test
public void fail_when_no_uuid_or_key_param() throws Exception {
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either 'uuid' or 'key' must be provided, not both");
+ expectedException.expectMessage("Either 'uuid' or 'key' must be provided");
WsTester.TestRequest request = wsTester.newGetRequest("api/sources", "lines");
request.execute();
assertThat(action.responseExampleAsString()).isNotEmpty();
assertThat(action.params()).hasSize(9);
assertThat(action.description()).isEqualTo("Get the list of tests either in a test file or that test a given line of source code.<br /> " +
- "Require Browse permission on the file's project.<br /> " +
+ "Requires 'Browse' permission on the file's project.<br /> " +
"One (and only one) of the following combination of parameters must be provided: " +
"<ul>" +
"<li>testId - get a specific test</li>" +
userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either parameter 'ceTaskId' or 'componentKey' must be defined");
+ expectedException.expectMessage("Either 'ceTaskId' or 'componentKey' must be provided");
ws.newRequest()
.setParam("componentKey", project.getDbKey())
WsResponse result = adminWsClient.wsConnector().call(new GetRequest("api/duplications/show"));
assertThat(result.code()).isEqualTo(HTTP_BAD_REQUEST);
- assertThat(result.content()).contains("Either 'uuid' or 'key' must be provided, not both");
+ assertThat(result.content()).contains("Either 'uuid' or 'key' must be provided");
}
}