.getInput(); | .getInput(); | ||||
assertJson(response).isSimilarTo("{\n" + | assertJson(response).isSimilarTo("{\n" + | ||||
" \"total\": 1,\n" + | |||||
" \"p\": 1,\n" + | |||||
" \"ps\": 50,\n" + | |||||
" \"paging\": {\n" + | " \"paging\": {\n" + | ||||
" \"pageIndex\": 1,\n" + | " \"pageIndex\": 1,\n" + | ||||
" \"pageSize\": 50,\n" + | " \"pageSize\": 50,\n" + | ||||
.execute() | .execute() | ||||
.getInput(); | .getInput(); | ||||
assertJson(response).isSimilarTo("{\"total\":0,\"p\":1,\"ps\":50,\"paging\":{\"pageIndex\":1,\"pageSize\":50,\"total\":0},\"events\":[]}"); | |||||
assertJson(response).isSimilarTo("{\"paging\":{\"pageIndex\":1,\"pageSize\":50,\"total\":0},\"events\":[]}"); | |||||
} | } | ||||
@Test | @Test | ||||
.setChangeType(ActiveRuleChange.Type.ACTIVATED.name()) | .setChangeType(ActiveRuleChange.Type.ACTIVATED.name()) | ||||
.setData(ImmutableMap.of("severity", "MAJOR", "param_format", "^[A-Z][a-zA-Z0-9]*$", "ruleUuid", rule3.getUuid()))); | .setData(ImmutableMap.of("severity", "MAJOR", "param_format", "^[A-Z][a-zA-Z0-9]*$", "ruleUuid", rule3.getUuid()))); | ||||
ws.newRequest() | |||||
String result = ws.newRequest() | |||||
.setMethod("GET") | .setMethod("GET") | ||||
.setParam(PARAM_LANGUAGE, profile.getLanguage()) | .setParam(PARAM_LANGUAGE, profile.getLanguage()) | ||||
.setParam(PARAM_QUALITY_PROFILE, profile.getName()) | .setParam(PARAM_QUALITY_PROFILE, profile.getName()) | ||||
.setParam("ps", "10") | .setParam("ps", "10") | ||||
.execute() | .execute() | ||||
.assertJson(this.getClass(), "changelog_example.json"); | |||||
.getInput(); | |||||
assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString()); | |||||
} | } | ||||
@Test | @Test |
.setParam(WebService.Param.FIELDS, "actives") | .setParam(WebService.Param.FIELDS, "actives") | ||||
.executeProtobuf(Rules.SearchResponse.class); | .executeProtobuf(Rules.SearchResponse.class); | ||||
assertThat(response.getTotal()).isZero(); | |||||
assertThat(response.getP()).isOne(); | |||||
assertThat(response.getPaging().getTotal()).isZero(); | assertThat(response.getPaging().getTotal()).isZero(); | ||||
assertThat(response.getPaging().getPageIndex()).isOne(); | assertThat(response.getPaging().getPageIndex()).isOne(); | ||||
assertThat(response.getPaging().getPageSize()).isNotZero(); | assertThat(response.getPaging().getPageSize()).isNotZero(); | ||||
SearchResponse result = ws.newRequest() | SearchResponse result = ws.newRequest() | ||||
.setParam("f", "langName") | .setParam("f", "langName") | ||||
.executeProtobuf(SearchResponse.class); | .executeProtobuf(SearchResponse.class); | ||||
assertThat(result.getTotal()).isOne(); | |||||
assertThat(result.getPaging().getTotal()).isOne(); | assertThat(result.getPaging().getTotal()).isOne(); | ||||
assertThat(result.getPaging().getPageIndex()).isOne(); | assertThat(result.getPaging().getPageIndex()).isOne(); | ||||
assertThat(result.getRulesCount()).isOne(); | assertThat(result.getRulesCount()).isOne(); | ||||
SearchResponse result = ws.newRequest() | SearchResponse result = ws.newRequest() | ||||
.setParam("f", "debtRemFn,remFnOverloaded,defaultDebtRemFn") | .setParam("f", "debtRemFn,remFnOverloaded,defaultDebtRemFn") | ||||
.executeProtobuf(SearchResponse.class); | .executeProtobuf(SearchResponse.class); | ||||
assertThat(result.getTotal()).isOne(); | |||||
assertThat(result.getPaging().getTotal()).isOne(); | assertThat(result.getPaging().getTotal()).isOne(); | ||||
assertThat(result.getPaging().getPageIndex()).isOne(); | assertThat(result.getPaging().getPageIndex()).isOne(); | ||||
assertThat(result.getRulesCount()).isOne(); | assertThat(result.getRulesCount()).isOne(); | ||||
SearchResponse result = ws.newRequest() | SearchResponse result = ws.newRequest() | ||||
.setParam("f", "debtRemFn,remFnOverloaded,defaultDebtRemFn") | .setParam("f", "debtRemFn,remFnOverloaded,defaultDebtRemFn") | ||||
.executeProtobuf(SearchResponse.class); | .executeProtobuf(SearchResponse.class); | ||||
assertThat(result.getTotal()).isOne(); | |||||
assertThat(result.getPaging().getTotal()).isOne(); | assertThat(result.getPaging().getTotal()).isOne(); | ||||
assertThat(result.getPaging().getPageIndex()).isOne(); | assertThat(result.getPaging().getPageIndex()).isOne(); | ||||
assertThat(result.getRulesCount()).isOne(); | assertThat(result.getRulesCount()).isOne(); | ||||
SearchResponse result = ws.newRequest() | SearchResponse result = ws.newRequest() | ||||
.setParam("f", "debtRemFn,remFnOverloaded,defaultDebtRemFn") | .setParam("f", "debtRemFn,remFnOverloaded,defaultDebtRemFn") | ||||
.executeProtobuf(SearchResponse.class); | .executeProtobuf(SearchResponse.class); | ||||
assertThat(result.getTotal()).isOne(); | |||||
assertThat(result.getPaging().getTotal()).isOne(); | assertThat(result.getPaging().getTotal()).isOne(); | ||||
assertThat(result.getPaging().getPageIndex()).isOne(); | assertThat(result.getPaging().getPageIndex()).isOne(); | ||||
assertThat(result.getRulesCount()).isOne(); | assertThat(result.getRulesCount()).isOne(); | ||||
.setParam("f", "isTemplate") | .setParam("f", "isTemplate") | ||||
.setParam("is_template", "true") | .setParam("is_template", "true") | ||||
.executeProtobuf(SearchResponse.class); | .executeProtobuf(SearchResponse.class); | ||||
assertThat(result.getTotal()).isOne(); | |||||
assertThat(result.getPaging().getTotal()).isOne(); | assertThat(result.getPaging().getTotal()).isOne(); | ||||
assertThat(result.getPaging().getPageIndex()).isOne(); | assertThat(result.getPaging().getPageIndex()).isOne(); | ||||
assertThat(result.getRulesCount()).isOne(); | assertThat(result.getRulesCount()).isOne(); | ||||
.setParam("f", "templateKey") | .setParam("f", "templateKey") | ||||
.setParam("template_key", templateRule.getRepositoryKey() + ":" + templateRule.getRuleKey()) | .setParam("template_key", templateRule.getRepositoryKey() + ":" + templateRule.getRuleKey()) | ||||
.executeProtobuf(SearchResponse.class); | .executeProtobuf(SearchResponse.class); | ||||
assertThat(result.getTotal()).isOne(); | |||||
assertThat(result.getPaging().getTotal()).isOne(); | assertThat(result.getPaging().getTotal()).isOne(); | ||||
assertThat(result.getPaging().getPageIndex()).isOne(); | assertThat(result.getPaging().getPageIndex()).isOne(); | ||||
assertThat(result.getRulesCount()).isOne(); | assertThat(result.getRulesCount()).isOne(); | ||||
SearchResponse result = ws.newRequest().executeProtobuf(SearchResponse.class); | SearchResponse result = ws.newRequest().executeProtobuf(SearchResponse.class); | ||||
assertThat(result.getTotal()).isZero(); | |||||
assertThat(result.getPaging().getTotal()).isZero(); | assertThat(result.getPaging().getTotal()).isZero(); | ||||
assertThat(result.getPaging().getPageIndex()).isOne(); | assertThat(result.getPaging().getPageIndex()).isOne(); | ||||
assertThat(result.getRulesCount()).isZero(); | assertThat(result.getRulesCount()).isZero(); | ||||
.setParam("q", rule.getName()) | .setParam("q", rule.getName()) | ||||
.setParam("activation", "true") | .setParam("activation", "true") | ||||
.executeProtobuf(SearchResponse.class); | .executeProtobuf(SearchResponse.class); | ||||
assertThat(result.getTotal()).isOne(); | |||||
assertThat(result.getPaging().getTotal()).isOne(); | assertThat(result.getPaging().getTotal()).isOne(); | ||||
assertThat(result.getPaging().getPageIndex()).isOne(); | assertThat(result.getPaging().getPageIndex()).isOne(); | ||||
assertThat(result.getRulesCount()).isOne(); | assertThat(result.getRulesCount()).isOne(); | ||||
.setParam("activation", "true") | .setParam("activation", "true") | ||||
.setParam("qprofile", profile.getKee()) | .setParam("qprofile", profile.getKee()) | ||||
.executeProtobuf(SearchResponse.class); | .executeProtobuf(SearchResponse.class); | ||||
assertThat(result.getTotal()).isOne(); | |||||
assertThat(result.getPaging().getTotal()).isOne(); | assertThat(result.getPaging().getTotal()).isOne(); | ||||
assertThat(result.getPaging().getPageIndex()).isOne(); | assertThat(result.getPaging().getPageIndex()).isOne(); | ||||
assertThat(result.getRulesCount()).isOne(); | assertThat(result.getRulesCount()).isOne(); | ||||
.setParam("qprofile", profile.getKee()) | .setParam("qprofile", profile.getKee()) | ||||
.executeProtobuf(SearchResponse.class); | .executeProtobuf(SearchResponse.class); | ||||
assertThat(result.getTotal()).isOne(); | |||||
assertThat(result.getPaging().getTotal()).isOne(); | assertThat(result.getPaging().getTotal()).isOne(); | ||||
assertThat(result.getPaging().getPageIndex()).isOne(); | assertThat(result.getPaging().getPageIndex()).isOne(); | ||||
assertThat(result.getRulesCount()).isOne(); | assertThat(result.getRulesCount()).isOne(); | ||||
requestPopulator.accept(request); | requestPopulator.accept(request); | ||||
Rules.SearchResponse response = request.executeProtobuf(Rules.SearchResponse.class); | Rules.SearchResponse response = request.executeProtobuf(Rules.SearchResponse.class); | ||||
assertThat(response.getP()).isOne(); | |||||
assertThat(response.getPaging().getPageIndex()).isOne(); | assertThat(response.getPaging().getPageIndex()).isOne(); | ||||
assertThat(response.getPaging().getPageSize()).isNotZero(); | assertThat(response.getPaging().getPageSize()).isNotZero(); | ||||
RuleKey[] expectedRuleKeys = stream(expectedRules).map(RuleDto::getKey).toList().toArray(new RuleKey[0]); | RuleKey[] expectedRuleKeys = stream(expectedRules).map(RuleDto::getKey).toList().toArray(new RuleKey[0]); | ||||
assertThat(response.getRulesList()) | assertThat(response.getRulesList()) | ||||
.extracting(r -> RuleKey.parse(r.getKey())) | .extracting(r -> RuleKey.parse(r.getKey())) | ||||
.containsExactlyInAnyOrder(expectedRuleKeys); | .containsExactlyInAnyOrder(expectedRuleKeys); | ||||
assertThat(response.getTotal()).isEqualTo(expectedRules.length); | |||||
assertThat(response.getPaging().getTotal()).isEqualTo(expectedRules.length); | assertThat(response.getPaging().getTotal()).isEqualTo(expectedRules.length); | ||||
assertThat(response.getRulesCount()).isEqualTo(expectedRules.length); | assertThat(response.getRulesCount()).isEqualTo(expectedRules.length); | ||||
} | } |
assertThat(wsDef.since()).isEqualTo("5.2"); | assertThat(wsDef.since()).isEqualTo("5.2"); | ||||
assertThat(wsDef.isPost()).isFalse(); | assertThat(wsDef.isPost()).isFalse(); | ||||
assertThat(wsDef.changelog()).extracting(Change::getVersion, Change::getDescription).containsOnly( | assertThat(wsDef.changelog()).extracting(Change::getVersion, Change::getDescription).containsOnly( | ||||
tuple("10.2", "Response fields 'total', 's', 'ps' dropped"), | |||||
tuple("10.0", "Field 'managed' added to the payload."), | tuple("10.0", "Field 'managed' added to the payload."), | ||||
tuple("10.0", "Parameter 'id' is removed. Use 'name' instead."), | tuple("10.0", "Parameter 'id' is removed. Use 'name' instead."), | ||||
tuple("9.8", "response fields 'total', 's', 'ps' have been deprecated, please use 'paging' object instead."), | tuple("9.8", "response fields 'total', 's', 'ps' have been deprecated, please use 'paging' object instead."), | ||||
assertJson(result).isSimilarTo(""" | assertJson(result).isSimilarTo(""" | ||||
{ | { | ||||
"p": 1, | |||||
"total": 0, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 1, | "pageIndex": 1, | ||||
"pageSize": 25, | "pageSize": 25, | ||||
.execute() | .execute() | ||||
.getInput()).isSimilarTo(""" | .getInput()).isSimilarTo(""" | ||||
{ | { | ||||
"p": 1, | |||||
"ps": 1, | |||||
"total": 2, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 1, | "pageIndex": 1, | ||||
"pageSize": 1, | "pageSize": 1, | ||||
.execute() | .execute() | ||||
.getInput()).isSimilarTo(""" | .getInput()).isSimilarTo(""" | ||||
{ | { | ||||
"p": 2, | |||||
"ps": 1, | |||||
"total": 2, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 2, | "pageIndex": 2, | ||||
"pageSize": 1, | "pageSize": 1, |
{ | { | ||||
"total": 0, | |||||
"paging": { | |||||
"total": 0 | |||||
}, | |||||
"issues": [] | "issues": [] | ||||
} | } |
{ | { | ||||
"total": 501, | |||||
"p": 1, | |||||
"ps": 100, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 1, | "pageIndex": 1, | ||||
"pageSize": 100, | "pageSize": 100, |
{ | { | ||||
"total": 0, | |||||
"p": 1, | |||||
"ps": 100, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 1, | "pageIndex": 1, | ||||
"pageSize": 100, | "pageSize": 100, |
{ | { | ||||
"total": 0, | |||||
"p": 1, | |||||
"ps": 100, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 1, | "pageIndex": 1, | ||||
"pageSize": 100, | "pageSize": 100, |
{ | { | ||||
"total": 1, | |||||
"p": 1, | |||||
"ps": 100, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 1, | "pageIndex": 1, | ||||
"pageSize": 100, | "pageSize": 100, |
{ | { | ||||
"total": 2, | |||||
"p": 1, | |||||
"ps": 100, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 1, | "pageIndex": 1, | ||||
"pageSize": 100, | "pageSize": 100, |
{ | { | ||||
"total": 2, | |||||
"p": 1, | |||||
"ps": 100, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 1, | "pageIndex": 1, | ||||
"pageSize": 100, | "pageSize": 100, |
{ | { | ||||
"total": 2, | |||||
"p": 1, | |||||
"ps": 100, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 1, | "pageIndex": 1, | ||||
"pageSize": 100, | "pageSize": 100, |
{ | { | ||||
"total": 1, | |||||
"p": 1, | |||||
"ps": 100, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 1, | "pageIndex": 1, | ||||
"pageSize": 100, | "pageSize": 100, |
{ | { | ||||
"total": 0, | |||||
"issues": [], | "issues": [], | ||||
"paging": { | "paging": { | ||||
"pageIndex": 1, | "pageIndex": 1, |
{ | { | ||||
"total": 12, | |||||
"p": 2, | |||||
"ps": 9, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 2, | "pageIndex": 2, | ||||
"pageSize": 9, | "pageSize": 9, |
{ | { | ||||
"total": 1, | |||||
"p": 1, | |||||
"ps": 100, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 1, | "pageIndex": 1, | ||||
"pageSize": 100, | "pageSize": 100, |
{ | { | ||||
"total": 3, | |||||
"p": 1, | |||||
"ps": 100, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 1, | "pageIndex": 1, | ||||
"pageSize": 100, | "pageSize": 100, |
{ | |||||
"total": 3, | |||||
"ps": 10, | |||||
"p": 1, | |||||
"paging": { | |||||
"pageSize": 10, | |||||
"total": 3, | |||||
"pageIndex": 1 | |||||
}, | |||||
"events": [ | |||||
{ | |||||
"date" : "2015-02-23T17:58:39+0100", | |||||
"action" : "ACTIVATED", | |||||
"authorLogin" : "anakin.skywalker", | |||||
"authorName" : "Anakin Skywalker", | |||||
"ruleKey" : "java:S2438", | |||||
"ruleName" : "\"Threads\" should not be used where \"Runnables\" are expected", | |||||
"params" : { | |||||
"severity" : "CRITICAL" | |||||
} | |||||
}, | |||||
{ | |||||
"date" : "2015-02-23T17:58:18+0100", | |||||
"action" : "DEACTIVATED", | |||||
"authorLogin" : "padme.amidala", | |||||
"authorName" : "Padme Amidala", | |||||
"ruleKey" : "java:S2162", | |||||
"ruleName" : "\"equals\" methods should be symmetric and work for subclasses" | |||||
}, | |||||
{ | |||||
"action" : "ACTIVATED", | |||||
"authorLogin" : "obiwan.kenobi", | |||||
"authorName" : "Obiwan Kenobi", | |||||
"ruleKey" : "java:S00101", | |||||
"ruleName" : "Class names should comply with a naming convention", | |||||
"date" : "2014-09-12T15:20:46+0200", | |||||
"params" : { | |||||
"severity" : "MAJOR", | |||||
"format" : "^[A-Z][a-zA-Z0-9]*$" | |||||
} | |||||
} | |||||
] | |||||
} |
{ | { | ||||
"total": 12, | |||||
"p": 2, | |||||
"ps": 9, | |||||
"paging": { | "paging": { | ||||
"pageIndex": 2, | "pageIndex": 2, | ||||
"pageSize": 9, | "pageSize": 9, |
+ "<br/>When issue indexation is in progress returns 503 service unavailable HTTP code.") | + "<br/>When issue indexation is in progress returns 503 service unavailable HTTP code.") | ||||
.setSince("3.6") | .setSince("3.6") | ||||
.setChangelog( | .setChangelog( | ||||
new Change("10.2", "Response fields 'total', 's', 'ps' dropped"), | |||||
new Change("10.2", format("Parameter '%s' renamed to '%s'", PARAM_COMPONENT_KEYS, PARAM_COMPONENTS)), | new Change("10.2", format("Parameter '%s' renamed to '%s'", PARAM_COMPONENT_KEYS, PARAM_COMPONENTS)), | ||||
new Change("10.1", "Add the 'codeVariants' parameter, facet and response field"), | new Change("10.1", "Add the 'codeVariants' parameter, facet and response field"), | ||||
new Change("10.0", "Parameter 'sansTop25' is deprecated"), | new Change("10.0", "Parameter 'sansTop25' is deprecated"), |
SearchWsResponse formatSearch(Set<SearchAdditionalField> fields, SearchResponseData data, Paging paging, Facets facets) { | SearchWsResponse formatSearch(Set<SearchAdditionalField> fields, SearchResponseData data, Paging paging, Facets facets) { | ||||
SearchWsResponse.Builder response = SearchWsResponse.newBuilder(); | SearchWsResponse.Builder response = SearchWsResponse.newBuilder(); | ||||
formatPaging(paging, response); | |||||
response.setPaging(formatPaging(paging)); | |||||
ofNullable(data.getEffortTotal()).ifPresent(response::setEffortTotal); | ofNullable(data.getEffortTotal()).ifPresent(response::setEffortTotal); | ||||
response.addAllIssues(createIssues(fields, data)); | response.addAllIssues(createIssues(fields, data)); | ||||
response.addAllComponents(formatComponents(data)); | response.addAllComponents(formatComponents(data)); | ||||
return response.build(); | return response.build(); | ||||
} | } | ||||
private static void formatPaging(Paging paging, SearchWsResponse.Builder response) { | |||||
response.setP(paging.pageIndex()); | |||||
response.setPs(paging.pageSize()); | |||||
response.setTotal(paging.total()); | |||||
response.setPaging(formatPaging(paging)); | |||||
} | |||||
private static Common.Paging.Builder formatPaging(Paging paging) { | private static Common.Paging.Builder formatPaging(Paging paging) { | ||||
return Common.Paging.newBuilder() | return Common.Paging.newBuilder() | ||||
.setPageIndex(paging.pageIndex()) | .setPageIndex(paging.pageIndex()) |
.setDescription("Get the history of changes on a quality profile: rule activation/deactivation, change in parameters/severity. " + | .setDescription("Get the history of changes on a quality profile: rule activation/deactivation, change in parameters/severity. " + | ||||
"Events are ordered by date in descending order (most recent first).") | "Events are ordered by date in descending order (most recent first).") | ||||
.setChangelog( | .setChangelog( | ||||
new org.sonar.api.server.ws.Change("10.2", "Response fields 'total', 's', 'ps' dropped"), | |||||
new org.sonar.api.server.ws.Change("9.8", "response fields 'total', 's', 'ps' have been deprecated, please use 'paging' object instead"), | new org.sonar.api.server.ws.Change("9.8", "response fields 'total', 's', 'ps' have been deprecated, please use 'paging' object instead"), | ||||
new org.sonar.api.server.ws.Change("9.8", "The field 'paging' has been added to the response")) | new org.sonar.api.server.ws.Change("9.8", "The field 'paging' has been added to the response")) | ||||
.setHandler(this) | .setHandler(this) | ||||
Map<String, UserDto> usersByUuid, Map<String, RuleDto> rulesByRuleUuids) { | Map<String, UserDto> usersByUuid, Map<String, RuleDto> rulesByRuleUuids) { | ||||
json.beginObject(); | json.beginObject(); | ||||
writePaging(json, total, page, pageSize); | writePaging(json, total, page, pageSize); | ||||
json.name("paging").beginObject() | |||||
.prop("pageIndex", page) | |||||
.prop("pageSize", pageSize) | |||||
.prop("total", total) | |||||
.endObject(); | |||||
json.name("events").beginArray(); | json.name("events").beginArray(); | ||||
changelogs.forEach(change -> { | changelogs.forEach(change -> { | ||||
JsonWriter changeWriter = json.beginObject(); | JsonWriter changeWriter = json.beginObject(); | ||||
json.endObject(); | json.endObject(); | ||||
} | } | ||||
/** | |||||
* @deprecated since 9.8 - replaced by 'paging' object structure. | |||||
*/ | |||||
@Deprecated(since = "9.8") | |||||
private static void writePaging(JsonWriter json, int total, int page, int pageSize) { | private static void writePaging(JsonWriter json, int total, int page, int pageSize) { | ||||
json.prop("total", total); | |||||
json.prop(Param.PAGE, page); | |||||
json.prop(Param.PAGE_SIZE, pageSize); | |||||
json.name("paging").beginObject() | |||||
.prop("pageIndex", page) | |||||
.prop("pageSize", pageSize) | |||||
.prop("total", total) | |||||
.endObject(); | |||||
} | } | ||||
/** | /** |
new Change("10.0", "The value 'debtRemFn' for the 'f' parameter has been deprecated, use 'remFn' instead"), | new Change("10.0", "The value 'debtRemFn' for the 'f' parameter has been deprecated, use 'remFn' instead"), | ||||
new Change("10.0", "The value 'defaultDebtRemFn' for the 'f' parameter has been deprecated, use 'defaultRemFn' instead"), | new Change("10.0", "The value 'defaultDebtRemFn' for the 'f' parameter has been deprecated, use 'defaultRemFn' instead"), | ||||
new Change("10.0", "The value 'sansTop25' for the parameter 'facets' has been deprecated"), | new Change("10.0", "The value 'sansTop25' for the parameter 'facets' has been deprecated"), | ||||
new Change("10.0", "Parameter 'sansTop25' is deprecated") | |||||
new Change("10.0", "Parameter 'sansTop25' is deprecated"), | |||||
new Change("10.2", "Response fields 'total', 's', 'ps' dropped") | |||||
); | ); | ||||
action.createParam(FACETS) | action.createParam(FACETS) | ||||
private SearchResponse buildResponse(DbSession dbSession, SearchRequest request, SearchOptions context, SearchResult result, RuleQuery query) { | private SearchResponse buildResponse(DbSession dbSession, SearchRequest request, SearchOptions context, SearchResult result, RuleQuery query) { | ||||
SearchResponse.Builder responseBuilder = SearchResponse.newBuilder(); | SearchResponse.Builder responseBuilder = SearchResponse.newBuilder(); | ||||
writeStatistics(responseBuilder, result, context); | |||||
writePaging(responseBuilder, result, context); | |||||
doContextResponse(dbSession, request, result, responseBuilder, query); | doContextResponse(dbSession, request, result, responseBuilder, query); | ||||
if (!context.getFacets().isEmpty()) { | if (!context.getFacets().isEmpty()) { | ||||
writeFacets(responseBuilder, request, context, result); | writeFacets(responseBuilder, request, context, result); | ||||
return responseBuilder.build(); | return responseBuilder.build(); | ||||
} | } | ||||
private static void writeStatistics(SearchResponse.Builder response, SearchResult searchResult, SearchOptions context) { | |||||
response.setTotal(searchResult.total); | |||||
response.setP(context.getPage()); | |||||
response.setPs(context.getLimit()); | |||||
private static void writePaging(SearchResponse.Builder response, SearchResult searchResult, SearchOptions context) { | |||||
response.setPaging(formatPaging(searchResult.total, context.getPage(), context.getLimit())); | response.setPaging(formatPaging(searchResult.total, context.getPage(), context.getLimit())); | ||||
} | } | ||||
.addSearchQuery("freddy", "names", "logins") | .addSearchQuery("freddy", "names", "logins") | ||||
.addPagingParams(25) | .addPagingParams(25) | ||||
.setChangelog( | .setChangelog( | ||||
new Change("10.2", "Response fields 'total', 's', 'ps' dropped"), | |||||
new Change("10.0", "Field 'managed' added to the payload."), | new Change("10.0", "Field 'managed' added to the payload."), | ||||
new Change("10.0", "Parameter 'id' is removed. Use 'name' instead."), | new Change("10.0", "Parameter 'id' is removed. Use 'name' instead."), | ||||
new Change("9.8", "response fields 'total', 's', 'ps' have been deprecated, please use 'paging' object instead."), | new Change("9.8", "response fields 'total', 's', 'ps' have been deprecated, please use 'paging' object instead."), | ||||
json.beginObject(); | json.beginObject(); | ||||
writeMembers(json, users, userUuidToIsManaged); | writeMembers(json, users, userUuidToIsManaged); | ||||
writePaging(json, paging); | writePaging(json, paging); | ||||
json.name("paging").beginObject() | |||||
.prop("pageIndex", page) | |||||
.prop("pageSize", pageSize) | |||||
.prop("total", total) | |||||
.endObject(); | |||||
json.endObject(); | json.endObject(); | ||||
} | } | ||||
} | } | ||||
json.endArray(); | json.endArray(); | ||||
} | } | ||||
/** | |||||
* @deprecated since 9.8 - replaced by 'paging' object structure. | |||||
*/ | |||||
@Deprecated(since = "9.8") | |||||
private static void writePaging(JsonWriter json, Paging paging) { | private static void writePaging(JsonWriter json, Paging paging) { | ||||
json.prop(Param.PAGE, paging.pageIndex()) | |||||
.prop(Param.PAGE_SIZE, paging.pageSize()) | |||||
.prop("total", paging.total()); | |||||
json.name("paging").beginObject() | |||||
.prop("pageIndex", paging.pageIndex()) | |||||
.prop("pageSize", paging.pageSize()) | |||||
.prop("total", paging.total()) | |||||
.endObject(); | |||||
} | } | ||||
private static String getMembership(String selected) { | private static String getMembership(String selected) { |
SearchResponse response = loadFromStream(wsClient.call(getRequest).contentStream()); | SearchResponse response = loadFromStream(wsClient.call(getRequest).contentStream()); | ||||
List<LoadedActiveRule> pageRules = readPage(response); | List<LoadedActiveRule> pageRules = readPage(response); | ||||
ruleList.addAll(pageRules); | ruleList.addAll(pageRules); | ||||
loaded += response.getPs(); | |||||
loaded += response.getPaging().getPageSize(); | |||||
if (response.getTotal() <= loaded) { | |||||
if (response.getPaging().getTotal() <= loaded) { | |||||
break; | break; | ||||
} | } | ||||
page++; | page++; |
import org.sonar.scanner.WsTestUtil; | import org.sonar.scanner.WsTestUtil; | ||||
import org.sonar.scanner.bootstrap.DefaultScannerWsClient; | import org.sonar.scanner.bootstrap.DefaultScannerWsClient; | ||||
import org.sonar.scanner.scan.branch.BranchConfiguration; | import org.sonar.scanner.scan.branch.BranchConfiguration; | ||||
import org.sonarqube.ws.Common; | |||||
import org.sonarqube.ws.Rules; | import org.sonarqube.ws.Rules; | ||||
import org.sonarqube.ws.Rules.Active; | import org.sonarqube.ws.Rules.Active; | ||||
import org.sonarqube.ws.Rules.ActiveList; | import org.sonarqube.ws.Rules.ActiveList; | ||||
}); | }); | ||||
rules.setActives(actives); | rules.setActives(actives); | ||||
rules.setPs(numberOfRules); | |||||
rules.setTotal(total); | |||||
rules.setPaging(Common.Paging.newBuilder().setPageSize(numberOfRules).setTotal(total)); | |||||
return new ByteArrayInputStream(rules.build().toByteArray()); | return new ByteArrayInputStream(rules.build().toByteArray()); | ||||
} | } | ||||
}); | }); | ||||
rules.setActives(actives); | rules.setActives(actives); | ||||
rules.setPs(3); | |||||
rules.setTotal(3); | |||||
rules.setPaging(Common.Paging.newBuilder().setPageSize(3).setTotal(3)); | |||||
return new ByteArrayInputStream(rules.build().toByteArray()); | return new ByteArrayInputStream(rules.build().toByteArray()); | ||||
} | } | ||||
} | } |
// Response of GET api/issues/search | // Response of GET api/issues/search | ||||
message SearchWsResponse { | message SearchWsResponse { | ||||
reserved 5; | reserved 5; | ||||
optional int64 total = 1 [deprecated=true]; | |||||
optional int64 p = 2 [deprecated=true]; | |||||
optional int32 ps = 3 [deprecated=true]; | |||||
reserved 1; | |||||
reserved 2; | |||||
reserved 3; | |||||
optional sonarqube.ws.commons.Paging paging = 4; | optional sonarqube.ws.commons.Paging paging = 4; | ||||
// Total amount of effort, only when the facet "total" is enabled | // Total amount of effort, only when the facet "total" is enabled |
// WS api/rules/search | // WS api/rules/search | ||||
message SearchResponse { | message SearchResponse { | ||||
optional int64 total = 1 [deprecated=true]; | |||||
optional int32 p = 2 [deprecated=true]; | |||||
optional int64 ps = 3 [deprecated=true]; | |||||
reserved 1; | |||||
reserved 2; | |||||
reserved 3; | |||||
repeated Rule rules = 4; | repeated Rule rules = 4; | ||||
optional Actives actives = 5; | optional Actives actives = 5; | ||||
optional QProfiles qProfiles = 6; | optional QProfiles qProfiles = 6; |